Class: SyntaxTree::YARV::TopN
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::TopN
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘topn` pushes a single value onto the stack that is a copy of the value within the stack that is `number` of slots down from the top.
### Usage
~~~ruby case 3 when 1..5
puts "foo"
end ~~~
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(number) ⇒ TopN
constructor
A new instance of TopN.
- #length ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(number) ⇒ TopN
Returns a new instance of TopN.
5702 5703 5704 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5702 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
5700 5701 5702 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5700 def number @number end |
Instance Method Details
#==(other) ⇒ Object
5718 5719 5720 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5718 def ==(other) other.is_a?(TopN) && other.number == number end |
#call(vm) ⇒ Object
5730 5731 5732 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5730 def call(vm) vm.push(vm.stack[-number - 1]) end |
#deconstruct_keys(_keys) ⇒ Object
5714 5715 5716 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5714 def deconstruct_keys(_keys) { number: number } end |
#disasm(fmt) ⇒ Object
5706 5707 5708 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5706 def disasm(fmt) fmt.instruction("topn", [fmt.object(number)]) end |
#length ⇒ Object
5722 5723 5724 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5722 def length 2 end |
#pushes ⇒ Object
5726 5727 5728 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5726 def pushes 1 end |
#to_a(_iseq) ⇒ Object
5710 5711 5712 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5710 def to_a(_iseq) [:topn, number] end |