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.



5375
5376
5377
# File 'lib/syntax_tree/yarv/instructions.rb', line 5375

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5373
5374
5375
# File 'lib/syntax_tree/yarv/instructions.rb', line 5373

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



5391
5392
5393
# File 'lib/syntax_tree/yarv/instructions.rb', line 5391

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

#call(vm) ⇒ Object



5407
5408
5409
# File 'lib/syntax_tree/yarv/instructions.rb', line 5407

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

#deconstruct_keys(_keys) ⇒ Object



5387
5388
5389
# File 'lib/syntax_tree/yarv/instructions.rb', line 5387

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



5379
5380
5381
# File 'lib/syntax_tree/yarv/instructions.rb', line 5379

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

#lengthObject



5395
5396
5397
# File 'lib/syntax_tree/yarv/instructions.rb', line 5395

def length
  2
end

#popsObject



5399
5400
5401
# File 'lib/syntax_tree/yarv/instructions.rb', line 5399

def pops
  1
end

#pushesObject



5403
5404
5405
# File 'lib/syntax_tree/yarv/instructions.rb', line 5403

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5383
5384
5385
# File 'lib/syntax_tree/yarv/instructions.rb', line 5383

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