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.



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

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
# File 'lib/syntax_tree/yarv/instructions.rb', line 1961

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



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

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

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  3
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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