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.
2256 2257 2258 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2256 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
2254 2255 2256 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2254 def number @number end |
Instance Method Details
#==(other) ⇒ Object
2272 2273 2274 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2272 def ==(other) other.is_a?(NewArray) && other.number == number end |
#call(vm) ⇒ Object
2288 2289 2290 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2288 def call(vm) vm.push(vm.pop(number)) end |
#deconstruct_keys(_keys) ⇒ Object
2268 2269 2270 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2268 def deconstruct_keys(_keys) { number: number } end |
#disasm(fmt) ⇒ Object
2260 2261 2262 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2260 def disasm(fmt) fmt.instruction("newarray", [fmt.object(number)]) end |
#length ⇒ Object
2276 2277 2278 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2276 def length 2 end |
#pops ⇒ Object
2280 2281 2282 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2280 def pops number end |
#pushes ⇒ Object
2284 2285 2286 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2284 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2264 2265 2266 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2264 def to_a(_iseq) [:newarray, number] end |