Class: SyntaxTree::YARV::DupN
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::DupN
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘dupn` duplicates the top `n` stack elements.
### Usage
~~~ruby Object::X ||= true ~~~
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) ⇒ DupN
constructor
A new instance of DupN.
- #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) ⇒ DupN
Returns a new instance of DupN.
1287 1288 1289 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1287 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
1285 1286 1287 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1285 def number @number end |
Instance Method Details
#==(other) ⇒ Object
1303 1304 1305 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1303 def ==(other) other.is_a?(DupN) && other.number == number end |
#call(vm) ⇒ Object
1315 1316 1317 1318 1319 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1315 def call(vm) values = vm.pop(number) vm.push(*values) vm.push(*values) end |
#deconstruct_keys(_keys) ⇒ Object
1299 1300 1301 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1299 def deconstruct_keys(_keys) { number: number } end |
#disasm(fmt) ⇒ Object
1291 1292 1293 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1291 def disasm(fmt) fmt.instruction("dupn", [fmt.object(number)]) end |
#length ⇒ Object
1307 1308 1309 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1307 def length 2 end |
#pushes ⇒ Object
1311 1312 1313 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1311 def pushes number end |
#to_a(_iseq) ⇒ Object
1295 1296 1297 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1295 def to_a(_iseq) [:dupn, number] end |