From ea882f403a17e73bd37f71f59267cbbd807c6d73 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 16 Mar 2018 11:03:29 +0530 Subject: [PATCH] pass parfait method to to_mom previously it was the toll incarnation, and that is almost the same But for the type of self. This s by definition only known in the parfait method And we need it off course for type checking/dispatch --- lib/vool/statements/basic_values.rb | 4 +++- lib/vool/statements/class_statement.rb | 13 +++++++------ lib/vool/statements/local_assignment.rb | 2 +- lib/vool/statements/method_statement.rb | 11 +++++------ lib/vool/statements/send_statement.rb | 2 +- lib/vool/statements/variables.rb | 2 +- test/support/compiling.rb | 2 +- test/vool/compilers/test_class_compiler.rb | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/vool/statements/basic_values.rb b/lib/vool/statements/basic_values.rb index 36166491..782676d9 100644 --- a/lib/vool/statements/basic_values.rb +++ b/lib/vool/statements/basic_values.rb @@ -1,6 +1,8 @@ module Vool class Constant < Expression - + #gobble it up + def each(&block) + end end class IntegerConstant < Constant diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index b6ca530b..ff855c5a 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -8,23 +8,24 @@ module Vool end def normalize - ClassStatement.new(@name , @super_class_name, @body.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 + # there is no mom equivalent for a class, this should never be called def to_mom( _ ) - @body.to_mom() + raise "should not be called (call create_objects)" end def each(&block) block.call(self) - @body.each(&block) + @body.each(&block) if @body end def create_objects create_class_object - self.each {|node| node.create_objects(@clazz) if node.is_a?(MethodStatement) } + mom = nil #return mom for test purpose + self.each {|node| mom = node.create_objects(@clazz) if node.is_a?(MethodStatement) } + mom end def create_class_object diff --git a/lib/vool/statements/local_assignment.rb b/lib/vool/statements/local_assignment.rb index 6f3409f7..7199e13b 100644 --- a/lib/vool/statements/local_assignment.rb +++ b/lib/vool/statements/local_assignment.rb @@ -8,7 +8,7 @@ module Vool end def to_mom( method ) - if method.args_type.variable_index(@name) + if method.arguments.variable_index(@name) type = :arguments else type = :frame diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index eeae8c7d..21c29c22 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -8,12 +8,10 @@ module Vool @clazz = clazz end - # compile to mom instructions. methods themselves do no result in instructions (yet) - # instead the resulting instruction tree is saved into the method object that - # represents the method + # there is no mom equivalent for a method definition, only a vool/parfait one + # Only the source of gets momed, this should never be called def to_mom( _ ) - method = @clazz.get_method( @name ) - @body.to_mom(method) + raise "should not be called (call create_objects)" end def each(&block) @@ -33,9 +31,10 @@ module Vool method = Parfait::VoolMethod.new(name , args_type , frame_type , body ) @clazz.add_method( method ) typed_method = method.create_parfait_method(clazz.instance_type) + head = @body.to_mom( typed_method ) compiler = Risc::MethodCompiler.new( typed_method ).init_method - head = @body.to_mom( method ) compiler.add_mom(head) + head # return for testing end private diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index 70ae7639..16b9f9c6 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -38,7 +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) + @receiver = SelfExpression.new(in_method.for_type) if @receiver.is_a?(SelfExpression) if(@receiver.ct_type) simple_call(in_method) else diff --git a/lib/vool/statements/variables.rb b/lib/vool/statements/variables.rb index 149a423e..fb8e412f 100644 --- a/lib/vool/statements/variables.rb +++ b/lib/vool/statements/variables.rb @@ -11,7 +11,7 @@ module Vool class LocalVariable < Expression include Named def slot_definition(method) - if method.args_type.variable_index(@name) + if method.arguments.variable_index(@name) type = :arguments else type = :frame diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 4961f937..83a899b9 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -26,7 +26,7 @@ module MomCompile assert_equal Parfait::Class , lst.clazz.class , lst @method = lst.clazz.get_method(:main) assert_equal Parfait::VoolMethod , @method.class - res = lst.to_mom( nil ) + res = lst.create_objects #puts "#{res.class}" res end diff --git a/test/vool/compilers/test_class_compiler.rb b/test/vool/compilers/test_class_compiler.rb index a0ce7486..dbac3e38 100644 --- a/test/vool/compilers/test_class_compiler.rb +++ b/test/vool/compilers/test_class_compiler.rb @@ -34,7 +34,7 @@ module Vool def test_class_body_is_scope clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end") - assert_equal ScopeStatement , clazz.body.class + assert_equal MethodStatement , clazz.body.class end def test_creates_class_without_deriviation