predef.icl 27.1 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
implementation module predef

Martijn Vervoort's avatar
Martijn Vervoort committed
3
import syntax, hashtable, type_io_common
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
4
5
6

::	PredefinedSymbols	:== {# PredefinedSymbol}

7
8
9
::	PredefinedSymbol = {
		pds_module	:: !Index,
		pds_def		:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
10
11
	}

12
13
14
15
16
17
cPredefinedModuleIndex :== 1

PD_StringTypeIndex :== 0
PD_Arity2TupleTypeIndex :== 8
PD_Arity32TupleTypeIndex :== 38

18
/* identifiers not present the hashtable */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
19
20
21

PD_PredefinedModule			:== 0

22
23
FirstTypePredefinedSymbolIndex:==PD_StringType; // to compute index in com_type_defs

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
24
25
PD_StringType				:== 1

26
27
28
29
30
31
32
PD_ListType :== 2
PD_StrictListType :== 3
PD_UnboxedListType :== 4
PD_TailStrictListType :== 5
PD_StrictTailStrictListType :== 6
PD_UnboxedTailStrictListType :== 7
PD_OverloadedListType :== 8
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
33

34
35
PD_Arity2TupleType			:== 9
PD_Arity32TupleType			:== 39
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
36

37
38
39
PD_LazyArrayType			:== 40
PD_StrictArrayType			:== 41
PD_UnboxedArrayType			:== 42
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
40

41
42
43
44
45
46
47
48
49
50
51
// constructors:

FirstConstructorPredefinedSymbolIndex :== PD_ConsSymbol; // to compute index in com_cons_defs

PD_ConsSymbol :== 43
PD_StrictConsSymbol :== 44
PD_UnboxedConsSymbol :== 45
PD_TailStrictConsSymbol :== 46
PD_StrictTailStrictConsSymbol :== 47
PD_UnboxedTailStrictConsSymbol :== 48
PD_OverloadedConsSymbol :== 49
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
PD_NilSymbol :== 50
PD_StrictNilSymbol :== 51
PD_UnboxedNilSymbol :== 52
PD_TailStrictNilSymbol :== 53
PD_StrictTailStrictNilSymbol :== 54
PD_UnboxedTailStrictNilSymbol :== 55
PD_OverloadedNilSymbol :== 56

PD_Arity2TupleSymbol		:== 57
PD_Arity32TupleSymbol		:== 87

// end constructors

PD_TypeVar_a0				:== 88
PD_TypeVar_a31				:== 119

/* Dynamics */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
70

71
72
73
74
PD_TypeCodeMember			:== 120
PD_DynamicTemp				:== 121
PD_DynamicValue				:== 122
PD_DynamicType				:== 123
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
75

76
/* identifiers present in the hashtable */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
77

78
79
80
PD_StdArray					:== 124
PD_StdEnum					:== 125
PD_StdBool					:== 126
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
81

82
83
PD_AndOp					:== 127
PD_OrOp						:== 128
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
84
85
86

/* Array functions */

87
PD_ArrayClass				:== 129
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
88

89
90
91
92
93
94
95
96
PD_CreateArrayFun			:== 130
PD__CreateArrayFun			:== 131
PD_ArraySelectFun			:== 132
PD_UnqArraySelectFun		:== 133
PD_ArrayUpdateFun			:== 134
PD_ArrayReplaceFun			:== 135
PD_ArraySizeFun				:== 136
PD_UnqArraySizeFun			:== 137
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
97
98
99

/* Enum/Comprehension functions */

100
PD_SmallerFun				:== 138
Artem Alimarine's avatar
Artem Alimarine committed
101
PD_LessOrEqualFun			:== 139
102
103
104
105
106
107
108
109
110
111
112
113
114
PD_IncFun					:== 140
PD_SubFun:== 141
PD_From						:== 142
PD_FromThen					:== 143
PD_FromTo					:== 144
PD_FromThenTo				:== 145

/* StdMisc */
PD_StdMisc					:== 146
PD_abort					:== 147
PD_undef					:== 148

PD_Start					:== 149
Artem Alimarine's avatar
Artem Alimarine committed
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
PD_DummyForStrictAliasFun	:== 150

PD_StdStrictLists:==151

PD_cons:==152
PD_decons:==153

PD_cons_u:==154
PD_decons_u:==155

PD_cons_uts:==156
PD_decons_uts:==157

PD_nil:==158
PD_nil_u:==159
PD_nil_uts:==160

PD_ListClass :== 161
PD_UListClass :== 162
PD_UTSListClass :== 163
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
136
137
138

/* Dynamics */

139
PD_StdDynamic				:== 164
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
140

141
142
143
144
145
146
PD_TypeCodeClass			:== 165
PD_TypeObjectType			:== 166
PD_TypeConsSymbol			:== 167
PD_unify					:== 168
PD_coerce					:== 169
PD_variablePlaceholder		:== 170
147
148
PD_UvariablePlaceholder		:== 171
PD_undo_indirections		:== 172
149

150
151
152
PD_TypeID					:== 173
PD_ModuleID					:== 174
PD_ModuleConsSymbol			:== 175
153

154
/* Generics */
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
PD_StdGeneric				:== 176

PD_TypeISO					:== 177
PD_ConsISO					:== 178
PD_iso_to					:== 179
PD_iso_from					:== 180

PD_TypeUNIT					:== 181
PD_ConsUNIT					:== 182
PD_TypeEITHER				:== 183
PD_ConsLEFT					:== 184
PD_ConsRIGHT				:== 185
PD_TypePAIR					:== 186
PD_ConsPAIR					:== 187
PD_TypeARROW				:== 188
PD_ConsARROW				:== 189

PD_TypeConsDefInfo			:== 190 
PD_ConsConsDefInfo			:== 191
PD_TypeTypeDefInfo			:== 192 
PD_ConsTypeDefInfo			:== 193
PD_cons_info				:== 194
PD_TypeCONS					:== 195
PD_ConsCONS					:== 196

PD_isomap_ARROW_			:== 197
PD_isomap_ID				:== 198

PD_TypeType					:== 199
PD_ConsTypeApp				:== 200
PD_ConsTypeVar				:== 201

PD_NrOfPredefSymbols		:== 202
188

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
189
(<<=) infixl
190
191
192
(<<=) symbol_table val
	:==	let (predefined_idents, index) = val
	  	in writePtr predefined_idents.[index].id_info EmptySymbolTableEntry symbol_table
193

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
194
(<<-) infixl
195
196
197
198
(<<-) hash_table val
	:== let (predefined_idents, table_kind, index) = val
		in putPredefinedIdentInHashTable predefined_idents.[index] table_kind hash_table

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
199
200
201
GetTupleConsIndex tup_arity :== PD_Arity2TupleSymbol + tup_arity - 2
GetTupleTypeIndex tup_arity :== PD_Arity2TupleType + tup_arity - 2

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
predefined_idents :: {!Ident}
predefined_idents
	# idents = createArray PD_NrOfPredefSymbols {id_name="",id_info=nilPtr}
	# idents = { idents &
					[PD_ConsSymbol] = i PD_ConsSymbol_String,
					[PD_StrictConsSymbol] = i "_!Cons",
					[PD_UnboxedConsSymbol] = i "_#Cons",
					[PD_TailStrictConsSymbol] = i "_Cons!",
					[PD_StrictTailStrictConsSymbol] = i "_!Cons!",
					[PD_UnboxedTailStrictConsSymbol] = i "_#Cons!",
					[PD_OverloadedConsSymbol] = i "_|Cons",
					[PD_NilSymbol] = i PD_NilSymbol_String,
					[PD_StrictNilSymbol] = i "_!Nil",
					[PD_UnboxedNilSymbol] = i "_#Nil",
					[PD_TailStrictNilSymbol] = 	i "_Nil!",
					[PD_StrictTailStrictNilSymbol] = i "_!Nil!",
					[PD_UnboxedTailStrictNilSymbol] = i "_#Nil!",
					[PD_OverloadedNilSymbol] = i "_|Nil",
			
					[PD_PredefinedModule] = i "_predefined",
					[PD_StringType] = i "_String",
					[PD_ListType] = i PD_ListType_String,
					[PD_StrictListType] = i "_!List",
					[PD_UnboxedListType] = i "_#List",
					[PD_TailStrictListType] = i "_List!",
					[PD_StrictTailStrictListType] = i "_!List!",
					[PD_UnboxedTailStrictListType] = i "_#List!",
					[PD_OverloadedListType] = i "_|List",
					[PD_LazyArrayType] = i "_Array",
					[PD_StrictArrayType] = i "_!Array",
					[PD_UnboxedArrayType] = i PD_UnboxedArray_String,
					[PD_TypeCodeMember] = i "_type_code",
					[PD_DummyForStrictAliasFun] = i "_dummyForStrictAlias"
				}
	# idents = build_tuples 2 32 idents
	# idents = build_variables 0 32 idents
	
	# idents = { idents &
					[PD_StdArray] = i "_SystemArray",
					[PD_StdEnum] = i "StdEnum",
					[PD_StdBool] = i "StdBool",
					[PD_AndOp] = i "&&",
					[PD_OrOp] = i "||",
					[PD_ArrayClass] = i "Array",
					[PD_CreateArrayFun] = i "createArray",
					[PD__CreateArrayFun] = i "_createArray",
					[PD_ArraySelectFun] = i "select",
					[PD_UnqArraySelectFun] = i "uselect",
					[PD_ArrayUpdateFun] = i "update",
					[PD_ArrayReplaceFun] = i "replace",
					[PD_ArraySizeFun] = i "size",
					[PD_UnqArraySizeFun] = i "usize",
				
					[PD_StdStrictLists] = i "StdStrictLists",
					[PD_cons] = i "cons",
					[PD_decons] = i "decons",
					[PD_nil] = i "nil",
				
					[PD_cons_u] = i "cons_u",
					[PD_decons_u] = i "decons_u",
					[PD_nil_u] = i "nil_u",
				
					[PD_cons_uts] = i "cons_uts",
					[PD_decons_uts] = i "decons_uts",
					[PD_nil_uts] = i "nil_uts",
		
					[PD_ListClass] = i "List",
					[PD_UListClass] = i "UList",
					[PD_UTSListClass] = i "UTSList",
					
					[PD_SmallerFun] = i "<",
					[PD_LessOrEqualFun] = i "<=",
					[PD_IncFun] = i "inc",
					[PD_SubFun] = i "-",
				
					[PD_From] = i "_from",
					[PD_FromThen] = i "_from_then",
					[PD_FromTo] = i "_from_to",
					[PD_FromThenTo] = i "_from_then_to",
					
					[PD_TypeCodeClass] = i "TC",
283
					[PD_TypeObjectType] = i T_ypeObjectTypeRepresentation_String,
284
285
					[PD_TypeConsSymbol] = i "T_ypeConsSymbol",
					[PD_variablePlaceholder] = i "P_laceholder",
286
					[PD_UvariablePlaceholder] = i "UP_laceholder",
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
					[PD_unify] = i "_unify",
					[PD_coerce] = i "_coerce",
					[PD_StdDynamic] = i UnderscoreSystemDynamicModule_String,
					[PD_undo_indirections] = i "_undo_indirections",
				
					[PD_DynamicTemp] = i DynamicRepresentation_String,
					[PD_ModuleConsSymbol] = i "__Module",
					[PD_TypeID] = i "T_ypeID",
					[PD_ModuleID] = i "ModuleID",
				
					[PD_StdGeneric] = i "StdGeneric",
					[PD_TypeISO] = i "ISO",
					[PD_ConsISO] = i "_ISO",
					[PD_TypeUNIT] = i "UNIT",
					[PD_ConsUNIT] = i "UNIT",
					[PD_TypeEITHER] = i "EITHER",
					[PD_ConsLEFT] = i "LEFT",
					[PD_ConsRIGHT] = i "RIGHT",
					[PD_TypePAIR] = i "PAIR",
					[PD_ConsPAIR] = i "PAIR",
					[PD_TypeARROW] = i "ARROW",
					[PD_ConsARROW] = i "ARROW",
					[PD_isomap_ARROW_] = i "isomap_ARROW_",
					[PD_isomap_ID] = i "isomap_ID",
					[PD_TypeConsDefInfo] = i "ConsDefInfo",
					[PD_ConsConsDefInfo] = i "_ConsDefInfo",
					[PD_TypeTypeDefInfo] = i "TypeDefInfo",
					[PD_ConsTypeDefInfo] = i "_TypeDefInfo",
					[PD_TypeCONS] = i "CONS",
					[PD_ConsCONS] = i "CONS",
					[PD_cons_info] = i "CONS_INFO",
					[PD_TypeType] = i "Type",
					[PD_ConsTypeApp] = i "TypeApp",
					[PD_ConsTypeVar] = i "TypeVar",
				
					[PD_StdMisc] = i "StdMisc",
					[PD_abort] = i "abort",
					[PD_undef] = i "undef",
					
					[PD_Start] = i "Start",
				
					[PD_iso_from] = i "iso_from",
					[PD_iso_to] = i "iso_to",
				
					[PD_DynamicType] = i "type",
					[PD_DynamicValue] = i "value"
		}
	=: idents
	where
		i s = { id_name = s, id_info = allocPtr };

		build_tuples tup_arity max_arity idents
			| tup_arity > max_arity
				= idents
				# tup_name = "_Tuple" +++ toString tup_arity
				# idents = {idents & [GetTupleTypeIndex tup_arity]=i tup_name, [GetTupleConsIndex tup_arity]=i tup_name}
				= build_tuples (inc tup_arity) max_arity idents

		build_variables var_number max_arity idents
			| var_number == max_arity
				= idents
				# var_name = "a" +++ toString var_number
				# idents = {idents & [PD_TypeVar_a0 + var_number] = i var_name}
				= build_variables (inc var_number) max_arity idents

init_identifiers :: !*SymbolTable !*World -> (!*SymbolTable,!*World)
init_identifiers heap world
	# local_predefined_idents = predefined_idents
	# (heap,world) = init_predefined_idents 0 heap world
356
		with
357
358
359
360
361
362
363
364
			init_predefined_idents i heap world
				| i<size local_predefined_idents
					| size local_predefined_idents.[i].id_name>0
						# (heap,world) = initPtr local_predefined_idents.[i].id_info EmptySymbolTableEntry heap world
						= init_predefined_idents (i+1) heap world
						= init_predefined_idents (i+1) heap world
					= (heap,world)
	= (heap,world)
365

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
366
367
buildPredefinedSymbols :: !*HashTable -> (!.PredefinedSymbols,!*HashTable)
buildPredefinedSymbols hash_table=:{hte_symbol_heap}
368
369
370
	# predef_symbol_table = createArray PD_NrOfPredefSymbols { pds_module = NoIndex, pds_def = NoIndex }
	  hte_symbol_heap = fill_table_without_hashing hte_symbol_heap
	= (predef_symbol_table,fill_table_with_hashing { hash_table & hte_symbol_heap = hte_symbol_heap })
371
where
372
	local_predefined_idents = predefined_idents
373
	
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
	fill_table_without_hashing hash_table
		= build_variables 0 32 (build_tuples 2 32 hash_table)
			<<= (local_predefined_idents, PD_PredefinedModule)
			<<= (local_predefined_idents, PD_StringType)
			<<= (local_predefined_idents, PD_ListType) <<= (local_predefined_idents, PD_ConsSymbol)<<= (local_predefined_idents, PD_NilSymbol)
			<<= (local_predefined_idents, PD_StrictListType) <<= (local_predefined_idents, PD_StrictConsSymbol) <<= (local_predefined_idents, PD_StrictNilSymbol)
			<<= (local_predefined_idents, PD_UnboxedListType) <<= (local_predefined_idents, PD_UnboxedConsSymbol) <<= (local_predefined_idents, PD_UnboxedNilSymbol)
			<<= (local_predefined_idents, PD_TailStrictListType) <<= (local_predefined_idents, PD_TailStrictConsSymbol) <<= (local_predefined_idents, PD_TailStrictNilSymbol)
			<<= (local_predefined_idents, PD_StrictTailStrictListType) <<= (local_predefined_idents, PD_StrictTailStrictConsSymbol) <<= (local_predefined_idents, PD_StrictTailStrictNilSymbol)
			<<= (local_predefined_idents, PD_UnboxedTailStrictListType) <<= (local_predefined_idents, PD_UnboxedTailStrictConsSymbol) <<= (local_predefined_idents, PD_UnboxedTailStrictNilSymbol)
			<<= (local_predefined_idents, PD_OverloadedListType) <<= (local_predefined_idents, PD_OverloadedConsSymbol) <<= (local_predefined_idents, PD_OverloadedNilSymbol)
			<<= (local_predefined_idents, PD_LazyArrayType)
			<<= (local_predefined_idents, PD_StrictArrayType)
			<<= (local_predefined_idents, PD_UnboxedArrayType)
			<<= (local_predefined_idents, PD_TypeCodeMember)
			<<= (local_predefined_idents, PD_DummyForStrictAliasFun) // MW++
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
390
	where
391
		build_tuples tup_arity max_arity hash_table
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
392
			| tup_arity > max_arity
393
394
395
				= hash_table
				= build_tuples (inc tup_arity) max_arity (hash_table <<= (local_predefined_idents, GetTupleTypeIndex tup_arity)
						<<= (local_predefined_idents, GetTupleConsIndex tup_arity))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
396

397
		build_variables var_number max_arity hash_table
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
398
			| var_number == max_arity
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
				= hash_table
				= build_variables (inc var_number) max_arity (hash_table <<= (local_predefined_idents, PD_TypeVar_a0 + var_number))

	fill_table_with_hashing hash_table
		# hash_table = hash_table
					<<- (local_predefined_idents, IC_Module, PD_StdArray)
					<<- (local_predefined_idents, IC_Module, PD_StdEnum)
					<<- (local_predefined_idents, IC_Module, PD_StdBool)
					<<- (local_predefined_idents, IC_Expression, PD_AndOp)
					<<- (local_predefined_idents, IC_Expression, PD_OrOp)
					<<- (local_predefined_idents, IC_Class, PD_ArrayClass)
					<<- (local_predefined_idents, IC_Expression, PD_CreateArrayFun)
					<<- (local_predefined_idents, IC_Expression, PD__CreateArrayFun)
					<<- (local_predefined_idents, IC_Expression, PD_ArraySelectFun)
					<<- (local_predefined_idents, IC_Expression, PD_UnqArraySelectFun)
					<<- (local_predefined_idents, IC_Expression, PD_ArrayUpdateFun)
					<<- (local_predefined_idents, IC_Expression, PD_ArrayReplaceFun)
					<<- (local_predefined_idents, IC_Expression, PD_ArraySizeFun)
					<<- (local_predefined_idents, IC_Expression, PD_UnqArraySizeFun)

					<<- (local_predefined_idents, IC_Module, PD_StdStrictLists)
					<<- (local_predefined_idents, IC_Expression, PD_cons)
					<<- (local_predefined_idents, IC_Expression, PD_decons)
					<<- (local_predefined_idents, IC_Expression, PD_nil)

					<<- (local_predefined_idents, IC_Expression, PD_cons_u)
					<<- (local_predefined_idents, IC_Expression, PD_decons_u)
					<<- (local_predefined_idents, IC_Expression, PD_nil_u)

					<<- (local_predefined_idents, IC_Expression, PD_cons_uts)
					<<- (local_predefined_idents, IC_Expression, PD_decons_uts)
					<<- (local_predefined_idents, IC_Expression, PD_nil_uts)

					<<- (local_predefined_idents, IC_Class, PD_ListClass)
					<<- (local_predefined_idents, IC_Class, PD_UListClass)
					<<- (local_predefined_idents, IC_Class, PD_UTSListClass)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
435
					
436
437
438
439
440
441
442
443
444
					<<- (local_predefined_idents, IC_Expression, PD_SmallerFun)
					<<- (local_predefined_idents, IC_Expression, PD_LessOrEqualFun)
					<<- (local_predefined_idents, IC_Expression, PD_IncFun)
					<<- (local_predefined_idents, IC_Expression, PD_SubFun)

					<<- (local_predefined_idents, IC_Expression, PD_From)
					<<- (local_predefined_idents, IC_Expression, PD_FromThen)
					<<- (local_predefined_idents, IC_Expression, PD_FromTo)
					<<- (local_predefined_idents, IC_Expression, PD_FromThenTo)
445
					
446
447
448
449
					<<- (local_predefined_idents,					 IC_Class, PD_TypeCodeClass)
					<<- (local_predefined_idents,		IC_Type, PD_TypeObjectType)
					<<- (local_predefined_idents,		IC_Expression, PD_TypeConsSymbol)
					<<- (local_predefined_idents,		IC_Expression, PD_variablePlaceholder)
450
					<<- (local_predefined_idents,		IC_Expression, PD_UvariablePlaceholder)
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
					<<- (local_predefined_idents,				IC_Expression, PD_unify)
					<<-	(local_predefined_idents,				IC_Expression, PD_coerce) /* MV */
					<<- (local_predefined_idents,		IC_Module, PD_StdDynamic)
					<<- (local_predefined_idents,	IC_Expression, PD_undo_indirections)

					<<- (local_predefined_idents,			IC_Type, PD_DynamicTemp)
					<<- (local_predefined_idents,			IC_Expression, PD_ModuleConsSymbol)
					<<- (local_predefined_idents,				IC_Type, PD_TypeID)
					<<- (local_predefined_idents,			IC_Expression, PD_ModuleID)

					<<- (local_predefined_idents,			IC_Module, 		PD_StdGeneric)
					<<- (local_predefined_idents,					IC_Type, 		PD_TypeISO)
					<<- (local_predefined_idents,				IC_Expression, 	PD_ConsISO)					
					<<- (local_predefined_idents,				IC_Type, 		PD_TypeUNIT)
					<<- (local_predefined_idents,				IC_Expression,	PD_ConsUNIT)
					<<- (local_predefined_idents,				IC_Type, 		PD_TypeEITHER)
					<<- (local_predefined_idents,				IC_Expression,	PD_ConsLEFT)
					<<- (local_predefined_idents,				IC_Expression,	PD_ConsRIGHT)
					<<- (local_predefined_idents,				IC_Type, 		PD_TypePAIR)					
					<<- (local_predefined_idents,				IC_Expression,	PD_ConsPAIR)					
					<<- (local_predefined_idents,				IC_Type, 		PD_TypeARROW)
					<<- (local_predefined_idents,				IC_Expression, 	PD_ConsARROW)										
					<<- (local_predefined_idents,		IC_Expression, 	PD_isomap_ARROW_)										
					<<- (local_predefined_idents,			IC_Expression, 	PD_isomap_ID)										
					<<- (local_predefined_idents,			IC_Type, 		PD_TypeConsDefInfo)					
					<<- (local_predefined_idents,		IC_Expression,	PD_ConsConsDefInfo)					
					<<- (local_predefined_idents,			IC_Type, 		PD_TypeTypeDefInfo)					
					<<- (local_predefined_idents,		IC_Expression,	PD_ConsTypeDefInfo)					
					<<- (local_predefined_idents,				IC_Type, 		PD_TypeCONS)					
					<<- (local_predefined_idents,				IC_Expression,	PD_ConsCONS)					
					<<- (local_predefined_idents,			IC_Expression, 	PD_cons_info)										
					<<- (local_predefined_idents,				IC_Type, 		PD_TypeType)										
					<<- (local_predefined_idents,				IC_Expression, 	PD_ConsTypeApp)										
					<<- (local_predefined_idents,				IC_Expression, 	PD_ConsTypeVar)										

					<<- (local_predefined_idents,				IC_Module, 		PD_StdMisc)
					<<- (local_predefined_idents,				IC_Expression, 	PD_abort)
					<<- (local_predefined_idents,				IC_Expression, 	PD_undef)					
489
					
490
					<<- (local_predefined_idents,				IC_Expression, PD_Start)
491

492
493
494
495
		# type_iso_ident = local_predefined_idents.[PD_TypeISO]
		# hash_table= hash_table 
					<<- (local_predefined_idents, IC_Field type_iso_ident, PD_iso_from)
					<<- (local_predefined_idents, IC_Field type_iso_ident, PD_iso_to)
496

497
498
499
500
501
502
		# dynamic_temp_ident = local_predefined_idents.[PD_DynamicTemp]
		# hash_table = hash_table 
					<<- (local_predefined_idents, IC_Field dynamic_temp_ident, PD_DynamicType)
					<<- (local_predefined_idents, IC_Field dynamic_temp_ident, PD_DynamicValue)

		= hash_table
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
503

504
MakeTupleConsSymbIndex arity 	:== arity - 2 + (PD_Arity2TupleSymbol-FirstConstructorPredefinedSymbolIndex)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
505
506
507
508
509
510
511
512
513

MaxTupleArity				:== 32

cTCClassSymbIndex			:== 0

cTCMemberSymbIndex			:== 0

cTCInstanceSymbIndex		:== 0

514
515
make_type_def :: !Int ![TypeVar] !a !*{#PredefinedSymbol} -> (!TypeDef a,!.{#PredefinedSymbol})
make_type_def type_cons_index type_vars type_rhs pre_def_symbols
516
517
	# type_cons_ident = predefined_idents.[type_cons_index]
	= (MakeTypeDef type_cons_ident (map (\tv -> MakeAttributedTypeVar tv) type_vars) type_rhs TA_None [] NoPos, pre_def_symbols)
518

519
520
make_list_definition :: Int Int Int Ident TypeVar AType StrictnessList *{#PredefinedSymbol} -> (!TypeDef TypeRhs,!ConsDef,!ConsDef,!.{#PredefinedSymbol})
make_list_definition list_type_pre_def_symbol_index cons_pre_def_symbol_index nil_pre_def_symbol_index pre_mod_id type_var type_var_with_attr cons_strictness pre_def_symbols
521
522
523
524
525
526
	# cons_ident = predefined_idents.[cons_pre_def_symbol_index]
	  nil_ident = predefined_idents.[nil_pre_def_symbol_index]
	  list_ident = predefined_idents.[list_type_pre_def_symbol_index] 
	  
	  cons_symb = { ds_ident = cons_ident, ds_arity = 2, ds_index = cons_pre_def_symbol_index-FirstConstructorPredefinedSymbolIndex }
	  nil_symb = { ds_ident = nil_ident, ds_arity=0 ,ds_index = nil_pre_def_symbol_index-FirstConstructorPredefinedSymbolIndex }
527
	  (list_def, pre_def_symbols) = make_type_def list_type_pre_def_symbol_index [type_var] (AlgType [cons_symb,nil_symb]) pre_def_symbols	
528
529
	  list_type = MakeAttributedType (TA (MakeNewTypeSymbIdent list_ident 1) [type_var_with_attr])
	  cons_def = {	pc_cons_name = cons_ident, pc_cons_arity = 2, pc_arg_types = [type_var_with_attr, list_type],
530
531
				 	pc_args_strictness=cons_strictness,	pc_cons_prio =  NoPrio, pc_exi_vars = [], pc_cons_pos = PreDefPos pre_mod_id}
	  nil_def = {	pc_cons_name = nil_ident, pc_cons_arity = 0, pc_arg_types = [], pc_args_strictness=NotStrict,
532
533
534
	  				pc_cons_prio =  NoPrio, pc_exi_vars = [], pc_cons_pos = PreDefPos pre_mod_id}
	= (list_def,ParsedConstructorToConsDef cons_def,ParsedConstructorToConsDef nil_def,pre_def_symbols);

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
535
536
buildPredefinedModule :: !*PredefinedSymbols -> (!ScannedModule, !.PredefinedSymbols)
buildPredefinedModule pre_def_symbols 
537
538
539
540
541
542
543
	# type_var_ident = predefined_idents.[PD_TypeVar_a0]
	  string_ident = predefined_idents.[PD_StringType]
	  unb_array_ident = predefined_idents.[PD_UnboxedArrayType]
	  pre_mod_ident = predefined_idents.[PD_PredefinedModule]
	  alias_dummy_ident = predefined_idents.[PD_DummyForStrictAliasFun]

	  type_var						= MakeTypeVar type_var_ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
544
	  type_var_with_attr			= MakeAttributedType (TV type_var)
545
	  unb_arr_of_char_type			= MakeAttributedType (TA (MakeNewTypeSymbIdent unb_array_ident 1) [MakeAttributedType (TB BT_Char)])
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
546
547
548

	  (string_def, pre_def_symbols)	= make_type_def PD_StringType [] (SynType unb_arr_of_char_type) pre_def_symbols
	
549
	  (list_def,cons_def,nil_def,pre_def_symbols)
550
		= make_list_definition PD_ListType PD_ConsSymbol PD_NilSymbol pre_mod_ident type_var type_var_with_attr NotStrict pre_def_symbols
551
	  (strict_list_def,strict_cons_def,strict_nil_def,pre_def_symbols)
552
		= make_list_definition PD_StrictListType PD_StrictConsSymbol PD_StrictNilSymbol pre_mod_ident type_var type_var_with_attr (Strict 1) pre_def_symbols
553
	  (unboxed_list_def,unboxed_cons_def,unboxed_nil_def,pre_def_symbols)
554
		= make_list_definition PD_UnboxedListType PD_UnboxedConsSymbol PD_UnboxedNilSymbol pre_mod_ident type_var type_var_with_attr (Strict 1) pre_def_symbols
555
	  (tail_strict_list_def,tail_strict_cons_def,tail_strict_nil_def,pre_def_symbols)
556
		= make_list_definition PD_TailStrictListType PD_TailStrictConsSymbol PD_TailStrictNilSymbol pre_mod_ident type_var type_var_with_attr (Strict 2) pre_def_symbols
557
	  (strict_tail_strict_list_def,strict_tail_strict_cons_def,strict_tail_strict_nil_def,pre_def_symbols)
558
		= make_list_definition PD_StrictTailStrictListType PD_StrictTailStrictConsSymbol PD_StrictTailStrictNilSymbol pre_mod_ident type_var type_var_with_attr (Strict 3) pre_def_symbols
559
	  (unboxed_tail_strict_list_def,unboxed_tail_strict_cons_def,unboxed_tail_strict_nil_def,pre_def_symbols)
560
		= make_list_definition PD_UnboxedTailStrictListType PD_UnboxedTailStrictConsSymbol PD_UnboxedTailStrictNilSymbol pre_mod_ident type_var type_var_with_attr (Strict 3) pre_def_symbols
561
	  (overloaded_list_def,overloaded_cons_def,overloaded_nil_def,pre_def_symbols)
562
		= make_list_definition PD_OverloadedListType PD_OverloadedConsSymbol PD_OverloadedNilSymbol pre_mod_ident type_var type_var_with_attr NotStrict pre_def_symbols
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
563
564
565
566
567

	  (array_def, pre_def_symbols)		= make_type_def PD_LazyArrayType [type_var] (AbstractType cAllBitsClear) pre_def_symbols
	  (strict_def, pre_def_symbols)		= make_type_def PD_StrictArrayType [type_var] (AbstractType cIsHyperStrict) pre_def_symbols
	  (unboxed_def, pre_def_symbols)	= make_type_def PD_UnboxedArrayType [type_var] (AbstractType cIsHyperStrict) pre_def_symbols

568
569
	  (type_defs, cons_defs, pre_def_symbols)	= add_tuple_defs pre_mod_ident MaxTupleArity [array_def,strict_def,unboxed_def] [] pre_def_symbols
	  alias_dummy_type = make_identity_fun_type alias_dummy_ident type_var
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
570
	  (class_def, member_def, pre_def_symbols) = make_TC_class_def pre_def_symbols
571
	= ({ mod_name = pre_mod_ident, mod_modification_time = "", mod_type = MK_System, mod_imports = [],  mod_imported_objects = [],
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
572
		 mod_defs = {
573
574
575
576
			def_types = [string_def, list_def,strict_list_def,unboxed_list_def,tail_strict_list_def,strict_tail_strict_list_def,unboxed_tail_strict_list_def,overloaded_list_def : type_defs],
						def_constructors = [cons_def,strict_cons_def,unboxed_cons_def,tail_strict_cons_def,strict_tail_strict_cons_def,unboxed_tail_strict_cons_def,overloaded_cons_def,
											nil_def,strict_nil_def,unboxed_nil_def,tail_strict_nil_def,strict_tail_strict_nil_def,unboxed_tail_strict_nil_def,overloaded_nil_def : cons_defs],
						def_selectors = [], def_classes = [class_def],
577
			def_macro_indices= { ir_from = 0, ir_to = 0 },def_macros=[],def_members = [member_def], def_funtypes = [alias_dummy_type], def_instances = [], def_generics = [] }}, pre_def_symbols)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
578
where
579

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
580
581
582
	add_tuple_defs pre_mod_id tup_arity type_defs cons_defs pre_def_symbols
		| tup_arity >= 2
			# (type_vars, pre_def_symbols)		= make_type_vars tup_arity [] pre_def_symbols
583
584
			  tuple_ident = predefined_idents.[GetTupleConsIndex tup_arity]
			  tuple_cons_symb					= { ds_ident = tuple_ident, ds_index = MakeTupleConsSymbIndex tup_arity, ds_arity = tup_arity }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
585
586
			  
			  (tuple_type_def, pre_def_symbols)	= make_type_def (GetTupleTypeIndex tup_arity) type_vars (AlgType [tuple_cons_symb]) pre_def_symbols
587
			  tuple_cons_def	= { pc_cons_name = tuple_ident, pc_cons_arity = tup_arity, pc_cons_pos = PreDefPos pre_mod_id,
588
589
590
			  						pc_arg_types = [ MakeAttributedType (TV tv) \\ tv <- type_vars],
			  						pc_args_strictness = NotStrict,
			  						pc_cons_prio =  NoPrio, pc_exi_vars = []}
591
			= add_tuple_defs pre_mod_id (dec tup_arity) [tuple_type_def : type_defs] [ParsedConstructorToConsDef tuple_cons_def : cons_defs] pre_def_symbols
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
592
593
594
595
596
597
			= (type_defs, cons_defs, pre_def_symbols)
	where
		make_type_vars nr_of_vars type_vars pre_def_symbols
			| nr_of_vars == 0
				= (type_vars, pre_def_symbols)
				# nr_of_vars = dec nr_of_vars
598
599
				# var_ident = predefined_idents.[PD_TypeVar_a0 + nr_of_vars]
				= make_type_vars nr_of_vars [MakeTypeVar var_ident : type_vars] pre_def_symbols
600
		
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
601
	make_TC_class_def pre_def_symbols
602
603
604
		# tc_class_name = predefined_idents.[PD_TypeCodeClass]
		  type_var_ident = predefined_idents.[PD_TypeVar_a0]
		  tc_member_name = predefined_idents.[PD_TypeCodeMember]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
605
		
606
		  class_var = MakeTypeVar type_var_ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
607

608
609
		  me_type = { st_vars = [], st_args = [], st_args_strictness=NotStrict, st_arity = 0,
					  st_result = { at_attribute = TA_None, at_type = TV class_var },
610
					  st_context = [ {tc_class = {glob_module = NoIndex, glob_object = {ds_ident = tc_class_name, ds_arity = 1, ds_index = NoIndex }},
611
					   				tc_types = [ TV class_var ], tc_var = nilPtr}],
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
612
613
					  st_attr_vars = [], st_attr_env = [] }

614
		  member_def = { me_symb = tc_member_name, me_type = me_type, me_pos = NoPos, me_priority = NoPrio,
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
615
616
						 me_offset = NoIndex, me_class_vars = [], me_class = { glob_module = NoIndex, glob_object = NoIndex}, me_type_ptr = nilPtr }
		
617
618
619
		  class_def = { class_name = tc_class_name, class_arity = 1, class_args = [class_var], class_context = [],
		  				class_members = {{ds_ident = tc_member_name, ds_index = cTCMemberSymbIndex, ds_arity = 0 }}, class_cons_vars = 0,
						class_dictionary = { ds_ident = { tc_class_name & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex }, class_pos = NoPos,
620
						class_arg_kinds = [] }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
621
622
623

		= (class_def, member_def, pre_def_symbols)

624
625
// MW..
	make_identity_fun_type alias_dummy_id type_var
626
627
		# a = { at_attribute = TA_Anonymous, at_type = TV type_var }
		  id_symbol_type = { st_vars = [], st_args = [a], st_args_strictness = Strict 1, st_arity = 1, st_result = a, st_context = [], 
628
629
630
							st_attr_vars = [], st_attr_env = [] } // !.a -> .a
		= { ft_symb = alias_dummy_id, ft_arity = 1, ft_priority = NoPrio, ft_type = id_symbol_type, ft_pos = NoPos,
			ft_specials = SP_None, ft_type_ptr = nilPtr }
Martijn Vervoort's avatar
Martijn Vervoort committed
631
632
633
634
635
636

// changes requires recompile of {static,dynamic}-linker plus all dynamics ever made
UnderscoreSystemDynamicModule_String	:== "_SystemDynamic"	

DynamicRepresentation_String			:== "DynamicTemp"		

637
638
T_ypeObjectTypeRepresentation_String	:== "T_ypeObjectType"

Martijn Vervoort's avatar
Martijn Vervoort committed
639
640
641
642
643
644
645
646
647
// List-type
PD_ListType_String				:== "_List"
PD_ConsSymbol_String			:== "_Cons"
PD_NilSymbol_String				:== "_Nil"

// Array-type
PD_UnboxedArray_String			:== "_#Array"
// ... MV