Class: SyntaxTree::YARV::GetBlockParamProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

getblockparamproxy is almost the same as getblockparam except that it pushes a proxy object onto the stack instead of the actual value of the block local. This is used when a method is being called on the block local.

### Usage

~~~ruby def foo(&block)

block.call

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, level) ⇒ GetBlockParamProxy

Returns a new instance of GetBlockParamProxy.



1608
1609
1610
1611
# File 'lib/syntax_tree/yarv/instructions.rb', line 1608

def initialize(index, level)
  @index = index
  @level = level
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1606
1607
1608
# File 'lib/syntax_tree/yarv/instructions.rb', line 1606

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1606
1607
1608
# File 'lib/syntax_tree/yarv/instructions.rb', line 1606

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



1630
1631
1632
1633
# File 'lib/syntax_tree/yarv/instructions.rb', line 1630

def ==(other)
  other.is_a?(GetBlockParamProxy) && other.index == index &&
    other.level == level
end

#call(vm) ⇒ Object



1651
1652
1653
# File 'lib/syntax_tree/yarv/instructions.rb', line 1651

def call(vm)
  vm.push(vm.local_get(index, level))
end

#canonicalObject



1647
1648
1649
# File 'lib/syntax_tree/yarv/instructions.rb', line 1647

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



1626
1627
1628
# File 'lib/syntax_tree/yarv/instructions.rb', line 1626

def deconstruct_keys(_keys)
  { index: index, level: level }
end

#disasm(fmt) ⇒ Object



1613
1614
1615
1616
1617
1618
# File 'lib/syntax_tree/yarv/instructions.rb', line 1613

def disasm(fmt)
  fmt.instruction(
    "getblockparamproxy",
    [fmt.local(index, explicit: level)]
  )
end

#lengthObject



1635
1636
1637
# File 'lib/syntax_tree/yarv/instructions.rb', line 1635

def length
  3
end

#popsObject



1639
1640
1641
# File 'lib/syntax_tree/yarv/instructions.rb', line 1639

def pops
  0
end

#pushesObject



1643
1644
1645
# File 'lib/syntax_tree/yarv/instructions.rb', line 1643

def pushes
  1
end

#to_a(iseq) ⇒ Object



1620
1621
1622
1623
1624
# File 'lib/syntax_tree/yarv/instructions.rb', line 1620

def to_a(iseq)
  current = iseq
  level.times { current = iseq.parent_iseq }
  [:getblockparamproxy, current.local_table.offset(index), level]
end