From f85906b67920c0e69599c6e59d843274aef152be Mon Sep 17 00:00:00 2001 From: dearblue Date: Thu, 21 May 2020 21:27:51 +0900 Subject: Remove `patch_irep()` in `mruby-eval` - It can now deal with operands in the range of `OP_EXT*`. - It can now call the same method as the variable name without arguments. ```ruby def a "Safe!" end a = "Auto!" eval "a()" # call method `a` ``` --- mrbgems/mruby-compiler/core/parse.y | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mrbgems/mruby-compiler/core/parse.y') diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 7280390a7..123c6c0c2 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -265,6 +265,7 @@ local_unnest(parser_state *p) static mrb_bool local_var_p(parser_state *p, mrb_sym sym) { + struct RProc *u; node *l = p->locals; while (l) { @@ -275,6 +276,18 @@ local_var_p(parser_state *p, mrb_sym sym) } l = l->cdr; } + + u = p->upper; + while (u && !MRB_PROC_CFUNC_P(u)) { + struct mrb_irep *ir = u->body.irep; + uint_fast16_t n = ir->nlocals; + const struct mrb_locals *v = ir->lv; + for (; n > 1; n --, v ++) { + if (v->name == sym) return TRUE; + } + if (MRB_PROC_SCOPE_P(u)) break; + u = u->upper; + } return FALSE; } @@ -6192,7 +6205,7 @@ parser_init_cxt(parser_state *p, mrbc_context *cxt) } p->capture_errors = cxt->capture_errors; p->no_optimize = cxt->no_optimize; - p->on_eval = cxt->on_eval; + p->upper = cxt->upper; if (cxt->partial_hook) { p->cxt = cxt; } -- cgit v1.2.3