From 2c1c38716bff73aeb0f06ba20a48f936e4a6d125 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 20 Jul 2015 13:01:15 +0300 Subject: [PATCH] move from new_object to normal new --- lib/parfait/class.rb | 2 +- lib/parfait/dictionary.rb | 4 ++-- lib/parfait/method.rb | 2 +- lib/parfait/module.rb | 4 ++-- lib/parfait/object.rb | 11 ++++++----- lib/parfait/space.rb | 4 ++-- lib/virtual/boot.rb | 2 +- lib/virtual/parfait_adapter.rb | 2 +- test/helper.rb | 2 +- test/parfait/test_list.rb | 2 +- test/parfait/test_object.rb | 2 +- test/parfait/test_space.rb | 11 +++++++++++ test/parfait/test_word.rb | 6 +++--- 13 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 78906636..1ba75505 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -19,7 +19,7 @@ module Parfait super( name , super_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 - @object_layout = Layout.new_object(self) + @object_layout = Layout.new(self) end def object_layout diff --git a/lib/parfait/dictionary.rb b/lib/parfait/dictionary.rb index cb149864..ee2edea9 100644 --- a/lib/parfait/dictionary.rb +++ b/lib/parfait/dictionary.rb @@ -7,8 +7,8 @@ module Parfait # internally we store keys and values in lists, which means this does **not** scale well def initialize super() - @keys = List.new_object() - @values = List.new_object() + @keys = List.new() + @values = List.new() end # return all values as a list diff --git a/lib/parfait/method.rb b/lib/parfait/method.rb index 167f2c04..f29edf4e 100644 --- a/lib/parfait/method.rb +++ b/lib/parfait/method.rb @@ -24,7 +24,7 @@ module Parfait raise "No class #{name}" unless clazz @for_class = clazz @name = name - @code = BinaryCode.new_object name + @code = BinaryCode.new name @arg_names = arg_names @locals = List.new @tmps = List.new diff --git a/lib/parfait/module.rb b/lib/parfait/module.rb index c08a22de..6e8c7e0a 100644 --- a/lib/parfait/module.rb +++ b/lib/parfait/module.rb @@ -16,7 +16,7 @@ module Parfait def initialize name , superclass super() @name = name - @instance_methods = List.new_object + @instance_methods = List.new @super_class = superclass @meta_class = nil#MetaClass.new(self) end @@ -58,7 +58,7 @@ module Parfait raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol) clazz = Space.object_space.get_class_by_name(self.name) raise "??? #{self.name}" unless clazz - Method.new_object( clazz , name , arg_names ) + Method.new( clazz , name , arg_names ) end # this needs to be done during booting as we can't have all the classes and superclassses diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 688114b7..d14e5d79 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -17,8 +17,9 @@ module Parfait LAYOUT_INDEX = 1 CLASS_INDEX = 2 #only used in class, but keep constants together - def self.new_object *args - object = self.new(*args) + def self.new *args + object = self.allocate + object.send :initialize , *args #puts "NEW #{object.class}" object end @@ -59,7 +60,7 @@ module Parfait def get_layout() 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 end @@ -70,13 +71,13 @@ module Parfait def get_instance_variable name index = instance_variable_defined(name) return nil if index == nil - return internal_get(index) + return internal_object_get(index) end def set_instance_variable name , value index = instance_variable_defined(name) return nil if index == nil - return internal_set(index , value) + return internal_object_set(index , value) end def instance_variable_defined name diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 20a63d85..6784a099 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -24,7 +24,7 @@ module Parfait def initialize super() Parfait::Space.set_object_space self - @classes = Parfait::Dictionary.new_object + @classes = Parfait::Dictionary.new end attr_reader :classes , :first_message @@ -81,7 +81,7 @@ module Parfait # so we get and keep exactly one per name def create_class name , superclass raise "uups #{name.class}" unless name.is_a? Symbol - c = Class.new_object(name , superclass) + c = Class.new(name , superclass) @classes[name] = c end diff --git a/lib/virtual/boot.rb b/lib/virtual/boot.rb index 0af1b2ba..b885e8eb 100644 --- a/lib/virtual/boot.rb +++ b/lib/virtual/boot.rb @@ -17,7 +17,7 @@ module Virtual # The way out is to build empty shell objects and stuff the neccessary data into them # (not use the normal initialize way) 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) class_mappings = {} #will later become instance variable diff --git a/lib/virtual/parfait_adapter.rb b/lib/virtual/parfait_adapter.rb index e59d7c19..77277f9d 100644 --- a/lib/virtual/parfait_adapter.rb +++ b/lib/virtual/parfait_adapter.rb @@ -25,7 +25,7 @@ module FakeMem end module Virtual def self.new_list array - list = Parfait::List.new_object + list = Parfait::List.new list.set_length array.length index = 1 while index <= array.length do diff --git a/test/helper.rb b/test/helper.rb index 2da396c8..731230ef 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -23,7 +23,7 @@ module Virtual # Functions to generate parfait objects def self.new_word( string ) 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 | word.set_char(index + 1 , code) end diff --git a/test/parfait/test_list.rb b/test/parfait/test_list.rb index 7f86e5a7..9db709f2 100644 --- a/test/parfait/test_list.rb +++ b/test/parfait/test_list.rb @@ -3,7 +3,7 @@ require_relative "../helper" class TestList < MiniTest::Test def setup - @list = ::Parfait::List.new_object + @list = ::Parfait::List.new end def test_list_create assert @list.empty? diff --git a/test/parfait/test_object.rb b/test/parfait/test_object.rb index 4b7be990..1aa5c45b 100644 --- a/test/parfait/test_object.rb +++ b/test/parfait/test_object.rb @@ -3,7 +3,7 @@ require_relative "../helper" class TestObject < MiniTest::Test def setup - @object = ::Parfait::Object.new_object + @object = ::Parfait::Object.new end def test_object_create diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 5c7f5c96..b8b3605f 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -34,4 +34,15 @@ class TestSpace < MiniTest::Test # there is a 5.times in space, but one Message gets created before assert_equal 5 + 1 , all.length 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 diff --git a/test/parfait/test_word.rb b/test/parfait/test_word.rb index 6c127881..932fbf6f 100644 --- a/test/parfait/test_word.rb +++ b/test/parfait/test_word.rb @@ -3,7 +3,7 @@ require_relative "../helper" class TestEmptyWord < MiniTest::Test def setup - @word = ::Parfait::Word.new_object(0) + @word = ::Parfait::Word.new(0) end def test_word_create assert @word.empty? @@ -25,7 +25,7 @@ end class TestWord < MiniTest::Test def setup - @word = ::Parfait::Word.new_object(5) + @word = ::Parfait::Word.new(5) end def test_len assert_equal 5 , @word.length @@ -42,7 +42,7 @@ class TestWord < MiniTest::Test assert_equal @word.copy , @word end def test_equals_same - assert_equal ::Parfait::Word.new_object(5) , @word + assert_equal ::Parfait::Word.new(5) , @word end def test_index_check_get assert_raises RuntimeError do