Commit 983bbab5 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Replaced OP_ident with static binding when possible.

parent 04617ddf
......@@ -434,6 +434,14 @@ static HRESULT emit_identifier_ref(compiler_ctx_t *ctx, const WCHAR *identifier,
return push_instr_bstr_uint(ctx, OP_identid, identifier, flags);
}
static HRESULT emit_identifier(compiler_ctx_t *ctx, const WCHAR *identifier)
{
int local_ref;
if(bind_local(ctx, identifier, &local_ref))
return push_instr_int(ctx, OP_local, local_ref);
return push_instr_bstr(ctx, OP_ident, identifier);
}
static HRESULT compile_memberid_expression(compiler_ctx_t *ctx, expression_t *expr, unsigned flags)
{
HRESULT hres = S_OK;
......@@ -994,7 +1002,7 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr, BOOL
hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_gteq);
break;
case EXPR_IDENT:
hres = push_instr_bstr(ctx, OP_ident, ((identifier_expression_t*)expr)->identifier);
hres = emit_identifier(ctx, ((identifier_expression_t*)expr)->identifier);
break;
case EXPR_IN:
hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_in);
......
......@@ -1225,6 +1225,26 @@ static HRESULT interp_identifier_ref(script_ctx_t *ctx, BSTR identifier, unsigne
return stack_push_exprval(ctx, &exprval);
}
static HRESULT identifier_value(script_ctx_t *ctx, BSTR identifier)
{
exprval_t exprval;
jsval_t v;
HRESULT hres;
hres = identifier_eval(ctx, identifier, &exprval);
if(FAILED(hres))
return hres;
if(exprval.type == EXPRVAL_INVALID)
return throw_type_error(ctx, exprval.u.hres, identifier);
hres = exprval_to_value(ctx, &exprval, &v);
if(FAILED(hres))
return hres;
return stack_push(ctx, v);
}
static HRESULT interp_local_ref(script_ctx_t *ctx)
{
const int arg = get_op_int(ctx, 0);
......@@ -1242,28 +1262,33 @@ static HRESULT interp_local_ref(script_ctx_t *ctx)
return stack_push_exprval(ctx, &ref);
}
/* ECMA-262 3rd Edition 10.1.4 */
static HRESULT interp_ident(script_ctx_t *ctx)
static HRESULT interp_local(script_ctx_t *ctx)
{
const BSTR arg = get_op_bstr(ctx, 0);
exprval_t exprval;
jsval_t v;
const int arg = get_op_int(ctx, 0);
call_frame_t *frame = ctx->call_ctx;
jsval_t copy;
HRESULT hres;
TRACE("%s\n", debugstr_w(arg));
TRACE("%d\n", arg);
hres = identifier_eval(ctx, arg, &exprval);
if(!frame->base_scope || !frame->base_scope->frame)
return identifier_value(ctx, local_name(frame, arg));
hres = jsval_copy(ctx->stack[local_off(frame, arg)], &copy);
if(FAILED(hres))
return hres;
if(exprval.type == EXPRVAL_INVALID)
return throw_type_error(ctx, exprval.u.hres, arg);
return stack_push(ctx, copy);
}
hres = exprval_to_value(ctx, &exprval, &v);
if(FAILED(hres))
return hres;
/* ECMA-262 3rd Edition 10.1.4 */
static HRESULT interp_ident(script_ctx_t *ctx)
{
const BSTR arg = get_op_bstr(ctx, 0);
return stack_push(ctx, v);
TRACE("%s\n", debugstr_w(arg));
return identifier_value(ctx, arg);
}
/* ECMA-262 3rd Edition 10.1.4 */
......
......@@ -48,6 +48,7 @@
X(int, 1, ARG_INT, 0) \
X(jmp, 0, ARG_ADDR, 0) \
X(jmp_z, 0, ARG_ADDR, 0) \
X(local, 1, ARG_INT, 0) \
X(local_ref, 1, ARG_INT, ARG_UINT) \
X(lshift, 1, 0,0) \
X(lt, 1, 0,0) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment