Fix ruby normalising to_vool

So that vool layer never has complex conditions or returns
Start with while, next if, return and assign
This commit is contained in:
2019-08-16 14:09:56 +03:00
parent 84b9811e55
commit c213cf874b
10 changed files with 40 additions and 31 deletions

View File

@ -22,20 +22,20 @@ module Ruby
class TestWhileStatementHoist < MiniTest::Test
include RubyTests
def setup
@lst = compile( "while(arg > 1) ; arg = 1 ; end" ).to_vool
@lst = compile( "while(call(arg > 1)) ; arg = 1 ; end" ).to_vool
end
def test_class
assert_equal Vool::WhileStatement , @lst.class
assert_equal Vool::LocalAssignment , @lst.body.class
end
def test_condition_class
assert_equal Vool::LocalVariable , @lst.condition.class
assert_equal Vool::SendStatement , @lst.condition.class
end
def test_hoist
assert_equal Vool::LocalAssignment , @lst.hoisted.class
assert_equal Vool::Statements , @lst.hoisted.class
end
def test_hoist_is_cond
assert_equal @lst.hoisted.name , @lst.condition.name
def test_hoist_is_assi
assert_equal Vool::LocalAssignment , @lst.hoisted.first.class
end
end
end

View File

@ -12,13 +12,13 @@ module Vool
end
def test_condition_compiles_to_check
assert_equal TruthCheck , @ins.next(5).class
assert_equal TruthCheck , @ins.next(4).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(5).condition.class , @ins
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
end
def test_hoisetd
jump = @ins.next(9)
jump = @ins.next(8)
assert_kind_of Jump , jump
assert jump.label.name.start_with?("cond_label") , jump.label.name
end
@ -28,9 +28,9 @@ module Vool
assert label.name.start_with?("cond_label") , label.name
end
def test_array
check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad ,
TruthCheck, MessageSetup, ArgumentTransfer, SimpleCall, Jump ,
Label, Label, ReturnSequence, Label] , @ins
check_array [Label, MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck ,
MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label ,
Label, ReturnSequence, Label] , @ins
end
end