Commit 5c158f1d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Use compiler to handle variable statement.

parent 2a59f016
......@@ -841,6 +841,7 @@ static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
return compile_expression_noret(ctx, expr, NULL);
}
/* ECMA-262 3rd Edition 12.1 */
static HRESULT compile_block_statement(compiler_ctx_t *ctx, statement_t *iter)
{
HRESULT hres;
......@@ -865,6 +866,28 @@ static HRESULT compile_block_statement(compiler_ctx_t *ctx, statement_t *iter)
return S_OK;
}
/* ECMA-262 3rd Edition 12.2 */
static HRESULT compile_var_statement(compiler_ctx_t *ctx, var_statement_t *stat)
{
variable_declaration_t *iter;
HRESULT hres;
for(iter = stat->variable_list; iter; iter = iter->next) {
if(!iter->expr)
continue;
hres = compile_expression(ctx, iter->expr);
if(FAILED(hres))
return hres;
hres = push_instr_bstr(ctx, OP_var_set, iter->identifier);
if(FAILED(hres))
return hres;
}
return push_instr(ctx, OP_undefined) == -1 ? E_OUTOFMEMORY : S_OK;
}
/* ECMA-262 3rd Edition 12.4 */
static HRESULT compile_expression_statement(compiler_ctx_t *ctx, expression_statement_t *stat)
{
......@@ -934,6 +957,8 @@ static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
return compile_expression_statement(ctx, (expression_statement_t*)stat);
case STAT_IF:
return compile_if_statement(ctx, (if_statement_t*)stat);
case STAT_VAR:
return compile_var_statement(ctx, (var_statement_t*)stat);
default:
return compile_interp_fallback(ctx, stat);
}
......
......@@ -688,19 +688,18 @@ static HRESULT variable_list_eval(script_ctx_t *ctx, variable_declaration_t *var
}
/* ECMA-262 3rd Edition 12.2 */
HRESULT var_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
static HRESULT interp_var_set(exec_ctx_t *ctx)
{
var_statement_t *stat = (var_statement_t*)_stat;
const BSTR name = ctx->parser->code->instrs[ctx->ip].arg1.bstr;
VARIANT *v;
HRESULT hres;
TRACE("\n");
hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
if(FAILED(hres))
return hres;
TRACE("%s\n", debugstr_w(name));
V_VT(ret) = VT_EMPTY;
return S_OK;
v = stack_pop(ctx);
hres = jsdisp_propput_name(ctx->var_disp, name, v, ctx->ei, NULL/*FIXME*/);
VariantClear(v);
return hres;
}
/* ECMA-262 3rd Edition 12.6.2 */
......
......@@ -104,6 +104,7 @@ typedef struct _func_stack {
X(ret, 0, 0,0) \
X(sub, 1, 0,0) \
X(undefined, 1, 0,0) \
X(var_set, 1, ARG_BSTR, 0) \
X(void, 1, 0,0) \
X(xor, 1, 0,0)
......@@ -398,7 +399,6 @@ typedef struct {
} try_statement_t;
HRESULT compiled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
......
......@@ -849,7 +849,7 @@ static const statement_eval_t stat_eval_table[] = {
switch_statement_eval,
throw_statement_eval,
try_statement_eval,
var_statement_eval,
compiled_statement_eval,
while_statement_eval,
with_statement_eval
};
......
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