Skip to content

Commit 276f4ce

Browse files
committed
ZJIT: Add dupn support
1 parent c99cb62 commit 276f4ce

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
@@ -699,6 +699,15 @@ def test = X
699699
end
700700
end
701701

702+
def test_dupn
703+
assert_compiles '[0, 1]', <<~RUBY, insns: [:dupn]
704+
def test(array) = (array[0] ||= 0)
705+
706+
array = [1]
707+
[test(array), array.first]
708+
RUBY
709+
end
710+
702711
def test_send_backtrace
703712
backtrace = [
704713
"-e:2:in 'Object#jit_frame1'",

zjit/src/hir.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,13 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23892389
}
23902390
YARVINSN_pop => { state.stack_pop()?; }
23912391
YARVINSN_dup => { state.stack_push(state.stack_top()?); }
2392+
YARVINSN_dupn => {
2393+
let n = get_arg(pc, 0).as_usize();
2394+
let top = state.stack_top()?;
2395+
for _ in 0..n {
2396+
state.stack_push(top);
2397+
}
2398+
}
23922399
YARVINSN_swap => {
23932400
let right = state.stack_pop()?;
23942401
let left = state.stack_pop()?;

0 commit comments

Comments
 (0)