Class: SyntaxTree::YARV::InvokeBlock
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::InvokeBlock
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
invokeblock invokes the block given to the current method. It pops the arguments for the block off the stack and pushes the result of running the block onto the stack.
### Usage
~~~ruby def foo
yield
end ~~~
Instance Attribute Summary collapse
-
#calldata ⇒ Object
readonly
Returns the value of attribute calldata.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(calldata) ⇒ InvokeBlock
constructor
A new instance of InvokeBlock.
- #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(calldata) ⇒ InvokeBlock
Returns a new instance of InvokeBlock.
2031 2032 2033 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2031 def initialize(calldata) @calldata = calldata end |
Instance Attribute Details
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
2029 2030 2031 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2029 def calldata @calldata end |
Instance Method Details
#==(other) ⇒ Object
2047 2048 2049 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2047 def ==(other) other.is_a?(InvokeBlock) && other.calldata == calldata end |
#call(vm) ⇒ Object
2063 2064 2065 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2063 def call(vm) vm.push(vm.frame_yield.block.call(*vm.pop(calldata.argc))) end |
#deconstruct_keys(_keys) ⇒ Object
2043 2044 2045 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2043 def deconstruct_keys(_keys) { calldata: calldata } end |
#disasm(fmt) ⇒ Object
2035 2036 2037 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2035 def disasm(fmt) fmt.instruction("invokeblock", [fmt.calldata(calldata)]) end |
#length ⇒ Object
2051 2052 2053 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2051 def length 2 end |
#pops ⇒ Object
2055 2056 2057 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2055 def pops calldata.argc end |
#pushes ⇒ Object
2059 2060 2061 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2059 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2039 2040 2041 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2039 def to_a(_iseq) [:invokeblock, calldata.to_h] end |