1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-29 15:22:09 +00:00
TegraExplorer/source/script/intClass.c

91 lines
2.5 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-23 00:10:03 +01:00
#ifndef WIN32
2021-07-21 14:19:27 +01:00
#include <utils/sprintf.h>
2021-07-23 00:10:03 +01:00
#endif
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) {
2021-07-23 00:10:03 +01:00
#ifndef WIN32
char buff[64] = { 0 };
2021-07-21 14:19:27 +01:00
s_printf(buff, "%d", getIntValue(caller));
return newStringVariablePtr(CpyStr(buff), 0, 1);
2021-07-23 00:10:03 +01:00
#else
return newIntVariablePtr(0);
#endif // !WIN32
2021-07-21 14:19:27 +01:00
}
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));
}