jscript: Use bytecode for int literal implementation.

oldstable
Jacek Caban 2011-11-23 12:13:46 +01:00 committed by Alexandre Julliard
parent 1c824ea606
commit b3feafab41
3 changed files with 43 additions and 1 deletions

View File

@ -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:

View File

@ -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)
{

View File

@ -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 {