summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bernstein <ruby@bernsteinbear.com>2025-08-28 09:48:15 -0400
committerMax Bernstein <tekknolagi@gmail.com>2025-08-28 10:14:37 -0700
commitec55b5b9aacf604634b6ca5b34366fba6e8b3f5e (patch)
tree54953f8347d4215f38157fb9fccd43e0c7a2a79b
parentca0ef794971f4fddf92c4652dee17ada63d52dbe (diff)
ZJIT: Generate code for ArrayPush
-rw-r--r--test/ruby/test_zjit.rb9
-rw-r--r--zjit/src/codegen.rs7
2 files changed, 15 insertions, 1 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index 7c29fdeb19..075a7765c8 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -109,6 +109,15 @@ class TestZJIT < Test::Unit::TestCase
}, insns: [:duphash]
end
+ def test_pushtoarray
+ assert_compiles '[1, 2, 3]', %q{
+ def test
+ [*[], 1, 2, 3]
+ end
+ test
+ }, insns: [:pushtoarray]
+ end
+
def test_setglobal_with_trace_var_exception
assert_compiles '"rescued"', %q{
def test
diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs
index 8b3f4f84be..f257e5c138 100644
--- a/zjit/src/codegen.rs
+++ b/zjit/src/codegen.rs
@@ -399,9 +399,9 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
Insn::ObjToString { val, cd, state, .. } => gen_objtostring(jit, asm, opnd!(val), *cd, &function.frame_state(*state)),
&Insn::CheckInterrupts { state } => no_output!(gen_check_interrupts(jit, asm, &function.frame_state(state))),
&Insn::HashDup { val, state } => { gen_hash_dup(asm, opnd!(val), &function.frame_state(state)) },
+ &Insn::ArrayPush { array, val, state } => { no_output!(gen_array_push(asm, opnd!(array), opnd!(val), &function.frame_state(state))) },
&Insn::ArrayExtend { state, .. }
| &Insn::ArrayMax { state, .. }
- | &Insn::ArrayPush { state, .. }
| &Insn::DefinedIvar { state, .. }
| &Insn::FixnumDiv { state, .. }
| &Insn::FixnumMod { state, .. }
@@ -689,6 +689,11 @@ fn gen_hash_dup(asm: &mut Assembler, val: Opnd, state: &FrameState) -> lir::Opnd
asm_ccall!(asm, rb_hash_resurrect, val)
}
+fn gen_array_push(asm: &mut Assembler, array: Opnd, val: Opnd, state: &FrameState) {
+ gen_prepare_call_with_gc(asm, state);
+ asm_ccall!(asm, rb_ary_push, array, val);
+}
+
/// Compile an interpreter entry block to be inserted into an ISEQ
fn gen_entry_prologue(asm: &mut Assembler, iseq: IseqPtr) {
asm_comment!(asm, "ZJIT entry point: {}", iseq_get_location(iseq, 0));