*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-19 12:08:04 +00:00
parent 1b7d49266a
commit 30382196be
15 changed files with 298 additions and 234 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: macros.h,v 1.26 2005-06-06 16:32:29 bacon Exp $
* $Id: macros.h,v 1.27 2005-07-19 12:08:04 bacon Exp $
*/
#ifndef _XP_MACROS_H_
@ -33,6 +33,7 @@
((XP_TYPE_IS_SIGNED(type)? (type)((type)1 << (xp_sizeof(type) * 8 - 1)): (type)0))
#define XP_NUM_IS_POWOF2(x) (((x) & ((x) - 1)) == 0)
#define XP_SWAP(x,y) ((x) ^= (y) ^= (x) ^= (y))
#define XP_LOOP_CONTINUE(id) goto __loop_ ## id ## _begin__;
#define XP_LOOP_BREAK(id) goto __loop_ ## id ## _end__;

View File

@ -1,12 +1,12 @@
/*
* $Id: bootstrp.c,v 1.26 2005-07-18 11:53:01 bacon Exp $
* $Id: bootstrp.c,v 1.27 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/bootstrp.h>
#include <xp/stx/symbol.h>
#include <xp/stx/class.h>
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/dict.h>
#include <xp/stx/misc.h>
static void __create_bootstrapping_objects (xp_stx_t* stx);
@ -226,7 +226,7 @@ static class_info_t class_info[] =
{
XP_TEXT("Dictionary"),
XP_TEXT("IndexedCollection"),
XP_NULL,
XP_TEXT("tally"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_WORD_INDEXABLE
@ -279,14 +279,6 @@ static class_info_t class_info[] =
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{
XP_TEXT("Pairlink"),
XP_TEXT("Link"),
XP_TEXT("key value"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{
XP_NULL,
XP_NULL,
@ -334,38 +326,37 @@ int xp_stx_bootstrap (xp_stx_t* stx)
stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray"));
stx->class_string = xp_stx_new_class (stx, XP_TEXT("String"));
stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character"));
stx->class_dictionary = xp_stx_new_class (stx, XP_TEXT("Dictionary"));
stx->class_method = xp_stx_new_class (stx, XP_TEXT("Method"));
stx->class_smallinteger = xp_stx_new_class (stx, XP_TEXT("SmallInteger"));
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"));
__create_builtin_classes (stx);
/* (Object class) setSuperclass: Class */
object_meta = XP_STX_CLASS(stx,stx->class_object);
XP_STX_WORDAT(stx,object_meta,XP_STX_METACLASS_SUPERCLASS) = stx->class_class;
XP_STX_WORD_AT(stx,object_meta,XP_STX_METACLASS_SUPERCLASS) = stx->class_class;
/* instance class for Object is set here as it is not
* set in __create_builtin_classes */
XP_STX_WORDAT(stx,object_meta,XP_STX_METACLASS_INSTANCE_CLASS) = stx->class_object;
XP_STX_WORD_AT(stx,object_meta,XP_STX_METACLASS_INSTANCE_CLASS) = stx->class_object;
/* for some fun here */
{
xp_word_t array;
array = __new_array (stx, 1);
XP_STX_WORDAT(stx,array,0) = object_meta;
XP_STX_WORDAT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
XP_STX_WORD_AT(stx,array,0) = object_meta;
XP_STX_WORD_AT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
}
/* more initialization */
XP_STX_CLASS(stx,stx->symbol_table) =
xp_stx_lookup_class (stx, XP_TEXT("SymbolTable"));
XP_STX_CLASS(stx,stx->smalltalk) =
xp_stx_lookup_class (stx, XP_TEXT("SystemDictionary"));
xp_stx_lookup_class(stx, XP_TEXT("SymbolTable"));
XP_STX_CLASS(stx,stx->smalltalk) = stx->class_system_dictionary;
symbol_Smalltalk =
xp_stx_new_symbol (stx, XP_TEXT("Smalltalk"));
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, symbol_Smalltalk),
symbol_Smalltalk, stx->smalltalk);
symbol_Smalltalk = xp_stx_new_symbol (stx, XP_TEXT("Smalltalk"));
xp_stx_dict_put (stx, stx->smalltalk, symbol_Smalltalk, stx->smalltalk);
/* create #nil, #true, #false */
xp_stx_new_symbol (stx, XP_TEXT("nil"));
@ -374,7 +365,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
/* nil setClass: UndefinedObject */
XP_STX_CLASS(stx,stx->nil) =
xp_stx_lookup_class (stx, XP_TEXT("UndefinedObject"));
xp_stx_lookup_class(stx, XP_TEXT("UndefinedObject"));
/* true setClass: True */
XP_STX_CLASS(stx,stx->true) =
xp_stx_lookup_class (stx, XP_TEXT("True"));
@ -391,11 +382,11 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
xp_word_t class_SymlinkMeta;
xp_word_t class_SymbolMeta;
xp_word_t class_MetaclassMeta;
xp_word_t class_PairlinkMeta;
xp_word_t class_AssociationMeta;
xp_word_t symbol_Symlink;
xp_word_t symbol_Symbol;
xp_word_t symbol_Metaclass;
xp_word_t symbol_Pairlink;
xp_word_t symbol_Association;
/* allocate three keyword objects */
stx->nil = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, 0);
@ -410,8 +401,12 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
/* TODO: symbol table and dictionary size */
stx->symbol_table = xp_stx_alloc_word_object (
stx, XP_NULL, 0, XP_NULL, 1000);
xp_printf (XP_TEXT("xxxxxxxxxxxxxxxxxx\n"));
stx->smalltalk = xp_stx_alloc_word_object (
stx, XP_NULL, 0, XP_NULL, 2000);
stx, XP_NULL, 1, XP_NULL, 1024);
xp_printf (XP_TEXT("yyyyyyyyyyyyyyyyyyy\n"));
/* set tally */
XP_STX_WORD_AT(stx,stx->smalltalk,0) = XP_STX_TO_SMALLINT(0);
/* Symlink */
stx->class_symlink = xp_stx_alloc_word_object(
@ -422,8 +417,8 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
/* Metaclass */
stx->class_metaclass = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
/* Pairlink */
stx->class_pairlink = xp_stx_alloc_word_object(
/* Association */
stx->class_association = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
/* Metaclass is a class so it has the same structure
@ -439,8 +434,8 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
/* Metaclass class */
class_MetaclassMeta = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_METACLASS_SIZE, XP_NULL, 0);
/* Pairlink class */
class_PairlinkMeta = xp_stx_alloc_word_object(
/* Association class */
class_AssociationMeta = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_METACLASS_SIZE, XP_NULL, 0);
/* (Symlink class) setClass: Metaclass */
@ -449,8 +444,8 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
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;
/* (Association class) setClass: Metaclass */
XP_STX_CLASS(stx,class_AssociationMeta) = stx->class_metaclass;
/* Symlink setClass: (Symlink class) */
XP_STX_CLASS(stx,stx->class_symlink) = class_SymlinkMeta;
@ -458,23 +453,23 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
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;
/* Association setClass: (Association class) */
XP_STX_CLASS(stx,stx->class_association) = class_AssociationMeta;
/* (Symlink class) setSpec: XP_STX_CLASS_SIZE */
XP_STX_WORDAT(stx,class_SymlinkMeta,XP_STX_CLASS_SPEC) =
XP_STX_WORD_AT(stx,class_SymlinkMeta,XP_STX_CLASS_SPEC) =
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* (Symbol class) setSpec: CLASS_SIZE */
XP_STX_WORDAT(stx,class_SymbolMeta,XP_STX_CLASS_SPEC) =
XP_STX_WORD_AT(stx,class_SymbolMeta,XP_STX_CLASS_SPEC) =
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* (Metaclass class) setSpec: CLASS_SIZE */
XP_STX_WORDAT(stx,class_MetaclassMeta,XP_STX_CLASS_SPEC) =
XP_STX_WORD_AT(stx,class_MetaclassMeta,XP_STX_CLASS_SPEC) =
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* (Pairlink class) setSpec: CLASS_SIZE */
XP_STX_WORDAT(stx,class_PairlinkMeta,XP_STX_CLASS_SPEC) =
/* (Association class) setSpec: CLASS_SIZE */
XP_STX_WORD_AT(stx,class_AssociationMeta,XP_STX_CLASS_SPEC) =
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* specs for class_metaclass, class_pairlink,
/* specs for class_metaclass, class_association,
* class_symbol, class_symlink are set later in
* __create_builtin_classes */
@ -484,31 +479,27 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
symbol_Symbol = xp_stx_new_symbol (stx, XP_TEXT("Symbol"));
/* #Metaclass */
symbol_Metaclass = xp_stx_new_symbol (stx, XP_TEXT("Metaclass"));
/* #Pairlink */
symbol_Pairlink = xp_stx_new_symbol (stx, XP_TEXT("Pairlink"));
/* #Association */
symbol_Association = xp_stx_new_symbol (stx, XP_TEXT("Association"));
/* Symlink setName: #Symlink */
XP_STX_WORDAT(stx,stx->class_symlink,XP_STX_CLASS_NAME) = symbol_Symlink;
XP_STX_WORD_AT(stx,stx->class_symlink,XP_STX_CLASS_NAME) = symbol_Symlink;
/* Symbol setName: #Symbol */
XP_STX_WORDAT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_Symbol;
XP_STX_WORD_AT(stx,stx->class_symbol,XP_STX_CLASS_NAME) = symbol_Symbol;
/* Metaclass setName: #Metaclass */
XP_STX_WORDAT(stx,stx->class_metaclass,XP_STX_CLASS_NAME) = symbol_Metaclass;
/* Pairlink setName: #Pairlink */
XP_STX_WORDAT(stx,stx->class_pairlink,XP_STX_CLASS_NAME) = symbol_Pairlink;
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;
/* register class names into the system dictionary */
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, symbol_Symlink),
symbol_Symlink, stx->class_symlink);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, symbol_Symbol),
symbol_Symbol, stx->class_symbol);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, symbol_Metaclass),
symbol_Metaclass, stx->class_metaclass);
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, symbol_Pairlink),
symbol_Pairlink, stx->class_pairlink);
xp_stx_dict_put (stx,
stx->smalltalk, symbol_Symlink, stx->class_symlink);
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);
}
static void __create_builtin_classes (xp_stx_t* stx)
@ -708,7 +699,7 @@ static xp_word_t __make_classvar_dict (
const xp_char_t* name;
dict = xp_stx_instantiate (
stx, stx->class_dictionary,
stx, stx->class_system_dictionary,
XP_NULL, XP_NULL, __count_names(names));
do {
@ -723,8 +714,11 @@ static xp_word_t __make_classvar_dict (
symbol = xp_stx_new_symbolx (stx, name, p - name);
/*
xp_stx_hash_insert (stx, dict,
xp_stx_hash_object(stx, symbol), symbol, stx->nil);
*/
xp_stx_dict_put (stx, dict, symbol, stx->nil);
} while (1);
return dict;

View File

@ -1,10 +1,10 @@
/*
* $Id: bytecode.c,v 1.7 2005-07-11 13:41:59 bacon Exp $
* $Id: bytecode.c,v 1.8 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/bytecode.h>
#include <xp/stx/class.h>
#include <xp/stx/method.h>
#include <xp/stx/hash.h>
#include <xp/stx/dict.h>
static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data);
static int __decode2 (xp_stx_t* stx,
@ -19,7 +19,7 @@ int xp_stx_decode (xp_stx_t* stx, xp_word_t class)
/* TODO */
xp_stx_hash_traverse (stx, class_obj->methods, __decode1, class_obj);
xp_stx_dict_traverse (stx, class_obj->methods, __decode1, class_obj);
return 0;
}
@ -29,7 +29,7 @@ static void __dump_object (xp_stx_t* stx, xp_word_t obj)
xp_printf (XP_TEXT("%d"), XP_STX_FROM_SMALLINT(obj));
}
else if (XP_STX_CLASS(stx,obj) == stx->class_character) {
xp_printf (XP_TEXT("$%c"), XP_STX_WORDAT(stx,obj,0));
xp_printf (XP_TEXT("$%c"), XP_STX_WORD_AT(stx,obj,0));
}
else if (XP_STX_CLASS(stx,obj) == stx->class_string) {
xp_printf (XP_TEXT("'%s'"), XP_STX_DATA(stx,obj));
@ -55,8 +55,8 @@ static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data)
{
xp_stx_method_t* method_obj;
xp_stx_class_t* class_obj;
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
xp_word_t key = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_KEY);
xp_word_t value = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_VALUE);
xp_word_t* literals;
xp_word_t literal_count, i;

View File

@ -1,11 +1,11 @@
/*
* $Id: class.c,v 1.21 2005-07-07 07:45:05 bacon Exp $
* $Id: class.c,v 1.22 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/class.h>
#include <xp/stx/symbol.h>
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/dict.h>
#include <xp/stx/misc.h>
xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name)
@ -18,7 +18,7 @@ xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name)
XP_STX_CLASS(stx,meta) = stx->class_metaclass;
/* the spec of the metaclass must be the spec of its
* instance. so the XP_STX_CLASS_SIZE is set */
XP_STX_WORDAT(stx,meta,XP_STX_METACLASS_SPEC) =
XP_STX_WORD_AT(stx,meta,XP_STX_METACLASS_SPEC) =
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* the spec of the class is set later in __create_builtin_classes */
@ -26,24 +26,26 @@ xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name)
stx, XP_NULL, XP_STX_CLASS_SIZE, XP_NULL, 0);
XP_STX_CLASS(stx,class) = meta;
class_name = xp_stx_new_symbol (stx, name);
XP_STX_WORDAT(stx,class,XP_STX_CLASS_NAME) = class_name;
XP_STX_WORD_AT(stx,class,XP_STX_CLASS_NAME) = class_name;
/*
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_object(stx, class_name),
class_name, class);
*/
xp_stx_dict_put (stx, stx->smalltalk, class_name, class);
return class;
}
xp_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_char_t* name)
{
xp_word_t link, meta, value;
xp_word_t assoc, meta, value;
link = xp_stx_hash_lookup_symbol (stx, stx->smalltalk, name);
if (link == stx->nil) return stx->nil;
value = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_VALUE);
assoc = xp_stx_dict_lookup (stx, stx->smalltalk, name);
if (assoc == stx->nil) return stx->nil;
value = XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_VALUE);
meta = XP_STX_CLASS(stx,value);
if (XP_STX_CLASS(stx,meta) != stx->class_metaclass) return stx->nil;
@ -108,8 +110,8 @@ xp_word_t xp_stx_lookup_class_variable (
/* TODO: can a metaclas have class variables? */
if (class_obj->header.class != stx->class_metaclass &&
class_obj->class_variables != stx->nil) {
if (xp_stx_hash_lookup_symbol(stx,
class_obj->class_variables, name) != stx->nil) return class_index;
if (xp_stx_dict_lookup(stx,
class_obj->class_variables,name) != stx->nil) return class_index;
}
return stx->nil;

View File

@ -1,5 +1,5 @@
/*
* $Id: context.c,v 1.10 2005-07-05 09:02:13 bacon Exp $
* $Id: context.c,v 1.11 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/context.h>
@ -38,7 +38,7 @@ static xp_byte_t __fetch_byte (
context_obj->ip = XP_STX_TO_SMALLINT(ip + 1);
xp_assert (XP_STX_TYPE(stx,method) == XP_STX_BYTE_INDEXED);
return XP_STX_BYTEAT(stx,method,ip);
return XP_STX_BYTE_AT(stx,method,ip);
}
int xp_stx_run_context (xp_stx_t* stx, xp_word_t context)

View File

@ -1,12 +1,12 @@
/*
* $Id: dict.c,v 1.1 2005-07-18 11:53:01 bacon Exp $
* $Id: dict.c,v 1.2 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/dict.h>
#include <xp/stx/object.h>
#include <xp/stx/misc.h>
xp_word_t xp_stx_new_association (
xp_word_t __new_association (
xp_stx_t* stx, xp_word_t key, xp_word_t value)
{
xp_word_t x;
@ -18,107 +18,165 @@ xp_word_t xp_stx_new_association (
return x;
}
#if 0
/* returns the entire link */
xp_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_word_t table,
xp_word_t hash, xp_word_t key)
static xp_word_t __dict_find_slot (
xp_stx_t* stx, xp_word_t dict, xp_word_t key)
{
xp_word_t link;
xp_stx_pairlink_t* obj;
xp_word_t size, hash, index, assoc, symbol;
xp_stx_word_object_t* dict_obj;
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
xp_assert (XP_STX_IS_WORD_OBJECT(stx, dict));
xp_assert (dict == stx->smalltalk ||
XP_STX_CLASS(stx,dict) == stx->class_system_dictionary);
xp_assert (XP_STX_CLASS(stx,key) == stx->class_symbol);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
size = XP_STX_SIZE(stx,dict);
hash = xp_stx_hash_object(stx, key);
xp_printf (XP_TEXT("find_slot %s %u\n"), XP_STX_DATA(stx,key), hash);
while (link != stx->nil) {
/*
if (XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link;
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
*/
/* consider tally, the only instance variable of a system dictionary */
index = hash % (size - 1) + 1;
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
if (obj->key == key) return link;
link = obj->link;
dict_obj = XP_STX_WORD_OBJECT(stx,dict);
while (1) {
assoc = dict_obj->data[index];
if (assoc == stx->nil) break;
symbol = XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_KEY);
xp_assert (XP_STX_CLASS(stx,symbol) == stx->class_symbol);
/*
* shallow comparison is enough for identity check
* because only a symbol can be a key of a system dictionary
*/
if (xp_stx_shallow_compare_object(stx, key, symbol) == 0) break;
/* consider tally here too */
index = index % (size - 1) + 1;
}
return stx->nil; /* not found */
return index;
}
xp_word_t xp_stx_hash_lookup_symbol (
xp_stx_t* stx, xp_word_t table, const xp_char_t* name)
static void __dict_grow (xp_stx_t* stx, xp_word_t dict)
{
xp_word_t link, hash;
xp_stx_pairlink_t* obj;
xp_stx_char_object_t* tmp;
xp_word_t new, size, index, assoc;
/*
* if this assertion fails, adjust the initial size of the
* system dictionary. i don't want this function to be called
* during the bootstrapping.
*/
xp_assert (stx->class_system_dictionary != stx->nil);
xp_assert (XP_STX_CLASS(stx,dict) == stx->class_system_dictionary);
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
size = XP_STX_SIZE(stx,dict);
new = xp_stx_instantiate (stx,
XP_STX_CLASS(stx,dict), XP_NULL, XP_NULL, (size - 1) * 2);
XP_STX_WORD_AT(stx,new,0) = XP_STX_TO_SMALLINT(0);
hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
for (index = 1; index < size; index++) {
assoc = XP_STX_WORD_AT(stx,dict,index);
if (assoc == stx->nil) continue;
while (link != stx->nil) {
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
tmp = XP_STX_CHAR_OBJECT(stx,obj->key);
if (tmp->header.class == stx->class_symbol &&
xp_strcmp (tmp->data, name) == 0) return link;
link = obj->link;
xp_stx_dict_put (stx, new,
XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_KEY),
XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_VALUE));
}
return stx->nil; /* not found */
xp_printf (XP_TEXT("dictionary grown. swapped the index\n"));
XP_SWAP (((xp_uint_t)XP_STX_OBJECT(stx,dict)),
((xp_uint_t)XP_STX_OBJECT(stx,new)));
}
void xp_stx_hash_insert (
xp_stx_t* stx, xp_word_t table,
xp_word_t hash, xp_word_t key, xp_word_t value)
xp_word_t xp_stx_dict_lookup (
xp_stx_t* stx, xp_word_t dict, const xp_char_t* key)
{
xp_word_t link, next;
xp_word_t size, hash, index, assoc, symbol;
xp_stx_word_object_t* dict_obj;
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
xp_assert (XP_STX_IS_WORD_OBJECT(stx, dict));
xp_assert (dict == stx->smalltalk ||
XP_STX_CLASS(stx,dict) == stx->class_system_dictionary);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
size = XP_STX_SIZE(stx,dict);
/*hash = xp_stx_hash_object(stx, key);*/
hash = xp_stx_hash(key, xp_strlen(key) * xp_sizeof(xp_char_t));
xp_printf (XP_TEXT("lookup hash %s %u\n"), key, hash);
if (link == stx->nil) {
XP_STX_WORDAT(stx,table,hash) =
xp_stx_new_pairlink (stx, key, value);
/* consider tally, the only instance variable of a system dictionary */
index = hash % (size - 1) + 1;
dict_obj = XP_STX_WORD_OBJECT(stx,dict);
while (1) {
xp_printf (XP_TEXT("dict_lookup: %d\n"), index);
assoc = dict_obj->data[index];
if (assoc == stx->nil) break;
symbol = XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_KEY);
xp_assert (XP_STX_CLASS(stx,symbol) == stx->class_symbol);
/*
* note that xp_strcmp should be compatible with
* character object comparison in xp_stx_shallow_compare_object.
* otherwise, you will be in trouble.
*/
if (xp_strcmp(key, XP_STX_DATA(stx,symbol)) == 0) break;
/* consider tally here too */
index = index % (size - 1) + 1;
}
else {
for (;;) {
/* TODO: contents comparison */
if (XP_STX_WORDAT(stx,link,1) == key) {
XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_VALUE) = value;
break;
}
next = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
if (next == stx->nil) {
XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK) =
xp_stx_new_pairlink (stx, key, value);
break;
}
link = next;
}
}
xp_printf (XP_TEXT("dict_lookup: %s, %d, %d\n"), key, index, XP_STX_WORD_AT(stx,dict,index));
return XP_STX_WORD_AT(stx,dict,index);
}
void xp_stx_hash_traverse (
xp_stx_t* stx, xp_word_t table,
xp_word_t xp_stx_dict_get (xp_stx_t* stx, xp_word_t dict, xp_word_t key)
{
return XP_STX_WORD_AT(stx,dict,__dict_find_slot(stx, dict, key));
}
xp_word_t xp_stx_dict_put (
xp_stx_t* stx, xp_word_t dict, xp_word_t key, xp_word_t value)
{
xp_word_t slot, capa, tally, assoc;
/* the dictionary must have at least one slot excluding tally */
xp_assert (XP_STX_SIZE(stx,dict) > 1);
capa = XP_STX_SIZE(stx,dict) - 1;
tally = XP_STX_FROM_SMALLINT(XP_STX_WORD_AT(stx,dict,0));
if (capa <= tally + 1) {
__dict_grow (stx, dict);
/* refresh tally */
tally = XP_STX_FROM_SMALLINT(XP_STX_WORD_AT(stx,dict,0));
}
slot = __dict_find_slot (stx, dict, key);
assoc = XP_STX_WORD_AT(stx,dict,slot);
if (assoc == stx->nil) {
XP_STX_WORD_AT(stx,dict,slot) =
__new_association (stx, key, value);
XP_STX_WORD_AT(stx,dict,0) = XP_STX_TO_SMALLINT(tally + 1);
}
else XP_STX_WORD_AT(stx,assoc,XP_STX_ASSOCIATION_VALUE) = value;
xp_printf (XP_TEXT("dict_put %s %d\n"), XP_STX_DATA(stx,key),slot);
return XP_STX_WORD_AT(stx,dict,slot);
}
void xp_stx_dict_traverse (
xp_stx_t* stx, xp_word_t dict,
void (*func) (xp_stx_t*,xp_word_t,void*), void* data)
{
xp_word_t link;
xp_word_t size = XP_STX_SIZE(stx,table);
xp_word_t index, assoc;
xp_word_t size = XP_STX_SIZE(stx,dict);
while (size-- > 0) {
link = XP_STX_WORDAT(stx,table,size);
while (link != stx->nil) {
func (stx, link, data);
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
}
for (index = 1; index < size; index++) {
assoc = XP_STX_WORD_AT(stx,dict,index);
if (assoc == stx->nil) continue;
func (stx, assoc, data);
}
}
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: dict.h,v 1.1 2005-07-18 11:53:01 bacon Exp $
* $Id: dict.h,v 1.2 2005-07-19 12:08:04 bacon Exp $
*/
#ifndef _XP_STX_DICT_H_
@ -24,22 +24,16 @@ typedef struct xp_stx_association_t xp_stx_association_t;
extern "C"
#endif
xp_word_t xp_stx_new_association (
xp_stx_t* stx, xp_word_t key, xp_word_t value);
xp_word_t xp_stx_dict_lookup (
xp_stx_t* stx, xp_word_t dict, const xp_char_t* key);
xp_word_t xp_stx_dict_get (
xp_stx_t* stx, xp_word_t dict, xp_word_t key);
xp_word_t xp_stx_dict_put (
xp_stx_t* stx, xp_word_t dict, xp_word_t key, xp_word_t value);
void xp_stx_dict_traverse (
xp_stx_t* stx, xp_word_t dict,
void (*func) (xp_stx_t*,xp_word_t,void*), void* data);
#if 0
xp_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_word_t table,
xp_word_t hash, xp_word_t key);
xp_word_t xp_stx_hash_lookup_symbol (
xp_stx_t* stx, xp_word_t table, const xp_char_t* name);
void xp_stx_hash_insert (
xp_stx_t* stx, xp_word_t table,
xp_word_t hash, xp_word_t key, xp_word_t value);
void xp_stx_hash_traverse (
xp_stx_t* stx, xp_word_t table,
void (*func) (xp_stx_t*,xp_word_t,void*), void* data);
#endif
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: hash.c,v 1.25 2005-07-07 07:45:05 bacon Exp $
* $Id: hash.c,v 1.26 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/hash.h>
@ -33,13 +33,14 @@ xp_word_t xp_stx_hash_lookup (
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
//hash = hash % XP_STX_SIZE(stx,table);
hash = hash % (XP_STX_SIZE(stx,table) - 1) + 1;
link = XP_STX_WORD_AT(stx,table,hash);
while (link != stx->nil) {
/*
if (XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link;
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
if (XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link;
link = XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_LINK);
*/
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
@ -59,8 +60,9 @@ xp_word_t xp_stx_hash_lookup_symbol (
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
//hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
hash = xp_stx_strhash(name) % (XP_STX_SIZE(stx,table) - 1) + 1;
link = XP_STX_WORD_AT(stx,table,hash);
while (link != stx->nil) {
obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link);
@ -81,25 +83,29 @@ void xp_stx_hash_insert (
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED);
hash = hash % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
hash = hash % (XP_STX_SIZE(stx,table) - 1) + 1;
link = XP_STX_WORD_AT(stx,table,hash);
if (link == stx->nil) {
XP_STX_WORDAT(stx,table,hash) =
XP_STX_WORD_AT(stx,table,hash) =
xp_stx_new_pairlink (stx, key, value);
XP_STX_WORD_AT(stx,table,0) = XP_STX_TO_SMALLINT(
XP_STX_FROM_SMALLINT(XP_STX_WORD_AT(stx,table,0)) + 1);
}
else {
for (;;) {
/* TODO: contents comparison */
if (XP_STX_WORDAT(stx,link,1) == key) {
XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_VALUE) = value;
if (XP_STX_WORD_AT(stx,link,1) == key) {
XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_VALUE) = value;
break;
}
next = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
next = XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_LINK);
if (next == stx->nil) {
XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK) =
XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_LINK) =
xp_stx_new_pairlink (stx, key, value);
XP_STX_WORD_AT(stx,table,0) = XP_STX_TO_SMALLINT(
XP_STX_FROM_SMALLINT(XP_STX_WORD_AT(stx,table,0)) + 1);
break;
}
@ -115,12 +121,13 @@ void xp_stx_hash_traverse (
xp_word_t link;
xp_word_t size = XP_STX_SIZE(stx,table);
while (size-- > 0) {
link = XP_STX_WORDAT(stx,table,size);
//while (size-- > 0) {
while (size-- > 1) {
link = XP_STX_WORD_AT(stx,table,size);
while (link != stx->nil) {
func (stx, link, data);
link = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_LINK);
link = XP_STX_WORD_AT(stx,link,XP_STX_PAIRLINK_LINK);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: object.c,v 1.37 2005-07-13 14:42:27 bacon Exp $
* $Id: object.c,v 1.38 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/object.h>
@ -24,6 +24,7 @@ xp_word_t xp_stx_alloc_word_object (
* number of variable instance variables) * word_size
*/
n = nfields + variable_nfields;
xp_printf (XP_TEXT(">> %d\n"), n);
idx = xp_stx_memory_alloc (&stx->memory,
n * xp_sizeof(xp_word_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed TODO: return a difference value OINDEX_INVALID */
@ -148,7 +149,7 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...)
n = 0;
while ((p = xp_va_arg(ap, const xp_char_t*)) != XP_NULL) {
while (*p != XP_CHAR('\0')) {
/*XP_STX_CHARAT(stx,idx,n++) = *p++;*/
/*XP_STX_CHAR_AT(stx,idx,n++) = *p++;*/
obj->data[n++] = *p++;
}
}
@ -166,8 +167,7 @@ xp_word_t xp_stx_hash_object (xp_stx_t* stx, xp_word_t object)
hv = xp_stx_hash(&tmp, xp_sizeof(tmp));
}
else if (XP_STX_IS_CHAR_OBJECT(stx,object)) {
/*hv = xp_stx_strxhash (
XP_STX_DATA(stx,object), XP_STX_SIZE(stx,object));*/
/* the additional null is not taken into account */
hv = xp_stx_hash (XP_STX_DATA(stx,object),
XP_STX_SIZE(stx,object) * xp_sizeof(xp_char_t));
}
@ -184,6 +184,16 @@ xp_word_t xp_stx_hash_object (xp_stx_t* stx, xp_word_t object)
return hv;
}
xp_bool_t xp_stx_shallow_compare_object (
xp_stx_t* stx, xp_word_t a, xp_word_t b)
{
if (XP_STX_TYPE(stx,a) != XP_STX_TYPE(stx,b)) return xp_false;
if (XP_STX_SIZE(stx,a) != XP_STX_SIZE(stx,b)) return xp_false;
if (XP_STX_CLASS(stx,a) != XP_STX_CLASS(stx,b)) return xp_false;
return xp_memcmp (XP_STX_DATA(stx,a),
XP_STX_DATA(stx,b), XP_STX_SIZE(stx,a)) == 0;
}
xp_word_t xp_stx_instantiate (
xp_stx_t* stx, xp_word_t class, const void* data,
const void* variable_data, xp_word_t variable_nfields)

View File

@ -1,5 +1,5 @@
/*
* $Id: object.h,v 1.26 2005-07-13 14:42:27 bacon Exp $
* $Id: object.h,v 1.27 2005-07-19 12:08:04 bacon Exp $
*/
#ifndef _XP_STX_OBJECT_H_
@ -25,6 +25,8 @@ xp_word_t xp_stx_alloc_char_objectx (
xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...);
xp_word_t xp_stx_hash_object (xp_stx_t* stx, xp_word_t object);
xp_bool_t xp_stx_shallow_compare_object (
xp_stx_t* stx, xp_word_t a, xp_word_t b);
xp_word_t xp_stx_instantiate (
xp_stx_t* stx, xp_word_t class_index, const void* data,

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.c,v 1.64 2005-07-12 16:16:42 bacon Exp $
* $Id: parser.c,v 1.65 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/parser.h>
@ -8,7 +8,7 @@
#include <xp/stx/method.h>
#include <xp/stx/symbol.h>
#include <xp/stx/bytecode.h>
#include <xp/stx/hash.h>
#include <xp/stx/dict.h>
#include <xp/stx/misc.h>
static int __parse_method (
@ -412,7 +412,7 @@ static int __add_character_literal (xp_stx_parser_t* parser, xp_char_t ch)
stx->class_smallinteger: XP_STX_CLASS (stx, parser->literals[i]);
if (c != stx->class_character) continue;
if (ch == XP_STX_CHARAT(stx,parser->literals[i],0)) return i;
if (ch == XP_STX_CHAR_AT(stx,parser->literals[i],0)) return i;
}
literal = xp_stx_instantiate (
@ -503,7 +503,8 @@ static int __finish_method (xp_stx_parser_t* parser)
if (class_obj->methods == stx->nil) {
/* TODO: reconfigure method dictionary size */
class_obj->methods = xp_stx_instantiate (
stx, stx->class_dictionary, XP_NULL, XP_NULL, 64);
stx, stx->class_system_dictionary,
XP_NULL, XP_NULL, 64);
}
xp_assert (class_obj->methods != stx->nil);
@ -529,11 +530,7 @@ static int __finish_method (xp_stx_parser_t* parser)
XP_STX_TO_SMALLINT(parser->temporary_count);
*/
/* TODO: dictionaryAtPut (), remove hash.h above */
xp_stx_hash_insert (
stx, class_obj->methods,
xp_stx_hash_object(stx, selector),
selector, method);
xp_stx_dict_put (stx, class_obj->methods, selector, method);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.c,v 1.33 2005-07-12 16:16:42 bacon Exp $
* $Id: stx.c,v 1.34 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/stx.h>
@ -30,14 +30,14 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity)
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_association = XP_STX_NIL;
stx->class_object = XP_STX_NIL;
stx->class_class = XP_STX_NIL;
stx->class_bytearray = XP_STX_NIL;
stx->class_array = XP_STX_NIL;
stx->class_string = XP_STX_NIL;
stx->class_dictionary = XP_STX_NIL;
stx->class_system_dictionary = XP_STX_NIL;
stx->class_method = XP_STX_NIL;
stx->class_smallinteger = XP_STX_NIL;

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.h,v 1.37 2005-07-18 11:53:01 bacon Exp $
* $Id: stx.h,v 1.38 2005-07-19 12:08:04 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
@ -71,7 +71,6 @@ struct xp_stx_t
xp_word_t class_symlink;
xp_word_t class_symbol;
xp_word_t class_metaclass;
xp_word_t class_pairlink;
xp_word_t class_association;
xp_word_t class_object;
@ -80,7 +79,7 @@ struct xp_stx_t
xp_word_t class_bytearray;
xp_word_t class_string;
xp_word_t class_character;
xp_word_t class_dictionary;
xp_word_t class_system_dictionary;
xp_word_t class_method;
xp_word_t class_smallinteger;
@ -126,11 +125,11 @@ struct xp_stx_t
#define XP_STX_CHAR_OBJECT(stx,idx) \
((xp_stx_char_object_t*)XP_STX_OBJECT(stx,idx))
#define XP_STX_WORDAT(stx,idx,n) \
#define XP_STX_WORD_AT(stx,idx,n) \
(((xp_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
#define XP_STX_BYTEAT(stx,idx,n) \
#define XP_STX_BYTE_AT(stx,idx,n) \
(((xp_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
#define XP_STX_CHARAT(stx,idx,n) \
#define XP_STX_CHAR_AT(stx,idx,n) \
(((xp_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: symbol.c,v 1.16 2005-07-18 11:53:01 bacon Exp $
* $Id: symbol.c,v 1.17 2005-07-19 12:08:04 bacon Exp $
*/
#include <xp/stx/symbol.h>
@ -13,8 +13,8 @@ xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t symbol)
x = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_SYMLINK_SIZE, XP_NULL, 0);
XP_STX_CLASS(stx,x) = stx->class_symlink;
XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil;
XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_SYMBOL) = symbol;
XP_STX_WORD_AT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil;
XP_STX_WORD_AT(stx,x,XP_STX_SYMLINK_SYMBOL) = symbol;
return x;
}
@ -31,27 +31,27 @@ xp_word_t xp_stx_new_symbolx (
table = stx->symbol_table;
hash = xp_stx_strxhash(name,len) % XP_STX_SIZE(stx,table);
link = XP_STX_WORDAT(stx,table,hash);
link = XP_STX_WORD_AT(stx,table,hash);
if (link == stx->nil) {
x = xp_stx_alloc_char_objectx (stx, name, len);
XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_WORDAT(stx,table,hash) = xp_stx_new_symlink(stx,x);
XP_STX_WORD_AT(stx,table,hash) = xp_stx_new_symlink(stx,x);
}
else {
do {
x = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_SYMBOL);
x = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_SYMBOL);
xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_strxcmp (
XP_STX_DATA(stx,x),
XP_STX_SIZE(stx,x), name) == 0) return x;
next = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK);
next = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK);
if (next == stx->nil) {
x = xp_stx_alloc_char_objectx (stx, name, len);
XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK) =
XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK) =
xp_stx_new_symlink(stx,x);
break;
}
@ -74,11 +74,11 @@ void xp_stx_traverse_symbol_table (
size = XP_STX_SIZE(stx,table);
while (size-- > 0) {
link = XP_STX_WORDAT(stx,table,size);
link = XP_STX_WORD_AT(stx,table,size);
while (link != stx->nil) {
func (stx, XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_SYMBOL), data);
link = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK);
func (stx, XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_SYMBOL), data);
link = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK);
}
}
}

View File

@ -13,19 +13,19 @@
#include <xp/stx/symbol.h>
#include <xp/stx/context.h>
#include <xp/stx/class.h>
#include <xp/stx/hash.h>
#include <xp/stx/dict.h>
void print_symbol_names (xp_stx_t* stx, xp_word_t sym, void* unused)
{
xp_printf (XP_TEXT("%lu [%s]\n"), (unsigned long)sym, &XP_STX_CHARAT(stx,sym,0));
xp_printf (XP_TEXT("%lu [%s]\n"), (unsigned long)sym, XP_STX_DATA(stx,sym));
}
void print_symbol_names_2 (xp_stx_t* stx, xp_word_t idx, void* unused)
{
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
xp_word_t key = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_KEY);
xp_word_t value = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_VALUE);
xp_printf (XP_TEXT("%lu [%s] %lu\n"),
(unsigned long)key, &XP_STX_CHARAT(stx,key,0), (unsigned long)value);
(unsigned long)key, XP_STX_DATA(stx,key), (unsigned long)value);
}
void print_superclasses (xp_stx_t* stx, const xp_char_t* name)
@ -119,7 +119,7 @@ void print_subclass_names (xp_stx_t* stx, xp_word_t class, int tabs)
xp_word_t count = XP_STX_SIZE(stx, obj->subclasses);
while (count-- > 0) {
print_subclass_names (stx,
XP_STX_WORDAT(stx,obj->subclasses,count), tabs + 1);
XP_STX_WORD_AT(stx,obj->subclasses,count), tabs + 1);
}
}
}
@ -170,7 +170,7 @@ int xp_main (int argc, xp_char_t* argv[])
xp_stx_traverse_symbol_table (&stx, print_symbol_names, XP_NULL);
xp_printf (XP_TEXT("-------------\n"));
xp_stx_hash_traverse (&stx, stx.smalltalk, print_symbol_names_2, XP_NULL);
xp_stx_dict_traverse (&stx, stx.smalltalk, print_symbol_names_2, XP_NULL);
xp_printf (XP_TEXT("-------------\n"));
print_superclasses (&stx, XP_TEXT("Array"));