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 2 - (view) (download) (as text)

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

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