Parfait documentation
outline of expanded parfait, documented but not coded
This commit is contained in:
parent
4f1e99d744
commit
fdb3fbc825
@ -1,2 +1,18 @@
|
||||
|
||||
# A class describes the capabilities of an object, ie what data it has
|
||||
# and functions it responds to
|
||||
#
|
||||
# An Object carries the data for the instance variables it has
|
||||
# The Layout lists the names of the instance variables
|
||||
# The class keeps a list of instance methods, these have a name and code
|
||||
# The class also keeps a list of class methods (with names+code)
|
||||
# Class methods are instance methods on the class object
|
||||
|
||||
# So it is essential that the class (the object defining the class)
|
||||
# can carry methods. It does so as instance variables.
|
||||
# In fact this property is implemented in the Object, as methods
|
||||
# may be added to any object at run-time
|
||||
|
||||
class Class
|
||||
|
||||
end
|
||||
|
@ -1,4 +1,9 @@
|
||||
|
||||
# A Frame is set up by functions that use local variables or temporary variables
|
||||
# in fact temporary variables are local variables named by the system
|
||||
|
||||
# It allows for access to those variables basically
|
||||
|
||||
class Frame
|
||||
|
||||
end
|
||||
|
31
lib/parfait/layout.rb
Normal file
31
lib/parfait/layout.rb
Normal file
@ -0,0 +1,31 @@
|
||||
# An Object is really a hash like structure. It is dynamic and
|
||||
# you want to store values by name.
|
||||
# One could (like mri), store the names in each object, but that is wasteful
|
||||
# Instead we store only the values, and access them by index.
|
||||
# The Layout allows the mapping of names to index.
|
||||
|
||||
# The Layout of an object describes the memory layout of the object
|
||||
# The Layout is a simple list of the names of instance variables.
|
||||
#
|
||||
# As every object has a Layout to describe it, the name "layout" is the
|
||||
# first name in the list for every Layout.
|
||||
# But as we want every Object to have a class, this is the second
|
||||
# entry in the list. The name for the entry is "object_class"
|
||||
|
||||
# In other words, the Layout is a list of names that describe
|
||||
# the values stored in an actual object.
|
||||
# The object is an array of values of length n and
|
||||
# the Layout is an array of names of length n
|
||||
# Together they turn the object into a hash like structure
|
||||
|
||||
class Layout < Object
|
||||
|
||||
# given a name as symbol, return the integer index of that entry
|
||||
# we use 0 as "not found" as we don't want negatives, and can't raise
|
||||
# luckily 0 is always the type-word in an object and so by returning
|
||||
# one-offsets we can use the return value straight without adding 1
|
||||
def index_of( name )
|
||||
#internal implementation....
|
||||
end
|
||||
|
||||
end
|
@ -1,9 +1,24 @@
|
||||
# this is not a "normal" ruby file, ie it is not required by salama
|
||||
# instead it is parsed by salama to define part of the program that runs
|
||||
# to be precise, this should be an ObjectReference, as the Reference is a Value
|
||||
# but we don't want to make that distinction all the time , so we don't.
|
||||
|
||||
class Object
|
||||
# that does lead to the fact that we have Reference functions on the Object though
|
||||
|
||||
class Object < Value
|
||||
|
||||
def get_type()
|
||||
OBJECT_TYPE
|
||||
end
|
||||
|
||||
# This is the crux of the object system. The class of an object is stored in the objects
|
||||
# memory (as opposed to an integer that has no memory and so always has the same class)
|
||||
#
|
||||
# In Salama we store the class in the Layout, and so the Layout is the only fixed
|
||||
# data that every object carries.
|
||||
def get_class()
|
||||
@layout.get_class()
|
||||
end
|
||||
|
||||
def get_layout()
|
||||
@layout
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,13 @@
|
||||
|
||||
# A Page (from the traditionally a memory page) represents a collection of
|
||||
# objects in a physically form. Ie the page holds the memory or data, that
|
||||
# the objects are made up of.
|
||||
|
||||
# Pages have a total size, but more importantly and object size.
|
||||
# All objects of a Page are same sized, and multiples of the smallest
|
||||
# object. The smallest object is usually a cache line, 16 bytes or
|
||||
# an exponent of two larger.
|
||||
|
||||
class Page
|
||||
|
||||
end
|
||||
|
@ -1,3 +1,13 @@
|
||||
|
||||
# A Space is a collection of pages. It stores objects, the data for the objects,
|
||||
# not references. See Page for more detail.
|
||||
|
||||
# Pages are stored by the object size they represent in a hash.
|
||||
|
||||
# Space and Page work together in making *new* objects available.
|
||||
# "New" is slightly misleading in that normal operation only ever
|
||||
# recycles objects.
|
||||
|
||||
class Space
|
||||
|
||||
end
|
||||
|
37
lib/parfait/value.rb
Normal file
37
lib/parfait/value.rb
Normal file
@ -0,0 +1,37 @@
|
||||
# this is not a "normal" ruby file, ie it is not required by salama
|
||||
# instead it is parsed by salama to define part of the program that runs
|
||||
|
||||
# Values are _not_ objects. Specifically they have the following properties not found in objects:
|
||||
# - they are immutable
|
||||
# - equality implies identity == is ===
|
||||
# - they have type, not class
|
||||
|
||||
# To make them useful in an oo system, we assign a class to each basic type
|
||||
# This makes them look more like objects, but they are not.
|
||||
|
||||
# Value is an abstract class that unifies the "has a type" concept
|
||||
# Types are not "objectified", but are represented as integer constants
|
||||
|
||||
class Value
|
||||
|
||||
# to make the machine work, the constants need
|
||||
# - to start at 0
|
||||
# - be unique
|
||||
# - be smaller enough to fit into the 2-4 bits available
|
||||
INTEGER_VALUE = 0
|
||||
OBJECT_VALUE = 1
|
||||
|
||||
# the type is what identifies the value
|
||||
def get_type()
|
||||
raise "abstract clalled on #{self}"
|
||||
end
|
||||
|
||||
# Get class works on the type. The value's type is stored by the machine.
|
||||
# So this function is not overriden in derived classes, because it is used
|
||||
# to espablish what class a value has! (it's that "fake" oo i mentioned)
|
||||
def get_class()
|
||||
type = self.get_type()
|
||||
return Integer if( type == INTEGER_VALUE )
|
||||
raise "invalid type"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user