comparison src/alloc.c @ 1983:9c872f33ecbe

[xemacs-hg @ 2004-04-05 22:49:31 by james] Add bignum, ratio, and bigfloat support.
author james
date Mon, 05 Apr 2004 22:50:11 +0000
parents 59e1bbea04fe
children f913c1545598
comparison
equal deleted inserted replaced
1982:a748951fd4fb 1983:9c872f33ecbe
643 It is also much easier to create a new lcrecord type because no 643 It is also much easier to create a new lcrecord type because no
644 additional code needs to be added to alloc.c. Finally, lcrecords 644 additional code needs to be added to alloc.c. Finally, lcrecords
645 may be more efficient when there are only a small number of them. 645 may be more efficient when there are only a small number of them.
646 646
647 The types that are stored in these large blocks (or "frob blocks") 647 The types that are stored in these large blocks (or "frob blocks")
648 are cons, float, compiled-function, symbol, marker, extent, event, 648 are cons, all number types except fixnum, compiled-function, symbol,
649 and string. 649 marker, extent, event, and string.
650 650
651 Note that strings are special in that they are actually stored in 651 Note that strings are special in that they are actually stored in
652 two parts: a structure containing information about the string, and 652 two parts: a structure containing information about the string, and
653 the actual data associated with the string. The former structure 653 the actual data associated with the string. The former structure
654 (a struct Lisp_String) is a fixed-size structure and is managed the 654 (a struct Lisp_String) is a fixed-size structure and is managed the
1161 1161
1162 /************************************************************************/ 1162 /************************************************************************/
1163 /* Float allocation */ 1163 /* Float allocation */
1164 /************************************************************************/ 1164 /************************************************************************/
1165 1165
1166 /*** With enhanced number support, these are short floats */
1167
1166 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float); 1168 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float);
1167 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000 1169 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
1168 1170
1169 Lisp_Object 1171 Lisp_Object
1170 make_float (double float_value) 1172 make_float (double float_value)
1180 set_lheader_implementation (&f->lheader, &lrecord_float); 1182 set_lheader_implementation (&f->lheader, &lrecord_float);
1181 float_data (f) = float_value; 1183 float_data (f) = float_value;
1182 return wrap_float (f); 1184 return wrap_float (f);
1183 } 1185 }
1184 1186
1187
1188 /************************************************************************/
1189 /* Enhanced number allocation */
1190 /************************************************************************/
1191
1192 /*** Bignum ***/
1193 #ifdef HAVE_BIGNUM
1194 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum);
1195 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250
1196
1197 /* WARNING: This function returns a bignum even if its argument fits into a
1198 fixnum. See Fcanonicalize_number(). */
1199 Lisp_Object
1200 make_bignum (long bignum_value)
1201 {
1202 Lisp_Bignum *b;
1203
1204 ALLOCATE_FIXED_TYPE (bignum, Lisp_Bignum, b);
1205 set_lheader_implementation (&b->lheader, &lrecord_bignum);
1206 bignum_init (bignum_data (b));
1207 bignum_set_long (bignum_data (b), bignum_value);
1208 return wrap_bignum (b);
1209 }
1210
1211 /* WARNING: This function returns a bignum even if its argument fits into a
1212 fixnum. See Fcanonicalize_number(). */
1213 Lisp_Object
1214 make_bignum_bg (bignum bg)
1215 {
1216 Lisp_Bignum *b;
1217
1218 ALLOCATE_FIXED_TYPE (bignum, Lisp_Bignum, b);
1219 set_lheader_implementation (&b->lheader, &lrecord_bignum);
1220 bignum_init (bignum_data (b));
1221 bignum_set (bignum_data (b), bg);
1222 return wrap_bignum (b);
1223 }
1224 #endif /* HAVE_BIGNUM */
1225
1226 /*** Ratio ***/
1227 #ifdef HAVE_RATIO
1228 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio);
1229 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250
1230
1231 Lisp_Object
1232 make_ratio (long numerator, unsigned long denominator)
1233 {
1234 Lisp_Ratio *r;
1235
1236 ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
1237 set_lheader_implementation (&r->lheader, &lrecord_ratio);
1238 ratio_init (ratio_data (r));
1239 ratio_set_long_ulong (ratio_data (r), numerator, denominator);
1240 ratio_canonicalize (ratio_data (r));
1241 return wrap_ratio (r);
1242 }
1243
1244 Lisp_Object
1245 make_ratio_bg (bignum numerator, bignum denominator)
1246 {
1247 Lisp_Ratio *r;
1248
1249 ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
1250 set_lheader_implementation (&r->lheader, &lrecord_ratio);
1251 ratio_init (ratio_data (r));
1252 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator);
1253 ratio_canonicalize (ratio_data (r));
1254 return wrap_ratio (r);
1255 }
1256
1257 Lisp_Object
1258 make_ratio_rt (ratio rat)
1259 {
1260 Lisp_Ratio *r;
1261
1262 ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
1263 set_lheader_implementation (&r->lheader, &lrecord_ratio);
1264 ratio_init (ratio_data (r));
1265 ratio_set (ratio_data (r), rat);
1266 return wrap_ratio (r);
1267 }
1268 #endif /* HAVE_RATIO */
1269
1270 /*** Bigfloat ***/
1271 #ifdef HAVE_BIGFLOAT
1272 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat);
1273 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250
1274
1275 /* This function creates a bigfloat with the default precision if the
1276 PRECISION argument is zero. */
1277 Lisp_Object
1278 make_bigfloat (double float_value, unsigned long precision)
1279 {
1280 Lisp_Bigfloat *f;
1281
1282 ALLOCATE_FIXED_TYPE (bigfloat, Lisp_Bigfloat, f);
1283 set_lheader_implementation (&f->lheader, &lrecord_bigfloat);
1284 if (precision == 0UL)
1285 bigfloat_init (bigfloat_data (f));
1286 else
1287 bigfloat_init_prec (bigfloat_data (f), precision);
1288 bigfloat_set_double (bigfloat_data (f), float_value);
1289 return wrap_bigfloat (f);
1290 }
1291
1292 /* This function creates a bigfloat with the precision of its argument */
1293 Lisp_Object
1294 make_bigfloat_bf (bigfloat float_value)
1295 {
1296 Lisp_Bigfloat *f;
1297
1298 ALLOCATE_FIXED_TYPE (bigfloat, Lisp_Bigfloat, f);
1299 set_lheader_implementation (&f->lheader, &lrecord_bigfloat);
1300 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value));
1301 bigfloat_set (bigfloat_data (f), float_value);
1302 return wrap_bigfloat (f);
1303 }
1304 #endif /* HAVE_BIGFLOAT */
1185 1305
1186 /************************************************************************/ 1306 /************************************************************************/
1187 /* Vector allocation */ 1307 /* Vector allocation */
1188 /************************************************************************/ 1308 /************************************************************************/
1189 1309
3784 #define ADDITIONAL_FREE_float(ptr) 3904 #define ADDITIONAL_FREE_float(ptr)
3785 3905
3786 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float); 3906 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float);
3787 } 3907 }
3788 3908
3909 #ifdef HAVE_BIGNUM
3910 static void
3911 sweep_bignums (void)
3912 {
3913 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
3914 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data)
3915
3916 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum);
3917 }
3918 #endif /* HAVE_BIGNUM */
3919
3920 #ifdef HAVE_RATIO
3921 static void
3922 sweep_ratios (void)
3923 {
3924 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
3925 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data)
3926
3927 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio);
3928 }
3929 #endif /* HAVE_RATIO */
3930
3931 #ifdef HAVE_BIGFLOAT
3932 static void
3933 sweep_bigfloats (void)
3934 {
3935 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
3936 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf)
3937
3938 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat);
3939 }
3940 #endif
3941
3789 static void 3942 static void
3790 sweep_symbols (void) 3943 sweep_symbols (void)
3791 { 3944 {
3792 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) 3945 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
3793 #define ADDITIONAL_FREE_symbol(ptr) 3946 #define ADDITIONAL_FREE_symbol(ptr)
4234 /* Free all unmarked compiled-function objects */ 4387 /* Free all unmarked compiled-function objects */
4235 sweep_compiled_functions (); 4388 sweep_compiled_functions ();
4236 4389
4237 /* Put all unmarked floats on free list */ 4390 /* Put all unmarked floats on free list */
4238 sweep_floats (); 4391 sweep_floats ();
4392
4393 #ifdef HAVE_BIGNUM
4394 /* Put all unmarked bignums on free list */
4395 sweep_bignums ();
4396 #endif
4397
4398 #ifdef HAVE_RATIO
4399 /* Put all unmarked ratios on free list */
4400 sweep_ratios ();
4401 #endif
4402
4403 #ifdef HAVE_BIGFLOAT
4404 /* Put all unmarked bigfloats on free list */
4405 sweep_bigfloats ();
4406 #endif
4239 4407
4240 /* Put all unmarked symbols on free list */ 4408 /* Put all unmarked symbols on free list */
4241 sweep_symbols (); 4409 sweep_symbols ();
4242 4410
4243 /* Put all unmarked extents on free list */ 4411 /* Put all unmarked extents on free list */
4794 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl); 4962 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
4795 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl); 4963 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
4796 HACK_O_MATIC (float, "float-storage", pl); 4964 HACK_O_MATIC (float, "float-storage", pl);
4797 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl); 4965 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
4798 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl); 4966 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
4967 #ifdef HAVE_BIGNUM
4968 HACK_O_MATIC (bignum, "bignum-storage", pl);
4969 pl = gc_plist_hack ("bignums-free", gc_count_num_bignum_freelist, pl);
4970 pl = gc_plist_hack ("bignums-used", gc_count_num_bignum_in_use, pl);
4971 #endif /* HAVE_BIGNUM */
4972 #ifdef HAVE_RATIO
4973 HACK_O_MATIC (ratio, "ratio-storage", pl);
4974 pl = gc_plist_hack ("ratios-free", gc_count_num_ratio_freelist, pl);
4975 pl = gc_plist_hack ("ratios-used", gc_count_num_ratio_in_use, pl);
4976 #endif /* HAVE_RATIO */
4977 #ifdef HAVE_BIGFLOAT
4978 HACK_O_MATIC (bigfloat, "bigfloat-storage", pl);
4979 pl = gc_plist_hack ("bigfloats-free", gc_count_num_bigfloat_freelist, pl);
4980 pl = gc_plist_hack ("bigfloats-used", gc_count_num_bigfloat_in_use, pl);
4981 #endif /* HAVE_BIGFLOAT */
4799 HACK_O_MATIC (string, "string-header-storage", pl); 4982 HACK_O_MATIC (string, "string-header-storage", pl);
4800 pl = gc_plist_hack ("long-strings-total-length", 4983 pl = gc_plist_hack ("long-strings-total-length",
4801 gc_count_string_total_size 4984 gc_count_string_total_size
4802 - gc_count_short_string_total_size, pl); 4985 - gc_count_short_string_total_size, pl);
4803 HACK_O_MATIC (string_chars, "short-string-storage", pl); 4986 HACK_O_MATIC (string_chars, "short-string-storage", pl);
5077 init_string_chars_alloc (); 5260 init_string_chars_alloc ();
5078 init_cons_alloc (); 5261 init_cons_alloc ();
5079 init_symbol_alloc (); 5262 init_symbol_alloc ();
5080 init_compiled_function_alloc (); 5263 init_compiled_function_alloc ();
5081 init_float_alloc (); 5264 init_float_alloc ();
5265 #ifdef HAVE_BIGNUM
5266 init_bignum_alloc ();
5267 #endif
5268 #ifdef HAVE_RATIO
5269 init_ratio_alloc ();
5270 #endif
5271 #ifdef HAVE_BIGFLOAT
5272 init_bigfloat_alloc ();
5273 #endif
5082 init_marker_alloc (); 5274 init_marker_alloc ();
5083 init_extent_alloc (); 5275 init_extent_alloc ();
5084 init_event_alloc (); 5276 init_event_alloc ();
5085 #ifdef EVENT_DATA_AS_OBJECTS 5277 #ifdef EVENT_DATA_AS_OBJECTS
5086 init_key_data_alloc (); 5278 init_key_data_alloc ();