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



2043
2044
2045
2046
# File 'lib/syntax_tree/yarv/instructions.rb', line 2043

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



2041
2042
2043
# File 'lib/syntax_tree/yarv/instructions.rb', line 2041

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



2041
2042
2043
# File 'lib/syntax_tree/yarv/instructions.rb', line 2041

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



2060
2061
2062
# File 'lib/syntax_tree/yarv/instructions.rb', line 2060

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

#call(vm) ⇒ Object



2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
# File 'lib/syntax_tree/yarv/instructions.rb', line 2072

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



2056
2057
2058
# File 'lib/syntax_tree/yarv/instructions.rb', line 2056

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

#disasm(fmt) ⇒ Object



2048
2049
2050
# File 'lib/syntax_tree/yarv/instructions.rb', line 2048

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

#lengthObject



2064
2065
2066
# File 'lib/syntax_tree/yarv/instructions.rb', line 2064

def length
  3
end

#pushesObject



2068
2069
2070
# File 'lib/syntax_tree/yarv/instructions.rb', line 2068

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2052
2053
2054
# File 'lib/syntax_tree/yarv/instructions.rb', line 2052

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