Jacek Caban : jscript: Use bytecode for int literal implementation.

Alexandre Julliard julliard at winehq.org
Wed Nov 23 13:40:05 CST 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Nov 23 12:13:46 2011 +0100

jscript: Use bytecode for int literal implementation.

---

 dlls/jscript/compile.c |   26 ++++++++++++++++++++++++++
 dlls/jscript/engine.c  |   13 +++++++++++++
 dlls/jscript/engine.h  |    5 ++++-
 3 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index e36dcbe..780e6b5 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -66,6 +66,18 @@ static inline instr_t *instr_ptr(compiler_ctx_t *ctx, unsigned off)
     return ctx->code->instrs + off;
 }
 
+static HRESULT push_instr_int(compiler_ctx_t *ctx, jsop_t op, LONG arg)
+{
+    unsigned instr;
+
+    instr = push_instr(ctx, op);
+    if(instr == -1)
+        return E_OUTOFMEMORY;
+
+    instr_ptr(ctx, instr)->arg1.lng = arg;
+    return S_OK;
+}
+
 static HRESULT compile_binary_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
 {
     HRESULT hres;
@@ -104,6 +116,18 @@ static HRESULT compile_interp_fallback(compiler_ctx_t *ctx, expression_t *expr)
     return S_OK;
 }
 
+static HRESULT compile_literal(compiler_ctx_t *ctx, literal_expression_t *expr)
+{
+    literal_t *literal = expr->literal;
+
+    switch(literal->type) {
+    case LT_INT:
+        return push_instr_int(ctx, OP_int, literal->u.lval);
+    default:
+        return compile_interp_fallback(ctx, &expr->expr);
+    }
+}
+
 static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
 {
     switch(expr->type) {
@@ -115,6 +139,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq2);
     case EXPR_IN:
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_in);
+    case EXPR_LITERAL:
+        return compile_literal(ctx, (literal_expression_t*)expr);
     case EXPR_LOGNEG:
         return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_neg);
     case EXPR_NOTEQEQ:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index c6b9eef..792ba13 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -1724,6 +1724,19 @@ HRESULT identifier_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD
     return hres;
 }
 
+/* ECMA-262 3rd Edition    7.8.3 */
+HRESULT interp_int(exec_ctx_t *ctx)
+{
+    const LONG arg = ctx->parser->code->instrs[ctx->ip].arg1.lng;
+    VARIANT v;
+
+    TRACE("%d\n", arg);
+
+    V_VT(&v) = VT_I4;
+    V_I4(&v) = arg;
+    return stack_push(ctx, &v);
+}
+
 /* ECMA-262 3rd Edition    7.8 */
 HRESULT literal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
 {
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index e5e316f..c210bb7 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -46,6 +46,7 @@ typedef struct _func_stack {
     X(bneg, 1, 0)                                 \
     X(eq2, 1, 0)                                  \
     X(in, 1, 0)                                   \
+    X(int, 1, ARG_INT)                            \
     X(neg, 1, 0)                                  \
     X(neq2, 1, 0)                                 \
     X(tonum, 1, 0)                                \
@@ -61,11 +62,13 @@ OP_LIST
 
 typedef union {
     expression_t *expr;
+    LONG lng;
 } instr_arg_t;
 
 typedef enum {
     ARG_NONE = 0,
-    ARG_EXPR
+    ARG_EXPR,
+    ARG_INT
 } instr_arg_type_t;
 
 typedef struct {




More information about the wine-cvs mailing list