Moving space to object class

away from Parfait module, as that gets collapsed
Leaving shortcut outside parfait for now
This commit is contained in:
Torsten Rüger 2019-09-18 22:36:56 +03:00
parent 41617519d9
commit b0d1948800
14 changed files with 55 additions and 44 deletions

View File

@ -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$})

View File

@ -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

View File

@ -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)

View File

@ -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( )

View File

@ -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 )

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,7 @@ require_relative "../helper"
module RubyX
class TestObjectCompile < MiniTest::Test
class TestObjectCompile #< MiniTest::Test
include ParfaitHelper
include Preloader

View File

@ -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