1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Implement tostring instruction for yjit

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
eileencodes 2021-08-04 13:23:34 -04:00 committed by Alan Wu
parent 5b4305f71c
commit d2e8b99b5b
2 changed files with 34 additions and 0 deletions

View file

@ -59,6 +59,10 @@ class TestYJIT < Test::Unit::TestCase
assert_compiles('$foo = 123; $foo', insns: %i[setglobal], result: 123)
end
def test_compile_tostring
assert_no_exits('"i am a string #{true}"')
end
def test_getlocal_with_level
assert_compiles(<<~RUBY, insns: %i[getlocal opt_plus], result: [[7]])
def foo(foo, bar)

View file

@ -3494,6 +3494,35 @@ gen_setglobal(jitstate_t* jit, ctx_t* ctx)
return YJIT_KEEP_COMPILING;
}
static codegen_status_t
gen_tostring(jitstate_t* jit, ctx_t* ctx)
{
// Save the PC and SP because we might make a Ruby call for
// Kernel#set_trace_var
jit_save_pc(jit, REG0);
jit_save_sp(jit, ctx);
// Save YJIT registers
yjit_save_regs(cb);
x86opnd_t str = ctx_stack_pop(ctx, 1);
x86opnd_t val = ctx_stack_pop(ctx, 1);
mov(cb, C_ARG_REGS[0], str);
mov(cb, C_ARG_REGS[1], val);
call_ptr(cb, REG0, (void *)&rb_obj_as_string_result);
// Load YJIT registers
yjit_load_regs(cb);
// Push the return value
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING);
mov(cb, stack_ret, RAX);
return YJIT_KEEP_COMPILING;
}
static codegen_status_t
gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx)
{
@ -3738,6 +3767,7 @@ yjit_init_codegen(void)
yjit_reg_op(BIN(leave), gen_leave);
yjit_reg_op(BIN(getglobal), gen_getglobal);
yjit_reg_op(BIN(setglobal), gen_setglobal);
yjit_reg_op(BIN(tostring), gen_tostring);
yjit_method_codegen_table = st_init_numtable();