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.



1440
1441
1442
1443
# File 'lib/syntax_tree/yarv/instructions.rb', line 1440

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1438
1439
1440
# File 'lib/syntax_tree/yarv/instructions.rb', line 1438

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1438
1439
1440
# File 'lib/syntax_tree/yarv/instructions.rb', line 1438

def level
  @level
end

Instance Method Details

#call(vm) ⇒ Object



1474
1475
1476
# File 'lib/syntax_tree/yarv/instructions.rb', line 1474

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

#canonicalObject



1470
1471
1472
# File 'lib/syntax_tree/yarv/instructions.rb', line 1470

def canonical
  self
end

#disasm(fmt) ⇒ Object



1445
1446
1447
1448
1449
1450
# File 'lib/syntax_tree/yarv/instructions.rb', line 1445

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

#lengthObject



1458
1459
1460
# File 'lib/syntax_tree/yarv/instructions.rb', line 1458

def length
  3
end

#popsObject



1462
1463
1464
# File 'lib/syntax_tree/yarv/instructions.rb', line 1462

def pops
  0
end

#pushesObject



1466
1467
1468
# File 'lib/syntax_tree/yarv/instructions.rb', line 1466

def pushes
  1
end

#to_a(iseq) ⇒ Object



1452
1453
1454
1455
1456
# File 'lib/syntax_tree/yarv/instructions.rb', line 1452

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