*** empty log message ***
This commit is contained in:
parent
2e19ebfe01
commit
e72d32500b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: hash.c,v 1.4 2005-05-10 06:08:57 bacon Exp $
|
* $Id: hash.c,v 1.5 2005-05-10 08:21:10 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/hash.h>
|
#include <xp/stx/hash.h>
|
||||||
@ -25,13 +25,12 @@ xp_stx_word_t xp_stx_hash_lookup (
|
|||||||
xp_stx_t* stx, xp_stx_word_t table,
|
xp_stx_t* stx, xp_stx_word_t table,
|
||||||
xp_stx_word_t hash, xp_stx_word_t key)
|
xp_stx_word_t hash, xp_stx_word_t key)
|
||||||
{
|
{
|
||||||
xp_stx_word_t harr, link;
|
xp_stx_word_t link;
|
||||||
|
|
||||||
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
|
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
|
||||||
|
|
||||||
harr = XP_STX_AT(stx,table,0);
|
|
||||||
hash = hash % XP_STX_SIZE(stx,table);
|
hash = hash % XP_STX_SIZE(stx,table);
|
||||||
link = XP_STX_AT(stx,harr,hash);
|
link = XP_STX_AT(stx,table,hash);
|
||||||
|
|
||||||
while (link != stx->nil) {
|
while (link != stx->nil) {
|
||||||
if (XP_STX_AT(stx,link,0) == key) return link;
|
if (XP_STX_AT(stx,link,0) == key) return link;
|
||||||
@ -45,16 +44,15 @@ void xp_stx_hash_insert (
|
|||||||
xp_stx_t* stx, xp_stx_word_t table,
|
xp_stx_t* stx, xp_stx_word_t table,
|
||||||
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value)
|
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value)
|
||||||
{
|
{
|
||||||
xp_stx_word_t harr, link, next;
|
xp_stx_word_t link, next;
|
||||||
|
|
||||||
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
|
xp_assert (XP_STX_TYPE(stx,table) == XP_STX_INDEXED);
|
||||||
|
|
||||||
harr = XP_STX_AT(stx,table,0);
|
|
||||||
hash = hash % XP_STX_SIZE(stx,table);
|
hash = hash % XP_STX_SIZE(stx,table);
|
||||||
link = XP_STX_AT(stx,harr,hash);
|
link = XP_STX_AT(stx,table,hash);
|
||||||
|
|
||||||
if (link == stx->nil) {
|
if (link == stx->nil) {
|
||||||
XP_STX_AT(stx,harr,hash) = xp_stx_new_link (stx, key, value);
|
XP_STX_AT(stx,table,hash) = xp_stx_new_link (stx, key, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: object.c,v 1.6 2005-05-08 15:22:45 bacon Exp $
|
* $Id: object.c,v 1.7 2005-05-10 08:21:10 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/object.h>
|
#include <xp/stx/object.h>
|
||||||
#include <xp/stx/memory.h>
|
#include <xp/stx/memory.h>
|
||||||
#include <xp/bas/string.h>
|
#include <xp/bas/string.h>
|
||||||
|
#include <xp/bas/assert.h>
|
||||||
|
|
||||||
/* n: number of instance variables */
|
/* n: number of instance variables */
|
||||||
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
|
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
|
||||||
@ -18,8 +19,9 @@ xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
|
|||||||
n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t));
|
n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t));
|
||||||
if (idx >= stx->memory.capacity) return idx; /* failed */
|
if (idx >= stx->memory.capacity) return idx; /* failed */
|
||||||
|
|
||||||
|
xp_assert (stx->nil == XP_STX_NIL);
|
||||||
XP_STX_CLASS(stx,idx) = stx->nil;
|
XP_STX_CLASS(stx,idx) = stx->nil;
|
||||||
XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x00);
|
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_INDEXED;
|
||||||
while (n--) XP_STX_AT(stx,idx,n) = stx->nil;
|
while (n--) XP_STX_AT(stx,idx,n) = stx->nil;
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
@ -34,14 +36,16 @@ xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n)
|
|||||||
&stx->memory, n + xp_sizeof(xp_stx_object_t));
|
&stx->memory, n + xp_sizeof(xp_stx_object_t));
|
||||||
if (idx >= stx->memory.capacity) return idx; /* failed */
|
if (idx >= stx->memory.capacity) return idx; /* failed */
|
||||||
|
|
||||||
|
xp_assert (stx->nil == XP_STX_NIL);
|
||||||
XP_STX_CLASS(stx,idx) = stx->nil;
|
XP_STX_CLASS(stx,idx) = stx->nil;
|
||||||
XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x01);
|
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_BYTE_INDEXED;
|
||||||
while (n--) XP_STX_BYTEAT(stx,idx,n) = 0;
|
while (n--) XP_STX_BYTEAT(stx,idx,n) = 0;
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
xp_stx_word_t xp_stx_alloc_string_object (xp_stx_t* stx, xp_stx_char_t* str)
|
xp_stx_word_t xp_stx_alloc_string_object (
|
||||||
|
xp_stx_t* stx, const xp_stx_char_t* str)
|
||||||
{
|
{
|
||||||
xp_stx_word_t idx, n;
|
xp_stx_word_t idx, n;
|
||||||
|
|
||||||
@ -50,14 +54,40 @@ xp_stx_word_t xp_stx_alloc_string_object (xp_stx_t* stx, xp_stx_char_t* str)
|
|||||||
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
|
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
|
||||||
if (idx >= stx->memory.capacity) return idx; /* failed */
|
if (idx >= stx->memory.capacity) return idx; /* failed */
|
||||||
|
|
||||||
|
xp_assert (stx->nil == XP_STX_NIL);
|
||||||
XP_STX_CLASS(stx,idx) = stx->nil;
|
XP_STX_CLASS(stx,idx) = stx->nil;
|
||||||
XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x02);
|
XP_STX_ACCESS(stx,idx) = (n << 2) | XP_STX_CHAR_INDEXED;
|
||||||
XP_STX_CHARAT(stx,idx,n) = XP_STX_CHAR('\0');
|
XP_STX_CHARAT(stx,idx,n) = XP_STX_CHAR('\0');
|
||||||
while (n--) XP_STX_CHARAT(stx,idx,n) = str[n];
|
while (n--) XP_STX_CHARAT(stx,idx,n) = str[n];
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xp_stx_word_t xp_stx_hash_string_object (xp_stx_t* stx, xp_stx_word_t idx)
|
||||||
|
{
|
||||||
|
xp_stx_word_t nb, h = 0;
|
||||||
|
xp_byte_t* p, * end;
|
||||||
|
|
||||||
|
xp_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED);
|
||||||
|
nb = XP_STX_SIZE(stx,idx) * xp_sizeof(xp_stx_char_t);
|
||||||
|
p = (xp_byte_t*)&XP_STX_AT(stx,idx,0); end = p + nb;
|
||||||
|
|
||||||
|
while (p < end) h = h * 31 + *p++;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, xp_stx_char_t* name)
|
||||||
|
{
|
||||||
|
xp_stx_word_t x;
|
||||||
|
|
||||||
|
x = xp_stx_alloc_string_object (stx, name);
|
||||||
|
XP_STX_CLASS(&stx,x) = stx->class_string;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
struct class_info_t
|
struct class_info_t
|
||||||
{
|
{
|
||||||
const xp_stx_char_t* name;
|
const xp_stx_char_t* name;
|
||||||
@ -71,14 +101,10 @@ class_info_t class_info[] =
|
|||||||
{ XP_STX_TEXT("Metaclass"), 5 },
|
{ XP_STX_TEXT("Metaclass"), 5 },
|
||||||
{ XP_NULL, 0 }
|
{ XP_NULL, 0 }
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
xp_stx_word_t xp_stx_instantiate_symbol (xp_stx_t* stx, xp_stx_char_t* name)
|
|
||||||
{
|
|
||||||
xp_stx_word_t x;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
xp_stx_word_t xp_stx_instantiate_class (xp_stx_t* stx, xp_stx_char_t* name)
|
xp_stx_word_t xp_stx_instantiate_class (xp_stx_t* stx, xp_stx_char_t* name)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: object.h,v 1.4 2005-05-08 15:22:45 bacon Exp $
|
* $Id: object.h,v 1.5 2005-05-10 08:21:10 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_STX_OBJECT_H_
|
#ifndef _XP_STX_OBJECT_H_
|
||||||
@ -17,7 +17,10 @@ extern "C" {
|
|||||||
|
|
||||||
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n);
|
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n);
|
||||||
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n);
|
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n);
|
||||||
xp_stx_word_t xp_stx_alloc_string_object (xp_stx_t* stx, xp_stx_char_t* str);
|
xp_stx_word_t xp_stx_alloc_string_object (
|
||||||
|
xp_stx_t* stx, const xp_stx_char_t* str);
|
||||||
|
|
||||||
|
xp_stx_word_t xp_stx_hash_string_object (xp_stx_t* stx, xp_stx_word_t idx);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: stx.c,v 1.6 2005-05-10 06:08:57 bacon Exp $
|
* $Id: stx.c,v 1.7 2005-05-10 08:21:10 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/stx.h>
|
#include <xp/stx/stx.h>
|
||||||
@ -40,11 +40,13 @@ void xp_stx_close (xp_stx_t* stx)
|
|||||||
|
|
||||||
int xp_stx_bootstrap (xp_stx_t* stx)
|
int xp_stx_bootstrap (xp_stx_t* stx)
|
||||||
{
|
{
|
||||||
xp_stx_word_t hash_table, symbol_table;
|
xp_stx_word_t symtab;
|
||||||
xp_stx_word_t symbol_Symbol, symbol_Symbol_class;
|
xp_stx_word_t symbol_Symbol, symbol_SymbolMeta;
|
||||||
xp_stx_word_t class_Symbol, class_Metaclass;
|
xp_stx_word_t symbol_Metaclass, symbol_MetaclassMeta;
|
||||||
xp_stx_word_t class_UndefinedObject;
|
xp_stx_word_t class_Symbol, class_SymbolMeta;
|
||||||
|
xp_stx_word_t class_Metaclass, class_MetaclassMeta;
|
||||||
|
|
||||||
|
/* allocate three keyword objects */
|
||||||
stx->nil = xp_stx_alloc_object (stx, 0);
|
stx->nil = xp_stx_alloc_object (stx, 0);
|
||||||
stx->true = xp_stx_alloc_object (stx, 0);
|
stx->true = xp_stx_alloc_object (stx, 0);
|
||||||
stx->false = xp_stx_alloc_object (stx, 0);
|
stx->false = xp_stx_alloc_object (stx, 0);
|
||||||
@ -53,13 +55,36 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
|||||||
xp_assert (stx->true == XP_STX_TRUE);
|
xp_assert (stx->true == XP_STX_TRUE);
|
||||||
xp_assert (stx->false == XP_STX_FALSE);
|
xp_assert (stx->false == XP_STX_FALSE);
|
||||||
|
|
||||||
/* TODO: decide the size of this hash table */
|
/* build a symbol table */ // TODO: symbol table size
|
||||||
hash_table = xp_stx_alloc_object (stx, 1000);
|
symtab = xp_stx_alloc_object (stx, 1000);
|
||||||
symbol_table = xp_stx_alloc_object (stx, 1);
|
|
||||||
XP_STX_AT(stx,symbol_table,0) = hash_table;
|
|
||||||
|
|
||||||
symbol_Symbol = xp_stx_instantiate_symbol (XP_STX_TEXT("Symbol"));
|
/* tweak the initial object structure */
|
||||||
symbol_Symbol_class = xp_stx_instantiate_symbol (XP_STX_TEXT("Symbol class"));
|
symbol_Symbol =
|
||||||
|
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Symbol"));
|
||||||
|
symbol_SymbolMeta =
|
||||||
|
xp_stx_alloc_string_object(stx,XP_STX_TEXT("SymbolMeta"));
|
||||||
|
symbol_Metaclass =
|
||||||
|
xp_stx_alloc_string_object(stx, XP_STX_TEXT("Metaclass"));
|
||||||
|
symbol_MetaclassMeta =
|
||||||
|
xp_stx_alloc_string_object(stx, XP_STX_TEXT("MetaclassMeta"));
|
||||||
|
|
||||||
|
// TODO: class size: maybe other than 5?
|
||||||
|
class_Metaclass = xp_stx_alloc_object(stx, 5);
|
||||||
|
class_MetaclassMeta = xp_stx_alloc_object(stx, 5);
|
||||||
|
class_Symbol = xp_stx_alloc_object(stx, 5);
|
||||||
|
class_SymbolMeta = xp_stx_alloc_object(stx, 5);
|
||||||
|
|
||||||
|
XP_STX_CLASS(stx,symbol_Symbol) = class_Symbol;
|
||||||
|
XP_STX_CLASS(stx,symbol_SymbolMeta) = class_Symbol;
|
||||||
|
XP_STX_CLASS(stx,symbol_Metaclass) = class_Symbol;
|
||||||
|
XP_STX_CLASS(stx,symbol_MetaclassMeta) = class_Symbol;
|
||||||
|
|
||||||
|
XP_STX_CLASS(stx,class_Symbol) = class_SymbolMeta;
|
||||||
|
XP_STX_CLASS(stx,class_SymbolMeta) = class_Metaclass;
|
||||||
|
XP_STX_CLASS(stx,class_Metaclass) = class_MetaclassMeta;
|
||||||
|
XP_STX_CLASS(stx,class_MetaclassMeta) = class_Metaclass;
|
||||||
|
|
||||||
|
/*
|
||||||
class_Symbol = xp_stx_instantiate_class (XP_STX_TEXT("Symbol"));
|
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_Symbol;
|
||||||
XP_STX_CLASS(stx,symbol_Symbol_class) = class_Symbol;
|
XP_STX_CLASS(stx,symbol_Symbol_class) = class_Symbol;
|
||||||
@ -85,9 +110,8 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
|||||||
insert_into_symbol_table (stx, symbol_table, symbol_false, stx->false);
|
insert_into_symbol_table (stx, symbol_table, symbol_false, stx->false);
|
||||||
|
|
||||||
class_Link = xp_stx_instantiate_class (XP_STX_TEXT("Link"));
|
class_Link = xp_stx_instantiate_class (XP_STX_TEXT("Link"));
|
||||||
/*
|
|
||||||
TODO here
|
// TODO here
|
||||||
*/
|
|
||||||
|
|
||||||
class_Array = xp_stx_instantiate_class (XP_STX_TEXT("Array"));
|
class_Array = xp_stx_instantiate_class (XP_STX_TEXT("Array"));
|
||||||
class_SymbolTable = xp_stx_instantiate_class (XP_STX_TEXT("SymbolTable"));
|
class_SymbolTable = xp_stx_instantiate_class (XP_STX_TEXT("SymbolTable"));
|
||||||
@ -100,6 +124,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
|
|||||||
class_Object = xp_stx_instantiate_class (XP_STX_TEXT("Object"));
|
class_Object = xp_stx_instantiate_class (XP_STX_TEXT("Object"));
|
||||||
class_Class = xp_stx_instantiate_class (XP_STX_TEXT("Class"));
|
class_Class = xp_stx_instantiate_class (XP_STX_TEXT("Class"));
|
||||||
XP_STX_AT(stx,classOf(class_Object),superClass,class_Class);
|
XP_STX_AT(stx,classOf(class_Object),superClass,class_Class);
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ int xp_main ()
|
|||||||
xp_stx_t stx;
|
xp_stx_t stx;
|
||||||
xp_stx_word_t i;
|
xp_stx_word_t i;
|
||||||
|
|
||||||
if (xp_stx_open (&stx, 10) == XP_NULL) {
|
if (xp_stx_open (&stx, 10000) == XP_NULL) {
|
||||||
xp_printf (XP_TEXT("cannot open stx\n"));
|
xp_printf (XP_TEXT("cannot open stx\n"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -21,6 +21,7 @@ int xp_main ()
|
|||||||
xp_printf (XP_TEXT("stx.true %d\n"), stx.true);
|
xp_printf (XP_TEXT("stx.true %d\n"), stx.true);
|
||||||
xp_printf (XP_TEXT("stx.false %d\n"), stx.false);
|
xp_printf (XP_TEXT("stx.false %d\n"), stx.false);
|
||||||
|
|
||||||
|
/*
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
xp_printf (XP_TEXT("%d, %d\n"),
|
xp_printf (XP_TEXT("%d, %d\n"),
|
||||||
i, xp_stx_memory_alloc(&stx.memory, 100));
|
i, xp_stx_memory_alloc(&stx.memory, 100));
|
||||||
@ -34,7 +35,7 @@ int xp_main ()
|
|||||||
xp_printf (XP_TEXT("%d, %d\n"),
|
xp_printf (XP_TEXT("%d, %d\n"),
|
||||||
i, xp_stx_memory_alloc(&stx.memory, 100));
|
i, xp_stx_memory_alloc(&stx.memory, 100));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
xp_stx_close (&stx);
|
xp_stx_close (&stx);
|
||||||
xp_printf (XP_TEXT("End of program\n"));
|
xp_printf (XP_TEXT("End of program\n"));
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user