summaryrefslogtreecommitdiff
path: root/lib/ruby_vm
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-03 22:17:34 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 23:28:59 -0800
commitf85393514cfeadf27129c5607c257368041dd544 (patch)
treee4b327eab0123379055325143dd7b28eee82521b /lib/ruby_vm
parent43d1a7afd44e6016a8638e4801da8ddc137b0654 (diff)
Implement anytostring
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib/ruby_vm')
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index ac759f504f..68f36c902a 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -24,7 +24,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 66/101
+ # 67/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -49,7 +49,7 @@ module RubyVM::MJIT
# putspecialobject
when :putstring then putstring(jit, ctx, asm)
# concatstrings
- # anytostring
+ when :anytostring then anytostring(jit, ctx, asm)
# toregexp
# intern
when :newarray then newarray(jit, ctx, asm)
@@ -556,7 +556,28 @@ module RubyVM::MJIT
end
# concatstrings
- # anytostring
+
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def anytostring(jit, ctx, asm)
+ # Save the PC and SP since we might call #to_s
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ str = ctx.stack_pop(1)
+ val = ctx.stack_pop(1)
+
+ asm.mov(C_ARGS[0], str)
+ asm.mov(C_ARGS[1], val)
+ asm.call(C.rb_obj_as_string_result)
+
+ # Push the return value
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
+
# toregexp
# intern