class SyntaxTree::YARV::Send

### Summary

‘send` invokes a method with an optional block. It pops its receiver and the arguments for the method off the stack and pushes the return value onto the stack. It has two arguments: the calldata for the call site and the optional block instruction sequence.

### Usage

~~~ruby “hello”.tap { |i| p i } ~~~

Attributes

block_iseq[R]
calldata[R]

Public Class Methods

new(calldata, block_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4824
def initialize(calldata, block_iseq)
  @calldata = calldata
  @block_iseq = block_iseq
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4845
def ==(other)
  other.is_a?(Send) && other.calldata == calldata &&
    other.block_iseq == block_iseq
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4863
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
    elsif calldata.flag?(CallData::CALL_ARGS_BLOCKARG)
      vm.pop
    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

  vm.push(
    receiver.__send__(calldata.method, *arguments, **keywords, &block)
  )
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4841
def deconstruct_keys(_keys)
  { calldata: calldata, block_iseq: block_iseq }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4829
def disasm(fmt)
  fmt.enqueue(block_iseq) if block_iseq
  fmt.instruction(
    "send",
    [fmt.calldata(calldata), block_iseq&.name || "nil"]
  )
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4850
def length
  3
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4854
def pops
  argb = (calldata.flag?(CallData::CALL_ARGS_BLOCKARG) ? 1 : 0)
  argb + calldata.argc + 1
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4859
def pushes
  1
end
to_a(_iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 4837
def to_a(_iseq)
  [:send, calldata.to_h, block_iseq&.to_a]
end