Class: SyntaxTree::YARV::SetN

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

Overview

### Summary

setn sets a value in the stack to a value popped off the top of the stack. It then pushes that value onto the top of the stack as well.

### Usage

~~~ruby = ‘val’ ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(number) ⇒ SetN

Returns a new instance of SetN.



5317
5318
5319
# File 'lib/syntax_tree/yarv/instructions.rb', line 5317

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5315
5316
5317
# File 'lib/syntax_tree/yarv/instructions.rb', line 5315

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



5333
5334
5335
# File 'lib/syntax_tree/yarv/instructions.rb', line 5333

def ==(other)
  other.is_a?(SetN) && other.number == number
end

#call(vm) ⇒ Object



5349
5350
5351
# File 'lib/syntax_tree/yarv/instructions.rb', line 5349

def call(vm)
  vm.stack[-number - 1] = vm.stack.last
end

#deconstruct_keys(_keys) ⇒ Object



5329
5330
5331
# File 'lib/syntax_tree/yarv/instructions.rb', line 5329

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



5321
5322
5323
# File 'lib/syntax_tree/yarv/instructions.rb', line 5321

def disasm(fmt)
  fmt.instruction("setn", [fmt.object(number)])
end

#lengthObject



5337
5338
5339
# File 'lib/syntax_tree/yarv/instructions.rb', line 5337

def length
  2
end

#popsObject



5341
5342
5343
# File 'lib/syntax_tree/yarv/instructions.rb', line 5341

def pops
  1
end

#pushesObject



5345
5346
5347
# File 'lib/syntax_tree/yarv/instructions.rb', line 5345

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5325
5326
5327
# File 'lib/syntax_tree/yarv/instructions.rb', line 5325

def to_a(_iseq)
  [:setn, number]
end