*** empty log message ***
This commit is contained in:
parent
5dd3db8cc5
commit
7f4e65d422
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* $Id: hash.c,v 1.6 2005-05-10 15:15:57 bacon Exp $
|
||||
* $Id: hash.c,v 1.7 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/stx/hash.h>
|
||||
#include <xp/stx/object.h>
|
||||
#include <xp/bas/assert.h>
|
||||
|
||||
xp_stx_word_t xp_stx_new_link (
|
||||
xp_stx_word_t xp_stx_new_symbol_link (
|
||||
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
|
||||
{
|
||||
xp_stx_word_t x;
|
||||
|
||||
x = xp_stx_alloc_object (stx, 3);
|
||||
XP_STX_CLASS(stx,x) = stx->class_link;
|
||||
XP_STX_AT(stx,x,0) = key;
|
||||
XP_STX_AT(stx,x,1) = value;
|
||||
/* XP_STX_AT(stx,x,2) = stx->nil; */
|
||||
XP_STX_CLASS(stx,x) = stx->class_symbol_link;
|
||||
/* XP_STX_AT(stx,x,0) = stx->nil; */
|
||||
XP_STX_AT(stx,x,1) = key;
|
||||
XP_STX_AT(stx,x,2) = value;
|
||||
|
||||
return x;
|
||||
}
|
||||
@ -52,18 +52,20 @@ void xp_stx_hash_insert (
|
||||
link = XP_STX_AT(stx,table,hash);
|
||||
|
||||
if (link == stx->nil) {
|
||||
XP_STX_AT(stx,table,hash) = xp_stx_new_link (stx, key, value);
|
||||
XP_STX_AT(stx,table,hash) =
|
||||
xp_stx_new_symbol_link (stx, key, value);
|
||||
}
|
||||
else {
|
||||
for (;;) {
|
||||
if (XP_STX_AT(stx,link,0) == key) {
|
||||
XP_STX_AT(stx,link,1) = value;
|
||||
if (XP_STX_AT(stx,link,1) == key) {
|
||||
XP_STX_AT(stx,link,2) = value;
|
||||
break;
|
||||
}
|
||||
|
||||
next = XP_STX_AT(stx,link,2);
|
||||
next = XP_STX_AT(stx,link,0);
|
||||
if (next == stx->nil) {
|
||||
XP_STX_AT(stx,link,2) = xp_stx_new_link (stx, key, value);
|
||||
XP_STX_AT(stx,link,0) =
|
||||
xp_stx_new_symbol_link (stx, key, value);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -71,3 +73,21 @@ void xp_stx_hash_insert (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void xp_stx_hash_traverse (
|
||||
xp_stx_t* stx, xp_stx_word_t table,
|
||||
void (*func) (xp_stx_t*,xp_stx_word_t))
|
||||
{
|
||||
xp_stx_word_t link;
|
||||
xp_stx_word_t size = XP_STX_SIZE(stx,table);
|
||||
|
||||
while (size-- > 0) {
|
||||
link = XP_STX_AT(stx,table,size);
|
||||
|
||||
while (link != stx->nil) {
|
||||
xp_stx_word_t key = XP_STX_AT(stx,link,1);
|
||||
func (stx,link);
|
||||
link = XP_STX_AT(stx,link,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: hash.h,v 1.2 2005-05-10 06:02:19 bacon Exp $
|
||||
* $Id: hash.h,v 1.3 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_STX_HASH_H_
|
||||
@ -11,7 +11,7 @@
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
xp_stx_word_t xp_stx_new_link (
|
||||
xp_stx_word_t xp_stx_new_symbol_link (
|
||||
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value);
|
||||
xp_stx_word_t xp_stx_hash_lookup (
|
||||
xp_stx_t* stx, xp_stx_word_t table,
|
||||
@ -19,6 +19,10 @@ xp_stx_word_t xp_stx_hash_lookup (
|
||||
void xp_stx_hash_insert (
|
||||
xp_stx_t* stx, xp_stx_word_t table,
|
||||
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value);
|
||||
void xp_stx_hash_traverse (
|
||||
xp_stx_t* stx, xp_stx_word_t table,
|
||||
void (*func) (xp_stx_t*,xp_stx_word_t));
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: object.c,v 1.11 2005-05-10 16:20:53 bacon Exp $
|
||||
* $Id: object.c,v 1.12 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/stx/object.h>
|
||||
@ -96,7 +96,7 @@ xp_stx_word_t xp_stx_allocn_string_object (xp_stx_t* stx, ...)
|
||||
n = 0;
|
||||
while ((p = xp_va_arg(ap, const xp_stx_char_t*)) != XP_NULL) {
|
||||
while (*p != XP_STX_CHAR('\0'))
|
||||
XP_STX_CHARAT(stx,idx,n) = *p++;
|
||||
XP_STX_CHARAT(stx,idx,n++) = *p++;
|
||||
}
|
||||
xp_va_end (ap);
|
||||
|
||||
@ -125,11 +125,12 @@ xp_stx_word_t xp_stx_new_symbol (
|
||||
return x;
|
||||
}
|
||||
|
||||
xp_stx_word_t xp_stx_new_symbol_postfix (
|
||||
xp_stx_t* stx, const xp_stx_char_t* name, const xp_char_t* postfix)
|
||||
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;
|
||||
x = xp_stx_allocn_string_object (stx, name, postfix, XP_NULL);
|
||||
x = xp_stx_allocn_string_object (stx, prefix, name, postfix, XP_NULL);
|
||||
XP_STX_CLASS(stx,x) = stx->class_symbol;
|
||||
return x;
|
||||
}
|
||||
@ -147,10 +148,10 @@ xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name)
|
||||
class = xp_stx_alloc_object (stx, XP_STX_CLASS_DIMENSION);
|
||||
XP_STX_CLASS(stx,class) = meta;
|
||||
|
||||
meta_name = xp_stx_new_symbol (stx, name);
|
||||
meta_name = xp_stx_new_symbol_pp (
|
||||
stx, name, XP_STX_TEXT(""), XP_STX_TEXT(" class"));
|
||||
XP_STX_AT(stx,meta,XP_STX_CLASS_NAME) = meta_name;
|
||||
class_name = xp_stx_new_symbol_postfix (
|
||||
stx, name, XP_STX_TEXT("Meta"));
|
||||
class_name = xp_stx_new_symbol (stx, name);
|
||||
XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name;
|
||||
|
||||
xp_stx_hash_insert (stx, stx->symbol_table,
|
||||
@ -158,7 +159,7 @@ xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name)
|
||||
meta_name, meta);
|
||||
xp_stx_hash_insert (stx, stx->symbol_table,
|
||||
xp_stx_hash_string_object(stx, class_name),
|
||||
meta_name, class);
|
||||
class_name, class);
|
||||
|
||||
return class;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: object.h,v 1.9 2005-05-10 16:20:53 bacon Exp $
|
||||
* $Id: object.h,v 1.10 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_STX_OBJECT_H_
|
||||
@ -36,8 +36,9 @@ xp_stx_word_t xp_stx_hash_string_object (xp_stx_t* stx, xp_stx_word_t idx);
|
||||
|
||||
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_postfix (
|
||||
xp_stx_t* stx, const xp_stx_char_t* name, const xp_stx_char_t* postfix);
|
||||
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 xp_stx_new_class (
|
||||
xp_stx_t* stx, const xp_stx_char_t* name);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: stx.c,v 1.10 2005-05-10 16:20:53 bacon Exp $
|
||||
* $Id: stx.c,v 1.11 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <xp/stx/stx.h>
|
||||
@ -30,7 +30,7 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
|
||||
stx->symbol_table = XP_STX_NIL;
|
||||
stx->class_symbol = XP_STX_NIL;
|
||||
stx->class_metaclass = XP_STX_NIL;
|
||||
stx->class_link = XP_STX_NIL;
|
||||
stx->class_symbol_link = XP_STX_NIL;
|
||||
|
||||
return stx;
|
||||
}
|
||||
@ -41,15 +41,19 @@ void xp_stx_close (xp_stx_t* stx)
|
||||
if (stx->__malloced) xp_free (stx);
|
||||
}
|
||||
|
||||
static void __reset_symbol_link_class (xp_stx_t* stx, xp_stx_word_t idx)
|
||||
{
|
||||
XP_STX_CLASS(stx,idx) = stx->class_symbol_link;
|
||||
}
|
||||
|
||||
int xp_stx_bootstrap (xp_stx_t* stx)
|
||||
{
|
||||
xp_stx_word_t symtab;
|
||||
xp_stx_word_t symtab, symbol_Smalltalk;
|
||||
xp_stx_word_t symbol_nil, symbol_true, symbol_false;
|
||||
xp_stx_word_t symbol_Symbol, symbol_SymbolMeta;
|
||||
xp_stx_word_t symbol_Metaclass, symbol_MetaclassMeta;
|
||||
xp_stx_word_t class_Symbol, class_SymbolMeta;
|
||||
xp_stx_word_t class_Metaclass, class_MetaclassMeta;
|
||||
xp_stx_word_t class_UndefinedObject;
|
||||
|
||||
/* allocate three keyword objects */
|
||||
stx->nil = xp_stx_alloc_object (stx, 0);
|
||||
@ -67,11 +71,11 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
||||
symbol_Symbol =
|
||||
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Symbol"));
|
||||
symbol_SymbolMeta =
|
||||
xp_stx_alloc_string_object(stx,XP_STX_TEXT("SymbolMeta"));
|
||||
xp_stx_alloc_string_object(stx,XP_STX_TEXT("Symbol class"));
|
||||
symbol_Metaclass =
|
||||
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass"));
|
||||
symbol_MetaclassMeta =
|
||||
xp_stx_alloc_string_object(stx, XP_STX_TEXT("MetaclassMeta"));
|
||||
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);
|
||||
@ -87,7 +91,6 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
||||
XP_STX_CLASS(stx,class_Metaclass) = class_MetaclassMeta;
|
||||
XP_STX_CLASS(stx,class_MetaclassMeta) = class_Metaclass;
|
||||
|
||||
|
||||
xp_stx_hash_insert (stx, symtab,
|
||||
xp_stx_hash_string_object(stx, symbol_Symbol),
|
||||
symbol_Symbol, class_Symbol);
|
||||
@ -101,18 +104,28 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
||||
xp_stx_hash_string_object(stx, symbol_MetaclassMeta),
|
||||
symbol_MetaclassMeta, class_MetaclassMeta);
|
||||
|
||||
/* ready to use new_symbol & new_class */
|
||||
/* now ready to use new_symbol & new_class */
|
||||
stx->symbol_table = symtab;
|
||||
stx->class_symbol = class_Symbol;
|
||||
stx->class_metaclass = class_Metaclass;
|
||||
|
||||
/* more initialization for symbol table */
|
||||
stx->class_symbol_link =
|
||||
xp_stx_new_class (stx, XP_STX_TEXT("SymbolLink"));
|
||||
|
||||
xp_stx_hash_traverse (stx, symtab, __reset_symbol_link_class);
|
||||
XP_STX_CLASS(stx,symtab) =
|
||||
xp_stx_new_class (stx, XP_STX_TEXT("Array"));
|
||||
symbol_Smalltalk =
|
||||
xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk"));
|
||||
xp_stx_hash_insert (stx, symtab,
|
||||
xp_stx_hash_string_object(stx, symbol_Smalltalk),
|
||||
symbol_Smalltalk, symtab);
|
||||
|
||||
/* more initialization for nil, true, false */
|
||||
symbol_nil = xp_stx_new_symbol (
|
||||
stx, XP_STX_TEXT("nil"));
|
||||
symbol_true = xp_stx_new_symbol (
|
||||
stx, XP_STX_TEXT("true"));
|
||||
symbol_false = xp_stx_new_symbol (
|
||||
stx, XP_STX_TEXT("false"));
|
||||
symbol_nil = xp_stx_new_symbol (stx, XP_STX_TEXT("nil"));
|
||||
symbol_true = xp_stx_new_symbol (stx, XP_STX_TEXT("true"));
|
||||
symbol_false = xp_stx_new_symbol (stx, XP_STX_TEXT("false"));
|
||||
|
||||
xp_stx_hash_insert (stx, symtab,
|
||||
xp_stx_hash_string_object(stx, symbol_nil),
|
||||
@ -124,45 +137,14 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
||||
xp_stx_hash_string_object(stx, symbol_false),
|
||||
symbol_false, stx->false);
|
||||
|
||||
class_UndefinedObject = xp_stx_new_class (stx, XP_STX_TEXT("UndefinedObject"));
|
||||
|
||||
/*
|
||||
class_Symbol = xp_stx_instantiate_class (XP_STX_TEXT("Symbol"));
|
||||
XP_STX_CLASS(stx,symbol_Symbol) = class_Symbol;
|
||||
XP_STX_CLASS(stx,symbol_Symbol_class) = class_Symbol;
|
||||
|
||||
class_Metaclass = xp_stx_instantiate_class (XP_STX_TEXT("Metaclass"));
|
||||
|
||||
XP_STX_CLASS(stx,class_Symbol) = class_Metaclass;
|
||||
XP_STX_CLASS(stx,class_Metaclass) = class_Metaclass;
|
||||
|
||||
class_UndefinedObject = xp_stx_instantiate_class (XP_STX_TEXT("UndefinedObject"));
|
||||
class_True = xp_stx_instantiate_class (XP_STX_TEXT("True"));
|
||||
class_False = xp_stx_instantiate_class (XP_STX_TEXT("False"));
|
||||
symbol_nil = xp_stx_instantiate_symbol (XP_STX_TEXT("nil"));
|
||||
symbol_true = xp_stx_instantiate_symbol (XP_STX_TEXT("true"));
|
||||
symbol_false = xp_stx_instantiate_symbol (XP_STX_TEXT("false"));
|
||||
|
||||
XP_STX_CLASS(stx,stx->nil) = class_UndefinedObject;
|
||||
XP_STX_CLASS(stx,stx->true) = class_True;
|
||||
XP_STX_CLASS(stx,stx->false) = class_False;
|
||||
|
||||
insert_into_symbol_table (stx, symbol_table, symbol_nil, stx->nil);
|
||||
insert_into_symbol_table (stx, symbol_table, symbol_true, stx->true);
|
||||
insert_into_symbol_table (stx, symbol_table, symbol_false, stx->false);
|
||||
|
||||
class_Link = xp_stx_instantiate_class (XP_STX_TEXT("Link"));
|
||||
|
||||
// TODO here
|
||||
|
||||
class_Array = xp_stx_instantiate_class (XP_STX_TEXT("Array"));
|
||||
class_SymbolTable = xp_stx_instantiate_class (XP_STX_TEXT("SymbolTable"));
|
||||
|
||||
XP_STX_CLASS(stx,hash_table) = class_Array;
|
||||
XP_STX_CLASS(stx,symbol_table) = class_SymbolTable;
|
||||
|
||||
insert_into_symbol_table (stx, symbol_table, symbol_table, symbol_table);
|
||||
XP_STX_CLASS(stx,stx->nil) =
|
||||
xp_stx_new_class (stx, XP_STX_TEXT("UndefinedObject"));
|
||||
XP_STX_CLASS(stx,stx->true) =
|
||||
xp_stx_new_class (stx, XP_STX_TEXT("True"));
|
||||
XP_STX_CLASS(stx,stx->false) =
|
||||
xp_stx_new_class (stx, XP_STX_TEXT("False"));
|
||||
|
||||
/*
|
||||
class_Object = xp_stx_instantiate_class (XP_STX_TEXT("Object"));
|
||||
class_Class = xp_stx_instantiate_class (XP_STX_TEXT("Class"));
|
||||
XP_STX_AT(stx,classOf(class_Object),superClass,class_Class);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: stx.h,v 1.10 2005-05-10 15:15:57 bacon Exp $
|
||||
* $Id: stx.h,v 1.11 2005-05-12 15:25:06 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _XP_STX_STX_H_
|
||||
@ -73,7 +73,7 @@ struct xp_stx_t
|
||||
xp_stx_word_t symbol_table;
|
||||
xp_stx_word_t class_symbol;
|
||||
xp_stx_word_t class_metaclass;
|
||||
xp_stx_word_t class_link;
|
||||
xp_stx_word_t class_symbol_link;
|
||||
xp_bool_t __malloced;
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
#include <xp/stx/memory.h>
|
||||
#include <xp/stx/stx.h>
|
||||
#include <xp/bas/stdio.h>
|
||||
|
||||
#include <xp/stx/hash.h>
|
||||
void print_symbol_names (xp_stx_t* stx, xp_stx_word_t idx)
|
||||
{
|
||||
xp_stx_word_t key = XP_STX_AT(stx,idx,1);
|
||||
xp_printf (XP_TEXT("%s\n"), &XP_STX_CHARAT(stx,key,0));
|
||||
}
|
||||
|
||||
int xp_main ()
|
||||
{
|
||||
xp_stx_t stx;
|
||||
@ -21,6 +28,8 @@ int xp_main ()
|
||||
xp_printf (XP_TEXT("stx.true %d\n"), stx.true);
|
||||
xp_printf (XP_TEXT("stx.false %d\n"), stx.false);
|
||||
|
||||
xp_stx_hash_traverse (&stx, stx.symbol_table, print_symbol_names);
|
||||
|
||||
/*
|
||||
for (i = 0; i < 20; i++) {
|
||||
xp_printf (XP_TEXT("%d, %d\n"),
|
||||
|
Loading…
Reference in New Issue
Block a user