summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler
diff options
context:
space:
mode:
authorYAMAMOTO Masaya <[email protected]>2017-11-04 01:23:12 +0900
committerYAMAMOTO Masaya <[email protected]>2017-11-04 01:23:12 +0900
commit625f9f6fa314872968632c5adbee7fb3823268b8 (patch)
treefdde1700b13048212606e4a995907f3757e18e2f /mrbgems/mruby-compiler
parentb70d69de09130ce2bc89289b4826b3deea8afaae (diff)
parente7fe6ee2638dee438c1d79ab16a0403aebec0a60 (diff)
downloadmruby-625f9f6fa314872968632c5adbee7fb3823268b8.tar.gz
mruby-625f9f6fa314872968632c5adbee7fb3823268b8.zip
Merge branch 'master' of github.com:mruby/mruby
Diffstat (limited to 'mrbgems/mruby-compiler')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c34
-rw-r--r--mrbgems/mruby-compiler/core/parse.y8
2 files changed, 33 insertions, 9 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index ba8ed2c71..fce5ac490 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -278,6 +278,19 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
}
}
break;
+ case OP_GETUPVAR:
+ if (c0 == OP_SETUPVAR) {
+ if (GETARG_B(i) == GETARG_B(i0) && GETARG_C(i) == GETARG_C(i0)) {
+ if (GETARG_A(i) == GETARG_A(i0)) {
+ /* just skip OP_SETUPVAR */
+ return 0;
+ }
+ else {
+ return genop(s, MKOP_AB(OP_MOVE, GETARG_A(i), GETARG_A(i0)));
+ }
+ }
+ }
+ break;
case OP_EPOP:
if (c0 == OP_EPOP) {
s->iseq[s->pc-1] = MKOP_A(OP_EPOP, GETARG_A(i0)+GETARG_A(i));
@@ -335,6 +348,14 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
s->iseq[s->pc-1] = MKOP_ABC(OP_SUBI, GETARG_A(i), GETARG_B(i), -c);
return 0;
}
+ break;
+ case OP_ARYCAT:
+ case OP_ARYPUSH:
+ if (c0 == OP_MOVE && GETARG_A(i0) >= s->nlocals) {
+ s->iseq[s->pc-1] = MKOP_AB(c1, GETARG_A(i), GETARG_B(i0));
+ return 0;
+ }
+ break;
case OP_STRCAT:
if (c0 == OP_STRING) {
mrb_value v = s->irep->pool[GETARG_Bx(i0)];
@@ -826,10 +847,10 @@ gen_values(codegen_scope *s, node *t, int val, int extra)
codegen(s, t->car, VAL);
pop(); pop();
if (is_splat) {
- genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1));
+ genop_peep(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1), NOVAL);
}
else {
- genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1));
+ genop_peep(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1), NOVAL);
}
}
t = t->cdr;
@@ -838,10 +859,10 @@ gen_values(codegen_scope *s, node *t, int val, int extra)
codegen(s, t->car, VAL);
pop(); pop();
if (nint(t->car->car) == NODE_SPLAT) {
- genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1));
+ genop_peep(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1), NOVAL);
}
else {
- genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1));
+ genop_peep(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1), NOVAL);
}
t = t->cdr;
}
@@ -2146,7 +2167,7 @@ codegen(codegen_scope *s, node *tree, int val)
while (up) {
idx = lv_idx(up, nsym(tree));
if (idx > 0) {
- genop(s, MKOP_ABC(OP_GETUPVAR, cursp(), idx, lv));
+ genop_peep(s, MKOP_ABC(OP_GETUPVAR, cursp(), idx, lv), VAL);
break;
}
lv++;
@@ -3031,6 +3052,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 b4a70873d..01269d8da 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -2579,7 +2579,7 @@ do_block : keyword_do_block
local_nest(p);
}
opt_block_param
- compstmt
+ bodystmt
keyword_end
{
$$ = new_block(p,$3,$4);
@@ -2669,7 +2669,7 @@ brace_block : '{'
$<num>$ = p->lineno;
}
opt_block_param
- compstmt keyword_end
+ bodystmt keyword_end
{
$$ = new_block(p,$3,$4);
SET_LINENO($$, $<num>2);
@@ -5731,7 +5731,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
new_table = (mrb_sym*)parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length);
if (p->filename_table) {
- memmove(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
+ memmove(new_table, p->filename_table, sizeof(mrb_sym) * p->current_filename_index);
}
p->filename_table = new_table;
p->filename_table[p->filename_table_length - 1] = sym;
@@ -5833,7 +5833,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;
}