summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-10-26 01:13:57 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-10-28 00:29:30 +0900
commit93f5f225772c398be6e409da3d3ef0f07ffbe1cf (patch)
tree37198a8c50baaf1a5714a581e049167073249ddc /mrbgems/mruby-compiler
parent3f9d00ded3ce987927d975f7ce70637a973de1fc (diff)
downloadmruby-93f5f225772c398be6e409da3d3ef0f07ffbe1cf.tar.gz
mruby-93f5f225772c398be6e409da3d3ef0f07ffbe1cf.zip
Heavily refactored how lexical scope links are implemented; fix #3821
Instead of `irep` links, we added a `upper` link to `struct RProc`. To make a space for the `upper` link, we moved `target_class` reference. If a `Proc` does not have `env`, `target_class` is saved in an `union` shared with `env` (if a `Proc` has env, you can tell it by `MRB_PROC_ENV_P()). Otherwise `target_class` is referenced from `env->c`. We removed links in `env` as well. This change removes 2 members from `mrb_irep` struct, thus saving 2 words per method/proc/block. This also fixes potential memory leaks due to the circular references caused by a link from `mrb_irep`.
Diffstat (limited to 'mrbgems/mruby-compiler')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c3
-rw-r--r--mrbgems/mruby-compiler/core/parse.y2
2 files changed, 4 insertions, 1 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index d9902a02e..da29077b0 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -3034,6 +3034,9 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
proc->c = NULL;
+ if (mrb->c->cibase && mrb->c->cibase->proc == proc->upper) {
+ proc->upper = NULL;
+ }
mrb->jmp = prev_jmp;
return proc;
}
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index bf9d3fe85..e5017b677 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -5825,7 +5825,7 @@ mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c)
c->keep_lv = TRUE;
}
}
- proc->target_class = target;
+ MRB_PROC_SET_TARGET_CLASS(proc, target);
if (mrb->c->ci) {
mrb->c->ci->target_class = target;
}