jscript: Replaced OP_ident with static binding when possible.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-08-04 13:40:44 +02:00 committed by Alexandre Julliard
parent 04617ddf21
commit 983bbab531
3 changed files with 50 additions and 16 deletions

View File

@ -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); 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) static HRESULT compile_memberid_expression(compiler_ctx_t *ctx, expression_t *expr, unsigned flags)
{ {
HRESULT hres = S_OK; 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); hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_gteq);
break; break;
case EXPR_IDENT: 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; break;
case EXPR_IN: case EXPR_IN:
hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_in); hres = compile_binary_expression(ctx, (binary_expression_t*)expr, OP_in);

View File

@ -1225,6 +1225,26 @@ static HRESULT interp_identifier_ref(script_ctx_t *ctx, BSTR identifier, unsigne
return stack_push_exprval(ctx, &exprval); 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) static HRESULT interp_local_ref(script_ctx_t *ctx)
{ {
const int arg = get_op_int(ctx, 0); 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); return stack_push_exprval(ctx, &ref);
} }
static HRESULT interp_local(script_ctx_t *ctx)
{
const int arg = get_op_int(ctx, 0);
call_frame_t *frame = ctx->call_ctx;
jsval_t copy;
HRESULT hres;
TRACE("%d\n", arg);
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;
return stack_push(ctx, copy);
}
/* ECMA-262 3rd Edition 10.1.4 */ /* ECMA-262 3rd Edition 10.1.4 */
static HRESULT interp_ident(script_ctx_t *ctx) static HRESULT interp_ident(script_ctx_t *ctx)
{ {
const BSTR arg = get_op_bstr(ctx, 0); const BSTR arg = get_op_bstr(ctx, 0);
exprval_t exprval;
jsval_t v;
HRESULT hres;
TRACE("%s\n", debugstr_w(arg)); TRACE("%s\n", debugstr_w(arg));
hres = identifier_eval(ctx, arg, &exprval); return identifier_value(ctx, arg);
if(FAILED(hres))
return hres;
if(exprval.type == EXPRVAL_INVALID)
return throw_type_error(ctx, exprval.u.hres, arg);
hres = exprval_to_value(ctx, &exprval, &v);
if(FAILED(hres))
return hres;
return stack_push(ctx, v);
} }
/* ECMA-262 3rd Edition 10.1.4 */ /* ECMA-262 3rd Edition 10.1.4 */

View File

@ -48,6 +48,7 @@
X(int, 1, ARG_INT, 0) \ X(int, 1, ARG_INT, 0) \
X(jmp, 0, ARG_ADDR, 0) \ X(jmp, 0, ARG_ADDR, 0) \
X(jmp_z, 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(local_ref, 1, ARG_INT, ARG_UINT) \
X(lshift, 1, 0,0) \ X(lshift, 1, 0,0) \
X(lt, 1, 0,0) \ X(lt, 1, 0,0) \