From 6d690be9690fc2fb705da5e7c7eb71318b5cc2ce Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 14 Jan 2014 19:06:44 +0100 Subject: [PATCH] Normal for statement. --- jscompile.c | 41 ++++++++++++++++++++++++++++++++--------- jsrun.c | 4 ++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/jscompile.c b/jscompile.c index ddee021..e74b9da 100644 --- a/jscompile.c +++ b/jscompile.c @@ -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; diff --git a/jsrun.c b/jsrun.c index cfa79c4..ef8ce7d 100644 --- a/jsrun.c +++ b/jsrun.c @@ -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++]);