changing to ruby instance variables

from the fake memory
This commit is contained in:
Torsten Ruger 2016-12-29 18:47:45 +02:00
parent b5f04ec718
commit 6214040888
4 changed files with 51 additions and 55 deletions

View File

@ -4,20 +4,16 @@
module Parfait
module Behaviour
# when included we set up the instance_methods attribute
def self.included(base)
base.attribute :instance_methods
end
def initialize
super()
self.instance_methods = List.new
@instance_methods = List.new
end
def methods
m = self.instance_methods
m = @instance_methods
return m if m
self.instance_methods = List.new
@instance_methods = List.new
end
def method_names
@ -49,7 +45,7 @@ module Parfait
raise "resolve_method #{m_name}.#{m_name.class}" unless m_name.is_a?(Symbol)
method = get_instance_method(m_name)
return method if method
if( self.super_class_name )
if( @super_class_name != :Object )
method = self.super_class.resolve_method(m_name)
end
method

View File

@ -16,20 +16,17 @@
module Parfait
class Class < Object
include Behaviour
attributes [:instance_type , :name , :super_class_name , :instance_names]
def initialize name , superclass
super()
self.name = name
self.super_class_name = superclass
# the type for this class (class = object of type Class) carries the class
# as an instance. The relation is from an object through the Type to it's class
# TODO the object type should copy the stuff from superclass
self.instance_type = Type.new(self)
def self.attributes
[:instance_type , :name , :super_class_name , :instance_names , :instance_methods]
end
def allocate_object
#space, and ruby allocate
attr_reader :instance_type , :name , :instance_methods , :super_class_name
def initialize( name , superclass , instance_type)
super()
@name = name
@super_class_name = superclass
@instance_type = instance_type
end
def sof_reference_name
@ -43,21 +40,13 @@ module Parfait
# setting the type generates all methods for this type
# (or will do, once we storet the methods code to do that)
def set_instance_type( type )
self.instance_type = type
end
# this needs to be done during booting as we can't have all the classes and superclassses
# instantiated. By that logic it should maybe be part of vm rather.
# On the other hand vague plans to load the hierachy from sof exist, so for now...
def set_super_class_name sup
raise "super_class_name must be a name, not #{sup}" unless sup.is_a?(Symbol)
self.super_class_name = sup
@instance_type = type
end
def super_class
raise "No super_class for class #{self.name}" unless self.super_class_name
s = Parfait::Space.object_space.get_class_by_name(self.super_class_name)
raise "superclass not found for class #{self.name} (#{self.super_class_name})" unless s
raise "No super_class for class #{@name}" unless @super_class_name
s = Parfait::Space.object_space.get_class_by_name(@super_class_name)
raise "superclass not found for class #{@name} (#{@super_class_name})" unless s
s
end

View File

@ -2,25 +2,29 @@
module Parfait
class Dictionary < Object
attribute :keys
attribute :values
def self.attributes
[:keys, :values]
end
# only empty initialization for now
#
# internally we store keys and values in lists, which means this does **not** scale well
def initialize
super()
self.keys = List.new()
self.values = List.new()
@keys = List.new()
@values = List.new()
end
attr_reader :values , :keys #FIXME these should be dupped, not handed out
# are there any key/value items in the list
def empty?
self.keys.empty?
@keys.empty?
end
# How many key/value pairs there are
def length()
return self.keys.get_length()
return @keys.get_length()
end
# get a value fot the given key
@ -29,7 +33,7 @@ module Parfait
def get(key)
index = key_index(key)
if( index )
self.values.get(index)
@values.get(index)
else
nil
end
@ -42,11 +46,11 @@ module Parfait
# private method
def key_index(key)
len = self.keys.get_length()
len = @keys.get_length()
index = 1
found = nil
while(index <= len)
if( self.keys.get(index) == key)
if( @keys.get(index) == key)
found = index
break
end
@ -59,10 +63,10 @@ module Parfait
def set(key , value)
index = key_index(key)
if( index )
self.keys.set(index , value)
@keys.set(index , value)
else
self.keys.push(key)
self.values.push(value)
@keys.push(key)
@values.push(value)
end
value
end
@ -75,9 +79,9 @@ module Parfait
# yield to each key value pair
def each
index = 1
while index <= self.keys.get_length
key = self.keys.get(index)
value = self.values.get(index)
while index <= @keys.get_length
key = @keys.get(index)
value = @values.get(index)
yield key , value
index = index + 1
end

View File

@ -9,20 +9,27 @@
module Parfait
class Message < Object
attributes [:next_message , :receiver , :locals , :return_address ]
attributes [:return_value, :caller , :name , :arguments]
def self.attributes
[:next_message , :receiver , :locals , :return_address ,
:return_value, :caller , :name , :arguments]
end
attr_reader :locals , :receiver , :return_value , :name
attr_accessor :next_message
def initialize next_m
self.next_message = next_m
self.locals = NamedList.new()
self.arguments = NamedList.new()
self.caller = nil
@next_message = next_m
@locals = NamedList.new()
@arguments = NamedList.new()
super()
end
def set_receiver(rec)
@receiver = rec
end
def set_caller caller
self.caller = caller
def set_caller(caller)
@caller = caller
end
def get_type_for(name)