Class: SyntaxTree::YARV::InvokeBlock

Inherits:
Object
  • Object
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

Constructor Details

#initialize(calldata) ⇒ InvokeBlock



2221
2222
2223
# File 'lib/syntax_tree/yarv/instructions.rb', line 2221

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2219
2220
2221
# File 'lib/syntax_tree/yarv/instructions.rb', line 2219

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



2237
2238
2239
# File 'lib/syntax_tree/yarv/instructions.rb', line 2237

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

#call(vm) ⇒ Object



2257
2258
2259
# File 'lib/syntax_tree/yarv/instructions.rb', line 2257

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

#canonicalObject



2253
2254
2255
# File 'lib/syntax_tree/yarv/instructions.rb', line 2253

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



2233
2234
2235
# File 'lib/syntax_tree/yarv/instructions.rb', line 2233

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



2225
2226
2227
# File 'lib/syntax_tree/yarv/instructions.rb', line 2225

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

#lengthObject



2241
2242
2243
# File 'lib/syntax_tree/yarv/instructions.rb', line 2241

def length
  2
end

#popsObject



2245
2246
2247
# File 'lib/syntax_tree/yarv/instructions.rb', line 2245

def pops
  calldata.argc
end

#pushesObject



2249
2250
2251
# File 'lib/syntax_tree/yarv/instructions.rb', line 2249

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2229
2230
2231
# File 'lib/syntax_tree/yarv/instructions.rb', line 2229

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