*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-17 16:18:56 +00:00
parent 7b8ab3b36e
commit 40de9dfb00
7 changed files with 252 additions and 39 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: hash.c,v 1.10 2005-05-16 14:14:34 bacon Exp $ * $Id: hash.c,v 1.11 2005-05-17 16:18:56 bacon Exp $
*/ */
#include <xp/stx/hash.h> #include <xp/stx/hash.h>
@ -7,21 +7,21 @@
#include <xp/stx/misc.h> #include <xp/stx/misc.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
#define _SYMBOL_LINK_DIMENSION 3 #define PLINK_DIMENSION 3
#define _SYMBOL_LINK_LINK 0 #define PLINK_LINK 0
#define _SYMBOL_LINK_KEY 1 #define PLINK_KEY 1
#define _SYMBOL_LINK_VALUE 2 #define PLINK_VALUE 2
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_t* stx, xp_stx_word_t key, xp_stx_word_t value)
{ {
xp_stx_word_t x; xp_stx_word_t x;
x = xp_stx_alloc_object (stx, _SYMBOL_LINK_DIMENSION); x = xp_stx_alloc_object (stx, PLINK_DIMENSION);
XP_STX_CLASS(stx,x) = stx->class_symbol_link; XP_STX_CLASS(stx,x) = stx->class_symbol_plink;
/* XP_STX_AT(stx,x,_SYMBOL_LINK_LINK) = stx->nil; */ /* XP_STX_AT(stx,x,PLINK_LINK) = stx->nil; */
XP_STX_AT(stx,x,_SYMBOL_LINK_KEY) = key; XP_STX_AT(stx,x,PLINK_KEY) = key;
XP_STX_AT(stx,x,_SYMBOL_LINK_VALUE) = value; XP_STX_AT(stx,x,PLINK_VALUE) = value;
return x; return x;
} }
@ -39,8 +39,8 @@ xp_stx_word_t xp_stx_hash_lookup (
link = XP_STX_AT(stx,table,hash); link = XP_STX_AT(stx,table,hash);
while (link != stx->nil) { while (link != stx->nil) {
if (XP_STX_AT(stx,link,_SYMBOL_LINK_KEY) == key) return link; if (XP_STX_AT(stx,link,PLINK_KEY) == key) return link;
link = XP_STX_AT(stx,link,_SYMBOL_LINK_LINK); link = XP_STX_AT(stx,link,PLINK_LINK);
} }
return stx->nil; /* not found */ return stx->nil; /* not found */
@ -58,7 +58,7 @@ xp_stx_word_t xp_stx_hash_lookup_symbol (
link = XP_STX_AT(stx,table,hash); link = XP_STX_AT(stx,table,hash);
while (link != stx->nil) { while (link != stx->nil) {
key = XP_STX_AT(stx,link,_SYMBOL_LINK_KEY); key = XP_STX_AT(stx,link,PLINK_KEY);
if (XP_STX_CLASS(stx,key) == stx->class_symbol && if (XP_STX_CLASS(stx,key) == stx->class_symbol &&
xp_stx_strxcmp ( xp_stx_strxcmp (
@ -66,7 +66,7 @@ xp_stx_word_t xp_stx_hash_lookup_symbol (
XP_STX_SIZE(stx,key), key_str) == 0) { XP_STX_SIZE(stx,key), key_str) == 0) {
return link; return link;
} }
link = XP_STX_AT(stx,link,_SYMBOL_LINK_LINK); link = XP_STX_AT(stx,link,PLINK_LINK);
} }
return stx->nil; /* not found */ return stx->nil; /* not found */
@ -85,19 +85,19 @@ void xp_stx_hash_insert (
if (link == stx->nil) { if (link == stx->nil) {
XP_STX_AT(stx,table,hash) = XP_STX_AT(stx,table,hash) =
xp_stx_new_symbol_link (stx, key, value); xp_stx_new_plink (stx, key, value);
} }
else { else {
for (;;) { for (;;) {
if (XP_STX_AT(stx,link,1) == key) { if (XP_STX_AT(stx,link,1) == key) {
XP_STX_AT(stx,link,_SYMBOL_LINK_VALUE) = value; XP_STX_AT(stx,link,PLINK_VALUE) = value;
break; break;
} }
next = XP_STX_AT(stx,link,_SYMBOL_LINK_LINK); next = XP_STX_AT(stx,link,PLINK_LINK);
if (next == stx->nil) { if (next == stx->nil) {
XP_STX_AT(stx,link,_SYMBOL_LINK_LINK) = XP_STX_AT(stx,link,PLINK_LINK) =
xp_stx_new_symbol_link (stx, key, value); xp_stx_new_plink (stx, key, value);
break; break;
} }
@ -118,12 +118,13 @@ void xp_stx_hash_traverse (
while (link != stx->nil) { while (link != stx->nil) {
func (stx,link); func (stx,link);
link = XP_STX_AT(stx,link,_SYMBOL_LINK_LINK); link = XP_STX_AT(stx,link,PLINK_LINK);
} }
} }
} }
/*
xp_stx_word_t xp_stx_new_symbol ( xp_stx_word_t xp_stx_new_symbol (
xp_stx_t* stx, const xp_stx_char_t* name) xp_stx_t* stx, const xp_stx_char_t* name)
{ {
@ -136,7 +137,7 @@ xp_stx_word_t xp_stx_new_symbol (
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil); xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil);
} }
else x = XP_STX_AT(stx,x,_SYMBOL_LINK_KEY); else x = XP_STX_AT(stx,x,PLINK_KEY);
return x; return x;
} }
@ -155,8 +156,8 @@ xp_stx_word_t xp_stx_new_symbol_pp (
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil); xp_stx_hash_insert (stx, stx->symbol_table, hash, x, stx->nil);
} }
else x = XP_STX_AT(stx,x,_SYMBOL_LINK_KEY); else x = XP_STX_AT(stx,x,PLINK_KEY);
return x; return x;
} }
*/

View File

@ -1,5 +1,5 @@
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 = stx.obj memory.obj object.obj hash.obj misc.obj context.obj OBJS = stx.obj memory.obj object.obj symbol.obj hash.obj misc.obj context.obj
OUT = xpstx.lib OUT = xpstx.lib
CC = lcc CC = lcc

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.c,v 1.13 2005-05-15 18:37:00 bacon Exp $ * $Id: object.c,v 1.14 2005-05-17 16:18:56 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
@ -123,10 +123,10 @@ xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name)
class_name = xp_stx_new_symbol (stx, name); class_name = xp_stx_new_symbol (stx, name);
XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name; XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name;
xp_stx_hash_insert (stx, stx->symbol_table, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, meta_name), xp_stx_hash_string_object(stx, meta_name),
meta_name, meta); meta_name, meta);
xp_stx_hash_insert (stx, stx->symbol_table, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, class_name), xp_stx_hash_string_object(stx, class_name),
class_name, class); class_name, class);

View File

@ -1,11 +1,12 @@
/* /*
* $Id: stx.c,v 1.14 2005-05-16 16:41:47 bacon Exp $ * $Id: stx.c,v 1.15 2005-05-17 16:18:56 bacon Exp $
*/ */
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
#include <xp/stx/memory.h> #include <xp/stx/memory.h>
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/hash.h> #include <xp/stx/hash.h>
#include <xp/stx/symbol.h>
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
@ -28,9 +29,12 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
stx->false = XP_STX_FALSE; stx->false = XP_STX_FALSE;
stx->symbol_table = XP_STX_NIL; stx->symbol_table = XP_STX_NIL;
stx->smalltalk = XP_STX_NIL;
stx->class_symbol_link = XP_STX_NIL;
stx->class_symbol = XP_STX_NIL; stx->class_symbol = XP_STX_NIL;
stx->class_metaclass = XP_STX_NIL; stx->class_metaclass = XP_STX_NIL;
stx->class_symbol_link = XP_STX_NIL;
stx->class_method = XP_STX_NIL; stx->class_method = XP_STX_NIL;
stx->class_context = XP_STX_NIL; stx->class_context = XP_STX_NIL;
@ -70,9 +74,84 @@ int xp_stx_bootstrap (xp_stx_t* stx)
xp_assert (stx->false == XP_STX_FALSE); xp_assert (stx->false == XP_STX_FALSE);
/* build a symbol table */ // TODO: symbol table size /* build a symbol table */ // TODO: symbol table size
symtab = xp_stx_alloc_object (stx, 1000); stx->symbol_table = xp_stx_alloc_object (stx, 1000);
/* 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);
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;
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 */ /* 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 = symbol_Symbol =
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Symbol")); xp_stx_alloc_string_object(stx, XP_STX_TEXT("Symbol"));
symbol_SymbolMeta = symbol_SymbolMeta =
@ -82,11 +161,6 @@ int xp_stx_bootstrap (xp_stx_t* stx)
symbol_MetaclassMeta = symbol_MetaclassMeta =
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass class")); xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass class"));
class_Metaclass = xp_stx_alloc_object(stx, XP_STX_CLASS_SIZE);
class_MetaclassMeta = xp_stx_alloc_object(stx, XP_STX_CLASS_SIZE);
class_Symbol = xp_stx_alloc_object(stx, XP_STX_CLASS_SIZE);
class_SymbolMeta = xp_stx_alloc_object(stx, XP_STX_CLASS_SIZE);
XP_STX_CLASS(stx,symbol_SymbolMeta) = class_Symbol; XP_STX_CLASS(stx,symbol_SymbolMeta) = class_Symbol;
XP_STX_CLASS(stx,symbol_Metaclass) = class_Symbol; XP_STX_CLASS(stx,symbol_Metaclass) = class_Symbol;
XP_STX_CLASS(stx,symbol_MetaclassMeta) = class_Symbol; XP_STX_CLASS(stx,symbol_MetaclassMeta) = class_Symbol;
@ -95,7 +169,9 @@ int xp_stx_bootstrap (xp_stx_t* stx)
XP_STX_CLASS(stx,class_SymbolMeta) = class_Metaclass; XP_STX_CLASS(stx,class_SymbolMeta) = class_Metaclass;
XP_STX_CLASS(stx,class_Metaclass) = class_MetaclassMeta; XP_STX_CLASS(stx,class_Metaclass) = class_MetaclassMeta;
XP_STX_CLASS(stx,class_MetaclassMeta) = class_Metaclass; XP_STX_CLASS(stx,class_MetaclassMeta) = class_Metaclass;
*/
/*
xp_stx_hash_insert (stx, symtab, xp_stx_hash_insert (stx, symtab,
xp_stx_hash_string_object(stx, symbol_Symbol), xp_stx_hash_string_object(stx, symbol_Symbol),
symbol_Symbol, class_Symbol); symbol_Symbol, class_Symbol);
@ -108,13 +184,17 @@ int xp_stx_bootstrap (xp_stx_t* stx)
xp_stx_hash_insert (stx, symtab, xp_stx_hash_insert (stx, symtab,
xp_stx_hash_string_object(stx, symbol_MetaclassMeta), xp_stx_hash_string_object(stx, symbol_MetaclassMeta),
symbol_MetaclassMeta, class_MetaclassMeta); symbol_MetaclassMeta, class_MetaclassMeta);
*/
/* now ready to use new_symbol & new_class */ /* now ready to use new_symbol & new_class */
/*
stx->symbol_table = symtab; stx->symbol_table = symtab;
stx->class_symbol = class_Symbol; stx->class_symbol = class_Symbol;
stx->class_metaclass = class_Metaclass; stx->class_metaclass = class_Metaclass;
*/
/* more initialization for symbol table */ /* more initialization for symbol table */
/*
stx->class_symbol_link = stx->class_symbol_link =
xp_stx_new_class (stx, XP_STX_TEXT("SymbolLink")); xp_stx_new_class (stx, XP_STX_TEXT("SymbolLink"));
@ -126,6 +206,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
xp_stx_hash_insert (stx, symtab, xp_stx_hash_insert (stx, symtab,
xp_stx_hash_string_object(stx, symbol_Smalltalk), xp_stx_hash_string_object(stx, symbol_Smalltalk),
symbol_Smalltalk, symtab); symbol_Smalltalk, symtab);
*/
/* more initialization for nil, true, false */ /* more initialization for nil, true, false */
/* /*

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.h,v 1.12 2005-05-15 18:37:00 bacon Exp $ * $Id: stx.h,v 1.13 2005-05-17 16:18:56 bacon Exp $
*/ */
#ifndef _XP_STX_STX_H_ #ifndef _XP_STX_STX_H_
@ -71,9 +71,12 @@ struct xp_stx_t
xp_stx_word_t false; xp_stx_word_t false;
xp_stx_word_t symbol_table; xp_stx_word_t symbol_table;
xp_stx_word_t smalltalk;
xp_stx_word_t class_symbol_link;
xp_stx_word_t class_symbol; xp_stx_word_t class_symbol;
xp_stx_word_t class_metaclass; xp_stx_word_t class_metaclass;
xp_stx_word_t class_symbol_link;
xp_stx_word_t class_method; xp_stx_word_t class_method;
xp_stx_word_t class_context; xp_stx_word_t class_context;

104
ase/stx/symbol.c Normal file
View File

@ -0,0 +1,104 @@
/*
* $Id: symbol.c,v 1.1 2005-05-17 16:18:56 bacon Exp $
*/
#include <xp/stx/symbol.h>
#include <xp/stx/object.h>
#include <xp/stx/misc.h>
#include <xp/bas/assert.h>
#define SYMBOL_LINK_DIMENSION 2
#define SYMBOL_LINK_LINK 0
#define SYMBOL_LINK_SYMBOL 1
xp_stx_word_t xp_stx_new_symbol_link (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;
return x;
}
xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name)
{
xp_stx_word_t x, hash, table, link, next;
table = stx->symbol_table;
hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,table,hash);
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);
}
else {
do {
x = XP_STX_AT(stx,link,SYMBOL_LINK_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);
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);
break;
}
link = next;
} while (1);
}
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, table, link, next;
table = stx->symbol_table;
hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,table,hash);
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);
}
else {
do {
x = XP_STX_AT(stx,link,SYMBOL_LINK_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);
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);
break;
}
link = next;
} while (1);
}
return x;
}

24
ase/stx/symbol.h Normal file
View File

@ -0,0 +1,24 @@
/*
* $Id: symbol.h,v 1.1 2005-05-17 16:18:56 bacon Exp $
*/
#ifndef _XP_STX_SYMBOL_H_
#define _XP_STX_SYMBOL_H_
#include <xp/stx/stx.h>
#ifdef __cplusplus
extern "C" {
#endif
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_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
#endif