3 This code was written as part of the CMU Common Lisp project at
4 Carnegie Mellon University, and has been placed in the public domain.
12 #include "internals.h"
18 #define GET_FREE_POINTER() ((lispobj *)SymbolValue(ALLOCATION_POINTER))
19 #define SET_FREE_POINTER(new_value) \
20 (SetSymbolValue(ALLOCATION_POINTER,(lispobj)(new_value)))
21 #define GET_GC_TRIGGER() ((lispobj *)SymbolValue(INTERNAL_GC_TRIGGER))
22 #define SET_GC_TRIGGER(new_value) \
23 (SetSymbolValue(INTERNAL_GC_TRIGGER,(lispobj)(new_value)))
25 #define GET_FREE_POINTER() current_dynamic_space_free_pointer
26 #define SET_FREE_POINTER(new_value) \
27 (current_dynamic_space_free_pointer = (new_value))
28 #define GET_GC_TRIGGER() current_auto_gc_trigger
29 #define SET_GC_TRIGGER(new_value) \
30 clear_auto_gc_trigger(); set_auto_gc_trigger(new_value);
33 #define ALIGNED_SIZE(n) (n+lowtag_Mask) & ~lowtag_Mask
35 /****************************************************************
37 ****************************************************************/
40 #define alloc(nbytes) alloc_pseudo_atomic(nbytes)
42 #elif defined(WANT_CGC)
43 extern lispobj *alloc(int bytes);
50 /* Round to dual word boundry. */
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 *) current_dynamic_space);
66 alloc_unboxed(int type, int words)
70 result = (lispobj *) alloc(ALIGNED_SIZE((1 + words) * sizeof(lispobj)));
72 *result = (lispobj) (words << type_Bits) | type;
78 alloc_vector(int type, int length, int size)
80 struct vector *result;
82 result = (struct vector *)
83 alloc(ALIGNED_SIZE((2 + (length * size + 31) / 32) * sizeof(lispobj)));
85 result->header = type;
86 result->length = make_fixnum(length);
88 return ((lispobj) result) | type_OtherPointer;
92 alloc_cons(lispobj car, lispobj cdr)
94 struct cons *ptr = (struct cons *) alloc(ALIGNED_SIZE(sizeof(struct cons)));
99 return (lispobj) ptr | type_ListPointer;
108 if (-0x2000000000000000 < n && n < 0x2000000000000000) /* -2^61 to 2^61 */
110 if (-0x20000000 < n && n < 0x20000000)
112 return make_fixnum(n);
114 ptr = (struct bignum *) alloc_unboxed(type_Bignum, 1);
118 return (lispobj) ptr | type_OtherPointer;
124 alloc_string(const char *str)
126 int len = strlen(str);
127 lispobj result = alloc_vector(type_SimpleString, len + 1, 8);
128 struct vector *vec = (struct vector *) PTR(result);
130 vec->length = make_fixnum(len);
131 strcpy((char *) vec->data, str);
136 alloc_string(const char *str)
139 int len = strlen(str);
140 lispobj result = alloc_vector(type_SimpleString, len + 1, 16);
141 struct vector *vec = (struct vector *) PTR(result);
142 unsigned short int *wide_char_data;
144 vec->length = make_fixnum(len);
145 wide_char_data = (unsigned short int*) vec->data;
146 for (k = 0; k < len; ++k) {
147 wide_char_data[k] = str[k] & 0xff;
151 fprintf(stderr, "alloc-string: 0x%lx %d -> `%s'\n",
163 struct sap *sap_ptr = (struct sap *) alloc_unboxed(type_Sap, 1);
165 struct sap *sap_ptr = (struct sap *) alloc_unboxed(type_Sap, 3);
167 sap_ptr->pointer = ptr;
169 return (lispobj) sap_ptr | type_OtherPointer;