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
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ 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.
2279 2280 2281 2282 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2279 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.
2277 2278 2279 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2277 def block_iseq @block_iseq end |
#calldata ⇒ Object (readonly)
Returns the value of attribute calldata.
2277 2278 2279 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2277 def calldata @calldata end |
Instance Method Details
#==(other) ⇒ Object
2300 2301 2302 2303 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2300 def ==(other) other.is_a?(InvokeSuper) && other.calldata == calldata && other.block_iseq == block_iseq end |
#call(vm) ⇒ Object
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2322 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
2318 2319 2320 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2318 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
2296 2297 2298 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2296 def deconstruct_keys(_keys) { calldata: calldata, block_iseq: block_iseq } end |
#disasm(fmt) ⇒ Object
2284 2285 2286 2287 2288 2289 2290 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2284 def disasm(fmt) fmt.enqueue(block_iseq) if block_iseq fmt.instruction( "invokesuper", [fmt.calldata(calldata), block_iseq&.name || "nil"] ) end |
#length ⇒ Object
2305 2306 2307 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2305 def length 1 end |
#pops ⇒ Object
2309 2310 2311 2312 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2309 def pops argb = (calldata.flag?(CallData::CALL_ARGS_BLOCKARG) ? 1 : 0) argb + calldata.argc + 1 end |
#pushes ⇒ Object
2314 2315 2316 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2314 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2292 2293 2294 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2292 def to_a(_iseq) [:invokesuper, calldata.to_h, block_iseq&.to_a] end |