simple sends and all whiles working

This commit is contained in:
Torsten Ruger 2018-03-16 18:41:17 +05:30
parent 35a0952943
commit da0e1cdc5f
7 changed files with 40 additions and 40 deletions

View File

@ -7,7 +7,11 @@ module Vool
# eg if( @var % 5) is not normalized # eg if( @var % 5) is not normalized
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if # but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
def normalize_name( condition ) def normalize_name( condition )
if( condition.is_a?(ScopeStatement) and condition.single?)
condition = condition.first
end
return [condition] if condition.is_a?(Named) return [condition] if condition.is_a?(Named)
condition = condition.normalize
local = "tmp_#{object_id}" local = "tmp_#{object_id}"
assign = Statements.new [LocalAssignment.new( local , condition)] assign = Statements.new [LocalAssignment.new( local , condition)]
[LocalVariable.new(local) , assign] [LocalVariable.new(local) , assign]

View File

@ -11,7 +11,7 @@ module Vool
end end
def normalize def normalize
cond , rest = *normalize_name(@condition.normalize) cond , rest = *normalize_name(@condition)
me = WhileStatement.new(cond , @body.normalize) me = WhileStatement.new(cond , @body.normalize)
return me unless rest return me unless rest
rest << me rest << me

View File

@ -27,5 +27,8 @@ module Vool
def test_call_has_method def test_call_has_method
assert_equal Parfait::TypedMethod, @ins.next(3).method.class assert_equal Parfait::TypedMethod, @ins.next(3).method.class
end end
def test_array
check_array [Mom::MessageSetup,Mom::SlotLoad,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins
end
end end
end end

View File

@ -3,39 +3,32 @@ require_relative "../helper"
module Vool module Vool
class TestSendCachedSimpleMom < MiniTest::Test class TestSendCachedSimpleMom < MiniTest::Test
include MomCompile include MomCompile
include Mom
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method_flat( "a = 5; a.mod4") @ins = compile_first_method_flat( "a = 5; a.mod4")
@first, @second , @third ,@fourth= @stats[0],@stats[1],@stats[2],@stats[3]
end
def test_compiles_not_array
assert Array != @stats.class , @stats
end
def test_four_instructions_are_returned
assert_equal 4 , @stats.length
end end
def test_if_first def test_if_first
assert_equal Mom::IfStatement , @first.class , @first assert_equal Mom::IfStatement , @ins.class , @ins
end end
def test_if_condition_set def test_if_condition_set
assert_equal Mom::NotSameCheck , @first.condition.class , @first assert_equal Mom::NotSameCheck , @ins.condition.class , @ins
end end
def test_if_true_moves_type def test_if_true_moves_type
assert_equal @first.if_true[0].class, Mom::SlotLoad , @first.if_true.to_rxf assert_equal @ins.if_true[0].class, Mom::SlotLoad , @ins.if_true.to_rxf
end end
def test_if_true_resolves_setup def test_if_true_resolves_setup
assert_equal @first.if_true[1].class , Mom::MessageSetup, @first.if_true.to_rxf assert_equal @ins.if_true[1].class , Mom::MessageSetup, @ins.if_true.to_rxf
end end
def test_if_true_resolves_transfer def test_if_true_resolves_transfer
assert_equal @first.if_true[2].class , Mom::ArgumentTransfer, @first.if_true.to_rxf assert_equal @ins.if_true[2].class , Mom::ArgumentTransfer, @ins.if_true.to_rxf
end end
def test_if_true_resolves_call def test_if_true_resolves_call
assert_equal @first.if_true[3].class , Mom::SimpleCall, @first.if_true.to_rxf assert_equal @ins.if_true[3].class , Mom::SimpleCall, @ins.if_true.to_rxf
end end
def test_if_true_resolves_move def test_if_true_resolves_move
assert_equal @first.if_true[4].class , Mom::SlotLoad, @first.if_true.to_rxf assert_equal @ins.if_true[4].class , Mom::SlotLoad, @ins.if_true.to_rxf
end end
def test_setup_second def test_setup_second
@ -51,7 +44,7 @@ module Vool
end end
def test_array def test_array
check_array [SlotLoad,NotSameCheck,Label,SlotLoad,MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,Label,MessageSetup,ArgumentTransfer,DynamicCall] , @stats check_array [SlotLoad,NotSameCheck,SlotLoad,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,SlotLoad,MessageSetup,SlotLoad,ArgumentTransfer,DynamicCall] , @ins
end end
end end

View File

@ -5,31 +5,31 @@ module Vool
class TestSendSelfMom < MiniTest::Test class TestSendSelfMom < MiniTest::Test
include MomCompile include MomCompile
include SimpleSendHarness include SimpleSendHarness
include Mom
def do_setup(str) def do_setup(str)
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( str).first @ins = compile_first_method( str)
@first = @stats.first
end end
def setup def setup
do_setup("self.get_internal_word(0)") do_setup("self.get_internal_word(0)")
end end
def test_receiver def test_receiver
assert_equal Mom::SlotDefinition, @stats[1].receiver.right.class assert_equal SlotDefinition, @ins.next.right.class
end end
def test_arg_one def test_arg_one
assert_equal Mom::SlotLoad, @stats[1].arguments[0].class assert_equal SlotLoad, @ins.next(2).arguments[0].class
end end
def test_call_two def test_call_two
assert_equal Mom::SimpleCall, @stats[2].class assert_equal SimpleCall, @ins.next(3).class
end end
def test_call_has_method def test_call_has_method
assert_equal Parfait::TypedMethod, @stats[2].method.class assert_equal Parfait::TypedMethod, @ins.next(3).method.class
end end
def test_call_has_right_method def test_call_has_right_method
assert_equal :get_internal_word, @stats[2].method.name assert_equal :get_internal_word, @ins.next(3).method.name
end end
end end
class TestSendSelfImplicitMom < TestSendSelfMom class TestSendSelfImplicitMom < TestSendSelfMom

View File

@ -8,19 +8,22 @@ module Vool
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( "'5'.get_internal_byte(1)") @ins = compile_first_method( "'5'.get_internal_byte(1)")
end end
def receiver def receiver
[Mom::StringConstant , "5"] [Mom::StringConstant , "5"]
end end
def test_args_one_move def test_args_one_move
assert_equal :next_message, @stats[1].arguments[0].left.slots[0] assert_equal :next_message, @ins.next.next.arguments[0].left.slots[0]
assert_equal :arguments, @stats[1].arguments[0].left.slots[1] assert_equal :arguments, @ins.next.next.arguments[0].left.slots[1]
end end
def test_args_one_str def test_args_one_str
assert_equal Mom::IntegerConstant, @stats[1].arguments[0].right.class assert_equal Mom::IntegerConstant, @ins.next.next.arguments[0].right.class
assert_equal 1, @stats[1].arguments[0].right.value assert_equal 1, @ins.next.next.arguments[0].right.value
end
def test_array
check_array [Mom::MessageSetup,Mom::SlotLoad,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins
end end
end end
end end

View File

@ -4,30 +4,27 @@ require_relative "helper"
module Vool module Vool
class TestSimpleWhileMom < MiniTest::Test class TestSimpleWhileMom < MiniTest::Test
include MomCompile include MomCompile
include Mom
def setup def setup
Risc.machine.boot Risc.machine.boot
@stats = compile_first_method( "while(@a) ; 5.mod4 ; end") @ins = compile_first_method( "while(@a) ; 5.mod4 ; end")
@first = @stats.first
end end
def test_compiles_not_array def test_compiles_not_array
assert Array != @stats.class , @stats assert Array != @ins.class , @ins
end end
def test_compiles_as_while def test_compiles_as_while
assert_equal Mom::WhileStatement , @first.class , @stats assert_equal Label , @ins.class , @ins
end end
def test_condition_compiles_to_check def test_condition_compiles_to_check
assert_equal Mom::TruthCheck , @first.condition.class , @stats assert_equal TruthCheck , @ins.next.class , @ins
end end
def test_condition_is_slot def test_condition_is_slot
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats assert_equal SlotDefinition , @ins.next.condition.class , @ins
end
def test_nothing_hoisted
assert_nil @first.hoisted , @stats
end end
def test_array def test_array
check_array [Label,SlotLoad,TruthCheck,Label] , @stats check_array [Label,TruthCheck,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Jump,Label] , @ins
end end
end end
end end