jscript: Use bytecode for conditional expressions.
This commit is contained in:
parent
88dc54a7f7
commit
25e58de596
|
@ -193,6 +193,40 @@ static HRESULT compile_logical_expression(compiler_ctx_t *ctx, binary_expression
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ECMA-262 3rd Edition 11.12 */
|
||||||
|
static HRESULT compile_conditional_expression(compiler_ctx_t *ctx, conditional_expression_t *expr)
|
||||||
|
{
|
||||||
|
unsigned jmp_false, jmp_end;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = compile_expression(ctx, expr->expression);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
jmp_false = push_instr(ctx, OP_jmp_z);
|
||||||
|
if(jmp_false == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
hres = compile_expression(ctx, expr->true_expression);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
jmp_end = push_instr(ctx, OP_jmp);
|
||||||
|
if(jmp_end == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
instr_ptr(ctx, jmp_false)->arg1.uint = ctx->code_off;
|
||||||
|
if(push_instr(ctx, OP_pop) == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
hres = compile_expression(ctx, expr->false_expression);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
instr_ptr(ctx, jmp_end)->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;
|
||||||
|
@ -252,6 +286,8 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
|
||||||
return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_bneg);
|
return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_bneg);
|
||||||
case EXPR_COMMA:
|
case EXPR_COMMA:
|
||||||
return compile_comma_expression(ctx, (binary_expression_t*)expr);
|
return compile_comma_expression(ctx, (binary_expression_t*)expr);
|
||||||
|
case EXPR_COND:
|
||||||
|
return compile_conditional_expression(ctx, (conditional_expression_t*)expr);
|
||||||
case EXPR_EQ:
|
case EXPR_EQ:
|
||||||
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq);
|
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq);
|
||||||
case EXPR_EQEQ:
|
case EXPR_EQEQ:
|
||||||
|
|
|
@ -1435,28 +1435,6 @@ HRESULT function_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD f
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 11.12 */
|
|
||||||
HRESULT conditional_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
|
||||||
{
|
|
||||||
conditional_expression_t *expr = (conditional_expression_t*)_expr;
|
|
||||||
exprval_t exprval;
|
|
||||||
VARIANT_BOOL b;
|
|
||||||
HRESULT hres;
|
|
||||||
|
|
||||||
TRACE("\n");
|
|
||||||
|
|
||||||
hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
|
|
||||||
if(FAILED(hres))
|
|
||||||
return hres;
|
|
||||||
|
|
||||||
hres = exprval_to_boolean(ctx, &exprval, ei, &b);
|
|
||||||
exprval_release(&exprval);
|
|
||||||
if(FAILED(hres))
|
|
||||||
return hres;
|
|
||||||
|
|
||||||
return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 11.2.1 */
|
/* ECMA-262 3rd Edition 11.2.1 */
|
||||||
HRESULT array_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
HRESULT array_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
|
||||||
{
|
{
|
||||||
|
@ -3291,6 +3269,16 @@ HRESULT assign_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD
|
||||||
return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);
|
return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT interp_jmp(exec_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
const unsigned arg = ctx->parser->code->instrs[ctx->ip].arg1.uint;
|
||||||
|
|
||||||
|
TRACE("\n");
|
||||||
|
|
||||||
|
ctx->ip = arg;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static HRESULT interp_pop(exec_ctx_t *ctx)
|
static HRESULT interp_pop(exec_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
TRACE("\n");
|
TRACE("\n");
|
||||||
|
|
|
@ -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, 0, ARG_ADDR, 0) \
|
||||||
X(jmp_nz, 0, ARG_ADDR, 0) \
|
X(jmp_nz, 0, ARG_ADDR, 0) \
|
||||||
X(jmp_z, 0, ARG_ADDR, 0) \
|
X(jmp_z, 0, ARG_ADDR, 0) \
|
||||||
X(minus, 1, 0,0) \
|
X(minus, 1, 0,0) \
|
||||||
|
@ -535,7 +536,6 @@ typedef struct {
|
||||||
} property_value_expression_t;
|
} property_value_expression_t;
|
||||||
|
|
||||||
HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
||||||
HRESULT conditional_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
|
||||||
HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
||||||
HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
||||||
HRESULT new_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
HRESULT new_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -1352,7 +1352,7 @@ static const expression_eval_t expression_eval_table[] = {
|
||||||
assign_and_expression_eval,
|
assign_and_expression_eval,
|
||||||
assign_or_expression_eval,
|
assign_or_expression_eval,
|
||||||
assign_xor_expression_eval,
|
assign_xor_expression_eval,
|
||||||
conditional_expression_eval,
|
compiled_expression_eval,
|
||||||
array_expression_eval,
|
array_expression_eval,
|
||||||
member_expression_eval,
|
member_expression_eval,
|
||||||
new_expression_eval,
|
new_expression_eval,
|
||||||
|
|
Loading…
Reference in New Issue