jscript: Use bytecode for return statement implementation.
This commit is contained in:
parent
dd7a5301e6
commit
fc092da98e
|
@ -1258,7 +1258,7 @@ static HRESULT pop_to_stat(compiler_ctx_t *ctx, statement_ctx_t *stat_ctx)
|
|||
statement_ctx_t *iter = ctx->stat_ctx;
|
||||
unsigned stack_pop = 0;
|
||||
|
||||
while(1) {
|
||||
while(iter) {
|
||||
if(iter->using_scope && push_instr(ctx, OP_pop_scope) == -1)
|
||||
return E_OUTOFMEMORY;
|
||||
if(iter->using_except && push_instr(ctx, OP_pop_except) == -1)
|
||||
|
@ -1343,8 +1343,19 @@ static HRESULT compile_break_statement(compiler_ctx_t *ctx, branch_statement_t *
|
|||
/* ECMA-262 3rd Edition 12.9 */
|
||||
static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statement_t *stat)
|
||||
{
|
||||
stat->stat.eval = return_statement_eval;
|
||||
return compile_interp_fallback(ctx, &stat->stat);
|
||||
HRESULT hres;
|
||||
|
||||
hres = pop_to_stat(ctx, NULL);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if(stat->expr) {
|
||||
hres = compile_expression(ctx, stat->expr);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
||||
return push_instr(ctx, OP_ret) == -1 ? E_OUTOFMEMORY : S_OK;
|
||||
}
|
||||
|
||||
/* ECMA-262 3rd Edition 12.10 */
|
||||
|
@ -1672,22 +1683,6 @@ static HRESULT init_compiler(parser_ctx_t *parser)
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT compile_subscript(parser_ctx_t *parser, expression_t *expr, unsigned *ret_off)
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
hres = init_compiler(parser);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
*ret_off = parser->compiler->code_off;
|
||||
hres = compile_expression(parser->compiler, expr);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
return push_instr(parser->compiler, OP_ret) == -1 ? E_OUTOFMEMORY : S_OK;
|
||||
}
|
||||
|
||||
HRESULT compile_subscript_stat(parser_ctx_t *parser, statement_t *stat, BOOL from_eval, unsigned *ret_off)
|
||||
{
|
||||
unsigned off;
|
||||
|
|
|
@ -54,8 +54,6 @@ struct _except_frame_t {
|
|||
except_frame_t *next;
|
||||
};
|
||||
|
||||
static HRESULT expr_eval(script_ctx_t*,expression_t*,jsexcept_t*,VARIANT*);
|
||||
|
||||
static HRESULT stack_push(exec_ctx_t *ctx, VARIANT *v)
|
||||
{
|
||||
if(!ctx->stack_size) {
|
||||
|
@ -670,27 +668,6 @@ HRESULT break_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_
|
|||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
/* ECMA-262 3rd Edition 12.9 */
|
||||
HRESULT return_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
|
||||
{
|
||||
expression_statement_t *stat = (expression_statement_t*)_stat;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("\n");
|
||||
|
||||
if(stat->expr) {
|
||||
hres = expr_eval(ctx, stat->expr, &rt->ei, ret);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}else {
|
||||
V_VT(ret) = VT_EMPTY;
|
||||
}
|
||||
|
||||
TRACE("= %s\n", debugstr_variant(ret));
|
||||
rt->type = RT_RETURN;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/* ECMA-262 3rd Edition 12.10 */
|
||||
HRESULT interp_push_scope(exec_ctx_t *ctx)
|
||||
{
|
||||
|
@ -2638,53 +2615,6 @@ static HRESULT enter_bytecode(script_ctx_t *ctx, unsigned ip, return_type_t *rt,
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT expr_eval(script_ctx_t *ctx, expression_t *expr, jsexcept_t *ei, VARIANT *ret)
|
||||
{
|
||||
exec_ctx_t *exec_ctx = ctx->exec_ctx;
|
||||
unsigned prev_ip, prev_top;
|
||||
jsexcept_t *prev_ei;
|
||||
jsop_t op;
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
TRACE("\n");
|
||||
|
||||
if(expr->instr_off == -1) {
|
||||
hres = compile_subscript(ctx->exec_ctx->parser, expr, &expr->instr_off);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
||||
prev_top = exec_ctx->top;
|
||||
prev_ip = exec_ctx->ip;
|
||||
prev_ei = exec_ctx->ei;
|
||||
exec_ctx->ip = expr->instr_off;
|
||||
exec_ctx->ei = ei;
|
||||
|
||||
while(exec_ctx->ip != -1) {
|
||||
op = exec_ctx->parser->code->instrs[exec_ctx->ip].op;
|
||||
hres = op_funcs[op](exec_ctx);
|
||||
if(FAILED(hres))
|
||||
break;
|
||||
exec_ctx->ip += op_move[op];
|
||||
}
|
||||
|
||||
exec_ctx->ip = prev_ip;
|
||||
exec_ctx->ei = prev_ei;
|
||||
|
||||
if(FAILED(hres)) {
|
||||
stack_popn(exec_ctx, exec_ctx->top-prev_top);
|
||||
return hres;
|
||||
}
|
||||
|
||||
assert(exec_ctx->top == prev_top+1);
|
||||
|
||||
if(exec_ctx->top == prev_top)
|
||||
V_VT(ret) = VT_EMPTY;
|
||||
else
|
||||
*ret = *stack_pop(exec_ctx);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, BOOL from_eval,
|
||||
jsexcept_t *ei, VARIANT *retv)
|
||||
{
|
||||
|
|
|
@ -413,7 +413,6 @@ typedef struct {
|
|||
|
||||
HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||
HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||
HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
|
@ -590,5 +589,4 @@ typedef struct {
|
|||
prop_val_t *property_list;
|
||||
} property_value_expression_t;
|
||||
|
||||
HRESULT compile_subscript(parser_ctx_t*,expression_t*,unsigned*) DECLSPEC_HIDDEN;
|
||||
HRESULT compile_subscript_stat(parser_ctx_t*,statement_t*,BOOL,unsigned*) DECLSPEC_HIDDEN;
|
||||
|
|
Loading…
Reference in New Issue