class/module body to honor whether value is required or not; reduce a few...

class/module body to honor whether value is required or not; reduce a few instructions for normal cases
parent bc7a6e88
...@@ -657,14 +657,17 @@ lambda_body(codegen_scope *s, node *tree, int blk) ...@@ -657,14 +657,17 @@ lambda_body(codegen_scope *s, node *tree, int blk)
} }
static int 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 *scope = scope_new(s->mrb, s, tree->car);
codegen(scope, tree->cdr, VAL); codegen(scope, tree->cdr, val);
if (!s->iseq) { if (!s->iseq) {
genop(scope, MKOP_A(OP_STOP, 0)); genop(scope, MKOP_A(OP_STOP, 0));
} }
else if (!val) {
genop(scope, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
}
else { else {
if (scope->nregs == 0) { if (scope->nregs == 0) {
genop(scope, MKOP_A(OP_LOADNIL, 0)); genop(scope, MKOP_A(OP_LOADNIL, 0));
...@@ -1235,7 +1238,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1235,7 +1238,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_Bx(OP_EPUSH, 0)); genop(s, MKOP_Bx(OP_EPUSH, 0));
s->ensure_level++; s->ensure_level++;
codegen(s, tree->car, val); 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->iseq[epush] = MKOP_Bx(OP_EPUSH, idx);
s->ensure_level--; s->ensure_level--;
genop_peep(s, MKOP_A(OP_EPOP, 1), NOVAL); genop_peep(s, MKOP_A(OP_EPOP, 1), NOVAL);
...@@ -1420,7 +1423,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1420,7 +1423,7 @@ codegen(codegen_scope *s, node *tree, int val)
break; break;
case NODE_SCOPE: case NODE_SCOPE:
scope_body(s, tree); scope_body(s, tree, NOVAL);
break; break;
case NODE_FCALL: case NODE_FCALL:
...@@ -2280,7 +2283,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2280,7 +2283,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop(); pop(); pop(); pop();
idx = new_msym(s, sym(tree->car->cdr)); idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_CLASS, cursp(), idx)); 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)); genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) { if (val) {
push(); push();
...@@ -2306,7 +2309,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2306,7 +2309,7 @@ codegen(codegen_scope *s, node *tree, int val)
pop(); pop();
idx = new_msym(s, sym(tree->car->cdr)); idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_MODULE, cursp(), idx)); 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)); genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) { if (val) {
push(); push();
...@@ -2321,7 +2324,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2321,7 +2324,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen(s, tree->car, VAL); codegen(s, tree->car, VAL);
pop(); pop();
genop(s, MKOP_AB(OP_SCLASS, cursp(), cursp())); 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)); genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) { if (val) {
push(); push();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment