Class: SyntaxTree::YARV::InvokeSuper
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::InvokeSuper
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
invokesuper is similar to the send instruction, except that it calls the super method. It pops the receiver and arguments off the stack and pushes the return value onto the stack.
### Usage
~~~ruby def foo
super
end ~~~
Instance Attribute Summary collapse
-
#block_iseq ⇒ Object
readonly
Returns the value of attribute block_iseq.
-
#calldata ⇒ Object
readonly
Returns the value of attribute calldata.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(calldata, block_iseq) ⇒ InvokeSuper
constructor
A new instance of InvokeSuper.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(calldata, block_iseq) ⇒ InvokeSuper
Returns a new instance of InvokeSuper.
2020 2021 2022 2023 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2020 def initialize(calldata, block_iseq) @calldata = calldata @block_iseq = block_iseq end |
Instance Attribute Details
#block_iseq ⇒ Object (readonly)
Returns the value of attribute block_iseq.
2018 2019 2020 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2018 def block_iseq @block_iseq end |
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
2018 2019 2020 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2018 def calldata @calldata end |
Instance Method Details
#call(vm) ⇒ Object
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2054 def call(vm) block = if (iseq = block_iseq) frame = vm.frame ->(*args, **kwargs, &blk) do vm.run_block_frame(iseq, frame, *args, **kwargs, &blk) end end keywords = if calldata.kw_arg calldata.kw_arg.zip(vm.pop(calldata.kw_arg.length)).to_h else {} end arguments = vm.pop(calldata.argc) receiver = vm.pop method = receiver.method(vm.frame.name).super_method vm.push(method.call(*arguments, **keywords, &block)) end |
#canonical ⇒ Object
2050 2051 2052 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2050 def canonical self end |
#disasm(fmt) ⇒ Object
2025 2026 2027 2028 2029 2030 2031 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2025 def disasm(fmt) fmt.enqueue(block_iseq) if block_iseq fmt.instruction( "invokesuper", [fmt.calldata(calldata), block_iseq&.name || "nil"] ) end |
#length ⇒ Object
2037 2038 2039 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2037 def length 1 end |
#pops ⇒ Object
2041 2042 2043 2044 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2041 def pops argb = (calldata.flag?(CallData::CALL_ARGS_BLOCKARG) ? 1 : 0) argb + calldata.argc + 1 end |
#pushes ⇒ Object
2046 2047 2048 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2046 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2033 2034 2035 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2033 def to_a(_iseq) [:invokesuper, calldata.to_h, block_iseq&.to_a] end |