From 0bef41c0338e3532d058a576099610ea813ef377 Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Sat, 10 Jul 2021 14:45:09 +0200 Subject: [PATCH] add break --- source/script/arrayClass.c | 10 ++++++++-- source/script/parser.c | 1 - source/script/scriptError.c | 3 ++- source/script/scriptError.h | 2 ++ source/script/standardLibrary.c | 18 ++++++++++++++++-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/source/script/arrayClass.c b/source/script/arrayClass.c index 21e3b3c..4a37057 100644 --- a/source/script/arrayClass.c +++ b/source/script/arrayClass.c @@ -113,8 +113,14 @@ ClassFunction(arrayForEach) { iter->gcDoNotFree = 1; Variable_t* res = genericCallDirect(args[1], NULL, 0); - if (res == NULL) - return NULL; + if (res == NULL) { + if (scriptLastError == SCRIPT_BREAK) { + break; + } + else { + return NULL; + } + } } iter->reference = 1; diff --git a/source/script/parser.c b/source/script/parser.c index f49f931..359c996 100644 --- a/source/script/parser.c +++ b/source/script/parser.c @@ -420,7 +420,6 @@ ParserRet_t parseScript(char* in) { op.token = EquationSeperator; op.lineNumber = lineNumber; - vecAdd(&lastFunc->operations, op); } else { SCRIPT_PARSER_ERR("Stack count is 1 or state is not a function"); diff --git a/source/script/scriptError.c b/source/script/scriptError.c index 3579060..e85ee98 100644 --- a/source/script/scriptError.c +++ b/source/script/scriptError.c @@ -3,10 +3,11 @@ #include s64 scriptCurrentLine; +u8 scriptLastError = 0; void printScriptError(u8 errLevel, char* message, ...) { va_list args; - + scriptLastError = errLevel; va_start(args, message); gfx_printf("\n\n[%s] ", (errLevel == SCRIPT_FATAL) ? "FATAL" : (errLevel == SCRIPT_PARSER_FATAL) ? "PARSE_FATAL" : "WARN"); gfx_vprintf(message, args); diff --git a/source/script/scriptError.h b/source/script/scriptError.h index 1bee452..161c55f 100644 --- a/source/script/scriptError.h +++ b/source/script/scriptError.h @@ -5,9 +5,11 @@ enum { SCRIPT_FATAL = 0, SCRIPT_PARSER_FATAL, SCRIPT_WARN, + SCRIPT_BREAK, }; extern s64 scriptCurrentLine; +extern u8 scriptLastError; void printScriptError(u8 errLevel, char* message, ...); diff --git a/source/script/standardLibrary.c b/source/script/standardLibrary.c index 0077caf..084f57d 100644 --- a/source/script/standardLibrary.c +++ b/source/script/standardLibrary.c @@ -5,6 +5,7 @@ #include "garbageCollector.h" #include "intClass.h" #include "standardLibrary.h" +#include "scriptError.h" #include #ifndef WIN32 @@ -37,8 +38,14 @@ ClassFunction(stdWhile) { while (result->integer.value) { removePendingReference(result); Variable_t* res = genericCallDirect(args[1], NULL, 0); - if (res == NULL) - return NULL; + if (res == NULL) { + if (scriptLastError == SCRIPT_BREAK) { + break; + } + else { + return NULL; + } + } removePendingReference(res); @@ -67,6 +74,11 @@ ClassFunction(stdExit) { return NULL; } +ClassFunction(stdBreak) { + scriptLastError = SCRIPT_BREAK; + return NULL; +} + #ifndef WIN32 ClassFunction(stdMountSysmmc){ if (connectMMC(MMC_CONN_EMMC)) @@ -108,6 +120,7 @@ enum standardFunctionIndexes { STD_MOUNTSYSMMC, STD_MOUNTSAVE, STD_EXIT, + STD_BREAK, }; u8 oneIntoneFunction[] = { IntClass, FunctionClass }; @@ -121,6 +134,7 @@ ClassFunctionTableEntry_t standardFunctionDefenitions[] = { [STD_MOUNTSYSMMC] = {"mountsys", stdMountSysmmc, 1, oneStringArgStd}, [STD_MOUNTSAVE] = {"readsave", stdMountSave, 1, oneStringArgStd}, [STD_EXIT] = {"exit", stdExit, 0, 0}, + [STD_BREAK] = {"break", stdBreak, 0, 0}, }; ClassFunctionTableEntry_t* searchStdLib(char* funcName) {