diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-08-10 05:15:58 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-08-10 05:15:58 +0900 |
| commit | 4debf651a3c7746fe360ec28838b67dae862245e (patch) | |
| tree | f8db4383cc3cd8cddbfb662bdd488e138a609c39 /src | |
| parent | 8d017ebdb79b8299a1cfb273868b12ba3cfbed16 (diff) | |
| download | mruby-4debf651a3c7746fe360ec28838b67dae862245e.tar.gz mruby-4debf651a3c7746fe360ec28838b67dae862245e.zip | |
optimize assignment just before OP_RETURN
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/codegen.c b/src/codegen.c index bf6fd0b3e..4f118753e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -142,6 +142,9 @@ genop(codegen_scope *s, mrb_code i) s->pc++; } +#define NOVAL 0 +#define VAL 1 + static void genop_peep(codegen_scope *s, mrb_code i, int val) { @@ -217,6 +220,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val) case OP_SETCV: case OP_SETCONST: case OP_SETMCNST: + case OP_SETGLOBAL: if (c0 == OP_MOVE) { if (GETARG_A(i) == GETARG_A(i0)) { s->iseq[s->pc-1] = MKOP_ABx(c1, GETARG_B(i0), GETARG_Bx(i)); @@ -261,6 +265,17 @@ genop_peep(codegen_scope *s, mrb_code i, int val) s->iseq[s->pc-1] = MKOP_ABC(c0, 0, GETARG_B(i0), GETARG_C(i0)); genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL)); return; + case OP_SETIV: + case OP_SETCV: + case OP_SETCONST: + case OP_SETMCNST: + case OP_SETUPVAR: + case OP_SETGLOBAL: + s->pc--; + genop_peep(s, i0, NOVAL); + i0 = s->iseq[s->pc-1]; + genop(s, MKOP_AB(OP_RETURN, GETARG_A(i0), OP_R_NORMAL)); + return; case OP_LOADSYM: case OP_GETGLOBAL: case OP_GETIV: @@ -436,9 +451,6 @@ lv_idx(codegen_scope *s, mrb_sym id) return 0; } -#define NOVAL 0 -#define VAL 1 - static void for_body(codegen_scope *s, node *tree) { |
