everything but dynamic dispatch

This commit is contained in:
Torsten Ruger 2018-03-16 19:39:35 +05:30
parent d01bdf5dc5
commit ba3ec9b1a2
9 changed files with 27 additions and 82 deletions

View File

@ -6,11 +6,13 @@ module Vool
#
# eg if( @var % 5) is not normalized
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
#
# also constants count, though they may not be so useful in ifs, but returns
def normalize_name( condition )
if( condition.is_a?(ScopeStatement) and condition.single?)
condition = condition.first
end
return [condition] if condition.respond_to?(:slot_definition)
return [condition] if condition.is_a?(Named) or condition.is_a?(Constant)
condition = condition.normalize
local = "tmp_#{object_id}"
assign = Statements.new [LocalAssignment.new( local , condition)]

View File

@ -1,32 +0,0 @@
require_relative "helper"
module Vool
module Compilers
class TestIvarCollect < MiniTest::Test
def compile(input)
lst = VoolCompiler.ruby_to_vool( input )
vars = []
lst.collect([]).each do |node|
node.add_ivar(vars)
end
vars
end
def test_instance_collect
vars = compile( "@var" )
assert_equal :var , vars.first
end
def test_return_collect
vars = compile( "return @var" )
assert_equal :var , vars.first
end
def test_assign_collect
vars = compile( "@var = 5" )
assert_equal :var , vars.first
end
end
end
end

View File

@ -1,27 +0,0 @@
require_relative "helper"
module Vool
module Compilers
class TestLocalCollect < MiniTest::Test
def compile(input)
lst = VoolCompiler.ruby_to_vool( input )
vars = []
lst.collect([]).each do |node|
node.add_local(vars)
end
vars
end
def test_assign_collect
vars = compile( "var = 5" )
assert_equal :var , vars.first
end
def test_return_collect
vars = compile( "var = 5 ; return var" )
assert_equal :var , vars.first
end
end
end
end

View File

@ -21,8 +21,7 @@ module Vool
end
def test_compile_class_body
assert_equal 0 , @lst.body.length
assert_equal ScopeStatement , @lst.body.class
assert_nil @lst.body
end
end

View File

@ -12,7 +12,7 @@ module Vool
end
def test_if_basic_cond
lst = RubyCompiler.compile( basic_if )
assert_equal SendStatement , lst.condition.class
assert_equal ScopeStatement , lst.condition.class
end
def test_if_basic_branches
lst = RubyCompiler.compile( basic_if )
@ -29,7 +29,7 @@ module Vool
end
def test_if_double_cond
lst = RubyCompiler.compile( double_if )
assert_equal FalseConstant , lst.condition.class
assert_equal ScopeStatement , lst.condition.class
end
def test_if_double_branches
lst = RubyCompiler.compile( double_if )
@ -63,7 +63,7 @@ module Vool
end
def test_if_reverse_cond
lst = RubyCompiler.compile( reverse_unless )
assert_equal FalseConstant , lst.condition.class
assert_equal ScopeStatement , lst.condition.class
end
def test_if_reverse_branches
lst = RubyCompiler.compile( reverse_unless )

View File

@ -32,9 +32,9 @@ module Vool
assert_equal LocalAssignment , lst.body.class
end
def test_body_is_scope_zero_statement
input = "def tryout(arg1, arg2) ; ; end "
input = "def tryout(arg1, arg2) ; arg1 = arg2 ; end "
lst = RubyCompiler.compile( input )
assert_equal ScopeStatement , lst.body.class
assert_equal LocalAssignment , lst.body.class
end
end
end

View File

@ -12,11 +12,11 @@ module Vool
end
def test_while_basic_cond
lst = RubyCompiler.compile( basic_while )
assert_equal SendStatement , lst.condition.class
assert_equal ScopeStatement , lst.condition.class
end
def test_while_basic_branches
lst = RubyCompiler.compile( basic_while )
assert_equal TrueConstant , lst.statements.class
assert_equal TrueConstant , lst.body.class
end
def reverse_while
@ -28,11 +28,11 @@ module Vool
end
def test_while_reverse_cond
lst = RubyCompiler.compile( reverse_while )
assert_equal FalseConstant , lst.condition.class
assert_equal ScopeStatement , lst.condition.class
end
def test_while_reverse_branches
lst = RubyCompiler.compile( reverse_while )
assert_equal TrueConstant , lst.statements.class
assert_equal TrueConstant , lst.body.class
end
end

View File

@ -10,37 +10,37 @@ module Vool
@ins = compile_first_method_flat( "a = 5; a.mod4")
end
def test_if_first
assert_equal Mom::IfStatement , @ins.class , @ins
assert_equal IfStatement , @ins.class , @ins
end
def test_if_condition_set
assert_equal Mom::NotSameCheck , @ins.condition.class , @ins
assert_equal NotSameCheck , @ins.condition.class , @ins
end
def test_if_true_moves_type
assert_equal @ins.if_true[0].class, Mom::SlotLoad , @ins.if_true.to_rxf
assert_equal @ins.if_true[0].class, SlotLoad , @ins.if_true.to_rxf
end
def test_if_true_resolves_setup
assert_equal @ins.if_true[1].class , Mom::MessageSetup, @ins.if_true.to_rxf
assert_equal @ins.if_true[1].class , MessageSetup, @ins.if_true.to_rxf
end
def test_if_true_resolves_transfer
assert_equal @ins.if_true[2].class , Mom::ArgumentTransfer, @ins.if_true.to_rxf
assert_equal @ins.if_true[2].class , ArgumentTransfer, @ins.if_true.to_rxf
end
def test_if_true_resolves_call
assert_equal @ins.if_true[3].class , Mom::SimpleCall, @ins.if_true.to_rxf
assert_equal @ins.if_true[3].class , SimpleCall, @ins.if_true.to_rxf
end
def test_if_true_resolves_move
assert_equal @ins.if_true[4].class , Mom::SlotLoad, @ins.if_true.to_rxf
assert_equal @ins.if_true[4].class , SlotLoad, @ins.if_true.to_rxf
end
def test_setup_second
assert_equal Mom::MessageSetup , @second.class , @second.to_rxf
assert_equal MessageSetup , @ins.next.class , @second.to_rxf
end
def test_transfer_third
assert_equal Mom::ArgumentTransfer , @third.class , @third.to_rxf
assert_equal ArgumentTransfer , @ins.next(2).class , @third.to_rxf
end
def test_call_third
assert_equal Mom::DynamicCall , @fourth.class , @fourth.to_rxf
assert_equal DynamicCall , @ins.last.class , @fourth.to_rxf
end
def test_array

View File

@ -47,8 +47,11 @@ module Vool
@ins = compile_first_method( "return 5.mod4")
end
def test_return_is_last
assert_equal ReturnSequence , @ins.last.class
end
def test_array
check_array [SlotLoad,ReturnSequence] , @ins
check_array [MessageSetup,SlotLoad,ArgumentTransfer,SimpleCall,SlotLoad,SlotLoad,ReturnSequence] , @ins
end
end
end