1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00
TegraExplorer/source/script/intClass.c

85 lines
2.4 KiB
C
Raw Normal View History

2021-07-09 21:56:13 +01:00
#include "intClass.h"
2021-07-21 14:19:27 +01:00
#include "StringClass.h"
2021-07-09 21:56:13 +01:00
#include "compat.h"
#include <malloc.h>
#include <string.h>
2021-07-21 14:19:27 +01:00
#include <utils/sprintf.h>
2021-07-09 21:56:13 +01:00
IntClass_t createIntClass(s64 in) {
IntClass_t a = { in };
return a;
}
Variable_t newIntVariable(s64 x) {
// Integers are always read-only
Variable_t var = { .variableType = IntClass, .readOnly = 1, .integer = createIntClass(x) };
return var;
}
ClassFunction(printIntVariable) {
IntClass_t* a = &caller->integer;
gfx_printf("%d", (int)a->value);
return &emptyClass;
}
2021-07-21 14:19:27 +01:00
ClassFunction(intToStr) {
char buff[64] = {0};
s_printf(buff, "%d", getIntValue(caller));
return newStringVariablePtr(CpyStr(buff), 0, 1);
}
2021-07-09 21:56:13 +01:00
#define IntOpFunction(name, op) ClassFunction(name) { s64 i1 = getIntValue(caller); s64 i2 = getIntValue(*args); return newIntVariablePtr((i1 op i2)); }
IntOpFunction(addInt, +)
IntOpFunction(minusInt, -)
IntOpFunction(multInt, *)
IntOpFunction(divInt, /)
IntOpFunction(modInt, %)
IntOpFunction(smallerInt, <)
IntOpFunction(biggerInt, >)
IntOpFunction(smallerEqInt, <=)
IntOpFunction(biggerEqInt, >=)
IntOpFunction(eqInt, ==)
IntOpFunction(notEqInt, !=)
IntOpFunction(logicAndInt, &&)
IntOpFunction(logicOrInt, ||)
IntOpFunction(andInt, &)
IntOpFunction(orInt, |)
IntOpFunction(bitshiftLeftInt, <<)
IntOpFunction(bitshiftRightInt, >>)
ClassFunction(notInt) {
return newIntVariablePtr(!(getIntValue(caller)));
}
u8 oneVarArgInt[] = { VARARGCOUNT };
u8 oneIntArgInt[] = { IntClass };
#define IntOpFunctionEntry(opName, functionName) {opName, functionName, 1, oneIntArgInt}
ClassFunctionTableEntry_t intFunctions[] = {
{"print", printIntVariable, 0, 0},
{"not", notInt, 0, 0},
2021-07-21 14:19:27 +01:00
{"str", intToStr, 0, 0},
2021-07-09 21:56:13 +01:00
IntOpFunctionEntry("+", addInt),
IntOpFunctionEntry("-", minusInt),
IntOpFunctionEntry("*", multInt),
IntOpFunctionEntry("/", divInt),
IntOpFunctionEntry("%", modInt),
IntOpFunctionEntry("<", smallerInt),
IntOpFunctionEntry(">", biggerInt),
IntOpFunctionEntry("<=", smallerEqInt),
IntOpFunctionEntry(">=", biggerEqInt),
IntOpFunctionEntry("==", eqInt),
IntOpFunctionEntry("!=", notEqInt),
IntOpFunctionEntry("&&", logicAndInt),
IntOpFunctionEntry("||", logicOrInt),
IntOpFunctionEntry("&", andInt),
IntOpFunctionEntry("|", orInt),
IntOpFunctionEntry("<<", bitshiftLeftInt),
IntOpFunctionEntry(">>", bitshiftRightInt),
};
Variable_t getIntegerMember(Variable_t* var, char* memberName) {
return getGenericFunctionMember(var, memberName, intFunctions, ARRAY_SIZE(intFunctions));
}