modules/mruby/src/codegen.c in webruby-0.2.4 vs modules/mruby/src/codegen.c in webruby-0.2.5
- old
+ new
@@ -655,27 +655,28 @@
scope_finish(s);
return parent->irep->rlen - 1;
}
static int
-scope_body(codegen_scope *s, node *tree)
+scope_body(codegen_scope *s, node *tree, int val)
{
codegen_scope *scope = scope_new(s->mrb, s, tree->car);
- codegen(scope, tree->cdr, VAL);
+ codegen(scope, tree->cdr, val);
if (!s->iseq) {
genop(scope, MKOP_A(OP_STOP, 0));
}
+ else if (!val) {
+ genop(scope, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
+ }
else {
if (scope->nregs == 0) {
genop(scope, MKOP_A(OP_LOADNIL, 0));
genop(scope, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
}
else {
- pop();
- genop_peep(scope, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL);
- push();
+ genop_peep(scope, MKOP_AB(OP_RETURN, scope->sp-1, OP_R_NORMAL), NOVAL);
}
}
scope_finish(scope);
if (!s->irep) {
/* should not happen */
@@ -1233,11 +1234,11 @@
int epush = s->pc;
genop(s, MKOP_Bx(OP_EPUSH, 0));
s->ensure_level++;
codegen(s, tree->car, val);
- idx = scope_body(s, tree->cdr);
+ idx = scope_body(s, tree->cdr, NOVAL);
s->iseq[epush] = MKOP_Bx(OP_EPUSH, idx);
s->ensure_level--;
genop_peep(s, MKOP_A(OP_EPOP, 1), NOVAL);
}
break;
@@ -1407,19 +1408,25 @@
pos3 = tmp;
if (pos1) dispatch(s, pos1);
tree = tree->cdr;
}
if (val) {
+ int pos = cursp();
genop(s, MKOP_A(OP_LOADNIL, cursp()));
+ if (pos3) dispatch_linked(s, pos3);
+ pop();
+ genop(s, MKOP_AB(OP_MOVE, cursp(), pos));
push();
}
- if (pos3) dispatch_linked(s, pos3);
+ else if (pos3) {
+ dispatch_linked(s, pos3);
+ }
}
break;
case NODE_SCOPE:
- scope_body(s, tree);
+ scope_body(s, tree, NOVAL);
break;
case NODE_FCALL:
case NODE_CALL:
gen_call(s, tree, 0, 0, val);
@@ -2275,11 +2282,11 @@
push();
}
pop(); pop();
idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_CLASS, cursp(), idx));
- idx = scope_body(s, tree->cdr->cdr->car);
+ idx = scope_body(s, tree->cdr->cdr->car, val);
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) {
push();
}
}
@@ -2301,11 +2308,11 @@
codegen(s, tree->car->car, VAL);
}
pop();
idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_MODULE, cursp(), idx));
- idx = scope_body(s, tree->cdr->car);
+ idx = scope_body(s, tree->cdr->car, val);
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) {
push();
}
}
@@ -2316,10 +2323,10 @@
int idx;
codegen(s, tree->car, VAL);
pop();
genop(s, MKOP_AB(OP_SCLASS, cursp(), cursp()));
- idx = scope_body(s, tree->cdr->car);
+ idx = scope_body(s, tree->cdr->car, val);
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) {
push();
}
}