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
|
2005-01-16 17:58:28 -05:00
|
|
|
#define BIGNUM_TYPE 1
|
2004-07-16 02:26:21 -04:00
|
|
|
#define CONS_TYPE 2
|
|
|
|
#define OBJECT_TYPE 3
|
2004-08-04 22:43:58 -04:00
|
|
|
#define RATIO_TYPE 4
|
2005-01-16 17:58:28 -05:00
|
|
|
#define FLOAT_TYPE 5
|
|
|
|
#define COMPLEX_TYPE 6
|
2005-01-29 16:39:30 -05:00
|
|
|
#define HEADER_TYPE 7 /* anything less than this is a tag */
|
2004-08-05 20:29:52 -04:00
|
|
|
#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 T object */
|
|
|
|
#define T_TYPE 7
|
|
|
|
CELL T;
|
|
|
|
|
2004-08-12 17:36:36 -04:00
|
|
|
#define ARRAY_TYPE 8
|
2005-01-16 17:58:28 -05:00
|
|
|
|
|
|
|
/* Canonical F object */
|
|
|
|
#define F_TYPE 9
|
|
|
|
#define F RETAG(0,OBJECT_TYPE)
|
|
|
|
|
2005-01-27 20:06:10 -05:00
|
|
|
#define HASHTABLE_TYPE 10
|
2004-10-31 14:36:42 -05:00
|
|
|
#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
|
2005-01-14 19:51:38 -05:00
|
|
|
#define WORD_TYPE 17
|
2005-01-29 16:39:30 -05:00
|
|
|
#define TUPLE_TYPE 18
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-01-29 16:39:30 -05:00
|
|
|
#define TYPE_COUNT 19
|
2005-01-14 19:51:38 -05:00
|
|
|
|
|
|
|
INLINE bool headerp(CELL cell)
|
|
|
|
{
|
|
|
|
return (cell != F
|
|
|
|
&& TAG(cell) == OBJECT_TYPE
|
|
|
|
&& cell < RETAG(TYPE_COUNT << TAG_BITS,OBJECT_TYPE));
|
|
|
|
}
|
2004-09-21 12:41:57 -04:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
INLINE CELL tag_header(CELL cell)
|
|
|
|
{
|
2005-01-14 19:51:38 -05:00
|
|
|
return RETAG(cell << TAG_BITS,OBJECT_TYPE);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
INLINE CELL untag_header(CELL cell)
|
|
|
|
{
|
2005-01-16 17:58:28 -05:00
|
|
|
return cell >> TAG_BITS;
|
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)
|
|
|
|
{
|
2005-01-16 17:58:28 -05:00
|
|
|
if(tagged == F)
|
|
|
|
return F_TYPE;
|
|
|
|
else
|
|
|
|
return untag_header(get(UNTAG(tagged)));
|
2004-07-27 22:52:35 -04:00
|
|
|
}
|
|
|
|
|
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(TAG(tagged) == OBJECT_TYPE
|
|
|
|
&& object_type(tagged) == type)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_error(type,tagged);
|
2004-09-19 00:57:33 -04:00
|
|
|
}
|
2005-01-17 19:55:18 -05:00
|
|
|
/*
|
|
|
|
* It is up to the caller to fill in the object's fields in a meaningful
|
|
|
|
* fashion!
|
|
|
|
*/
|
|
|
|
INLINE void* allot_object(CELL type, CELL length)
|
|
|
|
{
|
|
|
|
CELL* object = allot(length);
|
|
|
|
*object = tag_header(type);
|
|
|
|
return object;
|
|
|
|
}
|
2004-09-19 00:57:33 -04:00
|
|
|
|
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);
|
2004-12-18 20:32:32 -05:00
|
|
|
|
|
|
|
INLINE CELL type_of(CELL tagged)
|
|
|
|
{
|
|
|
|
CELL tag = TAG(tagged);
|
|
|
|
if(tag == OBJECT_TYPE)
|
2005-01-16 17:58:28 -05:00
|
|
|
return object_type(tagged);
|
2004-12-18 20:32:32 -05:00
|
|
|
else
|
|
|
|
return tag;
|
|
|
|
}
|
2004-12-24 02:52:02 -05:00
|
|
|
|
|
|
|
void primitive_slot(void);
|
|
|
|
void primitive_set_slot(void);
|
|
|
|
void primitive_integer_slot(void);
|
|
|
|
void primitive_set_integer_slot(void);
|