diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-12-24 12:29:06 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-12-24 12:29:06 +0900 |
| commit | c209fa9514ea6296a798168481a769bd2225243d (patch) | |
| tree | ab51ea42a156ce8f362a458714766600ea5d8972 | |
| parent | bc7a6e88a17e89e14de7cb4cbbd6ca19c4daa620 (diff) | |
| download | mruby-c209fa9514ea6296a798168481a769bd2225243d.tar.gz mruby-c209fa9514ea6296a798168481a769bd2225243d.zip | |
class/module body to honor whether value is required or not; reduce a few instructions for normal cases
| -rw-r--r-- | src/codegen.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/codegen.c b/src/codegen.c index dc80f2592..4114b496c 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -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(); |
