Skip to content

Commit

Permalink
Implement concatstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 6, 2023
1 parent f853935 commit 6b2c3ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/ruby_vm/mjit/insn_compiler.rb
Expand Up @@ -24,7 +24,7 @@ def compile(jit, ctx, asm, insn)
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")

# 67/101
# 68/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
Expand All @@ -48,7 +48,7 @@ def compile(jit, ctx, asm, insn)
when :putobject then putobject(jit, ctx, asm)
# putspecialobject
when :putstring then putstring(jit, ctx, asm)
# concatstrings
when :concatstrings then concatstrings(jit, ctx, asm)
when :anytostring then anytostring(jit, ctx, asm)
# toregexp
# intern
Expand Down Expand Up @@ -555,7 +555,28 @@ def putstring(jit, ctx, asm)
KeepCompiling
end

# concatstrings
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::Assembler]
def concatstrings(jit, ctx, asm)
n = jit.operand(0)

# Save the PC and SP because we are allocating
jit_prepare_routine_call(jit, ctx, asm)

asm.lea(:rax, ctx.sp_opnd(-C.VALUE.size * n))

# call rb_str_concat_literals(size_t n, const VALUE *strings);
asm.mov(C_ARGS[0], n)
asm.mov(C_ARGS[1], :rax)
asm.call(C.rb_str_concat_literals)

ctx.stack_pop(n)
stack_ret = ctx.stack_push
asm.mov(stack_ret, C_RET)

KeepCompiling
end

# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
Expand Down
4 changes: 4 additions & 0 deletions mjit_c.rb
Expand Up @@ -355,6 +355,10 @@ def rb_obj_as_string_result
Primitive.cexpr! 'SIZET2NUM((size_t)rb_obj_as_string_result)'
end

def rb_str_concat_literals
Primitive.cexpr! 'SIZET2NUM((size_t)rb_str_concat_literals)'
end

#========================================================================================
#
# Old stuff
Expand Down

0 comments on commit 6b2c3ff

Please sign in to comment.