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.



1989
1990
1991
# File 'lib/syntax_tree/yarv/instructions.rb', line 1989

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1987
1988
1989
# File 'lib/syntax_tree/yarv/instructions.rb', line 1987

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



2005
2006
2007
# File 'lib/syntax_tree/yarv/instructions.rb', line 2005

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

#call(vm) ⇒ Object



2021
2022
2023
# File 'lib/syntax_tree/yarv/instructions.rb', line 2021

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

#canonicalObject



2017
2018
2019
# File 'lib/syntax_tree/yarv/instructions.rb', line 2017

def canonical
  GetLocal.new(index, 1)
end

#deconstruct_keys(_keys) ⇒ Object



2001
2002
2003
# File 'lib/syntax_tree/yarv/instructions.rb', line 2001

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



1993
1994
1995
# File 'lib/syntax_tree/yarv/instructions.rb', line 1993

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

#lengthObject



2009
2010
2011
# File 'lib/syntax_tree/yarv/instructions.rb', line 2009

def length
  2
end

#pushesObject



2013
2014
2015
# File 'lib/syntax_tree/yarv/instructions.rb', line 2013

def pushes
  1
end

#to_a(iseq) ⇒ Object



1997
1998
1999
# File 'lib/syntax_tree/yarv/instructions.rb', line 1997

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