jscript: Use compiler for handling if statement.
This commit is contained in:
parent
ccba279b89
commit
cf2fc11e31
|
@ -882,6 +882,47 @@ static HRESULT compile_expression_statement(compiler_ctx_t *ctx, expression_stat
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ECMA-262 3rd Edition 12.5 */
|
||||||
|
static HRESULT compile_if_statement(compiler_ctx_t *ctx, if_statement_t *stat)
|
||||||
|
{
|
||||||
|
unsigned jmp_else, jmp_end;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = compile_expression(ctx, stat->expr);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
jmp_else = push_instr(ctx, OP_jmp_z);
|
||||||
|
if(jmp_else == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
hres = compile_statement(ctx, stat->if_stat);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
jmp_end = push_instr(ctx, OP_jmp);
|
||||||
|
if(jmp_end == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
instr_ptr(ctx, jmp_else)->arg1.uint = ctx->code_off;
|
||||||
|
|
||||||
|
if(push_instr(ctx, OP_pop) == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
|
if(stat->else_stat) {
|
||||||
|
hres = compile_statement(ctx, stat->else_stat);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
}else {
|
||||||
|
/* FIXME: We could sometimes avoid it */
|
||||||
|
if(push_instr(ctx, OP_undefined) == -1)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
instr_ptr(ctx, jmp_end)->arg1.uint = ctx->code_off;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
|
static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
|
||||||
{
|
{
|
||||||
switch(stat->type) {
|
switch(stat->type) {
|
||||||
|
@ -889,6 +930,8 @@ static HRESULT compile_statement(compiler_ctx_t *ctx, statement_t *stat)
|
||||||
return compile_block_statement(ctx, ((block_statement_t*)stat)->stat_list);
|
return compile_block_statement(ctx, ((block_statement_t*)stat)->stat_list);
|
||||||
case STAT_EXPR:
|
case STAT_EXPR:
|
||||||
return compile_expression_statement(ctx, (expression_statement_t*)stat);
|
return compile_expression_statement(ctx, (expression_statement_t*)stat);
|
||||||
|
case STAT_IF:
|
||||||
|
return compile_if_statement(ctx, (if_statement_t*)stat);
|
||||||
default:
|
default:
|
||||||
return compile_interp_fallback(ctx, stat);
|
return compile_interp_fallback(ctx, stat);
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,35 +712,6 @@ HRESULT empty_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 12.5 */
|
|
||||||
HRESULT if_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
|
||||||
{
|
|
||||||
if_statement_t *stat = (if_statement_t*)_stat;
|
|
||||||
VARIANT_BOOL b;
|
|
||||||
VARIANT v;
|
|
||||||
HRESULT hres;
|
|
||||||
|
|
||||||
TRACE("\n");
|
|
||||||
|
|
||||||
hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &v);
|
|
||||||
if(FAILED(hres))
|
|
||||||
return hres;
|
|
||||||
|
|
||||||
hres = to_boolean(&v, &b);
|
|
||||||
VariantClear(&v);
|
|
||||||
if(FAILED(hres))
|
|
||||||
return hres;
|
|
||||||
|
|
||||||
if(b)
|
|
||||||
hres = stat_eval(ctx, stat->if_stat, rt, ret);
|
|
||||||
else if(stat->else_stat)
|
|
||||||
hres = stat_eval(ctx, stat->else_stat, rt, ret);
|
|
||||||
else
|
|
||||||
V_VT(ret) = VT_EMPTY;
|
|
||||||
|
|
||||||
return hres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 12.6.2 */
|
/* ECMA-262 3rd Edition 12.6.2 */
|
||||||
HRESULT while_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
HRESULT while_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
||||||
{
|
{
|
||||||
|
|
|
@ -400,7 +400,6 @@ typedef struct {
|
||||||
HRESULT compiled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
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 var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||||
HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||||
HRESULT if_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 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 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;
|
HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -843,7 +843,7 @@ static const statement_eval_t stat_eval_table[] = {
|
||||||
compiled_statement_eval,
|
compiled_statement_eval,
|
||||||
for_statement_eval,
|
for_statement_eval,
|
||||||
forin_statement_eval,
|
forin_statement_eval,
|
||||||
if_statement_eval,
|
compiled_statement_eval,
|
||||||
labelled_statement_eval,
|
labelled_statement_eval,
|
||||||
return_statement_eval,
|
return_statement_eval,
|
||||||
switch_statement_eval,
|
switch_statement_eval,
|
||||||
|
|
Loading…
Reference in New Issue