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

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

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