Class: IntMultiplyInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/int/int_multiply.rb

Overview

pops the top 2 items of the :int stack; pushes a ValuePoint with their product onto the :int stack

needs: 2 :int

pushes: 1 :int

Instance Attribute Summary

Attributes inherited from Instruction

#context

Instance Method Summary collapse

Methods inherited from Instruction

all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode

Constructor Details

This class inherits a constructor from Instruction

Instance Method Details

#cleanupObject



20
21
22
# File 'lib/instructions/int/int_multiply.rb', line 20

def cleanup
  pushes :int, @result
end

#deriveObject



17
18
19
# File 'lib/instructions/int/int_multiply.rb', line 17

def derive
  @result = ValuePoint.new("int", @arg1 * @arg2)
end

#preconditions?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/instructions/int/int_multiply.rb', line 10

def preconditions?
  needs :int, 2
end

#setupObject



13
14
15
16
# File 'lib/instructions/int/int_multiply.rb', line 13

def setup
  @arg1 = @context.pop_value(:int)
  @arg2 = @context.pop_value(:int)
end