finish truth check (green again)
some (basic) if tests
This commit is contained in:
parent
8bac096f74
commit
2c6ea7ea46
@ -20,6 +20,9 @@ module Mom
|
|||||||
false_load = SlotDefinition.new( FalseConstant.new , nil ).to_register(compiler,self)
|
false_load = SlotDefinition.new( FalseConstant.new , nil ).to_register(compiler,self)
|
||||||
left << false_load
|
left << false_load
|
||||||
left << Risc::IsSame.new(self , left.register , false_load.register , false_label)
|
left << Risc::IsSame.new(self , left.register , false_load.register , false_label)
|
||||||
|
nil_load = SlotDefinition.new( NilConstant.new , nil ).to_register(compiler,self)
|
||||||
|
left << nil_load
|
||||||
|
left << Risc::IsSame.new(self , left.register , nil_load.register , false_label)
|
||||||
left
|
left
|
||||||
end
|
end
|
||||||
|
|
||||||
|
51
test/mom/test_if_else.rb
Normal file
51
test/mom/test_if_else.rb
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestIfElse < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "if(@a) ; arg = 5 ; else; arg = 6; end"
|
||||||
|
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, LoadConstant, IsSame ,
|
||||||
|
Label, LoadConstant, SlotToReg, RegToSlot, Label, Label ,
|
||||||
|
LoadConstant, SlotToReg, RegToSlot, Label]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_if_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_false_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal Mom::FalseConstant , produced.next(2).constant.known_object.class
|
||||||
|
end
|
||||||
|
def test_false_check
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(11) , produced.next(3).label
|
||||||
|
end
|
||||||
|
def test_nil_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal Mom::NilConstant , produced.next(4).constant.known_object.class
|
||||||
|
end
|
||||||
|
def test_nil_check
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(11) , produced.next(5).label
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_true_label
|
||||||
|
produced = produce_body
|
||||||
|
assert produced.next(6).name.start_with?("true_label")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_merge_label
|
||||||
|
produced = produce_body
|
||||||
|
assert produced.next(15).name.start_with?("merge_label")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_true_jump # should jumpp to merge label
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal "Jump" , produced.next(10).name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -7,17 +7,35 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "if(@a) ; arg = 5 ; end"
|
@input = "if(@a) ; arg = 5 ; end"
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, Label, LoadConstant ,
|
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, LoadConstant, IsSame ,
|
||||||
SlotToReg, RegToSlot, Label]
|
Label, LoadConstant, SlotToReg, RegToSlot, Label]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_instructions
|
def test_if_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def ttest_if_instructions
|
def test_false_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal 5 , produced.class , produced
|
assert_equal Mom::FalseConstant , produced.next(2).constant.known_object.class
|
||||||
end
|
end
|
||||||
|
def test_false_check
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(10) , produced.next(3).label
|
||||||
|
end
|
||||||
|
def test_nil_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal Mom::NilConstant , produced.next(4).constant.known_object.class
|
||||||
|
end
|
||||||
|
def test_nil_check
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next(10) , produced.next(5).label
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_true_label
|
||||||
|
produced = produce_body
|
||||||
|
assert produced.next(6).name.start_with?("true_label")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ class TypeApi < MiniTest::Test
|
|||||||
assert_equal Parfait::Space , space.class
|
assert_equal Parfait::Space , space.class
|
||||||
type = space.get_type
|
type = space.get_type
|
||||||
assert_equal Parfait::Type , type.class
|
assert_equal Parfait::Type , type.class
|
||||||
assert_equal 4 , type.names.get_length
|
assert_equal 7 , type.names.get_length
|
||||||
assert_equal type.object_class.class , Parfait::Class
|
assert_equal type.object_class.class , Parfait::Class
|
||||||
assert_equal type.object_class.name , :Space
|
assert_equal type.object_class.name , :Space
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user