flattening of moms while
This commit is contained in:
parent
0f83b89805
commit
d86282b007
@ -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
|
||||||
|
27
test/mom/test_while_statement.rb
Normal file
27
test/mom/test_while_statement.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user