diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 65d68610664..36ecb6a1da4 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -171,6 +171,28 @@ static HRESULT compile_comma_expression(compiler_ctx_t *ctx, binary_expression_t return compile_expression(ctx, expr->expression2); } +/* ECMA-262 3rd Edition 11.11 */ +static HRESULT compile_logical_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op) +{ + unsigned instr; + HRESULT hres; + + hres = compile_expression(ctx, expr->expression1); + if(FAILED(hres)) + return hres; + + instr = push_instr(ctx, op); + if(instr == -1) + return E_OUTOFMEMORY; + + hres = compile_expression(ctx, expr->expression2); + if(FAILED(hres)) + return hres; + + instr_ptr(ctx, instr)->arg1.uint = ctx->code_off; + return S_OK; +} + static HRESULT compile_interp_fallback(compiler_ctx_t *ctx, expression_t *expr) { unsigned instr; @@ -244,6 +266,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr) return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_neq); case EXPR_NOTEQEQ: return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_neq2); + case EXPR_OR: + return compile_logical_expression(ctx, (binary_expression_t*)expr, OP_jmp_nz); case EXPR_PLUS: return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_tonum); case EXPR_SUB: diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 9e26e934539..0cecd926073 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -94,6 +94,11 @@ static inline HRESULT stack_push_number(exec_ctx_t *ctx, double number) return stack_push(ctx, &v); } +static inline VARIANT *stack_top(exec_ctx_t *ctx) +{ + return ctx->stack + ctx->top-1; +} + static inline VARIANT *stack_pop(exec_ctx_t *ctx) { assert(ctx->top); @@ -1930,47 +1935,24 @@ HRESULT property_value_expression_eval(script_ctx_t *ctx, expression_t *_expr, D } /* ECMA-262 3rd Edition 11.11 */ -HRESULT logical_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) +HRESULT interp_jmp_nz(exec_ctx_t *ctx) { - binary_expression_t *expr = (binary_expression_t*)_expr; - exprval_t exprval; + const unsigned arg = ctx->parser->code->instrs[ctx->ip].arg1.uint; VARIANT_BOOL b; - VARIANT val; HRESULT hres; TRACE("\n"); - hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval); + hres = to_boolean(stack_top(ctx), &b); if(FAILED(hres)) return hres; - hres = exprval_to_value(ctx, &exprval, ei, &val); - exprval_release(&exprval); - if(FAILED(hres)) - return hres; - - hres = to_boolean(&val, &b); - if(SUCCEEDED(hres) && b) { - ret->type = EXPRVAL_VARIANT; - ret->u.var = val; - return S_OK; + if(b) { + ctx->ip = arg; + }else { + stack_popn(ctx, 1); + ctx->ip++; } - - VariantClear(&val); - if(FAILED(hres)) - return hres; - - hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval); - if(FAILED(hres)) - return hres; - - hres = exprval_to_value(ctx, &exprval, ei, &val); - exprval_release(&exprval); - if(FAILED(hres)) - return hres; - - ret->type = EXPRVAL_VARIANT; - ret->u.var = val; return S_OK; } diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index d74d57c426f..27083aa83f6 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_nz, 0, ARG_ADDR, 0) \ X(minus, 1, 0,0) \ X(neg, 1, 0,0) \ X(neq, 1, 0,0) \ @@ -77,12 +78,15 @@ typedef union { double *dbl; LONG lng; WCHAR *str; + unsigned uint; } instr_arg_t; typedef enum { ARG_NONE = 0, + ARG_ADDR, ARG_EXPR, - ARG_INT + ARG_INT, + ARG_STR } instr_arg_type_t; typedef struct { @@ -539,7 +543,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 logical_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN; HRESULT logical_and_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; diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y index 3c953ebe3a4..7e9febc5e0d 100644 --- a/dlls/jscript/parser.y +++ b/dlls/jscript/parser.y @@ -1306,7 +1306,7 @@ static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *ide static const expression_eval_t expression_eval_table[] = { compiled_expression_eval, - logical_or_expression_eval, + compiled_expression_eval, logical_and_expression_eval, binary_or_expression_eval, binary_xor_expression_eval,