qse/ase/stx/bootstrp.c

677 lines
17 KiB
C
Raw Normal View History

2005-05-22 15:38:31 +00:00
/*
2007-03-22 11:19:28 +00:00
* $Id: bootstrp.c,v 1.34 2007-03-22 11:19:28 bacon Exp $
2005-05-22 15:38:31 +00:00
*/
2007-03-22 11:19:28 +00:00
#include <ase/stx/bootstrp.h>
#include <ase/stx/symbol.h>
#include <ase/stx/class.h>
#include <ase/stx/object.h>
#include <ase/stx/dict.h>
#include <ase/stx/misc.h>
2005-05-22 15:38:31 +00:00
2007-03-22 11:19:28 +00:00
static void __create_bootstrapping_objects (ase_stx_t* stx);
static void __create_builtin_classes (ase_stx_t* stx);
static ase_word_t __make_classvar_dict (
ase_stx_t* stx, ase_word_t class, const ase_char_t* names);
static void __filein_kernel (ase_stx_t* stx);
2005-05-26 15:39:32 +00:00
2007-03-22 11:19:28 +00:00
static ase_word_t __count_names (const ase_char_t* str);
2005-05-23 15:51:03 +00:00
static void __set_names (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str);
2005-05-22 15:38:31 +00:00
2007-03-22 11:19:28 +00:00
static ase_word_t __count_subclasses (const ase_char_t* str);
2005-05-26 15:39:32 +00:00
static void __set_subclasses (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str);
2005-05-29 16:51:16 +00:00
static void __set_metaclass_subclasses (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str);
2005-05-26 15:39:32 +00:00
2005-05-22 16:26:58 +00:00
struct class_info_t
{
2007-03-22 11:19:28 +00:00
const ase_char_t* name;
const ase_char_t* superclass;
const ase_char_t* instance_variables;
const ase_char_t* class_variables;
const ase_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[] =
{
{
2007-03-22 11:19:28 +00:00
ASE_T("Object"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("UndefinedObject"),
ASE_T("Object"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Behavior"),
ASE_T("Object"),
ASE_T("spec methods superclass"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Class"),
ASE_T("Behavior"),
ASE_T("name variables classVariables poolDictionaries"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Metaclass"),
ASE_T("Behavior"),
ASE_T("instanceClass"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Block"),
ASE_T("Object"),
ASE_T("context argCount argLoc bytePointer"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Boolean"),
ASE_T("Object"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("True"),
ASE_T("Boolean"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("False"),
ASE_T("Boolean"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Context"),
ASE_T("Object"),
ASE_T("stack stackTop receiver pc method"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-23 14:43:03 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Method"),
ASE_T("Object"),
ASE_T("text selector bytecodes tmpCount argCount"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_WORD_INDEXABLE
2005-05-22 16:26:58 +00:00
},
2005-05-22 17:02:58 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("Magnitude"),
ASE_T("Object"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
2005-07-18 11:53:01 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("Association"),
ASE_T("Magnitude"),
ASE_T("key value"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-07-18 11:53:01 +00:00
},
2005-07-11 13:41:59 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("Character"),
ASE_T("Magnitude"),
ASE_T("value"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-07-11 13:41:59 +00:00
},
2005-07-12 16:16:42 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("Number"),
ASE_T("Magnitude"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-07-12 16:16:42 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Integer"),
ASE_T("Number"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-07-12 16:16:42 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("SmallInteger"),
ASE_T("Integer"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-07-12 16:16:42 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("LargeInteger"),
ASE_T("Integer"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_BYTE_INDEXABLE
2005-07-12 16:16:42 +00:00
},
2005-05-22 17:02:58 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("Collection"),
ASE_T("Magnitude"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("IndexedCollection"),
ASE_T("Collection"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Array"),
ASE_T("IndexedCollection"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_WORD_INDEXABLE
2005-07-04 16:23:13 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("ByteArray"),
ASE_T("IndexedCollection"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_BYTE_INDEXABLE
2005-05-22 17:02:58 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Dictionary"),
ASE_T("IndexedCollection"),
ASE_T("tally"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_WORD_INDEXABLE
2005-05-22 17:02:58 +00:00
},
2005-07-03 16:37:01 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("SystemDictionary"),
ASE_T("Dictionary"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_WORD_INDEXABLE
2005-07-03 16:37:01 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("PoolDictionary"),
ASE_T("Dictionary"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_WORD_INDEXABLE
2005-07-03 16:37:01 +00:00
},
2005-06-30 12:07:02 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_T("String"),
ASE_T("IndexedCollection"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_CHAR_INDEXABLE
2005-06-30 12:07:02 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Symbol"),
ASE_T("String"),
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_CHAR_INDEXABLE
2005-06-30 12:07:02 +00:00
},
{
2007-03-22 11:19:28 +00:00
ASE_T("Link"),
ASE_T("Object"),
ASE_T("link"),
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-06-30 12:07:02 +00:00
},
2005-05-22 16:26:58 +00:00
{
2007-03-22 11:19:28 +00:00
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_NULL,
ASE_STX_SPEC_NOT_INDEXABLE
2005-05-22 16:26:58 +00:00
}
};
2007-03-22 11:19:28 +00:00
ase_word_t INLINE __new_string (ase_stx_t* stx, const ase_char_t* str)
2005-06-30 12:07:02 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t x;
2005-06-30 12:07:02 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (stx->class_string != stx->nil);
x = ase_stx_alloc_char_object (stx, str);
ASE_STX_CLASS(stx,x) = stx->class_string;
2005-06-30 12:07:02 +00:00
return x;
}
2007-03-22 11:19:28 +00:00
int ase_stx_bootstrap (ase_stx_t* stx)
2005-05-22 15:38:31 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t symbol_Smalltalk;
ase_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 */
2007-03-22 11:19:28 +00:00
stx->class_object = ase_stx_new_class (stx, ASE_T("Object"));
stx->class_class = ase_stx_new_class (stx, ASE_T("Class"));
stx->class_array = ase_stx_new_class (stx, ASE_T("Array"));
stx->class_bytearray = ase_stx_new_class (stx, ASE_T("ByteArray"));
stx->class_string = ase_stx_new_class (stx, ASE_T("String"));
stx->class_character = ase_stx_new_class (stx, ASE_T("Character"));
stx->class_context = ase_stx_new_class (stx, ASE_T("Context"));
2005-07-19 12:08:04 +00:00
stx->class_system_dictionary =
2007-03-22 11:19:28 +00:00
ase_stx_new_class (stx, ASE_T("SystemDictionary"));
2005-07-19 12:08:04 +00:00
stx->class_method =
2007-03-22 11:19:28 +00:00
ase_stx_new_class (stx, ASE_T("Method"));
2005-07-19 12:08:04 +00:00
stx->class_smallinteger =
2007-03-22 11:19:28 +00:00
ase_stx_new_class (stx, ASE_T("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 */
2007-03-22 11:19:28 +00:00
object_meta = ASE_STX_CLASS(stx,stx->class_object);
ASE_STX_WORD_AT(stx,object_meta,ASE_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 */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,object_meta,ASE_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 */
{
2007-03-22 11:19:28 +00:00
ase_word_t array;
array = ase_stx_new_array (stx, 1);
ASE_STX_WORD_AT(stx,array,0) = object_meta;
ASE_STX_WORD_AT(stx,stx->class_class,ASE_STX_CLASS_SUBCLASSES) = array;
2005-05-29 16:51:16 +00:00
}
2005-05-22 15:38:31 +00:00
/* more initialization */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->smalltalk) = stx->class_system_dictionary;
2005-05-22 15:38:31 +00:00
2007-03-22 11:19:28 +00:00
symbol_Smalltalk = ase_stx_new_symbol (stx, ASE_T("Smalltalk"));
ase_stx_dict_put (stx, stx->smalltalk, symbol_Smalltalk, stx->smalltalk);
2005-05-22 15:38:31 +00:00
/* create #nil, #true, #false */
2007-03-22 11:19:28 +00:00
ase_stx_new_symbol (stx, ASE_T("nil"));
ase_stx_new_symbol (stx, ASE_T("true"));
ase_stx_new_symbol (stx, ASE_T("false"));
2005-05-22 15:38:31 +00:00
/* nil setClass: UndefinedObject */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->nil) =
ase_stx_lookup_class(stx, ASE_T("UndefinedObject"));
2005-05-22 15:38:31 +00:00
/* true setClass: True */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->true) =
ase_stx_lookup_class (stx, ASE_T("True"));
2005-05-22 15:38:31 +00:00
/* fales setClass: False */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->false) =
ase_stx_lookup_class (stx, ASE_T("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;
}
2007-03-22 11:19:28 +00:00
static void __create_bootstrapping_objects (ase_stx_t* stx)
2005-05-22 15:38:31 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t class_SymbolMeta;
ase_word_t class_MetaclassMeta;
ase_word_t class_AssociationMeta;
ase_word_t symbol_Symbol;
ase_word_t symbol_Metaclass;
ase_word_t symbol_Association;
2005-05-22 15:38:31 +00:00
/* allocate three keyword objects */
2007-03-22 11:19:28 +00:00
stx->nil = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0);
stx->true = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0);
stx->false = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0);
2005-05-22 15:38:31 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (stx->nil == ASE_STX_NIL);
ase_assert (stx->true == ASE_STX_TRUE);
ase_assert (stx->false == ASE_STX_FALSE);
2005-05-22 15:38:31 +00:00
2005-08-11 09:57:54 +00:00
/* system dictionary */
/* TODO: dictionary size */
2007-03-22 11:19:28 +00:00
stx->smalltalk = ase_stx_alloc_word_object (
stx, ASE_NULL, 1, ASE_NULL, 256);
2005-07-19 12:08:04 +00:00
/* set tally */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,stx->smalltalk,0) = ASE_STX_TO_SMALLINT(0);
2005-07-05 09:02:13 +00:00
/* Symbol */
2007-03-22 11:19:28 +00:00
stx->class_symbol = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0);
2005-07-05 09:02:13 +00:00
/* Metaclass */
2007-03-22 11:19:28 +00:00
stx->class_metaclass = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0);
2005-07-19 12:08:04 +00:00
/* Association */
2007-03-22 11:19:28 +00:00
stx->class_association = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_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 */
2007-03-22 11:19:28 +00:00
class_SymbolMeta = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0);
2005-07-05 09:02:13 +00:00
/* Metaclass class */
2007-03-22 11:19:28 +00:00
class_MetaclassMeta = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0);
2005-07-19 12:08:04 +00:00
/* Association class */
2007-03-22 11:19:28 +00:00
class_AssociationMeta = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0);
2005-05-22 15:38:31 +00:00
/* (Symbol class) setClass: Metaclass */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,class_SymbolMeta) = stx->class_metaclass;
2005-05-22 15:38:31 +00:00
/* (Metaclass class) setClass: Metaclass */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,class_MetaclassMeta) = stx->class_metaclass;
2005-07-19 12:08:04 +00:00
/* (Association class) setClass: Metaclass */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,class_AssociationMeta) = stx->class_metaclass;
2005-05-22 15:38:31 +00:00
/* Symbol setClass: (Symbol class) */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->class_symbol) = class_SymbolMeta;
2005-05-22 15:38:31 +00:00
/* Metaclass setClass: (Metaclass class) */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->class_metaclass) = class_MetaclassMeta;
2005-07-19 12:08:04 +00:00
/* Association setClass: (Association class) */
2007-03-22 11:19:28 +00:00
ASE_STX_CLASS(stx,stx->class_association) = class_AssociationMeta;
2005-05-22 15:38:31 +00:00
/* (Symbol class) setSpec: CLASS_SIZE */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,class_SymbolMeta,ASE_STX_CLASS_SPEC) =
ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE);
2005-05-22 15:38:31 +00:00
/* (Metaclass class) setSpec: CLASS_SIZE */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,class_MetaclassMeta,ASE_STX_CLASS_SPEC) =
ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE);
2005-07-19 12:08:04 +00:00
/* (Association class) setSpec: CLASS_SIZE */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,class_AssociationMeta,ASE_STX_CLASS_SPEC) =
ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_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 */
2007-03-22 11:19:28 +00:00
symbol_Symbol = ase_stx_new_symbol (stx, ASE_T("Symbol"));
2005-05-22 15:38:31 +00:00
/* #Metaclass */
2007-03-22 11:19:28 +00:00
symbol_Metaclass = ase_stx_new_symbol (stx, ASE_T("Metaclass"));
2005-07-19 12:08:04 +00:00
/* #Association */
2007-03-22 11:19:28 +00:00
symbol_Association = ase_stx_new_symbol (stx, ASE_T("Association"));
2005-05-22 15:38:31 +00:00
/* Symbol setName: #Symbol */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,stx->class_symbol,ASE_STX_CLASS_NAME) = symbol_Symbol;
2005-05-22 15:38:31 +00:00
/* Metaclass setName: #Metaclass */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,stx->class_metaclass,ASE_STX_CLASS_NAME) = symbol_Metaclass;
2005-07-19 12:08:04 +00:00
/* Association setName: #Association */
2007-03-22 11:19:28 +00:00
ASE_STX_WORD_AT(stx,stx->class_association,ASE_STX_CLASS_NAME) = symbol_Association;
2005-05-22 15:38:31 +00:00
/* register class names into the system dictionary */
2007-03-22 11:19:28 +00:00
ase_stx_dict_put (stx,
2005-07-19 12:08:04 +00:00
stx->smalltalk, symbol_Symbol, stx->class_symbol);
2007-03-22 11:19:28 +00:00
ase_stx_dict_put (stx,
2005-07-19 12:08:04 +00:00
stx->smalltalk, symbol_Metaclass, stx->class_metaclass);
2007-03-22 11:19:28 +00:00
ase_stx_dict_put (stx,
2005-07-19 12:08:04 +00:00
stx->smalltalk, symbol_Association, stx->class_association);
2005-05-22 15:38:31 +00:00
}
2007-03-22 11:19:28 +00:00
static void __create_builtin_classes (ase_stx_t* stx)
2005-05-22 16:26:58 +00:00
{
2005-05-23 14:43:03 +00:00
class_info_t* p;
2007-03-22 11:19:28 +00:00
ase_word_t class, superclass, array;
ase_stx_class_t* class_obj, * superclass_obj;
ase_word_t metaclass;
ase_stx_metaclass_t* metaclass_obj;
ase_word_t n, nfields;
2005-05-22 16:26:58 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (stx->class_array != stx->nil);
2005-05-23 14:43:03 +00:00
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
class = ase_stx_lookup_class(stx, p->name);
2005-05-22 17:02:58 +00:00
if (class == stx->nil) {
2007-03-22 11:19:28 +00:00
class = ase_stx_new_class (stx, p->name);
2005-05-22 16:26:58 +00:00
}
2005-05-22 17:02:58 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (class != stx->nil);
class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class);
class_obj->superclass = (p->superclass == ASE_NULL)?
stx->nil: ase_stx_lookup_class(stx,p->superclass);
2005-05-22 17:02:58 +00:00
2005-07-04 16:23:13 +00:00
nfields = 0;
2007-03-22 11:19:28 +00:00
if (p->superclass != ASE_NULL) {
ase_word_t meta;
ase_stx_metaclass_t* meta_obj;
2005-05-25 16:44:05 +00:00
2007-03-22 11:19:28 +00:00
superclass = ase_stx_lookup_class(stx,p->superclass);
ase_assert (superclass != stx->nil);
2005-05-25 16:44:05 +00:00
meta = class_obj->header.class;
2007-03-22 11:19:28 +00:00
meta_obj = (ase_stx_metaclass_t*)ASE_STX_OBJECT(stx,meta);
meta_obj->superclass = ASE_STX_CLASS(stx,superclass);
2005-05-25 16:44:05 +00:00
meta_obj->instance_class = class;
2005-05-23 16:07:39 +00:00
while (superclass != stx->nil) {
2007-03-22 11:19:28 +00:00
superclass_obj = (ase_stx_class_t*)
ASE_STX_OBJECT(stx,superclass);
2005-07-05 04:29:31 +00:00
nfields +=
2007-03-22 11:19:28 +00:00
ASE_STX_FROM_SMALLINT(superclass_obj->spec) >>
ASE_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
}
2007-03-22 11:19:28 +00:00
if (p->instance_variables != ASE_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
2007-03-22 11:19:28 +00:00
ase_assert (nfields <= 0 || (nfields > 0 &&
(p->indexable == ASE_STX_SPEC_NOT_INDEXABLE ||
p->indexable == ASE_STX_SPEC_WORD_INDEXABLE)));
2005-07-04 16:23:13 +00:00
2007-03-22 11:19:28 +00:00
class_obj->spec = ASE_STX_TO_SMALLINT(
(nfields << ASE_STX_SPEC_INDEXABLE_BITS) | p->indexable);
2005-07-03 16:37:01 +00:00
}
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
class = ase_stx_lookup_class(stx, p->name);
ase_assert (class != stx->nil);
2005-07-03 16:37:01 +00:00
2007-03-22 11:19:28 +00:00
class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class);
2005-05-24 03:28:31 +00:00
2007-03-22 11:19:28 +00:00
if (p->class_variables != ASE_NULL) {
2005-07-03 16:37:01 +00:00
class_obj->class_variables =
__make_classvar_dict(stx, class, p->class_variables);
}
2005-05-25 16:44:05 +00:00
/*
TODO:
2007-03-22 11:19:28 +00:00
if (p->pool_dictionaries != ASE_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 */
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
2005-05-26 15:39:32 +00:00
n = __count_subclasses (p->name);
2007-03-22 11:19:28 +00:00
array = ase_stx_new_array (stx, n);
__set_subclasses (stx, ASE_STX_DATA(stx,array), p->name);
2005-05-26 15:39:32 +00:00
2007-03-22 11:19:28 +00:00
class = ase_stx_lookup_class(stx, p->name);
ase_assert (class != stx->nil);
class_obj = (ase_stx_class_t*)ASE_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 */
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
2005-05-29 16:51:16 +00:00
n = __count_subclasses (p->name);
2007-03-22 11:19:28 +00:00
array = ase_stx_new_array (stx, n);
__set_metaclass_subclasses (stx, ASE_STX_DATA(stx,array), p->name);
2005-05-29 16:51:16 +00:00
2007-03-22 11:19:28 +00:00
class = ase_stx_lookup_class(stx, p->name);
ase_assert (class != stx->nil);
metaclass = ASE_STX_CLASS(stx,class);
metaclass_obj = (ase_stx_metaclass_t*)ASE_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
2007-03-22 11:19:28 +00:00
static ase_word_t __count_names (const ase_char_t* str)
2005-05-23 14:43:03 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t n = 0;
const ase_char_t* p = str;
2005-05-23 14:43:03 +00:00
do {
2007-03-22 11:19:28 +00:00
while (*p == ASE_T(' ') ||
*p == ASE_T('\t')) p++;
if (*p == ASE_T('\0')) break;
2005-05-23 14:43:03 +00:00
n++;
2007-03-22 11:19:28 +00:00
while (*p != ASE_T(' ') &&
*p != ASE_T('\t') &&
*p != ASE_T('\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 (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str)
2005-05-23 14:43:03 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t n = 0;
const ase_char_t* p = str;
const ase_char_t* name;
2005-05-23 14:43:03 +00:00
do {
2007-03-22 11:19:28 +00:00
while (*p == ASE_T(' ') ||
*p == ASE_T('\t')) p++;
if (*p == ASE_T('\0')) break;
2005-05-23 14:43:03 +00:00
2005-05-23 15:51:03 +00:00
name = p;
2007-03-22 11:19:28 +00:00
while (*p != ASE_T(' ') &&
*p != ASE_T('\t') &&
*p != ASE_T('\0')) p++;
2005-05-23 14:43:03 +00:00
2007-03-22 11:19:28 +00:00
array[n++] = ase_stx_new_symbolx (stx, name, p - name);
2005-05-23 15:51:03 +00:00
} while (1);
2005-05-23 14:43:03 +00:00
}
2005-05-26 15:39:32 +00:00
2007-03-22 11:19:28 +00:00
static ase_word_t __count_subclasses (const ase_char_t* str)
2005-05-26 15:39:32 +00:00
{
class_info_t* p;
2007-03-22 11:19:28 +00:00
ase_word_t n = 0;
2005-05-26 15:39:32 +00:00
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
if (p->superclass == ASE_NULL) continue;
if (ase_strcmp (str, p->superclass) == 0) n++;
2005-05-26 15:39:32 +00:00
}
return n;
}
static void __set_subclasses (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str)
2005-05-26 15:39:32 +00:00
{
class_info_t* p;
2007-03-22 11:19:28 +00:00
ase_word_t n = 0, class;
2005-05-26 15:39:32 +00:00
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
if (p->superclass == ASE_NULL) continue;
if (ase_strcmp (str, p->superclass) != 0) continue;
class = ase_stx_lookup_class (stx, p->name);
ase_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 (
2007-03-22 11:19:28 +00:00
ase_stx_t* stx, ase_word_t* array, const ase_char_t* str)
2005-05-29 16:51:16 +00:00
{
class_info_t* p;
2007-03-22 11:19:28 +00:00
ase_word_t n = 0, class;
for (p = class_info; p->name != ASE_NULL; p++) {
if (p->superclass == ASE_NULL) continue;
if (ase_strcmp (str, p->superclass) != 0) continue;
class = ase_stx_lookup_class (stx, p->name);
ase_assert (class != stx->nil);
array[n++] = ASE_STX_CLASS(stx,class);
2005-05-29 16:51:16 +00:00
}
}
2005-05-30 07:27:29 +00:00
2007-03-22 11:19:28 +00:00
static ase_word_t __make_classvar_dict (
ase_stx_t* stx, ase_word_t class, const ase_char_t* names)
2005-07-03 16:37:01 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t dict, symbol;
const ase_char_t* p = names;
const ase_char_t* name;
2005-07-03 16:37:01 +00:00
2007-03-22 11:19:28 +00:00
dict = ase_stx_instantiate (
2005-07-19 12:08:04 +00:00
stx, stx->class_system_dictionary,
2007-03-22 11:19:28 +00:00
ASE_NULL, ASE_NULL, __count_names(names));
2005-07-03 16:37:01 +00:00
do {
2007-03-22 11:19:28 +00:00
while (*p == ASE_T(' ') ||
*p == ASE_T('\t')) p++;
if (*p == ASE_T('\0')) break;
2005-07-03 16:37:01 +00:00
name = p;
2007-03-22 11:19:28 +00:00
while (*p != ASE_T(' ') &&
*p != ASE_T('\t') &&
*p != ASE_T('\0')) p++;
2005-07-03 16:37:01 +00:00
2007-03-22 11:19:28 +00:00
symbol = ase_stx_new_symbolx (stx, name, p - name);
ase_stx_dict_put (stx, dict, symbol, stx->nil);
2005-07-03 16:37:01 +00:00
} while (1);
return dict;
}
2007-03-22 11:19:28 +00:00
static void __filein_kernel (ase_stx_t* stx)
2005-05-30 07:27:29 +00:00
{
class_info_t* p;
2007-03-22 11:19:28 +00:00
for (p = class_info; p->name != ASE_NULL; p++) {
2005-05-30 07:27:29 +00:00
/* TODO: */
}
}
2005-07-03 16:37:01 +00:00