jscript: Use bytecode for logical or expression.

This commit is contained in:
Jacek Caban 2011-11-28 12:03:57 +01:00 committed by Alexandre Julliard
parent 7d5861f6d8
commit 28375af386
4 changed files with 43 additions and 34 deletions

View File

@ -171,6 +171,28 @@ static HRESULT compile_comma_expression(compiler_ctx_t *ctx, binary_expression_t
return compile_expression(ctx, expr->expression2); 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) static HRESULT compile_interp_fallback(compiler_ctx_t *ctx, expression_t *expr)
{ {
unsigned instr; 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); return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_neq);
case EXPR_NOTEQEQ: case EXPR_NOTEQEQ:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_neq2); 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: case EXPR_PLUS:
return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_tonum); return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_tonum);
case EXPR_SUB: case EXPR_SUB:

View File

@ -94,6 +94,11 @@ static inline HRESULT stack_push_number(exec_ctx_t *ctx, double number)
return stack_push(ctx, &v); 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) static inline VARIANT *stack_pop(exec_ctx_t *ctx)
{ {
assert(ctx->top); 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 */ /* 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; const unsigned arg = ctx->parser->code->instrs[ctx->ip].arg1.uint;
exprval_t exprval;
VARIANT_BOOL b; VARIANT_BOOL b;
VARIANT val;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval); hres = to_boolean(stack_top(ctx), &b);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = exprval_to_value(ctx, &exprval, ei, &val); if(b) {
exprval_release(&exprval); ctx->ip = arg;
if(FAILED(hres)) }else {
return hres; stack_popn(ctx, 1);
ctx->ip++;
hres = to_boolean(&val, &b);
if(SUCCEEDED(hres) && b) {
ret->type = EXPRVAL_VARIANT;
ret->u.var = val;
return S_OK;
} }
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; return S_OK;
} }

View File

@ -50,6 +50,7 @@ typedef struct _func_stack {
X(eq2, 1, 0,0) \ X(eq2, 1, 0,0) \
X(in, 1, 0,0) \ X(in, 1, 0,0) \
X(int, 1, ARG_INT, 0) \ X(int, 1, ARG_INT, 0) \
X(jmp_nz, 0, ARG_ADDR, 0) \
X(minus, 1, 0,0) \ X(minus, 1, 0,0) \
X(neg, 1, 0,0) \ X(neg, 1, 0,0) \
X(neq, 1, 0,0) \ X(neq, 1, 0,0) \
@ -77,12 +78,15 @@ typedef union {
double *dbl; double *dbl;
LONG lng; LONG lng;
WCHAR *str; WCHAR *str;
unsigned uint;
} instr_arg_t; } instr_arg_t;
typedef enum { typedef enum {
ARG_NONE = 0, ARG_NONE = 0,
ARG_ADDR,
ARG_EXPR, ARG_EXPR,
ARG_INT ARG_INT,
ARG_STR
} instr_arg_type_t; } instr_arg_type_t;
typedef struct { 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 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 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 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_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; HRESULT binary_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;

View File

@ -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[] = { static const expression_eval_t expression_eval_table[] = {
compiled_expression_eval, compiled_expression_eval,
logical_or_expression_eval, compiled_expression_eval,
logical_and_expression_eval, logical_and_expression_eval,
binary_or_expression_eval, binary_or_expression_eval,
binary_xor_expression_eval, binary_xor_expression_eval,