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.



6078
6079
6080
# File 'lib/syntax_tree/yarv/instructions.rb', line 6078

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



6076
6077
6078
# File 'lib/syntax_tree/yarv/instructions.rb', line 6076

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



6094
6095
6096
# File 'lib/syntax_tree/yarv/instructions.rb', line 6094

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

#call(vm) ⇒ Object



6114
6115
6116
# File 'lib/syntax_tree/yarv/instructions.rb', line 6114

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

#canonicalObject



6110
6111
6112
# File 'lib/syntax_tree/yarv/instructions.rb', line 6110

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



6090
6091
6092
# File 'lib/syntax_tree/yarv/instructions.rb', line 6090

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



6082
6083
6084
# File 'lib/syntax_tree/yarv/instructions.rb', line 6082

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

#lengthObject



6098
6099
6100
# File 'lib/syntax_tree/yarv/instructions.rb', line 6098

def length
  2
end

#popsObject



6102
6103
6104
# File 'lib/syntax_tree/yarv/instructions.rb', line 6102

def pops
  0
end

#pushesObject



6106
6107
6108
# File 'lib/syntax_tree/yarv/instructions.rb', line 6106

def pushes
  1
end

#to_a(_iseq) ⇒ Object



6086
6087
6088
# File 'lib/syntax_tree/yarv/instructions.rb', line 6086

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