Module: wine Branch: master Commit: 25e58de5961303ee9a8bbd43bec2219648d21b18 URL: http://source.winehq.org/git/wine.git/?a=commit;h=25e58de5961303ee9a8bbd43be...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Nov 28 12:04:51 2011 +0100
jscript: Use bytecode for conditional expressions.
---
dlls/jscript/compile.c | 36 ++++++++++++++++++++++++++++++++++++ dlls/jscript/engine.c | 32 ++++++++++---------------------- dlls/jscript/engine.h | 2 +- dlls/jscript/parser.y | 2 +- 4 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 6abeec4..5c830d2 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -193,6 +193,40 @@ static HRESULT compile_logical_expression(compiler_ctx_t *ctx, binary_expression return S_OK; }
+/* ECMA-262 3rd Edition 11.12 */ +static HRESULT compile_conditional_expression(compiler_ctx_t *ctx, conditional_expression_t *expr) +{ + unsigned jmp_false, jmp_end; + HRESULT hres; + + hres = compile_expression(ctx, expr->expression); + if(FAILED(hres)) + return hres; + + jmp_false = push_instr(ctx, OP_jmp_z); + if(jmp_false == -1) + return E_OUTOFMEMORY; + + hres = compile_expression(ctx, expr->true_expression); + if(FAILED(hres)) + return hres; + + jmp_end = push_instr(ctx, OP_jmp); + if(jmp_end == -1) + return E_OUTOFMEMORY; + + instr_ptr(ctx, jmp_false)->arg1.uint = ctx->code_off; + if(push_instr(ctx, OP_pop) == -1) + return E_OUTOFMEMORY; + + hres = compile_expression(ctx, expr->false_expression); + if(FAILED(hres)) + return hres; + + instr_ptr(ctx, jmp_end)->arg1.uint = ctx->code_off; + return S_OK; +} + static HRESULT compile_interp_fallback(compiler_ctx_t *ctx, expression_t *expr) { unsigned instr; @@ -252,6 +286,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr) return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_bneg); case EXPR_COMMA: return compile_comma_expression(ctx, (binary_expression_t*)expr); + case EXPR_COND: + return compile_conditional_expression(ctx, (conditional_expression_t*)expr); case EXPR_EQ: return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq); case EXPR_EQEQ: diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index bf35d8a..9244eff 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -1435,28 +1435,6 @@ HRESULT function_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD f return S_OK; }
-/* ECMA-262 3rd Edition 11.12 */ -HRESULT conditional_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) -{ - conditional_expression_t *expr = (conditional_expression_t*)_expr; - exprval_t exprval; - VARIANT_BOOL b; - HRESULT hres; - - TRACE("\n"); - - hres = expr_eval(ctx, expr->expression, 0, ei, &exprval); - if(FAILED(hres)) - return hres; - - hres = exprval_to_boolean(ctx, &exprval, ei, &b); - exprval_release(&exprval); - if(FAILED(hres)) - return hres; - - return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret); -} - /* ECMA-262 3rd Edition 11.2.1 */ HRESULT array_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) { @@ -3291,6 +3269,16 @@ HRESULT assign_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret); }
+HRESULT interp_jmp(exec_ctx_t *ctx) +{ + const unsigned arg = ctx->parser->code->instrs[ctx->ip].arg1.uint; + + TRACE("\n"); + + ctx->ip = arg; + return S_OK; +} + static HRESULT interp_pop(exec_ctx_t *ctx) { TRACE("\n"); diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 5b67413..a92b942 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -50,6 +50,7 @@ typedef struct _func_stack { X(eq2, 1, 0,0) \ X(in, 1, 0,0) \ X(int, 1, ARG_INT, 0) \ + X(jmp, 0, ARG_ADDR, 0) \ X(jmp_nz, 0, ARG_ADDR, 0) \ X(jmp_z, 0, ARG_ADDR, 0) \ X(minus, 1, 0,0) \ @@ -535,7 +536,6 @@ typedef struct { } property_value_expression_t;
HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; -HRESULT conditional_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT new_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y index 08e7b33..a3c54ad 100644 --- a/dlls/jscript/parser.y +++ b/dlls/jscript/parser.y @@ -1352,7 +1352,7 @@ static const expression_eval_t expression_eval_table[] = { assign_and_expression_eval, assign_or_expression_eval, assign_xor_expression_eval, - conditional_expression_eval, + compiled_expression_eval, array_expression_eval, member_expression_eval, new_expression_eval,