2 INLINE CELL array_size(CELL size)
4 return sizeof(F_ARRAY) + size * CELLS;
7 INLINE CELL string_capacity(F_STRING* str)
9 return untag_fixnum_fast(str->length);
12 INLINE CELL string_size(CELL size)
14 return sizeof(F_STRING) + size;
17 DEFINE_UNTAG(F_BYTE_ARRAY,BYTE_ARRAY_TYPE,byte_array)
19 INLINE CELL byte_array_capacity(F_BYTE_ARRAY *array)
21 return untag_fixnum_fast(array->capacity);
24 INLINE CELL byte_array_size(CELL size)
26 return sizeof(F_BYTE_ARRAY) + size;
29 INLINE CELL callstack_size(CELL size)
31 return sizeof(F_CALLSTACK) + size;
34 DEFINE_UNTAG(F_CALLSTACK,CALLSTACK_TYPE,callstack)
36 INLINE CELL tag_boolean(CELL untagged)
38 return (untagged == false ? F : T);
41 DEFINE_UNTAG(F_ARRAY,ARRAY_TYPE,array)
43 #define AREF(array,index) ((CELL)(array) + sizeof(F_ARRAY) + (index) * CELLS)
44 #define UNAREF(array,ptr) (((CELL)(ptr)-(CELL)(array)-sizeof(F_ARRAY)) / CELLS)
46 INLINE CELL array_nth(F_ARRAY *array, CELL slot)
48 return get(AREF(array,slot));
51 INLINE void set_array_nth(F_ARRAY *array, CELL slot, CELL value)
53 put(AREF(array,slot),value);
54 write_barrier((CELL)array);
57 INLINE CELL array_capacity(F_ARRAY* array)
59 return array->capacity >> TAG_BITS;
62 #define BREF(byte_array,index) ((CELL)byte_array + sizeof(F_BYTE_ARRAY) + (index))
63 #define SREF(string,index) ((CELL)string + sizeof(F_STRING) + (index))
65 INLINE F_STRING* untag_string(CELL tagged)
67 type_check(STRING_TYPE,tagged);
68 return untag_object(tagged);
71 DEFINE_UNTAG(F_QUOTATION,QUOTATION_TYPE,quotation)
73 DEFINE_UNTAG(F_WORD,WORD_TYPE,word)
75 INLINE CELL tag_tuple(F_TUPLE *tuple)
77 return RETAG(tuple,TUPLE_TYPE);
80 INLINE F_TUPLE *untag_tuple(CELL object)
82 type_check(TUPLE_TYPE,object);
83 return untag_object(object);
86 INLINE CELL tuple_size(F_TUPLE_LAYOUT *layout)
88 CELL size = untag_fixnum_fast(layout->size);
89 return sizeof(F_TUPLE) + size * CELLS;
92 INLINE CELL tuple_nth(F_TUPLE *tuple, CELL slot)
94 return get(AREF(tuple,slot));
97 INLINE void set_tuple_nth(F_TUPLE *tuple, CELL slot, CELL value)
99 put(AREF(tuple,slot),value);
100 write_barrier((CELL)tuple);
104 DLLEXPORT void box_boolean(bool value);
105 DLLEXPORT bool to_boolean(CELL value);
107 F_ARRAY *allot_array_internal(CELL type, CELL capacity);
108 F_ARRAY *allot_array(CELL type, CELL capacity, CELL fill);
109 F_BYTE_ARRAY *allot_byte_array(CELL size);
111 CELL allot_array_1(CELL obj);
112 CELL allot_array_4(CELL v1, CELL v2, CELL v3, CELL v4);
114 void primitive_array(void);
115 void primitive_tuple(void);
116 void primitive_tuple_boa(void);
117 void primitive_tuple_layout(void);
118 void primitive_byte_array(void);
119 void primitive_clone(void);
121 F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity);
122 F_BYTE_ARRAY *reallot_byte_array(F_BYTE_ARRAY *array, CELL capacity);
123 void primitive_resize_array(void);
124 void primitive_resize_byte_array(void);
126 F_STRING* allot_string_internal(CELL capacity);
127 F_STRING* allot_string(CELL capacity, CELL fill);
128 void primitive_string(void);
129 F_STRING *reallot_string(F_STRING *string, CELL capacity);
130 void primitive_resize_string(void);
132 F_STRING *memory_to_char_string(const char *string, CELL length);
133 F_STRING *from_char_string(const char *c_string);
134 DLLEXPORT void box_char_string(const char *c_string);
136 F_STRING *memory_to_u16_string(const u16 *string, CELL length);
137 F_STRING *from_u16_string(const u16 *c_string);
138 DLLEXPORT void box_u16_string(const u16 *c_string);
140 void char_string_to_memory(F_STRING *s, char *string);
141 F_BYTE_ARRAY *string_to_char_alien(F_STRING *s, bool check);
142 char* to_char_string(F_STRING *s, bool check);
143 DLLEXPORT char *unbox_char_string(void);
145 void u16_string_to_memory(F_STRING *s, u16 *string);
146 F_BYTE_ARRAY *string_to_u16_alien(F_STRING *s, bool check);
147 u16* to_u16_string(F_STRING *s, bool check);
148 DLLEXPORT u16 *unbox_u16_string(void);
150 /* String getters and setters */
151 CELL string_nth(F_STRING* string, CELL index);
152 void set_string_nth(F_STRING* string, CELL index, CELL value);
154 void primitive_string_nth(void);
155 void primitive_set_string_nth_slow(void);
156 void primitive_set_string_nth_fast(void);
158 F_WORD *allot_word(CELL vocab, CELL name);
159 void primitive_word(void);
160 void primitive_word_xt(void);
162 void primitive_wrapper(void);
164 /* Macros to simulate a vector in C */
165 #define GROWABLE_ARRAY(result) \
166 CELL result##_count = 0; \
167 CELL result = tag_object(allot_array(ARRAY_TYPE,100,F))
169 F_ARRAY *growable_array_add(F_ARRAY *result, CELL elt, CELL *result_count);
171 #define GROWABLE_ARRAY_ADD(result,elt) \
172 result = tag_object(growable_array_add(untag_object(result),elt,&result##_count))
174 F_ARRAY *growable_array_append(F_ARRAY *result, F_ARRAY *elts, CELL *result_count);
176 #define GROWABLE_ARRAY_APPEND(result,elts) \
177 result = tag_object(growable_array_append(untag_object(result),elts,&result##_count))
179 #define GROWABLE_ARRAY_TRIM(result) \
180 result = tag_object(reallot_array(untag_object(result),result##_count))
182 /* Macros to simulate a byte vector in C */
183 #define GROWABLE_BYTE_ARRAY(result) \
184 CELL result##_count = 0; \
185 CELL result = tag_object(allot_byte_array(100))
187 F_ARRAY *growable_byte_array_append(F_BYTE_ARRAY *result, void *elts, CELL len, CELL *result_count);
189 #define GROWABLE_BYTE_ARRAY_APPEND(result,elts,len) \
190 result = tag_object(growable_byte_array_append(untag_object(result),elts,len,&result##_count))
192 #define GROWABLE_BYTE_ARRAY_TRIM(result) \
193 result = tag_object(reallot_byte_array(untag_object(result),result##_count))