2005-05-08 07:39:51 +00:00
|
|
|
/*
|
2005-05-20 04:01:12 +00:00
|
|
|
* $Id: stx.h,v 1.16 2005-05-20 04:01:12 bacon Exp $
|
2005-05-08 07:39:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XP_STX_STX_H_
|
|
|
|
#define _XP_STX_STX_H_
|
|
|
|
|
|
|
|
#include <xp/types.h>
|
|
|
|
#include <xp/macros.h>
|
|
|
|
|
|
|
|
typedef xp_byte_t xp_stx_byte_t;
|
|
|
|
typedef xp_char_t xp_stx_char_t;
|
|
|
|
typedef xp_size_t xp_stx_word_t;
|
|
|
|
typedef xp_size_t xp_stx_size_t;
|
|
|
|
typedef xp_size_t xp_stx_index_t;
|
|
|
|
|
|
|
|
typedef struct xp_stx_object_t xp_stx_object_t;
|
2005-05-20 04:01:12 +00:00
|
|
|
/*
|
2005-05-08 07:39:51 +00:00
|
|
|
typedef struct xp_stx_byte_object_t xp_stx_byte_object_t;
|
|
|
|
typedef struct xp_stx_string_object_t xp_stx_string_object_t;
|
2005-05-20 04:01:12 +00:00
|
|
|
*/
|
2005-05-08 07:39:51 +00:00
|
|
|
typedef struct xp_stx_memory_t xp_stx_memory_t;
|
|
|
|
typedef struct xp_stx_t xp_stx_t;
|
|
|
|
|
|
|
|
#define XP_STX_CHAR(x) XP_CHAR(x)
|
|
|
|
#define XP_STX_TEXT(x) XP_TEXT(x)
|
|
|
|
|
|
|
|
/* common object header structure */
|
2005-05-08 10:31:25 +00:00
|
|
|
|
|
|
|
#define XP_STX_OBJECT_HEADER_SIZE \
|
|
|
|
(xp_sizeof(xp_stx_object_t) - xp_sizeof(xp_stx_word_t))
|
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
struct xp_stx_object_t
|
|
|
|
{
|
2005-05-10 06:02:19 +00:00
|
|
|
/* access - type: 2; size: rest;
|
|
|
|
* type - word indexed: 00 byte indexed: 01 char indexed: 10
|
2005-05-08 10:31:25 +00:00
|
|
|
*/
|
2005-05-08 07:39:51 +00:00
|
|
|
xp_stx_word_t access;
|
|
|
|
xp_stx_word_t class;
|
2005-05-08 11:16:07 +00:00
|
|
|
/*xp_stx_word_t data[1];*/
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2005-05-08 10:31:25 +00:00
|
|
|
/*
|
2005-05-08 07:39:51 +00:00
|
|
|
struct xp_stx_byte_object_t
|
|
|
|
{
|
|
|
|
xp_stx_word_t access;
|
|
|
|
xp_stx_word_t class;
|
2005-05-08 11:16:07 +00:00
|
|
|
xp_stx_byte_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_stx_string_object_t
|
|
|
|
{
|
|
|
|
xp_stx_word_t access;
|
|
|
|
xp_stx_word_t class;
|
2005-05-08 11:16:07 +00:00
|
|
|
xp_stx_char_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
2005-05-08 10:31:25 +00:00
|
|
|
*/
|
2005-05-08 07:39:51 +00:00
|
|
|
|
|
|
|
struct xp_stx_memory_t
|
|
|
|
{
|
|
|
|
xp_stx_word_t capacity;
|
|
|
|
xp_stx_object_t** slots;
|
|
|
|
xp_stx_object_t** free;
|
|
|
|
xp_bool_t __malloced;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_stx_t
|
|
|
|
{
|
|
|
|
xp_stx_memory_t memory;
|
|
|
|
|
|
|
|
xp_stx_word_t nil;
|
|
|
|
xp_stx_word_t true;
|
|
|
|
xp_stx_word_t false;
|
|
|
|
|
2005-05-10 12:00:43 +00:00
|
|
|
xp_stx_word_t symbol_table;
|
2005-05-17 16:18:56 +00:00
|
|
|
xp_stx_word_t smalltalk;
|
|
|
|
|
2005-05-18 04:01:51 +00:00
|
|
|
xp_stx_word_t class_symlink;
|
2005-05-10 15:15:58 +00:00
|
|
|
xp_stx_word_t class_symbol;
|
2005-05-10 12:00:43 +00:00
|
|
|
xp_stx_word_t class_metaclass;
|
2005-05-18 04:01:51 +00:00
|
|
|
xp_stx_word_t class_pairlink;
|
2005-05-17 16:18:56 +00:00
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
xp_stx_word_t class_method;
|
|
|
|
xp_stx_word_t class_context;
|
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
xp_bool_t __malloced;
|
2005-05-19 16:41:10 +00:00
|
|
|
xp_bool_t __wantabort; /* TODO: make it a function pointer */
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2005-05-08 10:31:25 +00:00
|
|
|
#define XP_STX_NIL 0
|
|
|
|
#define XP_STX_TRUE 1
|
|
|
|
#define XP_STX_FALSE 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define XP_STX_OBJECT(mem,idx) \
|
|
|
|
((xp_stx_object_t*)((mem)->slots[idx]))
|
|
|
|
#define XP_STX_BYTE_OBJECT(mem,idx) \
|
|
|
|
((xp_stx_byte_object_t*)((mem)->slots[idx]))
|
|
|
|
#define XP_STX_STRING_OBJECT(mem,idx) \
|
|
|
|
((xp_stx_string_object_t*)((mem)->slots[idx]))
|
|
|
|
#define XP_STX_OBJECT_DATA(mem,idx) \
|
2005-05-10 06:02:19 +00:00
|
|
|
((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_INDEXED)? \
|
2005-05-08 11:16:07 +00:00
|
|
|
(XP_STX_OBJECT(mem,idx)).data): \
|
2005-05-10 06:02:19 +00:00
|
|
|
((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_BYTE_INDEXED)? \
|
2005-05-08 11:16:07 +00:00
|
|
|
(XP_STX_BYTE_OBJECT(mem,idx)).data): \
|
|
|
|
(XP_STX_STRING_OBJECT(mem,idx)).data))
|
2005-05-08 10:31:25 +00:00
|
|
|
*/
|
|
|
|
|
2005-05-08 15:22:45 +00:00
|
|
|
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx])
|
|
|
|
#define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->class)
|
2005-05-10 06:02:19 +00:00
|
|
|
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->access)
|
2005-05-20 04:01:12 +00:00
|
|
|
#define XP_STX_DATA(stx,idx) ((void*)(XP_STX_OBJECT(stx,idx) + 1))
|
2005-05-10 06:02:19 +00:00
|
|
|
|
|
|
|
#define XP_STX_TYPE(stx,idx) (XP_STX_ACCESS(stx,idx) & 0x03)
|
|
|
|
#define XP_STX_SIZE(stx,idx) (XP_STX_ACCESS(stx,idx) >> 0x02)
|
|
|
|
#define XP_STX_INDEXED (0x00)
|
|
|
|
#define XP_STX_BYTE_INDEXED (0x01)
|
|
|
|
#define XP_STX_CHAR_INDEXED (0x02)
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-05-08 15:22:45 +00:00
|
|
|
#define XP_STX_AT(stx,idx,n) \
|
|
|
|
(((xp_stx_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
|
|
|
|
#define XP_STX_BYTEAT(stx,idx,n) \
|
|
|
|
(((xp_stx_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
|
|
|
|
#define XP_STX_CHARAT(stx,idx,n) \
|
|
|
|
(((xp_stx_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity);
|
|
|
|
void xp_stx_close (xp_stx_t* stx);
|
|
|
|
|
2005-05-08 10:44:58 +00:00
|
|
|
int xp_stx_bootstrap (xp_stx_t* stx);
|
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|