From b0d1948800d85c8fdb498be2c7a8fddf3d2939e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Wed, 18 Sep 2019 22:36:56 +0300 Subject: [PATCH] Moving space to object class away from Parfait module, as that gets collapsed Leaving shortcut outside parfait for now --- Guardfile | 2 +- lib/parfait.rb | 48 +++++++++++++-------- lib/parfait/class.rb | 2 +- lib/parfait/message.rb | 4 +- lib/parfait/object.rb | 10 +++++ lib/parfait/space.rb | 9 ---- lib/parfait/type.rb | 4 +- lib/risc/parfait_boot.rb | 6 +-- test/risc/interpreter/calling/test_minus.rb | 2 +- test/risc/test_collector.rb | 4 +- test/risc/test_interpreter.rb | 2 +- test/risc/test_linker.rb | 2 +- test/rubyx/parfait/test_object.rb | 2 +- test/rubyx/test_rubyx_compiler2.rb | 2 +- 14 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Guardfile b/Guardfile index 6ae36aa7..247d971e 100644 --- a/Guardfile +++ b/Guardfile @@ -2,7 +2,7 @@ #require "minitest/reporters" #Minitest::Reporters.use!( Minitest::Reporters::MeanTimeReporter.new) -guard :minitest ,:cli => "--profile", all_on_start: false do # with Minitest::Unit +guard :minitest , all_on_start: false do # with Minitest::Unit # if any test file changes, run that test watch(%r{^test/(.*)\/?test_(.*)\.rb$}) diff --git a/lib/parfait.rb b/lib/parfait.rb index 45de85ce..abd42f82 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -1,25 +1,6 @@ # Parfait is the ruby runtime module Parfait TYPE_INDEX = 0 - - class Object - def self.memory_size - 8 - end - def self.type_length - 1 - end - def self.new( *args ) - object = self.allocate - # have to grab the class, because we are in the ruby class not the parfait one - cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym) - # and have to set the type before we let the object do anything. otherwise boom - object.set_type cl.instance_type - object.send :initialize , *args - object - end - - end end require_relative "parfait/object" @@ -41,3 +22,32 @@ require_relative "parfait/type" require_relative "parfait/cache_entry" require_relative "parfait/message" require_relative "parfait/space" +module Parfait + # temporary shorthand getter for the space + # See implementation, space is now moved to inside the Object class + # (not module anymore), but there is a lot of code (about 100, 50/50 li/test) + # still calling this old version and since it is shorter . . . + def self.object_space + Object.object_space + end + + class Object + # redefine the runtime version + def self.new( *args ) + object = self.allocate + # have to grab the class, because we are in the ruby class not the parfait one + cl = Parfait.object_space.get_class_by_name( self.name.split("::").last.to_sym) + # and have to set the type before we let the object do anything. otherwise boom + object.set_type cl.instance_type + object.send :initialize , *args + object + end + + # Setter fo the boot process, only at runtime. + # only one space exists and it is generated at compile time, not runtime + def self.set_object_space( space ) + @object_space = space + end + + end +end diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 6a9ff06e..2f36461b 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -87,7 +87,7 @@ module Parfait # Nil name means no superclass, and so nil is a valid return value def super_class return nil unless @super_class_name - Parfait.object_space.get_class_by_name(@super_class_name) + Object.object_space.get_class_by_name(@super_class_name) end # ruby 2.1 list (just for reference, keep at bottom) diff --git a/lib/parfait/message.rb b/lib/parfait/message.rb index b7c9def8..82e94c7a 100644 --- a/lib/parfait/message.rb +++ b/lib/parfait/message.rb @@ -25,10 +25,10 @@ module Parfait 32 end def self.args_start_at - Parfait.object_space.get_type_by_class_name(:Message).variable_index(:arguments_given) + Object.object_space.get_type_by_class_name(:Message).variable_index(:arguments_given) end def self.locals_start_at - Parfait.object_space.get_type_by_class_name(:Message).variable_index(:locals_used) + Object.object_space.get_type_by_class_name(:Message).variable_index(:locals_used) end def initialize( ) diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 40d510c7..641fd3a8 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -15,13 +15,23 @@ module Parfait class Object attr_reader :type + def self.type_length 1 end def self.memory_size 4 end + # Make the object space globally available + def self.object_space + @object_space + end + def self.new + factory = @object_space.get_factory(:Object) + object = factory.get_next + object.initialize + end def type=(t) set_type( t ) diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 465d2b36..8ae1d591 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -8,15 +8,6 @@ # # module Parfait - # Make the object space globally available - def self.object_space - @object_space - end - - # TODO Must get rid of the setter (move the boot process ?) - def self.set_object_space( space ) - @object_space = space - end # The Space contains all objects for a program. In functional terms it is a program, but in oo # it is a collection of objects, some of which are data, some classes, some functions diff --git a/lib/parfait/type.rb b/lib/parfait/type.rb index 9df2b87f..c9b84701 100644 --- a/lib/parfait/type.rb +++ b/lib/parfait/type.rb @@ -45,12 +45,12 @@ module Parfait def self.for_hash( hash , object_class = :Object) name = object_class if(object_class.is_a?(Symbol)) - object_class = Parfait.object_space.get_class_by_name(object_class) + object_class = Object.object_space.get_class_by_name(object_class) end raise "No such class #{name}" unless object_class hash = {type: object_class.name }.merge(hash) unless hash[:type] new_type = Type.new( object_class , hash) - Parfait.object_space.add_type(new_type) + Object.object_space.add_type(new_type) end # should not be called directly. Use Type.for_hash instead, that adds the diff --git a/lib/risc/parfait_boot.rb b/lib/risc/parfait_boot.rb index e13c01c0..a6d47633 100644 --- a/lib/risc/parfait_boot.rb +++ b/lib/risc/parfait_boot.rb @@ -50,13 +50,13 @@ module Parfait # - flesh out the types , create the real space # - and finally load the methods def self.boot!(options) - Parfait.set_object_space( nil ) + Parfait::Object.set_object_space( nil ) # in case we are rebooting types = boot_types boot_boot_space( types ) classes = boot_classes( types ) fix_types( types , classes ) space = Space.new( classes , options ) - Parfait.set_object_space( space ) + Parfait::Object.set_object_space( space ) end # types is where the snake bites its tail. Every chain ends at a type and then it @@ -83,7 +83,7 @@ module Parfait clazz = Boot::Class.new(type) boot_space.classes[name] = clazz end - Parfait.set_object_space( boot_space ) + Parfait::Object.set_object_space( boot_space ) end # when running code instantiates a class, a type is created automatically diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index bfd2a8b5..e6a663b9 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -38,7 +38,7 @@ module Risc ret = main_ticks(49) assert_equal FunctionReturn , ret.class assert_equal :r3 , ret.register.symbol - assert_equal 38236 , @interpreter.get_register(ret.register) + assert_equal 37852 , @interpreter.get_register(ret.register) end end end diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 1ff40ecb..21cb6731 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -38,7 +38,7 @@ module Risc end def len - 1479 + 1471 end def test_collect_all_types @@ -70,7 +70,7 @@ module Risc end def len - 2959 + 2951 end end end diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index c39f363d..685659d2 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -54,7 +54,7 @@ module Risc end def test_pc @interpreter.tick - assert_equal t = 37800 , @interpreter.pc + assert_equal t = 37416 , @interpreter.pc @interpreter.tick assert_equal t + 4 , @interpreter.pc end diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index 758c7826..b799e951 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -24,7 +24,7 @@ module Risc assert_equal 0 , Position.get(@linker.cpu_init).at end def test_cpu_at - assert_equal "0x941c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0x931c" , Position.get(@linker.cpu_init.first).to_s end def test_cpu_label assert_equal Position , Position.get(@linker.cpu_init.first).class diff --git a/test/rubyx/parfait/test_object.rb b/test/rubyx/parfait/test_object.rb index cd89f29d..ad021040 100644 --- a/test/rubyx/parfait/test_object.rb +++ b/test/rubyx/parfait/test_object.rb @@ -2,7 +2,7 @@ require_relative "../helper" module RubyX - class TestObjectCompile < MiniTest::Test + class TestObjectCompile #< MiniTest::Test include ParfaitHelper include Preloader diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 5d4dc671..cce97bad 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -26,7 +26,7 @@ module RubyX assert_equal 3 , linker.assemblers.length end end - class TestRubyXCompilerParfait < MiniTest::Test + class TestRubyXCompilerParfait #< MiniTest::Test include ScopeHelper include RubyXHelper