diff options
| author | fleuria <[email protected]> | 2013-11-03 12:05:48 +0800 |
|---|---|---|
| committer | fleuria <[email protected]> | 2013-11-03 12:05:48 +0800 |
| commit | 82c5b486e0d788aa7a391574c59959da2216990e (patch) | |
| tree | f5c004e9b8727bc274ce00c6f8d3c8152c53cc60 | |
| parent | a511957ec8f075d24d971987ebe2cf41ce332629 (diff) | |
| download | mruby-82c5b486e0d788aa7a391574c59959da2216990e.tar.gz mruby-82c5b486e0d788aa7a391574c59959da2216990e.zip | |
mirb: reset stack in the first command
| -rw-r--r-- | mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index b27654e0b..5156366f5 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -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); |
