adding integer compare tests and fixing returns

true, false and nll were not handled correctly as returns
returns assume int, and reduce. The solution (hack?) is to add fake numbers into true,false and nil that get returned from from the arm syscall
(and it works!, which means i can fix other tests now)
This commit is contained in:
Torsten 2020-03-28 18:41:59 +02:00
parent 8dfcc0f5de
commit a3effe29f6
2 changed files with 81 additions and 7 deletions

View File

@ -155,7 +155,17 @@ module Risc
def write_data4( code )
write_ref_for( code.get_type )
write_ref_for( code.get_type )
write_ref_for( code.get_type )
case code
when Parfait::NilClass , nil
fake_int = 0
when Parfait::TrueClass , true
fake_int = 1
when Parfait::FalseClass , false
fake_int = 0
else
fake_int = code.get_type
end
write_ref_for( fake_int )
write_ref_for( code.get_type )
log.debug "Data4 witten stream 0x#{@stream.length.to_s(16)}"
end
@ -202,15 +212,19 @@ module Risc
# write means we write the resulting address straight into the assembler stream
# object means the object of which we write the address
def write_ref_for object
def write_ref_for( object )
if(object.is_a?( ::Integer) )
return @stream.write_signed_int_32(object)
end
case object
when nil
@stream.write_signed_int_32(0)
when ::Integer
@stream.write_signed_int_32(object)
else
@stream.write_signed_int_32(Position.get(object) + @linker.platform.loaded_at)
object = Parfait.object_space.nil_object
when true
object = Parfait.object_space.true_object
when false
object = Parfait.object_space.nil_object
end
@stream.write_signed_int_32(Position.get(object) + @linker.platform.loaded_at)
end
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary

View File

@ -0,0 +1,60 @@
require_relative "helper"
module Mains
class CompareTester < MiniTest::Test
include MainsHelper
def setup
super
@preload = [:le,:ge,:gt,:lt].collect{|op| "Integer.#{op}"}.join(";")
end
def test_smaller_true
run_main_return "4 < 5"
assert_result 1 , ""
end
def test_smaller_false
run_main_return "6 < 5"
assert_result 0 , ""
end
def test_smaller_false_same
run_main_return "5 < 5"
assert_result 0 , ""
end
def test_larger_true
run_main_return "5 > 4"
assert_result 1 , ""
end
def test_larger_false
run_main_return "5 > 6"
assert_result 0 , ""
end
def test_larger_false_same
run_main_return "5 > 5"
assert_result 0 , ""
end
def test_smaller_or_true
run_main_return "4 <= 5"
assert_result 1 , ""
end
def test_smaller_or_false
run_main_return "6 <= 5"
assert_result 0 , ""
end
def test_smaller_or_same
run_main_return "5 <= 5"
assert_result 1 , ""
end
def test_larger_or_true
run_main_return "5 >= 4"
assert_result 1 , ""
end
def test_larger_or_false
run_main_return "5 >= 6"
assert_result 0 , ""
end
def test_larger_or_same
run_main_return "5 >= 5"
assert_result 1 , ""
end
end
end