Class: SyntaxTree::YARV::GetSpecial

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

Overview

### Summary

‘getspecial` pushes the value of a special local variable onto the stack.

### Usage

~~~ruby 1 if (a == 1) .. (b == 2) ~~~

Constant Summary collapse

SVAR_LASTLINE =

$_

0
SVAR_BACKREF =

$~

1
SVAR_FLIPFLOP_START =

flipflop

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(key, type) ⇒ GetSpecial

Returns a new instance of GetSpecial.



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

def initialize(key, type)
  @key = key
  @type = type
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



2007
2008
2009
# File 'lib/syntax_tree/yarv/instructions.rb', line 2007

def ==(other)
  other.is_a?(GetSpecial) && other.key == key && other.type == type
end

#call(vm) ⇒ Object



2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
# File 'lib/syntax_tree/yarv/instructions.rb', line 2019

def call(vm)
  case key
  when SVAR_LASTLINE
    raise NotImplementedError, "getspecial SVAR_LASTLINE"
  when SVAR_BACKREF
    raise NotImplementedError, "getspecial SVAR_BACKREF"
  when SVAR_FLIPFLOP_START
    vm.frame_svar.svars[SVAR_FLIPFLOP_START]
  end
end

#deconstruct_keys(_keys) ⇒ Object



2003
2004
2005
# File 'lib/syntax_tree/yarv/instructions.rb', line 2003

def deconstruct_keys(_keys)
  { key: key, type: type }
end

#disasm(fmt) ⇒ Object



1995
1996
1997
# File 'lib/syntax_tree/yarv/instructions.rb', line 1995

def disasm(fmt)
  fmt.instruction("getspecial", [fmt.object(key), fmt.object(type)])
end

#lengthObject



2011
2012
2013
# File 'lib/syntax_tree/yarv/instructions.rb', line 2011

def length
  3
end

#pushesObject



2015
2016
2017
# File 'lib/syntax_tree/yarv/instructions.rb', line 2015

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1999
2000
2001
# File 'lib/syntax_tree/yarv/instructions.rb', line 1999

def to_a(_iseq)
  [:getspecial, key, type]
end