]> gitweb.factorcode.org Git - factor.git/blob - native/types.h
ca91b8e4cb114d5429828a16d3192de2bc030cbe
[factor.git] / native / types.h
1 #define TAG_MASK 7
2 #define TAG_BITS 3
3 #define TAG(cell) ((CELL)(cell) & TAG_MASK)
4 #define RETAG(cell,tag) ((CELL)(cell) | (tag))
5 #define UNTAG(cell) ((CELL)(cell) & ~TAG_MASK)
6
7 /*** Tags ***/
8 #define FIXNUM_TYPE 0
9 #define WORD_TYPE 1
10 #define CONS_TYPE 2
11 #define OBJECT_TYPE 3
12 #define HEADER_TYPE 4
13 #define XT_TYPE 5
14 #define GC_COLLECTED 6 /* See gc.c */
15
16 /*** Header types ***/
17
18 /* Canonical F object */
19 #define F_TYPE 6
20 CELL F;
21
22 /* Canonical T object */
23 #define T_TYPE 7
24 CELL T;
25
26 /* Empty stack marker */
27 #define EMPTY_TYPE 8
28 CELL empty;
29
30 #define ARRAY_TYPE 9
31 #define VECTOR_TYPE 10
32 #define STRING_TYPE 11
33 #define SBUF_TYPE 12
34 #define HANDLE_TYPE 13
35 #define BIGNUM_TYPE 14
36
37 bool typep(CELL type, CELL tagged);
38 CELL type_of(CELL tagged);
39 void type_check(CELL type, CELL tagged);
40
41 INLINE void check_non_empty(CELL cell)
42 {
43         if(cell == empty)
44                 general_error(ERROR_UNDERFLOW,F);
45 }
46
47 INLINE CELL tag_boolean(CELL untagged)
48 {
49         return (untagged == false ? F : T);
50 }
51
52 INLINE bool untag_boolean(CELL tagged)
53 {
54         check_non_empty(tagged);
55         return (tagged == F ? false : true);
56 }
57
58 INLINE CELL tag_header(CELL cell)
59 {
60         return RETAG(cell << TAG_BITS,HEADER_TYPE);
61 }
62
63 INLINE CELL untag_header(CELL cell)
64 {
65         if(TAG(cell) != HEADER_TYPE)
66                 critical_error("header type check",cell);
67         return cell >> TAG_BITS;
68 }
69
70 INLINE CELL tag_object(void* cell)
71 {
72         return RETAG(cell,OBJECT_TYPE);
73 }
74
75 INLINE CELL object_type(CELL tagged)
76 {
77         return untag_header(get(UNTAG(tagged)));
78 }
79
80 CELL allot_object(CELL type, CELL length);
81 CELL untagged_object_size(CELL pointer);
82 CELL object_size(CELL pointer);