Permalink
Browse files

save debugging lineno info in irep

  • Loading branch information...
1 parent 2f21cea commit 3e924e887fb2e9e2123f8002879ef81e597d08b9 @matz matz committed Aug 31, 2012
Showing with 14 additions and 6 deletions.
  1. +2 −2 include/mruby/compile.h
  2. +1 −0 include/mruby/irep.h
  3. +11 −4 src/codegen.c
View
@@ -20,7 +20,7 @@ typedef struct mrbc_context {
mrb_sym *syms;
int slen;
char *filename;
- int lineno;
+ short lineno;
int capture_errors:1;
int dump_result:1;
int no_exec:1;
@@ -33,7 +33,7 @@ const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
/* AST node structure */
typedef struct mrb_ast_node {
struct mrb_ast_node *car, *cdr;
- int lineno;
+ short lineno;
} mrb_ast_node;
/* lexer states */
View
@@ -18,6 +18,7 @@ typedef struct mrb_irep {
int nregs;
mrb_code *iseq;
+ short *lines;
mrb_value *pool;
mrb_sym *syms;
View
@@ -54,9 +54,10 @@ typedef struct scope {
struct loopinfo *loop;
int ensure_level;
char *filename;
- int lineno;
+ short lineno;
mrb_code *iseq;
+ short *lines;
int icapa;
mrb_value *pool;
@@ -144,8 +145,10 @@ genop(codegen_scope *s, mrb_code i)
if (s->pc == s->icapa) {
s->icapa *= 2;
s->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->icapa);
+ s->lines = (short*)codegen_realloc(s, s->lines, sizeof(short)*s->icapa);
}
s->iseq[s->pc] = i;
+ s->lines[s->pc] = s->lineno;
s->pc++;
}
@@ -2027,12 +2030,13 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
p->mrb = prev->mrb;
p->icapa = 1024;
- p->iseq = (mrb_code *)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa);
+ p->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa);
+ p->lines = (short*)mrb_malloc(mrb, sizeof(short)*p->icapa);
p->pcapa = 32;
- p->pool = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*p->pcapa);
+ p->pool = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value)*p->pcapa);
- p->syms = (mrb_sym *)mrb_malloc(mrb, sizeof(mrb_sym)*256);
+ p->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*256);
p->lv = lv;
p->sp += node_len(lv)+2;
@@ -2058,6 +2062,9 @@ scope_finish(codegen_scope *s, int idx)
if (s->iseq) {
irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc);
irep->ilen = s->pc;
+ if (s->lines) {
+ irep->lines = (short *)codegen_realloc(s, s->lines, sizeof(short)*s->pc);
+ }
}
if (s->pool) {
irep->pool = (mrb_value *)codegen_realloc(s, s->pool, sizeof(mrb_value)*s->plen);

0 comments on commit 3e924e8

Please sign in to comment.