syntax.dcl 39.4 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
definition module syntax

import StdEnv

import scanner, general, typeproperties, Heap

::	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
	}

29
::	STE_BoundTypeVariable	= { stv_count :: !Int, stv_attribute :: !TypeAttribute, stv_info_ptr :: !TypeVarInfoPtr }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
30
31
32
33
34
35
36
37

::	STE_Kind	= STE_FunctionOrMacro ![Index]
				| STE_Type
				| STE_Constructor
				| STE_Selector ![Global Index]
				| STE_Field !Ident
				| STE_Class
				| STE_Member
38
				| STE_Generic			// AA: For generic declarations
39
				| STE_Instance !Ident // argument: the class (used in explicitimports (1.3 syntax only))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
				| 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
				| STE_Called ![Index] /* used during macro expansion to indicate that this function is called */
54
55
56
				| 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
57
						the "actual" dcl module. Further for each class all encountered
58
59
60
61
						instances are accumulated.
					*/
				| STE_BelongingSymbol !Int

62
63
64
65
66
67
68
::	Declaration = Declaration !DeclarationRecord

::	DeclarationRecord =
	{	decl_ident	:: !Ident
	,	decl_pos	:: !Position
	,	decl_kind	:: !STE_Kind
	,	decl_index	:: !Index
69
70
71
72
73
74
75
	}

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

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
::	Global object =
	{	glob_object	:: !object
	,	glob_module	:: !Index
	}
	
::	Module defs = 
	{	mod_name		:: !Ident
	,	mod_type		:: !ModuleKind
	, 	mod_imports		:: ![ParsedImport]
	,	mod_imported_objects :: ![ImportedObject]
	,	mod_defs		:: !defs
	}

::	ParsedModule	:== Module  [ParsedDefinition]
::	ScannedModule 	:== Module  (CollectedDefinitions (ParsedInstance FunDef) IndexRange)
	
92
::	ModuleKind		= MK_Main | MK_Module | MK_System | MK_None | MK_NoMainDcl
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
93
94
95
96
97
98
99
100

::	RhsDefsOfType	= ConsList ![ParsedConstructor]
					| SelectorList !Ident ![ATypeVar] ![ParsedSelector]
					| TypeSpec !AType
					| EmptyRhs !BITVECT

::	CollectedDefinitions instance_kind macro_defs =
	{	def_types 			:: ![TypeDef TypeRhs]
101
102
	,	def_constructors	:: ![ConsDef]
	,	def_selectors		:: ![SelectorDef]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
103
104
105
	,	def_macros			:: !macro_defs
	,	def_classes			:: ![ClassDef]
	,	def_members			:: ![MemberDef]
106
	,	def_generics		:: ![GenericDef] // AA
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
107
108
109
110
111
112
113
114
115
	,	def_funtypes		:: ![FunType]
	,	def_instances		:: ![instance_kind]
	}

::	LocalDefs	= LocalParsedDefs [ParsedDefinition]
				| CollectedLocalDefs CollectedLocalDefs

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

116
117
118
119
120
121
122
::	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
123
124
125
126
127
128
129
130
131
::  Index	:== Int
NoIndex		:== -1


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

::	CollectedLocalDefs =
	{	loc_functions	:: !IndexRange
132
	,	loc_nodes		:: ![NodeDef ParsedExpr]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
133
134
135
136
137
	}

::	NodeDef dst =
	{	nd_dst		::!dst,
		nd_alts		::!OptGuardedAlts,
138
139
		nd_locals	::!LocalDefs,
		nd_position	::!Position		
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	}

::	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]
157
	|	PD_Generic GenericDef // AA
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
158
159
160
161
162
163
	|	PD_Instance (ParsedInstance ParsedDefinition)
	|	PD_Instances [ParsedInstance ParsedDefinition]
	|	PD_Import [ParsedImport]
	|	PD_ImportedObjects [ImportedObject]
	|	PD_Erroneous

164
165
166
167
::	FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_Unknown

::	DefOrImpFunKind = FK_DefFunction !Bool| FK_ImpFunction !Bool | FK_DefMacro | FK_ImpMacro | FK_ImpCaf | FK_DefOrImpUnknown

168
169
cNameNotLocationDependent :== False
cNameLocationDependent :== True
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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

::	ParsedSelector =
	{	ps_field_name		:: !Ident
	,	ps_selector_name	:: !Ident
	,	ps_field_type		:: !AType
	,	ps_field_var		:: !Ident
	,	ps_field_pos		:: !Position
	}

::	ParsedConstructor =
	{	pc_cons_name 	:: !Ident
	,	pc_cons_arity	:: !Int
	,	pc_exi_vars		:: ![ATypeVar]
	,	pc_arg_types	:: ![AType]
	,	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
196
	,	pi_generate  :: !Bool // AA: instance is to be generated
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
197
198
199
200
201
202
203
	}

/*
	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 
204
	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
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
	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 =
 	{	class_name			:: !Ident
	,	class_arity			:: !Int
	,	class_args			:: ![TypeVar]
	,	class_context		:: ![TypeContext]
	,	class_members		:: !{# DefinedSymbol}
	,	class_dictionary	:: !DefinedSymbol
	,	class_pos			:: !Position
	,	class_cons_vars		:: !BITVECT
252
	,	class_arg_kinds		:: ![TypeKind] // filled in in checkKindCorrectness phase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
253
254
255
256
257
258
259
260
261
262
263
264
265
	}

::	MemberDef =
	{	me_symb			:: !Ident
	,	me_class		:: !Global Index
	,	me_offset		:: !Index
	,	me_type			:: !SymbolType
	,	me_type_ptr		:: !VarInfoPtr
	,	me_class_vars	:: ![TypeVar]
	,	me_pos			:: !Position
	,	me_priority 	:: !Priority
	}

266
// AA ... 
Artem Alimarine's avatar
Artem Alimarine committed
267

268
::	GenericDef = 
Artem Alimarine's avatar
Artem Alimarine committed
269
270
	{	gen_name		:: !Ident				// the generics name in the IC_Class
	,	gen_member_name	:: !Ident				// the generics name in the IC_Member
271
	,	gen_type		:: !GenericType
272
	, 	gen_pos			:: !Position
273
	,	gen_kinds_ptr	:: !TypeVarInfoPtr		// hack: contains all used kinds 
274
	,	gen_cons_ptr 	:: !TypeVarInfoPtr		// hack: cons instance function
Artem Alimarine's avatar
Artem Alimarine committed
275
276
	, 	gen_classes		:: !GenericClassInfos 	// generated classes
	,	gen_isomap		:: !DefinedSymbol		// isomap function
277
	}
Artem Alimarine's avatar
Artem Alimarine committed
278

279
280
281
282
283
284
:: GenericType = 
	{	gt_type 		:: !SymbolType
	,	gt_vars			:: ![TypeVar]			// generic arguments
	,	gt_arity		:: !Int					// number of generic arguments	
	}
	
Artem Alimarine's avatar
Artem Alimarine committed
285
286
287
288
289
290
291
292
293
:: GenericClassInfo = 
	{	gci_kind 	:: !TypeKind
	,	gci_class	:: !DefinedSymbol
	}
:: GenericClassInfos :== [GenericClassInfo] 	 

getGenericClassForKind 	:: !GenericDef !TypeKind -> (!Bool, DefinedSymbol)
addGenericKind			:: !GenericDef !TypeKind -> !GenericDef

294
295
// ... AA

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
::	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
310
311
	,	ins_is_generic	:: !Bool				//AA 
	, 	ins_generate	:: !Bool				//AA
312
	,	ins_partial		:: !Bool				//AA
313
	,	ins_generic		:: !Global Index		//AA 	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
314
315
316
317
318
319
320
321
322
323
324
	}

/*
::	Export =
	{	export_class	:: Ident
	,	export_types	:: [Type]
	}
*/
::	Import from_symbol =
	{	import_module		:: !Ident
	,	import_symbols		:: ![from_symbol]
Martin Wierich's avatar
Martin Wierich committed
325
	,	import_file_position:: !Position	// for error messages
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	}

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])
342
						| ID_OldSyntax ![Ident]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
343
344
345

cIsImportedLibrary :== True
cIsImportedObject :== False
346

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
347
348
349
350
351
352
353
354
355
356
357
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
:: ImportedObject =
	{	io_is_library :: !Bool
	,	io_name    :: !{#Char}
	}

::	RecordType =
	{	rt_constructor	:: !DefinedSymbol
	,	rt_fields		:: !{# FieldSymbol}
	}
	
::	FieldSymbol =
	{	fs_name			:: !Ident
	,	fs_var			:: !Ident
	,	fs_index		:: !Index
	}

::	TypeRhs	= AlgType ![DefinedSymbol]
			| SynType !AType
			| RecordType !RecordType
			| AbstractType !BITVECT
			| UnknownType

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

/*
cIsHyperStrict		:== True
cIsNotHyperStrict	:== False
*/

cAllBitsClear			:== 0

cIsHyperStrict			:== 1
cIsNonCoercible			:== 2
// cMayBeNonCoercible		:== 4

::	TypeDef type_rhs =
 	{	td_name			:: !Ident
	,	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
	}

::	TypeDefInfo =
	{	tdi_kinds			:: ![TypeKind]
	,	tdi_properties		:: !BITVECT
	,	tdi_group			:: ![Global Index]
	,	tdi_group_nr		:: !Int
	,	tdi_group_vars		:: ![Int]
	,	tdi_cons_vars		:: ![Int]
402
	,	tdi_tmp_index		:: !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
	,	tdi_classification	:: !TypeClassification
	}

::	TypeDefInfos :== {# .{# TypeDefInfo}}

::	FunType =
	{	ft_symb			:: !Ident
	,	ft_arity		:: !Int
	,	ft_priority		:: !Priority
	,	ft_type			:: !SymbolType
	,	ft_pos			:: !Position
	,	ft_specials		:: !Specials
	,	ft_type_ptr		:: !VarInfoPtr
	}

::	FreeVar =
	{	fv_def_level	:: !Level
	,	fv_name			:: !Ident
	,	fv_info_ptr		:: !VarInfoPtr
//	,	fv_expr_ptr		:: !ExprInfoPtr
	,	fv_count		:: !Int
	}
	
::	FunCall =
	{	fc_level	:: !Level
	,	fc_index	:: !Index
	}

431
432
433
434
435
/* Sjaak 19-3-2001 ... */

FI_IsMacroFun	:== 1			// whether the function is a local function of a macro
FI_HasTypeSpec	:== 2			// whether the function has u user defined type

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
436
437
438
439
440
441
442
::	FunInfo =
	{	fi_calls			:: ![FunCall]
	,	fi_group_index		:: !Index
	,	fi_def_level		:: !Level
	,	fi_free_vars		:: ![FreeVar]
	,	fi_local_vars		:: ![FreeVar]
	,	fi_dynamics			:: ![ExprInfoPtr]
443
	,	fi_properties		:: !BITVECT
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
444
	}
445
/* ... Sjaak 19-3-2001 */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
446
447

::	ParsedBody =
448
449
450
	{	pb_args		:: ![ParsedExpr]
	,	pb_rhs		:: !Rhs
	,	pb_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
451
452
453
	}

::	CheckedBody =
454
455
	{	cb_args		:: ![FreeVar]
	,	cb_rhs		:: ![CheckedAlternative]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
456
457
	}

458
459
460
461
462
463
::	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
464
465
466
467
468
469
470
471
472
473
474
475
476
::	TransformedBody =
	{	tb_args			:: ![FreeVar]
	,	tb_rhs			:: !Expression
	}

::	FunctionBody	= ParsedBody ![ParsedBody]
					| CheckedBody !CheckedBody
	/* The next three constructors are used during macro expansion (module transform) */
					| PartioningMacro
					| PartioningFunction !CheckedBody !Int
					| RhsMacroBody !CheckedBody
	/* macro expansion transforms a CheckedBody into a TransformedBody */
					| TransformedBody !TransformedBody
477
					| Expanding ![FreeVar] // the parameters of the newly generated function
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
478
					| BackendBody ![BackendBody]
479
					| NoBody
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
480
481
482
483
484
485
486
487
488
489
490
491
492
					
::	BackendBody =
	{	bb_args	:: ![FunctionPattern]
	,	bb_rhs	:: !Expression
	}

::	FunDef =
	{	fun_symb		:: !Ident
	,	fun_arity		:: !Int
	,	fun_priority	:: !Priority
	,	fun_body		:: !FunctionBody
	,	fun_type		:: !Optional SymbolType
	,	fun_pos			:: !Position
493
	,	fun_kind		:: !DefOrImpFunKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
494
495
496
497
498
499
500
501
	,	fun_lifted		:: !Int
	,	fun_info		:: !FunInfo
	}

cIsAGlobalVar	:== True
cIsALocalVar	:== False

::	ConsClasses =
502
	{	cc_size			::!Int
503
504
	,	cc_args			::![ConsClass]
	,	cc_linear_bits	::![Bool]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
505
506
507
508
509
510
511
512
513
514
515
516
	}
					
::	ConsClass	:== Int

::	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
517
		| AP_WildCard !OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
518
519
520
521
		| AP_Empty !Ident

:: AP_Kind = APK_Constructor !Index | APK_Macro

522
523
::	VarInfo  =	VI_Empty | VI_Type !AType !(Optional CoercionPosition) | VI_FAType ![ATypeVar] !AType !(Optional CoercionPosition) |
				VI_Occurrence !Occurrence | VI_UsedVar !Ident |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
524
525
				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 */ |
526
				VI_AccVar !ConsClass !ArgumentPosition /* used during fusion to determine accumulating parameters of functions */ |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
527
528
529
				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
530
531
				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
532
				VI_Forward !BoundVar | VI_LetVar !LetVarInfo | VI_LetExpression !LetExpressionInfo | VI_CaseVar !VarInfoPtr |
533
				VI_CorrespondenceNumber !Int | /* it is assumed that this alternative is _only_ used in module comparedefimp */
534
				VI_SequenceNumber !Int | VI_AliasSequenceNumber !BoundVar |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
535
536
537
538
539
				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 |
540
				VI_Default !Int | VI_Indirection !Int | /* used during conversion of dynamics; the Int indiacted the refenrence count */
541
				VI_Body !SymbIdent !TransformedBody ![FreeVar] | /* used during fusion */
542
				VI_Dictionary !SymbIdent ![Expression] !Type | /* used during fusion */
Sjaak Smetsers's avatar
Sjaak Smetsers committed
543
				VI_Extended !ExtendedVarInfo !VarInfo |
544
				VI_Defined /* for marking type code variables during overloading */ | VI_LocallyDefined |
545
546
547
// MdM
				VI_CPSLocalExprVar !Int /* MdM - the index of the variable as generated by the theorem prover */
// ... MdM
548
549
				| VI_Labelled_Empty {#Char} // RWS debugging
				| VI_LocalLetVar // RWS, mark Let vars during case transformation
550

551
::	ExtendedVarInfo = EVI_VarType !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
552

553
554
::	ArgumentPosition :== Int

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
::	VarInfoPtr	:== Ptr VarInfo

::	LetVarInfo =
	{	lvi_count		:: !Int
	,	lvi_depth		:: !Int
	,	lvi_new			:: !Bool
	,	lvi_var			:: !Ident
	,	lvi_expression	:: !Expression	
	,   lvi_previous	:: ![PreviousLetVarInfo]
	}

::	PreviousLetVarInfo =
	{	plvi_count		:: !Int
	,	plvi_depth		:: !Int
	,	plvi_new		:: !Bool
	}

::	LetExpressionStatus	= LES_Untouched | LES_Moved | LES_Updated !Expression

::	LetExpressionInfo =
	{	lei_count			:: !Int
	,	lei_depth			:: !Int 
	,	lei_var				:: !FreeVar 
	,   lei_expression		:: !Expression
	,   lei_status			:: !LetExpressionStatus
	,   lei_type			:: !AType
	}

cNotVarNumber :== -1

::	BoundVar = 
	{	var_name		:: !Ident
	,	var_info_ptr	:: !VarInfoPtr
	,	var_expr_ptr	:: !ExprInfoPtr
	}

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

::	ApplicationKind	:== Bool
*/
 
::	TypeSymbIdent =
	{	type_name		:: !Ident
	,	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)
613
				| SK_LocalMacroFunction !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
614
				| SK_OverloadedFunction !(Global Index)
615
				| SK_Generic !(Global Index) !TypeKind		// AA
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
				| SK_Constructor !(Global Index)
				| SK_Macro !(Global Index)
//				| SK_RecordSelector !(Global Index)
				| SK_GeneratedFunction !FunctionInfoPtr !Index
				| 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
635
				| PR_Function !SymbIdent !Index
Martin Wierich's avatar
Martin Wierich committed
636
				| PR_Class !App ![(BoundVar, Type)] !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
637
//				| PR_Constructor !SymbIdent ![Expression]
638
639
				| PR_GeneratedFunction !SymbIdent !Index
				| PR_Curried !SymbIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665

::	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
666
667
//					| EI_Selection 	![Selection] !BoundVar ![Expression]	/* intermedediate, used during resolving of overloading */
					| EI_Selection 	![Selection] !VarInfoPtr ![Expression]	/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
668
669
670
671
					| EI_Context 	![Expression]							/* intermedediate, used during resolving of overloading */

		/* For handling dynamics */

Martijn Vervoort's avatar
Martijn Vervoort committed
672
					| EI_Dynamic 				!(Optional DynamicType) !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
					| EI_DynamicType			!DynamicType ![DynamicPtr]
//					| EI_DynamicType			!DynamicType !(Optional ExprInfoPtr)

		/* Auxiliary, was EI_DynamicType before checking */

					| EI_DynamicTypeWithVars	![TypeVar] !DynamicType ![DynamicPtr]				
//					| EI_DynamicTypeWithVars	![TypeVar] !DynamicType !(Optional ExprInfoPtr)			

		/* Auxiliary, used during type checking */

					| EI_TempDynamicType 		!(Optional DynamicType) !AType ![TypeContext] !ExprInfoPtr !SymbIdent
//					| EI_TempDynamicPattern 	![TypeVar] !DynamicType !(Optional ExprInfoPtr) ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
					| EI_TempDynamicPattern 	![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
					
					| EI_TypeOfDynamic 			![VarInfoPtr] !TypeCodeExpression				/* Final */
					| EI_TypeOfDynamicPattern 	![VarInfoPtr] !TypeCodeExpression				/* Final */

					| EI_TypeCode 		!TypeCodeExpression
					| EI_TypeCodes 		![TypeCodeExpression]

					| EI_Attribute !Int

695
		/* 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
696
697
		   the fusion result (i.e. the resulting function after elimination of dictionaries) */

698
					| EI_DictionaryType !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
699
700
701
702
703
704
705
					| EI_CaseType !CaseType
					| EI_LetType ![AType]
					| EI_CaseTypeAndRefCounts !CaseType !RefCountsInCase
					| EI_LetTypeAndRefCounts ![AType] ![Int]

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

706

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
707
708
					| EI_Default !Expression !AType !ExprInfoPtr
					| EI_DefaultFunction !SymbIdent ![Expression]
709
					| EI_Extended !ExtendedExprInfo !ExprInfo
710
711
712
713

::	ExtendedExprInfo
					= EEI_ActiveCase !ActiveCaseInfo

714

715
::	ActiveCaseInfo =
716
717
718
719
	{	aci_params					:: ![FreeVar]
	,	aci_opt_unfolder			:: !(Optional SymbIdent)
	,	aci_free_vars				:: !Optional [BoundVar]
	,	aci_linearity_of_patterns	:: ![[Bool]]
720
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
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

::	RefCountsInCase = 
	{	rcc_all_variables		:: ![CountedVariable]
	,	rcc_default_variables	:: ![CountedVariable]
	,	rcc_pattern_variables	:: ![[CountedVariable]]
	}

::	CountedVariable =
	{	cv_variable	:: !VarInfoPtr
	,	cv_count	:: !Int
	}

/*
::	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 =
	{	symb_name		:: !Ident
	,	symb_kind		:: !SymbKind
	,	symb_arity		:: !Int
	}

::	ConsDef =
	{	cons_symb			:: !Ident
	,	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 =
	{	sd_symb			:: !Ident
	,	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]
	,	st_arity		:: !Int
	,	st_result		:: !AType
	,	st_context		:: ![TypeContext]
	,	st_attr_vars	:: ![AttributeVar]
	,	st_attr_env		:: ![AttrInequality]
	}

::	TypeContext =
	{	tc_class	:: !Global DefinedSymbol
	,	tc_types	:: ![Type]
	,	tc_var		:: !VarInfoPtr
	}

::	AType =
	{	at_attribute	:: !TypeAttribute
	,	at_annotation	:: !Annotation
	,	at_type			:: !Type
	}
	
::	TempAttrId		:== Int
::	TempVarId		:== Int


::	Type	=	TA !TypeSymbIdent ![AType]
			|	(-->) infixr 9 !AType !AType
825
826
			| 	TArrow							/* (->) */
			| 	TArrow1	!AType					/* ((->) a) */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
827
828
829
			|	(:@:) infixl 9 !ConsVariable ![AType]
			|	TB !BasicType

830
			|	TFA [ATypeVar] Type				/* Universally quantified types */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
831
832
833
834
835
836
837
838
839
840

			| 	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 */
841

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
			|	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
				| KI_Arrow ![KindInfo]
				| KI_Const
				
				| KI_ConsVar
				
				| KI_VarBind !KindInfoPtr
				| KI_NormVar !Int

::	TypeVarInfo  	= TVI_Empty
					| TVI_Type !Type
868
					| TVI_TypeVar !TypeVarInfoPtr // Sjaak: to collect and check universally quantified type variables
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
869
870
871
					| TVI_Forward !TempVarId | TVI_TypeKind !KindInfoPtr
					| TVI_SignClass !Index !SignClassification !TypeVarInfo | TVI_PropClass !Index !PropClassification !TypeVarInfo
					| TVI_Attribute TypeAttribute
872
873
					| TVI_CorrespondenceNumber !Int /* auxiliary used in module comparedefimp */
					| TVI_AType !AType /* auxiliary used in module comparedefimp */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
874
875
					| TVI_Used /* to administer that this variable is encountered (in checkOpenTypes) */
					| TVI_TypeCode !TypeCodeExpression
876
					| TVI_CPSLocalTypeVar !Int /* MdM - the index of the variable as generated by the theorem prover */
877
					| TVI_Kinds ![TypeKind] // AA: used to collect kinds during checking 
878
					| TVI_Kind !TypeKind
879
					| TVI_ConsInstance !DefinedSymbol //AA: generic cons instance function 
Martijn Vervoort's avatar
Martijn Vervoort committed
880
					| TVI_Normalized !Int /* MV - position of type variable in its definition */
881
					
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
882
883
884
::	TypeVarInfoPtr	:== Ptr TypeVarInfo
::	TypeVarHeap 	:== Heap TypeVarInfo

885
886
887
888
::	AttrVarInfo  	= AVI_Empty
					| AVI_Attr !TypeAttribute
					| AVI_AttrVar !AttrVarInfoPtr // Sjaak: to collect universally quantified attribute variables
					| AVI_Forward !TempAttrId 
889
					| AVI_CorrespondenceNumber !Int /* auxiliary used in module comparedefimp */
890
					| AVI_Used
891
					| AVI_Count !Int /* auxiliary used in module typesupport */
892
893
					| AVI_SequenceNumber !Int // RWS

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
::	AttrVarInfoPtr	:== Ptr AttrVarInfo
::	AttrVarHeap 	:== Heap AttrVarInfo

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

::	TypeVar =
	{	tv_name				:: !Ident
	,	tv_info_ptr			:: !TypeVarInfoPtr
	}

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

913
::	TypeAttribute = TA_Unique | TA_Multi | TA_Var !AttributeVar | TA_RootVar AttributeVar | TA_TempVar !Int // | TA_TempExVar !Int
914
915
916
					| TA_Anonymous | TA_None
					| TA_List !Int !TypeAttribute | TA_Locked !TypeAttribute
					| TA_MultiOfPropagatingConsVar // only filled in after type checking, semantically equal to TA_Multi
917
					| TA_PA_BUG
918
							
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
919
920
921
922
923
924
925
926
927
928
929
930
931
::	AttributeVar =
	{	av_name			:: !Ident
	,	av_info_ptr		:: !AttrVarInfoPtr
	}

::	Annotation	=  AN_Strict | AN_None 

::	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 */

::	BasicValue	= BVI !String | BVC !String | BVB !Bool | BVR !String | BVS !String

932
933
::	TypeKind = KindVar !KindInfoPtr | KindConst | KindArrow ![TypeKind]

934
935
936
937
instance toString 	TypeKind
instance <<< 		TypeKind
instance == 		TypeKind
instance toString 	KindInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973

/* A few obscure type definitions */

::	Occurrence =
	{	occ_ref_count	:: !ReferenceCount
//	,	occ_aliases		:: ![[(FreeVar,Int)]]
//	,	occ_expression	:: !Expression
	,	occ_bind		:: !OccurrenceBinding
	,	occ_observing	:: !Bool
//	,	occ_attribute	:: !ExprInfoPtr
	,	occ_previous 	:: ![ReferenceCount]
	}

::	ReferenceCount = RC_Used !RC_Used | RC_Unused 

::	SelectiveUse = { su_field :: !Int, su_multiply :: ![ExprInfoPtr], su_uniquely :: ![ExprInfoPtr]  }

::	RC_Used = { rcu_multiply :: ![ExprInfoPtr], rcu_selectively :: ![SelectiveUse], rcu_uniquely :: ![ExprInfoPtr] }

::	OccurrenceBinding	= OB_Empty | OB_OpenLet !Expression | OB_LockedLet !Expression
						| OB_Pattern ![(FreeVar, Int)] !OccurrenceBinding
//						| OB_Closed !LetOccurrences | OB_Marked !LetOccurrences

/*
::	LetOccurrences =
	{	lo_used_lets		:: ![FreeVar]
	,	lo_free_variables	:: ![(FreeVar, ReferenceCount)]
	}
*/
::	OptGuardedAlts	= GuardedAlts ![GuardedExpr] !(Optional ExprWithLocalDefs)
				 	| UnGuardedExpr !ExprWithLocalDefs

::	GuardedExpr =
	{	alt_nodes	:: ![NodeDefWithLocals]
	,	alt_guard	:: !ParsedExpr
	,	alt_expr	:: !OptGuardedAlts
974
	,	alt_ident	:: !Ident
975
	,	alt_position:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
976
977
978
979
980
981
	}

::	ExprWithLocalDefs = 
	{	ewl_nodes	:: ![NodeDefWithLocals]
	,	ewl_expr	:: !ParsedExpr
	,	ewl_locals	:: !LocalDefs
982
	,	ewl_position:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
983
984
985
	}

::	NodeDefWithLocals =
986
987
988
989
	{	ndwl_strict		:: !Bool
	,	ndwl_def		:: !Bind ParsedExpr ParsedExpr
	,	ndwl_locals		:: !LocalDefs
	,	ndwl_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
	}

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

cUniqueSelection	:== True
cNonUniqueSelection	:== False

::	ParsedExpr	= PE_List ![ParsedExpr]
				| PE_Ident !Ident
				| PE_Basic !BasicValue
				| PE_Bound !BoundExpr
Martin Wierich's avatar
Martin Wierich committed
1006
				| PE_Lambda !Ident ![ParsedExpr] !ParsedExpr !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1007
1008
				| PE_Tuple ![ParsedExpr]				
				| PE_Record !ParsedExpr !(Optional Ident) ![FieldAssignment]
1009
				| PE_ArrayPattern ![ElemAssignment]
1010
				| PE_UpdateComprehension !ParsedExpr !ParsedExpr !ParsedExpr ![Qualifier]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1011
1012
1013
1014
1015
1016
				| PE_ArrayDenot ![ParsedExpr]
				| PE_Selection !Bool !ParsedExpr ![ParsedSelection]
				| PE_Update !ParsedExpr [ParsedSelection] ParsedExpr
				| PE_Case !Ident !ParsedExpr [CaseAlt]
				| PE_If !Ident !ParsedExpr !ParsedExpr !ParsedExpr
				| PE_Let !Bool !LocalDefs !ParsedExpr
1017
1018
				| 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
1019
1020
1021
1022
1023
1024
1025
1026
1027
				| 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)
1028
1029
1030
				
				| PE_Generic !Ident !TypeKind	/* AA: For generics, kind indexed identifier */
				
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1031
1032
1033
1034
1035
1036
1037
1038
				| PE_Empty

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

::	GeneratorKind :== Bool

1039
1040
IsListGenerator 	:== True
IsArrayGenerator	:== False
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1041
			
1042
1043
:: LineAndColumn = {lc_line :: !Int, lc_column :: !Int}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1044
1045
1046
1047
::	Generator =
	{	gen_kind	:: !GeneratorKind
	,	gen_pattern :: !ParsedExpr
	,	gen_expr	:: !ParsedExpr
1048
	,	gen_position :: !LineAndColumn
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1049
1050
1051
1052
1053
	}

::	Qualifier	=
	{	qual_generators	:: ![Generator]
	,	qual_filter		:: !Optional ParsedExpr
1054
	,	qual_position	:: !LineAndColumn
Martin Wierich's avatar
Martin Wierich committed
1055
	,	qual_filename	:: !FileName
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
	}

::	Sequence	= SQ_FromThen ParsedExpr ParsedExpr
				| SQ_FromThenTo ParsedExpr ParsedExpr ParsedExpr
				| SQ_From ParsedExpr
				| SQ_FromTo ParsedExpr ParsedExpr

::	BoundExpr	:== Bind ParsedExpr Ident

::	FieldAssignment :== Bind ParsedExpr Ident

1067
::	ElemAssignment :== Bind ParsedExpr [ParsedExpr]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084


cIsStrict		:== True
cIsNotStrict	:== False

/*
::	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
				| Selection !(Optional (Global DefinedSymbol)) !Expression ![Selection]
1085
							// Yes: a "!" selection
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1086
1087
1088
				| Update !Expression ![Selection] Expression
				| RecordUpdate !(Global DefinedSymbol) !Expression ![Bind Expression (Global FieldSymbol)]
				| TupleSelect !DefinedSymbol !Int !Expression
1089
//				| Lambda .[FreeVar] !Expression
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1090
1091
1092
1093
1094
1095
1096
1097
1098
				| BasicExpr !BasicValue !BasicType
				| WildCard
				| Conditional !Conditional

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

				| MatchExpr !(Optional (Global DefinedSymbol)) !(Global DefinedSymbol) !Expression
				| FreeVar FreeVar 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
1099
1100
				| 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
1101
1102
1103
1104
1105
1106

				| DynamicExpr !DynamicExpr
//				| TypeCase !TypeCase

				| TypeCodeExpression !TypeCodeExpression
				| EE 
1107
				| NoBind ExprInfoPtr /* auxiliary, to store fields that are not specified in a record expression */ 
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124


::	CodeBinding	variable :== Env String variable

::	App =
	{	app_symb 		:: !SymbIdent
	,	app_args 		:: ![Expression]
	,	app_info_ptr	:: !ExprInfoPtr
	}

::	Case =
	{	case_expr		:: !Expression
//	,	case_guards		:: ![PatternExpression]
	,	case_guards		:: !CasePatterns
	,	case_default	:: !Optional Expression
	,	case_ident		:: !Optional Ident
	,	case_info_ptr	:: !ExprInfoPtr
1125
1126
1127
// RWS ...
	,	case_explicit	:: !Bool
// ... RWS
1128
	,	case_default_pos:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1129
	}
Sjaak Smetsers's avatar
Sjaak Smetsers committed
1130
1131

::	Let =
1132
1133
	{	let_strict_binds	:: ![LetBind]
	,	let_lazy_binds		:: ![LetBind]
Sjaak Smetsers's avatar
Sjaak Smetsers committed
1134
1135
	,	let_expr			:: !Expression
	,	let_info_ptr		:: !ExprInfoPtr
1136
1137
1138
1139
1140
1141
1142
	,	let_expr_position	:: !Position
	}

::	LetBind =
	{	lb_dst		:: !FreeVar
	,	lb_src		:: !Expression
	,	lb_position	:: !Position
Sjaak Smetsers's avatar
Sjaak Smetsers committed
1143
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168

::	Conditional =
	{	if_cond		:: !Expression
	,	if_then		:: !Expression
	,	if_else		:: !Optional Expression
	}

/*
::	Conditional =
	{	if_cond		:: !Condition
	,	if_then		:: !Expression
	,	if_else		:: !Optional Expression
	}


::	Condition =
	{	con_positive 	:: !Bool
	,	con_expression	:: !Expression
	}
*/

::	DynamicExpr =
	{	dyn_expr		:: !Expression
	,	dyn_opt_type	:: !Optional DynamicType
	,	dyn_info_ptr	:: !ExprInfoPtr
1169
//	,	dyn_uni_vars	:: ![VarInfoPtr]			/* filled after type checking */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1170
1171
1172
	,	dyn_type_code	:: !TypeCodeExpression		/* filled after type checking */
	}	

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
::	CasePatterns= AlgebraicPatterns !(Global Index) ![AlgebraicPattern]
				| BasicPatterns !BasicType [BasicPattern]
				| DynamicPatterns [DynamicPattern]						/* auxiliary */
				| OverloadedListPatterns !OverloadedListType !Expression ![AlgebraicPattern]
				| NoPattern											/* auxiliary */

::	OverloadedListType	= UnboxedList !(Global Index) !Index !Index !Index // list_type_symbol StdStrictLists module index, decons_u index, nil_u index
						| UnboxedTailStrictList !(Global Index) !Index !Index !Index // list_type_symbol StdStrictLists module index, decons_uts index, nil_uts index
						| OverloadedList !(Global Index) !Index !Index !Index // list_type_symbol StdStrictLists module index, decons index, nil index

instance == OverloadedListType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1184
1185
1186
1187
1188

::	Selection	= RecordSelection !(Global DefinedSymbol) !Int
				| ArraySelection !(Global DefinedSymbol) !ExprInfoPtr !Expression
				| DictionarySelection !BoundVar ![Selection] !ExprInfoPtr !Expression

1189
1190
1191
1192
1193
1194
::	TypeCodeExpression	= TCE_Empty
						| TCE_Var 			!VarInfoPtr
						| TCE_TypeTerm		!VarInfoPtr
						| TCE_Constructor	!Index			![TypeCodeExpression]
						| TCE_Selector		![Selection]	!VarInfoPtr
						| TCE_UniType 		![VarInfoPtr] 	!TypeCodeExpression
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1195

1196
::	GlobalTCType = GTT_Basic !BasicType	| GTT_Constructor !TypeSymbIdent !String | GTT_Function
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
	

::	FunctionPattern	= FP_Basic !BasicValue !(Optional FreeVar)
					| FP_Algebraic !(Global DefinedSymbol) ![FunctionPattern] !(Optional FreeVar)
					| FP_Variable !FreeVar
					| FP_Dynamic ![VarInfoPtr] !FreeVar !TypeCodeExpression !(Optional FreeVar)
					| FP_Empty

::	AlgebraicPattern =
	{	ap_symbol	:: !(Global DefinedSymbol)
	,	ap_vars		:: ![FreeVar]
	,	ap_expr		:: !Expression
1209
	,	ap_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1210
1211
1212
1213
1214
	}
	
::	BasicPattern =
	{	bp_value	:: !BasicValue
	,	bp_expr		:: !Expression
1215
	,	bp_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
	}

::	TypeCase =
	{	type_case_dynamic	:: !Expression 
	,	type_case_patterns 	:: ![DynamicPattern]
	,	type_case_default	:: !Optional Expression
	,	type_case_info_ptr	:: !ExprInfoPtr
	}
	
::	DynamicPattern =
	{	dp_var					:: !FreeVar
	,	dp_type					:: !ExprInfoPtr
	,	dp_type_patterns_vars	:: ![VarInfoPtr]			/* filled after type checking */
	,	dp_type_code			:: !TypeCodeExpression		/* filled after type checking */
	,	dp_rhs					:: !Expression
1231
	,	dp_position				:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
	}
	
/*
	error handling
*/

:: Position			= FunPos  FileName LineNr FunctName
					| LinePos FileName LineNr
					| PreDefPos Ident
					| NoPos

Martin Wierich's avatar
Martin Wierich committed
1243
1244
1245
::	CoercionPosition
	=	CP_Expression !Expression
	|	CP_FunArg !Ident !Int // Function symbol, argument position (>=1)
1246
	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
::	IdentPos =
	{	ip_ident	:: !Ident
	,	ip_line		:: !Int
	,	ip_file		:: !FileName
	}

:: FileName			:== String

:: FunctName		:== String

:: LineNr			:== Int

cNotALineNumber :== -1

/* Used for hashing identifiers */

instance == ModuleKind, Ident
1264
1265
instance <<< (Module a) | <<< a, ParsedDefinition, InstanceType, AttributeVar, TypeVar, SymbolType, Expression, Type, Ident, (Global object) | <<< object,
			 Position, CaseAlt, AType, FunDef, ParsedExpr, TypeAttribute, (Bind a b) | <<< a & <<< b, ParsedConstructor, (TypeDef a) | <<< a, TypeVarInfo,
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1266
			 BasicValue, ATypeVar, TypeRhs, FunctionPattern, (Import from_symbol) | <<< from_symbol, ImportDeclaration, ImportedIdent, CasePatterns,
1267
			 (Optional a) | <<< a, ConsVariable, BasicType, Annotation, Selection, SelectorDef, ConsDef, LocalDefs, FreeVar, ClassInstance, SignClassification,
Martin Wierich's avatar
Martin Wierich committed
1268
			 TypeCodeExpression, CoercionPosition, AttrInequality, LetBind, Declaration, STE_Kind, BoundVar
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1269

1270
1271
instance <<< FunctionBody

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1272
1273
1274
1275
1276
1277
1278
instance == TypeAttribute
instance == Annotation
/*
ErrorToString :: Error -> String

*/

1279
1280
1281
1282
1283
EmptySymbolTableEntry :== EmptySymbolTableEntryCAF.boxed_symbol_table_entry

::BoxedSymbolTableEntry = {boxed_symbol_table_entry::!SymbolTableEntry}

EmptySymbolTableEntryCAF :: BoxedSymbolTableEntry
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1284
1285
1286
1287

cNotAGroupNumber :== -1

EmptyTypeDefInfo :== { tdi_kinds = [], tdi_properties = cAllBitsClear, tdi_group = [], tdi_group_vars = [], tdi_cons_vars = [],
1288
					   tdi_classification = EmptyTypeClassification, tdi_group_nr = cNotAGroupNumber, tdi_tmp_index = NoIndex }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1289
1290
1291
1292
1293
1294
1295
1296

MakeTypeVar name	:== { tv_name = name, tv_info_ptr = nilPtr }
MakeVar name		:== { var_name = name, var_info_ptr = nilPtr, var_expr_ptr = nilPtr }

MakeAttributedType type :== { at_attribute = TA_None, at_annotation = AN_None, at_type = type }
MakeAttributedTypeVar type_var :== { atv_attribute = TA_None, atv_annotation = AN_None, atv_variable = type_var }

EmptyFunInfo :== { fi_calls = [], fi_group_index = NoIndex, fi_def_level = NotALevel,
1297
				   fi_free_vars = [], fi_local_vars = [], fi_dynamics = [], fi_properties=0 }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1298
1299
1300
1301
1302
1303
1304

BottomSignClass		:== { sc_pos_vect = 0, sc_neg_vect = 0 }
PostiveSignClass	:== { sc_pos_vect = bitnot 0, sc_neg_vect = 0 }

NoPropClass			:== 0
PropClass			:== bitnot 0

1305
1306
newTypeSymbIdentCAF :: TypeSymbIdent;

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1307
MakeNewTypeSymbIdent name arity
1308
1309
	:== {newTypeSymbIdentCAF & type_name=name, type_arity=arity }

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1310
MakeTypeSymbIdent type_index name arity
1311
	:== {	newTypeSymbIdentCAF & type_name = name, type_arity = arity, type_index = type_index }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1312
1313
1314
1315

MakeSymbIdent name arity	:== { symb_name = name, symb_kind = SK_Unknown, symb_arity = arity  }
MakeConstant name			:== MakeSymbIdent name 0

1316
1317
ParsedSelectorToSelectorDef sd_type_index ps :==
	{	sd_symb = ps.ps_selector_name, sd_field_nr = NoIndex, sd_pos =  ps.ps_field_pos, sd_type_index = sd_type_index,
1318
		sd_exi_vars = [], sd_type_ptr = nilPtr, sd_field = ps.ps_field_name,
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1319
1320
1321
		sd_type	= { st_vars = [], st_args = [], st_result = ps.ps_field_type, st_arity = 0, st_context = [],
				    st_attr_env = [], st_attr_vars = [] }}

1322
ParsedConstructorToConsDef pc :==
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1323
1324
1325
	{	cons_symb = pc.pc_cons_name, cons_pos = pc.pc_cons_pos, cons_priority = pc.pc_cons_prio, cons_index = NoIndex, cons_type_index = NoIndex,
		cons_type = { st_vars = [], st_args = pc.pc_arg_types, st_result = MakeAttributedType TE, 
				  st_arity = pc.pc_cons_arity, st_context = [], st_attr_env = [], st_attr_vars = []},
1326
1327
		cons_exi_vars = pc.pc_exi_vars, cons_type_ptr = nilPtr, cons_arg_vars = [] }

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1328
1329
1330
ParsedInstanceToClassInstance pi members :==
 	{	ins_class = {glob_object = MakeDefinedSymbol pi.pi_class NoIndex (length pi.pi_types), glob_module = NoIndex}, ins_ident = pi.pi_ident, 
 		ins_type = { it_vars = [], it_types = pi.pi_types, it_attr_vars = [],
1331
1332
1333
 					 it_context = pi.pi_context }, ins_members = members, ins_specials = pi.pi_specials, ins_pos = pi.pi_pos, 
 		/*AA*/
 		ins_is_generic = False, 
1334
1335
 		ins_generate = pi.pi_generate,
 		ins_partial = False, 
1336
 		ins_generic = {glob_module = NoIndex, glob_object = NoIndex}}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346

MakeTypeDef name lhs rhs attr contexts pos  :== 
	{	td_name = name, td_index = -1, td_arity = length lhs, td_args = lhs, td_attrs = [], td_attribute = attr, td_context = contexts,
		td_pos = pos, td_rhs = rhs }

MakeDefinedSymbol ident index arity :== { ds_ident = ident, ds_arity = arity, ds_index = index }

MakeNewFunctionType name arity prio type pos specials var_ptr
	:== { ft_symb = name, ft_arity = arity, ft_priority = prio, ft_type = type, ft_pos = pos, ft_specials = specials, ft_type_ptr = var_ptr  }

Martin Wierich's avatar
Martin Wierich committed
1347
backslash :== '\\'