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



4884
4885
4886
# File 'lib/syntax_tree/yarv/instructions.rb', line 4884

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4882
4883
4884
# File 'lib/syntax_tree/yarv/instructions.rb', line 4882

def index
  @index
end

Instance Method Details

#call(vm) ⇒ Object



4912
4913
4914
# File 'lib/syntax_tree/yarv/instructions.rb', line 4912

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

#canonicalObject



4908
4909
4910
# File 'lib/syntax_tree/yarv/instructions.rb', line 4908

def canonical
  SetLocal.new(index, 0)
end

#disasm(fmt) ⇒ Object



4888
4889
4890
# File 'lib/syntax_tree/yarv/instructions.rb', line 4888

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

#lengthObject



4896
4897
4898
# File 'lib/syntax_tree/yarv/instructions.rb', line 4896

def length
  2
end

#popsObject



4900
4901
4902
# File 'lib/syntax_tree/yarv/instructions.rb', line 4900

def pops
  1
end

#pushesObject



4904
4905
4906
# File 'lib/syntax_tree/yarv/instructions.rb', line 4904

def pushes
  0
end

#to_a(iseq) ⇒ Object



4892
4893
4894
# File 'lib/syntax_tree/yarv/instructions.rb', line 4892

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