Class: SyntaxTree::YARV::GetLocal

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

Overview

### Summary

getlocal fetches the value of a local variable from a frame determined by the level and index arguments. The level is the number of frames back to look and the index is the index in the local table. It pushes the value it finds onto the stack.

### Usage

~~~ruby value = 5 tap { tap { value } } ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, level) ⇒ GetLocal

Returns a new instance of GetLocal.



1931
1932
1933
1934
# File 'lib/syntax_tree/yarv/instructions.rb', line 1931

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1929
1930
1931
# File 'lib/syntax_tree/yarv/instructions.rb', line 1929

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1929
1930
1931
# File 'lib/syntax_tree/yarv/instructions.rb', line 1929

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



1950
1951
1952
# File 'lib/syntax_tree/yarv/instructions.rb', line 1950

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

#call(vm) ⇒ Object



1970
1971
1972
# File 'lib/syntax_tree/yarv/instructions.rb', line 1970

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

#canonicalObject



1966
1967
1968
# File 'lib/syntax_tree/yarv/instructions.rb', line 1966

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



1946
1947
1948
# File 'lib/syntax_tree/yarv/instructions.rb', line 1946

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

#disasm(fmt) ⇒ Object



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

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

#lengthObject



1954
1955
1956
# File 'lib/syntax_tree/yarv/instructions.rb', line 1954

def length
  3
end

#popsObject



1958
1959
1960
# File 'lib/syntax_tree/yarv/instructions.rb', line 1958

def pops
  0
end

#pushesObject



1962
1963
1964
# File 'lib/syntax_tree/yarv/instructions.rb', line 1962

def pushes
  1
end

#to_a(iseq) ⇒ Object



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

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