Class: SyntaxTree::YARV::OptNewArrayMax

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

Overview

### Summary

opt_newarray_max is a specialization that occurs when the max method is called on an array literal. It pops the values of the array off the stack and pushes on the result.

### Usage

~~~ruby [a, b, c].max ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ OptNewArrayMax

Returns a new instance of OptNewArrayMax.



4050
4051
4052
# File 'lib/syntax_tree/yarv/instructions.rb', line 4050

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



4048
4049
4050
# File 'lib/syntax_tree/yarv/instructions.rb', line 4048

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



4066
4067
4068
# File 'lib/syntax_tree/yarv/instructions.rb', line 4066

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

#call(vm) ⇒ Object



4086
4087
4088
# File 'lib/syntax_tree/yarv/instructions.rb', line 4086

def call(vm)
  vm.push(vm.pop(number).max)
end

#canonicalObject



4082
4083
4084
# File 'lib/syntax_tree/yarv/instructions.rb', line 4082

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



4062
4063
4064
# File 'lib/syntax_tree/yarv/instructions.rb', line 4062

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



4054
4055
4056
# File 'lib/syntax_tree/yarv/instructions.rb', line 4054

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

#lengthObject



4070
4071
4072
# File 'lib/syntax_tree/yarv/instructions.rb', line 4070

def length
  2
end

#popsObject



4074
4075
4076
# File 'lib/syntax_tree/yarv/instructions.rb', line 4074

def pops
  number
end

#pushesObject



4078
4079
4080
# File 'lib/syntax_tree/yarv/instructions.rb', line 4078

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4058
4059
4060
# File 'lib/syntax_tree/yarv/instructions.rb', line 4058

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