From 73a6a5db39fb5c3d79519e04e9558545f516356e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 12 May 2015 09:54:36 +0300 Subject: [PATCH] move meta and boot class to parfait just cosmetic, fixed requires but not code --- lib/parfait.rb | 9 +++++ lib/parfait/class.rb | 49 +++++++++++++++++++++++ lib/{virtual => parfait}/meta_class.rb | 22 +++++------ lib/virtual/boot_class.rb | 54 -------------------------- lib/virtual/boot_space.rb | 1 - lib/virtual/object.rb | 7 +--- 6 files changed, 70 insertions(+), 72 deletions(-) create mode 100644 lib/parfait.rb rename lib/{virtual => parfait}/meta_class.rb (90%) delete mode 100644 lib/virtual/boot_class.rb diff --git a/lib/parfait.rb b/lib/parfait.rb new file mode 100644 index 00000000..211da352 --- /dev/null +++ b/lib/parfait.rb @@ -0,0 +1,9 @@ +require "parfait/value" +require "parfait/object" +require "parfait/module" +require "parfait/class" +require "parfait/hash" +require "parfait/array" +require "parfait/string" +require "parfait/message" +require "parfait/frame" diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 92903eaf..6fd20c04 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -1,6 +1,8 @@ # Class derives from and derives most of it's functionality (that you would associate with a class) # from there +# class is mainly a list of methods with a name (for now) +# layout of object is seperated into Layout # A Class is a module that can be instantiated @@ -8,8 +10,55 @@ # The Layout lists the names of the instance variables # The class keeps a list of instance methods, these have a name and code +require_relative "meta_class" + module Parfait class Class < Module + + def initialize name , super_class_name = :Object + super() + # class methods + @instance_methods = [] + @name = name.to_sym + @super_class_name = super_class_name.to_sym + @meta_class = Virtual::MetaClass.new(self) + end + attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name + def add_instance_method method + raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod + raise "syserr " unless method.name.is_a? Symbol + @instance_methods << method + end + + def get_instance_method fname + fname = fname.to_sym + @instance_methods.detect{ |fun| fun.name == fname } + end + + # get the method and if not found, try superclasses. raise error if not found + def resolve_method m_name + method = get_instance_method(m_name) + unless method + unless( @name == :Object) + supr = BootSpace.space.get_or_create_class(@super_class_name) + method = supr.resolve_method(m_name) + end + end + raise "Method not found #{m_name}, for #{@name}" unless method + method + end + + @@CLAZZ = { :names => [:name , :super_class_name , :instance_methods] , :types => [Virtual::Reference,Virtual::Reference,Virtual::Reference]} + def layout + @@CLAZZ + end + def mem_length + padded_words(3) + end + def to_s + inspect[0...300] + end + # ruby 2.1 list (just for reference, keep at bottom) #:allocate, :new, :superclass end diff --git a/lib/virtual/meta_class.rb b/lib/parfait/meta_class.rb similarity index 90% rename from lib/virtual/meta_class.rb rename to lib/parfait/meta_class.rb index 0e4fcf86..0b31e621 100644 --- a/lib/virtual/meta_class.rb +++ b/lib/parfait/meta_class.rb @@ -1,21 +1,21 @@ module Virtual - + # TODO : rethink - possibly needs to be a module to be mixed into Object # # class that acts like a class, but is really the object - - # described in the ruby language book as the eigenclass, what you get with - # class MyClass - # class << self <--- this is called the eigenclass, or metaclass, and really is just - # .... the class object but gives us the ability to use the + + # described in the ruby language book as the eigenclass, what you get with + # class MyClass + # class << self <--- this is called the eigenclass, or metaclass, and really is just + # .... the class object but gives us the ability to use the # syntax as if it were a class - # PS: can't say i fancy the << self syntax and am considerernig adding a + # PS: can't say i fancy the << self syntax and am considerernig adding a # keyword for it, like meta # In effect it is a very similar construct to def self.function(...) # So one could write def meta.function(...) and thus define on the meta-class - class MetaClass < Virtual::Object + class MetaClass < Object # no name, nor nothing. as this is just the object really - + def initialize(object) super() @functions = [] @@ -42,7 +42,7 @@ module Virtual end # get the function and if not found, try superclasses. raise error if not found - def resolve_method name + def resolve_method name fun = get_function name # TODO THE BOOK says is class A derives from B , then the metaclass of A derives from the metaclass of B # just get to it ! (and stop whimpering) @@ -50,7 +50,7 @@ module Virtual fun end - def to_s + def to_s "#{inspect} on #{@me_self}, #{@functions.length} functions" end end diff --git a/lib/virtual/boot_class.rb b/lib/virtual/boot_class.rb deleted file mode 100644 index 6a3bd3b5..00000000 --- a/lib/virtual/boot_class.rb +++ /dev/null @@ -1,54 +0,0 @@ -require_relative "meta_class" - -module Virtual - - # class is mainly a list of methods with a name (for now) - # layout of object is seperated into Layout - class BootClass < Virtual::ObjectConstant - def initialize name , super_class_name = :Object - super() - # class methods - @instance_methods = [] - @name = name.to_sym - @super_class_name = super_class_name.to_sym - @meta_class = Virtual::MetaClass.new(self) - end - attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name - def add_instance_method method - raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod - raise "syserr " unless method.name.is_a? Symbol - @instance_methods << method - end - - def get_instance_method fname - fname = fname.to_sym - @instance_methods.detect{ |fun| fun.name == fname } - end - - # get the method and if not found, try superclasses. raise error if not found - def resolve_method m_name - method = get_instance_method(m_name) - unless method - unless( @name == :Object) - supr = BootSpace.space.get_or_create_class(@super_class_name) - method = supr.resolve_method(m_name) - end - end - raise "Method not found #{m_name}, for #{@name}" unless method - method - end - - @@CLAZZ = { :names => [:name , :super_class_name , :instance_methods] , :types => [Virtual::Reference,Virtual::Reference,Virtual::Reference]} - def layout - @@CLAZZ - end - def mem_length - padded_words(3) - end - def to_s - inspect[0...300] - end - - end - -end diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index 50daa70f..dfcd581e 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -1,4 +1,3 @@ -require_relative "boot_class" require "register/builtin/object" module Virtual diff --git a/lib/virtual/object.rb b/lib/virtual/object.rb index 2b5893e8..cf52878f 100644 --- a/lib/virtual/object.rb +++ b/lib/virtual/object.rb @@ -1,10 +1,5 @@ require_relative "type" -require "parfait/message" -require "parfait/frame" -require "parfait/hash" -require "parfait/array" -require "parfait/string" -require "parfait/frame" +require "parfait" module Positioned def position