Jacek Caban : jscript: Use compiler to handle variable statement.
Alexandre Julliard
julliard at winehq.org
Tue Dec 20 13:43:25 CST 2011
Module: wine
Branch: master
Commit: 5c158f1df69a9eb8c5694bef0ae667fa9b6645a4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5c158f1df69a9eb8c5694bef0ae667fa9b6645a4
Author: Jacek Caban <jacek at codeweavers.com>
Date: Tue Dec 20 11:45:37 2011 +0100
jscript: Use compiler to handle variable statement.
---
dlls/jscript/compile.c | 25 +++++++++++++++++++++++++
dlls/jscript/engine.c | 17 ++++++++---------
dlls/jscript/engine.h | 2 +-
dlls/jscript/parser.y | 2 +-
4 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 09384bc..5bfbb09 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -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);
}
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 2dc1b29..2663833 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -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 */
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 0fae5fb..ebcfa45 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -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;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 085b819..3445476 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -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
};
More information about the wine-cvs
mailing list