Class: SyntaxTree::YARV::NewArray
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::NewArray
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘newarray` puts a new array initialized with `number` values from the stack. It pops `number` values off the stack and pushes the array onto the stack.
### Usage
~~~ruby
- “string”
-
~~~
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) ⇒ NewArray
constructor
A new instance of NewArray.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(number) ⇒ NewArray
Returns a new instance of NewArray.
2367 2368 2369 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2367 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
2365 2366 2367 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2365 def number @number end |
Instance Method Details
#==(other) ⇒ Object
2383 2384 2385 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2383 def ==(other) other.is_a?(NewArray) && other.number == number end |
#call(vm) ⇒ Object
2399 2400 2401 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2399 def call(vm) vm.push(vm.pop(number)) end |
#deconstruct_keys(_keys) ⇒ Object
2379 2380 2381 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2379 def deconstruct_keys(_keys) { number: number } end |
#disasm(fmt) ⇒ Object
2371 2372 2373 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2371 def disasm(fmt) fmt.instruction("newarray", [fmt.object(number)]) end |
#length ⇒ Object
2387 2388 2389 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2387 def length 2 end |
#pops ⇒ Object
2391 2392 2393 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2391 def pops number end |
#pushes ⇒ Object
2395 2396 2397 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2395 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2375 2376 2377 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2375 def to_a(_iseq) [:newarray, number] end |