Handles exceptions from code generation phase; fix
MODIFY
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -236,7 +236,10 @@ main(int argc, char **argv)
mrb_gc_arena_restore(mrb, ai);
mrbc_context_free(mrb, c);
if (mrb->exc) {
- if (!mrb_undef_p(v)) {
+ if (mrb_undef_p(v)) {
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
+ }
+ else {
mrb_print_error(mrb);
}
n = -1;

MODIFY
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
@@ -2993,6 +2993,7 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
{
codegen_scope *scope = scope_new(mrb, 0, 0);
struct RProc *proc;
+ struct mrb_jmpbuf *prev_jmp = mrb->jmp;
if (!scope) {
return NULL;
@@ -3003,17 +3004,20 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
scope->filename_index = p->current_filename_index;
MRB_TRY(&scope->jmp) {
+ mrb->jmp = &scope->jmp;
/* prepare irep */
codegen(scope, p->tree, NOVAL);
proc = mrb_proc_new(mrb, scope->irep);
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
proc->c = NULL;
+ mrb->jmp = prev_jmp;
return proc;
}
MRB_CATCH(&scope->jmp) {
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
+ mrb->jmp = prev_jmp;
return NULL;
}
MRB_END_EXC(&scope->jmp);

MODIFY
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
@@ -5579,7 +5579,6 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
}
MRB_CATCH(p->mrb->jmp) {
p->nerr++;
- mrb_p(p->mrb, mrb_obj_value(p->mrb->exc));
}
MRB_END_EXC(p->mrb->jmp);
p->mrb->jmp = 0;
@@ -5789,7 +5788,9 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
return mrb_undef_value();
}
else {
+ if (mrb->exc == NULL) {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error"));
+ }
mrb_parser_free(p);
return mrb_undef_value();
}
@@ -5797,7 +5798,9 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
proc = mrb_generate_code(mrb, p);
mrb_parser_free(p);
if (proc == NULL) {
+ if (mrb->exc == NULL) {
mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error"));
+ }
return mrb_undef_value();
}
if (c) {

Handles exceptions from code generation phase; fix #3695