flattening of moms while

This commit is contained in:
Torsten Ruger 2017-09-08 13:22:20 +03:00
parent 0f83b89805
commit d86282b007
3 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,17 @@ module Mom
@condition = cond @condition = cond
@statements = statements @statements = statements
end end
def flatten
cond_label = Label.new( "cond_label_#{object_id}")
head = cond_label
head.append hoisted.flatten
merge_label = Label.new( "merge_label_#{object_id}")
head.append condition.flatten( true_label: cond_label , false_label: merge_label)
head.append merge_label
head
end
end end
end end

View File

@ -0,0 +1,27 @@
require_relative "helper"
module Mom
class TestWhileConditionMom < MiniTest::Test
include MomCompile
def setup
Risc.machine.boot
@stats = compile_first_method_flat( "while(@a == 5) ; 5.mod4 ; end")
@first = @stats.next.next
end
def test_if_compiles
assert IfStatement != @stats.class , @stats
end
def test_check
assert_equal TruthCheck , @first.class
end
def test_condition_is_slot
assert_equal SlotDefinition , @first.condition.class , @first
end
def test_length
assert_equal 4 , @stats.length
end
end
end