| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | extern cell bignum_zero; | 
					
						
							|  |  |  | extern cell bignum_pos_one; | 
					
						
							|  |  |  | extern cell bignum_neg_one; | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-08 16:05:55 -04:00
										 |  |  | static const fixnum fixnum_max = (((fixnum)1 << (WORD_SIZE - TAG_BITS - 1)) - 1); | 
					
						
							|  |  |  | static const fixnum fixnum_min = (-((fixnum)1 << (WORD_SIZE - TAG_BITS - 1))); | 
					
						
							|  |  |  | static const fixnum array_size_max = ((cell)1 << (WORD_SIZE - TAG_BITS - 2)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | PRIMITIVE(fixnum_add); | 
					
						
							|  |  |  | PRIMITIVE(fixnum_subtract); | 
					
						
							|  |  |  | PRIMITIVE(fixnum_multiply); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIMITIVE(bignum_to_fixnum); | 
					
						
							|  |  |  | PRIMITIVE(float_to_fixnum); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIMITIVE(fixnum_divint); | 
					
						
							|  |  |  | PRIMITIVE(fixnum_divmod); | 
					
						
							|  |  |  | PRIMITIVE(fixnum_shift); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIMITIVE(fixnum_to_bignum); | 
					
						
							|  |  |  | PRIMITIVE(float_to_bignum); | 
					
						
							|  |  |  | PRIMITIVE(bignum_eq); | 
					
						
							|  |  |  | PRIMITIVE(bignum_add); | 
					
						
							|  |  |  | PRIMITIVE(bignum_subtract); | 
					
						
							|  |  |  | PRIMITIVE(bignum_multiply); | 
					
						
							|  |  |  | PRIMITIVE(bignum_divint); | 
					
						
							|  |  |  | PRIMITIVE(bignum_divmod); | 
					
						
							|  |  |  | PRIMITIVE(bignum_mod); | 
					
						
							|  |  |  | PRIMITIVE(bignum_and); | 
					
						
							|  |  |  | PRIMITIVE(bignum_or); | 
					
						
							|  |  |  | PRIMITIVE(bignum_xor); | 
					
						
							|  |  |  | PRIMITIVE(bignum_shift); | 
					
						
							|  |  |  | PRIMITIVE(bignum_less); | 
					
						
							|  |  |  | PRIMITIVE(bignum_lesseq); | 
					
						
							|  |  |  | PRIMITIVE(bignum_greater); | 
					
						
							|  |  |  | PRIMITIVE(bignum_greatereq); | 
					
						
							|  |  |  | PRIMITIVE(bignum_not); | 
					
						
							|  |  |  | PRIMITIVE(bignum_bitp); | 
					
						
							|  |  |  | PRIMITIVE(bignum_log2); | 
					
						
							|  |  |  | PRIMITIVE(byte_array_to_bignum); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static cell allot_integer(fixnum x) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-08 16:05:55 -04:00
										 |  |  | 	if(x < fixnum_min || x > fixnum_max) | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		return tag<bignum>(fixnum_to_bignum(x)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return tag_fixnum(x); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static cell allot_cell(cell x) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-08 16:05:55 -04:00
										 |  |  | 	if(x > (cell)fixnum_max) | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		return tag<bignum>(cell_to_bignum(x)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return tag_fixnum(x); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | cell unbox_array_size(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static double untag_float(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return untag<boxed_float>(tagged)->n; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static double untag_float_check(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return untag_check<boxed_float>(tagged)->n; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static cell allot_float(double n) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	boxed_float *flo = allot<boxed_float>(sizeof(boxed_float)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	flo->n = n; | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 	return tag(flo); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static fixnum float_to_fixnum(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return (fixnum)untag_float(tagged); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static bignum *float_to_bignum(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-02 21:47:29 -04:00
										 |  |  | 	return double_to_bignum(untag_float(tagged)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static double fixnum_to_float(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-02 21:47:29 -04:00
										 |  |  | 	return (double)untag_fixnum(tagged); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static double bignum_to_float(cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return bignum_to_double(untag<bignum>(tagged)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | PRIMITIVE(fixnum_to_float); | 
					
						
							|  |  |  | PRIMITIVE(bignum_to_float); | 
					
						
							|  |  |  | PRIMITIVE(str_to_float); | 
					
						
							|  |  |  | PRIMITIVE(float_to_str); | 
					
						
							|  |  |  | PRIMITIVE(float_to_bits); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIMITIVE(float_eq); | 
					
						
							|  |  |  | PRIMITIVE(float_add); | 
					
						
							|  |  |  | PRIMITIVE(float_subtract); | 
					
						
							|  |  |  | PRIMITIVE(float_multiply); | 
					
						
							|  |  |  | PRIMITIVE(float_divfloat); | 
					
						
							|  |  |  | PRIMITIVE(float_mod); | 
					
						
							|  |  |  | PRIMITIVE(float_less); | 
					
						
							|  |  |  | PRIMITIVE(float_lesseq); | 
					
						
							|  |  |  | PRIMITIVE(float_greater); | 
					
						
							|  |  |  | PRIMITIVE(float_greatereq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIMITIVE(float_bits); | 
					
						
							|  |  |  | PRIMITIVE(bits_float); | 
					
						
							|  |  |  | PRIMITIVE(double_bits); | 
					
						
							|  |  |  | PRIMITIVE(bits_double); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | VM_C_API void box_float(float flo); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_C_API float to_float(cell value); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | VM_C_API void box_double(double flo); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_C_API double to_double(cell value); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | VM_C_API void box_signed_1(s8 n); | 
					
						
							|  |  |  | VM_C_API void box_unsigned_1(u8 n); | 
					
						
							|  |  |  | VM_C_API void box_signed_2(s16 n); | 
					
						
							|  |  |  | VM_C_API void box_unsigned_2(u16 n); | 
					
						
							|  |  |  | VM_C_API void box_signed_4(s32 n); | 
					
						
							|  |  |  | VM_C_API void box_unsigned_4(u32 n); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_C_API void box_signed_cell(fixnum integer); | 
					
						
							|  |  |  | VM_C_API void box_unsigned_cell(cell cell); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | VM_C_API void box_signed_8(s64 n); | 
					
						
							|  |  |  | VM_C_API void box_unsigned_8(u64 n); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_C_API s64 to_signed_8(cell obj); | 
					
						
							|  |  |  | VM_C_API u64 to_unsigned_8(cell obj); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_C_API fixnum to_fixnum(cell tagged); | 
					
						
							|  |  |  | VM_C_API cell to_cell(cell tagged); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y); | 
					
						
							|  |  |  | VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y); | 
					
						
							|  |  |  | VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |