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.



5427
5428
5429
# File 'lib/syntax_tree/yarv/instructions.rb', line 5427

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5425
5426
5427
# File 'lib/syntax_tree/yarv/instructions.rb', line 5425

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



5443
5444
5445
# File 'lib/syntax_tree/yarv/instructions.rb', line 5443

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

#call(vm) ⇒ Object



5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
# File 'lib/syntax_tree/yarv/instructions.rb', line 5455

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



5439
5440
5441
# File 'lib/syntax_tree/yarv/instructions.rb', line 5439

def deconstruct_keys(_keys)
  { key: key }
end

#disasm(fmt) ⇒ Object



5431
5432
5433
# File 'lib/syntax_tree/yarv/instructions.rb', line 5431

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

#lengthObject



5447
5448
5449
# File 'lib/syntax_tree/yarv/instructions.rb', line 5447

def length
  2
end

#popsObject



5451
5452
5453
# File 'lib/syntax_tree/yarv/instructions.rb', line 5451

def pops
  1
end

#to_a(_iseq) ⇒ Object



5435
5436
5437
# File 'lib/syntax_tree/yarv/instructions.rb', line 5435

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