Class: SyntaxTree::YARV::TopN

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

Overview

### Summary

topn pushes a single value onto the stack that is a copy of the value within the stack that is number of slots down from the top.

### Usage

~~~ruby case 3 when 1..5

puts "foo"

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ TopN

Returns a new instance of TopN.



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

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



5293
5294
5295
# File 'lib/syntax_tree/yarv/instructions.rb', line 5293

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



5323
5324
5325
# File 'lib/syntax_tree/yarv/instructions.rb', line 5323

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

#canonicalObject



5319
5320
5321
# File 'lib/syntax_tree/yarv/instructions.rb', line 5319

def canonical
  self
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



5307
5308
5309
# File 'lib/syntax_tree/yarv/instructions.rb', line 5307

def length
  2
end

#popsObject



5311
5312
5313
# File 'lib/syntax_tree/yarv/instructions.rb', line 5311

def pops
  0
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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