*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-18 11:53:01 +00:00
parent 969cd186f6
commit 1b7d49266a
9 changed files with 199 additions and 73 deletions

View File

@ -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 <xp/stx/bootstrp.h> #include <xp/stx/bootstrp.h>
@ -135,6 +135,14 @@ static class_info_t class_info[] =
XP_NULL, XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE 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("Character"),
XP_TEXT("Magnitude"), XP_TEXT("Magnitude"),
@ -271,7 +279,14 @@ static class_info_t class_info[] =
XP_NULL, XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE 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,
XP_NULL, XP_NULL,

124
ase/stx/dict.c Normal file
View File

@ -0,0 +1,124 @@
/*
* $Id: dict.c,v 1.1 2005-07-18 11:53:01 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_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

48
ase/stx/dict.h Normal file
View File

@ -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 <xp/stx/stx.h>
#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

View File

@ -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_ #ifndef _XP_STX_HASH_H_
@ -27,7 +27,7 @@ extern "C"
#endif #endif
/* hash table manipulation */ /* 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_stx_t* stx, xp_word_t key, xp_word_t value);
xp_word_t xp_stx_hash_lookup ( xp_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_word_t table, xp_stx_t* stx, xp_word_t table,

View File

@ -1,5 +1,5 @@
SRCS = stx.c memory.c object.c symbol.c class.c \ 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) OBJS = $(SRCS:.c=.o)
OUT = libxpstx.a OUT = libxpstx.a

View File

@ -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_ #ifndef _XP_STX_STX_H_
@ -72,6 +72,7 @@ struct xp_stx_t
xp_word_t class_symbol; xp_word_t class_symbol;
xp_word_t class_metaclass; xp_word_t class_metaclass;
xp_word_t class_pairlink; xp_word_t class_pairlink;
xp_word_t class_association;
xp_word_t class_object; xp_word_t class_object;
xp_word_t class_class; xp_word_t class_class;

View File

@ -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 <xp/stx/symbol.h> #include <xp/stx/symbol.h>
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/misc.h> #include <xp/stx/misc.h>
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; 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); stx, XP_NULL, XP_STX_SYMLINK_SIZE, XP_NULL, 0);
XP_STX_CLASS(stx,x) = stx->class_symlink; 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_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; return x;
} }
@ -44,7 +44,7 @@ xp_word_t xp_stx_new_symbolx (
xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); xp_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_strxcmp ( if (xp_strxcmp (
&XP_STX_CHARAT(stx,x,0), XP_STX_DATA(stx,x),
XP_STX_SIZE(stx,x), name) == 0) return x; XP_STX_SIZE(stx,x), name) == 0) return x;
next = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK); next = XP_STX_WORDAT(stx,link,XP_STX_SYMLINK_LINK);

View File

@ -1,33 +0,0 @@
/*
* $Id: symtab.c,v 1.1 2005-07-17 16:06:28 bacon Exp $
*/
#include <xp/stx/symtab.h>
#include <xp/bas/memory.h>
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)
{
}

View File

@ -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 <xp/stx/stx.h>
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