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



3545
3546
3547
# File 'lib/syntax_tree/yarv/instructions.rb', line 3545

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3543
3544
3545
# File 'lib/syntax_tree/yarv/instructions.rb', line 3543

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



3573
3574
3575
# File 'lib/syntax_tree/yarv/instructions.rb', line 3573

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

#canonicalObject



3569
3570
3571
# File 'lib/syntax_tree/yarv/instructions.rb', line 3569

def canonical
  self
end

#disasm(fmt) ⇒ Object



3549
3550
3551
# File 'lib/syntax_tree/yarv/instructions.rb', line 3549

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

#lengthObject



3557
3558
3559
# File 'lib/syntax_tree/yarv/instructions.rb', line 3557

def length
  2
end

#popsObject



3561
3562
3563
# File 'lib/syntax_tree/yarv/instructions.rb', line 3561

def pops
  number
end

#pushesObject



3565
3566
3567
# File 'lib/syntax_tree/yarv/instructions.rb', line 3565

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3553
3554
3555
# File 'lib/syntax_tree/yarv/instructions.rb', line 3553

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