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

Returns a new instance of InvokeBlock.



1970
1971
1972
# File 'lib/syntax_tree/yarv/instructions.rb', line 1970

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



1968
1969
1970
# File 'lib/syntax_tree/yarv/instructions.rb', line 1968

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



1998
1999
2000
# File 'lib/syntax_tree/yarv/instructions.rb', line 1998

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

#canonicalObject



1994
1995
1996
# File 'lib/syntax_tree/yarv/instructions.rb', line 1994

def canonical
  self
end

#disasm(fmt) ⇒ Object



1974
1975
1976
# File 'lib/syntax_tree/yarv/instructions.rb', line 1974

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

#lengthObject



1982
1983
1984
# File 'lib/syntax_tree/yarv/instructions.rb', line 1982

def length
  2
end

#popsObject



1986
1987
1988
# File 'lib/syntax_tree/yarv/instructions.rb', line 1986

def pops
  calldata.argc
end

#pushesObject



1990
1991
1992
# File 'lib/syntax_tree/yarv/instructions.rb', line 1990

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1978
1979
1980
# File 'lib/syntax_tree/yarv/instructions.rb', line 1978

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