Class: SyntaxTree::YARV::NewHash
- Inherits:
-
Object
- Object
- 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
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(number) ⇒ NewHash
constructor
A new instance of NewHash.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(number) ⇒ NewHash
Returns a new instance of NewHash.
2284 2285 2286 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2284 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
2282 2283 2284 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2282 def number @number end |
Instance Method Details
#call(vm) ⇒ Object
2312 2313 2314 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2312 def call(vm) vm.push(vm.pop(number).each_slice(2).to_h) end |
#canonical ⇒ Object
2308 2309 2310 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2308 def canonical self end |
#disasm(fmt) ⇒ Object
2288 2289 2290 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2288 def disasm(fmt) fmt.instruction("newhash", [fmt.object(number)]) end |
#length ⇒ Object
2296 2297 2298 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2296 def length 2 end |
#pops ⇒ Object
2300 2301 2302 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2300 def pops number end |
#pushes ⇒ Object
2304 2305 2306 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2304 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2292 2293 2294 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2292 def to_a(_iseq) [:newhash, number] end |