Skip to content

Commit

Permalink
Fix failure to run JIT caused by String interpreting optimisation
Browse files Browse the repository at this point in the history
            JIT: JIT failures now don't stop execution of subsequent commands - function is just executed as normal JS
  • Loading branch information
gfwilliams committed Aug 4, 2023
1 parent 5cfde78 commit 8692182
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/jsjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ void jsjStatementDoOrWhile(bool isWhile) {
jsjPopAsBool(0);
jsjcCompareImm(0, 0);
jsjcBranchConditionalRelative(JSJAC_NE, codePosStart - (jsjcGetByteCount()+2));
}
}
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions src/jsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 8692182

Please sign in to comment.