2005-05-08 07:39:51 +00:00
|
|
|
/*
|
2005-05-10 06:08:57 +00:00
|
|
|
* $Id: stx.c,v 1.6 2005-05-10 06:08:57 bacon Exp $
|
2005-05-08 07:39:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xp/stx/stx.h>
|
|
|
|
#include <xp/stx/memory.h>
|
2005-05-08 15:22:45 +00:00
|
|
|
#include <xp/stx/object.h>
|
2005-05-08 07:39:51 +00:00
|
|
|
#include <xp/bas/memory.h>
|
2005-05-08 10:44:58 +00:00
|
|
|
#include <xp/bas/assert.h>
|
2005-05-08 07:39:51 +00:00
|
|
|
|
|
|
|
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
|
|
|
|
{
|
|
|
|
if (stx == XP_NULL) {
|
|
|
|
stx = (xp_stx_t*) xp_malloc (xp_sizeof(stx));
|
|
|
|
if (stx == XP_NULL) return XP_NULL;
|
|
|
|
stx->__malloced = xp_true;
|
|
|
|
}
|
|
|
|
else stx->__malloced = xp_false;
|
|
|
|
|
|
|
|
if (xp_stx_memory_open (&stx->memory, capacity) == XP_NULL) {
|
|
|
|
if (stx->__malloced) xp_free (stx);
|
|
|
|
return XP_NULL;
|
|
|
|
}
|
|
|
|
|
2005-05-08 10:31:25 +00:00
|
|
|
stx->nil = XP_STX_NIL;
|
|
|
|
stx->true = XP_STX_TRUE;
|
|
|
|
stx->false = XP_STX_FALSE;
|
|
|
|
|
2005-05-10 06:08:57 +00:00
|
|
|
stx->link_class = XP_STX_NIL;
|
|
|
|
stx->symbol_table = XP_STX_NIL;
|
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
return stx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xp_stx_close (xp_stx_t* stx)
|
|
|
|
{
|
|
|
|
xp_stx_memory_close (&stx->memory);
|
|
|
|
if (stx->__malloced) xp_free (stx);
|
|
|
|
}
|
|
|
|
|
2005-05-08 10:44:58 +00:00
|
|
|
int xp_stx_bootstrap (xp_stx_t* stx)
|
|
|
|
{
|
2005-05-08 15:22:45 +00:00
|
|
|
xp_stx_word_t hash_table, symbol_table;
|
|
|
|
xp_stx_word_t symbol_Symbol, symbol_Symbol_class;
|
|
|
|
xp_stx_word_t class_Symbol, class_Metaclass;
|
|
|
|
xp_stx_word_t class_UndefinedObject;
|
2005-05-08 11:16:07 +00:00
|
|
|
|
2005-05-08 15:22:45 +00:00
|
|
|
stx->nil = xp_stx_alloc_object (stx, 0);
|
|
|
|
stx->true = xp_stx_alloc_object (stx, 0);
|
|
|
|
stx->false = xp_stx_alloc_object (stx, 0);
|
2005-05-08 10:44:58 +00:00
|
|
|
|
|
|
|
xp_assert (stx->nil == XP_STX_NIL);
|
|
|
|
xp_assert (stx->true == XP_STX_TRUE);
|
|
|
|
xp_assert (stx->false == XP_STX_FALSE);
|
|
|
|
|
2005-05-08 15:22:45 +00:00
|
|
|
/* TODO: decide the size of this hash table */
|
|
|
|
hash_table = 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"));
|
|
|
|
symbol_Symbol_class = xp_stx_instantiate_symbol (XP_STX_TEXT("Symbol class"));
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2005-05-08 11:16:07 +00:00
|
|
|
|
2005-05-08 10:44:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-05-08 10:31:25 +00:00
|
|
|
|