Class: SyntaxTree::YARV::TopN
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(number) ⇒ TopN
constructor
A new instance of TopN.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(number) ⇒ TopN
Returns a new instance of TopN.
5295 5296 5297 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5295 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
5293 5294 5295 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5293 def number @number end |
Instance Method Details
#call(vm) ⇒ Object
5323 5324 5325 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5323 def call(vm) vm.push(vm.stack[-number - 1]) end |
#canonical ⇒ Object
5319 5320 5321 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5319 def canonical self end |
#disasm(fmt) ⇒ Object
5299 5300 5301 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5299 def disasm(fmt) fmt.instruction("topn", [fmt.object(number)]) end |
#length ⇒ Object
5307 5308 5309 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5307 def length 2 end |
#pops ⇒ Object
5311 5312 5313 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5311 def pops 0 end |
#pushes ⇒ Object
5315 5316 5317 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5315 def pushes 1 end |
#to_a(_iseq) ⇒ Object
5303 5304 5305 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5303 def to_a(_iseq) [:topn, number] end |