Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/kernel/globals.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/kernel/globals.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/kernel/globals.c

1 : monnier 2 /* globals.c
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
4 :     *
5 :     */
6 :    
7 :     #include "ml-base.h"
8 :     #include "machine-id.h"
9 :     #include "ml-values.h"
10 :     #include "tags.h"
11 :     #include "ml-globals.h"
12 :     #include "ml-objects.h"
13 :     #include "ml-limits.h"
14 :     #include "c-globals-tbl.h"
15 :    
16 :     #ifdef SIZES_C64_ML32
17 :     void PatchAddrs ();
18 :     #endif
19 :    
20 :    
21 :     #ifndef SIZES_C64_ML32
22 :    
23 :     /* Exceptions are identified by (string ref) values */
24 :     #define ML_EXNID(ex,name) \
25 :     ML_STRING(CONCAT(ex,_s),name); \
26 :     ml_val_t CONCAT(ex,_id0) [2] = { \
27 :     DESC_ref, \
28 :     PTR_CtoML(CONCAT(ex,_s).s) \
29 :     }
30 :    
31 :     #define ASM_CLOSURE(name) \
32 :     extern ml_val_t CONCAT(name,_a)[]; \
33 :     ml_val_t CONCAT(name,_v)[2] = { \
34 :     MAKE_DESC(1,DTAG_record), \
35 :     PTR_CtoML(CONCAT(name,_a)) \
36 :     }
37 :    
38 :     #else /* SIZES_C64_ML32 */
39 :     /* When the size of Addr_t is bigger than the size of an Word_t, we need
40 :     * to dynamically patch the static ML objects.
41 :     */
42 :    
43 :     /* Exceptions are identified by (string ref) values */
44 :     #define ML_EXNID(ex,name) \
45 :     ML_STRING(CONCAT(ex,_s),name); \
46 :     ml_val_t CONCAT(ex,_id0) [2] = { DESC_ref, }
47 :    
48 :     #define PATCH_ML_EXNID(ex) \
49 :     CONCAT(ex,_id0)[1] = PTR_CtoML(CONCAT(ex,_s).s)
50 :    
51 :     #define ASM_CLOSURE(name) \
52 :     extern ml_val_t CONCAT(name,_a)[]; \
53 :     ml_val_t CONCAT(name,_v)[2] = { \
54 :     MAKE_DESC(1, DTAG_record), \
55 :     }
56 :    
57 :     #define PATCH_ASM_CLOSURE(name) \
58 :     CONCAT(name,_v)[1] = PTR_CtoML(CONCAT(name,_a))
59 :    
60 :     #endif
61 :    
62 :    
63 :     #if (CALLEESAVE > 0)
64 :     #define ASM_CONT(name) \
65 :     extern ml_val_t CONCAT(name,_a)[]; \
66 :     ml_val_t *CONCAT(name,_c) = (ml_val_t *)(CONCAT(name,_a))
67 :     #else
68 :     #define ASM_CONT(name) \
69 :     ASM_CLOSURE(name); \
70 :     ml_val_t *CONCAT(name,_c) = (ml_val_t *)(CONCAT(name,_v)+1)
71 :     #endif
72 :    
73 :     /* machine identification strings */
74 :     ML_STRING(machine_id, MACHINE_ID);
75 :    
76 :    
77 :     ASM_CLOSURE(array);
78 :     ASM_CLOSURE(bind_cfun);
79 :     ASM_CLOSURE(callc);
80 :     ASM_CLOSURE(create_b);
81 :     ASM_CLOSURE(create_r);
82 :     ASM_CLOSURE(create_s);
83 :     ASM_CLOSURE(create_v);
84 :     ASM_CLOSURE(floor);
85 :     ASM_CLOSURE(logb);
86 :     ASM_CLOSURE(scalb);
87 :     ASM_CLOSURE(try_lock);
88 :     ASM_CLOSURE(unlock);
89 :     ASM_CLOSURE(handle);
90 :    
91 :     ASM_CONT(return);
92 :     ASM_CONT(sigh_return);
93 :     ASM_CONT(pollh_return);
94 :    
95 :    
96 :     /* A ref cell initialized to unit. */
97 :     #define REFCELL(z) ml_val_t z[2] = {DESC_ref, ML_unit}
98 :    
99 :     REFCELL(_ProfCurrent);
100 :     REFCELL(_PervStruct);
101 :     REFCELL(_MLSignalHandler);
102 :     REFCELL(_MLPollHandler);
103 :     REFCELL(_PollEvent0);
104 :     REFCELL(_PollFreq0);
105 :     REFCELL(_ActiveProcs0);
106 :    
107 :     ml_val_t RunTimeCompUnit = ML_unit;
108 :     #ifdef ASM_MATH
109 :     ml_val_t MathVec = ML_unit;
110 :     #endif
111 :    
112 :     /* aggregate structures of length zero */
113 :     ml_val_t _ML_string0[2] = {MAKE_DESC(0, DTAG_string), ML_unit};
114 :     ml_val_t _ML_array0[2] = {MAKE_DESC(0, DTAG_array), ML_unit};
115 :     ml_val_t _ML_bytearray0[2] = {MAKE_DESC(0, DTAG_bytearray), ML_unit};
116 :     ml_val_t _ML_realarray0[2] = {MAKE_DESC(0, DTAG_realdarray), ML_unit};
117 :     ml_val_t _ML_vector0[2] = {MAKE_DESC(0, DTAG_vector), ML_unit};
118 :    
119 : monnier 29 ML_EXNID(_Div,"Div");
120 :     ML_EXNID(_Overflow,"Overflow");
121 : monnier 2 ML_EXNID(SysErr, "SysErr");
122 :    
123 :     extern ml_val_t externlist0[];
124 :    
125 :     #ifdef ASM_MATH
126 : monnier 29 ML_EXNID(_Ln,"Ln");
127 :     ML_EXNID(_Sqrt,"Sqrt");
128 : monnier 2 #endif
129 :    
130 :    
131 :     /* A table of pointers to global C variables that are potential roots. */
132 :     ml_val_t *CRoots[MAX_C_ROOTS] = {
133 :     &RunTimeCompUnit,
134 :     _PervStruct+1,
135 :     _MLSignalHandler+1,
136 :     _MLPollHandler+1,
137 :     #ifdef ASM_MATH
138 :     &MathVec,
139 :     #else
140 :     NIL(ml_val_t *),
141 :     #endif
142 :     NIL(ml_val_t *), NIL(ml_val_t *)
143 :     };
144 :     #ifdef ASM_MATH
145 :     int NumCRoots = 5;
146 :     #else
147 :     int NumCRoots = 4;
148 :     #endif
149 :    
150 :    
151 :     /* AllocGlobals:
152 :     */
153 :     void AllocGlobals (ml_state_t *msp)
154 :     {
155 :     ml_val_t RunVec;
156 :     ml_val_t CStruct;
157 :    
158 :     #ifdef SIZES_C64_ML32
159 :     PatchAddrs ();
160 :     #endif
161 :    
162 :     /* allocate the RunVec */
163 :     #define RUNVEC_SZ 12
164 :     ML_AllocWrite(msp, 0, MAKE_DESC(RUNVEC_SZ, DTAG_record));
165 :     ML_AllocWrite(msp, 1, PTR_CtoML(array_v+1));
166 :     ML_AllocWrite(msp, 2, PTR_CtoML(bind_cfun_v+1));
167 :     ML_AllocWrite(msp, 3, PTR_CtoML(callc_v+1));
168 :     ML_AllocWrite(msp, 4, PTR_CtoML(create_b_v+1));
169 :     ML_AllocWrite(msp, 5, PTR_CtoML(create_r_v+1));
170 :     ML_AllocWrite(msp, 6, PTR_CtoML(create_s_v+1));
171 :     ML_AllocWrite(msp, 7, PTR_CtoML(create_v_v+1));
172 :     ML_AllocWrite(msp, 8, PTR_CtoML(floor_v+1));
173 :     ML_AllocWrite(msp, 9, PTR_CtoML(logb_v+1));
174 :     ML_AllocWrite(msp, 10, PTR_CtoML(scalb_v+1));
175 :     ML_AllocWrite(msp, 11, PTR_CtoML(try_lock_v+1));
176 :     ML_AllocWrite(msp, 12, PTR_CtoML(unlock_v+1));
177 :     RunVec = ML_Alloc(msp, RUNVEC_SZ);
178 :    
179 :     /* allocate the CStruct */
180 :     #define CSTRUCT_SZ 15
181 :     ML_AllocWrite(msp, 0, MAKE_DESC(CSTRUCT_SZ, DTAG_record));
182 :     ML_AllocWrite(msp, 1, RunVec);
183 : monnier 29 ML_AllocWrite(msp, 2, DivId);
184 :     ML_AllocWrite(msp, 3, OverflowId);
185 : monnier 2 ML_AllocWrite(msp, 4, SysErrId);
186 :     ML_AllocWrite(msp, 5, ML_array0);
187 :     ML_AllocWrite(msp, 6, ML_bytearray0);
188 :     ML_AllocWrite(msp, 7, ProfCurrent);
189 :     ML_AllocWrite(msp, 8, PollEvent);
190 :     ML_AllocWrite(msp, 9, PollFreq);
191 :     ML_AllocWrite(msp, 10, MLPollHandler);
192 :     ML_AllocWrite(msp, 11, ActiveProcs);
193 :     ML_AllocWrite(msp, 12, PervStruct);
194 :     ML_AllocWrite(msp, 13, ML_realarray0);
195 :     ML_AllocWrite(msp, 14, MLSignalHandler);
196 :     ML_AllocWrite(msp, 15, ML_vector0);
197 :     CStruct = ML_Alloc(msp, CSTRUCT_SZ);
198 :    
199 :     /* allocate 1-elem SRECORD just containing the CStruct */
200 :     REC_ALLOC1(msp, RunTimeCompUnit, CStruct);
201 :    
202 :     #ifdef ASM_MATH
203 :     #define MATHVEC_SZ 8
204 :     ML_AllocWrite(msp, 0, MAKE_DESC(MATHVEC_SZ, DTAG_record));
205 : monnier 29 ML_AllocWrite(msp, 1, LnId);
206 :     ML_AllocWrite(msp, 2, SqrtId);
207 : monnier 2 ML_AllocWrite(msp, 3, PTR_CtoML(arctan_v+1));
208 :     ML_AllocWrite(msp, 4, PTR_CtoML(cos_v+1));
209 :     ML_AllocWrite(msp, 5, PTR_CtoML(exp_v+1));
210 :     ML_AllocWrite(msp, 6, PTR_CtoML(ln_v+1));
211 :     ML_AllocWrite(msp, 7, PTR_CtoML(sin_v+1));
212 :     ML_AllocWrite(msp, 8, PTR_CtoML(sqrt_v+1));
213 :     MathVec = ML_Alloc(msp, MATHVEC_SZ);
214 :     #endif
215 :    
216 :     } /* end of AllocGlobals */
217 :    
218 :    
219 :     /* RecordGlobals:
220 :     *
221 :     * Record all global symbols that may be referenced from the ML heap.
222 :     */
223 :     void RecordGlobals ()
224 :     {
225 :     /* Misc. */
226 :     RecordCSymbol ("handle", PTR_CtoML(handle_v+1));
227 :     RecordCSymbol ("return", PTR_CtoML(return_c));
228 :     #if (CALLEESAVE == 0)
229 :     RecordCSymbol ("return_a", PTR_CtoML(return_a));
230 :     #endif
231 :    
232 :     /* RunVec */
233 :     RecordCSymbol ("RunVec.array", PTR_CtoML(array_v+1));
234 :     RecordCSymbol ("RunVec.bind_cfun", PTR_CtoML(bind_cfun_v+1));
235 :     RecordCSymbol ("RunVec.callc", PTR_CtoML(callc_v+1));
236 :     RecordCSymbol ("RunVec.create_b", PTR_CtoML(create_b_v+1));
237 :     RecordCSymbol ("RunVec.create_r", PTR_CtoML(create_r_v+1));
238 :     RecordCSymbol ("RunVec.create_s", PTR_CtoML(create_s_v+1));
239 :     RecordCSymbol ("RunVec.create_v", PTR_CtoML(create_v_v+1));
240 :     RecordCSymbol ("RunVec.floor", PTR_CtoML(floor_v+1));
241 :     RecordCSymbol ("RunVec.logb", PTR_CtoML(logb_v+1));
242 :     RecordCSymbol ("RunVec.scalb", PTR_CtoML(scalb_v+1));
243 :     RecordCSymbol ("RunVec.try_lock", PTR_CtoML(try_lock_v+1));
244 :     RecordCSymbol ("RunVec.unlock", PTR_CtoML(unlock_v+1));
245 :    
246 :     /* CStruct */
247 : monnier 29 RecordCSymbol ("CStruct.DivId", DivId);
248 :     RecordCSymbol ("CStruct.OverflowId", OverflowId);
249 : monnier 2 RecordCSymbol ("CStruct.SysErrId", SysErrId);
250 :     RecordCSymbol ("CStruct.array0", ML_array0);
251 :     RecordCSymbol ("CStruct.bytearray0", ML_bytearray0);
252 :     RecordCSymbol ("CStruct.machine_id", PTR_CtoML(machine_id.s));
253 :     RecordCSymbol ("CStruct.PervStruct", PervStruct);
254 :     RecordCSymbol ("CStruct.realarray0", ML_realarray0);
255 :     RecordCSymbol ("CStruct.MLSignalHandler", MLSignalHandler);
256 :     RecordCSymbol ("CStruct.vector0", ML_vector0);
257 :     RecordCSymbol ("CStruct.profCurrent", ProfCurrent);
258 :     RecordCSymbol ("CStruct.MLPollHandler", MLPollHandler);
259 :     RecordCSymbol ("CStruct.pollEvent", PollEvent);
260 :     RecordCSymbol ("CStruct.pollFreq", PollFreq);
261 :     RecordCSymbol ("CStruct.activeProcs", ActiveProcs);
262 :    
263 :     /* null string */
264 :     RecordCSymbol ("string0", ML_string0);
265 :    
266 :     #if defined(ASM_MATH)
267 :     /* MathVec */
268 : monnier 29 RecordCSymbol ("MathVec.LnId", LnId);
269 :     RecordCSymbol ("MathVec.SqrtId", SqrtId);
270 : monnier 2 RecordCSymbol ("MathVec.arctan", PTR_CtoML(arctan_v+1));
271 :     RecordCSymbol ("MathVec.cos", PTR_CtoML(cos_v+1));
272 :     RecordCSymbol ("MathVec.exp", PTR_CtoML(exp_v+1));
273 :     RecordCSymbol ("MathVec.ln", PTR_CtoML(ln_v+1));
274 :     RecordCSymbol ("MathVec.sin", PTR_CtoML(sin_v+1));
275 :     RecordCSymbol ("MathVec.sqrt", PTR_CtoML(sqrt_v+1));
276 :     #endif
277 :    
278 :     } /* end of RecordGlobals. */
279 :    
280 :     #ifdef SIZES_C64_ML32
281 :    
282 :     /* PatchAddrs:
283 :     *
284 :     * On machines where the size of Addr_t is bigger than the size of an Word_t,
285 :     * we need to dynamically patch the static ML objects.
286 :     */
287 :     void PatchAddrs ()
288 :     {
289 : monnier 29 PATCH_ML_EXNID(_Div);
290 :     PATCH_ML_EXNID(_Overflow);
291 : monnier 2 PATCH_ML_EXNID(SysErr);
292 :    
293 :     PATCH_ASM_CLOSURE(array);
294 :     PATCH_ASM_CLOSURE(bind_cfun);
295 :     PATCH_ASM_CLOSURE(callc);
296 :     PATCH_ASM_CLOSURE(create_b);
297 :     PATCH_ASM_CLOSURE(create_r);
298 :     PATCH_ASM_CLOSURE(create_s);
299 :     PATCH_ASM_CLOSURE(create_v);
300 :     PATCH_ASM_CLOSURE(floor);
301 :     PATCH_ASM_CLOSURE(logb);
302 :     PATCH_ASM_CLOSURE(scalb);
303 :     PATCH_ASM_CLOSURE(try_lock);
304 :     PATCH_ASM_CLOSURE(unlock);
305 :     PATCH_ASM_CLOSURE(handle);
306 :    
307 :     #if (CALLEESAVE <= 0)
308 :     PATCH_ASM_CLOSURE(return);
309 :     PATCH_ASM_CLOSURE(sigh_return);
310 :     #endif
311 :    
312 :     } /* end of PatchAddrs */
313 :    
314 :     #endif /* SIZES_C64_ML32 */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0