@@ -1840,6 +1840,54 @@ def pushes
1840
1840
end
1841
1841
end
1842
1842
1843
+ # ### Summary
1844
+ #
1845
+ # `opt_case_dispatch` is a branch instruction that moves the control flow
1846
+ # for case statements that have clauses where they can all be used as hash
1847
+ # keys for an internal hash.
1848
+ #
1849
+ # It has two arguments: the `case_dispatch_hash` and an `else_label`. It
1850
+ # pops one value off the stack: a hash key. `opt_case_dispatch` looks up the
1851
+ # key in the `case_dispatch_hash` and jumps to the corresponding label if
1852
+ # there is one. If there is no value in the `case_dispatch_hash`,
1853
+ # `opt_case_dispatch` jumps to the `else_label` index.
1854
+ #
1855
+ # ### Usage
1856
+ #
1857
+ # ~~~ruby
1858
+ # case 1
1859
+ # when 1
1860
+ # puts "foo"
1861
+ # else
1862
+ # puts "bar"
1863
+ # end
1864
+ # ~~~
1865
+ #
1866
+ class OptCaseDispatch
1867
+ attr_reader :case_dispatch_hash , :else_label
1868
+
1869
+ def initialize ( case_dispatch_hash , else_label )
1870
+ @case_dispatch_hash = case_dispatch_hash
1871
+ @else_label = else_label
1872
+ end
1873
+
1874
+ def to_a ( _iseq )
1875
+ [ :opt_case_dispatch , case_dispatch_hash , else_label ]
1876
+ end
1877
+
1878
+ def length
1879
+ 3
1880
+ end
1881
+
1882
+ def pops
1883
+ 1
1884
+ end
1885
+
1886
+ def pushes
1887
+ 0
1888
+ end
1889
+ end
1890
+
1843
1891
# ### Summary
1844
1892
#
1845
1893
# `opt_div` is a specialization of the `opt_send_without_block` instruction
@@ -3534,6 +3582,42 @@ def pushes
3534
3582
end
3535
3583
end
3536
3584
3585
+ # ### Summary
3586
+ #
3587
+ # `throw` pops a value off the top of the stack and throws it. It is caught
3588
+ # using the instruction sequence's (or an ancestor's) catch table. It pushes
3589
+ # on the result of throwing the value.
3590
+ #
3591
+ # ### Usage
3592
+ #
3593
+ # ~~~ruby
3594
+ # [1, 2, 3].map { break 2 }
3595
+ # ~~~
3596
+ #
3597
+ class Throw
3598
+ attr_reader :type
3599
+
3600
+ def initialize ( type )
3601
+ @type = type
3602
+ end
3603
+
3604
+ def to_a ( _iseq )
3605
+ [ :throw , type ]
3606
+ end
3607
+
3608
+ def length
3609
+ 2
3610
+ end
3611
+
3612
+ def pops
3613
+ 1
3614
+ end
3615
+
3616
+ def pushes
3617
+ 1
3618
+ end
3619
+ end
3620
+
3537
3621
# ### Summary
3538
3622
#
3539
3623
# `topn` pushes a single value onto the stack that is a copy of the value
0 commit comments