mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-08 13:11:54 +00:00
safety push
This commit is contained in:
parent
b730c060c7
commit
e41971c7d6
8 changed files with 139 additions and 44 deletions
11
scripts/ButtonTest.te
Normal file
11
scripts/ButtonTest.te
Normal file
|
@ -0,0 +1,11 @@
|
|||
println("Testing pause")
|
||||
x = pause()
|
||||
println(x.raw, " ", x.a, "", x.power)
|
||||
println("Testing masked pause")
|
||||
x = pausemask(1 << 3)
|
||||
println(x.raw, " ", x.a)
|
||||
color(0xFF0000)
|
||||
println("This text should be red!")
|
||||
color(0x00FF00)
|
||||
println("and this green!")
|
||||
exit()
|
|
@ -77,8 +77,7 @@ void RunScriptString(char *str, u32 size){
|
|||
ParserRet_t ret = parseScript(str, size);
|
||||
setStaticVars(&ret.staticVarHolder);
|
||||
initRuntimeVars();
|
||||
Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1);
|
||||
|
||||
eval(ret.main.operations.data, ret.main.operations.count, 0);
|
||||
exitRuntimeVars();
|
||||
exitStaticVars(&ret.staticVarHolder);
|
||||
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
||||
|
|
|
@ -62,15 +62,15 @@ int main()
|
|||
|
||||
return;
|
||||
*/
|
||||
|
||||
char* script = readFile("input.te");
|
||||
if (script == NULL)
|
||||
return;
|
||||
|
||||
//parseScript("#REQUIRE VER 3.0.5\nmain = { two = 1 + 1 }");
|
||||
//ParserRet_t ret = parseScript("a.b.c(1){ a.b.c() }");
|
||||
while (1) {
|
||||
ParserRet_t ret = parseScript(script, strlen(script));
|
||||
free(script);
|
||||
|
||||
|
||||
setStaticVars(&ret.staticVarHolder);
|
||||
initRuntimeVars();
|
||||
|
@ -82,7 +82,10 @@ int main()
|
|||
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
||||
vecFree(ret.staticVarHolder);
|
||||
vecFree(ret.main.operations);
|
||||
}
|
||||
|
||||
|
||||
free(script);
|
||||
gfx_printf("done");
|
||||
}
|
||||
#endif
|
|
@ -1,9 +1,20 @@
|
|||
#include "dictionaryClass.h"
|
||||
#include <string.h>
|
||||
#include "garbageCollector.h"
|
||||
#include "intClass.h"
|
||||
|
||||
u8 dictOneStrOneAll[] = { StringClass, VARARGCOUNT };
|
||||
|
||||
void addVariableToDict(Variable_t *dict, char* name, Variable_t *add){
|
||||
Dict_t a = {.name = CpyStr(name), .var = add};
|
||||
vecAdd(&dict->dictionary.vector, a);
|
||||
}
|
||||
|
||||
void addIntToDict(Variable_t *dict, char* name, s64 integer){
|
||||
Variable_t *v = newIntVariablePtr(integer);
|
||||
addVariableToDict(dict, name, v);
|
||||
}
|
||||
|
||||
Dict_t* getEntry(Vector_t *v, char* name) {
|
||||
vecForEach(Dict_t*, dict, v) {
|
||||
if (!strcmp(name, dict->name)) {
|
||||
|
|
|
@ -4,3 +4,5 @@
|
|||
#include "compat.h"
|
||||
|
||||
Variable_t getDictMember(Variable_t* var, char* memberName);
|
||||
void addVariableToDict(Variable_t *dict, char* name, Variable_t *add);
|
||||
void addIntToDict(Variable_t *dict, char* name, s64 integer);
|
|
@ -63,7 +63,6 @@ Variable_t* genericGet(Variable_t* var, CallArgs_t* ref) {
|
|||
|
||||
if (solvedIdx->variableType != IntClass) {
|
||||
SCRIPT_FATAL_ERR("Index is not an integer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Variable_t* res = callMemberFunctionDirect(var, "get", &solvedIdx, 1);
|
||||
|
@ -71,12 +70,13 @@ Variable_t* genericGet(Variable_t* var, CallArgs_t* ref) {
|
|||
return res;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
SCRIPT_FATAL_ERR("???");
|
||||
}
|
||||
|
||||
Variable_t* genericCallDirect(Variable_t* var, Variable_t** args, u8 len) {
|
||||
if (var->variableType != FunctionClass)
|
||||
return NULL;
|
||||
if (var->variableType != FunctionClass){
|
||||
SCRIPT_FATAL_ERR("Call on non function class");
|
||||
}
|
||||
|
||||
if (var->function.builtIn) {
|
||||
for (u32 i = 0; i < var->function.len; i++) {
|
||||
|
@ -109,8 +109,9 @@ Variable_t* genericCallDirect(Variable_t* var, Variable_t** args, u8 len) {
|
|||
}
|
||||
|
||||
Variable_t* genericCall(Variable_t* var, CallArgs_t* ref) {
|
||||
if (var->variableType != FunctionClass)
|
||||
return NULL;
|
||||
if (var->variableType != FunctionClass){
|
||||
SCRIPT_FATAL_ERR("Call on non function class");
|
||||
}
|
||||
|
||||
if (var->function.builtIn) {
|
||||
// TODO: implement arg handling
|
||||
|
@ -228,7 +229,7 @@ Variable_t* callMemberFunction(Variable_t* var, char* memberName, CallArgs_t* ar
|
|||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
SCRIPT_FATAL_ERR("Could not find function table for given type");
|
||||
}
|
||||
|
||||
Variable_t* callMemberFunctionDirect(Variable_t* var, char* memberName, Variable_t** args, u8 argsLen) {
|
||||
|
@ -249,7 +250,6 @@ Variable_t* callMemberFunctionDirect(Variable_t* var, char* memberName, Variable
|
|||
}
|
||||
|
||||
SCRIPT_FATAL_ERR("Could not find function table for given type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void freeVariableInternal(Variable_t* referencedTarget) {
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
#include "compat.h"
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#ifndef WIN32
|
||||
#include <utils/sprintf.h>
|
||||
#endif
|
||||
|
||||
IntClass_t createIntClass(s64 in) {
|
||||
IntClass_t a = { in };
|
||||
|
@ -23,9 +25,13 @@ ClassFunction(printIntVariable) {
|
|||
}
|
||||
|
||||
ClassFunction(intToStr) {
|
||||
char buff[64] = {0};
|
||||
#ifndef WIN32
|
||||
char buff[64] = { 0 };
|
||||
s_printf(buff, "%d", getIntValue(caller));
|
||||
return newStringVariablePtr(CpyStr(buff), 0, 1);
|
||||
#else
|
||||
return newIntVariablePtr(0);
|
||||
#endif // !WIN32
|
||||
}
|
||||
|
||||
#define IntOpFunction(name, op) ClassFunction(name) { s64 i1 = getIntValue(caller); s64 i2 = getIntValue(*args); return newIntVariablePtr((i1 op i2)); }
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "standardLibrary.h"
|
||||
#include "scriptError.h"
|
||||
#include <string.h>
|
||||
#include "dictionaryClass.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include "../storage/mountmanager.h"
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include "../fs/fscopy.h"
|
||||
#include <mem/heap.h>
|
||||
#include "../keys/nca.h"
|
||||
#include "../hid/hid.h"
|
||||
#endif
|
||||
|
||||
ClassFunction(stdIf) {
|
||||
|
@ -109,6 +111,7 @@ ClassFunction(stdMountSysmmc){
|
|||
}
|
||||
|
||||
ClassFunction(stdMountSave){
|
||||
|
||||
Variable_t *arg = (*args);
|
||||
Variable_t var = {.variableType = SaveClass};
|
||||
SaveClass_t* save = calloc(1, sizeof(SaveClass_t));
|
||||
|
@ -120,6 +123,8 @@ ClassFunction(stdMountSave){
|
|||
|
||||
var.save = save;
|
||||
return copyVariableToPtr(var);
|
||||
|
||||
return newIntVariablePtr(0);
|
||||
}
|
||||
ClassFunction(stdSetPixel) {
|
||||
u32 color = getIntValue(args[2]);
|
||||
|
@ -128,10 +133,9 @@ ClassFunction(stdSetPixel) {
|
|||
}
|
||||
|
||||
ClassFunction(stdReadDir){
|
||||
Vector_t dict = newVec(sizeof(Dict_t), 4);
|
||||
Variable_t* resPtr = newIntVariablePtr(0);
|
||||
Dict_t temp = {.name = CpyStr("result"), .var = resPtr};
|
||||
vecAdd(&dict, temp);
|
||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 4)};
|
||||
addVariableToDict(&ret, "result", resPtr);
|
||||
|
||||
Variable_t fileNamesArray = {.variableType = StringArrayClass, .solvedArray.vector = newVec(sizeof(char*), 0)};
|
||||
Variable_t dirNamesArray = {.variableType = StringArrayClass, .solvedArray.vector = newVec(sizeof(char*), 0)};
|
||||
|
@ -139,7 +143,6 @@ ClassFunction(stdReadDir){
|
|||
|
||||
DIR dir;
|
||||
if ((resPtr->integer.value = f_opendir(&dir, args[0]->string.value))){
|
||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = dict};
|
||||
return copyVariableToPtr(ret);
|
||||
}
|
||||
|
||||
|
@ -158,22 +161,69 @@ ClassFunction(stdReadDir){
|
|||
|
||||
f_closedir(&dir);
|
||||
|
||||
temp.name = CpyStr("files");
|
||||
temp.var = copyVariableToPtr(fileNamesArray);
|
||||
vecAdd(&dict, temp);
|
||||
addVariableToDict(&ret, "files", copyVariableToPtr(fileNamesArray));
|
||||
addVariableToDict(&ret, "folders", copyVariableToPtr(dirNamesArray));
|
||||
addVariableToDict(&ret, "fileSizes", copyVariableToPtr(fileSizeArray));
|
||||
|
||||
temp.name = CpyStr("folders");
|
||||
temp.var = copyVariableToPtr(dirNamesArray);
|
||||
vecAdd(&dict, temp);
|
||||
|
||||
temp.name = CpyStr("fileSizes");
|
||||
temp.var = copyVariableToPtr(fileSizeArray);
|
||||
vecAdd(&dict, temp);
|
||||
|
||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = dict};
|
||||
return copyVariableToPtr(ret);
|
||||
}
|
||||
|
||||
char *abxyNames[] = {
|
||||
"y",
|
||||
"x",
|
||||
"b",
|
||||
"a"
|
||||
};
|
||||
|
||||
char *ulrdNames[] = {
|
||||
"down",
|
||||
"up",
|
||||
"right",
|
||||
"left",
|
||||
};
|
||||
|
||||
char *powNames[] = {
|
||||
"power",
|
||||
"volplus",
|
||||
"volminus",
|
||||
};
|
||||
|
||||
ClassFunction(stdPauseMask){
|
||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
|
||||
Input_t *i = hidWaitMask((u32)getIntValue(*args));
|
||||
|
||||
u32 raw = i->buttons;
|
||||
|
||||
addIntToDict(&ret, "raw", raw);
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(abxyNames); i++){
|
||||
addIntToDict(&ret, abxyNames[i], raw & 0x1);
|
||||
raw >>= 1;
|
||||
}
|
||||
|
||||
raw >>= 12;
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(ulrdNames); i++){
|
||||
addIntToDict(&ret, ulrdNames[i], raw & 0x1);
|
||||
raw >>= 1;
|
||||
}
|
||||
|
||||
raw >>= 4;
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(powNames); i++){
|
||||
addIntToDict(&ret, powNames[i], raw & 0x1);
|
||||
raw >>= 1;
|
||||
}
|
||||
|
||||
return copyVariableToPtr(ret);
|
||||
}
|
||||
|
||||
ClassFunction(stdPause){
|
||||
Variable_t a = {.integer.value = 0xFFFFFFFF};
|
||||
Variable_t *b = &a;
|
||||
return stdPauseMask(caller, &b, 1);
|
||||
}
|
||||
|
||||
ClassFunction(stdFileCopy){
|
||||
ErrCode_t e = FileCopy(args[0]->string.value, args[1]->string.value, 0);
|
||||
return newIntVariablePtr(e.err);
|
||||
|
@ -190,11 +240,16 @@ ClassFunction(stdGetMemUsage){
|
|||
Dict_t a = {.name = CpyStr("used"), .var = newIntVariablePtr((s64)mon.used)};
|
||||
Dict_t b = {.name = CpyStr("total"), .var = newIntVariablePtr((s64)mon.total)};
|
||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 2)};
|
||||
vecAdd(&ret, a);
|
||||
vecAdd(&ret, b);
|
||||
vecAdd(&ret.dictionary.vector, a);
|
||||
vecAdd(&ret.dictionary.vector, b);
|
||||
return copyVariableToPtr(ret);
|
||||
}
|
||||
|
||||
ClassFunction(stdColor){
|
||||
gfx_con_setcol((u32)getIntValue(*args) | 0xFF000000, gfx_con.fillbg, gfx_con.bgcol);
|
||||
return &emptyClass;
|
||||
}
|
||||
|
||||
ClassFunction(stdGetNcaType){
|
||||
int type = GetNcaType(args[0]->string.value);
|
||||
return newIntVariablePtr(type);
|
||||
|
@ -225,6 +280,10 @@ ClassFunction(stdMkdir){
|
|||
ClassFunction(stdGetMemUsage) {
|
||||
return newIntVariablePtr(0);
|
||||
}
|
||||
|
||||
ClassFunction(stdGetNcaType) {
|
||||
return newIntVariablePtr(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
u8 oneIntoneFunction[] = { IntClass, FunctionClass };
|
||||
|
@ -232,6 +291,7 @@ u8 doubleFunctionClass[] = { FunctionClass, FunctionClass };
|
|||
u8 oneStringArgStd[] = {StringClass};
|
||||
u8 threeIntsStd[] = { IntClass, IntClass, IntClass };
|
||||
u8 twoStringArgStd[] = {StringClass, StringClass};
|
||||
u8 oneIntStd[] = {IntClass};
|
||||
|
||||
ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
||||
{"if", stdIf, 2, oneIntoneFunction},
|
||||
|
@ -249,6 +309,9 @@ ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
|||
{"mkdir", stdMkdir, 1, oneStringArgStd},
|
||||
{"memory", stdGetMemUsage, 0, 0},
|
||||
{"ncatype", stdGetNcaType, 1, oneStringArgStd},
|
||||
{"pause", stdPause, 0, 0},
|
||||
{"pausemask", stdPauseMask, 1, oneIntStd},
|
||||
{"color", stdColor, 1, oneIntStd},
|
||||
};
|
||||
|
||||
ClassFunctionTableEntry_t* searchStdLib(char* funcName) {
|
||||
|
|
Loading…
Reference in a new issue