array to list conversion

start on layouts
This commit is contained in:
Torsten Ruger
2015-05-16 14:01:48 +03:00
parent bee269f7a8
commit 7085dee510
6 changed files with 45 additions and 9 deletions

View File

@ -22,6 +22,7 @@ module Parfait
@name = name.to_sym
@super_class_name = super_class_name.to_sym
@meta_class = Virtual::MetaClass.new(self)
@object_layout = []
end
attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name
def add_instance_method method
@ -30,6 +31,11 @@ module Parfait
@instance_methods << method
end
def set_instance_names list
@object_layout = Layout.new_object
@object_layout.set_names list
end
def get_instance_method fname
fname = fname.to_sym
@instance_methods.detect{ |fun| fun.name == fname }

View File

@ -22,6 +22,17 @@
module Parfait
class Layout < List
# set the names of the instance variables in one go
# used while booting the classes. At runtime the list would grow dynamically
def set_names list
self.set_length list.length
index = 0
while index < list.length do
list.set(index , array.get(index))
end
end
# beat the recursion! fixed known offset for class object in the layout
def get_object_class()
return internal_object_get(2)
end

View File

@ -51,6 +51,10 @@ module Parfait
end
self
end
def set_length len
# TODO check if not shrinking
grow_to len
end
def grow_to(len)
raise "negative length for grow #{len}" if len < 0
return unless len > self.length

View File

@ -55,12 +55,15 @@ module Parfait
def get_class_by_name name
raise "uups #{name}.#{name.class}" unless name.is_a? Symbol
c = @classes[name]
unless c
c = Class.new_object(name)
@classes[name] = c
end
c
end
def create_class name , variable_names
c = Class.new_object(name)
c.set_instance_names Parfait.new_list(variable_names)
@classes[name] = c
end
def mem_length
padded_words( 5 )
end