backendconvert.icl 60.9 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
3
4
5
6
7
8
9
10
11
implementation module backendconvert

import code from library "backend_library"

import StdEnv

import frontend
import backend
import backendsupport, backendpreprocess
import RWSDebug

clean's avatar
clean committed
12
13
14
15
// trace macro
(-*->) infixl
(-*->) value trace
	:==	value // ---> trace
16
17
18
19
20
21
22
23
24
25
26
27
/*
sfoldr op r l
	:== foldr l
	where
		foldr [] = r
		foldr [a:x] = \s -> op a (foldr x) s
*/
sfoldr op r l s
	:== foldr l s
	where
		foldr [] = r
		foldr [a:x] = op a (foldr x)
clean's avatar
clean committed
28

29
:: BEMonad a :== St !*BackEndState !a
clean's avatar
clean committed
30

31
:: BackEnder :== *BackEndState -> *BackEndState
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
32

33
34
//
:: *BackEndState = {bes_backEnd :: !BackEnd, bes_varHeap :: !*VarHeap}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
35

36
37
38
39
appBackEnd f beState
	:== {beState & bes_backEnd = bes_backEnd}
	where
		bes_backEnd = f beState.bes_backEnd
40

41
42
43
44
45
46
47
accBackEnd f beState
	:== accBackEnd
	where
		accBackEnd
			# (result, bes_backEnd) =	f beState.bes_backEnd
			#! beState2 = {beState & bes_backEnd = bes_backEnd}
			= (result,beState2)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
48

49
50
accVarHeap f beState
	:== (result, {beState & bes_varHeap = varHeap})
51
	where
52
		(result, varHeap) =	f beState.bes_varHeap
53

54
55
56
57
read_from_var_heap ptr _ beState
	= (result, {beState & bes_varHeap = varHeap})
where
		(result, varHeap) =	readPtr ptr beState.bes_varHeap
58

59
60
61
62
63
write_to_var_heap ptr v beState
	= {beState & bes_varHeap = writePtr ptr v beState.bes_varHeap}
/*
read_from_var_heap ptr heap be
	= (sreadPtr ptr heap,be)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
64

65
66
67
68
::	*BackEndState :== BackEnd

appBackEnd f beState :== f beState
accBackEnd f beState :== f beState
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
69
accVarHeap f beState :== f beState
70
*/
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
71

72
beApFunction0 f
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
73
	:== appBackEnd f
74
beApFunction1 f m1
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
75
76
	:== m1 ==> \a1
	->	appBackEnd (f a1)
77
beApFunction2 f m1 m2
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
78
79
80
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	appBackEnd (f a1 a2)
81
beApFunction3 f m1 m2 m3
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
82
83
84
85
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	appBackEnd (f a1 a2 a3)
86
beApFunction4 f m1 m2 m3 m4
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
87
88
89
90
91
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	appBackEnd (f a1 a2 a3 a4)
92
beApFunction5 f m1 m2 m3 m4 m5
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
93
94
95
96
97
98
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	appBackEnd (f a1 a2 a3 a4 a5)
99
beApFunction6 f m1 m2 m3 m4 m5 m6
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
100
101
102
103
104
105
106
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	m6 ==> \a6
	->	appBackEnd (f a1 a2 a3 a4 a5 a6)
107
beApFunction7 f m1 m2 m3 m4 m5 m6 m7
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
108
109
110
111
112
113
114
115
116
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	m6 ==> \a6
	->	m7 ==> \a7
	->	appBackEnd (f a1 a2 a3 a4 a5 a6 a7)

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
beFunction0 f
	:== accBackEnd f
beFunction1 f m1
	:== m1 ==> \a1
	->	accBackEnd (f a1)
beFunction2 f m1 m2
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	accBackEnd (f a1 a2)
beFunction3 f m1 m2 m3
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	accBackEnd (f a1 a2 a3)
beFunction4 f m1 m2 m3 m4
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	accBackEnd (f a1 a2 a3 a4)
beFunction5 f m1 m2 m3 m4 m5
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	accBackEnd (f a1 a2 a3 a4 a5)
beFunction6 f m1 m2 m3 m4 m5 m6
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	m6 ==> \a6
	->	accBackEnd (f a1 a2 a3 a4 a5 a6)
beFunction7 f m1 m2 m3 m4 m5 m6 m7
	:== m1 ==> \a1
	->	m2 ==> \a2
	->	m3 ==> \a3
	->	m4 ==> \a4
	->	m5 ==> \a5
	->	m6 ==> \a6
	->	m7 ==> \a7
	->	accBackEnd (f a1 a2 a3 a4 a5 a6 a7)

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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
changeArrayFunctionIndex selectIndex
	:== selectIndex

beBoolSymbol value
	:==	beFunction0 (BEBoolSymbol value)
beLiteralSymbol type value
	:==	beFunction0 (BELiteralSymbol type value)
beFunctionSymbol functionIndex moduleIndex
	:==	beFunction0 (BEFunctionSymbol functionIndex moduleIndex)
beSpecialArrayFunctionSymbol arrayFunKind functionIndex moduleIndex
	:==	beFunction0 (BESpecialArrayFunctionSymbol arrayFunKind (changeArrayFunctionIndex functionIndex) moduleIndex)
beDictionarySelectFunSymbol
	:==	beFunction0 BEDictionarySelectFunSymbol
beDictionaryUpdateFunSymbol
	:==	beFunction0 BEDictionaryUpdateFunSymbol
beConstructorSymbol moduleIndex constructorIndex
	:==	beFunction0 (BEConstructorSymbol constructorIndex moduleIndex)
beFieldSymbol fieldIndex moduleIndex
	:==	beFunction0 (BEFieldSymbol fieldIndex moduleIndex)
beTypeSymbol typeIndex moduleIndex
	:==	beFunction0 (BETypeSymbol typeIndex moduleIndex)
beBasicSymbol typeSymbolIndex
	:==	beFunction0 (BEBasicSymbol typeSymbolIndex)
beDontCareDefinitionSymbol
	:==	beFunction0 BEDontCareDefinitionSymbol
beNoArgs
	:==	beFunction0 BENoArgs
beArgs
	:==	beFunction2 BEArgs
beNoTypeArgs
	:==	beFunction0 BENoTypeArgs
beTypeArgs
	:==	beFunction2 BETypeArgs
beNormalNode
	:==	beFunction2 BENormalNode
beIfNode
	:==	beFunction3 BEIfNode
beGuardNode
	:==	beFunction7 BEGuardNode
beSelectorNode selectorKind
	:==	beFunction2 (BESelectorNode selectorKind)
beUpdateNode
	:==	beFunction1 BEUpdateNode
beNormalTypeNode
	:==	beFunction2 BENormalTypeNode
beVarTypeNode name
	:==	beFunction0 (BEVarTypeNode name)
beRuleAlt lineNumber
	:==	beFunction5 (BERuleAlt lineNumber)
beNoRuleAlts
	:==	beFunction0 BENoRuleAlts
beRuleAlts
	:==	beFunction2 BERuleAlts
beTypeAlt
	:==	beFunction2 BETypeAlt
beRule index isCaf
	:==	beFunction2 (BERule index isCaf)
beNoRules
	:==	beFunction0 BENoRules
beRules
	:==	beFunction2 BERules
beNodeDef sequenceNumber
	:==	beFunction1 (BENodeDef sequenceNumber)
beNoNodeDefs
	:==	beFunction0 BENoNodeDefs
beNodeDefs
	:==	beFunction2 BENodeDefs
beStrictNodeId
	:==	beFunction1 BEStrictNodeId
beNoStrictNodeIds
	:==	beFunction0 BENoStrictNodeIds
beStrictNodeIds
	:==	beFunction2 BEStrictNodeIds
beNodeIdNode
	:==	beFunction2 BENodeIdNode
beNodeId sequenceNumber
	:==	beFunction0 (BENodeId sequenceNumber)
beWildCardNodeId
	:==	beFunction0 BEWildCardNodeId
beConstructor
	:==	beFunction1 BEConstructor
beNoConstructors
	:==	beFunction0 BENoConstructors
beConstructors
	:==	beFunction2 BEConstructors
beNoFields
	:==	beFunction0 BENoFields
beFields
	:==	beFunction2 BEFields
beField fieldIndex moduleIndex 
	:==	beFunction1 (BEField fieldIndex moduleIndex)
beAnnotateTypeNode annotation
	:==	beFunction1 (BEAnnotateTypeNode annotation)
beAttributeTypeNode attribution
	:==	beFunction1 (BEAttributeTypeNode attribution)
beDeclareRuleType functionIndex moduleIndex name
258
	:==	beApFunction0 (BEDeclareRuleType functionIndex moduleIndex name)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
259
beDefineRuleType functionIndex moduleIndex
260
	:==	beApFunction1 (BEDefineRuleType functionIndex moduleIndex)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
beCodeAlt lineNumber
	:==	beFunction3 (BECodeAlt lineNumber)
beString string
	:==	beFunction0 (BEString string)
beStrings
	:==	beFunction2 BEStrings
beNoStrings
	:==	beFunction0 BENoStrings
beCodeParameter location
	:==	beFunction1 (BECodeParameter location)
beCodeParameters
	:==	beFunction2 BECodeParameters
beNoCodeParameters
	:==	beFunction0 BENoCodeParameters
beAbcCodeBlock inline
	:==	beFunction1 (BEAbcCodeBlock inline)
beAnyCodeBlock
	:==	beFunction3 BEAnyCodeBlock
beDeclareNodeId number lhsOrRhs name
280
281
282
	:==	beApFunction0 (BEDeclareNodeId number lhsOrRhs name)
beAdjustArrayFunction backendId functionIndex moduleIndex
	:==	beApFunction0 (BEAdjustArrayFunction backendId functionIndex moduleIndex)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
283
284
285
286
287
288
289
290
beFlatType
	:==	beFunction2 BEFlatType
beNoTypeVars
	:==	beFunction0 BENoTypeVars
beTypeVars
	:==	beFunction2 BETypeVars
beTypeVar name
	:==	beFunction0 (BETypeVar name)
clean's avatar
clean committed
291
beExportType dclTypeIndex iclTypeIndex
292
	:==	beApFunction0 (BEExportType dclTypeIndex iclTypeIndex)
clean's avatar
clean committed
293
beExportConstructor dclConstructorIndex iclConstructorIndex
294
	:==	beApFunction0 (BEExportConstructor dclConstructorIndex iclConstructorIndex)
clean's avatar
clean committed
295
beExportField dclFieldIndex iclFieldIndex
296
	:==	beApFunction0 (BEExportField dclFieldIndex iclFieldIndex)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
297
beExportFunction dclIndexFunctionIndex iclFunctionIndex
298
	:==	beApFunction0 (BEExportFunction dclIndexFunctionIndex iclFunctionIndex)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
299
300
301
302
303
beTupleSelectNode arity index
	:==	beFunction1 (BETupleSelectNode arity index)
beMatchNode arity
	:==	beFunction2 (BEMatchNode arity)
beDefineImportedObjsAndLibs
304
	:== beApFunction2 BEDefineImportedObjsAndLibs
clean's avatar
clean committed
305
beAbsType
306
	:== beApFunction1 BEAbsType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
307
308
309
310
311

notYetImplementedExpr :: Expression
notYetImplementedExpr
	=	(BasicExpr (BVS "\"error in compiler (something was not implemented by lazy Ronny)\"") BT_Int)

312
313
314
315
316
317
318
319
320
321
backEndConvertModules :: PredefinedSymbols FrontEndSyntaxTree !Int *VarHeap *BackEnd -> (!*VarHeap,!*BackEnd)
/*
backEndConvertModules p s main_dcl_module_n v be
	= (newHeap,backEndConvertModulesH p s v be)
*/
backEndConvertModules p s main_dcl_module_n var_heap be
	# {bes_varHeap,bes_backEnd} = backEndConvertModulesH p s main_dcl_module_n newHeap {bes_varHeap=var_heap,bes_backEnd=be}
	= (bes_varHeap,bes_backEnd)

backEndConvertModulesH :: PredefinedSymbols FrontEndSyntaxTree !Int VarHeap *BackEndState -> *BackEndState
clean's avatar
clean committed
322
backEndConvertModulesH predefs {fe_icl = fe_icl =: {icl_name, icl_functions, icl_common,icl_imported_objects,icl_used_module_numbers}, fe_components, fe_dcls, fe_arrayInstances, fe_dclIclConversions, fe_iclDclConversions,fe_globalFunctions} main_dcl_module_n varHeap backEnd
323
	// sanity check ...
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
324
325
326
327
328
329
330
//	| cIclModIndex <> kIclModuleIndex || cPredefinedModuleIndex <> kPredefinedModuleIndex
//		=	undef <<- "backendconvert, backEndConvertModules: module index mismatch"
	// ... sanity check
/*
	#  backEnd
		=	ruleDoesNotMatch 1 backEnd
			with
331
332
				ruleDoesNotMatch 0 backEnd
					=	backEnd
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
333
334
335
	#  backEnd
		=	abort "front end abort" backEnd
*/
336
337
338
339
	#! backEnd = appBackEnd (BESetMainDclModuleN main_dcl_module_n) backEnd
	#! backEnd
		=	appBackEnd (BEDeclareModules (size fe_dcls)) backEnd
	#! backEnd
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
340
		=	predefineSymbols fe_dcls.[cPredefinedModuleIndex] predefs backEnd
clean's avatar
clean committed
341
342

	#  currentDcl
343
	   	=	fe_dcls.[main_dcl_module_n]
clean's avatar
clean committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
	   typeConversions
		=	currentModuleTypeConversions icl_common.com_class_defs currentDcl.dcl_common.com_class_defs currentDcl.dcl_conversions
/*
	# 	rstypes = reshuffleTypes (size icl_common.com_type_defs) typeConversions {type.td_name.id_name \\ type <-: currentDcl.dcl_common.com_type_defs}
		types = {type.td_name.id_name \\ type <-: icl_common.com_type_defs}
	#  backEnd
		=	backEnd ->>
				(	"dcl conversions"
				,	currentDcl.dcl_conversions
				,	"dcl constructors"
				,	[constructor.cons_symb.id_name \\ constructor <-: currentDcl.dcl_common.com_cons_defs]
				,	"dcl selectors"
				,	[selector.sd_symb.id_name \\ selector <-: currentDcl.dcl_common.com_selector_defs]
				,	"dcl types"
				,	[type.td_name.id_name \\ type <-: currentDcl.dcl_common.com_type_defs]
				,	"icl selectors"
				,	[constructor.cons_symb.id_name \\ constructor <-: icl_common.com_cons_defs]
				,	"icl fields"
				,	[selector.sd_symb.id_name \\ selector <-: icl_common.com_selector_defs]
				,	"icl types"
				,	[type.td_name.id_name \\ type <-: icl_common.com_type_defs]
				,	"compare names"
				,	(rstypes, types)
				)
*/
369
370
371
372
373
374
375
	#! backEnd
		=	declareCurrentDclModule fe_icl fe_dcls.[main_dcl_module_n] main_dcl_module_n (backEnd -*-> "declareCurrentDclModule")
	#! backEnd
		=	declareOtherDclModules fe_dcls main_dcl_module_n icl_used_module_numbers (backEnd -*-> "declareOtherDclModules")
	#! backEnd
		=	defineDclModule varHeap main_dcl_module_n fe_dcls.[main_dcl_module_n] (backEnd -*-> "defineDclModule(cIclMoIndex)")
	#! backEnd
clean's avatar
clean committed
376
		=	reshuffleTypes (size icl_common.com_type_defs) typeConversions (backEnd -*-> "reshuffleTypes")
377
378
	#! backEnd
		=	defineOtherDclModules fe_dcls main_dcl_module_n icl_used_module_numbers varHeap (backEnd -*-> "defineOtherDclModules")
clean's avatar
clean committed
379

380
381
382
	#! backEnd
		=	appBackEnd (BEDeclareIclModule icl_name.id_name (size icl_functions) (size icl_common.com_type_defs) (size icl_common.com_cons_defs) (size icl_common.com_selector_defs)) (backEnd -*-> "BEDeclareIclModule")
	#! backEnd
383
		=	declareFunctionSymbols icl_functions (getConversions fe_iclDclConversions) functionIndices fe_globalFunctions (backEnd -*-> "declareFunctionSymbols")
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
384
385
386
387
388
389
		with
			getConversions :: (Optional {#Int}) -> {#Int}
			getConversions No
				=	{}
			getConversions (Yes conversions)
				=	conversions
390
391
392
393
394
	#! backEnd
		=	declare main_dcl_module_n varHeap icl_common (backEnd -*-> "declare (main_dcl_module_n)")
	#! backEnd
		=	declareArrayInstances fe_arrayInstances main_dcl_module_n icl_functions (backEnd -*-> "declareArrayInstances")
	#! backEnd
clean's avatar
clean committed
395
		=	adjustArrayFunctions predefs fe_arrayInstances main_dcl_module_n icl_functions fe_dcls icl_common.com_instance_defs icl_used_module_numbers varHeap (backEnd -*-> "adjustArrayFunctions")
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
396
	#! (rules, backEnd)
397
398
399
		=	convertRules [(index, icl_functions.[index]) \\ (_, index) <- functionIndices] main_dcl_module_n predefs.[PD_DummyForStrictAliasFun].pds_ident varHeap (backEnd -*-> "convertRules")
	#! backEnd
		=	appBackEnd (BEDefineRules rules) (backEnd -*-> "BEDefineRules")
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
400
401
402
403
	#! backEnd
		=	beDefineImportedObjsAndLibs
				(convertStrings [imported.io_name \\ imported <- icl_imported_objects | not imported.io_is_library])
				(convertStrings [imported.io_name \\ imported <- icl_imported_objects | imported.io_is_library])
clean's avatar
clean committed
404
				(backEnd -*-> "beDefineImportedObjsAndLibs")
405
406
	#! backEnd
		=	markExports fe_dcls.[main_dcl_module_n] dcl_common.com_class_defs dcl_common.com_type_defs icl_common.com_class_defs icl_common.com_type_defs fe_dclIclConversions (backEnd -*-> "markExports")
clean's avatar
clean committed
407
408
409
			with
				dcl_common
					=	currentDcl.dcl_common
410
411
	#! backEnd = removeExpandedTypesFromDclModules fe_dcls icl_used_module_numbers backEnd
	=	(backEnd -*-> "backend done")
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
412
413
414
415
416
417
	where
		componentCount
			=	length functionIndices
		functionIndices
			=	flatten [[(componentIndex, member) \\ member <- group.group_members] \\ group <-: fe_components & componentIndex <- [0..]]

418
declareOtherDclModules :: {#DclModule} Int NumberSet -> BackEnder
419
declareOtherDclModules dcls main_dcl_module_n used_module_numbers
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
420
	=	foldStateWithIndexA declareOtherDclModule dcls
421
422
423
where
	declareOtherDclModule :: ModuleIndex DclModule -> BackEnder
	declareOtherDclModule moduleIndex dclModule
424
		| moduleIndex == main_dcl_module_n || moduleIndex == cPredefinedModuleIndex || not (inNumberSet moduleIndex used_module_numbers)
425
426
427
428
			=	identity
		// otherwise
			=	declareDclModule moduleIndex dclModule

429
defineOtherDclModules :: {#DclModule} Int NumberSet VarHeap -> BackEnder
430
defineOtherDclModules dcls main_dcl_module_n used_module_numbers varHeap
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
431
	=	foldStateWithIndexA (defineOtherDclModule varHeap) dcls
432
433
434
where
	defineOtherDclModule :: VarHeap ModuleIndex DclModule -> BackEnder
	defineOtherDclModule varHeap moduleIndex dclModule
435
		| moduleIndex == main_dcl_module_n || moduleIndex == cPredefinedModuleIndex || not (inNumberSet moduleIndex used_module_numbers)
436
437
438
439
440
441
442
			=	identity
		// otherwise
			=	defineDclModule varHeap moduleIndex dclModule

declareCurrentDclModule :: IclModule DclModule Int -> BackEnder
declareCurrentDclModule {icl_common} {dcl_name, dcl_functions, dcl_is_system, dcl_common} main_dcl_module_n
	=	appBackEnd (BEDeclareDclModule main_dcl_module_n dcl_name.id_name dcl_is_system (size dcl_functions) (size icl_common.com_type_defs) (size dcl_common.com_cons_defs) (size dcl_common.com_selector_defs))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
443
	
444
declareDclModule :: ModuleIndex DclModule -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
445
declareDclModule moduleIndex {dcl_name, dcl_common, dcl_functions, dcl_is_system}
446
447
	=	appBackEnd (BEDeclareDclModule moduleIndex dcl_name.id_name dcl_is_system (size dcl_functions) (size dcl_common.com_type_defs) (size dcl_common.com_cons_defs) (size dcl_common.com_selector_defs))
/*
448
defineCurrentDclModule :: VarHeap IclModule DclModule {#Int} -> BackEnder
clean's avatar
clean committed
449
450
defineCurrentDclModule varHeap {icl_common} {dcl_name, dcl_common, dcl_functions, dcl_is_system, dcl_conversions} typeConversions
	=	declareCurrentDclModuleTypes icl_common.com_type_defs typeConversions varHeap
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
451
	o`	defineCurrentDclModuleTypes dcl_common.com_cons_defs dcl_common.com_selector_defs dcl_common.com_type_defs typeConversions varHeap
452
*/
453
defineDclModule :: VarHeap ModuleIndex DclModule -> BackEnder
454
defineDclModule varHeap moduleIndex {dcl_name, dcl_common, dcl_functions, dcl_is_system,dcl_instances}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
455
	=	declare moduleIndex varHeap dcl_common
456
457
	o`	declareFunTypes moduleIndex dcl_functions dcl_instances.ir_from  varHeap

458
removeExpandedTypesFromDclModules :: {#DclModule} NumberSet -> BackEnder
459
460
461
462
463
removeExpandedTypesFromDclModules dcls used_module_numbers
	=	foldStateWithIndexA removeExpandedTypesFromDclModule dcls
where
	removeExpandedTypesFromDclModule :: ModuleIndex DclModule -> BackEnder
	removeExpandedTypesFromDclModule moduleIndex dclModule=:{dcl_functions}
464
		| moduleIndex == cPredefinedModuleIndex || not (inNumberSet moduleIndex used_module_numbers)
465
466
467
468
469
470
471
472
473
474
475
			= identity
			= foldStateWithIndexA (removeExpandedTypesFromFunType moduleIndex)  dcl_functions
			where
				removeExpandedTypesFromFunType :: ModuleIndex Index FunType -> BackEnder
				removeExpandedTypesFromFunType moduleIndex functionIndex {ft_symb, ft_type_ptr}
					= \be0 ->	let (ft_type,be) = read_from_var_heap ft_type_ptr 0 be0 in
						(case ft_type of
							VI_ExpandedType expandedType
								->	write_to_var_heap ft_type_ptr VI_Empty	
							_
								->	identity) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
476

clean's avatar
clean committed
477
478
479
480
// move types from their dcl to icl positions

class swapTypes a :: Int Int *a -> *a

481
482
instance swapTypes BackEndState where
//instance swapTypes BackEnd where
clean's avatar
clean committed
483
	swapTypes i j be
484
		=	appBackEnd (BESwapTypes i j) be
clean's avatar
clean committed
485
486
487
488
489
490
491
492
493
494
495
496

instance swapTypes {{#Char}} where
	swapTypes i j a
		=	swap i j a

swap i j a
	#! iValue = a.[i]
	#! jValue = a.[j]
	=	{a & [i] = jValue, [j] = iValue}

reshuffleTypes :: Int {#Int} *a -> *a | swapTypes a
reshuffleTypes nIclTypes dclIclConversions be
clean's avatar
clean committed
497
	=	thd3 (foldStateWithIndexA (swapType nDclTypes) dclIclConversions (idP nDclTypes, idP nIclTypes, be))
clean's avatar
clean committed
498
	where
clean's avatar
clean committed
499
500
501
		nDclTypes
			=	size dclIclConversions

clean's avatar
clean committed
502
503
504
505
		idP :: Int -> .{#Int}
		idP n
			=	{i \\ i <- [0 .. n-1]}

clean's avatar
clean committed
506
507
		swapType :: Int Int Int (*{#Int}, *{#Int},  *a) -> (*{#Int}, *{#Int},  *a) | swapTypes a
		swapType nDclTypes dclIndex iclIndex state=:(p,p`,be)
clean's avatar
clean committed
508
509
510
511
512
513
514
515
516
			#! frm
				=	p.[dclIndex]
			#! to
				=	iclIndex
			| frm == to
				=	state
			// otherwise
				#! frm` = dclIndex
				#! to` = p`.[iclIndex]
clean's avatar
clean committed
517
				#! to` = if (to` >= nDclTypes) frm` to`
clean's avatar
clean committed
518
519
				=	(swap frm` to` p, swap frm to p`, swapTypes frm to be)

520
521
:: DeclVarsInput :== (!Ident, !VarHeap)

522
class declareVars a :: a !DeclVarsInput -> BackEnder
523
524

instance declareVars [a] | declareVars a where
525
	declareVars :: [a] !DeclVarsInput -> BackEnder | declareVars a
526
527
528
529
530
531
532
533
	declareVars list dvInput
		=	foldState (flip declareVars dvInput) list

instance declareVars (Ptr VarInfo) where
	declareVars varInfoPtr (_, varHeap)
		=	declareVariable BELhsNodeId varInfoPtr "_var???" varHeap	// +++ name

instance declareVars FreeVar where
534
	declareVars :: FreeVar !DeclVarsInput -> BackEnder
535
536
537
	declareVars freeVar (_, varHeap)
		=	declareVariable BELhsNodeId freeVar.fv_info_ptr freeVar.fv_name.id_name varHeap

538
539
540
541
542
543
// MW0instance declareVars (Bind Expression FreeVar) where
instance declareVars LetBind where
// MW0	declareVars :: (Bind Expression FreeVar) !DeclVarsInput -> BackEnder
	declareVars :: LetBind !DeclVarsInput -> BackEnder
// MW0	declareVars {bind_src=App {app_symb, app_args=[Var _:_]}, bind_dst=freeVar} (aliasDummyId, varHeap)
	declareVars {lb_src=App {app_symb, app_args=[Var _:_]}, lb_dst=freeVar} (aliasDummyId, varHeap)
544
545
546
		| app_symb.symb_name==aliasDummyId
			= identity		// we have an alias. Don't declare the same variable twice
		= declareVariable BERhsNodeId freeVar.fv_info_ptr freeVar.fv_name.id_name varHeap
547
548
// MW0	declareVars {bind_dst=freeVar} (_, varHeap)
	declareVars {lb_dst=freeVar} (_, varHeap)
549
550
		= declareVariable BERhsNodeId freeVar.fv_info_ptr freeVar.fv_name.id_name varHeap

551
declareVariable :: Int (Ptr VarInfo) {#Char} VarHeap -> BackEnder
552
declareVariable lhsOrRhs varInfoPtr name varHeap
553
554
	= \be0 -> let (variable_sequence_number,be) = getVariableSequenceNumber varInfoPtr varHeap be0 in
		beDeclareNodeId variable_sequence_number lhsOrRhs name be
555
556

instance declareVars (Optional a) | declareVars a where
557
	declareVars :: (Optional a) !DeclVarsInput -> BackEnder | declareVars a
558
559
560
561
562
563
	declareVars (Yes x) dvInput
		=	declareVars x dvInput
	declareVars No _
		=	identity

instance declareVars FunctionPattern where
564
	declareVars :: FunctionPattern !DeclVarsInput -> BackEnder
565
566
567
568
569
570
571
572
573
574
575
	declareVars (FP_Algebraic _ freeVars optionalVar) dvInput
		=	declareVars freeVars dvInput
		o`	declareVars optionalVar dvInput
	declareVars (FP_Variable freeVar) dvInput
		=	declareVars freeVar dvInput
	declareVars (FP_Basic _ optionalVar) dvInput
		=	declareVars optionalVar dvInput
	declareVars FP_Empty dvInput
		=	identity

instance declareVars Expression where
576
	declareVars :: Expression !DeclVarsInput -> BackEnder
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
	declareVars (Let {let_strict_binds, let_lazy_binds, let_expr}) dvInput
		=	declareVars let_strict_binds dvInput
		o`	declareVars let_lazy_binds dvInput
		o`	declareVars let_expr dvInput
	declareVars (Conditional {if_then, if_else}) dvInput
		=	declareVars if_then dvInput
		o`	declareVars if_else dvInput
	declareVars (AnyCodeExpr _ outParams _) (_, varHeap)
		=	foldState (declVar varHeap) outParams 
	  where
		declVar varHeap {bind_dst=freeVar} 
			= declareVariable BERhsNodeId freeVar.fv_info_ptr freeVar.fv_name.id_name varHeap
	declareVars _ _
		=	identity

instance declareVars TransformedBody where
593
	declareVars :: TransformedBody !DeclVarsInput -> BackEnder
594
595
596
597
598
	declareVars {tb_args, tb_rhs} dvInput
		=	declareVars tb_args dvInput
		o`	declareVars tb_rhs dvInput

instance declareVars BackendBody where
599
	declareVars :: BackendBody !DeclVarsInput -> BackEnder
600
601
602
603
	declareVars {bb_args, bb_rhs} dvInput
		=	declareVars bb_args dvInput
		o`	declareVars bb_rhs dvInput

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
604
605
:: ModuleIndex :== Index

606
class declare a :: ModuleIndex !VarHeap a  -> BackEnder
607

608
class declareWithIndex a :: Index ModuleIndex !VarHeap a -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
609

610
//1.3
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
611
instance declare {#a} | declareWithIndex a & ArrayElem a where
612
	declare :: ModuleIndex  VarHeap {#a} -> BackEnder | declareWithIndex a & ArrayElem a 
613
614
615
//3.1
/*2.0
instance declare {#a} | declareWithIndex a & Array {#} a where
616
	declare :: ModuleIndex  VarHeap {#a} -> BackEnder | declareWithIndex a & Array {#} a 
617
0.2*/
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
618
619
620
	declare moduleIndex varHeap array
		=	foldStateWithIndexA (\i -> declareWithIndex i moduleIndex varHeap) array

621
declareFunctionSymbols :: {#FunDef} {#Int} [(Int, Int)] IndexRange *BackEndState -> *BackEndState
622
declareFunctionSymbols functions iclDclConversions functionIndices globalFunctions backEnd
623
	=	foldr (declare iclDclConversions) backEnd [(functionIndex, componentIndex, functions.[functionIndex]) \\ (componentIndex, functionIndex) <- functionIndices]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
624
625
	where
		declare iclDclConversions (functionIndex, componentIndex, function) backEnd
626
627
			=	appBackEnd (BEDeclareFunction (functionName function.fun_symb.id_name functionIndex iclDclConversions globalFunctions) 
					function.fun_arity functionIndex componentIndex) backEnd
628
629
630
			where
				functionName :: {#Char} Int {#Int} IndexRange -> {#Char}
				functionName name functionIndex iclDclConversions {ir_from, ir_to}
clean's avatar
clean committed
631
//				| trace_t ("|"+++toString functionIndex)
632
633
634
635
					| functionIndex >= ir_to || functionIndex < ir_from
						=	(name +++ ";" +++ toString iclDclConversions.[functionIndex])
					// otherwise
						=	name
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
636
637
638
639
640
641
642
643
644
645
646
647

// move to backendsupport
foldStateWithIndexRangeA function frm to array
	:== foldStateWithIndexRangeA frm
	where
		foldStateWithIndexRangeA index
			| index == to
				=	identity
			// otherwise
				=	function index array.[index]
				o`	foldStateWithIndexRangeA (index+1)

648
649
declareArrayInstances :: IndexRange Int {#FunDef} -> BackEnder
declareArrayInstances {ir_from, ir_to} main_dcl_module_n functions
clean's avatar
clean committed
650
//	| trace_tn ("declareArrayInstances "+++toString ir_from+++" "+++toString ir_to)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
651
652
	=	foldStateWithIndexRangeA declareArrayInstance ir_from ir_to functions
	where
653
		declareArrayInstance :: Index FunDef -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
654
		declareArrayInstance index {fun_symb={id_name}, fun_type=Yes type}
655
656
			=	beDeclareRuleType index main_dcl_module_n (id_name +++ ";" +++ toString index)
			o`	beDefineRuleType index main_dcl_module_n (convertTypeAlt index main_dcl_module_n type)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
657
658

instance declare CommonDefs where
659
	declare :: ModuleIndex VarHeap CommonDefs -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
660
661
662
663
	declare moduleIndex varHeap {com_cons_defs, com_type_defs, com_selector_defs, com_class_defs}
		=	declare moduleIndex varHeap com_type_defs
		o`	defineTypes moduleIndex com_cons_defs com_selector_defs com_type_defs varHeap

clean's avatar
clean committed
664
instance declareWithIndex (TypeDef a) where
665
	declareWithIndex :: Index ModuleIndex VarHeap (TypeDef a) -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
666
	declareWithIndex typeIndex moduleIndex _ {td_name}
667
		=	appBackEnd (BEDeclareType typeIndex moduleIndex td_name.id_name)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
668

669
declareFunTypes :: ModuleIndex {#FunType} Int VarHeap -> BackEnder
670
671
declareFunTypes moduleIndex funTypes nrOfDclFunctions varHeap
		=	foldStateWithIndexA (declareFunType moduleIndex varHeap nrOfDclFunctions) funTypes
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
672

673
declareFunType :: ModuleIndex VarHeap Index Int FunType -> BackEnder
674
declareFunType moduleIndex varHeap nrOfDclFunctions functionIndex {ft_symb, ft_type_ptr}
675
676
677
678
	= \be0 -> let (vi,be) = read_from_var_heap ft_type_ptr varHeap be0 in
					(case vi of
						VI_ExpandedType expandedType
							->	beDeclareRuleType functionIndex moduleIndex (functionName ft_symb.id_name functionIndex nrOfDclFunctions)
clean's avatar
clean committed
679
//							->	beDeclareRuleType functionIndex moduleIndex (functionName moduleIndex ft_symb.id_name functionIndex nrOfDclFunctions)
680
681
682
							o`	beDefineRuleType functionIndex moduleIndex (convertTypeAlt functionIndex moduleIndex expandedType)
						_
							->	identity) be
683
		where
clean's avatar
clean committed
684
685
686
687
688
/*
			functionName :: Int {#Char} Int Int -> {#Char}
			functionName moduleIndex name functionIndex nrOfDclFunctions 
				| trace_t (":"+++toString moduleIndex+++" "+++toString functionIndex)
*/
689
690
691
692
693
694
			functionName :: {#Char} Int Int -> {#Char}
			functionName name functionIndex nrOfDclFunctions 
				| functionIndex < nrOfDclFunctions
					=	name
				// otherwise
					=	name +++ ";" +++ toString functionIndex
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738

currentModuleTypeConversions :: {#ClassDef} {#ClassDef} (Optional ConversionTable) -> {#Int}
currentModuleTypeConversions iclClasses dclClasses (Yes conversionTable)
	// sanity check ...
	| sort [dclClass.class_dictionary.ds_index \\ dclClass <-: dclClasses]
				<> [size typeConversions .. size typeConversions + size dclClasses - 1]
		=	abort "backendconvert, currentModuleTypeConversions wrong index range for dcl dictionary types"
	// ... sanity check
	| nDclClasses == 0
		=	typeConversions
	// otherwise
		=	{createArray (nDclTypes + nDclClasses) NoIndex
				& [i] = typeConversion
					\\ typeConversion <-: typeConversions & i <- [0..]}
			:-  foldStateWithIndexA (updateDictionaryTypeIndex classConversions) classConversions
	where
		typeConversions
			=	conversionTable.[cTypeDefs]
		nDclTypes
			=	size typeConversions
		classConversions
			=	conversionTable.[cClassDefs]
		nDclClasses
			=	size classConversions

		updateDictionaryTypeIndex :: {#Int} Int Int *{#Int} -> *{#Int}
		updateDictionaryTypeIndex classConversions dclClassIndex iclClassIndex allTypeConversions
			// sanity check ...
			# (oldIndex, allTypeConversions)
				=	uselect allTypeConversions dclTypeIndex
			| oldIndex <> NoIndex
				=	abort "backendconvert, updateDictionaryTypeIndex wrong index overwritten"
			// ... sanity chechk
			=	{allTypeConversions & [dclTypeIndex] = iclTypeIndex}
			where
				dclTypeIndex
					=	dclClasses.[dclClassIndex].class_dictionary.ds_index
				iclClassIndex
					=	classConversions.[dclClassIndex]
				iclTypeIndex
					=	iclClasses.[iclClassIndex].class_dictionary.ds_index
currentModuleTypeConversions _ _ No
	=	{}

739
/*
740
declareCurrentDclModuleTypes :: {#CheckedTypeDef} {#Int} VarHeap -> BackEnder
741
*/
742
defineTypes :: ModuleIndex {#ConsDef} {#SelectorDef} {#CheckedTypeDef} VarHeap -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
743
744
745
746
747
748
749
750
751
defineTypes moduleIndex constructors selectors types varHeap
	=	foldStateWithIndexA (defineType moduleIndex constructors selectors varHeap) types

convertTypeLhs :: ModuleIndex Index  [ATypeVar] -> BEMonad BEFlatTypeP
convertTypeLhs moduleIndex typeIndex args
	=	beFlatType (beTypeSymbol typeIndex moduleIndex) (convertTypeVars args)

convertTypeVars :: [ATypeVar] -> BEMonad BETypeVarListP
convertTypeVars typeVars
752
	=	sfoldr (beTypeVars o convertTypeVar) beNoTypeVars typeVars
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
753
754
755
756
757

convertTypeVar :: ATypeVar -> BEMonad BETypeVarP
convertTypeVar typeVar
	=	beTypeVar typeVar.atv_variable.tv_name.id_name

758
defineType :: ModuleIndex {#ConsDef} {#SelectorDef} VarHeap Index CheckedTypeDef *BackEndState -> *BackEndState
clean's avatar
clean committed
759
defineType moduleIndex constructors _ varHeap typeIndex {td_name, td_args, td_rhs=AlgType constructorSymbols} be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
760
761
762
	# (flatType, be)
		=	convertTypeLhs moduleIndex typeIndex td_args be
	# (constructors, be)
clean's avatar
clean committed
763
		=	convertConstructors typeIndex td_name.id_name moduleIndex constructors constructorSymbols varHeap be
764
	=	appBackEnd (BEAlgebraicType flatType constructors) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
765
766
767
768
769
defineType moduleIndex constructors selectors varHeap typeIndex {td_args, td_rhs=RecordType {rt_constructor, rt_fields}} be
	# (flatType, be)
		=	convertTypeLhs moduleIndex typeIndex td_args be
	# (fields, be)
		=	convertSelectors moduleIndex selectors rt_fields varHeap be
770
	# (constructorType,be) = constructorTypeFunction be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
771
772
773
774
775
	# (constructorTypeNode, be)
		=	beNormalTypeNode
				(beConstructorSymbol moduleIndex constructorIndex)
				(convertSymbolTypeArgs constructorType)
				be
776
	=	appBackEnd (BERecordType moduleIndex flatType constructorTypeNode fields) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
777
778
779
780
781
	where
		constructorIndex
			=	rt_constructor.ds_index
		constructorDef
			=	constructors.[constructorIndex]
782
783
784
785
786
787
788
		constructorTypeFunction be0
			= let (cons_type,be) = read_from_var_heap constructorDef.cons_type_ptr varHeap be0 in
					(case cons_type of
						VI_ExpandedType expandedType
							->	(expandedType,be)
						_
							->	(constructorDef.cons_type,be))
clean's avatar
clean committed
789
790
defineType moduleIndex _ _ _ typeIndex {td_args, td_rhs=AbstractType _} be
 	=	beAbsType (convertTypeLhs moduleIndex typeIndex td_args) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
791
792
793
defineType _ _ _ _ _ _ be
	=	be

clean's avatar
clean committed
794
795
convertConstructors :: Int {#Char} ModuleIndex {#ConsDef} [DefinedSymbol] VarHeap -> BEMonad BEConstructorListP
convertConstructors typeIndex typeName moduleIndex constructors symbols varHeap
796
	=	sfoldr (beConstructors o convertConstructor typeIndex typeName moduleIndex constructors varHeap) beNoConstructors symbols
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
797

clean's avatar
clean committed
798
799
convertConstructor :: Int {#Char} ModuleIndex {#ConsDef} VarHeap DefinedSymbol -> BEMonad BEConstructorListP
convertConstructor typeIndex typeName moduleIndex constructorDefs varHeap {ds_index}
800
801
802
	= \be0 -> let (constructorType,be) = constructorTypeFunction be0 in
		(appBackEnd (BEDeclareConstructor ds_index moduleIndex constructorDef.cons_symb.id_name) // +++ remove declare
		o`	beConstructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
803
804
			(beNormalTypeNode
				(beConstructorSymbol moduleIndex ds_index)
805
				(convertSymbolTypeArgs constructorType))) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
806
807
808
	where
		constructorDef
			=	constructorDefs.[ds_index]
809
810
811
812
813
814
815
		constructorTypeFunction be0
			= let (cons_type,be) = read_from_var_heap constructorDef.cons_type_ptr varHeap be0 in
					(case cons_type of
						VI_ExpandedType expandedType
							->	(expandedType,be) // ->> (typeName, typeIndex, constructorDef.cons_symb.id_name, ds_index, expandedType)
						_
							->	(constructorDef.cons_type,be)) // ->> (typeName, typeIndex, constructorDef.cons_symb.id_name, ds_index, constructorDef.cons_type)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
816
817
818
819
820
821
822

convertSelectors :: ModuleIndex {#SelectorDef} {#FieldSymbol} VarHeap -> BEMonad BEFieldListP
convertSelectors moduleIndex selectors symbols varHeap
	=	foldrA (beFields o convertSelector moduleIndex selectors varHeap) beNoFields symbols

convertSelector :: ModuleIndex {#SelectorDef} VarHeap FieldSymbol -> BEMonad BEFieldListP
convertSelector moduleIndex selectorDefs varHeap {fs_index}
823
824
825
	= \be0 -> let (selectorType,be) = selectorTypeFunction be0 in
		(	appBackEnd (BEDeclareField fs_index moduleIndex selectorDef.sd_symb.id_name)
		o`	beField fs_index moduleIndex (convertAnnotTypeNode (selectorType.st_result))) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
826
827
828
	where
		selectorDef
			=	selectorDefs.[fs_index]
829
830
831
		selectorTypeFunction be0
			= let (sd_type,be) = read_from_var_heap selectorDef.sd_type_ptr varHeap be0 in
				(case sd_type of
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
832
					VI_ExpandedType expandedType
833
						->	(expandedType,be)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
834
					_
835
						->	(selectorDef.sd_type,be))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
836

837
predefineSymbols :: DclModule PredefinedSymbols -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
838
predefineSymbols {dcl_common} predefs
839
	=	appBackEnd (BEDeclarePredefinedModule (size dcl_common.com_type_defs) (size dcl_common.com_cons_defs))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
840
841
842
843
844
845
846
847
	o`	foldState predefineType types
	o`	foldState predefineConstructor constructors
	where
		predefineType (index, arity, symbolKind)
			// sanity check ...
			| predefs.[index].pds_def == NoIndex
				=	abort "backendconvert, predefineSymbols predef is not a type"
			// ... sanity check
848
			=	appBackEnd (BEPredefineTypeSymbol arity predefs.[index].pds_def cPredefinedModuleIndex symbolKind)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
849
850
851
852
853
854

		predefineConstructor (index, arity, symbolKind)
			// sanity check ...
			| predefs.[index].pds_def == NoIndex
				=	abort "backendconvert, predefineSymbols predef is not a constructor"
			// ... sanity check
855
			=	appBackEnd (BEPredefineConstructorSymbol arity predefs.[index].pds_def cPredefinedModuleIndex symbolKind)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879

		types :: [(Int, Int, BESymbKind)]
		types
			=	[	(PD_ListType, 1, BEListType)
				,	(PD_LazyArrayType, 1, BEArrayType)
				,	(PD_StrictArrayType, 1, BEStrictArrayType)
				,	(PD_UnboxedArrayType, 1, BEUnboxedArrayType)
				:	[(index, index-PD_Arity2TupleType+2, BETupleType) \\ index <- [PD_Arity2TupleType..PD_Arity32TupleType]]
				]

		constructors :: [(Int, Int, BESymbKind)]
		constructors
			=	[	(PD_NilSymbol, 0, BENilSymb)
				,	(PD_ConsSymbol, 2, BEConsSymb)
				:	[(index, index-PD_Arity2TupleSymbol+2, BETupleSymb) \\ index <- [PD_Arity2TupleSymbol..PD_Arity32TupleSymbol]]
				]

:: AdjustStdArrayInfo =
	{	asai_moduleIndex	:: !Int
	,	asai_mapping 		:: !{#BEArrayFunKind}
	,	asai_funs			:: !{#FunType}
	,	asai_varHeap	 	:: !VarHeap
	}

880
adjustArrayFunctions :: PredefinedSymbols IndexRange Int {#FunDef} {#DclModule} {#ClassInstance} NumberSet VarHeap -> BackEnder
clean's avatar
clean committed
881
882
883
adjustArrayFunctions predefs arrayInstancesRange main_dcl_module_n functions dcls icl_instances used_module_numbers varHeap
	=	adjustStdArray arrayInfo predefs
				(if (arrayModuleIndex == main_dcl_module_n) icl_instances stdArray.dcl_common.com_instance_defs)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
	o`	adjustIclArrayInstances arrayInstancesRange arrayMemberMapping functions
	where
		arrayModuleIndex
			=	predefs.[PD_StdArray].pds_def
		arrayClassIndex
			=	predefs.[PD_ArrayClass].pds_def
		arrayClass
			=	stdArray.dcl_common.com_class_defs.[arrayClassIndex]
		stdArray
			=	dcls.[arrayModuleIndex]
		arrayMemberMapping
			=	getArrayMemberMapping predefs arrayClass.class_members
		arrayInfo
			=	{	asai_moduleIndex	= arrayModuleIndex
				,	asai_mapping 		= arrayMemberMapping
				,	asai_funs			= stdArray.dcl_functions
				,	asai_varHeap		= varHeap
				}

		getArrayMemberMapping :: PredefinedSymbols {#DefinedSymbol} -> {#BEArrayFunKind}
		getArrayMemberMapping predefs members
			// sanity check ...
			| size members <> length (memberIndexMapping predefs)
				=	abort "backendconvert, arrayMemberMapping: incorrect number of members"
			// ... sanity check
			=	{	createArray (size members) BENoArrayFun
				&	[i] = backEndFunKind member.ds_index (memberIndexMapping predefs) \\ member <-: members & i <- [0..]
				}				
			where
				memberIndexMapping :: PredefinedSymbols -> [(!Index, !BEArrayFunKind)]
				memberIndexMapping predefs
					=	[(predefs.[predefIndex].pds_def, backEndArrayFunKind) \\ (predefIndex, backEndArrayFunKind) <- predefMapping]
					where
						predefMapping 
							=	[	(PD_CreateArrayFun,		BECreateArrayFun)
								,	(PD_ArraySelectFun,		BEArraySelectFun)
								,	(PD_UnqArraySelectFun,	BEUnqArraySelectFun)
								,	(PD_ArrayUpdateFun,		BEArrayUpdateFun)
								,	(PD_ArrayReplaceFun,	BEArrayReplaceFun)
								,	(PD_ArraySizeFun,		BEArraySizeFun)
								,	(PD_UnqArraySizeFun,	BEUnqArraySizeFun)
								,	(PD__CreateArrayFun,	BE_CreateArrayFun)
								]

				backEndFunKind :: Index [(!Index, !BEArrayFunKind)] -> BEArrayFunKind
				backEndFunKind memberIndex predefMapping
					=	hd [back \\ (predefMemberIndex, back) <- predefMapping | predefMemberIndex == memberIndex]

932
		adjustStdArray :: AdjustStdArrayInfo PredefinedSymbols {#ClassInstance} -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
933
		adjustStdArray arrayInfo predefs instances
934
			| arrayModuleIndex == NoIndex || not (inNumberSet arrayModuleIndex used_module_numbers)
clean's avatar
clean committed
935
//				|| arrayModuleIndex <> main_dcl_module_n
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
936
937
938
939
				=	identity
			// otherwise
				=	foldStateA (adjustStdArrayInstance arrayClassIndex arrayInfo) instances
			where
940
				adjustStdArrayInstance :: Index AdjustStdArrayInfo ClassInstance -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
941
942
943
944
945
946
				adjustStdArrayInstance arrayClassIndex arrayInfo=:{asai_moduleIndex} instance`=:{ins_class}
					| ins_class.glob_object.ds_index == arrayClassIndex && ins_class.glob_module == asai_moduleIndex
						=	adjustArrayClassInstance arrayInfo instance`
					// otherwise
						=	identity
					where
947
						adjustArrayClassInstance :: AdjustStdArrayInfo ClassInstance -> BackEnder
clean's avatar
clean committed
948
						adjustArrayClassInstance arrayInfo {ins_members, ins_ident}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
949
950
							=	foldStateWithIndexA (adjustMember arrayInfo) ins_members
						where
951
							adjustMember :: AdjustStdArrayInfo Int DefinedSymbol -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
952
							adjustMember {asai_moduleIndex, asai_mapping, asai_funs, asai_varHeap} offset {ds_index}
clean's avatar
clean committed
953
954
955
956
957
958
959
960
961
								| asai_moduleIndex == main_dcl_module_n
									=	beAdjustArrayFunction asai_mapping.[offset] ds_index asai_moduleIndex
								// otherwise
									= \be0 ->	let (ft_type,be) = read_from_var_heap asai_funs.[ds_index].ft_type_ptr varHeap be0 in
										(case ft_type of
											VI_ExpandedType _
												->	beAdjustArrayFunction asai_mapping.[offset] ds_index asai_moduleIndex
											_
												->	identity) be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
962

963
		adjustIclArrayInstances :: IndexRange {#BEArrayFunKind} {#FunDef} -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
964
965
966
		adjustIclArrayInstances  {ir_from, ir_to} mapping instances
			=	foldStateWithIndexRangeA (adjustIclArrayInstance mapping) ir_from ir_to instances
			where
967
				adjustIclArrayInstance :: {#BEArrayFunKind} Index FunDef -> BackEnder
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
968
969
970
				// for array functions fun_index is not the index in the FunDef array,
				// but its member index in the Array class
				adjustIclArrayInstance mapping index {fun_index}
971
					=	beAdjustArrayFunction mapping.[fun_index] index main_dcl_module_n
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
972

973
974
975
976
977
978
979
980
981
/*
convertRules :: [(Int, FunDef)] VarHeap -> BEMonad BEImpRuleP
convertRules rules varHeap
//	=	foldr (beRules o flip convertRule varHeap) beNoRules rules
	=	foldl (flip beRules) beNoRules (map (flip convertRule varHeap) rules)
*/

convertRules :: [(Int, FunDef)] Int Ident VarHeap *BackEndState -> (BEImpRuleP, *BackEndState)
convertRules rules main_dcl_module_n aliasDummyId varHeap be
clean's avatar
clean committed
982
	# (null, be)
983
		=	accBackEnd BENoRules be
clean's avatar
clean committed
984
	=	convert rules varHeap null be
985
//	=	foldr (beRules o flip convertRule main_dcl_module_n varHeap) beNoRules rules
clean's avatar
clean committed
986
	where
987
		convert :: [(Int, FunDef)] VarHeap BEImpRuleP *BackEndState -> (BEImpRuleP, *BackEndState)
clean's avatar
clean committed
988
989
990
991
		convert [] _ rulesP be
			=	(rulesP, be)
		convert [h:t] varHeap rulesP be
			# (ruleP, be)
992
				=	convertRule aliasDummyId h main_dcl_module_n varHeap be
clean's avatar
clean committed
993
			# (rulesP, be)
994
				=	accBackEnd (BERules ruleP rulesP) be
clean's avatar
clean committed
995
			=	convert t varHeap rulesP be
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
996

997
998
convertRule :: Ident (Int,FunDef) Int VarHeap -> BEMonad BEImpRuleP
convertRule aliasDummyId (index, {fun_type=Yes type, fun_body=body, fun_pos, fun_kind, fun_symb}) main_dcl_module_n varHeap
999
	=	beRule index (cafness fun_kind)
1000
1001
			(convertTypeAlt index main_dcl_module_n (type /* ->> ("convertRule", fun_symb.id_name, index, type) */))
			(convertFunctionBody index (positionToLineNumber fun_pos) aliasDummyId body main_dcl_module_n varHeap)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1002
	where
clean's avatar
clean committed
1003
1004
1005
1006
1007
1008
		cafness :: DefOrImpFunKind -> Int
		cafness (FK_DefFunction _)
			=	BEIsNotACaf
		cafness (FK_ImpFunction _)
			=	BEIsNotACaf
		cafness FK_DefMacro
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1009
			=	BEIsNotACaf
clean's avatar
clean committed
1010
		cafness FK_ImpMacro
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1011
			=	BEIsNotACaf
clean's avatar
clean committed
1012
		cafness FK_ImpCaf
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
			=	BEIsACaf
		cafness funKind
			=	BEIsNotACaf <<- ("backendconvert, cafness: unknown fun kind", funKind)

		positionToLineNumber :: Position -> Int
		positionToLineNumber (FunPos  _ lineNumber _)
			=	lineNumber
		positionToLineNumber (LinePos _ lineNumber)
			=	lineNumber
		positionToLineNumber _
			=	-1

convertTypeAlt :: Int ModuleIndex SymbolType -> BEMonad BETypeAltP
convertTypeAlt functionIndex moduleIndex symbol=:{st_result}
	=	beTypeAlt (beNormalTypeNode (beFunctionSymbol functionIndex moduleIndex) (convertSymbolTypeArgs symbol)) (convertAnnotTypeNode st_result)

convertSymbolTypeArgs :: SymbolType -> BEMonad BETypeArgP
convertSymbolTypeArgs {st_args}
	=	convertTypeArgs st_args

convertBasicTypeKind :: BasicType -> BESymbKind
convertBasicTypeKind BT_Int
	=	BEIntType
convertBasicTypeKind BT_Char
	=	BECharType
convertBasicTypeKind BT_Real
	=	BERealType
convertBasicTypeKind BT_Bool
	=	BEBoolType
convertBasicTypeKind BT_File
	=	BEFileType
convertBasicTypeKind BT_World
	=	BEWorldType
convertBasicTypeKind BT_Dynamic
	=	BEDynamicType
convertBasicTypeKind (BT_String _)
	=	undef <<- "convertBasicTypeKind (BT_String _) shouldn't occur"

convertAnnotation :: Annotation -> BEAnnotation
convertAnnotation AN_None
	=	BENoAnnot
convertAnnotation AN_Strict
	=	BEStrictAnnot

convertAttribution :: TypeAttribute -> BEAttribution
convertAttribution TA_Unique
	=	BEUniqueAttr
convertAttribution _ // +++ uni vars, etc.
	=	BENoUniAttr

convertAnnotTypeNode :: AType -> BEMonad BETypeNodeP
convertAnnotTypeNode {at_type, at_annotation, at_attribute}
1065
/*
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1066
1067
	=	convertTypeNode at_type
	:-	beAnnotateTypeNode (convertAnnotation at_annotation)
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
	:-	beAttributeTypeNode (convertAttribution at_attribute)
*/
	=
//	\s -> (
	convertTypeNode at_type
	:-	beAnnotateTypeNode c_annot
	:-	beAttributeTypeNode c_attrib
//	) s
	where
		c_annot = convertAnnotation at_annotation
		c_attrib = convertAttribution at_attribute
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1079
1080
1081
1082
1083

convertTypeNode :: Type -> BEMonad BETypeNodeP
convertTypeNode (TB (BT_String type))
	=	convertTypeNode type
convertTypeNode (TB basicType)
1084
	=	beNormalTypeNode (beBasicSymbol (convertBasicTypeKind basicType)) beNoTypeArgs	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
convertTypeNode (TA typeSymbolIdent typeArgs)
	=	beNormalTypeNode (convertTypeSymbolIdent typeSymbolIdent) (convertTypeArgs typeArgs)
convertTypeNode (TV {tv_name})
	=	beVarTypeNode tv_name.id_name
convertTypeNode (TempQV n)
	=	beVarTypeNode ("_tqv" +++ toString n)
convertTypeNode (TempV n)
	=	beVarTypeNode ("_tv" +++ toString n)
convertTypeNode (a --> b)
	=	beNormalTypeNode (beBasicSymbol BEFunType) (convertTypeArgs [a, b])
convertTypeNode (a :@: b)
	=	beNormalTypeNode (beBasicSymbol BEApplySymb) (convertTypeArgs [{at_attribute=TA_Multi, at_annotation=AN_None, at_type = consVariableToType a} : b])
convertTypeNode TE
	=	beNormalTypeNode beDontCareDefinitionSymbol beNoTypeArgs
convertTypeNode typeNode
	=	undef <<- ("backendconvert, convertTypeNode: unknown type node", typeNode)

consVariableToType :: ConsVariable -> Type
consVariableToType (CV typeVar)
	=	TV typeVar
consVariableToType (TempCV varId)
	=	TempV varId
consVariableToType (TempQCV varId)
	=	TempQV varId

convertTypeArgs :: [AType] -> BEMonad BETypeArgP
convertTypeArgs args
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
	=	sfoldr (beTypeArgs o convertAnnotTypeNode) beNoTypeArgs args

convertFunctionBody :: Int Int Ident FunctionBody Int VarHeap -> BEMonad BERuleAltP
convertFunctionBody functionIndex lineNumber aliasDummyId (BackendBody bodies) main_dcl_module_n varHeap
	=	convertBackendBodies functionIndex lineNumber bodies varHeap
where
	convertBackendBodies :: Int Int [BackendBody] VarHeap -> BEMonad BERuleAltP
	convertBackendBodies functionIndex lineNumber bodies varHeap
		=	sfoldr (beRuleAlts o (flip (convertBackendBody functionIndex lineNumber)) varHeap) beNoRuleAlts bodies
	where
		convertBackendBody :: Int Int BackendBody VarHeap -> BEMonad BERuleAltP
		convertBackendBody functionIndex lineNumber body=:{bb_args, bb_rhs=ABCCodeExpr instructions inline} varHeap
			=	beNoNodeDefs ==> \noNodeDefs
			->	declareVars body (aliasDummyId, varHeap)
			o`	beCodeAlt
					lineNumber
					(convertLhsNodeDefs bb_args noNodeDefs varHeap)
					(convertBackendLhs functionIndex bb_args varHeap)
					(beAbcCodeBlock inline (convertStrings instructions))
		convertBackendBody functionIndex lineNumber body=:{bb_args, bb_rhs=AnyCodeExpr inParams outParams instructions} varHeap
			=	beNoNodeDefs ==> \noNodeDefs
			->	declareVars body (aliasDummyId, varHeap)
			o`	beCodeAlt
					lineNumber
					(convertLhsNodeDefs bb_args noNodeDefs varHeap)
					(convertBackendLhs functionIndex bb_args varHeap)
					(beAnyCodeBlock (convertCodeParameters inParams varHeap) (convertCodeParameters outParams varHeap) (convertStrings instructions))
		convertBackendBody functionIndex lineNumber body=:{bb_args, bb_rhs} varHeap
			=	beNoNodeDefs ==> \noNodeDefs
			->	declareVars body (aliasDummyId, varHeap)
			o`	beRuleAlt
					lineNumber
					(convertLhsNodeDefs bb_args noNodeDefs varHeap)
					(convertBackendLhs functionIndex bb_args varHeap)
					(convertRhsNodeDefs aliasDummyId bb_rhs main_dcl_module_n varHeap)
					(convertRhsStrictNodeIds bb_rhs varHeap)
					(convertRootExpr aliasDummyId bb_rhs main_dcl_module_n varHeap)

		convertBackendLhs :: Int [FunctionPattern] VarHeap -> BEMonad BENodeP
		convertBackendLhs functionIndex patterns varHeap
			=	beNormalNode (beFunctionSymbol functionIndex main_dcl_module_n) (convertPatterns patterns varHeap)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1153
1154
1155

convertStrings :: [{#Char}] -> BEMonad BEStringListP
convertStrings strings
1156
	=	sfoldr (beStrings o beString) beNoStrings strings
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1157
1158
1159

convertCodeParameters :: (CodeBinding a) VarHeap -> BEMonad BECodeParameterP | varInfoPtr a
convertCodeParameters codeParameters varHeap
1160
	=	sfoldr (beCodeParameters o flip convertCodeParameter varHeap) beNoCodeParameters codeParameters
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

class varInfoPtr a :: a -> VarInfoPtr

instance varInfoPtr BoundVar where
	varInfoPtr boundVar
		=	boundVar.var_info_ptr

instance varInfoPtr FreeVar where
	varInfoPtr freeVar
		=	freeVar.fv_info_ptr

convertCodeParameter :: (Bind String a) VarHeap -> BEMonad BECodeParameterP | varInfoPtr a
convertCodeParameter {bind_src, bind_dst} varHeap
		=	beCodeParameter bind_src (convertVar (varInfoPtr bind_dst) varHeap)
1175
/*
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1176
1177
1178
convertTransformedLhs :: Int [FreeVar] VarHeap -> BEMonad BENodeP
convertTransformedLhs functionIndex freeVars varHeap
	=	beNormalNode (beFunctionSymbol functionIndex cIclModIndex) (convertLhsArgs freeVars varHeap)
1179
*/
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1180
1181
1182

convertPatterns :: [FunctionPattern] VarHeap -> BEMonad BEArgP
convertPatterns patterns varHeap
1183
	=	sfoldr (beArgs o flip convertPattern varHeap) beNoArgs patterns
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

convertPattern :: FunctionPattern VarHeap -> BEMonad BENodeP
convertPattern (FP_Variable freeVar) varHeap
	=	convertFreeVarPattern freeVar varHeap
convertPattern (FP_Basic _ (Yes freeVar)) varHeap
	=	convertFreeVarPattern freeVar varHeap
convertPattern (FP_Basic value No) _
	=	beNormalNode (convertLiteralSymbol value) beNoArgs
convertPattern (FP_Algebraic _ freeVars (Yes freeVar)) varHeap
	=	convertFreeVarPattern freeVar varHeap
convertPattern (FP_Algebraic {glob_module, glob_object={ds_index}} subpatterns No) varHeap
	=	beNormalNode (beConstructorSymbol glob_module ds_index) (convertPatterns subpatterns varHeap)
convertPattern (FP_Dynamic _ _ _ (Yes freeVar)) varHeap
	=	convertFreeVarPattern freeVar varHeap
convertPattern FP_Empty varHeap
	=	beNodeIdNode beWildCardNodeId beNoArgs

convertFreeVarPattern :: FreeVar  VarHeap -> BEMonad BENodeP
convertFreeVarPattern freeVar varHeap
	=	beNodeIdNode (convertVar freeVar.fv_info_ptr varHeap) beNoArgs

convertLhsArgs :: [FreeVar] VarHeap -> BEMonad BEArgP
convertLhsArgs freeVars varHeap
1207
	=	sfoldr (beArgs o (flip convertFreeVarPattern) varHeap) beNoArgs freeVars
Ronny Wichers Schreur's avatar