From 3909bdcc7d928df68cb62fdf62d4d6330fc31ad9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 16 Mar 2018 10:32:11 +0530 Subject: [PATCH] method tests working again --- lib/vool/statement.rb | 8 ++++---- lib/vool/statements/basic_values.rb | 7 +++++-- lib/vool/statements/class_statement.rb | 3 ++- lib/vool/statements/send_statement.rb | 14 +++++++------- lib/vool/statements/statements.rb | 3 --- test/vool/compilers/test_method_compiler.rb | 21 ++++++++++----------- test/vool/to_mom/send/test_send_simple.rb | 5 ++--- 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index eb028afb..cfed51a7 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -36,14 +36,14 @@ module Vool raise "Not implemented for #{self}" end - def ct_type - nil - end - end class Expression + def ct_type + nil + end + def normalize raise "should not be normalized #{self}" end diff --git a/lib/vool/statements/basic_values.rb b/lib/vool/statements/basic_values.rb index df13dfd3..36166491 100644 --- a/lib/vool/statements/basic_values.rb +++ b/lib/vool/statements/basic_values.rb @@ -43,13 +43,16 @@ module Vool end end class SelfExpression < Expression - attr_reader :clazz + attr_reader :my_type + def initialize(type = nil) + @my_type = type + end def to_mom(in_method) @clazz = in_method.clazz Mom::SlotDefinition.new(:message , [:receiver]) end def ct_type - @clazz.instance_type + @my_type end end class SuperExpression < Statement diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index 83210e6e..b6ca530b 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -10,10 +10,11 @@ module Vool def normalize ClassStatement.new(@name , @super_class_name, @body.normalize ) end + # compilation to the next layer, mom # context coming in for class is nil, also for methods, henceafter a method is passed down def to_mom( _ ) - @body.to_mom(nil) + @body.to_mom() end def each(&block) diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index 2b7841a5..70ae7639 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -38,6 +38,7 @@ module Vool # in a not so distant future, temporary variables will have to be created # and complex statements hoisted to assign to them. pps: same as in conditions def to_mom( in_method ) + @receiver = SelfExpression.new(in_method.for_class.instance_type) if @receiver.is_a?(SelfExpression) if(@receiver.ct_type) simple_call(in_method) else @@ -67,7 +68,7 @@ module Vool # - check the cached type and if neccessary update # - call the cached method def cached_call(in_method) - Mom::Statements.new( cache_check(in_method) + call_cached_method(in_method) ) + cache_check(in_method) << call_cached_method(in_method) end # check that current type is the cached type @@ -77,10 +78,9 @@ module Vool # if cached_type != current_type # cached_type = current_type # cached_method = current_type.resolve_method(method.name) - if_true = Mom::Statements.new(build_type_cache_update) - if_true.add_array build_method_cache_update(in_method) - #@if_true.to_mom( in_method ) #find and assign - [Mom::IfStatement.new( build_condition , if_true )] + check = build_condition + check << build_type_cache_update + check << build_method_cache_update(in_method) end # this may look like a simple_call, but the difference is that we don't know @@ -97,12 +97,12 @@ module Vool Mom::NotSameCheck.new(cached_type , current_type) end def build_type_cache_update - [Mom::SlotMove.new([@dynamic, :cached_type] , [:receiver , :type])] + Mom::SlotLoad.new([@dynamic, :cached_type] , [:receiver , :type]) end def build_method_cache_update(in_method) receiver = StringConstant.new(@name) resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new]) - move_method = Mom::SlotMove.new([@dynamic, :cached_method] , [:receiver , :return]) + move_method = Mom::SlotLoad.new([@dynamic, :cached_method] , [:receiver , :return]) resolve.to_mom(in_method) << move_method end end diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index 2b5213f3..4bcc9248 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -27,9 +27,6 @@ module Vool @statements << o self end - def add_array(a) - @statements += a - end # create machine instructions def to_mom( method ) diff --git a/test/vool/compilers/test_method_compiler.rb b/test/vool/compilers/test_method_compiler.rb index ba173685..9ede1f91 100644 --- a/test/vool/compilers/test_method_compiler.rb +++ b/test/vool/compilers/test_method_compiler.rb @@ -16,8 +16,7 @@ module Vool def test_method_has_source method = create_method - assert_equal ScopeStatement , method.source.class - assert_equal IvarAssignment , method.source.statements.first.class + assert_equal IvarAssignment , method.source.class end def test_method_has_no_locals @@ -38,22 +37,22 @@ module Vool def test_creates_method_statement_in_class clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end") - assert_equal MethodStatement , clazz.body.statements.first.class - end - - def test_parfait_class_creation - clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end") - assert_equal Parfait::Class , clazz.body.statements.first.clazz.class + assert_equal MethodStatement , clazz.body.class end def test_method_statement_has_class clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end") - assert clazz.body.statements.first.clazz + assert clazz.body.clazz + end + + def test_parfait_class_creation + clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5;end") + assert_equal Parfait::Class , clazz.body.clazz.class end def test_method_statement_has_class_in_main - clazz = VoolCompiler.ruby_to_vool as_main("def meth; @ivar = 5;end") - assert clazz.body.statements.first.clazz + clazz = VoolCompiler.ruby_to_vool in_Space("def meth; @ivar = 5;end") + assert clazz.body.clazz end def test_method_has_one_local diff --git a/test/vool/to_mom/send/test_send_simple.rb b/test/vool/to_mom/send/test_send_simple.rb index 284c9a63..12672a2c 100644 --- a/test/vool/to_mom/send/test_send_simple.rb +++ b/test/vool/to_mom/send/test_send_simple.rb @@ -8,14 +8,13 @@ module Vool def setup Risc.machine.boot - @stats = compile_first_method( "5.mod4").first - @first = @stats.first + @ins = compile_first_method( "5.mod4") end def receiver [Mom::IntegerConstant , 5] end def test_call_has_right_method - assert_equal :mod4, @stats[2].method.name + assert_equal :mod4, @ins.next(3).method.name end end