mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Allow commas in expressions at end of for loop -
This commit is contained in:
parent
3e5e7b30b1
commit
3600dce96f
@ -20,6 +20,7 @@
|
||||
Allow Array.map.forEach to be applied to Strings and ArrayBuffers (for #310)
|
||||
Tweaks to make more Array functions work on non-arrays
|
||||
Added Array.reduce
|
||||
Allow commas in expressions at end of for loop - `for (;;i++,j++)`
|
||||
|
||||
1v60 : Fix unary plug on variable not working (fix #268)
|
||||
Added DNS with eth.setIP() for W5500
|
||||
|
||||
@ -1364,7 +1364,7 @@ NO_INLINE JsVar *jspeAssignmentExpression() {
|
||||
return __jspeAssignmentExpression(jspeConditionalExpression());
|
||||
}
|
||||
|
||||
// jspeAssignmentExpression where ',' is allowed to add multiple expressions
|
||||
// ',' is allowed to add multiple expressions, this is not allowed in jspeAssignmentExpression
|
||||
NO_INLINE JsVar *jspeExpression() {
|
||||
while (!JSP_HAS_ERROR) {
|
||||
JsVar *a = jspeAssignmentExpression();
|
||||
@ -1702,7 +1702,7 @@ NO_INLINE JsVar *jspeStatementFor() {
|
||||
}
|
||||
jsvUnLock(forStatement);
|
||||
jsvUnLock(array);
|
||||
} else { // NORMAL FOR LOOP
|
||||
} else { // ----------------------------------------------- NORMAL FOR LOOP
|
||||
#ifdef JSPARSE_MAX_LOOP_ITERATIONS
|
||||
int loopCount = JSPARSE_MAX_LOOP_ITERATIONS;
|
||||
#endif
|
||||
@ -1722,7 +1722,7 @@ NO_INLINE JsVar *jspeStatementFor() {
|
||||
if (execInfo.lex->tk != ')') { // we could have 'for (;;)'
|
||||
JSP_SAVE_EXECUTE();
|
||||
jspSetNoExecute();
|
||||
jsvUnLock(jspeAssignmentExpression()); // iterator
|
||||
jsvUnLock(jspeExpression()); // iterator
|
||||
JSP_RESTORE_EXECUTE();
|
||||
}
|
||||
JSP_MATCH(')');
|
||||
@ -1743,7 +1743,7 @@ NO_INLINE JsVar *jspeStatementFor() {
|
||||
if (!loopCond) JSP_RESTORE_EXECUTE();
|
||||
if (loopCond) {
|
||||
jslSeekToP(execInfo.lex, &forIterStart);
|
||||
if (execInfo.lex->tk != ')') jsvUnLock(jspeAssignmentExpression());
|
||||
if (execInfo.lex->tk != ')') jsvUnLock(jspeExpression());
|
||||
}
|
||||
while (!hasHadBreak && JSP_SHOULD_EXECUTE && loopCond
|
||||
#ifdef JSPARSE_MAX_LOOP_ITERATIONS
|
||||
@ -1773,7 +1773,7 @@ NO_INLINE JsVar *jspeStatementFor() {
|
||||
}
|
||||
if (JSP_SHOULD_EXECUTE && loopCond) {
|
||||
jslSeekToP(execInfo.lex, &forIterStart);
|
||||
if (execInfo.lex->tk != ')') jsvUnLock(jspeAssignmentExpression());
|
||||
if (execInfo.lex->tk != ')') jsvUnLock(jspeExpression());
|
||||
}
|
||||
}
|
||||
jslSeekToP(execInfo.lex, &forBodyEnd);
|
||||
|
||||
11
tests/test_for_loop_comma.js
Normal file
11
tests/test_for_loop_comma.js
Normal file
@ -0,0 +1,11 @@
|
||||
var sumi = 0;
|
||||
var sumj = 0;
|
||||
var i,j;
|
||||
|
||||
for(i=0,j=7;i<10;i++,j++) {
|
||||
// console.log(i,j);
|
||||
sumi+=i;
|
||||
sumj+=j;
|
||||
}
|
||||
|
||||
result = sumi==45 && sumj==115;
|
||||
Loading…
x
Reference in New Issue
Block a user