Skip to content

Commit db671e2

Browse files
committed
ZJIT: Add dupn support
1 parent 86ffe18 commit db671e2

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

test/ruby/test_zjit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,15 @@ def test = X
671671
end
672672
end
673673

674+
def test_dupn
675+
assert_compiles '[0, 1]', <<~RUBY, insns: [:dupn]
676+
def test(array) = (array[0] ||= 0)
677+
678+
array = [1]
679+
[test(array), array.first]
680+
RUBY
681+
end
682+
674683
def test_send_backtrace
675684
backtrace = [
676685
"-e:2:in 'Object#jit_frame1'",

zjit/src/hir.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,13 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23492349
}
23502350
YARVINSN_pop => { state.stack_pop()?; }
23512351
YARVINSN_dup => { state.stack_push(state.stack_top()?); }
2352+
YARVINSN_dupn => {
2353+
let n = get_arg(pc, 0).as_usize();
2354+
let top = state.stack_top()?;
2355+
for _ in 0..n {
2356+
state.stack_push(top);
2357+
}
2358+
}
23522359
YARVINSN_swap => {
23532360
let right = state.stack_pop()?;
23542361
let left = state.stack_pop()?;

0 commit comments

Comments
 (0)