diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-17 07:49:47 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-17 07:49:47 +0900 |
| commit | 7c99df8416aa866725c11e5ced7f2c5a818a8c74 (patch) | |
| tree | 827ad7d0074e44eb28672ca8b41788a3c1bc28a4 /src | |
| parent | 6f044de578bd9b1056e59bb499d49a5dc7ebef2b (diff) | |
| download | mruby-7c99df8416aa866725c11e5ced7f2c5a818a8c74.tar.gz mruby-7c99df8416aa866725c11e5ced7f2c5a818a8c74.zip | |
ops.h: add `OP_ARYPUSH_N` instruction.
Add n elements at once. Reduces instructions for huge array
initialization. In addition, `gen_value` function in `codegen.c` was
refactored and clarified.
Diffstat (limited to 'src')
| -rw-r--r-- | src/codedump.c | 6 | ||||
| -rw-r--r-- | src/vm.c | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/codedump.c b/src/codedump.c index 87faa589c..3128d7467 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -428,13 +428,17 @@ codedump(mrb_state *mrb, const mrb_irep *irep) print_lv_ab(mrb, irep, a, b); break; CASE(OP_ARYCAT, B): - printf("OP_ARYCAT\tR%d\t", a); + printf("OP_ARYCAT\tR%d\tR%d\t", a, a+1); print_lv_a(mrb, irep, a); break; CASE(OP_ARYPUSH, B): printf("OP_ARYPUSH\tR%d\t", a); print_lv_a(mrb, irep, a); break; + CASE(OP_ARYPUSH_N, BB): + printf("OP_ARYPUSH_N\tR%d\t%d\t", a, b); + print_lv_a(mrb, irep, a); + break; CASE(OP_ARYDUP, B): printf("OP_ARYDUP\tR%d\t", a); print_lv_a(mrb, irep, a); @@ -2551,6 +2551,13 @@ RETRY_TRY_BLOCK: NEXT; } + CASE(OP_ARYPUSH_N, BB) { + for (mrb_int i=0; i<b; i++) { + mrb_ary_push(mrb, regs[a], regs[a+i+1]); + } + NEXT; + } + CASE(OP_ARYDUP, B) { mrb_value ary = regs[a]; if (mrb_array_p(ary)) { |
