From 86921823b2e8c8f59ff7b87916185132b520429b Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 4 Aug 2023 09:17:46 +0100 Subject: [PATCH] Fix failure to run JIT caused by String interpreting optimisation JIT: JIT failures now don't stop execution of subsequent commands - function is just executed as normal JS --- ChangeLog | 2 ++ src/jsjit.c | 4 +++- src/jsparse.c | 17 +++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f61099c85..746ce4541d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,8 @@ Graphics: drawImage now avoids getting pixels top/bottom of an image that might be cropped/offscreen Bangle.js: Handle pushing events via the event queue (allows events to be queued rather than lost) Bangle.js2: Allow HRM environment sensor data to be pushed, also add flags for disabling auto exposure and wear detect + Fix failure to run JIT caused by String interpreting optimisation + JIT: JIT failures now don't stop execution of subsequent commands - function is just executed as normal JS 2v18 : Fix drawString with setClipRect with 90/270-degree rotation (fix #2343) Pico/Wifi: Enabled JIT compiler diff --git a/src/jsjit.c b/src/jsjit.c index 66b0000943..7241151318 100644 --- a/src/jsjit.c +++ b/src/jsjit.c @@ -1008,7 +1008,7 @@ void jsjStatementDoOrWhile(bool isWhile) { jsjPopAsBool(0); jsjcCompareImm(0, 0); jsjcBranchConditionalRelative(JSJAC_NE, codePosStart - (jsjcGetByteCount()+2)); - } + } } } @@ -1094,6 +1094,7 @@ void jsjBlockOrStatement() { } JsVar *jsjParseFunction() { + JsExecFlags oldExec = execInfo.execute; jsjcStart(); // FIXME: I guess we need to create a function execution scope and unpack parameters? // Maybe we could use jspeFunctionCall to do all this for us (not creating a native function but a 'normal' one @@ -1118,6 +1119,7 @@ JsVar *jsjParseFunction() { } JsVar *v = jsjcStop(); JsVar *exception = jspGetException(); + execInfo.execute = oldExec; // restore exec state if (!exception) return v; // We had an error - don't return half-complete code jsiConsolePrintf("JIT %v\n", exception); diff --git a/src/jsparse.c b/src/jsparse.c index f2389a4de4..a38996ab08 100644 --- a/src/jsparse.c +++ b/src/jsparse.c @@ -330,18 +330,22 @@ NO_INLINE bool jspeFunctionDefinitionInternal(JsVar *funcVar, bool expressionOnl if (funcVar) funcVar->flags = (funcVar->flags & ~JSV_VARTYPEMASK) | JSV_FUNCTION_RETURN; } else { + JsExecFlags oldExec = execInfo.execute; + execInfo.execute = EXEC_YES; // we need to force EXEC_YES so that the next token is parsed if it's a string, for compiled/ram/jit test JSP_MATCH('{'); - #ifndef SAVE_ON_FLASH + execInfo.execute = oldExec; +#ifndef SAVE_ON_FLASH if (lex->tk==LEX_STR) { - if (!strcmp(jslGetTokenValueAsString(), "compiled")) + JsVar *tokenValue = jslGetTokenValueAsVar(); + if (jsvIsStringEqual(tokenValue, "compiled")) { jsWarn("Function marked with \"compiled\" uploaded in source form"); - if (!strcmp(jslGetTokenValueAsString(), "ram")) { + } else if (jsvIsStringEqual(tokenValue, "ram")) { JSP_ASSERT_MATCH(LEX_STR); if (lex->tk==';') JSP_ASSERT_MATCH(';'); forcePretokenise = true; } #ifdef ESPR_JIT - if (!strcmp(jslGetTokenValueAsString(), "jit")) { + else if (jsvIsStringEqual(tokenValue, "jit")) { JslCharPos funcCodeStart; jslCharPosFromLex(&funcCodeStart); JSP_ASSERT_MATCH(LEX_STR); @@ -367,9 +371,10 @@ NO_INLINE bool jspeFunctionDefinitionInternal(JsVar *funcVar, bool expressionOnl jslCharPosFree(&funcCodeStart); } } -#endif +#endif // ESPR_JIT + jsvUnLock(tokenValue); } - #endif +#endif // SAVE_ON_FLASH /* If the function starts with return, treat it specially - * we don't want to store the 'return' part of it