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.
24 #define GET_FREE_POINTER() dynamic_space_free_pointer
25 #define SET_FREE_POINTER(new_value) \
26 (dynamic_space_free_pointer = (new_value))
27 #define GET_GC_TRIGGER() current_auto_gc_trigger
28 #define SET_GC_TRIGGER(new_value) \
29 clear_auto_gc_trigger(); set_auto_gc_trigger(new_value);
31 #define ALIGNED_SIZE(n) (n+LOWTAG_MASK) & ~LOWTAG_MASK
34 extern lispobj *alloc(int bytes);
41 /* Round to dual word boundary. */
42 bytes = (bytes + LOWTAG_MASK) & ~LOWTAG_MASK;
44 result = (char *)GET_FREE_POINTER();
46 SET_FREE_POINTER((lispobj *)(result + bytes));
48 if (GET_GC_TRIGGER() && GET_FREE_POINTER() > GET_GC_TRIGGER()) {
49 SET_GC_TRIGGER((char *)GET_FREE_POINTER()
50 - (char *)current_dynamic_space);
52 return (lispobj *) result;
57 alloc_unboxed(int type, int words)
61 result = alloc(ALIGNED_SIZE((1 + words) * sizeof(lispobj)));
62 *result = (lispobj) (words << N_WIDETAG_BITS) | type;
67 alloc_vector(int type, int length, int size)
69 struct vector *result;
71 result = (struct vector *)
72 alloc(ALIGNED_SIZE((2 + (length*size + 31) / 32) * sizeof(lispobj)));
74 result->header = type;
75 result->length = make_fixnum(length);
77 return ((lispobj)result)|OTHER_POINTER_LOWTAG;
81 alloc_cons(lispobj car, lispobj cdr)
83 struct cons *ptr = (struct cons *)alloc(ALIGNED_SIZE(sizeof(struct cons)));
88 return (lispobj)ptr | LIST_POINTER_LOWTAG;
96 if (-0x20000000 < n && n < 0x20000000)
97 return make_fixnum(n);
99 ptr = (struct bignum *)alloc_unboxed(BIGNUM_WIDETAG, 1);
103 return (lispobj) ptr | OTHER_POINTER_LOWTAG;
108 alloc_string(char *str)
110 int len = strlen(str);
111 lispobj result = alloc_vector(SIMPLE_STRING_WIDETAG, len+1, 8);
112 struct vector *vec = (struct vector *)native_pointer(result);
114 vec->length = make_fixnum(len);
115 strcpy((char *)vec->data, str);
125 alloc_unboxed((int)SAP_WIDETAG, sizeof(struct sap)/sizeof(lispobj) -1);
127 return (lispobj) sap | OTHER_POINTER_LOWTAG;