qse/ase/stx/bootstrp.c

677 lines
16 KiB
C
Raw Normal View History

2005-05-22 15:38:31 +00:00
/*
2005-09-11 15:15:35 +00:00
* $Id: bootstrp.c,v 1.32 2005-09-11 15:15:35 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>
2005-07-19 12:08:04 +00:00
#include <xp/stx/dict.h>
2005-05-22 15:38:31 +00:00
#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-09-11 15:15:35 +00:00
XP_TEXT("stack stackTop receiver pc method"),
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-09-11 15:15:35 +00:00
XP_TEXT("text selector bytecodes tmpcount"),
2005-05-24 03:28:31 +00:00
XP_NULL,
2005-07-05 09:02:13 +00:00
XP_NULL,
XP_STX_SPEC_WORD_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-07-18 11:53:01 +00:00
{
XP_TEXT("Association"),
XP_TEXT("Magnitude"),
XP_TEXT("key value"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
2005-07-11 13:41:59 +00:00
{
XP_TEXT("Character"),
XP_TEXT("Magnitude"),
XP_TEXT("value"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
2005-07-12 16:16:42 +00:00
{
XP_TEXT("Number"),
XP_TEXT("Magnitude"),
XP_NULL,
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{
XP_TEXT("Integer"),
XP_TEXT("Number"),
XP_NULL,
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{
XP_TEXT("SmallInteger"),
XP_TEXT("Integer"),
XP_NULL,
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{
XP_TEXT("LargeInteger"),
XP_TEXT("Integer"),
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("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-07-03 16:37:01 +00:00
XP_TEXT("Dictionary"),
2005-06-08 16:00:51 +00:00
XP_TEXT("IndexedCollection"),
2005-07-19 12:08:04 +00:00
XP_TEXT("tally"),
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_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
},
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-07-11 13:41:59 +00:00
xp_word_t INLINE __new_string (xp_stx_t* stx, const xp_char_t* str)
2005-06-30 12:07:02 +00:00
{
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-11 13:41:59 +00:00
stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character"));
2005-08-15 16:03:57 +00:00
stx->class_context = xp_stx_new_class (stx, XP_TEXT("Context"));
2005-07-19 12:08:04 +00:00
stx->class_system_dictionary =
xp_stx_new_class (stx, XP_TEXT("SystemDictionary"));
stx->class_method =
xp_stx_new_class (stx, XP_TEXT("Method"));
stx->class_smallinteger =
xp_stx_new_class (stx, XP_TEXT("SmallInteger"));
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-07-19 12:08:04 +00:00
XP_STX_WORD_AT(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-07-19 12:08:04 +00:00
XP_STX_WORD_AT(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-08-15 16:03:57 +00:00
array = xp_stx_new_array (stx, 1);
2005-07-19 12:08:04 +00:00
XP_STX_WORD_AT(stx,array,0) = object_meta;
XP_STX_WORD_AT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
2005-05-29 16:51:16 +00:00
}
2005-05-22 15:38:31 +00:00
/* more initialization */
2005-07-19 12:08:04 +00:00
XP_STX_CLASS(stx,stx->smalltalk) = stx->class_system_dictionary;
2005-05-22 15:38:31 +00:00
2005-07-19 12:08:04 +00:00
symbol_Smalltalk = xp_stx_new_symbol (stx, XP_TEXT("Smalltalk"));
xp_stx_dict_put (stx, stx->smalltalk, symbol_Smalltalk, stx->smalltalk);
2005-05-22 15:38:31 +00:00
/* 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-07-19 12:08:04 +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_SymbolMeta;
xp_word_t class_MetaclassMeta;
2005-07-19 12:08:04 +00:00
xp_word_t class_AssociationMeta;
2005-06-08 16:00:51 +00:00
xp_word_t symbol_Symbol;
xp_word_t symbol_Metaclass;
2005-07-19 12:08:04 +00:00
xp_word_t symbol_Association;
2005-05-22 15:38:31 +00:00
/* allocate three keyword objects */
2005-07-05 09:02:13 +00:00
stx->nil = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, 0);
stx->true = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, 0);
stx->false = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, 0);
2005-05-22 15:38:31 +00:00
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
2005-08-11 09:57:54 +00:00
/* system dictionary */
/* TODO: dictionary size */
2005-07-05 09:02:13 +00:00
stx->smalltalk = xp_stx_alloc_word_object (
2005-07-19 16:10:16 +00:00
stx, XP_NULL, 1, XP_NULL, 256);
2005-07-19 12:08:04 +00:00
/* set tally */
XP_STX_WORD_AT(stx,stx->smalltalk,0) = XP_STX_TO_SMALLINT(0);
2005-07-05 09:02:13 +00:00
/* Symbol */
stx->class_symbol = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
/* Metaclass */
stx->class_metaclass = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
2005-07-19 12:08:04 +00:00
/* Association */
stx->class_association = xp_stx_alloc_word_object(
2005-07-05 09:02:13 +00:00
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
2005-05-22 15:38:31 +00:00
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-07-05 09:02:13 +00:00
/* Symbol class */
class_SymbolMeta = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_METACLASS_SIZE, XP_NULL, 0);
/* Metaclass class */
class_MetaclassMeta = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_METACLASS_SIZE, XP_NULL, 0);
2005-07-19 12:08:04 +00:00
/* Association class */
class_AssociationMeta = xp_stx_alloc_word_object(
2005-07-05 09:02:13 +00:00
stx, XP_NULL, XP_STX_METACLASS_SIZE, XP_NULL, 0);
2005-05-22 15:38:31 +00:00
/* (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;
2005-07-19 12:08:04 +00:00
/* (Association class) setClass: Metaclass */
XP_STX_CLASS(stx,class_AssociationMeta) = stx->class_metaclass;
2005-05-22 15:38:31 +00:00
/* 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;
2005-07-19 12:08:04 +00:00
/* Association setClass: (Association class) */
XP_STX_CLASS(stx,stx->class_association) = class_AssociationMeta;
2005-05-22 15:38:31 +00:00
/* (Symbol class) setSpec: CLASS_SIZE */
2005-07-19 12:08:04 +00:00
XP_STX_WORD_AT(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-07-19 12:08:04 +00:00
XP_STX_WORD_AT(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-07-19 12:08:04 +00:00
/* (Association class) setSpec: CLASS_SIZE */
XP_STX_WORD_AT(stx,class_AssociationMeta,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-07-19 12:08:04 +00:00
/* specs for class_metaclass, class_association,
2005-08-11 09:57:54 +00:00
* class_symbol are set later in __create_builtin_classes */
2005-05-25 16:44:05 +00:00
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-07-19 12:08:04 +00:00
/* #Association */
symbol_Association = xp_stx_new_symbol (stx, XP_TEXT("Association"));
2005-05-22 15:38:31 +00:00
/* Symbol setName: #Symbol */
2005-07-19 12:08:04 +00:00
XP_STX_WORD_AT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_Symbol;
2005-05-22 15:38:31 +00:00
/* Metaclass setName: #Metaclass */
2005-07-19 12:08:04 +00:00
XP_STX_WORD_AT(stx,stx->class_metaclass,XP_STX_CLASS_NAME) = symbol_Metaclass;
/* Association setName: #Association */
XP_STX_WORD_AT(stx,stx->class_association,XP_STX_CLASS_NAME) = symbol_Association;
2005-05-22 15:38:31 +00:00
/* register class names into the system dictionary */
2005-07-19 12:08:04 +00:00
xp_stx_dict_put (stx,
stx->smalltalk, symbol_Symbol, stx->class_symbol);
xp_stx_dict_put (stx,
stx->smalltalk, symbol_Metaclass, stx->class_metaclass);
xp_stx_dict_put (stx,
stx->smalltalk, symbol_Association, stx->class_association);
2005-05-22 15:38:31 +00:00
}
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-07-07 07:45:05 +00:00
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
2005-05-22 17:02:58 +00:00
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;
2005-07-07 07:45:05 +00:00
meta_obj = (xp_stx_metaclass_t*)XP_STX_OBJECT(stx,meta);
2005-05-25 16:44:05 +00:00
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*)
2005-07-07 07:45:05 +00:00
XP_STX_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 =
2005-07-11 13:41:59 +00:00
__new_string (stx, p->instance_variables);
2005-06-30 12:07:02 +00:00
}
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);
2005-07-07 07:45:05 +00:00
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
2005-05-24 03:28:31 +00:00
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);
2005-08-15 16:03:57 +00:00
array = xp_stx_new_array (stx, n);
2005-05-26 15:39:32 +00:00
__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-07-07 07:45:05 +00:00
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
2005-05-26 15:39:32 +00:00
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);
2005-08-15 16:03:57 +00:00
array = xp_stx_new_array (stx, n);
2005-05-29 16:51:16 +00:00
__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);
2005-07-07 07:45:05 +00:00
metaclass_obj = (xp_stx_metaclass_t*)XP_STX_OBJECT(stx, metaclass);
2005-05-29 16:51:16 +00:00
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 (
2005-07-19 12:08:04 +00:00
stx, stx->class_system_dictionary,
2005-07-05 09:02:13 +00:00
XP_NULL, XP_NULL, __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);
2005-07-19 12:08:04 +00:00
xp_stx_dict_put (stx, dict, symbol, stx->nil);
2005-07-03 16:37:01 +00:00
} 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