From d8b58d8da6d8ddcbc8e02a1b9b6e05d3bb235a6f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 4 Jul 2018 09:17:30 +0300 Subject: [PATCH] fix inital main (again) stop even compiling a fake main if a real exists (in builtin) previous version was still buggy: using builting methods types (especially locals) even comiled version had different --- lib/mom/mom_compiler.rb | 7 +------ lib/risc/builtin.rb | 14 ++++++++------ test/mom/test_mom_compiler.rb | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/mom/mom_compiler.rb b/lib/mom/mom_compiler.rb index 17160ad7..68cec826 100644 --- a/lib/mom/mom_compiler.rb +++ b/lib/mom/mom_compiler.rb @@ -3,12 +3,7 @@ module Mom attr_reader :method_compilers def initialize(compilers = []) - @method_compilers = compilers - Risc::Builtin.boot_functions.each do |boot_comp| - next if @method_compilers.find{|comp| comp.method == boot_comp.method } - @method_compilers << boot_comp - end - + @method_compilers = compilers + Risc::Builtin.boot_functions end # collects constants from all compilers into one array diff --git a/lib/risc/builtin.rb b/lib/risc/builtin.rb index 85508fef..c933544b 100644 --- a/lib/risc/builtin.rb +++ b/lib/risc/builtin.rb @@ -12,15 +12,17 @@ module Risc # This should return the implementation of the method (ie a method object), # not actually try to implement it(as that's impossible in ruby) # - def self.boot_functions - compilers = [] - space = Parfait.object_space - # very fiddly chicken 'n egg problem. Functions need to be in the right order, - # and in fact we have to define some dummies, just for the others to compile + # When no main has been compiled, we will add an empty main (for testing) + # + def self.boot_functions(add_main = false) # TODO go through the virtual parfait layer and adjust function names # to what they really are + compilers = [] + space = Parfait.object_space space_type = space.get_class.instance_type - compilers << compiler_for( space_type , Space , :main) + if(space_type.methods.nil?) + compilers << compiler_for( space_type , Space , :main) + end obj_type = space.get_class_by_name(:Object).instance_type [ :get_internal_word , :set_internal_word , :_method_missing, diff --git a/test/mom/test_mom_compiler.rb b/test/mom/test_mom_compiler.rb index c1285312..0005226c 100644 --- a/test/mom/test_mom_compiler.rb +++ b/test/mom/test_mom_compiler.rb @@ -13,10 +13,10 @@ module Mom assert_equal MomCompiler , @comp.class end def test_compilers - assert_equal 24 , @comp.method_compilers.length + assert_equal 23 , @comp.method_compilers.length end def test_compilers_bare - assert_equal 23 , MomCompiler.new.method_compilers.length + assert_equal 22 , MomCompiler.new.method_compilers.length end def test_returns_constants assert_equal Array , @comp.constants.class