diff --git a/ase/stx/context.c b/ase/stx/context.c index 44dbc606..a73a88b0 100644 --- a/ase/stx/context.c +++ b/ase/stx/context.c @@ -1,11 +1,11 @@ /* - * $Id: context.c,v 1.2 2005-05-16 14:14:34 bacon Exp $ + * $Id: context.c,v 1.3 2005-05-18 04:01:51 bacon Exp $ */ #include #include -#define XP_STX_CONTEXT_DIMENSION 4 +#define XP_STX_CONTEXT_SIZE 4 #define XP_STX_CONTEXT_IP 0 #define XP_STX_CONTEXT_METHOD 1 #define XP_STX_CONTEXT_ARGUMENTS 2 @@ -16,7 +16,7 @@ xp_stx_word_t xp_stx_new_context (xp_stx_t* stx, { xp_stx_word_t context; - context = xp_stx_alloc_object(stx,XP_STX_CONTEXT_DIMENSION); + context = xp_stx_alloc_object(stx,XP_STX_CONTEXT_SIZE); XP_STX_CLASS(stx,context) = stx->class_context; XP_STX_AT(stx,context,XP_STX_CONTEXT_IP) = XP_STX_TO_SMALLINT(0); XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD) = method; diff --git a/ase/stx/hash.c b/ase/stx/hash.c index 422c0ea6..7505b131 100644 --- a/ase/stx/hash.c +++ b/ase/stx/hash.c @@ -1,5 +1,5 @@ /* - * $Id: hash.c,v 1.11 2005-05-17 16:18:56 bacon Exp $ + * $Id: hash.c,v 1.12 2005-05-18 04:01:51 bacon Exp $ */ #include @@ -7,21 +7,16 @@ #include #include -#define PLINK_DIMENSION 3 -#define PLINK_LINK 0 -#define PLINK_KEY 1 -#define PLINK_VALUE 2 - -xp_stx_word_t xp_stx_new_plink ( +xp_stx_word_t xp_stx_new_pairlink ( xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value) { xp_stx_word_t x; - x = xp_stx_alloc_object (stx, PLINK_DIMENSION); - XP_STX_CLASS(stx,x) = stx->class_symbol_plink; - /* XP_STX_AT(stx,x,PLINK_LINK) = stx->nil; */ - XP_STX_AT(stx,x,PLINK_KEY) = key; - XP_STX_AT(stx,x,PLINK_VALUE) = value; + x = xp_stx_alloc_object (stx, XP_STX_PAIRLINK_SIZE); + XP_STX_CLASS(stx,x) = stx->class_pairlink; + /* XP_STX_AT(stx,x,XP_STX_PAIRLINK_LINK) = stx->nil; */ + XP_STX_AT(stx,x,XP_STX_PAIRLINK_KEY) = key; + XP_STX_AT(stx,x,XP_STX_PAIRLINK_VALUE) = value; return x; } @@ -39,8 +34,8 @@ xp_stx_word_t xp_stx_hash_lookup ( link = XP_STX_AT(stx,table,hash); while (link != stx->nil) { - if (XP_STX_AT(stx,link,PLINK_KEY) == key) return link; - link = XP_STX_AT(stx,link,PLINK_LINK); + if (XP_STX_AT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link; + link = XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK); } return stx->nil; /* not found */ @@ -58,7 +53,7 @@ xp_stx_word_t xp_stx_hash_lookup_symbol ( link = XP_STX_AT(stx,table,hash); while (link != stx->nil) { - key = XP_STX_AT(stx,link,PLINK_KEY); + key = XP_STX_AT(stx,link,XP_STX_PAIRLINK_KEY); if (XP_STX_CLASS(stx,key) == stx->class_symbol && xp_stx_strxcmp ( @@ -66,7 +61,7 @@ xp_stx_word_t xp_stx_hash_lookup_symbol ( XP_STX_SIZE(stx,key), key_str) == 0) { return link; } - link = XP_STX_AT(stx,link,PLINK_LINK); + link = XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK); } return stx->nil; /* not found */ @@ -85,19 +80,19 @@ void xp_stx_hash_insert ( if (link == stx->nil) { XP_STX_AT(stx,table,hash) = - xp_stx_new_plink (stx, key, value); + xp_stx_new_pairlink (stx, key, value); } else { for (;;) { if (XP_STX_AT(stx,link,1) == key) { - XP_STX_AT(stx,link,PLINK_VALUE) = value; + XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE) = value; break; } - next = XP_STX_AT(stx,link,PLINK_LINK); + next = XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK); if (next == stx->nil) { - XP_STX_AT(stx,link,PLINK_LINK) = - xp_stx_new_plink (stx, key, value); + XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK) = + xp_stx_new_pairlink (stx, key, value); break; } @@ -118,46 +113,8 @@ void xp_stx_hash_traverse ( while (link != stx->nil) { func (stx,link); - link = XP_STX_AT(stx,link,PLINK_LINK); + link = XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK); } } } - -/* -xp_stx_word_t xp_stx_new_symbol ( - xp_stx_t* stx, const xp_stx_char_t* name) -{ - xp_stx_word_t x, hash; - - hash = xp_stx_strhash(name); - x = xp_stx_hash_lookup_symbol(stx, stx->symbol_table, hash, name); - if (x == stx->nil) { - x = xp_stx_alloc_string_object (stx, name); - XP_STX_CLASS(stx,x) = stx->class_symbol; - xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil); - } - else x = XP_STX_AT(stx,x,PLINK_KEY); - - return x; -} - -xp_stx_word_t xp_stx_new_symbol_pp ( - xp_stx_t* stx, const xp_stx_char_t* name, - const xp_stx_char_t* prefix, const xp_stx_char_t* postfix) -{ - xp_stx_word_t x, hash; - - hash = xp_stx_strhash(name); - - x = xp_stx_hash_lookup_symbol(stx, stx->symbol_table, hash, name); - if (x == stx->nil) { - x = xp_stx_allocn_string_object (stx, prefix, name, postfix, XP_NULL); - XP_STX_CLASS(stx,x) = stx->class_symbol; - xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil); - } - else x = XP_STX_AT(stx,x,PLINK_KEY); - - return x; -} -*/ diff --git a/ase/stx/hash.h b/ase/stx/hash.h index 65715a8c..20b9fb7e 100644 --- a/ase/stx/hash.h +++ b/ase/stx/hash.h @@ -1,5 +1,5 @@ /* - * $Id: hash.h,v 1.5 2005-05-16 14:14:34 bacon Exp $ + * $Id: hash.h,v 1.6 2005-05-18 04:01:51 bacon Exp $ */ #ifndef _XP_STX_HASH_H_ @@ -7,12 +7,17 @@ #include +#define XP_STX_PAIRLINK_SIZE 3 +#define XP_STX_PAIRLINK_LINK 0 +#define XP_STX_PAIRLINK_KEY 1 +#define XP_STX_PAIRLINK_VALUE 2 + #ifdef __cplusplus extern "C" #endif /* hash table manipulation */ -xp_stx_word_t xp_stx_new_symbol_link ( +xp_stx_word_t xp_stx_new_plink ( xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value); xp_stx_word_t xp_stx_hash_lookup ( xp_stx_t* stx, xp_stx_word_t table, @@ -27,12 +32,6 @@ void xp_stx_hash_traverse ( xp_stx_t* stx, xp_stx_word_t table, void (*func) (xp_stx_t*,xp_stx_word_t)); -xp_stx_word_t xp_stx_new_symbol ( - xp_stx_t* stx, const xp_stx_char_t* name); -xp_stx_word_t xp_stx_new_symbol_pp ( - xp_stx_t* stx, const xp_stx_char_t* name, - const xp_stx_char_t* prefix, const xp_stx_char_t* postfix); - #ifdef __cplusplus } #endif diff --git a/ase/stx/interp.c b/ase/stx/interp.c index 33235ecf..111e864a 100644 --- a/ase/stx/interp.c +++ b/ase/stx/interp.c @@ -1,15 +1,15 @@ /* - * $Id: interp.c,v 1.2 2005-05-15 18:37:00 bacon Exp $ + * $Id: interp.c,v 1.3 2005-05-18 04:01:51 bacon Exp $ */ #include -#define XP_STX_PROCESS_DIMENSION 3 +#define XP_STX_PROCESS_SIZE 3 #define XP_STX_PROCESS_STACK 0 #define XP_STX_PROCESS_STACK_TOP 1 #define XP_STX_PROCESS_LINK 2 -#define XP_STX_CONTEXT_DIMENSION 6 +#define XP_STX_CONTEXT_SIZE 6 #define XP_STX_PROCESS_LINK 0 #define XP_STX_PROCESS_METHOD 1 #define XP_STX_PROCESS_ARGUMENTS 2 @@ -39,7 +39,7 @@ static byte_code_func_t byte_code_funcs[] = xp_stx_word_t xp_stx_new_method (xp_stx_t* stx) { xp_stx_word_t method; - method = xp_stx_alloc_object(XP_STX_METHOD_DIMENSION); + method = xp_stx_alloc_object(XP_STX_METHOD_SIZE); return method; } @@ -49,7 +49,7 @@ xp_stx_word_t xp_stx_new_context (xp_stx_t* stx, { xp_stx_word_t context; - context = xp_stx_alloc_object(XP_STX_CONTEXT_DIMENSION); + context = xp_stx_alloc_object(XP_STX_CONTEXT_SIZE); XP_STX_CLASS(stx,context) = stx->class_context; XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD) = method; XP_STX_AT(stx,context,XP_STX_CONTEXT_ARGUMENTS) = args; @@ -62,7 +62,7 @@ xp_stx_word_t xp_stx_new_process (xp_stx_t* stx, xp_stx_word_t method) { xp_stx_word_t process, stx; - process = xp_stx_alloc_object(XP_STX_PROCESS_DIMENSION); + process = xp_stx_alloc_object(XP_STX_PROCESS_SIZE); stack = xp_new_array(stx,50); XP_STX_CLASS(stx,process) = stx->class_process; diff --git a/ase/stx/makefile.in b/ase/stx/makefile.in index b9d6e7ac..0c2146d9 100644 --- a/ase/stx/makefile.in +++ b/ase/stx/makefile.in @@ -1,4 +1,4 @@ -SRCS = stx.c memory.c object.c hash.c misc.c context.c +SRCS = stx.c memory.c object.c symbol.c hash.c misc.c context.c OBJS = $(SRCS:.c=.o) OUT = libxpstx.a diff --git a/ase/stx/object.c b/ase/stx/object.c index e22cba4b..74a20bdf 100644 --- a/ase/stx/object.c +++ b/ase/stx/object.c @@ -1,9 +1,10 @@ /* - * $Id: object.c,v 1.14 2005-05-17 16:18:56 bacon Exp $ + * $Id: object.c,v 1.15 2005-05-18 04:01:51 bacon Exp $ */ #include #include +#include #include #include #include @@ -107,25 +108,29 @@ xp_stx_word_t xp_stx_hash_string_object (xp_stx_t* stx, xp_stx_word_t idx) xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name) { xp_stx_word_t meta, class; - xp_stx_word_t meta_name, class_name; + xp_stx_word_t /*meta_name,*/ class_name; - meta = xp_stx_alloc_object (stx, XP_STX_CLASS_DIMENSION); + meta = xp_stx_alloc_object (stx, XP_STX_CLASS_SIZE); XP_STX_CLASS(stx,meta) = stx->class_metaclass; XP_STX_AT(stx,meta,XP_STX_CLASS_SIZE) = - XP_STX_TO_SMALLINT(XP_STX_CLASS_DIMENSION); + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); - class = xp_stx_alloc_object (stx, XP_STX_CLASS_DIMENSION); + class = xp_stx_alloc_object (stx, XP_STX_CLASS_SIZE); XP_STX_CLASS(stx,class) = meta; + /* meta_name = xp_stx_new_symbol_pp ( stx, name, XP_STX_TEXT(""), XP_STX_TEXT(" class")); XP_STX_AT(stx,meta,XP_STX_CLASS_NAME) = meta_name; + */ class_name = xp_stx_new_symbol (stx, name); XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name; + /* xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_string_object(stx, meta_name), meta_name, meta); + */ xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_string_object(stx, class_name), class_name, class); @@ -140,10 +145,10 @@ int xp_stx_lookup_global ( // TODO: maybe xp_stx_hash_object is required instead of // xp_stx_hash_string_object. - link = xp_stx_hash_lookup (stx, stx->symbol_table, + link = xp_stx_hash_lookup (stx, stx->smalltalk, xp_stx_hash_string_object(stx,key), key); if (link == stx->nil) return -1; - *value = XP_STX_AT(stx,link,2); + *value = XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE); return 0; } diff --git a/ase/stx/object.h b/ase/stx/object.h index 6d989a8d..cd3ce3eb 100644 --- a/ase/stx/object.h +++ b/ase/stx/object.h @@ -1,5 +1,5 @@ /* - * $Id: object.h,v 1.11 2005-05-15 18:37:00 bacon Exp $ + * $Id: object.h,v 1.12 2005-05-18 04:01:51 bacon Exp $ */ #ifndef _XP_STX_OBJECT_H_ @@ -12,9 +12,9 @@ #define XP_STX_FROM_SMALLINT(x) ((x) >> 1) /* definitions for common objects */ -#define XP_STX_CLASS_DIMENSION 8 +#define XP_STX_CLASS_SIZE 8 #define XP_STX_CLASS_NAME 0 -#define XP_STX_CLASS_SIZE 1 +#define XP_STX_CLASS_SPEC 1 #define XP_STX_CLASS_METHODS 2 #define XP_STX_CLASS_SUPERCLASS 3 #define XP_STX_CLASS_VARIABLES 4 diff --git a/ase/stx/stx.c b/ase/stx/stx.c index 206d763e..d7f85dd6 100644 --- a/ase/stx/stx.c +++ b/ase/stx/stx.c @@ -1,5 +1,5 @@ /* - * $Id: stx.c,v 1.15 2005-05-17 16:18:56 bacon Exp $ + * $Id: stx.c,v 1.16 2005-05-18 04:01:51 bacon Exp $ */ #include @@ -10,6 +10,8 @@ #include #include +static void __create_initial_objects (xp_stx_t* stx); + xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity) { if (stx == XP_NULL) { @@ -31,9 +33,10 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity) stx->symbol_table = XP_STX_NIL; stx->smalltalk = XP_STX_NIL; - stx->class_symbol_link = XP_STX_NIL; + stx->class_symlink = XP_STX_NIL; stx->class_symbol = XP_STX_NIL; stx->class_metaclass = XP_STX_NIL; + stx->class_pairlink = XP_STX_NIL; stx->class_method = XP_STX_NIL; stx->class_context = XP_STX_NIL; @@ -48,19 +51,9 @@ void xp_stx_close (xp_stx_t* stx) if (stx->__malloced) xp_free (stx); } -static void __reset_symbol_link_class (xp_stx_t* stx, xp_stx_word_t idx) -{ - XP_STX_CLASS(stx,idx) = stx->class_symbol_link; -} - int xp_stx_bootstrap (xp_stx_t* stx) { - xp_stx_word_t symtab, symbol_Smalltalk; - xp_stx_word_t symbol_nil, symbol_true, symbol_false; - xp_stx_word_t symbol_Symbol, symbol_SymbolMeta; - xp_stx_word_t symbol_Metaclass, symbol_MetaclassMeta; - xp_stx_word_t class_Symbol, class_SymbolMeta; - xp_stx_word_t class_Metaclass, class_MetaclassMeta; + xp_stx_word_t symbol_Smalltalk, symbol_nil, symbol_true, symbol_false; xp_stx_word_t class_Object, class_Class; xp_stx_word_t tmp; @@ -79,154 +72,25 @@ int xp_stx_bootstrap (xp_stx_t* stx) /* build a system dictionary */ stx->smalltalk = xp_stx_alloc_object (stx, 2000); - /* create classes to make xp_stx_new_symbol work */ - stx->class_symbol_link = - xp_stx_alloc_object(stx,XP_STX_CLASS_DIMENSION); - stx->class_symbol = - xp_stx_alloc_object(stx,XP_STX_CLASS_DIMENSION); + /* initial system objects */ + __create_initial_objects (stx); - symbol_SymbolLink = - xp_stx_new_symbol (XP_STX_TEXT("SymbolLink")); - symbol_SymbolLinkMeta - xp_stx_new_symbol (XP_STX_TEXT("SymbolLink class")); - symbol_Symbol = - xp_stx_new_symbol (XP_STX_TEXT("Symbol")); - symbol_SymbolMeta = - xp_stx_new_symbol (XP_STX_TEXT("Symbol class")); - - XP_STX_AT(stx,stx->class_symbol_link,XP_STX_CLASS_NAME) = symbol_SymbolLinkMeta; - XP_STX_AT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_SymbolLink; + /* more initialization */ + XP_STX_CLASS(stx,stx->symbol_table) = + xp_stx_new_class (stx, XP_STX_TEXT("SymbolTable")); + XP_STX_CLASS(stx,stx->smalltalk) = + xp_stx_new_class (stx, XP_STX_TEXT("SystemDictionary")); + symbol_Smalltalk = xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk")); xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_string_object(stx, symbol_SymbolLink), - symbol_SymbolLink, stx->class_symbol); - xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_string_object(stx, symbol_Symbol), - symbol_Symbol, stx->class_symbol); - - /* class_metaclass to make xp_stx_new_class to work */ - stx->class_metaclass = - xp_stx_alloc_object(stx,XP_STX_CLASS_DIMENSION); - - symbol_Meaclass = - xp_stx_new_symbol (XP_STX_TEXT("Metaclass")); - symbol_MeaclassMeta = - xp_stx_new_symbol (XP_STX_TEXT("Metaclass class")); - - XP_STX_AT(stx->class_metaclass,XP_STX_CLASS_NAME) = symbol_Metaclass; - - xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_string_object(stx, symbol_Metaclass), - symbol_Metaclass, stx->class_metaclass); - - - /* .............. */ - symbol->Metaclass = xp_stx_new_symbol (XP_STX_TEXT("Metaclass")); - class_Metaclass = - xp_stx_alloc_object(stx,XP_STX_CLASS_DIMENSION); - - - xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_string_object(stx, symbol_Metaclass), - symbol_Metaclass, class_Metaclass); - - stx->class_metaclass = class_Metaclass; - - - class_Metaclass = xp_stx_new_class (stx, XP_STX_TEXT("Metaclass")); - class_Symbol = xp_stx_new_class (stx, XP_STX_TEXT("Symbol")); - - symbol_Symbol = - xp_stx_new_symbol (XP_STX_TEXT("Symbol")); - symbol_SymbolMeta = - xp_stx_new_symbol (XP_STX_TEXT("Symbol class")); - symbol_Metaclass = - xp_stx_new_symbol (XP_STX_TEXT("Metaclass")); - symbol_MetaclassMeta = - xp_stx_new_symbol (XP_STX_TEXT("Metaclass class")); - - /* tweak the initial object structure */ - /* - class_Metaclass = xp_stx_alloc_object(stx, XP_STX_CLASS_DIMENSION); - class_MetaclassMeta = xp_stx_alloc_object(stx, XP_STX_CLASS_DIMENSION); - class_Symbol = xp_stx_alloc_object(stx, XP_STX_CLASS_DIMENSION); - class_SymbolMeta = xp_stx_alloc_object(stx, XP_STX_CLASS_DIMENSION); - - symbol_Symbol = - xp_stx_alloc_string_object(stx, XP_STX_TEXT("Symbol")); - symbol_SymbolMeta = - xp_stx_alloc_string_object(stx,XP_STX_TEXT("Symbol class")); - symbol_Metaclass = - xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass")); - symbol_MetaclassMeta = - xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass class")); - - XP_STX_CLASS(stx,symbol_SymbolMeta) = class_Symbol; - XP_STX_CLASS(stx,symbol_Metaclass) = class_Symbol; - XP_STX_CLASS(stx,symbol_MetaclassMeta) = class_Symbol; - - XP_STX_CLASS(stx,class_Symbol) = class_SymbolMeta; - XP_STX_CLASS(stx,class_SymbolMeta) = class_Metaclass; - XP_STX_CLASS(stx,class_Metaclass) = class_MetaclassMeta; - XP_STX_CLASS(stx,class_MetaclassMeta) = class_Metaclass; - */ - - /* - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_Symbol), - symbol_Symbol, class_Symbol); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_SymbolMeta), - symbol_SymbolMeta, class_SymbolMeta); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_Metaclass), - symbol_Metaclass, class_Metaclass); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_MetaclassMeta), - symbol_MetaclassMeta, class_MetaclassMeta); - */ - - /* now ready to use new_symbol & new_class */ - /* - stx->symbol_table = symtab; - stx->class_symbol = class_Symbol; - stx->class_metaclass = class_Metaclass; - */ - - /* more initialization for symbol table */ - /* - stx->class_symbol_link = - xp_stx_new_class (stx, XP_STX_TEXT("SymbolLink")); - - xp_stx_hash_traverse (stx, symtab, __reset_symbol_link_class); - XP_STX_CLASS(stx,symtab) = - xp_stx_new_class (stx, XP_STX_TEXT("Array")); - symbol_Smalltalk = - xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk")); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_Smalltalk), - symbol_Smalltalk, symtab); - */ + xp_stx_hash_string_object(stx,symbol_Smalltalk), + symbol_Smalltalk, stx->smalltalk); /* more initialization for nil, true, false */ - /* -// nil, true, false must be treated specially by the compiler.... -// so it doesn't have to be registered into the system dictionary.... symbol_nil = xp_stx_new_symbol (stx, XP_STX_TEXT("nil")); symbol_true = xp_stx_new_symbol (stx, XP_STX_TEXT("true")); symbol_false = xp_stx_new_symbol (stx, XP_STX_TEXT("false")); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_nil), - symbol_nil, stx->nil); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_true), - symbol_true, stx->true); - xp_stx_hash_insert (stx, symtab, - xp_stx_hash_string_object(stx, symbol_false), - symbol_false, stx->false); - */ - XP_STX_CLASS(stx,stx->nil) = xp_stx_new_class (stx, XP_STX_TEXT("UndefinedObject")); XP_STX_CLASS(stx,stx->true) = @@ -246,3 +110,123 @@ int xp_stx_bootstrap (xp_stx_t* stx) return 0; } +static void __create_initial_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; + + stx->class_symlink = /* Symlink */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_symbol = /* Symbol */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_metaclass = /* Metaclass */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_pairlink = /* Pairlink */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + + class_SymlinkMeta = /* Symlink class */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + class_SymbolMeta = /* Symbol class */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + class_MetaclassMeta = /* Metaclass class */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + class_PairlinkMeta = /* Pairlink class */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + + /* (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; + + stx->class_symlink = /* Symlink */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_symbol = /* Symbol */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_metaclass = /* Metaclass */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + stx->class_pairlink = /* Pairlink */ + xp_stx_alloc_object(stx,XP_STX_CLASS_SIZE); + + /* (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: (Metaclass class) */ + XP_STX_CLASS(stx,stx->class_pairlink) = class_PairlinkMeta; + + /* (Symlink class) setSpec: CLASS_SIZE */ + XP_STX_AT(stx,class_SymlinkMeta,XP_STX_CLASS_SPEC) = + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); + /* (Symbol class) setSpec: CLASS_SIZE */ + XP_STX_AT(stx,class_SymbolMeta,XP_STX_CLASS_SPEC) = + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); + /* (Metaclass class) setSpec: CLASS_SIZE */ + XP_STX_AT(stx,class_MetaclassMeta,XP_STX_CLASS_SPEC) = + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); + /* (Pairlink class) setSpec: CLASS_SIZE */ + XP_STX_AT(stx,class_PairlinkMeta,XP_STX_CLASS_SPEC) = + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); + + /* #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 */ + XP_STX_AT(stx,stx->class_symlink,XP_STX_CLASS_NAME) = symbol_Symlink; + /* Symbol setName: #Symbol */ + XP_STX_AT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_Symbol; + /* Metaclass setName: #Metaclass */ + XP_STX_AT(stx,stx->class_metaclass,XP_STX_CLASS_NAME) = symbol_Metaclass; + /* Pairlink setName: #Pairlink */ + XP_STX_AT(stx,stx->class_pairlink,XP_STX_CLASS_NAME) = symbol_Pairlink; + + /* register class names into the system dictionary */ + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_string_object(stx, symbol_Symlink), + symbol_Symlink, stx->class_symlink); + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_string_object(stx, symbol_Symbol), + symbol_Symbol, stx->class_symbol); + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_string_object(stx, symbol_Metaclass), + symbol_Metaclass, stx->class_metaclass); + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_string_object(stx, symbol_Pairlink), + symbol_Pairlink, stx->class_pairlink); +} + diff --git a/ase/stx/stx.h b/ase/stx/stx.h index f41cac5c..e420e13a 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.13 2005-05-17 16:18:56 bacon Exp $ + * $Id: stx.h,v 1.14 2005-05-18 04:01:51 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -73,9 +73,10 @@ struct xp_stx_t xp_stx_word_t symbol_table; xp_stx_word_t smalltalk; - xp_stx_word_t class_symbol_link; + xp_stx_word_t class_symlink; xp_stx_word_t class_symbol; xp_stx_word_t class_metaclass; + xp_stx_word_t class_pairlink; xp_stx_word_t class_method; xp_stx_word_t class_context; diff --git a/ase/stx/symbol.c b/ase/stx/symbol.c index e308191d..9ea865ad 100644 --- a/ase/stx/symbol.c +++ b/ase/stx/symbol.c @@ -1,5 +1,5 @@ /* - * $Id: symbol.c,v 1.1 2005-05-17 16:18:56 bacon Exp $ + * $Id: symbol.c,v 1.2 2005-05-18 04:01:51 bacon Exp $ */ #include @@ -7,18 +7,18 @@ #include #include -#define SYMBOL_LINK_DIMENSION 2 -#define SYMBOL_LINK_LINK 0 -#define SYMBOL_LINK_SYMBOL 1 +#define SYMLINK_SIZE 2 +#define SYMLINK_LINK 0 +#define SYMLINK_SYMBOL 1 -xp_stx_word_t xp_stx_new_symbol_link (xp_stx_t* stx, xp_stx_word_t sym) +xp_stx_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_stx_word_t sym) { xp_stx_word_t x; - x = xp_stx_alloc_object (stx, SYMBOL_LINK_DIMENSION); - XP_STX_CLASS(stx,x) = stx->class_symbol_link; - /*XP_STX_AT(stx,x,SYMBOL_LINK_LINK) = stx->nil;*/ - XP_STX_AT(stx,x,SYMBOL_LINK_SYMBOL) = sym; + x = xp_stx_alloc_object (stx, SYMLINK_SIZE); + XP_STX_CLASS(stx,x) = stx->class_symlink; + /*XP_STX_AT(stx,x,SYMLINK_LINK) = stx->nil;*/ + XP_STX_AT(stx,x,SYMLINK_SYMBOL) = sym; return x; } @@ -34,23 +34,23 @@ xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name) if (link == stx->nil) { x = xp_stx_alloc_string_object (stx, name); XP_STX_CLASS(stx,x) = stx->class_symbol; - XP_STX_AT(stx,table,hash) = xp_stx_new_symbol_link(stx,x); + XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x); } else { do { - x = XP_STX_AT(stx,link,SYMBOL_LINK_SYMBOL); + x = XP_STX_AT(stx,link,SYMLINK_SYMBOL); xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); if (xp_stx_strxcmp ( &XP_STX_CHARAT(stx,x,0), XP_STX_SIZE(stx,x), name) == 0) return x; - next = XP_STX_AT(stx,link,SYMBOL_LINK_LINK); + next = XP_STX_AT(stx,link,SYMLINK_LINK); if (next == stx->nil) { x = xp_stx_alloc_string_object (stx, name); XP_STX_CLASS(stx,x) = stx->class_symbol; - XP_STX_AT(stx,link,SYMBOL_LINK_LINK) = - xp_stx_new_symbol_link(stx,x); + XP_STX_AT(stx,link,SYMLINK_LINK) = + xp_stx_new_symlink(stx,x); break; } @@ -75,23 +75,23 @@ xp_stx_word_t xp_stx_new_symbol_pp ( if (link == stx->nil) { x = xp_stx_allocn_string_object (stx, prefix, name, postfix); XP_STX_CLASS(stx,x) = stx->class_symbol; - XP_STX_AT(stx,table,hash) = xp_stx_new_symbol_link(stx,x); + XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x); } else { do { - x = XP_STX_AT(stx,link,SYMBOL_LINK_SYMBOL); + x = XP_STX_AT(stx,link,SYMLINK_SYMBOL); xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); if (xp_stx_strxcmp ( &XP_STX_CHARAT(stx,x,0), XP_STX_SIZE(stx,x), name) == 0) return x; - next = XP_STX_AT(stx,link,SYMBOL_LINK_LINK); + next = XP_STX_AT(stx,link,SYMLINK_LINK); if (next == stx->nil) { x = xp_stx_allocn_string_object (stx, prefix, name, postfix); XP_STX_CLASS(stx,x) = stx->class_symbol; - XP_STX_AT(stx,link,SYMBOL_LINK_LINK) = - xp_stx_new_symbol_link(stx,x); + XP_STX_AT(stx,link,SYMLINK_LINK) = + xp_stx_new_symlink(stx,x); break; } @@ -102,3 +102,23 @@ xp_stx_word_t xp_stx_new_symbol_pp ( return x; } + +void xp_stx_traverse_symbol_table ( + xp_stx_t* stx, void (*func) (xp_stx_t*,xp_stx_word_t)) +{ + xp_stx_word_t link; + xp_stx_word_t size; + xp_stx_word_t table; + + table = stx->symbol_table; + size = XP_STX_SIZE(stx,table); + + while (size-- > 0) { + link = XP_STX_AT(stx,table,size); + + while (link != stx->nil) { + func (stx,XP_STX_AT(stx,link,SYMLINK_SYMBOL)); + link = XP_STX_AT(stx,link,SYMLINK_LINK); + } + } +} diff --git a/ase/stx/symbol.h b/ase/stx/symbol.h index dca787b9..a492d306 100644 --- a/ase/stx/symbol.h +++ b/ase/stx/symbol.h @@ -1,5 +1,5 @@ /* - * $Id: symbol.h,v 1.1 2005-05-17 16:18:56 bacon Exp $ + * $Id: symbol.h,v 1.2 2005-05-18 04:01:51 bacon Exp $ */ #ifndef _XP_STX_SYMBOL_H_ @@ -16,6 +16,9 @@ xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name); xp_stx_word_t xp_stx_new_symbol_pp ( xp_stx_t* stx, const xp_stx_char_t* name, const xp_stx_char_t* prefix, const xp_stx_char_t* postfix); +void xp_stx_traverse_symbol_table ( + xp_stx_t* stx, void (*func) (xp_stx_t*,xp_stx_word_t)); + #ifdef __cplusplus } diff --git a/ase/test/stx/stx.c b/ase/test/stx/stx.c index 70fd3322..c8c49098 100644 --- a/ase/test/stx/stx.c +++ b/ase/test/stx/stx.c @@ -2,10 +2,20 @@ #include #include +#include #include #include -void print_symbol_names (xp_stx_t* stx, xp_stx_word_t idx) +void print_symbol_names (xp_stx_t* stx, xp_stx_word_t sym) +{ + /* + xp_stx_word_t key = XP_STX_AT(stx,idx,1); + xp_printf (XP_TEXT("%u -> %s\n"), key, &XP_STX_CHARAT(stx,key,0)); + */ + xp_printf (XP_TEXT("%u -> %s\n"), sym, &XP_STX_CHARAT(stx,sym,0)); +} + +void print_symbol_names_2 (xp_stx_t* stx, xp_stx_word_t idx) { xp_stx_word_t key = XP_STX_AT(stx,idx,1); xp_printf (XP_TEXT("%u -> %s\n"), key, &XP_STX_CHARAT(stx,key,0)); @@ -35,8 +45,13 @@ int xp_main (int argc, xp_char_t* argv[]) xp_printf (XP_TEXT("stx.nil %d\n"), stx.nil); xp_printf (XP_TEXT("stx.true %d\n"), stx.true); xp_printf (XP_TEXT("stx.false %d\n"), stx.false); + xp_printf (XP_TEXT("-------------\n")); - xp_stx_hash_traverse (&stx, stx.symbol_table, print_symbol_names); + xp_stx_traverse_symbol_table (&stx, print_symbol_names); + xp_printf (XP_TEXT("-------------\n")); + + xp_stx_hash_traverse (&stx, stx.smalltalk, print_symbol_names_2); + xp_printf (XP_TEXT("-------------\n")); { xp_stx_word_t class_name, method_name; @@ -46,7 +61,7 @@ int xp_main (int argc, xp_char_t* argv[]) class_name = xp_stx_new_symbol (&stx,argv[1]); method_name = xp_stx_new_symbol (&stx,XP_STX_TEXT("main")); - if (xp_stx_lookup_global (&stx,class_name, &main_class) == -1) { + if (xp_stx_lookup_global (&stx,class_name,&main_class) == -1) { xp_printf (XP_TEXT("non-existent class: %s\n"), argv[1]); return -1; }