Class Hierarchy

The data structure of objects are defined by classes, and their behaviors are defined by methods in the classes. In EusLisp, a few dozens of classes have already been defined in tree structured hierarchy as depicted in fig. 4. You can browse the real inheritance structure by the class-hierarchy function. The class 'object' at the leftmost is the ultimate super-class of all the classes in EusLisp. User-defined classes can inherit any of these built-in classes.

Figure 4: Hierarchy of Predefined Classes
\begin{figure}\small
\begin{verbatim}object
cons
propertied-object
symbol -...
...h-table
surrounding-box
stereo-viewing\end{verbatim}
\normalsize\end{figure}

A class is defined the defclass macro or by the defstruct macro.


 (defclass class-name &key :super   class 

:slots ()
:metaclass metaclass
:element-type t
:size -1
)
(defstruct struct-name slots...)
(defstruct (struct-name [struct-options ...])
(slot-name1 [slot-option...])
(slot-name2 [slot-option...])
...)

Methods are defined by the defmethod special form. Defmethod can appear any times for a particular class.


 (defmethod class-name  

(:method-name1 (parameter...) . body1)
(:method-name2 (parameter...) . body2)
...)

Field definitions for most of built-in classes are found in *eusdir*/c/eus.h header file. (describe) class) gives the description of all the slots in class, namely, super class, slot names, slot types, method list, and so on. Definitions of built-in classes follow. Note that the superclass of class object is NIL since it has no super class.


 (defclass object :super NIL :slots ()) 


 (defclass cons :super object :slots (car cdr)) 


 (defclass propertied-object :super object 

:slots (plist)) ;property list


 (defclass symbol :super propertied-object 

:slots (value ;specially bound value
vtype ;const(0),var(1),special(2)
function ;global func def
pname ;print name string
homepkg)) ;home package


 (defclass foreign-pod :super symbol 

:slots (podcode ;entry code
paramtypes ;type of arguments
resulttype))


 (defclass package :super propertied-object 

:slots (names ;list of package name and nicknames
uses ;spread use-package list
symvector ;hashed obvector
symcount ;number of interned symbols
intsymvector ;hashed obvector of internal symbols
intsymcount ;number of interned internal symbols
shadows ;shadowed symbols
used-by)) ;packages using this package


 (defclass stream :super propertied-object   

:slots (direction ;:input or :output, nil if closed
buffer ;buffer string
count ;current character index
tail)) ;last character index


 (defclass file-stream :super stream 

:slots (fd ;file descriptor (integer)
fname)) ;file name str; qid for msgq


 (defclass broadcast-stream :super stream

:slots (destinations)) ;streams to which output is delivered


 (defclass io-stream :super propertied-object

:slots (instream outstream))


 (defclass socket-stream :super io-stream

:slots (address)) ; socket address


 (defclass read-table  :super propertied-object 

:slots (syntax ; byte vector representing character types
; 0:illegal, 1:white, 2:comment, 3:macro
; 4:constituent, 5:single_escape
; 6:multi_escape, 7:term_macro, 8:nonterm_macro
macro ;character macro expansion function
dispatch-macro))


 (defclass array :super propertied-object 

:slots (entity ;simple vector storing array entity
rank ;number of dimensions: 0-7
fillpointer ;pointer to push next element
offset ;offset for displaced array
dim0,dim1,dim2,dim3,dim4,dim5,dim6)) ;dimensions


 (defclass metaclass :super propertied-object 

:slots (name ;class name symbol
super ;super class
cix ;class id
vars ;var name vector including inherited vars
types ;type vector of object variables
forwards ;components to which messages are forwarded
methods)) ;method list


 (defclass vectorclass :super metaclass  

:slots (element-type ;vector element type 0-7
size)) ;vector size; 0 if unspecified


 (defclass cstructclass :super vectorclass  

:slots (slotlist)) ;cstruct slot descriptors


 (defclass vector :super object :slots (size)) 


 (defclass float-vector :super vector :element-type :float) 


 (defclass string :super vector :element-type :char) 


 (defclass hash-table :super propertied-object 

:slots (lisp::key ;hashed key vector
value ; value vector
size ; the size of the hash table
count ; number of elements entered in the table
lisp::hash-function
lisp::test-function
lisp::rehash-size
lisp::empty lisp::deleted )


 (defclass pathname :super propertied-object 

:slots (lisp::host device ; not used
directory ; list of directories
name ; file name before the last "."
type ; type field after the last "."
lisp::version) ; not used


 (defclass label-reference    ;for reading #n=, #n# objects 

:super object
:slots (label value unsolved next))


 (defclass compiled-code :super object 

:slots (codevector
quotevector
type ;0=func, 1=macro, 2=special
entry)) ;entry offset


 (defclass closure :super compiled-code 

:slots (env1 env2));environment


 (defclass foreign-code  :super compiled-code  

:slots (paramtypes ;list of parameter types
resulttype)) ;function result type


 (defclass load-module  :super compiled-code  

:slots (symbol-table ;hashtable of symbols defined
object-file ;name of the object file loaded, needed for unloading
handle ;file handle returned by ''dlopen''

k-okada 2013-05-21