2004-07-16 02:26:21 -04:00
|
|
|
#define TAG_MASK 7
|
|
|
|
#define TAG_BITS 3
|
|
|
|
#define TAG(cell) ((CELL)(cell) & TAG_MASK)
|
|
|
|
#define RETAG(cell,tag) ((CELL)(cell) | (tag))
|
|
|
|
#define UNTAG(cell) ((CELL)(cell) & ~TAG_MASK)
|
|
|
|
|
2004-07-27 20:23:08 -04:00
|
|
|
/*** Tags ***/
|
2004-07-16 02:26:21 -04:00
|
|
|
#define FIXNUM_TYPE 0
|
|
|
|
#define WORD_TYPE 1
|
|
|
|
#define CONS_TYPE 2
|
|
|
|
#define OBJECT_TYPE 3
|
2004-08-04 22:43:58 -04:00
|
|
|
#define RATIO_TYPE 4
|
2004-08-05 20:29:52 -04:00
|
|
|
#define COMPLEX_TYPE 5
|
|
|
|
#define HEADER_TYPE 6
|
|
|
|
#define GC_COLLECTED 7 /* See gc.c */
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-07-27 20:23:08 -04:00
|
|
|
/*** Header types ***/
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
/* Canonical F object */
|
|
|
|
#define F_TYPE 6
|
2004-09-08 02:31:03 -04:00
|
|
|
#define F RETAG(0,OBJECT_TYPE)
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
/* Canonical T object */
|
|
|
|
#define T_TYPE 7
|
|
|
|
CELL T;
|
|
|
|
|
2004-08-12 17:36:36 -04:00
|
|
|
#define ARRAY_TYPE 8
|
2004-10-31 14:36:42 -05:00
|
|
|
#define BIGNUM_TYPE 9
|
|
|
|
#define FLOAT_TYPE 10
|
|
|
|
#define VECTOR_TYPE 11
|
|
|
|
#define STRING_TYPE 12
|
|
|
|
#define SBUF_TYPE 13
|
|
|
|
#define PORT_TYPE 14
|
2004-09-18 18:15:01 -04:00
|
|
|
#define DLL_TYPE 15
|
2004-09-19 17:39:28 -04:00
|
|
|
#define ALIEN_TYPE 16
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-09-21 12:41:57 -04:00
|
|
|
#define TYPE_COUNT 17
|
|
|
|
|
2004-08-05 20:29:52 -04:00
|
|
|
/* Pseudo-types. For error reporting only. */
|
2004-12-10 21:46:42 -05:00
|
|
|
#define INTEGER_TYPE 100 /* F_FIXNUM or BIGNUM */
|
|
|
|
#define RATIONAL_TYPE 101 /* INTEGER or F_RATIO */
|
|
|
|
#define REAL_TYPE 102 /* RATIONAL or F_FLOAT */
|
|
|
|
#define NUMBER_TYPE 103 /* F_COMPLEX or REAL */
|
|
|
|
#define TEXT_TYPE 104 /* F_FIXNUM or F_STRING */
|
2004-08-05 20:29:52 -04:00
|
|
|
|
2004-12-13 16:17:05 -05:00
|
|
|
DLLEXPORT CELL type_of(CELL tagged);
|
2004-08-23 01:13:09 -04:00
|
|
|
bool typep(CELL type, CELL tagged);
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
INLINE CELL tag_header(CELL cell)
|
|
|
|
{
|
|
|
|
return RETAG(cell << TAG_BITS,HEADER_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
INLINE CELL untag_header(CELL cell)
|
|
|
|
{
|
2004-09-18 18:15:01 -04:00
|
|
|
CELL type = cell >> TAG_BITS;
|
2004-12-11 13:26:36 -05:00
|
|
|
#ifdef HEADER_DEBUG
|
2004-07-16 02:26:21 -04:00
|
|
|
if(TAG(cell) != HEADER_TYPE)
|
2004-07-20 02:59:32 -04:00
|
|
|
critical_error("header type check",cell);
|
2004-09-18 18:15:01 -04:00
|
|
|
if(type <= HEADER_TYPE && type != WORD_TYPE)
|
|
|
|
critical_error("header invariant check",cell);
|
2004-12-11 13:26:36 -05:00
|
|
|
#endif
|
2004-09-18 18:15:01 -04:00
|
|
|
return type;
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
INLINE CELL tag_object(void* cell)
|
|
|
|
{
|
|
|
|
return RETAG(cell,OBJECT_TYPE);
|
|
|
|
}
|
|
|
|
|
2004-07-27 22:52:35 -04:00
|
|
|
INLINE CELL object_type(CELL tagged)
|
|
|
|
{
|
|
|
|
return untag_header(get(UNTAG(tagged)));
|
|
|
|
}
|
|
|
|
|
2004-09-19 00:57:33 -04:00
|
|
|
INLINE void type_check(CELL type, CELL tagged)
|
|
|
|
{
|
|
|
|
if(type < HEADER_TYPE)
|
|
|
|
{
|
2004-09-20 21:02:48 -04:00
|
|
|
if(TAG(tagged) == type)
|
|
|
|
return;
|
2004-09-19 00:57:33 -04:00
|
|
|
}
|
2004-09-20 21:02:48 -04:00
|
|
|
else if(tagged == F)
|
|
|
|
{
|
|
|
|
if(type == F_TYPE)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(TAG(tagged) == OBJECT_TYPE
|
|
|
|
&& object_type(tagged) == type)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_error(type,tagged);
|
2004-09-19 00:57:33 -04:00
|
|
|
}
|
|
|
|
|
2004-08-05 16:49:55 -04:00
|
|
|
void* allot_object(CELL type, CELL length);
|
2004-07-16 02:26:21 -04:00
|
|
|
CELL untagged_object_size(CELL pointer);
|
|
|
|
CELL object_size(CELL pointer);
|
2004-09-18 22:29:29 -04:00
|
|
|
void primitive_type(void);
|
|
|
|
void primitive_size(void);
|