mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-26 05:42:07 +00:00
implement if.else()
This commit is contained in:
parent
623634b515
commit
65a28d8ef6
8 changed files with 55 additions and 10 deletions
|
@ -145,6 +145,7 @@
|
||||||
<ClCompile Include="ABadIdeaVersion3.c" />
|
<ClCompile Include="ABadIdeaVersion3.c" />
|
||||||
<ClCompile Include="arrayClass.c" />
|
<ClCompile Include="arrayClass.c" />
|
||||||
<ClCompile Include="arrayReferenceClass.c" />
|
<ClCompile Include="arrayReferenceClass.c" />
|
||||||
|
<ClCompile Include="else.c" />
|
||||||
<ClCompile Include="eval.c" />
|
<ClCompile Include="eval.c" />
|
||||||
<ClCompile Include="functionClass.c" />
|
<ClCompile Include="functionClass.c" />
|
||||||
<ClCompile Include="garbageCollector.c" />
|
<ClCompile Include="garbageCollector.c" />
|
||||||
|
@ -163,6 +164,7 @@
|
||||||
<ClInclude Include="arrayReferenceClass.h" />
|
<ClInclude Include="arrayReferenceClass.h" />
|
||||||
<ClInclude Include="compat.h" />
|
<ClInclude Include="compat.h" />
|
||||||
<ClInclude Include="dictionaryClass.h" />
|
<ClInclude Include="dictionaryClass.h" />
|
||||||
|
<ClInclude Include="else.h" />
|
||||||
<ClInclude Include="eval.h" />
|
<ClInclude Include="eval.h" />
|
||||||
<ClInclude Include="functionClass.h" />
|
<ClInclude Include="functionClass.h" />
|
||||||
<ClInclude Include="garbageCollector.h" />
|
<ClInclude Include="garbageCollector.h" />
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
<Filter Include="Source Files\Classes\Int">
|
<Filter Include="Source Files\Classes\Int">
|
||||||
<UniqueIdentifier>{64738969-63b9-4d0e-85b9-d9a63a7e36b3}</UniqueIdentifier>
|
<UniqueIdentifier>{64738969-63b9-4d0e-85b9-d9a63a7e36b3}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Source Files\Classes\Elseable">
|
||||||
|
<UniqueIdentifier>{ba83a808-23f1-44c6-85e4-d0c6c77200fa}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ABadIdeaVersion3.c">
|
<ClCompile Include="ABadIdeaVersion3.c">
|
||||||
|
@ -81,6 +84,9 @@
|
||||||
<ClCompile Include="scriptError.c">
|
<ClCompile Include="scriptError.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="else.c">
|
||||||
|
<Filter>Source Files\Classes\Elseable</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="compat.h">
|
<ClInclude Include="compat.h">
|
||||||
|
@ -131,5 +137,8 @@
|
||||||
<ClInclude Include="scriptError.h">
|
<ClInclude Include="scriptError.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="else.h">
|
||||||
|
<Filter>Source Files\Classes\Elseable</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
22
source/script/else.c
Normal file
22
source/script/else.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "else.h"
|
||||||
|
|
||||||
|
ClassFunction(scriptElse) {
|
||||||
|
if (!caller->integer.value) {
|
||||||
|
Variable_t* res = genericCallDirect(args[0], NULL, 0);
|
||||||
|
if (res == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
removePendingReference(res);
|
||||||
|
}
|
||||||
|
return &emptyClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 elseOneFunction[] = { FunctionClass };
|
||||||
|
|
||||||
|
ClassFunctionTableEntry_t elseFunctions[] = {
|
||||||
|
{"else", scriptElse, 1, elseOneFunction},
|
||||||
|
};
|
||||||
|
|
||||||
|
Variable_t getElseMember(Variable_t* var, char* memberName) {
|
||||||
|
return getGenericFunctionMember(var, memberName, elseFunctions, ARRAY_SIZE(elseFunctions));
|
||||||
|
}
|
7
source/script/else.h
Normal file
7
source/script/else.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
#include "model.h"
|
||||||
|
#include "genericClass.h"
|
||||||
|
#include "compat.h"
|
||||||
|
#include "garbageCollector.h"
|
||||||
|
|
||||||
|
Variable_t getElseMember(Variable_t* var, char* memberName);
|
|
@ -12,6 +12,7 @@
|
||||||
#include "scriptError.h"
|
#include "scriptError.h"
|
||||||
#include "saveClass.h"
|
#include "saveClass.h"
|
||||||
#include "unsolvedArrayClass.h"
|
#include "unsolvedArrayClass.h"
|
||||||
|
#include "else.h"
|
||||||
|
|
||||||
Variable_t* copyVariableToPtr(Variable_t var) {
|
Variable_t* copyVariableToPtr(Variable_t var) {
|
||||||
Variable_t* a = malloc(sizeof(Variable_t));
|
Variable_t* a = malloc(sizeof(Variable_t));
|
||||||
|
@ -28,6 +29,7 @@ MemberGetters_t memberGetters[] = {
|
||||||
{ByteArrayClass, getArrayMember},
|
{ByteArrayClass, getArrayMember},
|
||||||
{SolvedArrayReferenceClass, getArrayReferenceMember},
|
{SolvedArrayReferenceClass, getArrayReferenceMember},
|
||||||
{UnresolvedArrayClass, getUnsolvedArrayMember},
|
{UnresolvedArrayClass, getUnsolvedArrayMember},
|
||||||
|
{ElseClass, getElseMember},
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
{SaveClass, getSaveMember},
|
{SaveClass, getSaveMember},
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef enum {
|
||||||
EmptyClass,
|
EmptyClass,
|
||||||
SolvedArrayReferenceClass,
|
SolvedArrayReferenceClass,
|
||||||
SaveClass,
|
SaveClass,
|
||||||
|
ElseClass,
|
||||||
} VariableType_t;
|
} VariableType_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -389,15 +389,17 @@ ParserRet_t parseScript(char* in) {
|
||||||
SCRIPT_PARSER_ERR("GET variable before {}");
|
SCRIPT_PARSER_ERR("GET variable before {}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set last arg to {}
|
||||||
CallArgs_t* lastCall = getLastRef(&lastOp->callArgs);
|
CallArgs_t* lastCall = getLastRef(&lastOp->callArgs);
|
||||||
if (lastCall->extraAction == ActionExtraCallArgs) {
|
if (lastCall->extraAction == ActionExtraCallArgs) {
|
||||||
Function_t* funcArgs = lastCall->extra;
|
Function_t* funcArgs = lastCall->extra;
|
||||||
|
if (funcArgs->operations.count != 0) {
|
||||||
op.token = EquationSeperator;
|
op.token = EquationSeperator;
|
||||||
op.lineNumber = lineNumber;
|
op.lineNumber = lineNumber;
|
||||||
vecAdd(&funcArgs->operations, op);
|
vecAdd(&funcArgs->operations, op);
|
||||||
op.token = Variable;
|
op.token = Variable;
|
||||||
|
}
|
||||||
|
|
||||||
Variable_t a = newFunctionVariable(createFunctionClass(*popFunc, NULL));
|
Variable_t a = newFunctionVariable(createFunctionClass(*popFunc, NULL));
|
||||||
vecAdd(&staticVariableHolder, a);
|
vecAdd(&staticVariableHolder, a);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
ClassFunction(stdIf) {
|
ClassFunction(stdIf) {
|
||||||
s64 value = getIntValue(args[0]);
|
s64 value = getIntValue(args[0]);
|
||||||
|
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
Variable_t* res = genericCallDirect(args[1], NULL, 0);
|
Variable_t* res = genericCallDirect(args[1], NULL, 0);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
|
@ -24,10 +23,11 @@ ClassFunction(stdIf) {
|
||||||
removePendingReference(res);
|
removePendingReference(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return &emptyClass;
|
Variable_t* ret = newIntVariablePtr(value);
|
||||||
}
|
ret->variableType = ElseClass;
|
||||||
|
|
||||||
// TODO: implement else by making if return a class that is else-able
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ClassFunction(stdWhile) {
|
ClassFunction(stdWhile) {
|
||||||
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
|
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
|
||||||
|
|
Loading…
Reference in a new issue