diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index a5f1e5eb..e03d5e8a 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -1,5 +1,5 @@ /* - * $Id: bootstrp.c,v 1.25 2005-07-12 16:16:42 bacon Exp $ + * $Id: bootstrp.c,v 1.26 2005-07-18 11:53:01 bacon Exp $ */ #include @@ -135,6 +135,14 @@ static class_info_t class_info[] = XP_NULL, XP_STX_SPEC_NOT_INDEXABLE }, + { + XP_TEXT("Association"), + XP_TEXT("Magnitude"), + XP_TEXT("key value"), + XP_NULL, + XP_NULL, + XP_STX_SPEC_NOT_INDEXABLE + }, { XP_TEXT("Character"), XP_TEXT("Magnitude"), @@ -271,7 +279,14 @@ 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, diff --git a/ase/stx/dict.c b/ase/stx/dict.c new file mode 100644 index 00000000..7d936128 --- /dev/null +++ b/ase/stx/dict.c @@ -0,0 +1,124 @@ +/* + * $Id: dict.c,v 1.1 2005-07-18 11:53:01 bacon Exp $ + */ + +#include +#include +#include + +xp_word_t xp_stx_new_association ( + xp_stx_t* stx, xp_word_t key, xp_word_t value) +{ + xp_word_t x; + xp_word_t data[2] = { key, value }; + + x = xp_stx_alloc_word_object ( + stx, data, XP_STX_ASSOCIATION_SIZE, XP_NULL, 0); + XP_STX_CLASS(stx,x) = stx->class_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) +{ + xp_word_t link; + xp_stx_pairlink_t* obj; + + 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); + + 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); + */ + + obj = (xp_stx_pairlink_t*)XP_STX_OBJECT(stx,link); + if (obj->key == key) return link; + link = obj->link; + } + + return stx->nil; /* not found */ +} + +xp_word_t xp_stx_hash_lookup_symbol ( + xp_stx_t* stx, xp_word_t table, const xp_char_t* name) +{ + xp_word_t link, hash; + xp_stx_pairlink_t* obj; + xp_stx_char_object_t* tmp; + + 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); + + 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; + } + + return stx->nil; /* not found */ +} + +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 link, next; + + 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); + + if (link == stx->nil) { + XP_STX_WORDAT(stx,table,hash) = + xp_stx_new_pairlink (stx, key, value); + } + 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; + } + } +} + +void xp_stx_hash_traverse ( + xp_stx_t* stx, xp_word_t table, + void (*func) (xp_stx_t*,xp_word_t,void*), void* data) +{ + xp_word_t link; + xp_word_t size = XP_STX_SIZE(stx,table); + + 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); + } + } +} + +#endif diff --git a/ase/stx/dict.h b/ase/stx/dict.h new file mode 100644 index 00000000..aab05d08 --- /dev/null +++ b/ase/stx/dict.h @@ -0,0 +1,48 @@ +/* + * $Id: dict.h,v 1.1 2005-07-18 11:53:01 bacon Exp $ + */ + +#ifndef _XP_STX_DICT_H_ +#define _XP_STX_DICT_H_ + +#include + +#define XP_STX_ASSOCIATION_SIZE 2 +#define XP_STX_ASSOCIATION_KEY 0 +#define XP_STX_ASSOCIATION_VALUE 1 + +struct xp_stx_association_t +{ + xp_stx_objhdr_t header; + xp_word_t key; + xp_word_t value; +}; + +typedef struct xp_stx_association_t xp_stx_association_t; + +#ifdef __cplusplus +extern "C" +#endif + +xp_word_t xp_stx_new_association ( + xp_stx_t* stx, xp_word_t key, xp_word_t value); + +#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 +} +#endif + +#endif diff --git a/ase/stx/hash.h b/ase/stx/hash.h index 857b4b3f..a971be1f 100644 --- a/ase/stx/hash.h +++ b/ase/stx/hash.h @@ -1,5 +1,5 @@ /* - * $Id: hash.h,v 1.10 2005-07-07 07:45:05 bacon Exp $ + * $Id: hash.h,v 1.11 2005-07-18 11:53:01 bacon Exp $ */ #ifndef _XP_STX_HASH_H_ @@ -27,7 +27,7 @@ extern "C" #endif /* hash table manipulation */ -xp_word_t xp_stx_new_plink ( +xp_word_t xp_stx_new_pairlink ( xp_stx_t* stx, xp_word_t key, xp_word_t value); xp_word_t xp_stx_hash_lookup ( xp_stx_t* stx, xp_word_t table, diff --git a/ase/stx/makefile.in b/ase/stx/makefile.in index c6dd0ae3..8cefcc24 100644 --- a/ase/stx/makefile.in +++ b/ase/stx/makefile.in @@ -1,5 +1,5 @@ SRCS = stx.c memory.c object.c symbol.c class.c \ - hash.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c + hash.c dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c OBJS = $(SRCS:.c=.o) OUT = libxpstx.a diff --git a/ase/stx/stx.h b/ase/stx/stx.h index f7f96316..95118586 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.36 2005-07-12 16:16:42 bacon Exp $ + * $Id: stx.h,v 1.37 2005-07-18 11:53:01 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -72,6 +72,7 @@ struct xp_stx_t 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; xp_word_t class_class; diff --git a/ase/stx/symbol.c b/ase/stx/symbol.c index 87ae6c89..44cec826 100644 --- a/ase/stx/symbol.c +++ b/ase/stx/symbol.c @@ -1,12 +1,12 @@ /* - * $Id: symbol.c,v 1.15 2005-07-17 15:55:01 bacon Exp $ + * $Id: symbol.c,v 1.16 2005-07-18 11:53:01 bacon Exp $ */ #include #include #include -xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t sym) +xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t symbol) { xp_word_t x; @@ -14,7 +14,7 @@ xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t sym) 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) = sym; + XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_SYMBOL) = symbol; return x; } @@ -43,8 +43,8 @@ xp_word_t xp_stx_new_symbolx ( x = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_SYMBOL); xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); - if (xp_strxcmp ( - &XP_STX_CHARAT(stx,x,0), + 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); diff --git a/ase/stx/symtab.c b/ase/stx/symtab.c deleted file mode 100644 index cb184938..00000000 --- a/ase/stx/symtab.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * $Id: symtab.c,v 1.1 2005-07-17 16:06:28 bacon Exp $ - */ - -#include -#include - -xp_stx_symtab_t* xp_stx_symtab_open (xp_stx_symtab_t* symtab) -{ - if (symtab == XP_NULL) { - symtab = (xp_stx_symtab_t*) - xp_malloc (xp_sizeof(xp_stx_symtab_t)); - if (symtab == XP_NULL) return -1; - symtab->__malloced = xp_true; - } - else symtab->__malloced = xp_false; - - symtab->data = XP_NULL; - symtab->capacity = 0; - symtab->size = 0; - - return symtab; -} - -void xp_stx_symtab_close (xp_stx_symtab_t* symtab) -{ - if (symtab->data != XP_NULL) xp_free (symtab->data); - if (symtab->__malloced) xp_free (symtab); -} - -int xp_stx_symtab_get (xp_stx_symtab_t* symtab, const xp_char_t* str) -{ -} diff --git a/ase/stx/symtab.h b/ase/stx/symtab.h deleted file mode 100644 index 458fda52..00000000 --- a/ase/stx/symtab.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * $Id: symtab.h,v 1.1 2005-07-17 16:06:28 bacon Exp $ - */ - -#ifndef _XP_STX_SYMTAB_H_ -#define _XP_STX_SYMTAB_H_ - -#include - -struct xp_stx_symtab_t -{ - xp_word_t* data; - xp_word_t capacity; - xp_word_t size; - xp_bool_t __malloced; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -xp_stx_symtab_t* xp_stx_symtab_open (xp_stx_symtab_t* symtab); -void xp_stx_symtab_close (xp_stx_symtab_t* symtab); - -#ifdef __cplusplus -} -#endif - -#endif