Sha256: 5a4ba53ee37a13f44dfa4631c8d4542c56ad8942e928d3d48eb4a520c43a7cdf

Contents?: true

Size: 493 Bytes

Versions: 3

Compression:

Stored size: 493 Bytes

Contents

# pops the top 2 items of the +:int+ stack;
# pushes a new ValuePoint onto the +:int+ stack with the largest of the two values
#
# *needs:* 2 +:int+
#
# *pushes:* 1 +:int+
#

class IntMaxInstruction < Instruction
  def preconditions?
    needs :int, 2
  end
  def setup
    @arg2 = @context.pop_value(:int)
    @arg1 = @context.pop_value(:int)
  end
  def derive
      @max = [@arg1,@arg2].max
      @result = ValuePoint.new("int", @max)
  end
  def cleanup
    pushes :int, @result
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nudge-0.2.9 lib/instructions/int/int_max.rb
nudge-0.2.8 lib/instructions/int/int_max.rb
nudge-0.2.7 lib/instructions/int/int_max.rb