Class: SyntaxTree::YARV::SetLocalWC0

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

Overview

### Summary

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

### Usage

~~~ruby value = 5 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(index) ⇒ SetLocalWC0

Returns a new instance of SetLocalWC0.



5372
5373
5374
# File 'lib/syntax_tree/yarv/instructions.rb', line 5372

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5370
5371
5372
# File 'lib/syntax_tree/yarv/instructions.rb', line 5370

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



5388
5389
5390
# File 'lib/syntax_tree/yarv/instructions.rb', line 5388

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

#call(vm) ⇒ Object



5404
5405
5406
# File 'lib/syntax_tree/yarv/instructions.rb', line 5404

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

#canonicalObject



5400
5401
5402
# File 'lib/syntax_tree/yarv/instructions.rb', line 5400

def canonical
  SetLocal.new(index, 0)
end

#deconstruct_keys(_keys) ⇒ Object



5384
5385
5386
# File 'lib/syntax_tree/yarv/instructions.rb', line 5384

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



5376
5377
5378
# File 'lib/syntax_tree/yarv/instructions.rb', line 5376

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

#lengthObject



5392
5393
5394
# File 'lib/syntax_tree/yarv/instructions.rb', line 5392

def length
  2
end

#popsObject



5396
5397
5398
# File 'lib/syntax_tree/yarv/instructions.rb', line 5396

def pops
  1
end

#to_a(iseq) ⇒ Object



5380
5381
5382
# File 'lib/syntax_tree/yarv/instructions.rb', line 5380

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