Class: SyntaxTree::YARV::SetLocalWC0

Inherits:
Object
  • Object
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

Constructor Details

#initialize(index) ⇒ SetLocalWC0

Returns a new instance of SetLocalWC0.



5611
5612
5613
# File 'lib/syntax_tree/yarv/instructions.rb', line 5611

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5609
5610
5611
# File 'lib/syntax_tree/yarv/instructions.rb', line 5609

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



5627
5628
5629
# File 'lib/syntax_tree/yarv/instructions.rb', line 5627

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

#call(vm) ⇒ Object



5647
5648
5649
# File 'lib/syntax_tree/yarv/instructions.rb', line 5647

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

#canonicalObject



5643
5644
5645
# File 'lib/syntax_tree/yarv/instructions.rb', line 5643

def canonical
  SetLocal.new(index, 0)
end

#deconstruct_keys(_keys) ⇒ Object



5623
5624
5625
# File 'lib/syntax_tree/yarv/instructions.rb', line 5623

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



5615
5616
5617
# File 'lib/syntax_tree/yarv/instructions.rb', line 5615

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

#lengthObject



5631
5632
5633
# File 'lib/syntax_tree/yarv/instructions.rb', line 5631

def length
  2
end

#popsObject



5635
5636
5637
# File 'lib/syntax_tree/yarv/instructions.rb', line 5635

def pops
  1
end

#pushesObject



5639
5640
5641
# File 'lib/syntax_tree/yarv/instructions.rb', line 5639

def pushes
  0
end

#to_a(iseq) ⇒ Object



5619
5620
5621
# File 'lib/syntax_tree/yarv/instructions.rb', line 5619

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