2005-05-08 07:39:51 +00:00
|
|
|
/*
|
2007-03-22 11:21:59 +00:00
|
|
|
* $Id: stx.h,v 1.47 2007-03-22 11:21:59 bacon Exp $
|
2005-05-08 07:39:51 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#ifndef _ASE_STX_STX_H_
|
|
|
|
#define _ASE_STX_STX_H_
|
2005-05-08 07:39:51 +00:00
|
|
|
|
2007-03-22 11:21:59 +00:00
|
|
|
#include <ase/cmn/types.h>
|
|
|
|
#include <ase/cmn/macros.h>
|
2005-05-08 07:39:51 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
typedef struct ase_stx_objhdr_t ase_stx_objhdr_t;
|
|
|
|
typedef struct ase_stx_object_t ase_stx_object_t;
|
|
|
|
typedef struct ase_stx_word_object_t ase_stx_word_object_t;
|
|
|
|
typedef struct ase_stx_byte_object_t ase_stx_byte_object_t;
|
|
|
|
typedef struct ase_stx_char_object_t ase_stx_char_object_t;
|
|
|
|
typedef struct ase_stx_memory_t ase_stx_memory_t;
|
|
|
|
typedef struct ase_stx_symtab_t ase_stx_symtab_t;
|
|
|
|
typedef struct ase_stx_t ase_stx_t;
|
2005-05-08 07:39:51 +00:00
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
/* common object structure */
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_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
|
|
|
*/
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_word_t access;
|
|
|
|
ase_word_t class;
|
2005-05-21 15:55:50 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_object_t
|
2005-05-21 15:55:50 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_objhdr_t header;
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_word_object_t
|
2005-05-22 04:34:22 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_objhdr_t header;
|
|
|
|
ase_word_t data[1];
|
2005-05-22 04:34:22 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_byte_object_t
|
2005-05-08 07:39:51 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_objhdr_t header;
|
|
|
|
ase_byte_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_char_object_t
|
2005-05-08 07:39:51 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_objhdr_t header;
|
|
|
|
ase_char_t data[1];
|
2005-05-08 07:39:51 +00:00
|
|
|
};
|
|
|
|
|
2005-08-18 15:28:18 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_memory_t
|
2005-08-18 15:28:18 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_word_t capacity;
|
|
|
|
ase_stx_object_t** slots;
|
|
|
|
ase_stx_object_t** free;
|
|
|
|
ase_bool_t __dynamic;
|
2005-08-18 15:28:18 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_symtab_t
|
2005-08-18 15:28:18 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_word_t* datum;
|
|
|
|
ase_word_t size;
|
|
|
|
ase_word_t capacity;
|
2005-08-18 15:28:18 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
struct ase_stx_t
|
2005-08-18 15:28:18 +00:00
|
|
|
{
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_memory_t memory;
|
|
|
|
ase_stx_symtab_t symtab;
|
|
|
|
|
|
|
|
ase_word_t nil;
|
|
|
|
ase_word_t true;
|
|
|
|
ase_word_t false;
|
|
|
|
|
|
|
|
ase_word_t smalltalk;
|
|
|
|
|
|
|
|
ase_word_t class_symbol;
|
|
|
|
ase_word_t class_metaclass;
|
|
|
|
ase_word_t class_association;
|
|
|
|
|
|
|
|
ase_word_t class_object;
|
|
|
|
ase_word_t class_class;
|
|
|
|
ase_word_t class_array;
|
|
|
|
ase_word_t class_bytearray;
|
|
|
|
ase_word_t class_string;
|
|
|
|
ase_word_t class_character;
|
|
|
|
ase_word_t class_context;
|
|
|
|
ase_word_t class_system_dictionary;
|
|
|
|
ase_word_t class_method;
|
|
|
|
ase_word_t class_smallinteger;
|
|
|
|
|
|
|
|
ase_bool_t __dynamic;
|
|
|
|
ase_bool_t __wantabort; /* TODO: make it a function pointer */
|
2005-08-18 15:28:18 +00:00
|
|
|
};
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01)
|
|
|
|
#define ASE_STX_TO_SMALLINT(x) (((x) << 1) | 0x01)
|
|
|
|
#define ASE_STX_FROM_SMALLINT(x) ((x) >> 1)
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_IS_OINDEX(x) (((x) & 0x01) == 0x00)
|
|
|
|
#define ASE_STX_TO_OINDEX(x) (((x) << 1) | 0x00)
|
|
|
|
#define ASE_STX_FROM_OINDEX(x) ((x) >> 1)
|
2005-07-05 10:22:35 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_NIL ASE_STX_TO_OINDEX(0)
|
|
|
|
#define ASE_STX_TRUE ASE_STX_TO_OINDEX(1)
|
|
|
|
#define ASE_STX_FALSE ASE_STX_TO_OINDEX(2)
|
2005-07-05 10:22:35 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_OBJECT(stx,idx) (((stx)->memory).slots[ASE_STX_FROM_OINDEX(idx)])
|
|
|
|
#define ASE_STX_CLASS(stx,idx) (ASE_STX_OBJECT(stx,(idx))->header.class)
|
|
|
|
#define ASE_STX_ACCESS(stx,idx) (ASE_STX_OBJECT(stx,(idx))->header.access)
|
|
|
|
#define ASE_STX_DATA(stx,idx) ((void*)(ASE_STX_OBJECT(stx,idx) + 1))
|
2005-05-10 06:02:19 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_TYPE(stx,idx) (ASE_STX_ACCESS(stx,idx) & 0x03)
|
|
|
|
#define ASE_STX_SIZE(stx,idx) (ASE_STX_ACCESS(stx,idx) >> 0x02)
|
2005-07-04 16:23:13 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_WORD_INDEXED (0x00)
|
|
|
|
#define ASE_STX_BYTE_INDEXED (0x01)
|
|
|
|
#define ASE_STX_CHAR_INDEXED (0x02)
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_IS_WORD_OBJECT(stx,idx) \
|
|
|
|
(ASE_STX_TYPE(stx,idx) == ASE_STX_WORD_INDEXED)
|
|
|
|
#define ASE_STX_IS_BYTE_OBJECT(stx,idx) \
|
|
|
|
(ASE_STX_TYPE(stx,idx) == ASE_STX_BYTE_INDEXED)
|
|
|
|
#define ASE_STX_IS_CHAR_OBJECT(stx,idx) \
|
|
|
|
(ASE_STX_TYPE(stx,idx) == ASE_STX_CHAR_INDEXED)
|
2005-07-04 16:23:13 +00:00
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_WORD_OBJECT(stx,idx) \
|
|
|
|
((ase_stx_word_object_t*)ASE_STX_OBJECT(stx,idx))
|
|
|
|
#define ASE_STX_BYTE_OBJECT(stx,idx) \
|
|
|
|
((ase_stx_byte_object_t*)ASE_STX_OBJECT(stx,idx))
|
|
|
|
#define ASE_STX_CHAR_OBJECT(stx,idx) \
|
|
|
|
((ase_stx_char_object_t*)ASE_STX_OBJECT(stx,idx))
|
2005-05-22 04:34:22 +00:00
|
|
|
|
2005-09-30 12:19:00 +00:00
|
|
|
/*
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_WORD_AT(stx,idx,n) \
|
|
|
|
(((ase_word_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n])
|
|
|
|
#define ASE_STX_BYTE_AT(stx,idx,n) \
|
|
|
|
(((ase_byte_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n])
|
|
|
|
#define ASE_STX_CHAR_AT(stx,idx,n) \
|
|
|
|
(((ase_char_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n])
|
2005-09-30 12:19:00 +00:00
|
|
|
*/
|
2007-03-22 11:19:28 +00:00
|
|
|
#define ASE_STX_WORD_AT(stx,idx,n) \
|
|
|
|
(ASE_STX_WORD_OBJECT(stx,idx)->data[n])
|
|
|
|
#define ASE_STX_BYTE_AT(stx,idx,n) \
|
|
|
|
(ASE_STX_BYTE_OBJECT(stx,idx)->data[n])
|
|
|
|
#define ASE_STX_CHAR_AT(stx,idx,n) \
|
|
|
|
(ASE_STX_CHAR_OBJECT(stx,idx)->data[n])
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-05-08 07:39:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 11:19:28 +00:00
|
|
|
ase_stx_t* ase_stx_open (ase_stx_t* stx, ase_word_t capacity);
|
|
|
|
void ase_stx_close (ase_stx_t* stx);
|
2005-05-08 07:39:51 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|