Jacek Caban : jscript: Use compiler for handling if statement.
Alexandre Julliard
julliard at winehq.org
Mon Dec 19 13:39:23 CST 2011
Module: wine
Branch: master
Commit: cf2fc11e318cfd165a5224a4b393dc57d72096aa
URL: http://source.winehq.org/git/wine.git/?a=commit;h=cf2fc11e318cfd165a5224a4b393dc57d72096aa
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Dec 19 14:59:51 2011 +0100
jscript: Use compiler for handling if statement.
---
dlls/jscript/compile.c | 43 +++++++++++++++++++++++++++++++++++++++++++
dlls/jscript/engine.c | 29 -----------------------------
dlls/jscript/engine.h | 1 -
dlls/jscript/parser.y | 2 +-
4 files changed, 44 insertions(+), 31 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index b46ea59..9fdce33 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -882,6 +882,47 @@ static HRESULT compile_expression_statement(compiler_ctx_t *ctx, expression_stat
return S_OK;
}
+/* ECMA-262 3rd Edition 12.5 */
+static HRESULT compile_if_statement(compiler_ctx_t *ctx, if_statement_t *stat)
+{
+ unsigned jmp_else, jmp_end;
+ HRESULT hres;
+
+ hres = compile_expression(ctx, stat->expr);
+ if(FAILED(hres))
+ return hres;
+
+ jmp_else = push_instr(ctx, OP_jmp_z);
+ if(jmp_else == -1)
+ return E_OUTOFMEMORY;
+
+ hres = compile_statement(ctx, stat->if_stat);
+ if(FAILED(hres))
+ return hres;
+
+ jmp_end = push_instr(ctx, OP_jmp);
+ if(jmp_end == -1)
+ return E_OUTOFMEMORY;
+
+ instr_ptr(ctx, jmp_else)->arg1.uint = ctx->code_off;
+
+ if(push_instr(ctx, OP_pop) == -1)
+ return E_OUTOFMEMORY;
+
+ if(stat->else_stat) {
+ hres = compile_statement(ctx, stat->else_stat);
+ if(FAILED(hres))
+ return hres;
+ }else {
+ /* FIXME: We could sometimes avoid it */
+ if(push_instr(ctx, OP_undefined) == -1)
+ return E_OUTOFMEMORY;
+ }
+
+ instr_ptr(ctx, jmp_end)->arg1.uint = ctx->code_off;
+ return S_OK;
+}
+
static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
{
switch(stat->type) {
@@ -889,6 +930,8 @@ static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
return compile_block_statement(ctx, ((block_statement_t*)stat)->stat_list);
case STAT_EXPR:
return compile_expression_statement(ctx, (expression_statement_t*)stat);
+ case STAT_IF:
+ return compile_if_statement(ctx, (if_statement_t*)stat);
default:
return compile_interp_fallback(ctx, stat);
}
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 664af86..6ca10b3 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -712,35 +712,6 @@ HRESULT empty_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t
return S_OK;
}
-/* ECMA-262 3rd Edition 12.5 */
-HRESULT if_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
-{
- if_statement_t *stat = (if_statement_t*)_stat;
- VARIANT_BOOL b;
- VARIANT v;
- HRESULT hres;
-
- TRACE("\n");
-
- hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &v);
- if(FAILED(hres))
- return hres;
-
- hres = to_boolean(&v, &b);
- VariantClear(&v);
- if(FAILED(hres))
- return hres;
-
- if(b)
- hres = stat_eval(ctx, stat->if_stat, rt, ret);
- else if(stat->else_stat)
- hres = stat_eval(ctx, stat->else_stat, rt, ret);
- else
- V_VT(ret) = VT_EMPTY;
-
- return hres;
-}
-
/* ECMA-262 3rd Edition 12.6.2 */
HRESULT while_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
{
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 804713e..ebca7db 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -400,7 +400,6 @@ typedef struct {
HRESULT compiled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
-HRESULT if_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index adbcb6e..925b12d 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -843,7 +843,7 @@ static const statement_eval_t stat_eval_table[] = {
compiled_statement_eval,
for_statement_eval,
forin_statement_eval,
- if_statement_eval,
+ compiled_statement_eval,
labelled_statement_eval,
return_statement_eval,
switch_statement_eval,
More information about the wine-cvs
mailing list