mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
class/module body to honor whether value is required or not; reduce a few instructions for normal cases
This commit is contained in:
+10
-7
@@ -657,14 +657,17 @@ lambda_body(codegen_scope *s, node *tree, int blk)
|
||||
}
|
||||
|
||||
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));
|
||||
@@ -1235,7 +1238,7 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
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);
|
||||
@@ -1420,7 +1423,7 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
break;
|
||||
|
||||
case NODE_SCOPE:
|
||||
scope_body(s, tree);
|
||||
scope_body(s, tree, NOVAL);
|
||||
break;
|
||||
|
||||
case NODE_FCALL:
|
||||
@@ -2280,7 +2283,7 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
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();
|
||||
@@ -2306,7 +2309,7 @@ codegen(codegen_scope *s, node *tree, int 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();
|
||||
@@ -2321,7 +2324,7 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user