qse/ase/stx/stx.c

69 lines
1.6 KiB
C
Raw Normal View History

2005-05-08 07:39:51 +00:00
/*
2005-08-11 09:57:54 +00:00
* $Id: stx.c,v 1.36 2005-08-11 09:57:54 bacon Exp $
2005-05-08 07:39:51 +00:00
*/
#include <xp/stx/stx.h>
#include <xp/stx/memory.h>
2005-05-19 16:41:10 +00:00
#include <xp/stx/misc.h>
2005-05-08 07:39:51 +00:00
2005-06-08 16:05:41 +00:00
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity)
2005-05-08 07:39:51 +00:00
{
2005-07-24 16:50:53 +00:00
xp_word_t i;
2005-05-08 07:39:51 +00:00
if (stx == XP_NULL) {
2005-06-08 16:05:41 +00:00
stx = (xp_stx_t*)xp_malloc (xp_sizeof(stx));
2005-05-08 07:39:51 +00:00
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) {
2005-06-08 16:05:41 +00:00
if (stx->__malloced) xp_free (stx);
2005-05-08 07:39:51 +00:00
return XP_NULL;
}
2005-07-24 16:50:53 +00:00
stx->symtab.size = 0;
2005-08-11 09:57:54 +00:00
stx->symtab.capacity = 128; /* TODO: symbol table size */
stx->symtab.datum = (xp_word_t*)xp_malloc (
2005-07-24 16:50:53 +00:00
xp_sizeof(xp_word_t) * stx->symtab.capacity);
2005-08-11 09:57:54 +00:00
if (stx->symtab.datum == XP_NULL) {
2005-07-24 16:50:53 +00:00
xp_stx_memory_close (&stx->memory);
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-17 16:18:56 +00:00
stx->smalltalk = XP_STX_NIL;
2005-05-10 15:15:58 +00:00
stx->class_symbol = XP_STX_NIL;
2005-05-10 12:00:43 +00:00
stx->class_metaclass = XP_STX_NIL;
2005-07-19 12:08:04 +00:00
stx->class_association = XP_STX_NIL;
2005-05-17 16:18:56 +00:00
2005-05-25 16:44:05 +00:00
stx->class_object = XP_STX_NIL;
stx->class_class = XP_STX_NIL;
2005-07-05 04:29:31 +00:00
stx->class_bytearray = XP_STX_NIL;
2005-05-23 14:43:03 +00:00
stx->class_array = XP_STX_NIL;
2005-07-05 04:29:31 +00:00
stx->class_string = XP_STX_NIL;
2005-07-19 12:08:04 +00:00
stx->class_system_dictionary = XP_STX_NIL;
2005-07-05 09:02:13 +00:00
stx->class_method = XP_STX_NIL;
2005-07-12 16:16:42 +00:00
stx->class_smallinteger = XP_STX_NIL;
2005-05-10 06:08:57 +00:00
2005-07-24 16:50:53 +00:00
for (i = 0; i < stx->symtab.capacity; i++) {
2005-08-11 09:57:54 +00:00
stx->symtab.datum[i] = stx->nil;
2005-07-24 16:50:53 +00:00
}
2005-05-15 18:37:00 +00:00
stx->__wantabort = xp_false;
2005-05-08 07:39:51 +00:00
return stx;
}
void xp_stx_close (xp_stx_t* stx)
{
2005-08-11 09:57:54 +00:00
xp_free (stx->symtab.datum);
2005-05-08 07:39:51 +00:00
xp_stx_memory_close (&stx->memory);
2005-06-08 16:05:41 +00:00
if (stx->__malloced) xp_free (stx);
2005-05-08 07:39:51 +00:00
}