Class: SyntaxTree::YARV::InvokeBlock

Inherits:
Instruction show all
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

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(calldata) ⇒ InvokeBlock

Returns a new instance of InvokeBlock.



2089
2090
2091
# File 'lib/syntax_tree/yarv/instructions.rb', line 2089

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2087
2088
2089
# File 'lib/syntax_tree/yarv/instructions.rb', line 2087

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2105
2106
2107
# File 'lib/syntax_tree/yarv/instructions.rb', line 2105

def ==(other)
  other.is_a?(InvokeBlock) && other.calldata == calldata
end

#call(vm) ⇒ Object



2121
2122
2123
# File 'lib/syntax_tree/yarv/instructions.rb', line 2121

def call(vm)
  vm.push(vm.frame_yield.block.call(*vm.pop(calldata.argc)))
end

#deconstruct_keys(_keys) ⇒ Object



2101
2102
2103
# File 'lib/syntax_tree/yarv/instructions.rb', line 2101

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2093
2094
2095
# File 'lib/syntax_tree/yarv/instructions.rb', line 2093

def disasm(fmt)
  fmt.instruction("invokeblock", [fmt.calldata(calldata)])
end

#lengthObject



2109
2110
2111
# File 'lib/syntax_tree/yarv/instructions.rb', line 2109

def length
  2
end

#popsObject



2113
2114
2115
# File 'lib/syntax_tree/yarv/instructions.rb', line 2113

def pops
  calldata.argc
end

#pushesObject



2117
2118
2119
# File 'lib/syntax_tree/yarv/instructions.rb', line 2117

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2097
2098
2099
# File 'lib/syntax_tree/yarv/instructions.rb', line 2097

def to_a(_iseq)
  [:invokeblock, calldata.to_h]
end