Jacek Caban : jscript: Use bytecode for logical or expression.

Alexandre Julliard julliard at winehq.org
Mon Nov 28 14:00:07 CST 2011


Module: wine
Branch: master
Commit: 28375af386aec7c5aa01344ce0dac3124fc8bc47
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=28375af386aec7c5aa01344ce0dac3124fc8bc47

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Nov 28 12:03:57 2011 +0100

jscript: Use bytecode for logical or expression.

---

 dlls/jscript/compile.c |   24 ++++++++++++++++++++++++
 dlls/jscript/engine.c  |   44 +++++++++++++-------------------------------
 dlls/jscript/engine.h  |    7 +++++--
 dlls/jscript/parser.y  |    2 +-
 4 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 65d6861..36ecb6a 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 9e26e93..0cecd92 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 d74d57c..27083aa 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 3c953eb..7e9febc 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,




More information about the wine-cvs mailing list