/[cmucl]/src/lisp/alloc.c
ViewVC logotype

Contents of /src/lisp/alloc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Thu Jun 11 16:04:01 2009 UTC (4 years, 10 months ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, post-merge-intl-branch, merged-unicode-utf16-extfmt-2009-06-11, intl-branch-working-2010-02-19-1000, unicode-string-buffer-impl-base, release-20b-pre1, release-20b-pre2, unicode-string-buffer-base, sparc-tramp-assem-2010-07-19, amd64-dd-start, intl-2-branch-base, GIT-CONVERSION, cross-sol-x86-merged, intl-branch-working-2010-02-11-1000, RELEASE_20b, release-20a-base, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, pre-merge-intl-branch, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-01, snapshot-2010-03, snapshot-2010-02, snapshot-2010-08, cross-sol-x86-2010-12-20, intl-branch-2010-03-18-1300, RELEASE_20a, release-20a-pre1, snapshot-2009-11, snapshot-2009-12, portable-clx-import-2009-06-16, cross-sparc-branch-base, intl-branch-base, portable-clx-base, snapshot-2009-08, snapshot-2009-07, HEAD
Branch point for: portable-clx-branch, cross-sparc-branch, RELEASE-20B-BRANCH, unicode-string-buffer-branch, sparc-tramp-assem-branch, RELEASE-20A-BRANCH, amd64-dd-branch, unicode-string-buffer-impl-branch, intl-branch, cross-sol-x86-branch, intl-2-branch
Changes since 1.11: +26 -1 lines
File MIME type: text/plain
Merge Unicode work to trunk.  From label
unicode-utf16-extfmt-2009-06-11.
1 /* $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/alloc.c,v 1.12 2009/06/11 16:04:01 rtoy Rel $ */
2
3 #include <stdio.h>
4 #include <string.h>
5
6 #include "lisp.h"
7 #include "internals.h"
8 #include "alloc.h"
9 #include "globals.h"
10 #include "gc.h"
11
12 #ifdef ibmrt
13 #define GET_FREE_POINTER() ((lispobj *)SymbolValue(ALLOCATION_POINTER))
14 #define SET_FREE_POINTER(new_value) \
15 (SetSymbolValue(ALLOCATION_POINTER,(lispobj)(new_value)))
16 #define GET_GC_TRIGGER() ((lispobj *)SymbolValue(INTERNAL_GC_TRIGGER))
17 #define SET_GC_TRIGGER(new_value) \
18 (SetSymbolValue(INTERNAL_GC_TRIGGER,(lispobj)(new_value)))
19 #else
20 #define GET_FREE_POINTER() current_dynamic_space_free_pointer
21 #define SET_FREE_POINTER(new_value) \
22 (current_dynamic_space_free_pointer = (new_value))
23 #define GET_GC_TRIGGER() current_auto_gc_trigger
24 #define SET_GC_TRIGGER(new_value) \
25 clear_auto_gc_trigger(); set_auto_gc_trigger(new_value);
26 #endif
27
28 #define ALIGNED_SIZE(n) (n+lowtag_Mask) & ~lowtag_Mask
29
30 /****************************************************************
31 Allocation Routines.
32 ****************************************************************/
33
34 #if defined GENCGC
35 #define alloc(nbytes) alloc_pseudo_atomic(nbytes)
36 #include "gencgc.h"
37 #elif defined(WANT_CGC)
38 extern lispobj *alloc(int bytes);
39 #else
40 static lispobj *
41 alloc(int bytes)
42 {
43 lispobj *result;
44
45 /* Round to dual word boundry. */
46 bytes = (bytes + lowtag_Mask) & ~lowtag_Mask;
47
48 result = GET_FREE_POINTER();
49 SET_FREE_POINTER(result + (bytes / sizeof(lispobj)));
50
51 if (GET_GC_TRIGGER() && GET_FREE_POINTER() > GET_GC_TRIGGER()) {
52 SET_GC_TRIGGER((char *) GET_FREE_POINTER()
53 - (char *) current_dynamic_space);
54 }
55
56 return result;
57 }
58 #endif
59
60 static lispobj *
61 alloc_unboxed(int type, int words)
62 {
63 lispobj *result;
64
65 result = (lispobj *) alloc(ALIGNED_SIZE((1 + words) * sizeof(lispobj)));
66
67 *result = (lispobj) (words << type_Bits) | type;
68
69 return result;
70 }
71
72 static lispobj
73 alloc_vector(int type, int length, int size)
74 {
75 struct vector *result;
76
77 result = (struct vector *)
78 alloc(ALIGNED_SIZE((2 + (length * size + 31) / 32) * sizeof(lispobj)));
79
80 result->header = type;
81 result->length = make_fixnum(length);
82
83 return ((lispobj) result) | type_OtherPointer;
84 }
85
86 lispobj
87 alloc_cons(lispobj car, lispobj cdr)
88 {
89 struct cons *ptr = (struct cons *) alloc(ALIGNED_SIZE(sizeof(struct cons)));
90
91 ptr->car = car;
92 ptr->cdr = cdr;
93
94 return (lispobj) ptr | type_ListPointer;
95 }
96
97 lispobj
98 alloc_number(long n)
99 {
100 struct bignum *ptr;
101
102 #ifdef __x86_64
103 if (-0x2000000000000000 < n && n < 0x2000000000000000) /* -2^61 to 2^61 */
104 #else
105 if (-0x20000000 < n && n < 0x20000000)
106 #endif
107 return make_fixnum(n);
108 else {
109 ptr = (struct bignum *) alloc_unboxed(type_Bignum, 1);
110
111 ptr->digits[0] = n;
112
113 return (lispobj) ptr | type_OtherPointer;
114 }
115 }
116
117 #ifndef UNICODE
118 lispobj
119 alloc_string(const char *str)
120 {
121 int len = strlen(str);
122 lispobj result = alloc_vector(type_SimpleString, len + 1, 8);
123 struct vector *vec = (struct vector *) PTR(result);
124
125 vec->length = make_fixnum(len);
126 strcpy((char *) vec->data, str);
127 return result;
128 }
129 #else
130 lispobj
131 alloc_string(const char *str)
132 {
133 int k;
134 int len = strlen(str);
135 lispobj result = alloc_vector(type_SimpleString, len + 1, 16);
136 struct vector *vec = (struct vector *) PTR(result);
137 unsigned short int *wide_char_data;
138
139 vec->length = make_fixnum(len);
140 wide_char_data = (unsigned short int*) vec->data;
141 for (k = 0; k < len; ++k) {
142 wide_char_data[k] = str[k] & 0xff;
143 }
144
145 #if 0
146 fprintf(stderr, "alloc-string: 0x%lx %d -> `%s'\n",
147 result, len, str);
148 #endif
149
150 return result;
151 }
152 #endif
153
154 lispobj
155 alloc_sap(void *ptr)
156 {
157 #ifndef alpha
158 struct sap *sap_ptr = (struct sap *) alloc_unboxed(type_Sap, 1);
159 #else
160 struct sap *sap_ptr = (struct sap *) alloc_unboxed(type_Sap, 3);
161 #endif
162 sap_ptr->pointer = ptr;
163
164 return (lispobj) sap_ptr | type_OtherPointer;
165 }

  ViewVC Help
Powered by ViewVC 1.1.5