File: globals.c

package info (click to toggle)
smlnj 110.79-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 82,564 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,296; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (336 lines) | stat: -rw-r--r-- 9,227 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/* globals.c
 *
 * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
 *
 */

#include "ml-base.h"
#include "machine-id.h"
#include "ml-values.h"
#include "tags.h"
#include "ml-globals.h"
#include "ml-objects.h"
#include "ml-limits.h"
#include "c-globals-tbl.h"

#ifdef SIZES_C64_ML32
void PatchAddrs ();
#endif

#ifndef SIZES_C64_ML32

typedef struct {
	ml_val_t	desc;
	char		*s;
	ml_val_t	len;
} ml_string_t;

#define ML_STRING(id, s)				\
    ml_string_t id = {					\
	DESC_string,					\
	s,						\
	INT_CtoML(sizeof(s)-1)				\
    }

/* Exceptions are identified by (string ref) values */
#define ML_EXNID(ex,name)				\
    ML_STRING(CONCAT(ex,_s), name);			\
    ml_val_t CONCAT(ex,_id0) [2] = {			\
	DESC_ref,					\
	PTR_CtoML(&(CONCAT(ex,_s).s))			\
    }

#define ASM_CLOSURE(name)				\
    extern ml_val_t CONCAT(name,_a)[];			\
    ml_val_t CONCAT(name,_v)[2] = {			\
	MAKE_DESC(1,DTAG_record),			\
	PTR_CtoML(CONCAT(name,_a))			\
    }

#else /* SIZES_C64_ML32 */
/* When the size of Addr_t is bigger than the size of an Word_t, we need
 * to dynamically patch the static ML objects.
 */

typedef struct {
	ml_val_t	desc;
	ml_val_t	s;
	ml_val_t	len;
} ml_string_t;

#define ML_STRING(id,s)					\
    PVT char CONCAT(id,_data)[] = s;			\
    ml_string_t id = {					\
	DESC_string, ML_unit, INT_CtoML(sizeof(s)-1)	\
    }

#define PATCH_ML_STRING(id)				\
    id.s = PTR_CtoML(CONCAT(id,_data))

/* Exceptions are identified by (string ref) values */
#define ML_EXNID(ex,name)				\
    ML_STRING(CONCAT(ex,_s),name);			\
    ml_val_t CONCAT(ex,_id0) [2] = { DESC_ref, }

#define PATCH_ML_EXNID(ex)				\
    PATCH_ML_STRING(CONCAT(ex,_s));			\
    CONCAT(ex,_id0)[1] = PTR_CtoML(&(CONCAT(ex,_s).s))

#define ASM_CLOSURE(name)				\
    extern ml_val_t CONCAT(name,_a)[];			\
    ml_val_t CONCAT(name,_v)[2] = {			\
	MAKE_DESC(1, DTAG_record),			\
    }

#define PATCH_ASM_CLOSURE(name)				\
    CONCAT(name,_v)[1] = PTR_CtoML(CONCAT(name,_a))

#endif


#if (CALLEESAVE > 0)
#define ASM_CONT(name) 							\
    extern ml_val_t CONCAT(name,_a)[];					\
    ml_val_t *CONCAT(name,_c) = (ml_val_t *)(CONCAT(name,_a))
#else
#define ASM_CONT(name)							\
    ASM_CLOSURE(name);							\
    ml_val_t *CONCAT(name,_c) = (ml_val_t *)(CONCAT(name,_v)+1)
#endif

/* machine identification strings */
ML_STRING(machine_id, MACHINE_ID);


ASM_CLOSURE(array);
ASM_CLOSURE(bind_cfun);
ASM_CLOSURE(callc);
ASM_CLOSURE(create_b);
ASM_CLOSURE(create_r);
ASM_CLOSURE(create_s);
ASM_CLOSURE(create_v);
ASM_CLOSURE(floor);
ASM_CLOSURE(logb);
ASM_CLOSURE(scalb);
ASM_CLOSURE(try_lock);
ASM_CLOSURE(unlock);
ASM_CLOSURE(handle);

ASM_CONT(return);
ASM_CONT(sigh_return);
ASM_CONT(pollh_return);


/* A ref cell initialized to unit. */
#define REFCELL(z)	ml_val_t z[2] = {DESC_ref, ML_unit}

REFCELL(_ProfCurrent);
REFCELL(_PervStruct);
REFCELL(_MLSignalHandler);
REFCELL(_MLPollHandler);
REFCELL(_PollEvent0);
REFCELL(_PollFreq0);
REFCELL(_ActiveProcs0);

ml_val_t		RunTimeCompUnit = ML_unit;
#ifdef ASM_MATH
ml_val_t		MathVec = ML_unit;
#endif

/* aggregate structures of length zero */
const char _ML_string0_data[1]  = {0};
ml_val_t _ML_string0[3]		= {DESC_string, PTR_CtoML(_ML_string0_data), INT_CtoML(0)};
ml_val_t _ML_vector0[3]		= {DESC_polyvec, ML_unit, INT_CtoML(0)};

ML_EXNID(_Div,"Div");
ML_EXNID(_Overflow,"Overflow");
ML_EXNID(SysErr, "SysErr");

extern ml_val_t externlist0[];

#ifdef ASM_MATH
ML_EXNID(_Ln,"Ln");
ML_EXNID(_Sqrt,"Sqrt");
#endif


/* A table of pointers to global C variables that are potential roots. */
ml_val_t	*CRoots[MAX_C_ROOTS] = {
    &RunTimeCompUnit,
    _PervStruct+1,
    _MLSignalHandler+1,
    _MLPollHandler+1,
#ifdef ASM_MATH
    &MathVec,
#else
    NIL(ml_val_t *),
#endif
    NIL(ml_val_t *), NIL(ml_val_t *)
};
#ifdef ASM_MATH
int		NumCRoots = 5;
#else
int		NumCRoots = 4;
#endif


/* AllocGlobals:
 */
void AllocGlobals (ml_state_t *msp)
{
    ml_val_t	RunVec;
    ml_val_t    CStruct;

#ifdef SIZES_C64_ML32
    PatchAddrs ();
#endif

  /* allocate the RunVec */
#define RUNVEC_SZ	12
    ML_AllocWrite(msp,  0, MAKE_DESC(RUNVEC_SZ, DTAG_record));
    ML_AllocWrite(msp,  1, PTR_CtoML(array_v+1));
    ML_AllocWrite(msp,  2, PTR_CtoML(bind_cfun_v+1));
    ML_AllocWrite(msp,  3, PTR_CtoML(callc_v+1));
    ML_AllocWrite(msp,  4, PTR_CtoML(create_b_v+1));
    ML_AllocWrite(msp,  5, PTR_CtoML(create_r_v+1));
    ML_AllocWrite(msp,  6, PTR_CtoML(create_s_v+1));
    ML_AllocWrite(msp,  7, PTR_CtoML(create_v_v+1));
    ML_AllocWrite(msp,  8, PTR_CtoML(floor_v+1));
    ML_AllocWrite(msp,  9, PTR_CtoML(logb_v+1));
    ML_AllocWrite(msp, 10, PTR_CtoML(scalb_v+1));
    ML_AllocWrite(msp, 11, PTR_CtoML(try_lock_v+1));
    ML_AllocWrite(msp, 12, PTR_CtoML(unlock_v+1));
    RunVec = ML_Alloc(msp, RUNVEC_SZ);

  /* allocate the CStruct */
#define CSTRUCT_SZ	12
    ML_AllocWrite(msp,  0, MAKE_DESC(CSTRUCT_SZ, DTAG_record));
    ML_AllocWrite(msp,  1, RunVec);
    ML_AllocWrite(msp,  2, DivId);
    ML_AllocWrite(msp,  3, OverflowId);
    ML_AllocWrite(msp,  4, SysErrId);
    ML_AllocWrite(msp,  5, ProfCurrent);
    ML_AllocWrite(msp,  6, PollEvent);
    ML_AllocWrite(msp,  7, PollFreq);
    ML_AllocWrite(msp,  8, MLPollHandler);
    ML_AllocWrite(msp,  9, ActiveProcs);
    ML_AllocWrite(msp, 10, PervStruct);
    ML_AllocWrite(msp, 11, MLSignalHandler);
    ML_AllocWrite(msp, 12, ML_vector0);
    CStruct = ML_Alloc(msp, CSTRUCT_SZ);

  /* allocate 1-elem SRECORD just containing the CStruct */
    REC_ALLOC1(msp, RunTimeCompUnit, CStruct);

#ifdef ASM_MATH
#define MATHVEC_SZ	8
    ML_AllocWrite(msp,  0, MAKE_DESC(MATHVEC_SZ, DTAG_record));
    ML_AllocWrite(msp,  1, LnId);
    ML_AllocWrite(msp,  2, SqrtId);
    ML_AllocWrite(msp,  3, PTR_CtoML(arctan_v+1));
    ML_AllocWrite(msp,  4, PTR_CtoML(cos_v+1));
    ML_AllocWrite(msp,  5, PTR_CtoML(exp_v+1));
    ML_AllocWrite(msp,  6, PTR_CtoML(ln_v+1));
    ML_AllocWrite(msp,  7, PTR_CtoML(sin_v+1));
    ML_AllocWrite(msp,  8, PTR_CtoML(sqrt_v+1));
    MathVec = ML_Alloc(msp, MATHVEC_SZ);
#endif

} /* end of AllocGlobals */


/* RecordGlobals:
 *
 * Record all global symbols that may be referenced from the ML heap.
 */
void RecordGlobals ()
{
  /* Misc. */
    RecordCSymbol ("handle",		PTR_CtoML(handle_v+1));
    RecordCSymbol ("return",		PTR_CtoML(return_c));
#if (CALLEESAVE == 0)
    RecordCSymbol ("return_a",		PTR_CtoML(return_a));
#endif

  /* RunVec */
    RecordCSymbol ("RunVec.array",	PTR_CtoML(array_v+1));
    RecordCSymbol ("RunVec.bind_cfun",	PTR_CtoML(bind_cfun_v+1));
    RecordCSymbol ("RunVec.callc",	PTR_CtoML(callc_v+1));
    RecordCSymbol ("RunVec.create_b",	PTR_CtoML(create_b_v+1));
    RecordCSymbol ("RunVec.create_r",	PTR_CtoML(create_r_v+1));
    RecordCSymbol ("RunVec.create_s",	PTR_CtoML(create_s_v+1));
    RecordCSymbol ("RunVec.create_v",	PTR_CtoML(create_v_v+1));
    RecordCSymbol ("RunVec.floor",	PTR_CtoML(floor_v+1));
    RecordCSymbol ("RunVec.logb",	PTR_CtoML(logb_v+1));
    RecordCSymbol ("RunVec.scalb",	PTR_CtoML(scalb_v+1));
    RecordCSymbol ("RunVec.try_lock",	PTR_CtoML(try_lock_v+1));
    RecordCSymbol ("RunVec.unlock",	PTR_CtoML(unlock_v+1));

  /* CStruct */
    RecordCSymbol ("CStruct.DivId",		DivId);
    RecordCSymbol ("CStruct.OverflowId",	OverflowId);
    RecordCSymbol ("CStruct.SysErrId",		SysErrId);
    RecordCSymbol ("CStruct.machine_id",	PTR_CtoML(machine_id.s));
    RecordCSymbol ("CStruct.PervStruct",	PervStruct);
    RecordCSymbol ("CStruct.MLSignalHandler",	MLSignalHandler);
    RecordCSymbol ("CStruct.vector0",		ML_vector0);
    RecordCSymbol ("CStruct.profCurrent",	ProfCurrent);
    RecordCSymbol ("CStruct.MLPollHandler",     MLPollHandler);
    RecordCSymbol ("CStruct.pollEvent",		PollEvent);
    RecordCSymbol ("CStruct.pollFreq",		PollFreq);
    RecordCSymbol ("CStruct.activeProcs",	ActiveProcs);

  /* null string */
    RecordCSymbol ("string0",			ML_string0);

#if defined(ASM_MATH)
  /* MathVec */
    RecordCSymbol ("MathVec.LnId",	LnId);
    RecordCSymbol ("MathVec.SqrtId",	SqrtId);
    RecordCSymbol ("MathVec.arctan",	PTR_CtoML(arctan_v+1));
    RecordCSymbol ("MathVec.cos",	PTR_CtoML(cos_v+1));
    RecordCSymbol ("MathVec.exp",	PTR_CtoML(exp_v+1));
    RecordCSymbol ("MathVec.ln",	PTR_CtoML(ln_v+1));
    RecordCSymbol ("MathVec.sin",	PTR_CtoML(sin_v+1));
    RecordCSymbol ("MathVec.sqrt",	PTR_CtoML(sqrt_v+1));
#endif

} /* end of RecordGlobals. */

#ifdef SIZES_C64_ML32

/* PatchAddrs:
 *
 * On machines where the size of Addr_t is bigger than the size of an Word_t,
 * we need to dynamically patch the static ML objects.
 */
void PatchAddrs ()
{
    PATCH_ML_STRING(machine_id);

    PATCH_ML_EXNID(_Div);
    PATCH_ML_EXNID(_Overflow);
    PATCH_ML_EXNID(SysErr);

    PATCH_ASM_CLOSURE(array);
    PATCH_ASM_CLOSURE(bind_cfun);
    PATCH_ASM_CLOSURE(callc);
    PATCH_ASM_CLOSURE(create_b);
    PATCH_ASM_CLOSURE(create_r);
    PATCH_ASM_CLOSURE(create_s);
    PATCH_ASM_CLOSURE(create_v);
    PATCH_ASM_CLOSURE(floor);
    PATCH_ASM_CLOSURE(logb);
    PATCH_ASM_CLOSURE(scalb);
    PATCH_ASM_CLOSURE(try_lock);
    PATCH_ASM_CLOSURE(unlock);
    PATCH_ASM_CLOSURE(handle);

#if (CALLEESAVE <= 0)
    PATCH_ASM_CLOSURE(return);
    PATCH_ASM_CLOSURE(sigh_return);
#endif

} /* end of PatchAddrs */

#endif /* SIZES_C64_ML32 */