move from new_object to normal new

This commit is contained in:
Torsten Ruger 2015-07-20 13:01:15 +03:00
parent 08e1852e5f
commit 2c1c38716b
13 changed files with 33 additions and 21 deletions

View File

@ -19,7 +19,7 @@ module Parfait
super( name , super_class) super( name , super_class)
# the layout for this class (class = object of type Class) carries the class # the layout for this class (class = object of type Class) carries the class
# as an instance. The relation is from an object through the Layout to it's class # as an instance. The relation is from an object through the Layout to it's class
@object_layout = Layout.new_object(self) @object_layout = Layout.new(self)
end end
def object_layout def object_layout

View File

@ -7,8 +7,8 @@ module Parfait
# internally we store keys and values in lists, which means this does **not** scale well # internally we store keys and values in lists, which means this does **not** scale well
def initialize def initialize
super() super()
@keys = List.new_object() @keys = List.new()
@values = List.new_object() @values = List.new()
end end
# return all values as a list # return all values as a list

View File

@ -24,7 +24,7 @@ module Parfait
raise "No class #{name}" unless clazz raise "No class #{name}" unless clazz
@for_class = clazz @for_class = clazz
@name = name @name = name
@code = BinaryCode.new_object name @code = BinaryCode.new name
@arg_names = arg_names @arg_names = arg_names
@locals = List.new @locals = List.new
@tmps = List.new @tmps = List.new

View File

@ -16,7 +16,7 @@ module Parfait
def initialize name , superclass def initialize name , superclass
super() super()
@name = name @name = name
@instance_methods = List.new_object @instance_methods = List.new
@super_class = superclass @super_class = superclass
@meta_class = nil#MetaClass.new(self) @meta_class = nil#MetaClass.new(self)
end end
@ -58,7 +58,7 @@ module Parfait
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol) raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
clazz = Space.object_space.get_class_by_name(self.name) clazz = Space.object_space.get_class_by_name(self.name)
raise "??? #{self.name}" unless clazz raise "??? #{self.name}" unless clazz
Method.new_object( clazz , name , arg_names ) Method.new( clazz , name , arg_names )
end end
# this needs to be done during booting as we can't have all the classes and superclassses # this needs to be done during booting as we can't have all the classes and superclassses

View File

@ -17,8 +17,9 @@ module Parfait
LAYOUT_INDEX = 1 LAYOUT_INDEX = 1
CLASS_INDEX = 2 #only used in class, but keep constants together CLASS_INDEX = 2 #only used in class, but keep constants together
def self.new_object *args def self.new *args
object = self.new(*args) object = self.allocate
object.send :initialize , *args
#puts "NEW #{object.class}" #puts "NEW #{object.class}"
object object
end end
@ -59,7 +60,7 @@ module Parfait
def get_layout() def get_layout()
l = internal_object_get(LAYOUT_INDEX) l = internal_object_get(LAYOUT_INDEX)
raise "No layout #{self.object_id.to_s(16)}=#{self.to_s[0 ... 100]}:#{self.class} " unless l raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
return l return l
end end
@ -70,13 +71,13 @@ module Parfait
def get_instance_variable name def get_instance_variable name
index = instance_variable_defined(name) index = instance_variable_defined(name)
return nil if index == nil return nil if index == nil
return internal_get(index) return internal_object_get(index)
end end
def set_instance_variable name , value def set_instance_variable name , value
index = instance_variable_defined(name) index = instance_variable_defined(name)
return nil if index == nil return nil if index == nil
return internal_set(index , value) return internal_object_set(index , value)
end end
def instance_variable_defined name def instance_variable_defined name

View File

@ -24,7 +24,7 @@ module Parfait
def initialize def initialize
super() super()
Parfait::Space.set_object_space self Parfait::Space.set_object_space self
@classes = Parfait::Dictionary.new_object @classes = Parfait::Dictionary.new
end end
attr_reader :classes , :first_message attr_reader :classes , :first_message
@ -81,7 +81,7 @@ module Parfait
# so we get and keep exactly one per name # so we get and keep exactly one per name
def create_class name , superclass def create_class name , superclass
raise "uups #{name.class}" unless name.is_a? Symbol raise "uups #{name.class}" unless name.is_a? Symbol
c = Class.new_object(name , superclass) c = Class.new(name , superclass)
@classes[name] = c @classes[name] = c
end end

View File

@ -17,7 +17,7 @@ module Virtual
# The way out is to build empty shell objects and stuff the neccessary data into them # The way out is to build empty shell objects and stuff the neccessary data into them
# (not use the normal initialize way) # (not use the normal initialize way)
def boot_parfait! def boot_parfait!
@space = Parfait::Space.new_object @space = Parfait::Space.new
# map from the vm - class_name to the Parfait class (which carries parfait name) # map from the vm - class_name to the Parfait class (which carries parfait name)
class_mappings = {} #will later become instance variable class_mappings = {} #will later become instance variable

View File

@ -25,7 +25,7 @@ module FakeMem
end end
module Virtual module Virtual
def self.new_list array def self.new_list array
list = Parfait::List.new_object list = Parfait::List.new
list.set_length array.length list.set_length array.length
index = 1 index = 1
while index <= array.length do while index <= array.length do

View File

@ -23,7 +23,7 @@ module Virtual
# Functions to generate parfait objects # Functions to generate parfait objects
def self.new_word( string ) def self.new_word( string )
string = string.to_s if string.is_a? Symbol string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new_object( string.length ) word = Parfait::Word.new( string.length )
string.codepoints.each_with_index do |code , index | string.codepoints.each_with_index do |code , index |
word.set_char(index + 1 , code) word.set_char(index + 1 , code)
end end

View File

@ -3,7 +3,7 @@ require_relative "../helper"
class TestList < MiniTest::Test class TestList < MiniTest::Test
def setup def setup
@list = ::Parfait::List.new_object @list = ::Parfait::List.new
end end
def test_list_create def test_list_create
assert @list.empty? assert @list.empty?

View File

@ -3,7 +3,7 @@ require_relative "../helper"
class TestObject < MiniTest::Test class TestObject < MiniTest::Test
def setup def setup
@object = ::Parfait::Object.new_object @object = ::Parfait::Object.new
end end
def test_object_create def test_object_create

View File

@ -34,4 +34,15 @@ class TestSpace < MiniTest::Test
# there is a 5.times in space, but one Message gets created before # there is a 5.times in space, but one Message gets created before
assert_equal 5 + 1 , all.length assert_equal 5 + 1 , all.length
end end
def test_message_layout
mess = @machine.space.first_message
one_way = mess.get_layout
assert one_way
assert mess.instance_variable_defined :next_message
other_way = mess.get_instance_variable :layout
#puts mess.get_instance_variables
# assert other_way
# assert_equal one_way , other_way , "not same "
end
end end

View File

@ -3,7 +3,7 @@ require_relative "../helper"
class TestEmptyWord < MiniTest::Test class TestEmptyWord < MiniTest::Test
def setup def setup
@word = ::Parfait::Word.new_object(0) @word = ::Parfait::Word.new(0)
end end
def test_word_create def test_word_create
assert @word.empty? assert @word.empty?
@ -25,7 +25,7 @@ end
class TestWord < MiniTest::Test class TestWord < MiniTest::Test
def setup def setup
@word = ::Parfait::Word.new_object(5) @word = ::Parfait::Word.new(5)
end end
def test_len def test_len
assert_equal 5 , @word.length assert_equal 5 , @word.length
@ -42,7 +42,7 @@ class TestWord < MiniTest::Test
assert_equal @word.copy , @word assert_equal @word.copy , @word
end end
def test_equals_same def test_equals_same
assert_equal ::Parfait::Word.new_object(5) , @word assert_equal ::Parfait::Word.new(5) , @word
end end
def test_index_check_get def test_index_check_get
assert_raises RuntimeError do assert_raises RuntimeError do