qse/ase/stx/bootstrp.c

558 lines
15 KiB
C
Raw Normal View History

2005-05-22 15:38:31 +00:00
/*
2005-05-30 07:27:29 +00:00
* $Id: bootstrp.c,v 1.10 2005-05-30 07:27:29 bacon Exp $
2005-05-22 15:38:31 +00:00
*/
2005-05-23 12:06:53 +00:00
#include <xp/stx/bootstrp.h>
2005-05-22 15:38:31 +00:00
#include <xp/stx/symbol.h>
#include <xp/stx/class.h>
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/misc.h>
static void __create_bootstrapping_objects (xp_stx_t* stx);
2005-05-22 17:02:58 +00:00
static void __create_builtin_classes (xp_stx_t* stx);
2005-05-30 07:27:29 +00:00
static void __filein_kernel (xp_stx_t* stx);
2005-05-26 15:39:32 +00:00
2005-05-23 14:43:03 +00:00
static xp_stx_word_t __count_names (const xp_stx_char_t* str);
2005-05-23 15:51:03 +00:00
static void __set_names (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str);
2005-05-22 15:38:31 +00:00
2005-05-26 15:39:32 +00:00
static xp_stx_word_t __count_subclasses (const xp_stx_char_t* str);
static void __set_subclasses (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str);
2005-05-29 16:51:16 +00:00
static void __set_metaclass_subclasses (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str);
2005-05-26 15:39:32 +00:00
2005-05-22 16:26:58 +00:00
struct class_info_t
{
const xp_stx_char_t* name;
const xp_stx_char_t* superclass;
const xp_stx_char_t* instance_variables;
const xp_stx_char_t* class_variables;
const xp_stx_char_t* pool_dictionaries;
2005-05-24 03:28:31 +00:00
const int is_indexable;
2005-05-22 16:26:58 +00:00
};
typedef struct class_info_t class_info_t;
static class_info_t class_info[] =
{
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Object"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-05-30 07:27:29 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("UndefinedObject"),
XP_STX_TEXT("Object"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Behavior"),
XP_STX_TEXT("Object"),
2005-05-25 16:44:05 +00:00
XP_STX_TEXT("spec methods superclass"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Class"),
XP_STX_TEXT("Behavior"),
2005-05-25 16:44:05 +00:00
XP_STX_TEXT("name variables classVariables poolDictionaries"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Metaclass"),
XP_STX_TEXT("Behavior"),
2005-05-25 16:44:05 +00:00
XP_STX_TEXT("instanceClass"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Block"),
XP_STX_TEXT("Object"),
XP_STX_TEXT("context argCount argLoc bytePointer"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Boolean"),
XP_STX_TEXT("Object"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("True"),
XP_STX_TEXT("Boolean"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("False"),
XP_STX_TEXT("Boolean"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Context"),
XP_STX_TEXT("Object"),
XP_NULL,
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-23 14:43:03 +00:00
},
{
XP_STX_TEXT("Method"),
XP_STX_TEXT("Object"),
XP_STX_TEXT("text message bytecodes literals stackSize temporarySize class"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
},
2005-05-22 17:02:58 +00:00
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Magnitude"),
XP_STX_TEXT("Object"),
XP_NULL,
2005-05-22 17:02:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 17:02:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Collection"),
XP_STX_TEXT("Magnitude"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 17:02:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("IndexedCollection"),
XP_STX_TEXT("Collection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
1
2005-05-22 17:02:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("Array"),
XP_STX_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
1
2005-05-22 17:02:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("SymbolTable"),
XP_STX_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
1
2005-05-22 17:02:58 +00:00
},
{
2005-05-23 14:43:03 +00:00
XP_STX_TEXT("SystemDictionary"),
XP_STX_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
1
2005-05-22 17:02:58 +00:00
},
2005-05-22 16:26:58 +00:00
{
XP_NULL,
XP_NULL,
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
0
2005-05-22 16:26:58 +00:00
}
};
2005-05-23 15:51:03 +00:00
xp_stx_word_t xp_stx_new_array (xp_stx_t* stx, xp_stx_word_t size)
2005-05-23 14:43:03 +00:00
{
2005-05-23 15:51:03 +00:00
xp_stx_word_t x;
xp_stx_assert (stx->class_array != stx->nil);
x = xp_stx_alloc_word_object (stx, size);
XP_STX_CLASS(stx,x) = stx->class_array;
return x;
2005-05-23 14:43:03 +00:00
}
2005-05-22 15:38:31 +00:00
int xp_stx_bootstrap (xp_stx_t* stx)
{
xp_stx_word_t symbol_Smalltalk;
2005-05-25 16:44:05 +00:00
xp_stx_word_t object_meta;
2005-05-22 15:38:31 +00:00
__create_bootstrapping_objects (stx);
2005-05-23 14:43:03 +00:00
2005-05-25 16:44:05 +00:00
/* object, class, and array are precreated for easier instantiation
2005-05-23 14:43:03 +00:00
* of builtin classes */
2005-05-25 16:44:05 +00:00
stx->class_object = xp_stx_new_class (stx, XP_STX_TEXT("Object"));
stx->class_class = xp_stx_new_class (stx, XP_STX_TEXT("Class"));
2005-05-23 14:43:03 +00:00
stx->class_array = xp_stx_new_class (stx, XP_STX_TEXT("Array"));
2005-05-22 17:02:58 +00:00
__create_builtin_classes (stx);
2005-05-22 15:38:31 +00:00
2005-05-25 16:44:05 +00:00
/* (Object class) setSuperclass: Class */
object_meta = XP_STX_CLASS(stx,stx->class_object);
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,object_meta,XP_STX_METACLASS_SUPERCLASS) = stx->class_class;
2005-05-25 16:44:05 +00:00
/* instance class for Object is set here as it is not
* set in __create_builtin_classes */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,object_meta,XP_STX_METACLASS_INSTANCE_CLASS) = stx->class_object;
2005-05-25 16:44:05 +00:00
2005-05-29 16:51:16 +00:00
/* for some fun here */
{
xp_stx_word_t array;
array = xp_stx_new_array (stx, 1);
XP_STX_WORDAT(stx,array,0) = object_meta;
XP_STX_WORDAT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
}
2005-05-22 15:38:31 +00:00
/* more initialization */
XP_STX_CLASS(stx,stx->symbol_table) =
2005-05-22 17:02:58 +00:00
xp_stx_lookup_class (stx, XP_STX_TEXT("SymbolTable"));
2005-05-22 15:38:31 +00:00
XP_STX_CLASS(stx,stx->smalltalk) =
2005-05-22 17:02:58 +00:00
xp_stx_lookup_class (stx, XP_STX_TEXT("SystemDictionary"));
2005-05-22 15:38:31 +00:00
symbol_Smalltalk =
xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk"));
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx,symbol_Smalltalk),
symbol_Smalltalk, stx->smalltalk);
/* create #nil, #true, #false */
xp_stx_new_symbol (stx, XP_STX_TEXT("nil"));
xp_stx_new_symbol (stx, XP_STX_TEXT("true"));
xp_stx_new_symbol (stx, XP_STX_TEXT("false"));
/* nil setClass: UndefinedObject */
XP_STX_CLASS(stx,stx->nil) =
2005-05-22 17:02:58 +00:00
xp_stx_lookup_class (stx, XP_STX_TEXT("UndefinedObject"));
2005-05-22 15:38:31 +00:00
/* true setClass: True */
XP_STX_CLASS(stx,stx->true) =
2005-05-22 17:02:58 +00:00
xp_stx_lookup_class (stx, XP_STX_TEXT("True"));
2005-05-22 15:38:31 +00:00
/* fales setClass: False */
XP_STX_CLASS(stx,stx->false) =
2005-05-22 17:02:58 +00:00
xp_stx_lookup_class (stx, XP_STX_TEXT("False"));
2005-05-22 15:38:31 +00:00
2005-05-30 07:27:29 +00:00
__filein_kernel (stx);
2005-05-22 15:38:31 +00:00
return 0;
}
static void __create_bootstrapping_objects (xp_stx_t* stx)
{
xp_stx_word_t class_SymlinkMeta;
xp_stx_word_t class_SymbolMeta;
xp_stx_word_t class_MetaclassMeta;
xp_stx_word_t class_PairlinkMeta;
xp_stx_word_t symbol_Symlink;
xp_stx_word_t symbol_Symbol;
xp_stx_word_t symbol_Metaclass;
xp_stx_word_t symbol_Pairlink;
/* allocate three keyword objects */
stx->nil = xp_stx_alloc_word_object (stx, 0);
stx->true = xp_stx_alloc_word_object (stx, 0);
stx->false = xp_stx_alloc_word_object (stx, 0);
xp_stx_assert (stx->nil == XP_STX_NIL);
xp_stx_assert (stx->true == XP_STX_TRUE);
xp_stx_assert (stx->false == XP_STX_FALSE);
/* symbol table & system dictionary */
/* TODO: symbol table and dictionary size */
stx->symbol_table = xp_stx_alloc_word_object (stx, 1000);
stx->smalltalk = xp_stx_alloc_word_object (stx, 2000);
stx->class_symlink = /* Symlink */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE);
stx->class_symbol = /* Symbol */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE);
stx->class_metaclass = /* Metaclass */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE);
stx->class_pairlink = /* Pairlink */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE);
2005-05-25 16:44:05 +00:00
/* Metaclass is a class so it has the same structure
* as a normal class. "Metaclass class" is an instance of
* Metaclass. */
2005-05-22 15:38:31 +00:00
class_SymlinkMeta = /* Symlink class */
2005-05-25 16:44:05 +00:00
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE);
2005-05-22 15:38:31 +00:00
class_SymbolMeta = /* Symbol class */
2005-05-25 16:44:05 +00:00
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE);
2005-05-22 15:38:31 +00:00
class_MetaclassMeta = /* Metaclass class */
2005-05-25 16:44:05 +00:00
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE);
2005-05-22 15:38:31 +00:00
class_PairlinkMeta = /* Pairlink class */
2005-05-25 16:44:05 +00:00
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE);
2005-05-22 15:38:31 +00:00
/* (Symlink class) setClass: Metaclass */
XP_STX_CLASS(stx,class_SymlinkMeta) = stx->class_metaclass;
/* (Symbol class) setClass: Metaclass */
XP_STX_CLASS(stx,class_SymbolMeta) = stx->class_metaclass;
/* (Metaclass class) setClass: Metaclass */
XP_STX_CLASS(stx,class_MetaclassMeta) = stx->class_metaclass;
/* (Pairlink class) setClass: Metaclass */
XP_STX_CLASS(stx,class_PairlinkMeta) = stx->class_metaclass;
/* Symlink setClass: (Symlink class) */
XP_STX_CLASS(stx,stx->class_symlink) = class_SymlinkMeta;
/* Symbol setClass: (Symbol class) */
XP_STX_CLASS(stx,stx->class_symbol) = class_SymbolMeta;
/* Metaclass setClass: (Metaclass class) */
XP_STX_CLASS(stx,stx->class_metaclass) = class_MetaclassMeta;
/* Pairlink setClass: (Pairlink class) */
XP_STX_CLASS(stx,stx->class_pairlink) = class_PairlinkMeta;
2005-05-25 16:44:05 +00:00
/* (Symlink class) setSpec: XP_STX_CLASS_SIZE */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,class_SymlinkMeta,XP_STX_CLASS_SPEC) =
2005-05-24 03:28:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << 1) | 0x00);
2005-05-22 15:38:31 +00:00
/* (Symbol class) setSpec: CLASS_SIZE */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,class_SymbolMeta,XP_STX_CLASS_SPEC) =
2005-05-24 03:28:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << 1) | 0x00);
2005-05-22 15:38:31 +00:00
/* (Metaclass class) setSpec: CLASS_SIZE */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,class_MetaclassMeta,XP_STX_CLASS_SPEC) =
2005-05-24 03:28:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << 1) | 0x00);
2005-05-22 15:38:31 +00:00
/* (Pairlink class) setSpec: CLASS_SIZE */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,class_PairlinkMeta,XP_STX_CLASS_SPEC) =
2005-05-24 03:28:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << 1) | 0x00);
2005-05-22 15:38:31 +00:00
2005-05-25 16:44:05 +00:00
/* specs for class_metaclass, class_pairlink,
* class_symbol, class_symlink are set later in
* __create_builtin_classes */
2005-05-22 15:38:31 +00:00
/* #Symlink */
symbol_Symlink = xp_stx_new_symbol (stx, XP_STX_TEXT("Symlink"));
/* #Symbol */
symbol_Symbol = xp_stx_new_symbol (stx, XP_STX_TEXT("Symbol"));
/* #Metaclass */
symbol_Metaclass = xp_stx_new_symbol (stx, XP_STX_TEXT("Metaclass"));
/* #Pairlink */
symbol_Pairlink = xp_stx_new_symbol (stx, XP_STX_TEXT("Pairlink"));
/* Symlink setName: #Symlink */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,stx->class_symlink,XP_STX_CLASS_NAME) = symbol_Symlink;
2005-05-22 15:38:31 +00:00
/* Symbol setName: #Symbol */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_Symbol;
2005-05-22 15:38:31 +00:00
/* Metaclass setName: #Metaclass */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,stx->class_metaclass,XP_STX_CLASS_NAME) = symbol_Metaclass;
2005-05-22 15:38:31 +00:00
/* Pairlink setName: #Pairlink */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,stx->class_pairlink,XP_STX_CLASS_NAME) = symbol_Pairlink;
2005-05-22 15:38:31 +00:00
/* register class names into the system dictionary */
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx, symbol_Symlink),
symbol_Symlink, stx->class_symlink);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx, symbol_Symbol),
symbol_Symbol, stx->class_symbol);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx, symbol_Metaclass),
symbol_Metaclass, stx->class_metaclass);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx, symbol_Pairlink),
symbol_Pairlink, stx->class_pairlink);
}
2005-05-22 17:02:58 +00:00
static void __create_builtin_classes (xp_stx_t* stx)
2005-05-22 16:26:58 +00:00
{
2005-05-23 14:43:03 +00:00
class_info_t* p;
2005-05-23 16:07:39 +00:00
xp_stx_word_t class, superclass, array;
xp_stx_class_t* class_obj, * superclass_obj;
2005-05-29 16:51:16 +00:00
xp_stx_word_t metaclass;
xp_stx_metaclass_t* metaclass_obj;
2005-05-24 03:28:31 +00:00
xp_stx_word_t n, spec;
2005-05-22 16:26:58 +00:00
2005-05-23 14:43:03 +00:00
xp_stx_assert (stx->class_array != stx->nil);
for (p = class_info; p->name != XP_NULL; p++) {
2005-05-22 17:02:58 +00:00
class = xp_stx_lookup_class(stx, p->name);
if (class == stx->nil) {
class = xp_stx_new_class (stx, p->name);
2005-05-22 16:26:58 +00:00
}
2005-05-22 17:02:58 +00:00
xp_stx_assert (class != stx->nil);
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
class_obj->superclass = (p->superclass == XP_NULL)?
stx->nil: xp_stx_lookup_class(stx,p->superclass);
2005-05-25 16:44:05 +00:00
spec = 0;
2005-05-23 16:07:39 +00:00
if (p->superclass != XP_NULL) {
2005-05-25 16:44:05 +00:00
xp_stx_word_t meta;
xp_stx_metaclass_t* meta_obj;
2005-05-23 16:07:39 +00:00
superclass = xp_stx_lookup_class(stx,p->superclass);
xp_stx_assert (superclass != stx->nil);
2005-05-25 16:44:05 +00:00
meta = class_obj->header.class;
meta_obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx,meta);
meta_obj->superclass = XP_STX_CLASS(stx,superclass);
meta_obj->instance_class = class;
2005-05-23 16:07:39 +00:00
while (superclass != stx->nil) {
superclass_obj = (xp_stx_class_t*)
XP_STX_WORD_OBJECT(stx,superclass);
2005-05-24 03:28:31 +00:00
spec += XP_STX_FROM_SMALLINT(superclass_obj->spec >> 1);
2005-05-23 16:07:39 +00:00
superclass = superclass_obj->superclass;
}
2005-05-25 16:44:05 +00:00
2005-05-23 16:07:39 +00:00
}
2005-05-23 14:43:03 +00:00
if (p->instance_variables != XP_NULL) {
n = __count_names (p->instance_variables);
array = xp_stx_new_array (stx, n);
2005-05-23 15:51:03 +00:00
__set_names (stx, XP_STX_DATA(stx,array), p->instance_variables);
2005-05-23 14:43:03 +00:00
class_obj->variables = array;
}
2005-05-24 03:28:31 +00:00
class_obj->spec = XP_STX_TO_SMALLINT(((spec + n) << 1) | p->is_indexable);
2005-05-23 14:43:03 +00:00
if (p->class_variables != XP_NULL) {
2005-05-23 15:51:03 +00:00
n = __count_names (p->class_variables);
2005-05-23 14:43:03 +00:00
array = xp_stx_new_array (stx, n);
2005-05-23 15:51:03 +00:00
__set_names (stx, XP_STX_DATA(stx,array), p->class_variables);
2005-05-25 16:44:05 +00:00
class_obj->class_variables = array;
}
/*
TODO:
if (p->pool_dictionaries != XP_NULL) {
2005-05-23 14:43:03 +00:00
}
2005-05-25 16:44:05 +00:00
*/
2005-05-22 16:26:58 +00:00
}
2005-05-26 15:39:32 +00:00
/* fill subclasses */
for (p = class_info; p->name != XP_NULL; p++) {
n = __count_subclasses (p->name);
array = xp_stx_new_array (stx, n);
__set_subclasses (stx, XP_STX_DATA(stx,array), p->name);
class = xp_stx_lookup_class(stx, p->name);
xp_stx_assert (class != stx->nil);
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
class_obj->subclasses = array;
}
2005-05-29 16:51:16 +00:00
/* fill subclasses for metaclasses */
for (p = class_info; p->name != XP_NULL; p++) {
n = __count_subclasses (p->name);
array = xp_stx_new_array (stx, n);
__set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name);
class = xp_stx_lookup_class(stx, p->name);
xp_stx_assert (class != stx->nil);
metaclass = XP_STX_CLASS(stx,class);
metaclass_obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx, metaclass);
metaclass_obj->subclasses = array;
}
2005-05-22 16:26:58 +00:00
}
2005-05-23 14:43:03 +00:00
static xp_stx_word_t __count_names (const xp_stx_char_t* str)
{
xp_stx_word_t n = 0;
const xp_stx_char_t* p = str;
do {
while (*p == XP_STX_CHAR(' ') ||
*p == XP_STX_CHAR('\t')) p++;
if (*p == XP_STX_CHAR('\0')) break;
n++;
while (*p != XP_STX_CHAR(' ') &&
*p != XP_STX_CHAR('\t') &&
*p != XP_STX_CHAR('\0')) p++;
} while (1);
return n;
}
2005-05-23 15:51:03 +00:00
static void __set_names (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str)
2005-05-23 14:43:03 +00:00
{
xp_stx_word_t n = 0;
const xp_stx_char_t* p = str;
2005-05-23 15:51:03 +00:00
const xp_stx_char_t* name;
2005-05-23 14:43:03 +00:00
do {
while (*p == XP_STX_CHAR(' ') ||
*p == XP_STX_CHAR('\t')) p++;
if (*p == XP_STX_CHAR('\0')) break;
2005-05-23 15:51:03 +00:00
name = p;
2005-05-23 14:43:03 +00:00
while (*p != XP_STX_CHAR(' ') &&
*p != XP_STX_CHAR('\t') &&
*p != XP_STX_CHAR('\0')) p++;
2005-05-23 15:51:03 +00:00
array[n++] = xp_stx_new_symbolx (stx, name, p - name);
} while (1);
2005-05-23 14:43:03 +00:00
}
2005-05-26 15:39:32 +00:00
static xp_stx_word_t __count_subclasses (const xp_stx_char_t* str)
{
class_info_t* p;
xp_stx_word_t n = 0;
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
if (xp_stx_strcmp (str, p->superclass) == 0) n++;
}
return n;
}
static void __set_subclasses (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str)
{
class_info_t* p;
xp_stx_word_t n = 0, class;
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
if (xp_stx_strcmp (str, p->superclass) != 0) continue;
class = xp_stx_lookup_class (stx, p->name);
xp_stx_assert (class != stx->nil);
array[n++] = class;
}
}
2005-05-29 16:51:16 +00:00
static void __set_metaclass_subclasses (
xp_stx_t* stx, xp_stx_word_t* array, const xp_stx_char_t* str)
{
class_info_t* p;
xp_stx_word_t n = 0, class;
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
if (xp_stx_strcmp (str, p->superclass) != 0) continue;
class = xp_stx_lookup_class (stx, p->name);
xp_stx_assert (class != stx->nil);
array[n++] = XP_STX_CLASS(stx,class);
}
}
2005-05-30 07:27:29 +00:00
static void __filein_kernel (xp_stx_t* stx)
{
class_info_t* p;
for (p = class_info; p->name != XP_NULL; p++) {
/* TODO: */
}
}