simple sends and all whiles working
This commit is contained in:
parent
35a0952943
commit
da0e1cdc5f
@ -7,7 +7,11 @@ module Vool
|
||||
# eg if( @var % 5) is not normalized
|
||||
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
|
||||
def normalize_name( condition )
|
||||
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||
condition = condition.first
|
||||
end
|
||||
return [condition] if condition.is_a?(Named)
|
||||
condition = condition.normalize
|
||||
local = "tmp_#{object_id}"
|
||||
assign = Statements.new [LocalAssignment.new( local , condition)]
|
||||
[LocalVariable.new(local) , assign]
|
||||
|
@ -11,7 +11,7 @@ module Vool
|
||||
end
|
||||
|
||||
def normalize
|
||||
cond , rest = *normalize_name(@condition.normalize)
|
||||
cond , rest = *normalize_name(@condition)
|
||||
me = WhileStatement.new(cond , @body.normalize)
|
||||
return me unless rest
|
||||
rest << me
|
||||
|
@ -27,5 +27,8 @@ module Vool
|
||||
def test_call_has_method
|
||||
assert_equal Parfait::TypedMethod, @ins.next(3).method.class
|
||||
end
|
||||
def test_array
|
||||
check_array [Mom::MessageSetup,Mom::SlotLoad,Mom::ArgumentTransfer,Mom::SimpleCall] , @ins
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,39 +3,32 @@ require_relative "../helper"
|
||||
module Vool
|
||||
class TestSendCachedSimpleMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = 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
|
||||
@ins = compile_first_method_flat( "a = 5; a.mod4")
|
||||
end
|
||||
def test_if_first
|
||||
assert_equal Mom::IfStatement , @first.class , @first
|
||||
assert_equal Mom::IfStatement , @ins.class , @ins
|
||||
end
|
||||
def test_if_condition_set
|
||||
assert_equal Mom::NotSameCheck , @first.condition.class , @first
|
||||
assert_equal Mom::NotSameCheck , @ins.condition.class , @ins
|
||||
end
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
def test_setup_second
|
||||
@ -51,7 +44,7 @@ module Vool
|
||||
end
|
||||
|
||||
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
|
||||
|
@ -5,31 +5,31 @@ module Vool
|
||||
class TestSendSelfMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include SimpleSendHarness
|
||||
include Mom
|
||||
|
||||
def do_setup(str)
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( str).first
|
||||
@first = @stats.first
|
||||
@ins = compile_first_method( str)
|
||||
end
|
||||
def setup
|
||||
do_setup("self.get_internal_word(0)")
|
||||
end
|
||||
|
||||
def test_receiver
|
||||
assert_equal Mom::SlotDefinition, @stats[1].receiver.right.class
|
||||
assert_equal SlotDefinition, @ins.next.right.class
|
||||
end
|
||||
|
||||
def test_arg_one
|
||||
assert_equal Mom::SlotLoad, @stats[1].arguments[0].class
|
||||
assert_equal SlotLoad, @ins.next(2).arguments[0].class
|
||||
end
|
||||
def test_call_two
|
||||
assert_equal Mom::SimpleCall, @stats[2].class
|
||||
assert_equal SimpleCall, @ins.next(3).class
|
||||
end
|
||||
def test_call_has_method
|
||||
assert_equal Parfait::TypedMethod, @stats[2].method.class
|
||||
assert_equal Parfait::TypedMethod, @ins.next(3).method.class
|
||||
end
|
||||
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
|
||||
class TestSendSelfImplicitMom < TestSendSelfMom
|
||||
|
@ -8,19 +8,22 @@ module Vool
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( "'5'.get_internal_byte(1)")
|
||||
@ins = compile_first_method( "'5'.get_internal_byte(1)")
|
||||
end
|
||||
def receiver
|
||||
[Mom::StringConstant , "5"]
|
||||
end
|
||||
|
||||
def test_args_one_move
|
||||
assert_equal :next_message, @stats[1].arguments[0].left.slots[0]
|
||||
assert_equal :arguments, @stats[1].arguments[0].left.slots[1]
|
||||
assert_equal :next_message, @ins.next.next.arguments[0].left.slots[0]
|
||||
assert_equal :arguments, @ins.next.next.arguments[0].left.slots[1]
|
||||
end
|
||||
def test_args_one_str
|
||||
assert_equal Mom::IntegerConstant, @stats[1].arguments[0].right.class
|
||||
assert_equal 1, @stats[1].arguments[0].right.value
|
||||
assert_equal Mom::IntegerConstant, @ins.next.next.arguments[0].right.class
|
||||
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
|
||||
|
@ -4,30 +4,27 @@ require_relative "helper"
|
||||
module Vool
|
||||
class TestSimpleWhileMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( "while(@a) ; 5.mod4 ; end")
|
||||
@first = @stats.first
|
||||
@ins = compile_first_method( "while(@a) ; 5.mod4 ; end")
|
||||
end
|
||||
|
||||
def test_compiles_not_array
|
||||
assert Array != @stats.class , @stats
|
||||
assert Array != @ins.class , @ins
|
||||
end
|
||||
def test_compiles_as_while
|
||||
assert_equal Mom::WhileStatement , @first.class , @stats
|
||||
assert_equal Label , @ins.class , @ins
|
||||
end
|
||||
def test_condition_compiles_to_check
|
||||
assert_equal Mom::TruthCheck , @first.condition.class , @stats
|
||||
assert_equal TruthCheck , @ins.next.class , @ins
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
||||
end
|
||||
def test_nothing_hoisted
|
||||
assert_nil @first.hoisted , @stats
|
||||
assert_equal SlotDefinition , @ins.next.condition.class , @ins
|
||||
end
|
||||
def test_array
|
||||
check_array [Label,SlotLoad,TruthCheck,Label] , @stats
|
||||
check_array [Label,TruthCheck,MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,Jump,Label] , @ins
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user