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.



1486
1487
1488
1489
# File 'lib/syntax_tree/yarv/instructions.rb', line 1486

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1484
1485
1486
# File 'lib/syntax_tree/yarv/instructions.rb', line 1484

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1484
1485
1486
# File 'lib/syntax_tree/yarv/instructions.rb', line 1484

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



1508
1509
1510
1511
# File 'lib/syntax_tree/yarv/instructions.rb', line 1508

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

#call(vm) ⇒ Object



1521
1522
1523
# File 'lib/syntax_tree/yarv/instructions.rb', line 1521

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

#deconstruct_keys(_keys) ⇒ Object



1504
1505
1506
# File 'lib/syntax_tree/yarv/instructions.rb', line 1504

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

#disasm(fmt) ⇒ Object



1491
1492
1493
1494
1495
1496
# File 'lib/syntax_tree/yarv/instructions.rb', line 1491

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

#lengthObject



1513
1514
1515
# File 'lib/syntax_tree/yarv/instructions.rb', line 1513

def length
  3
end

#pushesObject



1517
1518
1519
# File 'lib/syntax_tree/yarv/instructions.rb', line 1517

def pushes
  1
end

#to_a(iseq) ⇒ Object



1498
1499
1500
1501
1502
# File 'lib/syntax_tree/yarv/instructions.rb', line 1498

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