mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 11:56:42 +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="arrayClass.c" />
|
||||
<ClCompile Include="arrayReferenceClass.c" />
|
||||
<ClCompile Include="else.c" />
|
||||
<ClCompile Include="eval.c" />
|
||||
<ClCompile Include="functionClass.c" />
|
||||
<ClCompile Include="garbageCollector.c" />
|
||||
|
@ -163,6 +164,7 @@
|
|||
<ClInclude Include="arrayReferenceClass.h" />
|
||||
<ClInclude Include="compat.h" />
|
||||
<ClInclude Include="dictionaryClass.h" />
|
||||
<ClInclude Include="else.h" />
|
||||
<ClInclude Include="eval.h" />
|
||||
<ClInclude Include="functionClass.h" />
|
||||
<ClInclude Include="garbageCollector.h" />
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
<Filter Include="Source Files\Classes\Int">
|
||||
<UniqueIdentifier>{64738969-63b9-4d0e-85b9-d9a63a7e36b3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Classes\Elseable">
|
||||
<UniqueIdentifier>{ba83a808-23f1-44c6-85e4-d0c6c77200fa}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ABadIdeaVersion3.c">
|
||||
|
@ -81,6 +84,9 @@
|
|||
<ClCompile Include="scriptError.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="else.c">
|
||||
<Filter>Source Files\Classes\Elseable</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="compat.h">
|
||||
|
@ -131,5 +137,8 @@
|
|||
<ClInclude Include="scriptError.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="else.h">
|
||||
<Filter>Source Files\Classes\Elseable</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</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 "saveClass.h"
|
||||
#include "unsolvedArrayClass.h"
|
||||
#include "else.h"
|
||||
|
||||
Variable_t* copyVariableToPtr(Variable_t var) {
|
||||
Variable_t* a = malloc(sizeof(Variable_t));
|
||||
|
@ -28,6 +29,7 @@ MemberGetters_t memberGetters[] = {
|
|||
{ByteArrayClass, getArrayMember},
|
||||
{SolvedArrayReferenceClass, getArrayReferenceMember},
|
||||
{UnresolvedArrayClass, getUnsolvedArrayMember},
|
||||
{ElseClass, getElseMember},
|
||||
#ifndef WIN32
|
||||
{SaveClass, getSaveMember},
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef enum {
|
|||
EmptyClass,
|
||||
SolvedArrayReferenceClass,
|
||||
SaveClass,
|
||||
ElseClass,
|
||||
} VariableType_t;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -389,15 +389,17 @@ ParserRet_t parseScript(char* in) {
|
|||
SCRIPT_PARSER_ERR("GET variable before {}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Set last arg to {}
|
||||
CallArgs_t* lastCall = getLastRef(&lastOp->callArgs);
|
||||
if (lastCall->extraAction == ActionExtraCallArgs) {
|
||||
Function_t* funcArgs = lastCall->extra;
|
||||
|
||||
op.token = EquationSeperator;
|
||||
op.lineNumber = lineNumber;
|
||||
vecAdd(&funcArgs->operations, op);
|
||||
op.token = Variable;
|
||||
if (funcArgs->operations.count != 0) {
|
||||
op.token = EquationSeperator;
|
||||
op.lineNumber = lineNumber;
|
||||
vecAdd(&funcArgs->operations, op);
|
||||
op.token = Variable;
|
||||
}
|
||||
|
||||
Variable_t a = newFunctionVariable(createFunctionClass(*popFunc, NULL));
|
||||
vecAdd(&staticVariableHolder, a);
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
ClassFunction(stdIf) {
|
||||
s64 value = getIntValue(args[0]);
|
||||
|
||||
|
||||
if (value) {
|
||||
Variable_t* res = genericCallDirect(args[1], NULL, 0);
|
||||
if (res == NULL)
|
||||
|
@ -24,10 +23,11 @@ ClassFunction(stdIf) {
|
|||
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) {
|
||||
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
|
||||
|
|
Loading…
Reference in a new issue