diff options
| author | dearblue <[email protected]> | 2020-05-21 21:27:51 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-02 14:49:27 +0900 |
| commit | f85906b67920c0e69599c6e59d843274aef152be (patch) | |
| tree | 1f6852e91266cd14899974d725dffbeedfb9cd37 /mrbgems/mruby-compiler/core/parse.y | |
| parent | 1fc9345b4567bf65ed27d1ed7a84002b898f08d2 (diff) | |
| download | mruby-f85906b67920c0e69599c6e59d843274aef152be.tar.gz mruby-f85906b67920c0e69599c6e59d843274aef152be.zip | |
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`
```
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 15 |
1 files changed, 14 insertions, 1 deletions
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; } |
