Class: SyntaxTree::YARV::SetLocalWC1

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

Overview

### Summary

‘setlocal_WC_1` is a specialized version of the `setlocal` instruction. It sets the value of a local variable on the parent frame to the value at the top of the stack as determined by the index given as its only argument.

### Usage

~~~ruby value = 5 self.then { value = 10 } ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(index) ⇒ SetLocalWC1

Returns a new instance of SetLocalWC1.



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

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5423
5424
5425
# File 'lib/syntax_tree/yarv/instructions.rb', line 5423

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



5441
5442
5443
# File 'lib/syntax_tree/yarv/instructions.rb', line 5441

def ==(other)
  other.is_a?(SetLocalWC1) && other.index == index
end

#call(vm) ⇒ Object



5457
5458
5459
# File 'lib/syntax_tree/yarv/instructions.rb', line 5457

def call(vm)
  canonical.call(vm)
end

#canonicalObject



5453
5454
5455
# File 'lib/syntax_tree/yarv/instructions.rb', line 5453

def canonical
  SetLocal.new(index, 1)
end

#deconstruct_keys(_keys) ⇒ Object



5437
5438
5439
# File 'lib/syntax_tree/yarv/instructions.rb', line 5437

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



5429
5430
5431
# File 'lib/syntax_tree/yarv/instructions.rb', line 5429

def disasm(fmt)
  fmt.instruction("setlocal_WC_1", [fmt.local(index, implicit: 1)])
end

#lengthObject



5445
5446
5447
# File 'lib/syntax_tree/yarv/instructions.rb', line 5445

def length
  2
end

#popsObject



5449
5450
5451
# File 'lib/syntax_tree/yarv/instructions.rb', line 5449

def pops
  1
end

#to_a(iseq) ⇒ Object



5433
5434
5435
# File 'lib/syntax_tree/yarv/instructions.rb', line 5433

def to_a(iseq)
  [:setlocal_WC_1, iseq.parent_iseq.local_table.offset(index)]
end