6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
27 #define GET_FREE_POINTER() ((lispobj *)SymbolValue(ALLOCATION_POINTER))
28 #define SET_FREE_POINTER(new_value) \
29 (SetSymbolValue(ALLOCATION_POINTER,(lispobj)(new_value)))
30 #define GET_GC_TRIGGER() ((lispobj *)SymbolValue(INTERNAL_GC_TRIGGER))
31 #define SET_GC_TRIGGER(new_value) \
32 (SetSymbolValue(INTERNAL_GC_TRIGGER,(lispobj)(new_value)))
34 #define GET_FREE_POINTER() dynamic_space_free_pointer
35 #define SET_FREE_POINTER(new_value) (dynamic_space_free_pointer = (new_value))
36 #define GET_GC_TRIGGER() current_auto_gc_trigger
37 #define SET_GC_TRIGGER(new_value) \
38 clear_auto_gc_trigger(); set_auto_gc_trigger(new_value);
41 #define ALIGNED_SIZE(n) (n+lowtag_Mask) & ~lowtag_Mask
43 #if defined(WANT_CGC) || defined(GENCGC)
44 extern lispobj *alloc(int bytes);
46 static lispobj *alloc(int bytes)
50 /* Round to dual word boundary. */
51 bytes = (bytes + lowtag_Mask) & ~lowtag_Mask;
53 result = GET_FREE_POINTER();
54 SET_FREE_POINTER(result + (bytes / sizeof(lispobj)));
56 if (GET_GC_TRIGGER() && GET_FREE_POINTER() > GET_GC_TRIGGER()) {
57 SET_GC_TRIGGER((char *)GET_FREE_POINTER()
58 - (char *)DYNAMIC_SPACE_START);
65 static lispobj *alloc_unboxed(int type, int words)
69 result = alloc(ALIGNED_SIZE((1 + words) * sizeof(lispobj)));
71 *result = (lispobj) (words << type_Bits) | type;
76 static lispobj alloc_vector(int type, int length, int size)
78 struct vector *result;
80 result = (struct vector *)
81 alloc(ALIGNED_SIZE((2 + (length*size + 31) / 32) * sizeof(lispobj)));
83 result->header = type;
84 result->length = make_fixnum(length);
86 return ((lispobj)result)|type_OtherPointer;
89 lispobj alloc_cons(lispobj car, lispobj cdr)
91 struct cons *ptr = (struct cons *)alloc(ALIGNED_SIZE(sizeof(struct cons)));
96 return (lispobj)ptr | type_ListPointer;
99 lispobj alloc_number(long n)
103 if (-0x20000000 < n && n < 0x20000000)
104 return make_fixnum(n);
106 ptr = (struct bignum *)alloc_unboxed(type_Bignum, 1);
110 return (lispobj) ptr | type_OtherPointer;
114 lispobj alloc_string(char *str)
116 int len = strlen(str);
117 lispobj result = alloc_vector(type_SimpleString, len+1, 8);
118 struct vector *vec = (struct vector *)PTR(result);
120 vec->length = make_fixnum(len);
121 strcpy((char *)vec->data, str);
126 lispobj alloc_sap(void *ptr)
128 /* FIXME: It would probably be good to grep for "alpha" everywhere
129 * and replace this kind of weirdness with nicer parameterizations
130 * like N_WORDS_IN_POINTER. However, it might be hard to do this
131 * well enough to be useful without an Alpha to test on. What to do? */
133 struct sap *sap = (struct sap *)alloc_unboxed(type_Sap, 1);
135 struct sap *sap = (struct sap *)alloc_unboxed(type_Sap, 3);
139 return (lispobj) sap | type_OtherPointer;