ref: 6d690be9690fc2fb705da5e7c7eb71318b5cc2ce
parent: f77a6e7e8e367ed8a6360ac7a44cac28ff5ed3ee
author: Tor Andersson <[email protected]>
date: Tue Jan 14 14:06:44 EST 2014
Normal for statement.
--- a/jscompile.c
+++ b/jscompile.c
@@ -332,6 +332,7 @@
if (var->b) {
cexp(J, F, var->b);
emitstring(J, F, OP_SETVAR, var->a->string);
+ emit(J, F, OP_POP);
}
list = list->b;
}
@@ -578,6 +579,13 @@
}
break;
+ case STM_DO:
+ loop = here(J, F);
+ cstm(J, F, stm->a);
+ cexp(J, F, stm->b);
+ jumpto(J, F, OP_JTRUE, loop);
+ break;
+
case STM_WHILE:
loop = here(J, F);
cexp(J, F, stm->a);
@@ -587,16 +595,30 @@
label(J, F, end);
break;
- case STM_DO:
+ case STM_FOR:
+ cexp(J, F, stm->a);
+ emit(J, F, OP_POP);
+ goto for_body;
+
+ case STM_FOR_VAR:
+ cvarinit(J, F, stm->a);
+ goto for_body;
+
+ for_body:
loop = here(J, F);
- cstm(J, F, stm->a);
cexp(J, F, stm->b);
- jumpto(J, F, OP_JTRUE, loop);
+ end = jump(J, F, OP_JFALSE);
+ cstm(J, F, stm->d);
+ cexp(J, F, stm->c);
+ emit(J, F, OP_POP);
+ jumpto(J, F, OP_JUMP, loop);
+ label(J, F, end);
break;
-
- // for
// for-in
+ // break
+ // continue
+
case STM_RETURN:
if (stm->a)
cexp(J, F, stm->a);
@@ -613,13 +635,14 @@
break;
// switch
- // throw, try
- // label
case STM_THROW:
cexp(J, F, stm->a);
emit(J, F, OP_THROW);
break;
+
+ // try
+ // label
case STM_DEBUGGER:
emit(J, F, OP_DEBUGGER);
--- a/jsrun.c
+++ b/jsrun.c
@@ -237,8 +237,8 @@
case OP_NEWOBJECT: js_pushobject(J, js_newobject(J)); break;
case OP_NEWARRAY: js_pushobject(J, js_newobject(J)); break;
- // FUNDEC
- // VARDEC
+ case OP_FUNDEC: js_pop(J, 1); break;
+ case OP_VARDEC: pc++; break;
case OP_GETVAR:
ref = js_getproperty(J, E, ST[*pc++]);