qse/ase/stx/bootstrp.c

683 lines
17 KiB
C
Raw Normal View History

2005-05-22 15:38:31 +00:00
/*
2005-07-05 04:29:31 +00:00
* $Id: bootstrp.c,v 1.19 2005-07-05 04:29:31 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-07-03 16:37:01 +00:00
static xp_word_t __make_classvar_dict (
xp_stx_t* stx, xp_word_t class, const xp_char_t* names);
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-06-08 16:00:51 +00:00
static xp_word_t __count_names (const xp_char_t* str);
2005-05-23 15:51:03 +00:00
static void __set_names (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str);
2005-05-22 15:38:31 +00:00
2005-06-08 16:00:51 +00:00
static xp_word_t __count_subclasses (const xp_char_t* str);
2005-05-26 15:39:32 +00:00
static void __set_subclasses (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str);
2005-05-29 16:51:16 +00:00
static void __set_metaclass_subclasses (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str);
2005-05-26 15:39:32 +00:00
2005-05-22 16:26:58 +00:00
struct class_info_t
{
2005-06-08 16:00:51 +00:00
const xp_char_t* name;
const xp_char_t* superclass;
const xp_char_t* instance_variables;
const xp_char_t* class_variables;
const xp_char_t* pool_dictionaries;
2005-07-04 16:23:13 +00:00
const int indexable;
2005-05-22 16:26:58 +00:00
};
typedef struct class_info_t class_info_t;
static class_info_t class_info[] =
{
{
2005-06-08 16:00:51 +00:00
XP_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-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("UndefinedObject"),
XP_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-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Behavior"),
XP_TEXT("Object"),
XP_TEXT("spec methods superclass"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Class"),
XP_TEXT("Behavior"),
XP_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,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Metaclass"),
XP_TEXT("Behavior"),
XP_TEXT("instanceClass"),
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Block"),
XP_TEXT("Object"),
XP_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,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Boolean"),
XP_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-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("True"),
XP_TEXT("Boolean"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("False"),
XP_TEXT("Boolean"),
2005-05-22 16:26:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Context"),
XP_TEXT("Object"),
2005-05-23 14:43:03 +00:00
XP_NULL,
2005-05-22 16:26:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-23 14:43:03 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Method"),
XP_TEXT("Object"),
2005-07-04 11:32:41 +00:00
XP_TEXT("text message bytecodes literals stackSize temporarySize"),
2005-07-03 16:37:01 +00:00
//XP_NULL,
XP_TEXT("Win32Errors"), // TODO: REMOVE THIS
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
2005-05-22 17:02:58 +00:00
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Magnitude"),
XP_TEXT("Object"),
2005-05-23 14:43:03 +00:00
XP_NULL,
2005-05-22 17:02:58 +00:00
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Collection"),
XP_TEXT("Magnitude"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("IndexedCollection"),
XP_TEXT("Collection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("Array"),
XP_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_WORD_INDEXABLE
},
{
XP_TEXT("ByteArray"),
XP_TEXT("IndexedCollection"),
XP_NULL,
XP_NULL,
XP_NULL,
XP_STX_SPEC_BYTE_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2005-06-08 16:00:51 +00:00
XP_TEXT("SymbolTable"),
XP_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_WORD_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2005-07-03 16:37:01 +00:00
XP_TEXT("Dictionary"),
2005-06-08 16:00:51 +00:00
XP_TEXT("IndexedCollection"),
2005-05-22 17:02:58 +00:00
XP_NULL,
XP_NULL,
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_WORD_INDEXABLE
2005-05-22 17:02:58 +00:00
},
2005-07-03 16:37:01 +00:00
{
XP_TEXT("SystemDictionary"),
XP_TEXT("Dictionary"),
XP_NULL,
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_WORD_INDEXABLE
2005-07-03 16:37:01 +00:00
},
{
XP_TEXT("PoolDictionary"),
XP_TEXT("Dictionary"),
XP_NULL,
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_WORD_INDEXABLE
2005-07-03 16:37:01 +00:00
},
2005-06-30 12:07:02 +00:00
{
XP_TEXT("String"),
XP_TEXT("IndexedCollection"),
XP_NULL,
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_CHAR_INDEXABLE
2005-06-30 12:07:02 +00:00
},
{
XP_TEXT("Symbol"),
XP_TEXT("String"),
XP_NULL,
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_CHAR_INDEXABLE
2005-06-30 12:07:02 +00:00
},
{
XP_TEXT("Link"),
XP_TEXT("Object"),
XP_TEXT("link"),
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-06-30 12:07:02 +00:00
},
{
XP_TEXT("Symlink"),
XP_TEXT("Link"),
XP_TEXT("symbol"),
XP_NULL,
XP_NULL,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-06-30 12:07:02 +00:00
},
2005-07-04 16:23:13 +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,
2005-07-04 16:23:13 +00:00
XP_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
}
};
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size)
2005-05-23 14:43:03 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t x;
2005-05-23 15:51:03 +00:00
2005-06-08 16:00:51 +00:00
xp_assert (stx->class_array != stx->nil);
2005-05-23 15:51:03 +00:00
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-06-30 12:07:02 +00:00
xp_word_t xp_stx_new_string (xp_stx_t* stx, const xp_char_t* str)
{
xp_word_t x;
xp_assert (stx->class_string != stx->nil);
x = xp_stx_alloc_char_object (stx, str);
XP_STX_CLASS(stx,x) = stx->class_string;
return x;
}
2005-05-22 15:38:31 +00:00
int xp_stx_bootstrap (xp_stx_t* stx)
{
2005-06-08 16:00:51 +00:00
xp_word_t symbol_Smalltalk;
xp_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-06-08 16:00:51 +00:00
stx->class_object = xp_stx_new_class (stx, XP_TEXT("Object"));
stx->class_class = xp_stx_new_class (stx, XP_TEXT("Class"));
stx->class_array = xp_stx_new_class (stx, XP_TEXT("Array"));
2005-07-05 04:29:31 +00:00
stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray"));
2005-06-30 12:07:02 +00:00
stx->class_string = xp_stx_new_class (stx, XP_TEXT("String"));
2005-07-05 04:29:31 +00:00
stx->class_dictionary = xp_stx_new_class (stx, XP_TEXT("Dictionary"));
2005-05-23 14:43:03 +00:00
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 */
{
2005-06-08 16:00:51 +00:00
xp_word_t array;
2005-05-29 16:51:16 +00:00
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-06-08 16:00:51 +00:00
xp_stx_lookup_class (stx, XP_TEXT("SymbolTable"));
2005-05-22 15:38:31 +00:00
XP_STX_CLASS(stx,stx->smalltalk) =
2005-06-08 16:00:51 +00:00
xp_stx_lookup_class (stx, XP_TEXT("SystemDictionary"));
2005-05-22 15:38:31 +00:00
symbol_Smalltalk =
2005-06-08 16:00:51 +00:00
xp_stx_new_symbol (stx, XP_TEXT("Smalltalk"));
2005-05-22 15:38:31 +00:00
xp_stx_hash_insert (stx, stx->smalltalk,
2005-07-03 16:37:01 +00:00
xp_stx_hash_char_object(stx, symbol_Smalltalk),
2005-05-22 15:38:31 +00:00
symbol_Smalltalk, stx->smalltalk);
/* create #nil, #true, #false */
2005-06-08 16:00:51 +00:00
xp_stx_new_symbol (stx, XP_TEXT("nil"));
xp_stx_new_symbol (stx, XP_TEXT("true"));
xp_stx_new_symbol (stx, XP_TEXT("false"));
2005-05-22 15:38:31 +00:00
/* nil setClass: UndefinedObject */
XP_STX_CLASS(stx,stx->nil) =
2005-06-08 16:00:51 +00:00
xp_stx_lookup_class (stx, XP_TEXT("UndefinedObject"));
2005-05-22 15:38:31 +00:00
/* true setClass: True */
XP_STX_CLASS(stx,stx->true) =
2005-06-08 16:00:51 +00:00
xp_stx_lookup_class (stx, XP_TEXT("True"));
2005-05-22 15:38:31 +00:00
/* fales setClass: False */
XP_STX_CLASS(stx,stx->false) =
2005-06-08 16:00:51 +00:00
xp_stx_lookup_class (stx, XP_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)
{
2005-06-08 16:00:51 +00:00
xp_word_t class_SymlinkMeta;
xp_word_t class_SymbolMeta;
xp_word_t class_MetaclassMeta;
xp_word_t class_PairlinkMeta;
xp_word_t symbol_Symlink;
xp_word_t symbol_Symbol;
xp_word_t symbol_Metaclass;
xp_word_t symbol_Pairlink;
2005-05-22 15:38:31 +00:00
/* 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);
2005-06-08 16:00:51 +00:00
xp_assert (stx->nil == XP_STX_NIL);
xp_assert (stx->true == XP_STX_TRUE);
xp_assert (stx->false == XP_STX_FALSE);
2005-05-22 15:38:31 +00:00
/* 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-07-05 04:29:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
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-07-05 04:29:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
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-07-05 04:29:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
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-07-05 04:29:31 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
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 */
2005-06-08 16:00:51 +00:00
symbol_Symlink = xp_stx_new_symbol (stx, XP_TEXT("Symlink"));
2005-05-22 15:38:31 +00:00
/* #Symbol */
2005-06-08 16:00:51 +00:00
symbol_Symbol = xp_stx_new_symbol (stx, XP_TEXT("Symbol"));
2005-05-22 15:38:31 +00:00
/* #Metaclass */
2005-06-08 16:00:51 +00:00
symbol_Metaclass = xp_stx_new_symbol (stx, XP_TEXT("Metaclass"));
2005-05-22 15:38:31 +00:00
/* #Pairlink */
2005-06-08 16:00:51 +00:00
symbol_Pairlink = xp_stx_new_symbol (stx, XP_TEXT("Pairlink"));
2005-05-22 15:38:31 +00:00
/* 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-06-08 16:00:51 +00:00
xp_word_t class, superclass, array;
2005-05-23 16:07:39 +00:00
xp_stx_class_t* class_obj, * superclass_obj;
2005-06-08 16:00:51 +00:00
xp_word_t metaclass;
2005-05-29 16:51:16 +00:00
xp_stx_metaclass_t* metaclass_obj;
2005-07-04 16:23:13 +00:00
xp_word_t n, nfields;
2005-05-22 16:26:58 +00:00
2005-06-08 16:00:51 +00:00
xp_assert (stx->class_array != stx->nil);
2005-05-23 14:43:03 +00:00
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
2005-06-08 16:00:51 +00:00
xp_assert (class != stx->nil);
2005-05-22 17:02:58 +00:00
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-07-04 16:23:13 +00:00
nfields = 0;
2005-05-23 16:07:39 +00:00
if (p->superclass != XP_NULL) {
2005-06-08 16:00:51 +00:00
xp_word_t meta;
2005-05-25 16:44:05 +00:00
xp_stx_metaclass_t* meta_obj;
2005-05-23 16:07:39 +00:00
superclass = xp_stx_lookup_class(stx,p->superclass);
2005-06-08 16:00:51 +00:00
xp_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-07-05 04:29:31 +00:00
nfields +=
XP_STX_FROM_SMALLINT(superclass_obj->spec) >>
XP_STX_SPEC_INDEXABLE_BITS;
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-06-30 12:07:02 +00:00
if (p->instance_variables != XP_NULL) {
2005-07-04 16:23:13 +00:00
nfields += __count_names (p->instance_variables);
2005-06-30 12:07:02 +00:00
class_obj->variables =
xp_stx_new_string (stx, p->instance_variables);
}
2005-05-23 14:43:03 +00:00
2005-07-04 16:23:13 +00:00
xp_assert (nfields <= 0 || (nfields > 0 &&
(p->indexable == XP_STX_SPEC_NOT_INDEXABLE ||
p->indexable == XP_STX_SPEC_WORD_INDEXABLE)));
2005-07-05 04:29:31 +00:00
class_obj->spec = XP_STX_TO_SMALLINT(
(nfields << XP_STX_SPEC_INDEXABLE_BITS) | p->indexable);
2005-07-03 16:37:01 +00:00
}
for (p = class_info; p->name != XP_NULL; p++) {
class = xp_stx_lookup_class(stx, p->name);
xp_assert (class != stx->nil);
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
2005-05-24 03:28:31 +00:00
2005-07-03 16:37:01 +00:00
/*
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;
}
2005-07-03 16:37:01 +00:00
*/
if (p->class_variables != XP_NULL) {
class_obj->class_variables =
__make_classvar_dict(stx, class, p->class_variables);
}
2005-05-25 16:44:05 +00:00
/*
TODO:
if (p->pool_dictionaries != XP_NULL) {
2005-07-03 16:37:01 +00:00
class_obj->pool_dictionaries =
__make_pool_dictionary(stx, class, p->pool_dictionaries);
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);
2005-06-08 16:00:51 +00:00
xp_assert (class != stx->nil);
2005-05-26 15:39:32 +00:00
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);
2005-06-08 16:00:51 +00:00
xp_assert (class != stx->nil);
2005-05-29 16:51:16 +00:00
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
2005-06-08 16:00:51 +00:00
static xp_word_t __count_names (const xp_char_t* str)
2005-05-23 14:43:03 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t n = 0;
const xp_char_t* p = str;
2005-05-23 14:43:03 +00:00
do {
2005-06-08 16:00:51 +00:00
while (*p == XP_CHAR(' ') ||
*p == XP_CHAR('\t')) p++;
if (*p == XP_CHAR('\0')) break;
2005-05-23 14:43:03 +00:00
n++;
2005-06-08 16:00:51 +00:00
while (*p != XP_CHAR(' ') &&
*p != XP_CHAR('\t') &&
*p != XP_CHAR('\0')) p++;
2005-05-23 14:43:03 +00:00
} while (1);
return n;
}
2005-05-23 15:51:03 +00:00
static void __set_names (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str)
2005-05-23 14:43:03 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t n = 0;
const xp_char_t* p = str;
const xp_char_t* name;
2005-05-23 14:43:03 +00:00
do {
2005-06-08 16:00:51 +00:00
while (*p == XP_CHAR(' ') ||
*p == XP_CHAR('\t')) p++;
if (*p == XP_CHAR('\0')) break;
2005-05-23 14:43:03 +00:00
2005-05-23 15:51:03 +00:00
name = p;
2005-06-08 16:00:51 +00:00
while (*p != XP_CHAR(' ') &&
*p != XP_CHAR('\t') &&
*p != XP_CHAR('\0')) p++;
2005-05-23 14:43:03 +00:00
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
2005-06-08 16:00:51 +00:00
static xp_word_t __count_subclasses (const xp_char_t* str)
2005-05-26 15:39:32 +00:00
{
class_info_t* p;
2005-06-08 16:00:51 +00:00
xp_word_t n = 0;
2005-05-26 15:39:32 +00:00
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
2005-06-08 16:14:52 +00:00
if (xp_strcmp (str, p->superclass) == 0) n++;
2005-05-26 15:39:32 +00:00
}
return n;
}
static void __set_subclasses (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str)
2005-05-26 15:39:32 +00:00
{
class_info_t* p;
2005-06-08 16:00:51 +00:00
xp_word_t n = 0, class;
2005-05-26 15:39:32 +00:00
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
2005-06-08 16:14:52 +00:00
if (xp_strcmp (str, p->superclass) != 0) continue;
2005-05-26 15:39:32 +00:00
class = xp_stx_lookup_class (stx, p->name);
2005-06-08 16:00:51 +00:00
xp_assert (class != stx->nil);
2005-05-26 15:39:32 +00:00
array[n++] = class;
}
}
2005-05-29 16:51:16 +00:00
static void __set_metaclass_subclasses (
2005-06-08 16:00:51 +00:00
xp_stx_t* stx, xp_word_t* array, const xp_char_t* str)
2005-05-29 16:51:16 +00:00
{
class_info_t* p;
2005-06-08 16:00:51 +00:00
xp_word_t n = 0, class;
2005-05-29 16:51:16 +00:00
for (p = class_info; p->name != XP_NULL; p++) {
if (p->superclass == XP_NULL) continue;
2005-06-08 16:14:52 +00:00
if (xp_strcmp (str, p->superclass) != 0) continue;
2005-05-29 16:51:16 +00:00
class = xp_stx_lookup_class (stx, p->name);
2005-06-08 16:00:51 +00:00
xp_assert (class != stx->nil);
2005-05-29 16:51:16 +00:00
array[n++] = XP_STX_CLASS(stx,class);
}
}
2005-05-30 07:27:29 +00:00
2005-07-03 16:37:01 +00:00
static xp_word_t __make_classvar_dict (
xp_stx_t* stx, xp_word_t class, const xp_char_t* names)
{
xp_word_t dict, symbol;
const xp_char_t* p = names;
const xp_char_t* name;
2005-07-05 04:29:31 +00:00
dict = xp_stx_instantiate (
stx, stx->class_dictionary, __count_names(names));
2005-07-03 16:37:01 +00:00
do {
while (*p == XP_CHAR(' ') ||
*p == XP_CHAR('\t')) p++;
if (*p == XP_CHAR('\0')) break;
name = p;
while (*p != XP_CHAR(' ') &&
*p != XP_CHAR('\t') &&
*p != XP_CHAR('\0')) p++;
symbol = xp_stx_new_symbolx (stx, name, p - name);
xp_stx_hash_insert (stx, dict,
xp_stx_hash_char_object(stx, symbol), symbol, stx->nil);
} while (1);
return dict;
}
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: */
}
}
2005-07-03 16:37:01 +00:00