Jacek Caban : jscript: Use bytecode for '-' expression implementation.

Alexandre Julliard julliard at winehq.org
Fri Nov 25 10:27:32 CST 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Nov 25 12:06:05 2011 +0100

jscript: Use bytecode for '-' expression implementation.

---

 dlls/jscript/compile.c |    2 ++
 dlls/jscript/engine.c  |   34 +++++++++++++++++++++++++++++++---
 dlls/jscript/engine.h  |    2 +-
 dlls/jscript/parser.y  |    2 +-
 4 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 77391bd..12dd04f 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -240,6 +240,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_neq2);
     case EXPR_PLUS:
         return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_tonum);
+    case EXPR_SUB:
+        return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_sub);
     case EXPR_THIS:
         return push_instr(ctx, OP_this) == -1 ? E_OUTOFMEMORY : S_OK;
     case EXPR_VOID:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 87f873c..a004326 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -86,6 +86,14 @@ static HRESULT stack_push_bool(exec_ctx_t *ctx, BOOL b)
     return stack_push(ctx, &v);
 }
 
+static inline HRESULT stack_push_number(exec_ctx_t *ctx, double number)
+{
+    VARIANT v;
+
+    num_set_val(&v, number);
+    return stack_push(ctx, &v);
+}
+
 static inline VARIANT *stack_pop(exec_ctx_t *ctx)
 {
     assert(ctx->top);
@@ -98,6 +106,17 @@ static void stack_popn(exec_ctx_t *ctx, unsigned n)
         VariantClear(stack_pop(ctx));
 }
 
+static HRESULT stack_pop_number(exec_ctx_t *ctx, VARIANT *r)
+{
+    VARIANT *v;
+    HRESULT hres;
+
+    v = stack_pop(ctx);
+    hres = to_number(ctx->parser->script, v, &ctx->ei, r);
+    VariantClear(v);
+    return hres;
+}
+
 static void exprval_release(exprval_t *val)
 {
     switch(val->type) {
@@ -2297,13 +2316,22 @@ static HRESULT sub_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcep
 }
 
 /* ECMA-262 3rd Edition    11.6.2 */
-HRESULT sub_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
+HRESULT interp_sub(exec_ctx_t *ctx)
 {
-    binary_expression_t *expr = (binary_expression_t*)_expr;
+    VARIANT l, r;
+    HRESULT hres;
 
     TRACE("\n");
 
-    return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
+    hres = stack_pop_number(ctx, &r);
+    if(FAILED(hres))
+        return hres;
+
+    hres = stack_pop_number(ctx, &l);
+    if(FAILED(hres))
+        return hres;
+
+    return stack_push_number(ctx, num_val(&l)-num_val(&r));
 }
 
 /* ECMA-262 3rd Edition    11.5.1 */
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index a713e02..736fe5a 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -59,6 +59,7 @@ typedef struct _func_stack {
     X(tonum,      1, 0,0)                  \
     X(tree,       1, ARG_EXPR,   0)        \
     X(ret,        0, 0,0)                  \
+    X(sub,        1, 0,0)                  \
     X(void,       1, 0,0)
 
 typedef enum {
@@ -541,7 +542,6 @@ HRESULT binary_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,
 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;
-HRESULT sub_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT mul_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT div_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT mod_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 d8daa59..2e8c0d8 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1314,7 +1314,7 @@ static const expression_eval_t expression_eval_table[] = {
    instanceof_expression_eval,
    compiled_expression_eval,
    compiled_expression_eval,
-   sub_expression_eval,
+   compiled_expression_eval,
    mul_expression_eval,
    div_expression_eval,
    mod_expression_eval,




More information about the wine-cvs mailing list