diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-03-30 01:35:11 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-03-30 01:35:11 +0900 |
| commit | 4979b52d613f867b8fa7fdcc969c939a085e315f (patch) | |
| tree | f1c75e3aa50487f0ba69fafc2dc43498292b611c /mrbgems/mruby-compiler/core/codegen.c | |
| parent | 0e03a7f2a3c874c26ef1d786f99a555f4c652701 (diff) | |
| download | mruby-4979b52d613f867b8fa7fdcc969c939a085e315f.tar.gz mruby-4979b52d613f867b8fa7fdcc969c939a085e315f.zip | |
reduce OP_ARRAY in argument splat
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index f68c04c85..e417bddd4 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -780,16 +780,22 @@ gen_values(codegen_scope *s, node *t, int val) is_splat = (intptr_t)t->car->car == NODE_SPLAT; /* splat mode */ if (n >= 127 || is_splat) { if (val) { - pop_n(n); - genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), n)); - push(); - codegen(s, t->car, VAL); - pop(); pop(); - if (is_splat) { - genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1)); + if (is_splat && n == 0 && (intptr_t)t->car->cdr->car == NODE_ARRAY) { + codegen(s, t->car->cdr, VAL); + pop(); } else { - genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); + pop_n(n); + genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), n)); + push(); + codegen(s, t->car, VAL); + pop(); pop(); + if (is_splat) { + genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1)); + } + else { + genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); + } } t = t->cdr; while (t) { |
