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.



5213
5214
5215
# File 'lib/syntax_tree/yarv/instructions.rb', line 5213

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5211
5212
5213
# File 'lib/syntax_tree/yarv/instructions.rb', line 5211

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



5229
5230
5231
# File 'lib/syntax_tree/yarv/instructions.rb', line 5229

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

#call(vm) ⇒ Object



5245
5246
5247
# File 'lib/syntax_tree/yarv/instructions.rb', line 5245

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

#canonicalObject



5241
5242
5243
# File 'lib/syntax_tree/yarv/instructions.rb', line 5241

def canonical
  SetLocal.new(index, 0)
end

#deconstruct_keys(_keys) ⇒ Object



5225
5226
5227
# File 'lib/syntax_tree/yarv/instructions.rb', line 5225

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



5217
5218
5219
# File 'lib/syntax_tree/yarv/instructions.rb', line 5217

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

#lengthObject



5233
5234
5235
# File 'lib/syntax_tree/yarv/instructions.rb', line 5233

def length
  2
end

#popsObject



5237
5238
5239
# File 'lib/syntax_tree/yarv/instructions.rb', line 5237

def pops
  1
end

#to_a(iseq) ⇒ Object



5221
5222
5223
# File 'lib/syntax_tree/yarv/instructions.rb', line 5221

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