fix interpreter overflow issue

flag set for bigness, result reduced
tests for + and *
fixed fibs tests
This commit is contained in:
Torsten Ruger
2015-11-08 15:15:55 +02:00
parent 6ea698d397
commit d6108e7b3a
8 changed files with 73 additions and 33 deletions

View File

@ -1,5 +1,6 @@
require_relative "eventable"
require 'bigdecimal'
module Interpreter
class Interpreter
@ -174,10 +175,10 @@ module Interpreter
end
def execute_OperatorInstruction
log.debug @instruction
left = get_register(@instruction.left)
rr = @instruction.right
right = get_register(rr)
@flags[:overflow] = false
case @instruction.operator.to_s
when "+"
result = left + right
@ -193,8 +194,11 @@ module Interpreter
else
raise "unimplemented '#{@instruction.operator}' #{@instruction}"
end
## result not over 2**62 => overflow
log.debug "#{@instruction} == #{result} (#{left}|#{right})"
if( result.is_a? Bignum)
@flags[:overflow] = true
result = result % 2**62
end
log.debug "#{@instruction} == #{result}(#{result.class}) (#{left}|#{right})"
right = set_register(@instruction.left , result)
true
end