Fix if statements hoisting, now that send is working
Same same, just have to remembe to actually execute the condition if it is a send Having send a possible expression, removes one tmp variable and associated move, for a little extra work. Next return and assign (rest)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
class TestAssignment < MiniTest::Test
|
||||
class TestAssignmentRuby < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_local
|
||||
@ -25,11 +25,14 @@ module Ruby
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
end
|
||||
class TestAssignmentVoolBar < MiniTest::Test
|
||||
class TestAssignmentVoolLocal < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "foo = bar").to_vool
|
||||
end
|
||||
def test_tos
|
||||
assert_equal "foo = self.bar()" , @lst.to_s
|
||||
end
|
||||
def test_local
|
||||
assert_equal Vool::LocalAssignment , @lst.class
|
||||
end
|
||||
@ -45,6 +48,9 @@ module Ruby
|
||||
def setup
|
||||
@lst = compile( "@foo = bar").to_vool
|
||||
end
|
||||
def test_tos
|
||||
assert_equal "@foo = self.bar()" , @lst.to_s
|
||||
end
|
||||
def test_instance
|
||||
assert_equal Vool::IvarAssignment , @lst.class
|
||||
end
|
||||
|
@ -1,26 +1,15 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
class TestLocalAssignment < MiniTest::Test
|
||||
class TestVoolCallMulti2 < MiniTest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_local
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "@foo = a.call(b)").to_vool
|
||||
end
|
||||
def test_local_name
|
||||
lst = compile( "foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
def test_s
|
||||
assert_equal "" , @lst.to_s
|
||||
end
|
||||
def test_local_const
|
||||
lst = compile( "foo = 5")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_ivar
|
||||
lst = compile( "foo = @iv")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
assert_equal InstanceVariable , lst.value.class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ module Ruby
|
||||
include RubyTests
|
||||
|
||||
def setup
|
||||
@lst = compile("if(a == 1) ; a = 1 end").to_vool
|
||||
@lst = compile("if(foo() == 1) ; a = 1 ; end").to_vool
|
||||
end
|
||||
|
||||
def test_class
|
||||
@ -40,8 +40,8 @@ module Ruby
|
||||
assert_equal Vool::LocalAssignment , @lst.last.if_true.class
|
||||
end
|
||||
def test_condition
|
||||
assert_equal Vool::LocalVariable , @lst.last.condition.class
|
||||
assert_equal @lst.first.name , @lst.last.condition.name
|
||||
assert_equal Vool::SendStatement , @lst.last.condition.class
|
||||
assert_equal :== , @lst.last.condition.name
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,4 +81,37 @@ module Ruby
|
||||
assert_equal "Word_Type" , sent.receiver.ct_type.name
|
||||
end
|
||||
end
|
||||
class TestSendReceiver < MiniTest::Test
|
||||
include RubyTests
|
||||
def setup
|
||||
@lst = compile( "call.once.more").to_vool
|
||||
end
|
||||
def test_class
|
||||
assert_equal Vool::Statements , @lst.class
|
||||
end
|
||||
def test_one
|
||||
assert_equal Vool::LocalAssignment , @lst.first.class
|
||||
end
|
||||
def test_one_name
|
||||
assert @lst[0].name.to_s.start_with?("tmp_")
|
||||
end
|
||||
def test_one_value
|
||||
assert_equal :call , @lst[0].value.name
|
||||
end
|
||||
def test_two_name
|
||||
assert @lst[1].name.to_s.start_with?("tmp_")
|
||||
end
|
||||
def test_two_value
|
||||
assert_equal :once , @lst[1].value.name
|
||||
end
|
||||
def test_three_class
|
||||
assert_equal Vool::SendStatement, @lst[2].class
|
||||
end
|
||||
def test_three_name
|
||||
assert_equal :more , @lst[2].name
|
||||
end
|
||||
def test_three_self
|
||||
assert @lst[2].receiver.name.to_s.start_with?("tmp_")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,19 +11,19 @@ module Vool
|
||||
end
|
||||
|
||||
def test_condition
|
||||
assert_equal TruthCheck , @ins.next(4).class
|
||||
assert_equal TruthCheck , @ins.next(3).class
|
||||
end
|
||||
def test_condition_is_slot
|
||||
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
||||
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
|
||||
end
|
||||
def test_hoisted_dynamic_call
|
||||
def test_hoisted_call
|
||||
assert_equal SimpleCall , @ins.next(2).class
|
||||
assert_equal :div4 , @ins.next(2).method.name
|
||||
end
|
||||
def test_array
|
||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck,
|
||||
Label ,SlotLoad, Jump, Label, SlotLoad, Label,
|
||||
Label, ReturnSequence, Label ] , @ins
|
||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck, Label ,
|
||||
SlotLoad, Jump, Label, SlotLoad, Label ,
|
||||
Label, ReturnSequence, Label] , @ins
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user