2005-05-17 16:18:56 +00:00
|
|
|
/*
|
2005-07-19 15:52:19 +00:00
|
|
|
* $Id: symbol.c,v 1.18 2005-07-19 15:52:19 bacon Exp $
|
2005-05-17 16:18:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xp/stx/symbol.h>
|
|
|
|
#include <xp/stx/object.h>
|
|
|
|
#include <xp/stx/misc.h>
|
|
|
|
|
2005-07-18 11:53:01 +00:00
|
|
|
xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t symbol)
|
2005-05-17 16:18:56 +00:00
|
|
|
{
|
2005-06-08 16:05:41 +00:00
|
|
|
xp_word_t x;
|
2005-05-17 16:18:56 +00:00
|
|
|
|
2005-07-05 09:02:13 +00:00
|
|
|
x = xp_stx_alloc_word_object(
|
|
|
|
stx, XP_NULL, XP_STX_SYMLINK_SIZE, XP_NULL, 0);
|
2005-05-18 04:01:51 +00:00
|
|
|
XP_STX_CLASS(stx,x) = stx->class_symlink;
|
2005-07-19 12:08:04 +00:00
|
|
|
XP_STX_WORD_AT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil;
|
|
|
|
XP_STX_WORD_AT(stx,x,XP_STX_SYMLINK_SYMBOL) = symbol;
|
2005-05-17 16:18:56 +00:00
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2005-06-08 16:05:41 +00:00
|
|
|
xp_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_char_t* name)
|
2005-05-17 16:18:56 +00:00
|
|
|
{
|
2005-07-17 15:55:01 +00:00
|
|
|
return xp_stx_new_symbolx (stx, name, xp_strlen(name));
|
2005-05-23 14:43:03 +00:00
|
|
|
}
|
|
|
|
|
2005-06-08 16:05:41 +00:00
|
|
|
xp_word_t xp_stx_new_symbolx (
|
|
|
|
xp_stx_t* stx, const xp_char_t* name, xp_word_t len)
|
2005-05-23 14:43:03 +00:00
|
|
|
{
|
2005-06-08 16:05:41 +00:00
|
|
|
xp_word_t x, hash, table, link, next;
|
2005-05-23 14:43:03 +00:00
|
|
|
|
|
|
|
table = stx->symbol_table;
|
2005-07-17 15:55:01 +00:00
|
|
|
hash = xp_stx_strxhash(name,len) % XP_STX_SIZE(stx,table);
|
2005-07-19 12:08:04 +00:00
|
|
|
link = XP_STX_WORD_AT(stx,table,hash);
|
2005-05-23 14:43:03 +00:00
|
|
|
|
|
|
|
if (link == stx->nil) {
|
2005-05-23 15:51:03 +00:00
|
|
|
x = xp_stx_alloc_char_objectx (stx, name, len);
|
2005-05-23 14:43:03 +00:00
|
|
|
XP_STX_CLASS(stx,x) = stx->class_symbol;
|
2005-07-19 12:08:04 +00:00
|
|
|
XP_STX_WORD_AT(stx,table,hash) = xp_stx_new_symlink(stx,x);
|
2005-05-23 14:43:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
do {
|
2005-07-19 12:08:04 +00:00
|
|
|
x = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_SYMBOL);
|
2005-07-19 15:52:19 +00:00
|
|
|
xp_assert (xp_stx_classof(stx,x) == stx->class_symbol);
|
2005-05-23 14:43:03 +00:00
|
|
|
|
2005-07-18 11:53:01 +00:00
|
|
|
if (xp_strxcmp (
|
|
|
|
XP_STX_DATA(stx,x),
|
2005-05-23 14:43:03 +00:00
|
|
|
XP_STX_SIZE(stx,x), name) == 0) return x;
|
|
|
|
|
2005-07-19 12:08:04 +00:00
|
|
|
next = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK);
|
2005-05-23 14:43:03 +00:00
|
|
|
if (next == stx->nil) {
|
2005-05-23 15:51:03 +00:00
|
|
|
x = xp_stx_alloc_char_objectx (stx, name, len);
|
2005-05-23 14:43:03 +00:00
|
|
|
XP_STX_CLASS(stx,x) = stx->class_symbol;
|
2005-07-19 12:08:04 +00:00
|
|
|
XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK) =
|
2005-05-23 14:43:03 +00:00
|
|
|
xp_stx_new_symlink(stx,x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
} while (1);
|
|
|
|
}
|
2005-05-17 16:18:56 +00:00
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2005-05-18 04:01:51 +00:00
|
|
|
void xp_stx_traverse_symbol_table (
|
2005-07-07 07:45:05 +00:00
|
|
|
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_word_t,void*), void* data)
|
2005-05-18 04:01:51 +00:00
|
|
|
{
|
2005-06-08 16:05:41 +00:00
|
|
|
xp_word_t link;
|
|
|
|
xp_word_t size;
|
|
|
|
xp_word_t table;
|
2005-05-18 04:01:51 +00:00
|
|
|
|
|
|
|
table = stx->symbol_table;
|
|
|
|
size = XP_STX_SIZE(stx,table);
|
|
|
|
|
|
|
|
while (size-- > 0) {
|
2005-07-19 12:08:04 +00:00
|
|
|
link = XP_STX_WORD_AT(stx,table,size);
|
2005-05-18 04:01:51 +00:00
|
|
|
|
|
|
|
while (link != stx->nil) {
|
2005-07-19 12:08:04 +00:00
|
|
|
func (stx, XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_SYMBOL), data);
|
|
|
|
link = XP_STX_WORD_AT(stx,link,XP_STX_SYMLINK_LINK);
|
2005-05-18 04:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|