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.



5271
5272
5273
# File 'lib/syntax_tree/yarv/instructions.rb', line 5271

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5269
5270
5271
# File 'lib/syntax_tree/yarv/instructions.rb', line 5269

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object



5287
5288
5289
# File 'lib/syntax_tree/yarv/instructions.rb', line 5287

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

#call(vm) ⇒ Object



5303
5304
5305
# File 'lib/syntax_tree/yarv/instructions.rb', line 5303

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

#canonicalObject



5299
5300
5301
# File 'lib/syntax_tree/yarv/instructions.rb', line 5299

def canonical
  SetLocal.new(index, 0)
end

#deconstruct_keys(_keys) ⇒ Object



5283
5284
5285
# File 'lib/syntax_tree/yarv/instructions.rb', line 5283

def deconstruct_keys(_keys)
  { index: index }
end

#disasm(fmt) ⇒ Object



5275
5276
5277
# File 'lib/syntax_tree/yarv/instructions.rb', line 5275

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

#lengthObject



5291
5292
5293
# File 'lib/syntax_tree/yarv/instructions.rb', line 5291

def length
  2
end

#popsObject



5295
5296
5297
# File 'lib/syntax_tree/yarv/instructions.rb', line 5295

def pops
  1
end

#to_a(iseq) ⇒ Object



5279
5280
5281
# File 'lib/syntax_tree/yarv/instructions.rb', line 5279

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