diff options
| author | fleuria <[email protected]> | 2013-11-03 11:32:59 +0800 |
|---|---|---|
| committer | fleuria <[email protected]> | 2013-11-03 11:32:59 +0800 |
| commit | d75a907edf761b823d83aa658025de52508b8966 (patch) | |
| tree | be384155c9a34aeb4b12aba9801e707df752d30d /src/vm.c | |
| parent | d2451dfb1660c219e7ba7bc2ae4ee859040b8d84 (diff) | |
| download | mruby-d75a907edf761b823d83aa658025de52508b8966.tar.gz mruby-d75a907edf761b823d83aa658025de52508b8966.zip | |
introduce mrb_context_run()
currently there are two scnenario to call mrb_run(), the first is
calling a proc, in this case mrb should create a new environment,
discarding all the variables except args, reciever and block.
the second is calling the newly generated irep, like in mirb.
in this case, the variables should be kept after mrb_run().
so we introduce mrb_context_run() to handle this seperately.
Diffstat (limited to 'src/vm.c')
| -rw-r--r-- | src/vm.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -546,8 +546,8 @@ void mrb_gv_val_set(mrb_state *mrb, mrb_sym sym, mrb_value val); #define CALL_MAXARGS 127 -mrb_value -mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) +static mrb_value +run_proc(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep) { /* mrb_assert(mrb_proc_cfunc_p(proc)) */ mrb_irep *irep = proc->body.irep; @@ -595,7 +595,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) if (!mrb->c->stack) { stack_init(mrb); } - stack_extend(mrb, irep->nregs, mrb->c->ci->argc + 2); /* argc + 2 (receiver and block) */ + stack_extend(mrb, irep->nregs, stack_keep); mrb->c->ci->err = pc; mrb->c->ci->proc = proc; mrb->c->ci->nregs = irep->nregs + 1; @@ -2145,6 +2145,18 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) END_DISPATCH; } +mrb_value +mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) +{ + return run_proc(mrb, proc, self, mrb->c->ci->argc + 2); /* argc + 2 (receiver and block) */ +} + +mrb_value +mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self) +{ + return run_proc(mrb, proc, self, proc->body.irep->nregs); +} + void mrb_longjmp(mrb_state *mrb) { |
