Normal for statement.

This commit is contained in:
Tor Andersson
2014-01-14 19:06:44 +01:00
parent f77a6e7e8e
commit 6d690be969
2 changed files with 34 additions and 11 deletions
+32 -9
View File
@@ -332,6 +332,7 @@ static void cvarinit(JF, js_Ast *list)
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 @@ static void cstm(JF, js_Ast *stm)
}
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 @@ static void cstm(JF, js_Ast *stm)
label(J, F, end);
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_FOR:
cexp(J, F, stm->a);
emit(J, F, OP_POP);
goto for_body;
// for
case STM_FOR_VAR:
cvarinit(J, F, stm->a);
goto for_body;
for_body:
loop = here(J, F);
cexp(J, F, stm->b);
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-in
// break
// continue
case STM_RETURN:
if (stm->a)
cexp(J, F, stm->a);
@@ -613,14 +635,15 @@ static void cstm(JF, js_Ast *stm)
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);
break;
+2 -2
View File
@@ -237,8 +237,8 @@ static void runfun(js_State *J, js_Function *F, js_Object *E)
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++]);