mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mirb: reset stack in the first command
This commit is contained in:
@@ -255,6 +255,9 @@ main(int argc, char **argv)
|
||||
int n;
|
||||
int code_block_open = FALSE;
|
||||
int ai;
|
||||
struct RProc *proc;
|
||||
int first_command = 1;
|
||||
unsigned int nregs;
|
||||
|
||||
/* new interpreter instance */
|
||||
mrb = mrb_open();
|
||||
@@ -363,11 +366,14 @@ main(int argc, char **argv)
|
||||
/* generate bytecode */
|
||||
n = mrb_generate_code(mrb, parser);
|
||||
|
||||
/* pass a proc for evaulation */
|
||||
proc = mrb_proc_new(mrb, mrb->irep[n]);
|
||||
nregs = first_command ? 0: proc->body.irep->nregs;
|
||||
/* evaluate the bytecode */
|
||||
result = mrb_context_run(mrb,
|
||||
/* pass a proc for evaulation */
|
||||
mrb_proc_new(mrb, mrb->irep[n]),
|
||||
mrb_top_self(mrb), 0);
|
||||
proc,
|
||||
mrb_top_self(mrb),
|
||||
nregs);
|
||||
/* did an exception occur? */
|
||||
if (mrb->exc) {
|
||||
p(mrb, mrb_obj_value(mrb->exc), 0);
|
||||
@@ -387,6 +393,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
mrb_parser_free(parser);
|
||||
cxt->lineno++;
|
||||
first_command = 0;
|
||||
}
|
||||
mrbc_context_free(mrb, cxt);
|
||||
mrb_close(mrb);
|
||||
|
||||
Reference in New Issue
Block a user