diff options
| -rw-r--r-- | mrbgems/mruby-bin-mruby/bintest/mruby.rb | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 13 | ||||
| -rw-r--r-- | mrbgems/mruby-rational/src/rational.c | 2 | ||||
| -rw-r--r-- | src/dump.c | 77 | ||||
| -rw-r--r-- | src/vm.c | 2 |
5 files changed, 88 insertions, 8 deletions
diff --git a/mrbgems/mruby-bin-mruby/bintest/mruby.rb b/mrbgems/mruby-bin-mruby/bintest/mruby.rb index 35a108a9d..a1952ca6d 100644 --- a/mrbgems/mruby-bin-mruby/bintest/mruby.rb +++ b/mrbgems/mruby-bin-mruby/bintest/mruby.rb @@ -160,7 +160,7 @@ end assert('codegen error') do code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end" - assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code]) + assert_mruby("", /\A.*\n\z/, false, ["-e", code]) end assert('top level local variables are in file scope') do diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 857496f00..a17dbf972 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -141,10 +141,10 @@ codegen_error(codegen_scope *s, const char *message) #ifndef MRB_NO_STDIO if (s->filename_sym && s->lineno) { const char *filename = mrb_sym_name_len(s->mrb, s->filename_sym, NULL); - fprintf(stderr, "codegen error:%s:%d: %s\n", filename, s->lineno, message); + fprintf(stderr, "%s:%d: %s\n", filename, s->lineno, message); } else { - fprintf(stderr, "codegen error: %s\n", message); + fprintf(stderr, "%s\n", message); } #endif MRB_THROW(&s->jmp); @@ -2321,7 +2321,9 @@ codegen(codegen_scope *s, node *tree, int val) s2 = s2->prev; if (!s2) break; } - if (s2) ainfo = s2->ainfo; + if (s2 && s2->ainfo > 0) { + ainfo = s2->ainfo; + } genop_2S(s, OP_ARGARY, cursp(), (ainfo<<4)|(lv & 0xf)); push(); push(); pop(); /* ARGARY pushes two values */ if (tree && tree->cdr) { @@ -2361,7 +2363,10 @@ codegen(codegen_scope *s, node *tree, int val) s2 = s2->prev; if (!s2) break; } - if (s2) ainfo = s2->ainfo; + if (s2) { + ainfo = s2->ainfo; + if (ainfo < 0) codegen_error(s, "invalid yield (SyntaxError)"); + } push(); if (tree) { n = gen_values(s, tree, VAL, 0); diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 1d53afb5c..b12e7cf0a 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -641,7 +641,7 @@ mrb_rational_div(mrb_state *mrb, mrb_value x) #ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: { - mrb_float z = mrb_div_flo(p1->numerator, mrb_to_flo(mrb, y)); + mrb_float z = mrb_div_flo((mrb_float)p1->numerator, mrb_to_flo(mrb, y)); return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator)); } #else diff --git a/src/dump.c b/src/dump.c index 0822b2fac..74d52d689 100644 --- a/src/dump.c +++ b/src/dump.c @@ -1162,11 +1162,70 @@ dump_syms(mrb_state *mrb, const char *name, const char *key, int n, int syms_len return MRB_DUMP_OK; } +//Handle the simple/common case of debug_info: +// - 1 file associated with a single irep +// - mrb_debug_line_ary format only +static int +simple_debug_info(mrb_irep_debug_info *info) +{ + if (!info || + info->flen != 1 || + info->files[0]->line_type != mrb_debug_line_ary) { + return 0; + } + return 1; +} + +//Adds debug information to c-structs and +//adds filenames in init_syms_code block +static int +dump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, + mrb_value init_syms_code, FILE *fp) +{ + char buffer[256]; + const char *filename; + mrb_int file_len; + int len, i; + + if (!simple_debug_info(info)) + return MRB_DUMP_INVALID_IREP; + + len = info->files[0]->line_entry_count; + + filename = mrb_sym_name_len(mrb, info->files[0]->filename_sym, &file_len); + snprintf(buffer, sizeof(buffer), " %s_debug_file_%d.filename_sym = mrb_intern_lit(mrb,\"", + name, n); + mrb_str_cat_cstr(mrb, init_syms_code, buffer); + mrb_str_cat_cstr(mrb, init_syms_code, filename); + mrb_str_cat_cstr(mrb, init_syms_code, "\");\n"); + + fprintf(fp, "static uint16_t %s_debug_lines_%d[%d] = {", name, n, len); + for (i=0; i<len; i++) { + if (i%10 == 0) fputs("\n", fp); + fprintf(fp, "0x%04x,", info->files[0]->lines.ary[i]); + } + fputs("};\n", fp); + + fprintf(fp, "static mrb_irep_debug_info_file %s_debug_file_%d = {\n", name, n); + fprintf(fp, "%d, %d, %d, 0, {%s_debug_lines_%d}};\n", + info->files[0]->start_pos, + info->files[0]->filename_sym, + info->files[0]->line_entry_count, + name,n); + fprintf(fp, "static mrb_irep_debug_info_file *%s_debug_file_%d_ = &%s_debug_file_%d;\n", name, n, name, n); + + fprintf(fp, "static mrb_irep_debug_info %s_debug_%d = {\n", name, n); + fprintf(fp, "%d, %d, &%s_debug_file_%d_};\n", info->pc_count, info->flen, name, n); + + return MRB_DUMP_OK; +} + static int dump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, const char *name, int n, mrb_value init_syms_code, int *mp) { int i, len; int max = *mp; + int debug_available = 0; /* dump reps */ if (irep->reps) { @@ -1207,6 +1266,15 @@ dump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, if (irep->lv) { dump_syms(mrb, name, "lv", n, irep->nlocals-1, irep->lv, init_syms_code, fp); } + /* dump debug */ + if (flags & MRB_DUMP_DEBUG_INFO) { + if(dump_debug(mrb, name, n, irep->debug_info, + init_syms_code, fp) == MRB_DUMP_OK) { + debug_available = 1; + } + } + + /* dump irep */ fprintf(fp, "static const mrb_irep %s_irep_%d = {\n", name, n); fprintf(fp, " %d,%d,%d,\n", irep->nlocals, irep->nregs, irep->clen); @@ -1235,7 +1303,12 @@ dump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp, else { fputs( " NULL,\t\t\t\t\t/* lv */\n", fp); } - fputs( " NULL,\t\t\t\t\t/* debug_info */\n", fp); + if(debug_available) { + fprintf(fp, " &%s_debug_%d,\n", name, n); + } + else { + fputs(" NULL,\t\t\t\t\t/* debug_info */\n", fp); + } fprintf(fp, " %d,%d,%d,%d,0\n};\n", irep->ilen, irep->plen, irep->slen, irep->rlen); return MRB_DUMP_OK; @@ -1248,6 +1321,8 @@ mrb_dump_irep_cstruct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE return MRB_DUMP_INVALID_ARGUMENT; } if (fprintf(fp, "#include <mruby.h>\n" + "#include <mruby/irep.h>\n" + "#include <mruby/debug.h>\n" "#include <mruby/proc.h>\n" "#include <mruby/presym.h>\n" "\n") < 0) { @@ -547,7 +547,7 @@ mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p, mrb_func_t posthook) { mrb_callinfo *ci = mrb->c->ci; - mrb_int keep, nregs; + int keep, nregs; ci->stack[0] = self; mrb_vm_ci_proc_set(ci, p); |
