Class: SyntaxTree::YARV::GetBlockParamProxy

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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?

Constructor Details

#initialize(index, level) ⇒ GetBlockParamProxy

Returns a new instance of GetBlockParamProxy.



1544
1545
1546
1547
# File 'lib/syntax_tree/yarv/instructions.rb', line 1544

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1542
1543
1544
# File 'lib/syntax_tree/yarv/instructions.rb', line 1542

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1542
1543
1544
# File 'lib/syntax_tree/yarv/instructions.rb', line 1542

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



1566
1567
1568
1569
# File 'lib/syntax_tree/yarv/instructions.rb', line 1566

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

#call(vm) ⇒ Object



1579
1580
1581
# File 'lib/syntax_tree/yarv/instructions.rb', line 1579

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

#deconstruct_keys(_keys) ⇒ Object



1562
1563
1564
# File 'lib/syntax_tree/yarv/instructions.rb', line 1562

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

#disasm(fmt) ⇒ Object



1549
1550
1551
1552
1553
1554
# File 'lib/syntax_tree/yarv/instructions.rb', line 1549

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

#lengthObject



1571
1572
1573
# File 'lib/syntax_tree/yarv/instructions.rb', line 1571

def length
  3
end

#pushesObject



1575
1576
1577
# File 'lib/syntax_tree/yarv/instructions.rb', line 1575

def pushes
  1
end

#to_a(iseq) ⇒ Object



1556
1557
1558
1559
1560
# File 'lib/syntax_tree/yarv/instructions.rb', line 1556

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