Class: SyntaxTree::YARV::GetLocalWC1

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

Overview

### Summary

getlocal_WC_1 is a specialized version of the getlocal instruction. It fetches the value of a local variable from the parent frame determined by the index given as its only argument.

### Usage

~~~ruby value = 5 self.then { value } ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ GetLocalWC1

Returns a new instance of GetLocalWC1.



1821
1822
1823
# File 'lib/syntax_tree/yarv/instructions.rb', line 1821

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1819
1820
1821
# File 'lib/syntax_tree/yarv/instructions.rb', line 1819

def index
  @index
end

Instance Method Details

#call(vm) ⇒ Object



1849
1850
1851
# File 'lib/syntax_tree/yarv/instructions.rb', line 1849

def call(vm)
  canonical.call(vm)
end

#canonicalObject



1845
1846
1847
# File 'lib/syntax_tree/yarv/instructions.rb', line 1845

def canonical
  GetLocal.new(index, 1)
end

#disasm(fmt) ⇒ Object



1825
1826
1827
# File 'lib/syntax_tree/yarv/instructions.rb', line 1825

def disasm(fmt)
  fmt.instruction("getlocal_WC_1", [fmt.local(index, implicit: 1)])
end

#lengthObject



1833
1834
1835
# File 'lib/syntax_tree/yarv/instructions.rb', line 1833

def length
  2
end

#popsObject



1837
1838
1839
# File 'lib/syntax_tree/yarv/instructions.rb', line 1837

def pops
  0
end

#pushesObject



1841
1842
1843
# File 'lib/syntax_tree/yarv/instructions.rb', line 1841

def pushes
  1
end

#to_a(iseq) ⇒ Object



1829
1830
1831
# File 'lib/syntax_tree/yarv/instructions.rb', line 1829

def to_a(iseq)
  [:getlocal_WC_1, iseq.parent_iseq.local_table.offset(index)]
end