syntax.dcl 42.6 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
3
4
5
definition module syntax

import StdEnv

import scanner, general, typeproperties, Heap
6
import IndexType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

::	Ident =
	{ 	id_name		:: !String
	,	id_info 	:: !SymbolPtr
	}

instance toString Ident


/*	Each Identifier is equipped with a pointer to a SymbolTableEntry that is
	used for binding the identifier with its definition.
*/

::	SymbolTable			:== Heap SymbolTableEntry
::	SymbolPtr 			:== Ptr SymbolTableEntry

::	SymbolTableEntry = 
	{	ste_kind		:: !STE_Kind
	,	ste_index		:: !Index
	,	ste_def_level	:: !Level
	,	ste_previous	:: SymbolTableEntry
	}

30
31
32
33
:: FunctionOrMacroIndex = FunctionOrIclMacroIndex !Int | DclMacroIndex /*module_n*/ !Int /*macro_n_in_module*/ !Int;

instance == FunctionOrMacroIndex

34
::	STE_BoundTypeVariable	= { stv_count :: !Int, stv_attribute :: !TypeAttribute, stv_info_ptr :: !TypeVarInfoPtr }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
35

36
37
::	STE_Kind	= STE_FunctionOrMacro ![FunctionOrMacroIndex]
				| STE_DclMacroOrLocalMacroFunction ![FunctionOrMacroIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
38
39
40
41
42
43
				| STE_Type
				| STE_Constructor
				| STE_Selector ![Global Index]
				| STE_Field !Ident
				| STE_Class
				| STE_Member
44
45
				| STE_Generic			// AA
				| STE_GenericCase  // AA
46
				| STE_Instance !Ident // argument: the class (used in explicitimports (1.3 syntax only))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
47
48
49
50
51
52
53
54
55
56
57
58
59
				| STE_Variable !VarInfoPtr
				| STE_TypeVariable !TypeVarInfoPtr
				| STE_TypeAttribute !AttrVarInfoPtr
				| STE_BoundTypeVariable !STE_BoundTypeVariable
				| STE_Imported !STE_Kind !Index
				| STE_DclFunction
				| STE_Module !(Module (CollectedDefinitions ClassInstance IndexRange))
				| STE_ClosedModule
				| STE_Empty
					/* for creating class dictionaries */
				| STE_DictType !CheckedTypeDef
				| STE_DictCons !ConsDef
				| STE_DictField !SelectorDef
60
				| STE_Called ![FunctionOrMacroIndex] /* used during macro expansion to indicate that this function is called */
61
62
63
				| STE_ExplImpSymbol !Int
				| STE_ExplImpComponentNrs ![ComponentNrAndIndex] ![Declaration]
					/*	stores the numbers of all module components that import the symbol from
Martin Wierich's avatar
Martin Wierich committed
64
						the "actual" dcl module. Further for each class all encountered
65
66
67
						instances are accumulated.
					*/
				| STE_BelongingSymbol !Int
68
69
70
				
				| STE_UsedType !Index !STE_Kind
					/* used during binding of types to mark types that have been applied. The first  */
71
72
				| STE_BelongingSymbolExported
				| STE_BelongingSymbolForExportedSymbol
73

74
75
76
77
78
79
80
::	Declaration = Declaration !DeclarationRecord

::	DeclarationRecord =
	{	decl_ident	:: !Ident
	,	decl_pos	:: !Position
	,	decl_kind	:: !STE_Kind
	,	decl_index	:: !Index
81
82
83
84
85
86
87
	}

::	ComponentNrAndIndex =
	{	cai_component_nr	:: !Int
	,	cai_index			:: !Int // points into ExplImpInfos
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
88
89
90
91
92
93
::	Global object =
	{	glob_object	:: !object
	,	glob_module	:: !Index
	}
	
::	Module defs = 
94
	{	mod_ident		:: !Ident
95
	,	mod_modification_time		:: {#Char}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
96
97
98
	,	mod_type		:: !ModuleKind
	, 	mod_imports		:: ![ParsedImport]
	,	mod_imported_objects :: ![ImportedObject]
99
	,	mod_foreign_exports :: ![ParsedForeignExport]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
100
101
102
	,	mod_defs		:: !defs
	}

103
104
105
106
107
108
109
::	ParsedForeignExport =
	{	pfe_ident	:: !Ident
	,	pfe_line	:: !Int
	,	pfe_file	:: !FileName
	,	pfe_stdcall	:: !Bool
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
110
111
112
::	ParsedModule	:== Module  [ParsedDefinition]
::	ScannedModule 	:== Module  (CollectedDefinitions (ParsedInstance FunDef) IndexRange)
	
113
::	ModuleKind		= MK_Main | MK_Module | MK_System | MK_None | MK_NoMainDcl
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
114
115

::	RhsDefsOfType	= ConsList ![ParsedConstructor]
116
					| SelectorList !Ident ![ATypeVar] !Bool /*is_boxed_record*/ ![ParsedSelector]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
117
118
					| TypeSpec !AType
					| EmptyRhs !BITVECT
119
					| AbstractTypeSpec !BITVECT !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
120

121
::	CollectedDefinitions instance_kind def_macros =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
122
	{	def_types 			:: ![TypeDef TypeRhs]
123
124
	,	def_constructors	:: ![ConsDef]
	,	def_selectors		:: ![SelectorDef]
125
126
	,	def_macros			:: ![FunDef]
	,	def_macro_indices	:: !IndexRange
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
127
128
129
130
	,	def_classes			:: ![ClassDef]
	,	def_members			:: ![MemberDef]
	,	def_funtypes		:: ![FunType]
	,	def_instances		:: ![instance_kind]
131
132
	,	def_generics		:: ![GenericDef] // AA
	, 	def_generic_cases 	:: ![GenericCaseDef]	 // AA	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
133
134
135
136
137
138
139
	}

::	LocalDefs	= LocalParsedDefs [ParsedDefinition]
				| CollectedLocalDefs CollectedLocalDefs

::	IndexRange	= { ir_from :: !Index, ir_to :: !Index }

140
141
142
143
144
145
146
::	ArrayAndListInstances = {
		ali_array_first_instance_indices :: ![Int],
		ali_list_first_instance_indices :: ![Int],
		ali_tail_strict_list_first_instance_indices :: ![Int],
		ali_instances_range :: !IndexRange
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
147
148
149
150
151
152
153
154
NoIndex		:== -1


::  Level	:== Int
NotALevel 	:==  -1

::	CollectedLocalDefs =
	{	loc_functions	:: !IndexRange
155
	,	loc_nodes		:: ![NodeDef ParsedExpr]
156
	,	loc_in_icl_module :: !Bool // False for local functions in macros in dcl modules, otherwise True
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
157
158
159
160
161
	}

::	NodeDef dst =
	{	nd_dst		::!dst,
		nd_alts		::!OptGuardedAlts,
162
163
		nd_locals	::!LocalDefs,
		nd_position	::!Position		
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	}

::	Rhs =
	{	rhs_alts	:: !OptGuardedAlts
	,	rhs_locals	:: !LocalDefs
	}


cIsAFunction	:== True
cIsNotAFunction :== False

::	ParsedDefinition 
	=	PD_Function  Position Ident Bool [ParsedExpr] Rhs FunKind
	|	PD_NodeDef  Position ParsedExpr Rhs
	|	PD_Type ParsedTypeDef
	|	PD_TypeSpec Position Ident Priority (Optional SymbolType) Specials
	|	PD_Class ClassDef [ParsedDefinition]
	|	PD_Instance (ParsedInstance ParsedDefinition)
	|	PD_Instances [ParsedInstance ParsedDefinition]
	|	PD_Import [ParsedImport]
	|	PD_ImportedObjects [ImportedObject]
185
	|	PD_ForeignExport !Ident !{#Char} !Int !Bool /* if stdcall */
186
187
188
	|	PD_Generic GenericDef // AA
	| 	PD_GenericCase GenericCaseDef // AA	
	|	PD_Derive [GenericCaseDef] // AA
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
189
190
	|	PD_Erroneous

191
::	FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_NodeDefOrFunction | FK_Unknown
192

193
194
::	StrictnessList = NotStrict | Strict !Int | StrictList !Int StrictnessList

195
196
cNameNotLocationDependent :== False
cNameLocationDependent :== True
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
197
198

::	ParsedSelector =
199
200
	{	ps_field_ident		:: !Ident
	,	ps_selector_ident	:: !Ident
201
	,	ps_field_annotation	:: !Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
202
203
204
205
206
207
	,	ps_field_type		:: !AType
	,	ps_field_var		:: !Ident
	,	ps_field_pos		:: !Position
	}

::	ParsedConstructor =
208
	{	pc_cons_ident 	:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
209
210
211
	,	pc_cons_arity	:: !Int
	,	pc_exi_vars		:: ![ATypeVar]
	,	pc_arg_types	:: ![AType]
212
	,	pc_args_strictness	:: !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	,	pc_cons_prio	:: !Priority
	,	pc_cons_pos		:: !Position
	}
	
::	ParsedInstance member =
	{	pi_class 	:: !Ident
	,	pi_ident	:: !Ident
	,	pi_types	:: ![Type]
	,	pi_context	:: ![TypeContext]
	,	pi_pos		:: !Position
	,	pi_members	:: ![member]
	,	pi_specials	:: !Specials
	}

/*
	Objects of type Specials are used to specify specialized instances of overloaded functions.
	These can only occur in definition modules. After parsing the SP_ParsedSubstitutions alternative
	is used to indicate the specific instantiation. The SP_Substitutions alternative is used to deduce
	the type of the specialized version. Finally the SP_ContextTypes alternative is set and used during 
232
	the typing to check whether this instance has been used. The auxiliary SP_FunIndex alternative is used
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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
	to store the index of the function that has been specialized.
*/


::	Specials
	= SP_ParsedSubstitutions 	![Env Type TypeVar]
	| SP_Substitutions 		 	![SpecialSubstitution]
	| SP_ContextTypes			![Special]
	| SP_FunIndex				!Index
	| SP_TypeOffset				!Int
	| SP_None

::	SpecialSubstitution =
	{	ss_environ	:: !Env Type TypeVar
	,	ss_context	:: ![TypeContext]
	,	ss_vars		:: ![TypeVar]
	,	ss_attrs	:: ![AttributeVar]
	}

::	Special =
	{	spec_index	:: !Global Index
	,	spec_types	:: ![[Type]]
	,	spec_vars	:: ![TypeVar]
	, 	spec_attrs	:: ![AttributeVar]
	}

::	AttrInequality =
	{	ai_demanded :: !AttributeVar
	,	ai_offered	:: !AttributeVar
	}


::	DefinedSymbol = 
	{	ds_ident		:: !Ident
	,	ds_arity		:: !Int
	,	ds_index		:: !Index
	}

::	ClassDef =
272
 	{	class_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
273
274
275
276
277
278
279
280
281
	,	class_arity			:: !Int
	,	class_args			:: ![TypeVar]
	,	class_context		:: ![TypeContext]
	,	class_members		:: !{# DefinedSymbol}
	,	class_dictionary	:: !DefinedSymbol
	,	class_pos			:: !Position
	,	class_cons_vars		:: !BITVECT
	}

282
283
::	ClassDefInfos :== {# .{! [TypeKind]}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
284
::	MemberDef =
285
	{	me_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
286
287
288
289
290
291
292
293
294
	,	me_class		:: !Global Index
	,	me_offset		:: !Index
	,	me_type			:: !SymbolType
	,	me_type_ptr		:: !VarInfoPtr
	,	me_class_vars	:: ![TypeVar]
	,	me_pos			:: !Position
	,	me_priority 	:: !Priority
	}

295
// AA ... 
Artem Alimarine's avatar
Artem Alimarine committed
296

297
:: GenericDef = 
298
299
	{	gen_ident		:: !Ident		// the generics name in IC_Class 
	,	gen_member_ident	:: !Ident		// the generics name in IC_Member
300
	, 	gen_pos			:: !Position
301
302
303
	,	gen_type		:: !SymbolType	// Generic type (st_vars include generic type vars)
	,	gen_vars		:: ![TypeVar]	// Generic type variables
	,	gen_info_ptr	:: !GenericInfoPtr
304
	}
Artem Alimarine's avatar
Artem Alimarine committed
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
:: GenericClassInfo = 
	{	gci_kind	:: !TypeKind	// the kind
	,	gci_module 	:: !Index		// filled with main_module_index
	,	gci_class	:: !Index		// class_index in the main module
	,	gci_member	:: !Index 		// the class member index 
	}
:: GenericClassInfos :== {[GenericClassInfo]}

:: GenericInfo = 
	{	gen_classes		:: !GenericClassInfos
	,	gen_cases		:: ![GlobalIndex] 
	,	gen_var_kinds	:: ![TypeKind]  	// kinds of all st_vars of the gen_type
	, 	gen_star_case	:: !GlobalIndex 	// general case for kind-star types
	}
:: GenericInfoPtr :== Ptr GenericInfo	
:: GenericHeap :== Heap GenericInfo

:: TypeCons 
	= TypeConsSymb TypeSymbIdent 
	| TypeConsBasic BasicType 
	| TypeConsArrow
	| TypeConsVar TypeVar 

:: GenericCaseDef = 
330
331
	{	gc_ident			:: !Ident				// name in IC_GenricCase namespace
	,	gc_gident		:: !Ident  				// name in IC_Generic namespace
332
333
334
335
336
337
338
339
340
341
342
343
344
345
	,	gc_generic		:: !GlobalIndex  		// index of the generic
	,	gc_arity		:: !Int					// arity of the function
	,	gc_pos			:: !Position			// position in the source file
	,	gc_type			:: !Type				// the instance type
	,   gc_type_cons	:: !TypeCons			// type constructor of the type argument
	,	gc_body			:: !GenericCaseBody		// the body function or NoIndex
	,	gc_kind			:: !TypeKind			// kind of the instance type
	}
:: GenericCaseBody 
	= GCB_None 									// to be generated
	| GCB_FunIndex !Index 
	| GCB_FunDef !FunDef 
	| GCB_ParsedBody ![ParsedExpr] !Rhs 

346
347
348
349
350
351
:: GenericType = 
	{	gt_type 		:: !SymbolType
	,	gt_vars			:: ![TypeVar]			// generic arguments
	,	gt_arity		:: !Int					// number of generic arguments	
	}
	
Artem Alimarine's avatar
Artem Alimarine committed
352

353
354
//getGenericClassForKind 	:: !GenericDef !TypeKind -> (!Bool, DefinedSymbol)
//addGenericKind			:: !GenericDef !TypeKind -> !GenericDef
Artem Alimarine's avatar
Artem Alimarine committed
355

356
357
// ... AA

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
::	InstanceType =
	{	it_vars			:: [TypeVar]
	,	it_types		:: ![Type]
	,	it_attr_vars	:: [AttributeVar]
	,	it_context		:: ![TypeContext]
	}

::	ClassInstance =
 	{	ins_class		:: !Global DefinedSymbol
	,	ins_ident		:: !Ident
	,	ins_type		:: !InstanceType
	,	ins_members		:: !{# DefinedSymbol}
	,	ins_specials	:: !Specials
	,	ins_pos			:: !Position
	}

/*
::	Export =
	{	export_class	:: Ident
	,	export_types	:: [Type]
	}
*/
::	Import from_symbol =
	{	import_module		:: !Ident
	,	import_symbols		:: ![from_symbol]
Martin Wierich's avatar
Martin Wierich committed
383
	,	import_file_position:: !Position	// for error messages
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
	}

instance toString (Import from_symbol), AttributeVar, TypeAttribute, Annotation

::	ParsedImport		:== Import ImportDeclaration

::	ImportedIdent =
	{	ii_ident	:: !Ident
	,	ii_extended	:: !Bool
	}

::	ImportDeclaration	= ID_Function !ImportedIdent
						| ID_Class !ImportedIdent !(Optional [ImportedIdent])
						| ID_Type !ImportedIdent !(Optional [ImportedIdent])
						| ID_Record !ImportedIdent !(Optional [ImportedIdent])
						| ID_Instance !ImportedIdent !Ident !(![Type],![TypeContext])
400
						| ID_OldSyntax ![Ident]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
401
402
403

cIsImportedLibrary :== True
cIsImportedObject :== False
404

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
405
406
407
408
409
410
411
412
:: ImportedObject =
	{	io_is_library :: !Bool
	,	io_name    :: !{#Char}
	}

::	RecordType =
	{	rt_constructor	:: !DefinedSymbol
	,	rt_fields		:: !{# FieldSymbol}
413
	,	rt_is_boxed_record :: !Bool
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
414
415
416
	}
	
::	FieldSymbol =
417
	{	fs_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
418
419
420
421
422
423
424
425
	,	fs_var			:: !Ident
	,	fs_index		:: !Index
	}

::	TypeRhs	= AlgType ![DefinedSymbol]
			| SynType !AType
			| RecordType !RecordType
			| AbstractType !BITVECT
426
			| AbstractSynType !BITVECT !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
427
428
429
430
431
432
433
434
			| UnknownType

::	ParsedTypeDef	:== TypeDef RhsDefsOfType
::	CheckedTypeDef	:== TypeDef TypeRhs

cAllBitsClear			:== 0
cIsHyperStrict			:== 1
cIsNonCoercible			:== 2
435
436
437
438
439
440
cIsAnalysed				:== 4

::	GlobalIndex =
	{	gi_module	::!Int
	,	gi_index	::!Int
	}
441
NoGlobalIndex :== {gi_module=NoIndex,gi_index=NoIndex}	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
442
443

::	TypeDef type_rhs =
444
 	{	td_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
445
446
447
448
449
450
451
452
	,	td_index		:: !Int
	,	td_arity		:: !Int
	,	td_args			:: ![ATypeVar]
	,	td_attrs		:: ![AttributeVar]
	,	td_context		:: ![TypeContext]
	,	td_rhs			:: !type_rhs
	,	td_attribute	:: !TypeAttribute
	,	td_pos			:: !Position
453
	,	td_used_types	:: ![GlobalIndex]
454
	,	td_fun_index	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
455
456
457
458
459
	}

::	TypeDefInfo =
	{	tdi_kinds			:: ![TypeKind]
	,	tdi_properties		:: !BITVECT
460
	,	tdi_group			:: ![GlobalIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
461
462
463
	,	tdi_group_nr		:: !Int
	,	tdi_group_vars		:: ![Int]
	,	tdi_cons_vars		:: ![Int]
464
	,	tdi_index_in_group	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
465
	,	tdi_classification	:: !TypeClassification
466
467
	,	tdi_mark			:: !Bool //AA
	,	tdi_gen_rep 		:: !Optional GenericTypeRep //AA
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
468
469
	}

470
// AA..
471
472
473
474
475
// type structure is used to specialize a generic to a type
:: GenTypeStruct 
	= GTSAppCons TypeKind [GenTypeStruct]
	| GTSAppVar TypeVar [GenTypeStruct] 
	| GTSVar TypeVar
Artem Alimarine's avatar
Artem Alimarine committed
476
	| GTSArrow GenTypeStruct GenTypeStruct	// needed for simplifying bimaps
477
478
 	| GTSCons DefinedSymbol GenTypeStruct
 	| GTSField DefinedSymbol GenTypeStruct
Artem Alimarine's avatar
Artem Alimarine committed
479
 	| GTSObject DefinedSymbol GenTypeStruct
480
481
 	| GTSE
 
482
:: GenericTypeRep = 
483
	{ gtr_type :: GenTypeStruct		// generic structure type
484
485
486
487
	, gtr_iso  :: DefinedSymbol		// the conversion isomorphism
	}
// ..AA

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
488
489
490
::	TypeDefInfos :== {# .{# TypeDefInfo}}

::	FunType =
491
	{	ft_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
492
493
494
495
496
497
498
499
500
501
	,	ft_arity		:: !Int
	,	ft_priority		:: !Priority
	,	ft_type			:: !SymbolType
	,	ft_pos			:: !Position
	,	ft_specials		:: !Specials
	,	ft_type_ptr		:: !VarInfoPtr
	}

::	FreeVar =
	{	fv_def_level	:: !Level
502
	,	fv_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
503
504
505
506
	,	fv_info_ptr		:: !VarInfoPtr
//	,	fv_expr_ptr		:: !ExprInfoPtr
	,	fv_count		:: !Int
	}
507
508
509
510
511

::	ModuleIndex:==Index;
::	DclFunctionIndex:==Index;

::	FunCall = FunCall !Index !Level | MacroCall !ModuleIndex !Index Level | DclFunCall !ModuleIndex !DclFunctionIndex;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
512

513
514
FI_IsMacroFun	:== 1			// whether the function is a local function of a macro
FI_HasTypeSpec	:== 2			// whether the function has u user defined type
515
516
FI_IsNonRecursive :== 4			// used in trans.icl and partition.icl
FI_IsUnboxedListOfRecordsConsOrNil :== 8
517

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
518
519
520
521
522
523
524
::	FunInfo =
	{	fi_calls			:: ![FunCall]
	,	fi_group_index		:: !Index
	,	fi_def_level		:: !Level
	,	fi_free_vars		:: ![FreeVar]
	,	fi_local_vars		:: ![FreeVar]
	,	fi_dynamics			:: ![ExprInfoPtr]
525
	,	fi_properties		:: !BITVECT
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
526
527
528
	}

::	ParsedBody =
529
530
531
	{	pb_args		:: ![ParsedExpr]
	,	pb_rhs		:: !Rhs
	,	pb_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
532
533
534
	}

::	CheckedBody =
535
536
	{	cb_args		:: ![FreeVar]
	,	cb_rhs		:: ![CheckedAlternative]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
537
538
	}

539
540
541
542
543
544
::	CheckedAlternative =
	{	ca_rhs		:: !Expression
	,	ca_position	:: !Position	// the position is NoPos iff the position information for this
	}								// alternative is already stored in a case alternative
									// (in ap_position, bp_position or dp_position)

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
545
546
547
548
549
550
551
552
::	TransformedBody =
	{	tb_args			:: ![FreeVar]
	,	tb_rhs			:: !Expression
	}

::	FunctionBody	= ParsedBody ![ParsedBody]
					| CheckedBody !CheckedBody
	/* The next three constructors are used during macro expansion (module transform) */
553
554
					| PartitioningMacro
					| PartitioningFunction !CheckedBody !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
555
556
557
					| RhsMacroBody !CheckedBody
	/* macro expansion transforms a CheckedBody into a TransformedBody */
					| TransformedBody !TransformedBody
558
					| Expanding ![FreeVar] // the parameters of the newly generated function
559
					| GeneratedBody // the body will be generated automatically - for generics
560
					| NoBody
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
561
562

::	FunDef =
563
	{	fun_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
564
565
566
567
568
	,	fun_arity		:: !Int
	,	fun_priority	:: !Priority
	,	fun_body		:: !FunctionBody
	,	fun_type		:: !Optional SymbolType
	,	fun_pos			:: !Position
569
	,	fun_kind		:: !FunKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
570
571
572
573
574
575
576
577
	,	fun_lifted		:: !Int
	,	fun_info		:: !FunInfo
	}

cIsAGlobalVar	:== True
cIsALocalVar	:== False

::	ConsClasses =
578
	{	cc_size			::!Int
579
580
	,	cc_args			::![ConsClass]
	,	cc_linear_bits	::![Bool]
581
	,	cc_producer		::!ProdClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
582
583
584
585
	}
					
::	ConsClass	:== Int

586
587
588
589
::	ProdClass	:== Bool

pIsSafe			:== True

590
591
592
593
::	ImportedConstructors	:== [Global Index]
::	ImportedFunctions		:== [Global Index]
::	ImportedTypes			:== {#{# CheckedTypeDef}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
594
595
596
597
598
599
600
601
::	OptionalVariable :== Optional (Bind Ident VarInfoPtr)

:: 	AuxiliaryPattern
		= AP_Algebraic !(Global DefinedSymbol) !Index [AuxiliaryPattern] OptionalVariable
		| AP_Variable !Ident !VarInfoPtr OptionalVariable
		| AP_Basic !BasicValue OptionalVariable
		| AP_Dynamic !AuxiliaryPattern !DynamicType !OptionalVariable
		| AP_Constant !AP_Kind !(Global DefinedSymbol) !Priority
602
		| AP_WildCard !OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
603
604
		| AP_Empty !Ident

605
:: AP_Kind = APK_Constructor !Index | APK_Macro !Bool // is_dcl_macro
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
606

607
from convertDynamics import :: TypeCodeVariableInfo, :: DynamicValueAliasInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
608

609
610
611
612
613
614
::	VI_TypeInfo	= VITI_Empty
				| VITI_Coercion		CoercionPosition
				| VITI_PatternType	[AType] VI_TypeInfo

//::	VarInfo  =	VI_Empty | VI_Type !AType !(Optional CoercionPosition) | VI_FAType ![ATypeVar] !AType !(Optional CoercionPosition) |
::	VarInfo  =	VI_Empty | VI_Type !AType !VI_TypeInfo | VI_FAType ![ATypeVar] !AType !VI_TypeInfo |
615
				VI_Occurrence !Occurrence | VI_UsedVar !Ident |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
616
617
				VI_Expression !Expression | VI_Variable !Ident !VarInfoPtr | VI_LiftedVariable !VarInfoPtr |
				VI_Count !Int /* the reference count of a variable */ !Bool /* true if the variable is global, false otherwise */ |
618
				VI_AccVar !ConsClass !ArgumentPosition /* used during fusion to determine accumulating parameters of functions */ |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
619
620
621
				VI_Alias !BoundVar /* used for resolving aliases just before type checking (in transform) */ |
				 /* used during elimination and lifting of cases */
				VI_FreeVar !Ident !VarInfoPtr !Int !AType | VI_BoundVar !AType | VI_LocalVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
622
623
				VI_ClassVar !Ident !VarInfoPtr !Int | /* to hold dictionary variables during overloading */
				VI_ForwardClassVar !VarInfoPtr | /* to hold the dictionary variable generated during overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
624
				VI_Forward !BoundVar | VI_LetVar !LetVarInfo | VI_LetExpression !LetExpressionInfo | VI_CaseVar !VarInfoPtr |
625
				VI_CorrespondenceNumber !Int | /* it is assumed that this alternative is _only_ used in module comparedefimp */
626
				VI_SequenceNumber !Int | VI_AliasSequenceNumber !BoundVar |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
627
628
629
630
631
				VI_Used | /* for indicating that an imported function has been used */
				VI_PropagationType !SymbolType | /* for storing the type with propagation environment of an imported function */
				VI_ExpandedType !SymbolType | /* for storing the (expanded) type of an imported function */
				VI_Record ![AuxiliaryPattern] |
				VI_Pattern !AuxiliaryPattern |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
632
				VI_TypeCodeVariable !TypeCodeVariableInfo |
633
				VI_DynamicValueAlias !DynamicValueAliasInfo |
634
				VI_Body !SymbIdent !TransformedBody ![FreeVar] | /* used during fusion */
635
				VI_Dictionary !SymbIdent ![Expression] !Type | /* used during fusion */
Sjaak Smetsers's avatar
Sjaak Smetsers committed
636
				VI_Extended !ExtendedVarInfo !VarInfo |
637
				VI_Defined /* for marking type code variables during overloading */ | VI_LocallyDefined |
638
// MdM
639
				VI_CPSExprVar !CheatCompiler /* a pointer to a variable in CleanProverSystem is stored here, using a cast */
640
// ... MdM
641
642
				| VI_Labelled_Empty {#Char} // RWS debugging
				| VI_LocalLetVar // RWS, mark Let vars during case transformation
643

644
::	ExtendedVarInfo = EVI_VarType !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
645

646
647
::	ArgumentPosition :== Int

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
648
649
::	VarInfoPtr	:== Ptr VarInfo

650
651
from convertcases import :: LetVarInfo, :: LetExpressionInfo,
							:: RefCountsInCase,	:: SplitsInCase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
652
653
654
655

cNotVarNumber :== -1

::	BoundVar = 
656
	{	var_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
657
658
659
660
661
662
663
664
665
666
667
668
	,	var_info_ptr	:: !VarInfoPtr
	,	var_expr_ptr	:: !ExprInfoPtr
	}

/*
cRecursiveAppl		:== True
cNonRecursiveAppl	:== False	

::	ApplicationKind	:== Bool
*/
 
::	TypeSymbIdent =
669
	{	type_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
670
671
672
673
674
675
676
677
678
679
680
681
682
	,	type_arity		:: !Int
	,	type_index		:: !Global Index
	,	type_prop		:: !TypeSymbProperties
	}

::	TypeSymbProperties =
	{	tsp_sign		:: !SignClassification
	,	tsp_propagation	:: !PropClassification
	,	tsp_coercible	:: !Bool
	}

::	SymbKind	= SK_Unknown
				| SK_Function !(Global Index)
683
				| SK_IclMacro !Index
684
				| SK_LocalMacroFunction !Index
685
686
				| SK_DclMacro !(Global Index)
				| SK_LocalDclMacroFunction !(Global Index)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
687
688
				| SK_OverloadedFunction !(Global Index)
				| SK_GeneratedFunction !FunctionInfoPtr !Index
689
690
				| SK_Constructor !(Global Index)
				| SK_Generic !(Global Index) !TypeKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
				| SK_TypeCode

/*	Some auxiliary type definitions used during fusion. Actually, these definitions
	should have been given in seperate module. Unfortunately, Clean's module system
	forbids cyclic dependencies between def modules.
	
*/

::	FunctionHeap 	:== Heap FunctionInfo

::	FunctionInfoPtr	:== Ptr FunctionInfo

::	FunctionInfo	= FI_Empty | FI_Function !GeneratedFunction

::	Producer	= PR_Empty
706
				| PR_Function !SymbIdent !Int !Index
Martin Wierich's avatar
Martin Wierich committed
707
				| PR_Class !App ![(BoundVar, Type)] !Type
708
709
710
				| PR_Constructor !SymbIdent !Int ![Expression]
				| PR_GeneratedFunction !SymbIdent !Int !Index
				| PR_Curried !SymbIdent !Int
711
				| PR_Unused
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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

::	InstanceInfo = II_Empty | II_Node !{! Producer} !FunctionInfoPtr !InstanceInfo !InstanceInfo

::	GeneratedFunction = 
	{	gf_fun_def			:: !FunDef
	,	gf_instance_info	:: !InstanceInfo
	,	gf_cons_args		:: !ConsClasses
	,	gf_fun_index		:: !Index
	}
	
/*	... main type definitions continued .... */

::	ExpressionHeap 	:== Heap ExprInfo

::	ExprInfoPtr		:== Ptr ExprInfo

::	TempLocalVar	:== Int

::	DynamicPtr		:== ExprInfoPtr

::	ExprInfo		= EI_Empty

		/* For handling overloading */

					| EI_Overloaded !OverloadedCall 						/* initial, set by the type checker */
					| EI_Instance 	!(Global DefinedSymbol) ![Expression]	/* intermedediate, used during resolving of overloading */ 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
738
					| EI_Selection 	![Selection] !VarInfoPtr ![Expression]	/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
739
740
741
742
					| EI_Context 	![Expression]							/* intermedediate, used during resolving of overloading */

		/* For handling dynamics */

Sjaak Smetsers's avatar
Sjaak Smetsers committed
743
744
					| EI_UnmarkedDynamic 		!(Optional DynamicType) ![DynamicPtr]
					| EI_Dynamic 				!(Optional DynamicType) ![DynamicPtr]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
745
746
747
748
749
750
751
752
					| EI_DynamicType			!DynamicType ![DynamicPtr]

		/* Auxiliary, was EI_DynamicType before checking */

					| EI_DynamicTypeWithVars	![TypeVar] !DynamicType ![DynamicPtr]				

		/* Auxiliary, used during type checking */

Sjaak Smetsers's avatar
Sjaak Smetsers committed
753
					| EI_TempDynamicType 		!(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
754
755
					| EI_TempDynamicPattern 	![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
					
756
					| EI_TypeOfDynamic 			!TypeCodeExpression				/* Final */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
757
758
759
760
761
762
763
					| EI_TypeOfDynamicPattern 	![VarInfoPtr] !TypeCodeExpression				/* Final */

					| EI_TypeCode 		!TypeCodeExpression
					| EI_TypeCodes 		![TypeCodeExpression]

					| EI_Attribute !Int

764
		/* EI_DictionaryType is used to store the instance type of a class. This type is used during fusion to generate proper types for 
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
765
766
		   the fusion result (i.e. the resulting function after elimination of dictionaries) */

767
					| EI_DictionaryType !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
768
769
770
					| EI_CaseType !CaseType
					| EI_LetType ![AType]
					| EI_CaseTypeAndRefCounts !CaseType !RefCountsInCase
771
					| EI_CaseTypeAndSplits !CaseType !SplitsInCase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
772
773
774
775
					| EI_LetTypeAndRefCounts ![AType] ![Int]

		/* for converting case into function patterns the following auxiliary constuctors are used */

776

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
777
778
					| EI_Default !Expression !AType !ExprInfoPtr
					| EI_DefaultFunction !SymbIdent ![Expression]
779
					| EI_Extended !ExtendedExprInfo !ExprInfo
780
781
782
783

::	ExtendedExprInfo
					= EEI_ActiveCase !ActiveCaseInfo

784

785
::	ActiveCaseInfo =
786
787
788
789
	{	aci_params					:: ![FreeVar]
	,	aci_opt_unfolder			:: !(Optional SymbIdent)
	,	aci_free_vars				:: !Optional [BoundVar]
	,	aci_linearity_of_patterns	:: ![[Bool]]
790
	,	aci_safe					:: !Bool
791
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
792

793

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
/*
::	UnboundVariable =
	{	free_name		:: !Ident
	,	free_info_ptr	:: !VarInfoPtr
	,	free_selections	:: ![Int]
	}
*/

/*
	OverloadedCall contains (type) information about functions that are overloaded. This structure is built during type checking
	and used after (standard) unification to insert the proper instances of the corresponding functions.

*/

::	OverloadedCall = 
	{	oc_symbol	:: !SymbIdent
	,	oc_context	:: ![TypeContext]
	,	oc_specials	:: ![Special]
	}

/*
	CaseType contains the type information needed to type the corresponding case construct:
		ct_pattern_type : the type of the pattern
		ct_result_type  : the type of the result (of each pattern)
		ct_cons_types   : the types of the arguments of each pattern constructor
*/
		
::	CaseType =
	{	ct_pattern_type	:: !AType
	,	ct_result_type	:: !AType
	,	ct_cons_types 	:: ![[AType]]
	}
		
::	SymbIdent =
828
	{	symb_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
829
830
831
832
	,	symb_kind		:: !SymbKind
	}

::	ConsDef =
833
	{	cons_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
834
835
836
837
838
839
840
841
842
843
844
845
	,	cons_type			:: !SymbolType
	,	cons_arg_vars		:: ![[ATypeVar]]
	,	cons_priority		:: !Priority
	,	cons_index			:: !Index
	,	cons_type_index		:: !Index
	,	cons_exi_vars		:: ![ATypeVar]
//	,	cons_exi_attrs		:: ![AttributeVar]
	,	cons_type_ptr		:: !VarInfoPtr
	,	cons_pos			:: !Position
	}

::	SelectorDef =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
846
	{	sd_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
847
848
849
850
851
852
853
854
855
856
857
858
859
	,	sd_field		:: !Ident
	,	sd_type			:: !SymbolType
	,	sd_exi_vars		:: ![ATypeVar]
//	,	sd_exi_attrs	:: ![AttributeVar]
	,	sd_field_nr		:: !Int
	,	sd_type_index	:: !Int
	,	sd_type_ptr		:: !VarInfoPtr
	,	sd_pos			:: !Position
	}

::	SymbolType =
	{	st_vars			:: ![TypeVar]
	,	st_args			:: ![AType]
860
	,	st_args_strictness :: !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
861
862
863
864
865
866
867
868
	,	st_arity		:: !Int
	,	st_result		:: !AType
	,	st_context		:: ![TypeContext]
	,	st_attr_vars	:: ![AttributeVar]
	,	st_attr_env		:: ![AttrInequality]
	}

::	TypeContext =
869
	{	tc_class	:: !TCClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
870
871
872
873
	,	tc_types	:: ![Type]
	,	tc_var		:: !VarInfoPtr
	}

874
875
876
877
878
879
880
881
882
883
884
//AA: class in a type context is either normal class or a generic class
:: TCClass 	= TCClass 		!(Global DefinedSymbol) // Normal class
			| TCGeneric 	!GenericTypeContext		// Generic class

:: GenericTypeContext = 
	{ gtc_generic 	:: !(Global DefinedSymbol)
	, gtc_kind		:: !TypeKind 
	, gtc_class		:: !(Global DefinedSymbol) // generated class
	, gtc_dictionary:: !(Global DefinedSymbol) // HACK: dictionary different from the one contained in the class
	}
//..AA
885

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
886
887
888
889
890
891
892
893
894
895
::	AType =
	{	at_attribute	:: !TypeAttribute
	,	at_type			:: !Type
	}
	
::	TempAttrId		:== Int
::	TempVarId		:== Int


::	Type	=	TA !TypeSymbIdent ![AType]
896
			|	TAS !TypeSymbIdent ![AType] !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
897
			|	(-->) infixr 9 !AType !AType
898
899
			| 	TArrow							/* (->) */
			| 	TArrow1	!AType					/* ((->) a) */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
900
901
902
			|	(:@:) infixl 9 !ConsVariable ![AType]
			|	TB !BasicType

903
			|	TFA [ATypeVar] Type				/* Universally quantified types */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
904
905
906
907
908
909
910
911
912
913

			| 	GTV !TypeVar
			| 	TV !TypeVar
			|	TempV !TempVarId				/* Auxiliary, used during type checking */

			
			|	TQV	TypeVar
			|	TempQV !TempVarId				/* Auxiliary, used during type checking */

			|	TLifted !TypeVar				/* Auxiliary, used during type checking of lifted arguments */
914

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
			|	TE

::	ConsVariable = CV 		!TypeVar
				 | TempCV 	!TempVarId
				 | TempQCV 	!TempVarId

::	DynamicType =
	{	dt_uni_vars 	:: ![ATypeVar]
	,	dt_global_vars	:: ![TypeVar]
	,	dt_type			:: !AType
	}

::	KindHeap	:== Heap KindInfo
::	KindInfoPtr	:== Ptr KindInfo

::	KindInfo	= KI_Var !KindInfoPtr
931
				| KI_Arrow !KindInfo !KindInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
932
933
934
935
936
937
938
939
940
				| KI_Const
				
				| KI_ConsVar
				
				| KI_VarBind !KindInfoPtr
				| KI_NormVar !Int

::	TypeVarInfo  	= TVI_Empty
					| TVI_Type !Type
941
					| TVI_TypeVar !TypeVarInfoPtr // Sjaak: to collect and check universally quantified type variables
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
942
943
					| TVI_Forward !TempVarId | TVI_TypeKind !KindInfoPtr
					| TVI_SignClass !Index !SignClassification !TypeVarInfo | TVI_PropClass !Index !PropClassification !TypeVarInfo
944
					| TVI_AttrAndRefCount !TypeAttribute !Int
945
946
					| TVI_CorrespondenceNumber !Int /* auxiliary used in module comparedefimp */
					| TVI_AType !AType /* auxiliary used in module comparedefimp */
947
					| TVI_Reify !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
948
949
					| TVI_Used /* to administer that this variable is encountered (in checkOpenTypes) */
					| TVI_TypeCode !TypeCodeExpression
950
					| TVI_CPSLocalTypeVar !Int /* MdM - the index of the variable as generated by the theorem prover */
951
					| TVI_Kinds ![TypeKind] // AA: used to collect kinds during checking 
952
					| TVI_Kind !TypeKind
953
					| TVI_ConsInstance !DefinedSymbol //AA: generic cons instance function 
Martijn Vervoort's avatar
Martijn Vervoort committed
954
					| TVI_Normalized !Int /* MV - position of type variable in its definition */
955
					| TVI_Expr !Expression	/* AA: Expression corresponding to the type var during generic specialization */
956
957
958
959
// MdM
					| TVI_CPSTypeVar !CheatCompiler /* a pointer to a variable in CleanProverSystem is stored here, using a cast */
// ... MdM

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
960
961
962
::	TypeVarInfoPtr	:== Ptr TypeVarInfo
::	TypeVarHeap 	:== Heap TypeVarInfo

963
964
965
966
::	AttrVarInfo  	= AVI_Empty
					| AVI_Attr !TypeAttribute
					| AVI_AttrVar !AttrVarInfoPtr // Sjaak: to collect universally quantified attribute variables
					| AVI_Forward !TempAttrId 
967
					| AVI_CorrespondenceNumber !Int /* auxiliary used in module comparedefimp */
968
					| AVI_Used
969
					| AVI_Count !Int /* auxiliary used in module typesupport */
970
					| AVI_SequenceNumber !Int // RWS
971
					| AVI_Collected // RWS
972

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
973
974
975
976
977
978
979
980
981
::	AttrVarInfoPtr	:== Ptr AttrVarInfo
::	AttrVarHeap 	:== Heap AttrVarInfo

::	TypeHeaps =
	{	th_vars		:: ! .TypeVarHeap
	,	th_attrs	:: ! .AttrVarHeap
	}

::	TypeVar =
982
	{	tv_ident				:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
983
984
985
986
987
988
989
990
	,	tv_info_ptr			:: !TypeVarInfoPtr
	}

::	ATypeVar =
	{	atv_attribute		:: !TypeAttribute
	,	atv_variable		:: !TypeVar
	}

991
::	TypeAttribute = TA_Unique | TA_Multi | TA_Var !AttributeVar | TA_RootVar AttributeVar | TA_TempVar !Int // | TA_TempExVar !Int
992
993
994
995
					| TA_Anonymous | TA_None
					| TA_List !Int !TypeAttribute | TA_Locked !TypeAttribute
					| TA_MultiOfPropagatingConsVar // only filled in after type checking, semantically equal to TA_Multi
							
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
996
::	AttributeVar =
997
	{	av_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
998
999
1000
	,	av_info_ptr		:: !AttrVarInfoPtr
	}

1001
::	Annotation	=  AN_Strict | AN_None
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1002
1003
1004
1005
1006

::	BasicType	= BT_Int | BT_Char | BT_Real | BT_Bool | BT_Dynamic
				| BT_File | BT_World
				| BT_String !Type /* the internal string type synonym only used to type string denotations */

1007
::	BasicValue	= BVI !String | BVInt !Int |BVC !String | BVB !Bool | BVR !String | BVS !String
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1008

1009
::	TypeKind = KindVar !KindInfoPtr | KindConst | KindArrow ![TypeKind] | KindCycle | KindError
1010

1011
1012
1013
1014
instance toString 	TypeKind
instance <<< 		TypeKind
instance == 		TypeKind
instance toString 	KindInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1015
1016
1017

/* A few obscure type definitions */

1018
1019
1020
1021
1022
::	PatternVar =
	{	pv_var		:: !FreeVar
	,	pv_arg_nr	:: !Int
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1023
::	Occurrence =
1024
1025
1026
	{	occ_ref_count		:: !ReferenceCount
	,	occ_bind			:: !OccurrenceBinding
	,	occ_pattern_vars	:: ![[PatternVar]]
1027
	,	occ_observing		:: (Bool, Ptr ExprInfo)
1028
	,	occ_previous 		:: ![ReferenceCount]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1029
1030
1031
1032
	}

::	ReferenceCount = RC_Used !RC_Used | RC_Unused 

1033
1034
1035
1036
1037
::	SelectiveUse =
	{	su_field	:: !Int
	,	su_multiply :: ![ExprInfoPtr]
	,	su_uniquely :: ![ExprInfoPtr]
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1038

1039
1040
1041
1042
1043
::	RC_Used =
	{ 	rcu_multiply	:: ![ExprInfoPtr]
	,	rcu_selectively :: ![SelectiveUse]
	,	rcu_uniquely	:: ![ExprInfoPtr]
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1044

1045
1046
::	CountedFreeVar =
	{	cfv_var		:: !FreeVar
1047
	,	cfv_is_let	:: !Bool
1048
	,	cfv_count	:: !ReferenceCount
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1049
	}
1050
1051

::	OccurrenceBinding	= OB_Empty 
1052
1053
1054
1055
						| OB_OpenLet	FreeVar (Optional RefMarkResult)
						| OB_LockedLet	OccurrenceBinding

::	RefMarkResult :== ([CountedFreeVar], [FreeVar])
1056

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1057
1058
1059
1060
1061
1062
1063
::	OptGuardedAlts	= GuardedAlts ![GuardedExpr] !(Optional ExprWithLocalDefs)
				 	| UnGuardedExpr !ExprWithLocalDefs

::	GuardedExpr =
	{	alt_nodes	:: ![NodeDefWithLocals]
	,	alt_guard	:: !ParsedExpr
	,	alt_expr	:: !OptGuardedAlts
1064
	,	alt_ident	:: !Ident
1065
	,	alt_position:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1066
1067
1068
1069
1070
1071
	}

::	ExprWithLocalDefs = 
	{	ewl_nodes	:: ![NodeDefWithLocals]
	,	ewl_expr	:: !ParsedExpr
	,	ewl_locals	:: !LocalDefs
1072
	,	ewl_position:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1073
1074
1075
	}

::	NodeDefWithLocals =
1076
1077
1078
1079
	{	ndwl_strict		:: !Bool
	,	ndwl_def		:: !Bind ParsedExpr ParsedExpr
	,	ndwl_locals		:: !LocalDefs
	,	ndwl_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1080
1081
1082
1083
1084
1085
1086
1087
1088
	}

::	CaseAlt =
	{	calt_pattern	:: !ParsedExpr
	,	calt_rhs		:: !Rhs
	}
	
:: LocalDef		:== ParsedDefinition

1089
1090
1091
1092
::	ParsedSelectorKind
		=	ParsedNormalSelector	// .
		|	ParsedUniqueSelector	// !
				!Bool					// 	is result element unique?
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1093
1094
1095
1096
1097

::	ParsedExpr	= PE_List ![ParsedExpr]
				| PE_Ident !Ident
				| PE_Basic !BasicValue
				| PE_Bound !BoundExpr
Martin Wierich's avatar
Martin Wierich committed
1098
				| PE_Lambda !Ident ![ParsedExpr] !ParsedExpr !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1099
1100
				| PE_Tuple ![ParsedExpr]				
				| PE_Record !ParsedExpr !(Optional Ident) ![FieldAssignment]
1101
				| PE_ArrayPattern ![ElemAssignment]
1102
				| PE_UpdateComprehension !ParsedExpr !ParsedExpr !ParsedExpr ![Qualifier]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1103
				| PE_ArrayDenot ![ParsedExpr]
1104
				| PE_Selection !ParsedSelectorKind !ParsedExpr ![ParsedSelection]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1105
1106
1107
1108
				| PE_Update !ParsedExpr [ParsedSelection] ParsedExpr
				| PE_Case !Ident !ParsedExpr [CaseAlt]
				| PE_If !Ident !ParsedExpr !ParsedExpr !ParsedExpr
				| PE_Let !Bool !LocalDefs !ParsedExpr
1109
1110
				| PE_ListCompr /*predef_cons_index:*/ !Int /*predef_nil_index:*/ !Int !ParsedExpr ![Qualifier]
				| PE_ArrayCompr !ParsedExpr ![Qualifier]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1111
1112
1113
1114
1115
1116
1117
1118
1119
				| PE_Sequ Sequence
				| PE_WildCard
				| PE_Field !ParsedExpr !(Global FieldSymbol) /* Auxiliary, used during checking */

				| PE_ABC_Code ![String] !Bool
				| PE_Any_Code !(CodeBinding Ident) !(CodeBinding Ident) ![String]

				| PE_DynamicPattern !ParsedExpr !DynamicType
				| PE_Dynamic !ParsedExpr !(Optional DynamicType)
1120
1121
1122
				
				| PE_Generic !Ident !TypeKind	/* AA: For generics, kind indexed identifier */
				
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1123
1124
1125
1126
1127
1128
				| PE_Empty

::	ParsedSelection	= PS_Record !Ident !(Optional Ident)
					| PS_Array  !ParsedExpr
					| PS_Erroneous

1129
::	GeneratorKind = IsListGenerator | IsOverloadedListGenerator | IsArrayGenerator
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1130
			
1131
1132
:: LineAndColumn = {lc_line :: !Int, lc_column :: !Int}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1133
1134
1135
1136
::	Generator =
	{	gen_kind	:: !GeneratorKind
	,	gen_pattern :: !ParsedExpr
	,	gen_expr	:: !ParsedExpr
1137
	,	gen_position :: !LineAndColumn
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1138
1139
1140
1141
1142
	}

::	Qualifier	=
	{	qual_generators	:: ![Generator]
	,	qual_filter		:: !Optional ParsedExpr
1143
	,	qual_position	:: !LineAndColumn
Martin Wierich's avatar
Martin Wierich committed
1144
	,	qual_filename	:: !FileName
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1145
1146
	}

1147
1148
1149
1150
::	Sequence	= SQ_FromThen !Int ParsedExpr ParsedExpr
				| SQ_FromThenTo !Int ParsedExpr ParsedExpr ParsedExpr
				| SQ_From !Int ParsedExpr
				| SQ_FromTo !Int ParsedExpr ParsedExpr
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1151
1152
1153
1154
1155

::	BoundExpr	:== Bind ParsedExpr Ident

::	FieldAssignment :== Bind ParsedExpr Ident

1156
::	ElemAssignment :== Bind ParsedExpr [ParsedExpr]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1157
1158
1159
1160
1161


cIsStrict		:== True
cIsNotStrict	:== False

1162
::	SelectorKind
1163
1164
		=	NormalSelector
		|	NormalSelectorUniqueElementResult
1165
1166
		|	UniqueSelector			// !

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
/*
::	SelectorKind	= SEK_Normal | SEK_First | SEK_Next | SEK_Last

::	ArraySelector	= DictionarySelection !(Global DefinedSymbol) !Int !Expression
					| SelectorInstance !(Global DefinedSymbol)
*/
::	Expression	= Var !BoundVar 
				| App !App
				| (@) infixl 9  !Expression ![Expression]
				| Let !Let
				| Case !Case
1178
				| Selection !SelectorKind !Expression ![Selection]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1179
1180
1181
				| Update !Expression ![Selection] Expression
				| RecordUpdate !(Global DefinedSymbol) !Expression ![Bind Expression (Global FieldSymbol)]
				| TupleSelect !DefinedSymbol !Int !Expression
1182
				| BasicExpr !BasicValue
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1183
1184
1185
1186
1187
1188
				| WildCard
				| Conditional !Conditional

				| AnyCodeExpr !(CodeBinding BoundVar) !(CodeBinding FreeVar) ![String]
				| ABCCodeExpr ![String] !Bool

1189
				| MatchExpr !(Global DefinedSymbol) !Expression
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1190
				| FreeVar FreeVar 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
1191
1192
				| Constant !SymbIdent !Int !Priority !Bool	/* auxiliary clause used during checking */
				| ClassVariable !VarInfoPtr					/* auxiliary clause used during overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1193
1194
1195
1196
1197
1198

				| DynamicExpr !DynamicExpr
//				| TypeCase !TypeCase

				| TypeCodeExpression !TypeCodeExpression
				| EE 
1199
				| NoBind ExprInfoPtr /* auxiliary, to store fields that are not specified in a record expression */ 
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1200
				| FailExpr !Ident // only allowed on (case) root positions
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217


::	CodeBinding	variable :== Env String variable

::	App =
	{	app_symb 		:: !SymbIdent