add internal function mrb_toplevel_run_keep() to keep stack contents; close #2326

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-05-30 15:25:58 +09:00
parent f38e53ecca
commit 6bf1ee78c8
3 changed files with 14 additions and 4 deletions
+2
View File
@@ -35,6 +35,8 @@ void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
mrb_value mrb_toplevel_run_keep(mrb_state*, struct RProc*, unsigned int);
/* AST node structure */
typedef struct mrb_ast_node {
struct mrb_ast_node *car, *cdr;
+3 -1
View File
@@ -5522,6 +5522,7 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c)
struct RClass *target = mrb->object_class;
struct RProc *proc;
mrb_value v;
unsigned int keep = 0;
if (!p) {
return mrb_undef_value();
@@ -5555,12 +5556,13 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c)
if (c->target_class) {
target = c->target_class;
}
keep = c->slen + 1;
}
proc->target_class = target;
if (mrb->c->ci) {
mrb->c->ci->target_class = target;
}
v = mrb_toplevel_run(mrb, proc);
v = mrb_toplevel_run_keep(mrb, proc, keep);
if (mrb->exc) return mrb_nil_value();
return v;
}
+9 -3
View File
@@ -2402,19 +2402,25 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
mrb_value
mrb_toplevel_run(mrb_state *mrb, struct RProc *proc)
mrb_toplevel_run_keep(mrb_state *mrb, struct RProc *proc, unsigned int stack_keep)
{
mrb_callinfo *ci;
mrb_value v;
if (!mrb->c->cibase || mrb->c->ci == mrb->c->cibase) {
return mrb_context_run(mrb, proc, mrb_top_self(mrb), 0);
return mrb_context_run(mrb, proc, mrb_top_self(mrb), stack_keep);
}
ci = cipush(mrb);
ci->acc = CI_ACC_SKIP;
ci->target_class = mrb->object_class;
v = mrb_context_run(mrb, proc, mrb_top_self(mrb), 0);
v = mrb_context_run(mrb, proc, mrb_top_self(mrb), stack_keep);
cipop(mrb);
return v;
}
mrb_value
mrb_toplevel_run(mrb_state *mrb, struct RProc *proc)
{
return mrb_toplevel_run_keep(mrb, proc, 0);
}