| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | /* Inline functions */ | 
					
						
							|  |  |  | INLINE CELL array_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(F_ARRAY) + size * CELLS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL string_capacity(F_STRING* str) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return untag_fixnum_fast(str->length); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL string_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-02-04 15:05:31 -05:00
										 |  |  | 	return sizeof(F_STRING) + size; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_BYTE_ARRAY,BYTE_ARRAY_TYPE,byte_array) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | INLINE CELL byte_array_capacity(F_BYTE_ARRAY *array) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return untag_fixnum_fast(array->capacity); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL byte_array_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(F_BYTE_ARRAY) + size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_BIT_ARRAY,BIT_ARRAY_TYPE,bit_array) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | INLINE CELL bit_array_capacity(F_BIT_ARRAY *array) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return untag_fixnum_fast(array->capacity); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL bit_array_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(F_BIT_ARRAY) + (size + 7) / 8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_FLOAT_ARRAY,FLOAT_ARRAY_TYPE,float_array) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | INLINE CELL float_array_capacity(F_FLOAT_ARRAY *array) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return untag_fixnum_fast(array->capacity); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL float_array_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(F_FLOAT_ARRAY) + size * sizeof(double); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL callstack_size(CELL size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(F_CALLSTACK) + size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_CALLSTACK,CALLSTACK_TYPE,callstack) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL tag_boolean(CELL untagged) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (untagged == false ? F : T); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_ARRAY,ARRAY_TYPE,array) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define AREF(array,index) ((CELL)(array) + sizeof(F_ARRAY) + (index) * CELLS)
 | 
					
						
							|  |  |  | #define UNAREF(array,ptr) (((CELL)(ptr)-(CELL)(array)-sizeof(F_ARRAY)) / CELLS)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL array_nth(F_ARRAY *array, CELL slot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return get(AREF(array,slot)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE void set_array_nth(F_ARRAY *array, CELL slot, CELL value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	put(AREF(array,slot),value); | 
					
						
							|  |  |  | 	write_barrier((CELL)array); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL array_capacity(F_ARRAY* array) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return array->capacity >> TAG_BITS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-01 19:36:13 -05:00
										 |  |  | #define BREF(byte_array,index) ((CELL)byte_array + sizeof(F_BYTE_ARRAY) + (index))
 | 
					
						
							|  |  |  | #define SREF(string,index) ((CELL)string + sizeof(F_STRING) + (index))
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | INLINE F_STRING* untag_string(CELL tagged) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	type_check(STRING_TYPE,tagged); | 
					
						
							|  |  |  | 	return untag_object(tagged); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_QUOTATION,QUOTATION_TYPE,quotation) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DEFINE_UNTAG(F_WORD,WORD_TYPE,word) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | INLINE CELL tag_tuple(F_ARRAY *tuple) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return RETAG(tuple,TUPLE_TYPE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Prototypes */ | 
					
						
							|  |  |  | DLLEXPORT void box_boolean(bool value); | 
					
						
							|  |  |  | DLLEXPORT bool to_boolean(CELL value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | F_ARRAY *allot_array_internal(CELL type, CELL capacity); | 
					
						
							|  |  |  | F_ARRAY *allot_array(CELL type, CELL capacity, CELL fill); | 
					
						
							|  |  |  | F_BYTE_ARRAY *allot_byte_array(CELL size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | CELL allot_array_1(CELL obj); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | CELL allot_array_2(CELL v1, CELL v2); | 
					
						
							|  |  |  | CELL allot_array_4(CELL v1, CELL v2, CELL v3, CELL v4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(tuple); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(tuple_boa); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(byte_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(bit_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(float_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(clone); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(tuple_to_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(to_tuple); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity, CELL fill); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(resize_array); | 
					
						
							| 
									
										
										
										
											2008-01-29 16:04:26 -05:00
										 |  |  | DECLARE_PRIMITIVE(resize_byte_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(resize_bit_array); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(resize_float_array); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | F_STRING* allot_string_internal(CELL capacity); | 
					
						
							|  |  |  | F_STRING* allot_string(CELL capacity, CELL fill); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(string); | 
					
						
							| 
									
										
										
										
											2008-02-01 00:03:10 -05:00
										 |  |  | F_STRING *reallot_string(F_STRING *string, CELL capacity, CELL fill); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | DECLARE_PRIMITIVE(resize_string); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | F_STRING *memory_to_char_string(const char *string, CELL length); | 
					
						
							|  |  |  | F_STRING *from_char_string(const char *c_string); | 
					
						
							|  |  |  | DLLEXPORT void box_char_string(const char *c_string); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(alien_to_char_string); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | F_STRING *memory_to_u16_string(const u16 *string, CELL length); | 
					
						
							|  |  |  | F_STRING *from_u16_string(const u16 *c_string); | 
					
						
							|  |  |  | DLLEXPORT void box_u16_string(const u16 *c_string); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(alien_to_u16_string); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void char_string_to_memory(F_STRING *s, char *string); | 
					
						
							|  |  |  | F_BYTE_ARRAY *string_to_char_alien(F_STRING *s, bool check); | 
					
						
							|  |  |  | char* to_char_string(F_STRING *s, bool check); | 
					
						
							|  |  |  | DLLEXPORT char *unbox_char_string(void); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(string_to_char_alien); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void u16_string_to_memory(F_STRING *s, u16 *string); | 
					
						
							|  |  |  | F_BYTE_ARRAY *string_to_u16_alien(F_STRING *s, bool check); | 
					
						
							|  |  |  | u16* to_u16_string(F_STRING *s, bool check); | 
					
						
							|  |  |  | DLLEXPORT u16 *unbox_u16_string(void); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(string_to_u16_alien); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-01 00:03:10 -05:00
										 |  |  | /* String getters and setters */ | 
					
						
							|  |  |  | CELL string_nth(F_STRING* string, CELL index); | 
					
						
							|  |  |  | void set_string_nth(F_STRING* string, CELL index, CELL value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(string_nth); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(set_string_nth); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | F_WORD *allot_word(CELL vocab, CELL name); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(word); | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(word_xt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DECLARE_PRIMITIVE(wrapper); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Macros to simulate a vector in C */ | 
					
						
							|  |  |  | #define GROWABLE_ARRAY(result) \
 | 
					
						
							|  |  |  | 	CELL result##_count = 0; \ | 
					
						
							| 
									
										
										
										
											2007-12-26 01:45:16 -05:00
										 |  |  | 	CELL result = tag_object(allot_array(ARRAY_TYPE,100,F)) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-26 17:14:33 -05:00
										 |  |  | F_ARRAY *growable_add(F_ARRAY *result, CELL elt, CELL *result_count); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GROWABLE_ADD(result,elt) \
 | 
					
						
							| 
									
										
										
										
											2007-12-26 01:45:16 -05:00
										 |  |  | 	result = tag_object(growable_add(untag_object(result),elt,&result##_count)) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-26 17:14:33 -05:00
										 |  |  | F_ARRAY *growable_append(F_ARRAY *result, F_ARRAY *elts, CELL *result_count); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GROWABLE_APPEND(result,elts) \
 | 
					
						
							| 
									
										
										
										
											2007-12-26 01:45:16 -05:00
										 |  |  | 	result = tag_object(growable_append(untag_object(result),elts,&result##_count)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GROWABLE_TRIM(result) \
 | 
					
						
							|  |  |  | 	result = tag_object(reallot_array(untag_object(result),result##_count,F)) |