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.



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

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5327
5328
5329
# File 'lib/syntax_tree/yarv/instructions.rb', line 5327

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



5361
5362
5363
# File 'lib/syntax_tree/yarv/instructions.rb', line 5361

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

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  2
end

#popsObject



5353
5354
5355
# File 'lib/syntax_tree/yarv/instructions.rb', line 5353

def pops
  1
end

#pushesObject



5357
5358
5359
# File 'lib/syntax_tree/yarv/instructions.rb', line 5357

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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