From 96b13314eb450a98dd1360e2d98f1a46e49b3485 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 29 Nov 2011 11:09:35 +0100 Subject: [PATCH] jscript: Use bytecode for binary or implementation. --- dlls/jscript/compile.c | 2 ++ dlls/jscript/engine.c | 29 ++++++++++++++++++++++++++--- dlls/jscript/engine.h | 2 +- dlls/jscript/parser.y | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 4793fa3acb4..7520756d763 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -346,6 +346,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr) return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_add); case EXPR_BITNEG: return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_bneg); + case EXPR_BOR: + return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_or); case EXPR_COMMA: return compile_comma_expression(ctx, (binary_expression_t*)expr); case EXPR_COND: diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 1cdc4d0f362..16a3a061e10 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -94,6 +94,15 @@ static inline HRESULT stack_push_number(exec_ctx_t *ctx, double number) return stack_push(ctx, &v); } +static inline HRESULT stack_push_int(exec_ctx_t *ctx, INT n) +{ + VARIANT v; + + V_VT(&v) = VT_I4; + V_I4(&v) = n; + return stack_push(ctx, &v); +} + static inline VARIANT *stack_top(exec_ctx_t *ctx) { assert(ctx->top); @@ -129,6 +138,11 @@ static HRESULT stack_pop_number(exec_ctx_t *ctx, VARIANT *r) return hres; } +static inline HRESULT stack_pop_int(exec_ctx_t *ctx, INT *r) +{ + return to_int32(ctx->parser->script, stack_pop(ctx), &ctx->ei, r); +} + static void exprval_release(exprval_t *val) { switch(val->type) { @@ -2009,13 +2023,22 @@ static HRESULT bitor_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexc } /* ECMA-262 3rd Edition 11.10 */ -HRESULT binary_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) +static HRESULT interp_or(exec_ctx_t *ctx) { - binary_expression_t *expr = (binary_expression_t*)_expr; + INT l, r; + HRESULT hres; TRACE("\n"); - return binary_expr_eval(ctx, expr, bitor_eval, ei, ret); + hres = stack_pop_int(ctx, &r); + if(FAILED(hres)) + return hres; + + hres = stack_pop_int(ctx, &l); + if(FAILED(hres)) + return hres; + + return stack_push_int(ctx, l|r); } /* ECMA-262 3rd Edition 11.10 */ diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 5ef200204c1..6ac6d23308d 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -63,6 +63,7 @@ typedef struct _func_stack { X(neq2, 1, 0,0) \ X(new, 1, ARG_INT, 0) \ X(null, 1, 0,0) \ + X(or, 1, 0,0) \ X(pop, 1, 0,0) \ X(regexp, 1, ARG_STR, ARG_INT) \ X(str, 1, ARG_STR, 0) \ @@ -554,7 +555,6 @@ HRESULT identifier_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t* HRESULT array_literal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; -HRESULT binary_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT binary_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT binary_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT instanceof_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 36f8f198765..fecde803753 100644 --- a/dlls/jscript/parser.y +++ b/dlls/jscript/parser.y @@ -1308,7 +1308,7 @@ static const expression_eval_t expression_eval_table[] = { compiled_expression_eval, compiled_expression_eval, compiled_expression_eval, - binary_or_expression_eval, + compiled_expression_eval, binary_xor_expression_eval, binary_and_expression_eval, instanceof_expression_eval,