2005-05-08 07:39:51 +00:00
|
|
|
/*
|
2005-07-19 12:08:04 +00:00
|
|
|
* $Id: stx.h,v 1.38 2005-07-19 12:08:04 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>
|
|
|
|
|
2005-05-21 15:55:50 +00:00
|
|
|
typedef struct xp_stx_objhdr_t xp_stx_objhdr_t;
|
2005-05-08 07:39:51 +00:00
|
|
|
typedef struct xp_stx_object_t xp_stx_object_t;
|
2005-05-22 04:34:22 +00:00
|
|
|
typedef struct xp_stx_word_object_t xp_stx_word_object_t;
|
2005-05-08 07:39:51 +00:00
|
|
|
typedef struct xp_stx_byte_object_t xp_stx_byte_object_t;
|
2005-05-21 15:55:50 +00:00
|
|
|
typedef struct xp_stx_char_object_t xp_stx_char_object_t;
|
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;
|
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
/* common object structure */
|
2005-05-21 15:55:50 +00:00
|
|
|
struct xp_stx_objhdr_t
|
2005-05-08 07:39:51 +00:00
|
|
|
{
|
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-06-08 15:49:35 +00:00
|
|
|
xp_word_t access;
|
|
|
|
xp_word_t class;
|
2005-05-21 15:55:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_stx_object_t
|
|
|
|
{
|
|
|
|
xp_stx_objhdr_t header;
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
struct xp_stx_word_object_t
|
|
|
|
{
|
|
|
|
xp_stx_objhdr_t header;
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t data[1];
|
2005-05-22 04:34:22 +00:00
|
|
|
};
|
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
struct xp_stx_byte_object_t
|
|
|
|
{
|
2005-05-21 15:55:50 +00:00
|
|
|
xp_stx_objhdr_t header;
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_byte_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2005-05-21 15:55:50 +00:00
|
|
|
struct xp_stx_char_object_t
|
2005-05-08 07:39:51 +00:00
|
|
|
{
|
2005-05-21 15:55:50 +00:00
|
|
|
xp_stx_objhdr_t header;
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_char_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_stx_memory_t
|
|
|
|
{
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t capacity;
|
2005-05-08 07:39:51 +00:00
|
|
|
xp_stx_object_t** slots;
|
|
|
|
xp_stx_object_t** free;
|
|
|
|
xp_bool_t __malloced;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xp_stx_t
|
|
|
|
{
|
|
|
|
xp_stx_memory_t memory;
|
|
|
|
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t nil;
|
|
|
|
xp_word_t true;
|
|
|
|
xp_word_t false;
|
2005-05-08 07:39:51 +00:00
|
|
|
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t symbol_table;
|
|
|
|
xp_word_t smalltalk;
|
2005-05-17 16:18:56 +00:00
|
|
|
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t class_symlink;
|
|
|
|
xp_word_t class_symbol;
|
|
|
|
xp_word_t class_metaclass;
|
2005-07-18 11:53:01 +00:00
|
|
|
xp_word_t class_association;
|
2005-05-25 16:44:05 +00:00
|
|
|
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_word_t class_object;
|
|
|
|
xp_word_t class_class;
|
|
|
|
xp_word_t class_array;
|
2005-07-05 04:29:31 +00:00
|
|
|
xp_word_t class_bytearray;
|
2005-06-30 12:07:02 +00:00
|
|
|
xp_word_t class_string;
|
2005-07-11 13:41:59 +00:00
|
|
|
xp_word_t class_character;
|
2005-07-19 12:08:04 +00:00
|
|
|
xp_word_t class_system_dictionary;
|
2005-07-05 09:02:13 +00:00
|
|
|
xp_word_t class_method;
|
2005-07-12 16:16:42 +00:00
|
|
|
xp_word_t class_smallinteger;
|
2005-05-15 18:37:00 +00:00
|
|
|
|
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-07-05 10:22:35 +00:00
|
|
|
#define XP_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01)
|
|
|
|
#define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01)
|
|
|
|
#define XP_STX_FROM_SMALLINT(x) ((x) >> 1)
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-07-05 10:22:35 +00:00
|
|
|
#define XP_STX_IS_OINDEX(x) (((x) & 0x01) == 0x00)
|
|
|
|
#define XP_STX_TO_OINDEX(x) (((x) << 1) | 0x00)
|
|
|
|
#define XP_STX_FROM_OINDEX(x) ((x) >> 1)
|
|
|
|
|
|
|
|
#define XP_STX_NIL XP_STX_TO_OINDEX(0)
|
|
|
|
#define XP_STX_TRUE XP_STX_TO_OINDEX(1)
|
|
|
|
#define XP_STX_FALSE XP_STX_TO_OINDEX(2)
|
|
|
|
|
|
|
|
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[XP_STX_FROM_OINDEX(idx)])
|
2005-05-21 15:55:50 +00:00
|
|
|
#define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.class)
|
|
|
|
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.access)
|
|
|
|
#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)
|
2005-07-04 16:23:13 +00:00
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
#define XP_STX_WORD_INDEXED (0x00)
|
2005-05-10 06:02:19 +00:00
|
|
|
#define XP_STX_BYTE_INDEXED (0x01)
|
2005-06-30 12:07:02 +00:00
|
|
|
#define XP_STX_CHAR_INDEXED (0x02)
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-07-05 09:52:00 +00:00
|
|
|
#define XP_STX_IS_WORD_OBJECT(stx,idx) \
|
2005-07-04 16:23:13 +00:00
|
|
|
(XP_STX_TYPE(stx,idx) == XP_STX_WORD_INDEXED)
|
2005-07-05 09:52:00 +00:00
|
|
|
#define XP_STX_IS_BYTE_OBJECT(stx,idx) \
|
2005-07-04 16:23:13 +00:00
|
|
|
(XP_STX_TYPE(stx,idx) == XP_STX_BYTE_INDEXED)
|
2005-07-05 09:52:00 +00:00
|
|
|
#define XP_STX_IS_CHAR_OBJECT(stx,idx) \
|
2005-07-04 16:23:13 +00:00
|
|
|
(XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED)
|
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
#define XP_STX_WORD_OBJECT(stx,idx) \
|
|
|
|
((xp_stx_word_object_t*)XP_STX_OBJECT(stx,idx))
|
|
|
|
#define XP_STX_BYTE_OBJECT(stx,idx) \
|
|
|
|
((xp_stx_byte_object_t*)XP_STX_OBJECT(stx,idx))
|
2005-06-30 12:07:02 +00:00
|
|
|
#define XP_STX_CHAR_OBJECT(stx,idx) \
|
2005-05-22 04:34:22 +00:00
|
|
|
((xp_stx_char_object_t*)XP_STX_OBJECT(stx,idx))
|
|
|
|
|
2005-07-19 12:08:04 +00:00
|
|
|
#define XP_STX_WORD_AT(stx,idx,n) \
|
2005-06-08 15:49:35 +00:00
|
|
|
(((xp_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
|
2005-07-19 12:08:04 +00:00
|
|
|
#define XP_STX_BYTE_AT(stx,idx,n) \
|
2005-06-08 15:49:35 +00:00
|
|
|
(((xp_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
|
2005-07-19 12:08:04 +00:00
|
|
|
#define XP_STX_CHAR_AT(stx,idx,n) \
|
2005-06-08 15:49:35 +00:00
|
|
|
(((xp_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
|
|
|
|
|
2005-06-08 15:49:35 +00:00
|
|
|
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity);
|
2005-05-08 07:39:51 +00:00
|
|
|
void xp_stx_close (xp_stx_t* stx);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|