8000 Merge pull request #196 from jhawthorn/gen_newrange · github/ruby@2efce29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2efce29

Browse files
authored
Merge pull request #196 from jhawthorn/gen_newrange
Implement newrange
2 parents adc67cf + 3e30675 commit 2efce29

File tree

2 files changed

+31
-0
lines changed
Expand file tree

2 files changed

+31
-0
lines changed

test/ruby/test_yjit.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def test_compile_opt_duparray
3636
assert_compiles('[1, 2, 3]', insns: %i[duparray], result: [1, 2, 3])
3737
end
3838

39+
def test_compile_newrange
40+
assert_compiles('s = 1; (s..5)', insns: %i[newrange], result: 1..5)
41+
assert_compiles('s = 1; e = 5; (s..e)', insns: %i[newrange], result: 1..5)
42+
assert_compiles('s = 1; (s...5)', insns: %i[newrange], result: 1...5)
43+
assert_compiles('s = 1; (s..)', insns: %i[newrange], result: 1..)
44+
assert_compiles('e = 5; (..e)', insns: %i[newrange], result: ..5)
45+
end
46+
3947
def test_compile_opt_nil_p
4048
assert_compiles('nil.nil?', insns: %i[opt_nil_p], result: true)
4149
assert_compiles('false.nil?', insns: %i[opt_nil_p], result: false)

yjit_codegen.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,28 @@ gen_splatarray(jitstate_t* jit, ctx_t* ctx)
916916
return YJIT_KEEP_COMPILING;
917917
}
918918

919+
// new range initialized from top 2 values
920+
static codegen_status_t
921+
gen_newrange(jitstate_t* jit, ctx_t* ctx)
922+
{
923+
rb_num_t flag = (rb_num_t)jit_get_arg(jit, 0);
924+
925+
// rb_range_new() allocates and can raise
926+
jit_prepare_routine_call(jit, ctx, REG0);
927+
928+
// val = rb_range_new(low, high, (int)flag);
929+
mov(cb, C_ARG_REGS[0], ctx_stack_opnd(ctx, 1));
930+
mov(cb, C_ARG_REGS[1], ctx_stack_opnd(ctx, 0));
931+
mov(cb, C_ARG_REGS[2], imm_opnd(flag));
932+
call_ptr(cb, REG0, (void *)rb_range_new);
933+
934+
ctx_stack_pop(ctx, 2);
935+
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_HEAP);
936+
mov(cb, stack_ret, RAX);
937+
938+
return YJIT_KEEP_COMPILING;
939+
}
940+
919941
static void
920942
guard_object_is_heap(codeblock_t *cb, x86opnd_t object_opnd, ctx_t *ctx, uint8_t *side_exit)
921943
{
@@ -4013,6 +4035,7 @@ yjit_init_codegen(void)
40134035
yjit_reg_op(BIN(splatarray), gen_splatarray);
40144036
yjit_reg_op(BIN(expandarray), gen_expandarray);
40154037
yjit_reg_op(BIN(newhash), gen_newhash);
4038+
yjit_reg_op(BIN(newrange), gen_newrange);
40164039
yjit_reg_op(BIN(concatstrings), gen_concatstrings);
40174040
yjit_reg_op(BIN(putnil), gen_putnil);
40184041
yjit_reg_op(BIN(putobject), gen_putobject);

0 commit comments

Comments
 (0)
0