mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
@@ -261,6 +261,7 @@ void mrb_close(mrb_state*);
|
||||
|
||||
mrb_value mrb_top_self(mrb_state *);
|
||||
mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
|
||||
mrb_value mrb_context_run(mrb_state*, struct RProc*, mrb_value);
|
||||
|
||||
void mrb_p(mrb_state*, mrb_value);
|
||||
mrb_int mrb_obj_id(mrb_value obj);
|
||||
|
||||
@@ -364,7 +364,7 @@ main(int argc, char **argv)
|
||||
n = mrb_generate_code(mrb, parser);
|
||||
|
||||
/* evaluate the bytecode */
|
||||
result = mrb_run(mrb,
|
||||
result = mrb_context_run(mrb,
|
||||
/* pass a proc for evaulation */
|
||||
mrb_proc_new(mrb, mrb->irep[n]),
|
||||
mrb_top_self(mrb));
|
||||
|
||||
@@ -203,7 +203,7 @@ main(int argc, char **argv)
|
||||
fprintf(stderr, "failed to load mrb file: %s\n", args.cmdline);
|
||||
}
|
||||
else if (!args.check_syntax) {
|
||||
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
mrb_context_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
n = 0;
|
||||
if (mrb->exc) {
|
||||
mrb_print_error(mrb);
|
||||
|
||||
+2
-2
@@ -510,7 +510,7 @@ mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
|
||||
irep_error(mrb, n);
|
||||
return mrb_nil_value();
|
||||
}
|
||||
return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
return mrb_context_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_STDIO
|
||||
@@ -760,6 +760,6 @@ mrb_load_irep_file(mrb_state *mrb, FILE* fp)
|
||||
irep_error(mrb, n);
|
||||
return mrb_nil_value();
|
||||
}
|
||||
return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
return mrb_context_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
|
||||
}
|
||||
#endif /* ENABLE_STDIO */
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user