Class: SyntaxTree::YARV::NewHash
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
def foo(key, value)
{ key => value }
end
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(number) ⇒ NewHash
Returns a new instance of NewHash.
2420
2421
2422
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2420
def initialize(number)
@number = number
end
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
2418
2419
2420
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2418
def number
@number
end
|
Instance Method Details
#==(other) ⇒ Object
2436
2437
2438
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2436
def ==(other)
other.is_a?(NewHash) && other.number == number
end
|
#call(vm) ⇒ Object
2452
2453
2454
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2452
def call(vm)
vm.push(vm.pop(number).each_slice(2).to_h)
end
|
#deconstruct_keys(_keys) ⇒ Object
2432
2433
2434
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2432
def deconstruct_keys(_keys)
{ number: number }
end
|
#disasm(fmt) ⇒ Object
2424
2425
2426
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2424
def disasm(fmt)
fmt.instruction("newhash", [fmt.object(number)])
end
|
#length ⇒ Object
2440
2441
2442
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2440
def length
2
end
|
#pops ⇒ Object
2444
2445
2446
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2444
def pops
number
end
|
#pushes ⇒ Object
2448
2449
2450
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2448
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
2428
2429
2430
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2428
def to_a(_iseq)
[:newhash, number]
end
|