simple if test without else
unveils many a bug that is now fixed
This commit is contained in:
parent
d910c02b4a
commit
e0f6ba7bcf
@ -8,18 +8,26 @@ module Mom
|
|||||||
@condition = cond
|
@condition = cond
|
||||||
@if_true = if_true
|
@if_true = if_true
|
||||||
@if_false = if_false
|
@if_false = if_false
|
||||||
|
raise if_true.class unless if_true.is_a? Statement
|
||||||
end
|
end
|
||||||
|
|
||||||
def flatten
|
def flatten(options = {})
|
||||||
head = hoisted.flatten
|
|
||||||
true_label = Label.new( "true_label_#{object_id}")
|
true_label = Label.new( "true_label_#{object_id}")
|
||||||
false_label = Label.new( "false_label_#{object_id}")
|
false_label = Label.new( "false_label_#{object_id}")
|
||||||
merge_label = Label.new( "merge_label_#{object_id}")
|
merge_label = Label.new( "merge_label_#{object_id}")
|
||||||
head.append condition.flatten( true_label: true_label , false_label: false_label)
|
first = condition.flatten( true_label: true_label , false_label: false_label)
|
||||||
|
if hoisted
|
||||||
|
head = hoisted.flatten
|
||||||
|
head.append first
|
||||||
|
else
|
||||||
|
head = first
|
||||||
|
end
|
||||||
head.append true_label
|
head.append true_label
|
||||||
head.append if_true.flatten( merge_label: merge_label)
|
head.append if_true.flatten( merge_label: merge_label)
|
||||||
head.append false_label
|
if( if_false)
|
||||||
head.append if_false.flatten( merge_label: merge_label)
|
head.append false_label
|
||||||
|
head.append if_false.flatten( merge_label: merge_label)
|
||||||
|
end
|
||||||
head.append merge_label
|
head.append merge_label
|
||||||
head
|
head
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Vool
|
|||||||
|
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
if_true = @if_true.to_mom( method )
|
if_true = @if_true.to_mom( method )
|
||||||
if_false = @if_false.to_mom( method )
|
if_false = @if_false ? @if_false.to_mom( method ) : nil
|
||||||
condition , hoisted = hoist_condition( method )
|
condition , hoisted = hoist_condition( method )
|
||||||
cond = Mom::TruthCheck.new(condition.to_mom(method))
|
cond = Mom::TruthCheck.new(condition.to_mom(method))
|
||||||
check = Mom::IfStatement.new( cond , if_true , if_false )
|
check = Mom::IfStatement.new( cond , if_true , if_false )
|
||||||
@ -25,7 +25,7 @@ module Vool
|
|||||||
|
|
||||||
def collect(arr)
|
def collect(arr)
|
||||||
@if_true.collect(arr)
|
@if_true.collect(arr)
|
||||||
@if_false.collect(arr)
|
@if_false.collect(arr) if @if_false
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
29
test/mom/test_if_simple_statement.rb
Normal file
29
test/mom/test_if_simple_statement.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Mom
|
||||||
|
class TestSimpleIfMom < MiniTest::Test
|
||||||
|
include MomCompile
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Risc.machine.boot
|
||||||
|
@stats = compile_first_method_flat( "if(@a == 5) ; 5.mod4 ; end")
|
||||||
|
@first = @stats.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 7 , @stats.length
|
||||||
|
end
|
||||||
|
def test_array
|
||||||
|
check_array [SlotMove,TruthCheck,Label,MessageSetup,SimpleCall,ArgumentTransfer,Label], @stats
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user