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.



2142
2143
2144
# File 'lib/syntax_tree/yarv/instructions.rb', line 2142

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2140
2141
2142
# File 'lib/syntax_tree/yarv/instructions.rb', line 2140

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2158
2159
2160
# File 'lib/syntax_tree/yarv/instructions.rb', line 2158

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

#call(vm) ⇒ Object



2174
2175
2176
# File 'lib/syntax_tree/yarv/instructions.rb', line 2174

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

#deconstruct_keys(_keys) ⇒ Object



2154
2155
2156
# File 'lib/syntax_tree/yarv/instructions.rb', line 2154

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2146
2147
2148
# File 'lib/syntax_tree/yarv/instructions.rb', line 2146

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

#lengthObject



2162
2163
2164
# File 'lib/syntax_tree/yarv/instructions.rb', line 2162

def length
  2
end

#popsObject



2166
2167
2168
# File 'lib/syntax_tree/yarv/instructions.rb', line 2166

def pops
  calldata.argc
end

#pushesObject



2170
2171
2172
# File 'lib/syntax_tree/yarv/instructions.rb', line 2170

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2150
2151
2152
# File 'lib/syntax_tree/yarv/instructions.rb', line 2150

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