Class: SyntaxTree::YARV::GetLocalWC1

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

Methods inherited from Instruction

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

Constructor Details

#initialize(index) ⇒ GetLocalWC1

Returns a new instance of GetLocalWC1.



1936
1937
1938
# File 'lib/syntax_tree/yarv/instructions.rb', line 1936

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1934
1935
1936
# File 'lib/syntax_tree/yarv/instructions.rb', line 1934

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



1952
1953
1954
# File 'lib/syntax_tree/yarv/instructions.rb', line 1952

def ==(other)
  other.is_a?(GetLocalWC1) && other.index == index
end

#call(vm) ⇒ Object



1968
1969
1970
# File 'lib/syntax_tree/yarv/instructions.rb', line 1968

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

#canonicalObject



1964
1965
1966
# File 'lib/syntax_tree/yarv/instructions.rb', line 1964

def canonical
  GetLocal.new(index, 1)
end

#deconstruct_keys(_keys) ⇒ Object



1948
1949
1950
# File 'lib/syntax_tree/yarv/instructions.rb', line 1948

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



1940
1941
1942
# File 'lib/syntax_tree/yarv/instructions.rb', line 1940

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

#lengthObject



1956
1957
1958
# File 'lib/syntax_tree/yarv/instructions.rb', line 1956

def length
  2
end

#pushesObject



1960
1961
1962
# File 'lib/syntax_tree/yarv/instructions.rb', line 1960

def pushes
  1
end

#to_a(iseq) ⇒ Object



1944
1945
1946
# File 'lib/syntax_tree/yarv/instructions.rb', line 1944

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