diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2012-12-07 15:57:40 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2012-12-07 15:57:40 +0900 |
| commit | f4867743524c37c14acdfb93caa874818cc6c101 (patch) | |
| tree | df49cf6267d121200ba10ff08a3c64062c60547a /src/codegen.c | |
| parent | 40daee12cfbf6dac4421f47c9c953788985fe238 (diff) | |
| download | mruby-f4867743524c37c14acdfb93caa874818cc6c101.tar.gz mruby-f4867743524c37c14acdfb93caa874818cc6c101.zip | |
refactor and move irep malloc away to mrb_add_irep()
Diffstat (limited to 'src/codegen.c')
| -rw-r--r-- | src/codegen.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/codegen.c b/src/codegen.c index a6c94d871..c9225e91e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -2055,8 +2055,9 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv) static const codegen_scope codegen_scope_zero = { 0 }; mrb_pool *pool = mrb_pool_open(mrb); codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope)); - if (!p) return 0; + mrb_irep *irep; + if (!p) return 0; *p = codegen_scope_zero; p->mrb = mrb; p->mpool = pool; @@ -2079,11 +2080,9 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv) p->nlocals = p->sp; p->ai = mrb->arena_idx; - //because of a potential bad memory access in case of gc let's allocate the irep right now - mrb_add_irep(mrb, mrb->irep_len); - mrb->irep[mrb->irep_len] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); - mrb->irep[mrb->irep_len]->plen = 0; - p->idx = mrb->irep_len++; + irep = mrb_add_irep(mrb); + p->idx = irep->idx; + p->filename = prev->filename; if (p->filename) { p->lines = (short*)mrb_malloc(mrb, sizeof(short)*p->icapa); @@ -2097,13 +2096,8 @@ scope_finish(codegen_scope *s, int idx) mrb_state *mrb = s->mrb; mrb_irep *irep; - //Comment out these instructions already done in scope_new - //mrb_add_irep(mrb, idx); - //irep = mrb->irep[idx] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); irep = mrb->irep[idx]; - irep->flags = 0; - irep->idx = idx; if (s->iseq) { irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc); irep->ilen = s->pc; |
