Class: SyntaxTree::YARV::GetSpecial

Inherits:
Object
  • Object
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

Constructor Details

#initialize(key, type) ⇒ GetSpecial

Returns a new instance of GetSpecial.



2106
2107
2108
2109
# File 'lib/syntax_tree/yarv/instructions.rb', line 2106

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



2104
2105
2106
# File 'lib/syntax_tree/yarv/instructions.rb', line 2104

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



2104
2105
2106
# File 'lib/syntax_tree/yarv/instructions.rb', line 2104

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



2123
2124
2125
# File 'lib/syntax_tree/yarv/instructions.rb', line 2123

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

#call(vm) ⇒ Object



2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
# File 'lib/syntax_tree/yarv/instructions.rb', line 2143

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

#canonicalObject



2139
2140
2141
# File 'lib/syntax_tree/yarv/instructions.rb', line 2139

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



2119
2120
2121
# File 'lib/syntax_tree/yarv/instructions.rb', line 2119

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

#disasm(fmt) ⇒ Object



2111
2112
2113
# File 'lib/syntax_tree/yarv/instructions.rb', line 2111

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

#lengthObject



2127
2128
2129
# File 'lib/syntax_tree/yarv/instructions.rb', line 2127

def length
  3
end

#popsObject



2131
2132
2133
# File 'lib/syntax_tree/yarv/instructions.rb', line 2131

def pops
  0
end

#pushesObject



2135
2136
2137
# File 'lib/syntax_tree/yarv/instructions.rb', line 2135

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2115
2116
2117
# File 'lib/syntax_tree/yarv/instructions.rb', line 2115

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