From f0ba86372187be9780120d4822ff1b60d6b68754 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 26 Jun 2018 20:46:58 +0300 Subject: [PATCH] remove to_mom / create_objects dichotomy wsa supposed to be clearer, but even to me seems confusing now. --- lib/parfait/vool_method.rb | 2 +- lib/vool/statements/class_statement.rb | 15 ++++++------- lib/vool/statements/method_statement.rb | 28 +++++++++---------------- lib/vool/vool_compiler.rb | 2 +- test/risc/test_padding.rb | 2 +- test/support/compiling.rb | 2 +- 6 files changed, 20 insertions(+), 31 deletions(-) diff --git a/lib/parfait/vool_method.rb b/lib/parfait/vool_method.rb index 5f65256c..fe5a9b11 100644 --- a/lib/parfait/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -22,7 +22,7 @@ module Parfait raise "source must be vool" unless source.is_a?(Vool::Statement) end - def create_parfait_method( type ) + def create_typed_method( type ) raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type type.create_method( @name , @args_type , @frame_type) end diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index ff855c5a..00f77d5f 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -11,9 +11,13 @@ module Vool ClassStatement.new(@name , @super_class_name, @body&.normalize ) end - # there is no mom equivalent for a class, this should never be called def to_mom( _ ) - raise "should not be called (call create_objects)" + create_class_object + mom = nil #return mom for test purpose + self.each do |node| + mom = node.to_mom(@clazz) if node.is_a?(MethodStatement) + end + mom end def each(&block) @@ -21,13 +25,6 @@ module Vool @body.each(&block) if @body end - def create_objects - create_class_object - 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 @clazz = Parfait.object_space.get_class_by_name(@name ) if(@clazz) diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index 67437931..6989223f 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -8,10 +8,16 @@ module Vool @clazz = clazz end - # 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( _ ) - raise "should not be called (call create_objects)" + def to_mom(clazz) + @clazz = clazz + raise "no class" unless clazz + method = Parfait::VoolMethod.new(name , make_type , make_frame , body ) + @clazz.add_method( method ) + typed_method = method.create_typed_method(clazz.instance_type) + head = @body.to_mom( typed_method ) + compiler = Risc::MethodCompiler.new( typed_method ) + compiler.add_mom(head) + head # return for testing end def each(&block) @@ -23,20 +29,6 @@ module Vool MethodStatement.new( @name , @args , @body.normalize) end - def create_objects(clazz) - @clazz = clazz - raise "no class" unless clazz - args_type = make_type - frame_type = make_frame - 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 ) - compiler.add_mom(head) - head # return for testing - end - private def make_type( ) diff --git a/lib/vool/vool_compiler.rb b/lib/vool/vool_compiler.rb index 582795f2..ed8a73ca 100644 --- a/lib/vool/vool_compiler.rb +++ b/lib/vool/vool_compiler.rb @@ -6,7 +6,7 @@ module Vool def self.ruby_to_vool( ruby_source ) statements = RubyCompiler.compile( ruby_source ) statements = statements.normalize - statements.create_objects + statements.to_mom(nil) statements end def self.ruby_to_mom(source) diff --git a/test/risc/test_padding.rb b/test/risc/test_padding.rb index cc7c530e..151e752c 100644 --- a/test/risc/test_padding.rb +++ b/test/risc/test_padding.rb @@ -4,7 +4,7 @@ module Risc class TestPadding < MiniTest::Test def setup - Risc.machine.boot unless Risc.machine.booted + Risc.machine.boot end def test_small diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 10237b5e..739d151b 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -26,7 +26,7 @@ module MomCompile # but here we return the intermediate mom instructions that are otherwise not available statements = Vool::RubyCompiler.compile as_test_main( input ) statements = statements.normalize - res = statements.create_objects + res = statements.to_mom(nil) assert_equal Parfait::Class , statements.clazz.class , statements @method = statements.clazz.get_method(:main) assert_equal Parfait::VoolMethod , @method.class