Class: SyntaxTree::YARV::NewHash
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::NewHash
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘newhash` puts a new hash onto the stack, using `number` elements from the stack. `number` needs to be even. It pops `number` elements off the stack and pushes a hash onto the stack.
### Usage
~~~ruby def foo(key, value)
{ key => value }
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) ⇒ NewHash
constructor
A new instance of NewHash.
- #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) ⇒ NewHash
Returns a new instance of NewHash.
2362 2363 2364 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2362 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
2360 2361 2362 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2360 def number @number end |
Instance Method Details
#==(other) ⇒ Object
2378 2379 2380 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2378 def ==(other) other.is_a?(NewHash) && other.number == number end |
#call(vm) ⇒ Object
2394 2395 2396 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2394 def call(vm) vm.push(vm.pop(number).each_slice(2).to_h) end |
#deconstruct_keys(_keys) ⇒ Object
2374 2375 2376 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2374 def deconstruct_keys(_keys) { number: number } end |
#disasm(fmt) ⇒ Object
2366 2367 2368 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2366 def disasm(fmt) fmt.instruction("newhash", [fmt.object(number)]) end |
#length ⇒ Object
2382 2383 2384 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2382 def length 2 end |
#pops ⇒ Object
2386 2387 2388 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2386 def pops number end |
#pushes ⇒ Object
2390 2391 2392 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2390 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2370 2371 2372 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2370 def to_a(_iseq) [:newhash, number] end |