Class: SyntaxTree::YARV::SetSpecial

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

Overview

### Summary

‘setspecial` pops a value off the top of the stack and sets a special local variable to that value. The special local variable is determined by the key given as its only argument.

### Usage

~~~ruby baz if (foo == 1) .. (bar == 1) ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(key) ⇒ SetSpecial

Returns a new instance of SetSpecial.



5528
5529
5530
# File 'lib/syntax_tree/yarv/instructions.rb', line 5528

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5526
5527
5528
# File 'lib/syntax_tree/yarv/instructions.rb', line 5526

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



5544
5545
5546
# File 'lib/syntax_tree/yarv/instructions.rb', line 5544

def ==(other)
  other.is_a?(SetSpecial) && other.key == key
end

#call(vm) ⇒ Object



5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
# File 'lib/syntax_tree/yarv/instructions.rb', line 5556

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

#deconstruct_keys(_keys) ⇒ Object



5540
5541
5542
# File 'lib/syntax_tree/yarv/instructions.rb', line 5540

def deconstruct_keys(_keys)
  { key: key }
end

#disasm(fmt) ⇒ Object



5532
5533
5534
# File 'lib/syntax_tree/yarv/instructions.rb', line 5532

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

#lengthObject



5548
5549
5550
# File 'lib/syntax_tree/yarv/instructions.rb', line 5548

def length
  2
end

#popsObject



5552
5553
5554
# File 'lib/syntax_tree/yarv/instructions.rb', line 5552

def pops
  1
end

#to_a(_iseq) ⇒ Object



5536
5537
5538
# File 'lib/syntax_tree/yarv/instructions.rb', line 5536

def to_a(_iseq)
  [:setspecial, key]
end