Jacek Caban : jscript: Use bytecode for pre-increment expression implementation.

Alexandre Julliard julliard at winehq.org
Thu Dec 8 13:43:38 CST 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Dec  8 12:02:08 2011 +0100

jscript: Use bytecode for pre-increment expression implementation.

---

 dlls/jscript/compile.c |   10 ++++++----
 dlls/jscript/engine.c  |   39 +++++++++++++++++++--------------------
 dlls/jscript/engine.h  |    2 +-
 dlls/jscript/parser.y  |    2 +-
 4 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 0ed6f29..c3e845e 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -292,7 +292,7 @@ static HRESULT compile_memberid_expression(compiler_ctx_t *ctx, expression_t *ex
     return hres;
 }
 
-static HRESULT compile_increment_expression(compiler_ctx_t *ctx, unary_expression_t *expr, int n)
+static HRESULT compile_increment_expression(compiler_ctx_t *ctx, unary_expression_t *expr, jsop_t op, int n)
 {
     HRESULT hres;
 
@@ -308,7 +308,7 @@ static HRESULT compile_increment_expression(compiler_ctx_t *ctx, unary_expressio
     if(FAILED(hres))
         return hres;
 
-    return push_instr_int(ctx, OP_postinc, n);
+    return push_instr_int(ctx, op, n);
 }
 
 /* ECMA-262 3rd Edition    11.14 */
@@ -648,9 +648,11 @@ static HRESULT compile_expression_noret(compiler_ctx_t *ctx, expression_t *expr,
     case EXPR_PLUS:
         return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_tonum);
     case EXPR_POSTDEC:
-        return compile_increment_expression(ctx, (unary_expression_t*)expr, -1);
+        return compile_increment_expression(ctx, (unary_expression_t*)expr, OP_postinc, -1);
     case EXPR_POSTINC:
-        return compile_increment_expression(ctx, (unary_expression_t*)expr, 1);
+        return compile_increment_expression(ctx, (unary_expression_t*)expr, OP_postinc, 1);
+    case EXPR_PREINC:
+        return compile_increment_expression(ctx, (unary_expression_t*)expr, OP_preinc, 1);
     case EXPR_SUB:
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_sub);
     case EXPR_THIS:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 102c305..d2c07f1 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -2736,37 +2736,36 @@ static HRESULT interp_postinc(exec_ctx_t *ctx)
 }
 
 /* ECMA-262 3rd Edition    11.4.4 */
-HRESULT pre_increment_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
+static HRESULT interp_preinc(exec_ctx_t *ctx)
 {
-    unary_expression_t *expr = (unary_expression_t*)_expr;
-    VARIANT val, num;
-    exprval_t exprval;
+    const int arg = ctx->parser->code->instrs[ctx->ip].arg1.lng;
+    IDispatch *obj;
+    DISPID id;
+    VARIANT v;
     HRESULT hres;
 
-    TRACE("\n");
+    TRACE("%d\n", arg);
 
-    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
-    if(FAILED(hres))
-        return hres;
+    obj = stack_pop_objid(ctx, &id);
+    if(!obj)
+        return throw_type_error(ctx->parser->script, &ctx->ei, JS_E_OBJECT_EXPECTED, NULL);
 
-    hres = exprval_value(ctx, &exprval, ei, &val);
+    hres = disp_propget(ctx->parser->script, obj, id, &v, &ctx->ei, NULL/*FIXME*/);
     if(SUCCEEDED(hres)) {
-        hres = to_number(ctx, &val, ei, &num);
-        VariantClear(&val);
-    }
+        VARIANT n;
 
-    if(SUCCEEDED(hres)) {
-        num_set_val(&val, num_val(&num)+1.0);
-        hres = put_value(ctx, &exprval, &val, ei);
+        hres = to_number(ctx->parser->script, &v, &ctx->ei, &n);
+        VariantClear(&v);
+        if(SUCCEEDED(hres)) {
+            num_set_val(&v, num_val(&n)+(double)arg);
+            hres = disp_propput(ctx->parser->script, obj, id, &v, &ctx->ei, NULL/*FIXME*/);
+        }
     }
-
-    exprval_release(&exprval);
+    IDispatch_Release(obj);
     if(FAILED(hres))
         return hres;
 
-    ret->type = EXPRVAL_VARIANT;
-    ret->u.var = val;
-    return S_OK;
+    return stack_push(ctx, &v);
 }
 
 /* ECMA-262 3rd Edition    11.4.5 */
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 7359d06..e3672a4 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -78,6 +78,7 @@ typedef struct _func_stack {
     X(or,         1, 0,0)                  \
     X(pop,        1, 0,0)                  \
     X(postinc,    1, ARG_INT,    0)        \
+    X(preinc,     1, ARG_INT,    0)        \
     X(regexp,     1, ARG_STR,    ARG_INT)  \
     X(str,        1, ARG_STR,    0)        \
     X(this,       1, 0,0)                  \
@@ -563,7 +564,6 @@ HRESULT binary_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*
 HRESULT instanceof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT delete_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT typeof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
-HRESULT pre_increment_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT pre_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT left_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT right_shift_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 07414ce..1b053a0 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1324,7 +1324,7 @@ static const expression_eval_t expression_eval_table[] = {
    compiled_expression_eval,
    compiled_expression_eval,
    compiled_expression_eval,
-   pre_increment_expression_eval,
+   compiled_expression_eval,
    pre_decrement_expression_eval,
    compiled_expression_eval,
    compiled_expression_eval,




More information about the wine-cvs mailing list