Skip to content

Commit ded951a

Browse files
authored
Merge pull request ruby#126 from Shopify/splatarray
Implement splatarray
2 parents fdf38be + ebaba20 commit ded951a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

bootstraptest/test_yjit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,3 +1386,12 @@ def is_inf(obj)
13861386
is_inf(1.0/0.0)
13871387
]
13881388
}
1389+
1390+
assert_equal '[1, 2, 3, 4, 5]', %q{
1391+
def splatarray
1392+
[*(1..5)]
1393+
end
1394+
1395+
splatarray
1396+
splatarray
1397+
}

vm_insnhelper.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,6 +4244,12 @@ vm_splat_array(VALUE flag, VALUE ary)
42444244
}
42454245
}
42464246

4247+
VALUE
4248+
rb_vm_splat_array(VALUE flag, VALUE ary)
4249+
{
4250+
return vm_splat_array(flag, ary);
4251+
}
4252+
42474253
static VALUE
42484254
vm_check_match(rb_execution_context_t *ec, VALUE target, VALUE pattern, rb_num_t flag)
42494255
{

yjit_codegen.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,35 @@ gen_duparray(jitstate_t* jit, ctx_t* ctx)
689689
return YJIT_KEEP_COMPILING;
690690
}
691691

692+
VALUE rb_vm_splat_array(VALUE flag, VALUE ary);
693+
694+
// call to_a on the array on the stack
695+
static codegen_status_t
696+
gen_splatarray(jitstate_t* jit, ctx_t* ctx)
697+
{
698+
VALUE flag = (VALUE) jit_get_arg(jit, 0);
699+
700+
// Save the PC and SP because the callee may allocate
701+
// Note that this modifies REG_SP, which is why we do it first
702+
jit_save_pc(jit, REG0);
703+
jit_save_sp(jit, ctx);
704+
705+
// Get the operands from the stack
706+
x86opnd_t ary_opnd = ctx_stack_pop(ctx, 1);
707+
708+
// Call rb_vm_splat_array(flag, ary)
709+
yjit_save_regs(cb);
710+
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], flag);
711+
mov(cb, C_ARG_REGS[1], ary_opnd);
712+
call_ptr(cb, REG1, (void *) rb_vm_splat_array);
713+
yjit_load_regs(cb);
714+
715+
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_ARRAY);
716+
mov(cb, stack_ret, RAX);
717+
718+
return YJIT_KEEP_COMPILING;
719+
}
720+
692721
// new hash initialized from top N values
693722
static codegen_status_t
694723
gen_newhash(jitstate_t* jit, ctx_t* ctx)
@@ -3468,6 +3497,7 @@ yjit_init_codegen(void)
34683497
yjit_reg_op(BIN(adjuststack), gen_adjuststack);
34693498
yjit_reg_op(BIN(newarray), gen_newarray);
34703499
yjit_reg_op(BIN(duparray), gen_duparray);
3500+
yjit_reg_op(BIN(splatarray), gen_splatarray);
34713501
yjit_reg_op(BIN(newhash), gen_newhash);
34723502
yjit_reg_op(BIN(concatstrings), gen_concatstrings);
34733503
yjit_reg_op(BIN(putnil), gen_putnil);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy