Predefined.icl 12.3 KB
Newer Older
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
/*
** Program: Clean Prover System
** Module:  Predefined (.icl)
** 
** Author:  Maarten de Mol
** Created: 23 August 2000
**
** Remark: The variables occuring in a tuple{type/build/select}, are SHARED for all
**         arities!!!!
*/

implementation module 
	Predefined

import
	StdEnv,
	CoreTypes,
	Heaps

// -------------------------------------------------------------------------------------------------------------------------------------------------
CTuple :: !*CHeaps -> (!CArity -> CAlgTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CTuple heaps
	# tvar_defs				= [{tvarName = "t" +++ (toString num), tvarInfo = DummyValue} \\ num <- [1..32]]
	# (tvar_ptrs, heaps)	= newPointers tvar_defs heaps
	= (tuple tvar_ptrs, heaps)
	where
		tuple :: ![CTypeVarPtr] !CArity -> CAlgTypeDefH
		tuple tvars arity
			=	{ atdName			= "_Tuple_" +++ (toString arity)
				, atdArity			= arity
				, atdTypeVarScope	= take arity tvars
				, atdConstructors	= [CBuildTuplePtr arity]
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CNormalArray :: !*CHeaps -> (!CAlgTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CNormalArray heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (array tvar_ptr, heaps)
	where
		array :: !CTypeVarPtr -> CAlgTypeDefH
		array tvar
			=	{ atdName			= "{}"
				, atdArity			= 1
				, atdTypeVarScope	= [tvar]
				, atdConstructors	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CStrictArray :: !*CHeaps -> (!CAlgTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CStrictArray heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (array tvar_ptr, heaps)
	where
		array :: !CTypeVarPtr -> CAlgTypeDefH
		array tvar
			=	{ atdName			= "{!}"
				, atdArity			= 1
				, atdTypeVarScope	= [tvar]
				, atdConstructors	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CUnboxedArray :: !*CHeaps -> (!CAlgTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CUnboxedArray heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (array tvar_ptr, heaps)
	where
		array :: !CTypeVarPtr -> CAlgTypeDefH
		array tvar
			=	{ atdName			= "{#}"
				, atdArity			= 1
				, atdTypeVarScope	= [tvar]
				, atdConstructors	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CList :: !*CHeaps -> (!CAlgTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CList heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (list tvar_ptr, heaps)
	where
		list :: !CTypeVarPtr -> CAlgTypeDefH
		list tvar
			=	{ atdName			= "[]"
				, atdArity			= 1
				, atdTypeVarScope	= [tvar]
				, atdConstructors	= [CNilPtr, CConsPtr]
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CBuildTuple :: !*CHeaps -> (!CArity -> CDataConsDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CBuildTuple heaps
	# tvar_defs				= [{tvarName = "t" +++ toString num, tvarInfo = DummyValue} \\ num <- [1..32]]
	# (tvar_ptrs, heaps)	= newPointers tvar_defs heaps
	# evar_defs				= [{evarName = "t" +++ toString num, evarInfo = DummyValue} \\ num <- [1..32]]
	# (evar_ptrs, heaps)	= newPointers evar_defs heaps
	= (build_tuple tvar_ptrs evar_ptrs, heaps)
	where
		build_tuple :: ![CTypeVarPtr] ![CExprVarPtr] !CArity -> CDataConsDefH
		build_tuple tvars evars arity
			# types			= map CTypeVar tvars
			=	{ dcdName			= "_Tuple_" +++ (toString arity)
				, dcdArity			= arity
				, dcdAlgType		= CTuplePtr arity
				, dcdInfix			= CNoInfix
				, dcdSymbolType		= 	{ sytTypeVarScope		= take arity tvars
										, sytArguments			= take arity types
										, sytResult				= CTuplePtr arity @@^ (take arity types)
										, sytClassRestrictions	= []
										}
				, dcdTypeVarScope	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CNil :: !*CHeaps -> (!CDataConsDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CNil heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (nil tvar_ptr, heaps)
	where
		nil :: !CTypeVarPtr -> CDataConsDefH
		nil var
			=	{ dcdName			= "_Nil"
				, dcdArity			= 0
				, dcdAlgType		= CListPtr
				, dcdInfix			= CNoInfix
				, dcdSymbolType		=	{ sytTypeVarScope		= [var]
										, sytArguments			= []
										, sytResult				= CListPtr @@^ [CTypeVar var]
										, sytClassRestrictions	= []
										}
				, dcdTypeVarScope	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CCons :: !*CHeaps -> (!CDataConsDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CCons heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (cons tvar_ptr, heaps)
	where
		cons :: !CTypeVarPtr -> CDataConsDefH
		cons var
			=	{ dcdName			= "_Cons"
				, dcdArity			= 2
				, dcdAlgType		= CListPtr
				, dcdInfix			= CNotAssociative 9
				, dcdSymbolType		=	{ sytTypeVarScope		= [var]
										, sytArguments			= [CTypeVar var, CListPtr @@^ [CTypeVar var]]
										, sytResult				= CListPtr @@^ [CTypeVar var]
										, sytClassRestrictions	= []
										}
				, dcdTypeVarScope	= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CTupleSelect :: !*CHeaps -> (!CArity Int -> CFunDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CTupleSelect heaps
	# tvar_defs				= [{tvarName = "t" +++ (toString num), tvarInfo = DummyValue} \\ num <- [1..32]]
	# (tvar_ptrs, heaps)	= newPointers tvar_defs heaps
	# evar_def				= {evarName = "_tuple", evarInfo = DummyValue}
	# (evar_ptr, heaps)		= newPointer evar_def heaps
	# evar_defs				= [{evarName = "e" +++ (toString num), evarInfo = DummyValue} \\ num <- [1..32]]
	# (evar_ptrs, heaps)	= newPointers evar_defs heaps
	= (tuple_select tvar_ptrs evar_ptr evar_ptrs, heaps)
	where
		tuple_select :: ![CTypeVarPtr] !CExprVarPtr ![CExprVarPtr] !CArity !Int -> CFunDefH
		tuple_select tvars tuple_var component_vars arity index
			# types			= map CTypeVar tvars
			=	{ fdName				= "_tupleselect_" +++ (toString arity) +++ "_" +++ (toString index)
				, fdOldName				= ""
				, fdArity				= 1
				, fdCaseVariables		= [0]
				, fdStrictVariables		= [0]
				, fdInfix				= CNoInfix
				, fdSymbolType			=	{ sytArguments			= [CTuplePtr arity @@^ (take arity types)]
											, sytTypeVarScope		= take arity tvars
											, sytResult				= types !! (index-1)
											, sytClassRestrictions	= []
											}
				, fdHasType				= True
				, fdExprVarScope		= [tuple_var]
				, fdBody				= CCase (CExprVar tuple_var) 
												(CAlgPatterns (CTuplePtr arity)
												[	{ atpDataCons		= CBuildTuplePtr arity
													, atpExprVarScope	= take arity component_vars
													, atpResult			= CExprVar (component_vars !! (index-1))
													}
												]
											) Nothing
				, fdIsRecordSelector	= False
				, fdIsRecordUpdater		= False
				, fdNrDictionaries		= 0
				, fdRecordFieldDef		= DummyValue
				, fdDeltaRule			= Nothing
				, fdOpaque				= False
				, fdHalting				= False
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CTC :: !*CHeaps -> (!CClassDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CTC heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (tc tvar_ptr, heaps)
	where
		tc :: !CTypeVarPtr -> CClassDefH
		tc tvar
			=	{ cldName				= "TC"
				, cldArity				= 1
				, cldTypeVarScope		= [tvar]
				, cldClassRestrictions	= []
				, cldMembers			= []
				, cldDictionary			= CTCDictPtr
				, cldInstances			= []
				}

// -------------------------------------------------------------------------------------------------------------------------------------------------
CTCDict :: !*CHeaps -> (!CRecordTypeDefH, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
CTCDict heaps
	# tvar_def				= {tvarName = "a", tvarInfo = DummyValue}
	# (tvar_ptr, heaps)		= newPointer tvar_def heaps
	= (tc_dict tvar_ptr, heaps)
	where
		tc_dict :: !CTypeVarPtr -> CRecordTypeDefH
		tc_dict tvar
			=	{ rtdName				= "dictionary_TC"
				, rtdArity				= 1
				, rtdTypeVarScope		= [tvar]
				, rtdFields				= []
				, rtdRecordConstructor	= DummyValue
				, rtdIsDictionary		= True
				, rtdClassDef			= CTCPtr
				}












// -------------------------------------------------------------------------------------------------------------------------------------------------
CPredefined :: CModule
// -------------------------------------------------------------------------------------------------------------------------------------------------
CPredefined
	=	{ pmName				= "_Predefined"
		, pmPath				= "-"
		, pmImportedModules		= []
		, pmAlgTypePtrs			= [CListPtr, CNormalArrayPtr, CStrictArrayPtr, CUnboxedArrayPtr] ++ 
								  [CTuplePtr arity \\ arity <- [2..32]]
		, pmClassPtrs			= [CTCPtr]
		, pmDataConsPtrs		= [CNilPtr, CConsPtr] ++ 
								  [CBuildTuplePtr arity \\ arity <- [2..32]]
		, pmFunPtrs				= [CTupleSelectPtr arity index \\ arity <- [2..32], index <- [1..arity]]
		, pmInstancePtrs		= []
		, pmMemberPtrs			= []
		, pmRecordFieldPtrs		= []
		, pmRecordTypePtrs		= [CTCDictPtr]
		, pmCompilerStore		= Nothing
		, pmCompilerConversion	= DummyValue
282
		, pmOriginalNrDclConses	= DummyValue
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
		}

// -------------------------------------------------------------------------------------------------------------------------------------------------
buildPredefined :: !*CHeaps -> (!CPredefined, !*CHeaps)
// -------------------------------------------------------------------------------------------------------------------------------------------------
buildPredefined heaps
	# (preTuple, heaps)			= CTuple heaps
	# (preNormalArray, heaps)	= CNormalArray heaps
	# (preStrictArray, heaps)	= CStrictArray heaps
	# (preUnboxedArray, heaps)	= CUnboxedArray heaps
	# (preList, heaps)			= CList heaps
	# (preBuildTuple, heaps)	= CBuildTuple heaps
	# (preCons, heaps)			= CCons heaps
	# (preNil, heaps)			= CNil heaps
	# (preTupleSelect, heaps)	= CTupleSelect heaps
	# (preTC, heaps)			= CTC heaps
	# (preTCDict, heaps)		= CTCDict heaps
	= (	{ preTuple			= preTuple
		, preNormalArray	= preNormalArray
		, preStrictArray	= preStrictArray
		, preUnboxedArray	= preUnboxedArray
		, preList			= preList
		, preBuildTuple		= preBuildTuple
		, preCons			= preCons
		, preNil			= preNil
		, preTupleSelect	= preTupleSelect
		, preTC				= preTC
		, preTCDict			= preTCDict
		}, heaps)