syntax.dcl 46.9 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
7
from containers import ::NumberSet
8
from convertcases import :: LetVarInfo, :: LetExpressionInfo, :: RefCountsInCase, :: SplitsInCase
9

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
::	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
	}

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

instance == FunctionOrMacroIndex

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

37
38
::	STE_Kind	= STE_FunctionOrMacro ![FunctionOrMacroIndex]
				| STE_DclMacroOrLocalMacroFunction ![FunctionOrMacroIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
39
40
41
42
43
44
				| STE_Type
				| STE_Constructor
				| STE_Selector ![Global Index]
				| STE_Field !Ident
				| STE_Class
				| STE_Member
45
46
				| STE_Generic
				| STE_GenericCase
47
				| STE_Instance
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
48
49
50
51
				| STE_Variable !VarInfoPtr
				| STE_TypeVariable !TypeVarInfoPtr
				| STE_TypeAttribute !AttrVarInfoPtr
				| STE_BoundTypeVariable !STE_BoundTypeVariable
52
				| STE_Imported !STE_Kind !ModuleN
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
53
				| STE_DclFunction
54
				| STE_Module !(Module (CollectedDefinitions ClassInstance))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
55
				| STE_ClosedModule
56
				| STE_ModuleQualifiedImports !SortedQualifiedImports
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
57
58
59
60
61
				| STE_Empty
					/* for creating class dictionaries */
				| STE_DictType !CheckedTypeDef
				| STE_DictCons !ConsDef
				| STE_DictField !SelectorDef
62
				| STE_Called ![FunctionOrMacroIndex] /* used during macro expansion to indicate that this function is called */
63
				| STE_ExplImpSymbol !Int
64
				| STE_ExplImpComponentNrs ![ComponentNrAndIndex]
65
					/*	stores the numbers of all module components that import the symbol from
66
						the "actual" dcl module.
67
68
					*/
				| STE_BelongingSymbol !Int
69
70
71
72
73
74
				| STE_ExplImpSymbolNotImported !ModuleN !STE_Kind
				| STE_ImportedQualified !Declaration !STE_Kind

				| STE_UsedType !ModuleN !STE_Kind
					/* used during binding of types to mark types that have been applied. */
				| STE_UsedQualifiedType !ModuleN !Index !STE_Kind
75
76
				| STE_BelongingSymbolExported
				| STE_BelongingSymbolForExportedSymbol
77

78
79
80
81
::	ModuleN:==Int;

::	SortedQualifiedImports	= SortedQualifiedImports !Declaration !SortedQualifiedImports !SortedQualifiedImports
							| EmptySortedQualifiedImports
82

83
84
85
86
87
88
89
::	Declaration = Declaration !DeclarationRecord

::	DeclarationRecord =
	{	decl_ident	:: !Ident
	,	decl_pos	:: !Position
	,	decl_kind	:: !STE_Kind
	,	decl_index	:: !Index
90
91
92
93
94
95
96
	}

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

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
97
98
99
100
::	Global object =
	{	glob_object	:: !object
	,	glob_module	:: !Index
	}
101

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
102
::	Module defs = 
103
	{	mod_ident		:: !Ident
104
	,	mod_modification_time		:: {#Char}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
105
106
107
	,	mod_type		:: !ModuleKind
	, 	mod_imports		:: ![ParsedImport]
	,	mod_imported_objects :: ![ImportedObject]
108
	,	mod_foreign_exports :: ![ParsedForeignExport]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
109
110
111
	,	mod_defs		:: !defs
	}

112
113
114
115
116
117
118
::	ParsedForeignExport =
	{	pfe_ident	:: !Ident
	,	pfe_line	:: !Int
	,	pfe_file	:: !FileName
	,	pfe_stdcall	:: !Bool
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
119
::	ParsedModule	:== Module  [ParsedDefinition]
120
::	ScannedModule 	:== Module  (CollectedDefinitions (ScannedInstanceAndMembersR FunDef))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
121
	
122
::	ModuleKind		= MK_Main | MK_Module | MK_System | MK_None | MK_NoMainDcl
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
::	FunDefIndex:==Int

::	IclFunctionIndices =
	{	ifi_global_function_indices	:: ![IndexRange]
	,	ifi_local_function_indices	:: !IndexRange
	,	ifi_instance_indices		:: ![IndexRange]
	,	ifi_specials_indices		:: !IndexRange
	,	ifi_gencase_indices			:: ![IndexRange]
	,	ifi_type_function_indices	:: ![IndexRange]
	}

::	IclModule  =
	{	icl_name				:: !Ident
	,	icl_functions			:: !.{# FunDef }
	,	icl_function_indices	:: !IclFunctionIndices
	,	icl_common				:: !.CommonDefs
	,	icl_import				:: !{!Declaration}
	,	icl_qualified_imports	:: ![([Declaration], ModuleN, Position)]
	,	icl_imported_objects	:: ![ImportedObject]
	,	icl_foreign_exports		:: ![ForeignExport]
	,	icl_used_module_numbers :: !NumberSet
	,	icl_modification_time	:: !{#Char}
	}

::	DclModule =
	{	dcl_name			:: !Ident
	,	dcl_functions		:: !{# FunType }
	,	dcl_instances		:: !IndexRange
	,	dcl_macros			:: !IndexRange
	,	dcl_specials		:: !IndexRange
	,	dcl_gencases		:: !IndexRange
	,	dcl_type_funs		:: !IndexRange
	,	dcl_common			:: !CommonDefs
	,	dcl_sizes			:: !{# Int}
	,	dcl_dictionary_info	:: !DictionaryInfo
	,	dcl_declared		:: !Declarations
160
	,	dcl_has_macro_conversions :: !Bool
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	,	dcl_module_kind		:: !ModuleKind
	,	dcl_modification_time:: !{#Char}
	,	dcl_imported_module_numbers :: !NumberSet
	}

:: ForeignExport = {fe_fd_index :: !FunDefIndex, fe_stdcall :: !Bool}

::	CopiedDefinitions =
	{	copied_type_defs	:: {#Bool}
	,	copied_class_defs	:: {#Bool}
	,	copied_generic_defs :: {#Bool}
	}

::	Declarations = {
		dcls_import	::!{!Declaration}
	,	dcls_local		::![Declaration]
	,	dcls_local_for_import ::!{!Declaration}
	}

::	DictionaryInfo = { n_dictionary_types :: !Int, n_dictionary_constructors :: !Int, n_dictionary_selectors :: !Int }

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
182
::	RhsDefsOfType	= ConsList ![ParsedConstructor]
183
					| SelectorList !Ident ![ATypeVar] !Bool /*is_boxed_record*/ ![ParsedSelector]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
184
					| TypeSpec !AType
John van Groningen's avatar
John van Groningen committed
185
					| NewTypeCons !ParsedConstructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
186
					| EmptyRhs !BITVECT
187
					| AbstractTypeSpec !BITVECT !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
188

189
::	CollectedDefinitions instance_kind =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
190
	{	def_types 			:: ![TypeDef TypeRhs]
191
192
	,	def_constructors	:: ![ConsDef]
	,	def_selectors		:: ![SelectorDef]
193
194
	,	def_macros			:: ![FunDef]
	,	def_macro_indices	:: !IndexRange
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
195
196
197
198
	,	def_classes			:: ![ClassDef]
	,	def_members			:: ![MemberDef]
	,	def_funtypes		:: ![FunType]
	,	def_instances		:: ![instance_kind]
199
200
201
202
203
204
205
206
207
208
209
210
211
	,	def_generics		:: ![GenericDef]
	, 	def_generic_cases 	:: ![GenericCaseDef]
	}

::	CommonDefs =
	{	com_type_defs 		:: !.{# CheckedTypeDef}
	,	com_cons_defs		:: !.{# ConsDef}
	,	com_selector_defs	:: !.{# SelectorDef}
	,	com_class_defs		:: !.{# ClassDef}
	,	com_member_defs		:: !.{# MemberDef}
	,	com_instance_defs	:: !.{# ClassInstance}
	,	com_generic_defs	:: !.{# GenericDef}
	,	com_gencase_defs 	:: !.{# GenericCaseDef}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
212
213
214
215
216
217
218
	}

::	LocalDefs	= LocalParsedDefs [ParsedDefinition]
				| CollectedLocalDefs CollectedLocalDefs

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

219
220
221
222
223
224
225
::	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
226
227
228
229
230
231
232
233
NoIndex		:== -1


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

::	CollectedLocalDefs =
	{	loc_functions	:: !IndexRange
234
	,	loc_nodes		:: ![NodeDef ParsedExpr]
235
	,	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
236
237
238
239
240
	}

::	NodeDef dst =
	{	nd_dst		::!dst,
		nd_alts		::!OptGuardedAlts,
241
242
		nd_locals	::!LocalDefs,
		nd_position	::!Position		
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
243
244
245
246
247
248
249
250
251
252
253
254
	}

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


cIsAFunction	:== True
cIsNotAFunction :== False

::	ParsedDefinition 
255
256
	=	PD_Function Position Ident Bool [ParsedExpr] Rhs FunKind
	|	PD_NodeDef Position ParsedExpr Rhs
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
257
	|	PD_Type ParsedTypeDef
258
	|	PD_TypeSpec Position Ident Priority (Optional SymbolType) FunSpecials
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
259
	|	PD_Class ClassDef [ParsedDefinition]
260
261
	|	PD_Instance ParsedInstanceAndMembers
	|	PD_Instances [ParsedInstanceAndMembers]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
262
263
	|	PD_Import [ParsedImport]
	|	PD_ImportedObjects [ImportedObject]
264
	|	PD_ForeignExport !Ident !{#Char} !Int !Bool /* if stdcall */
265
266
267
	|	PD_Generic GenericDef
	| 	PD_GenericCase GenericCaseDef
	|	PD_Derive [GenericCaseDef]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
268
269
	|	PD_Erroneous

270
::	FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_NodeDefOrFunction | FK_Unknown
271

272
273
::	StrictnessList = NotStrict | Strict !Int | StrictList !Int StrictnessList

274
275
cNameNotLocationDependent :== False
cNameLocationDependent :== True
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
276
277

::	ParsedSelector =
278
279
	{	ps_field_ident		:: !Ident
	,	ps_selector_ident	:: !Ident
280
	,	ps_field_annotation	:: !Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
281
282
283
284
285
286
	,	ps_field_type		:: !AType
	,	ps_field_var		:: !Ident
	,	ps_field_pos		:: !Position
	}

::	ParsedConstructor =
287
	{	pc_cons_ident 	:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
288
289
290
	,	pc_cons_arity	:: !Int
	,	pc_exi_vars		:: ![ATypeVar]
	,	pc_arg_types	:: ![AType]
291
	,	pc_args_strictness	:: !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
292
293
294
	,	pc_cons_prio	:: !Priority
	,	pc_cons_pos		:: !Position
	}
295
296

::	ParsedInstance =
297
	{	pi_class 	:: !IdentOrQualifiedIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
298
299
300
301
302
303
304
	,	pi_ident	:: !Ident
	,	pi_types	:: ![Type]
	,	pi_context	:: ![TypeContext]
	,	pi_pos		:: !Position
	,	pi_specials	:: !Specials
	}

305
306
307
308
309
310
311
312
313
314
315
::	ParsedInstanceAndMembers =
	{	pim_pi 		:: !ParsedInstance
	,	pim_members	:: ![ParsedDefinition]
	}

::	ScannedInstanceAndMembersR icl_member =
	{	sim_pi 				:: !ParsedInstance
	,	sim_members			:: ![icl_member]	// for .icl
	,	sim_member_types	:: ![FunType]	// for .dcl
	}

316
317
318
319
::	IdentOrQualifiedIdent
	= Ident !Ident
	| QualifiedIdent /*module*/!Ident !String

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
320
321
322
323
324
/*
	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 
325
	the typing to check whether this instance has been used. The auxiliary FSP_FunIndex alternative is used
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
326
327
328
329
330
331
332
	to store the index of the function that has been specialized.
*/

::	Specials
	= SP_ParsedSubstitutions 	![Env Type TypeVar]
	| SP_Substitutions 		 	![SpecialSubstitution]
	| SP_ContextTypes			![Special]
333
	| SP_TypeOffset				!Int					// index in SP_Substitutions for specialized instance
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
334
335
	| SP_None

336
337
::	FunSpecials
	= FSP_ParsedSubstitutions 	![Env Type TypeVar]
338
	| FSP_Substitutions			![SpecialSubstitution]
339
340
341
342
	| FSP_ContextTypes			![Special]
	| FSP_FunIndex				!Index
	| FSP_None

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
::	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 =
369
 	{	class_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
370
371
372
373
374
375
376
377
378
	,	class_arity			:: !Int
	,	class_args			:: ![TypeVar]
	,	class_context		:: ![TypeContext]
	,	class_members		:: !{# DefinedSymbol}
	,	class_dictionary	:: !DefinedSymbol
	,	class_pos			:: !Position
	,	class_cons_vars		:: !BITVECT
	}

379
380
::	ClassDefInfos :== {# .{! [TypeKind]}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
381
::	MemberDef =
John van Groningen's avatar
John van Groningen committed
382
	{	me_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
383
384
385
386
387
388
389
390
391
	,	me_class		:: !Global Index
	,	me_offset		:: !Index
	,	me_type			:: !SymbolType
	,	me_type_ptr		:: !VarInfoPtr
	,	me_class_vars	:: ![TypeVar]
	,	me_pos			:: !Position
	,	me_priority 	:: !Priority
	}

392
:: GenericDef = 
John van Groningen's avatar
John van Groningen committed
393
	{	gen_ident		:: !Ident		// the generics name in IC_Generic
394
	,	gen_member_ident	:: !Ident	// the generics name in IC_Expression
395
	, 	gen_pos			:: !Position
396
397
398
	,	gen_type		:: !SymbolType	// Generic type (st_vars include generic type vars)
	,	gen_vars		:: ![TypeVar]	// Generic type variables
	,	gen_info_ptr	:: !GenericInfoPtr
399
	}
Artem Alimarine's avatar
Artem Alimarine committed
400

401
402
403
404
405
406
407
408
409
410
411
:: 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_var_kinds	:: ![TypeKind]  	// kinds of all st_vars of the gen_type
412
	,	gen_OBJECT_CONS_FIELD_indices	:: !{#OBJECT_CONS_FIELD_index}
413
	}
414
415
416
417
418
419
420

::	OBJECT_CONS_FIELD_index =
	{	ocf_module	:: !Int
	,	ocf_index	:: !Int
	,	ocf_ident	:: !Ident
	}

421
422
423
424
425
426
427
428
429
430
:: GenericInfoPtr :== Ptr GenericInfo	
:: GenericHeap :== Heap GenericInfo

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

:: GenericCaseDef = 
431
	{	gc_ident		:: !Ident				// name in IC_GenricCase namespace
432
	,	gc_gident		:: !Ident  				// name in IC_Generic namespace
433
434
435
436
437
438
439
440
441
442
443
444
445
446
	,	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 

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
447
448
449
450
451
452
453
454
::	InstanceType =
	{	it_vars			:: [TypeVar]
	,	it_types		:: ![Type]
	,	it_attr_vars	:: [AttributeVar]
	,	it_context		:: ![TypeContext]
	}

::	ClassInstance =
John van Groningen's avatar
John van Groningen committed
455
456
 	{	ins_class_index	:: !GlobalIndex
	,	ins_class_ident	:: !ClassIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
457
458
	,	ins_ident		:: !Ident
	,	ins_type		:: !InstanceType
459
	,	ins_member_types :: ![FunType]	// for .dcl
460
	,	ins_members		:: !{#ClassInstanceMember}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
461
462
463
464
	,	ins_specials	:: !Specials
	,	ins_pos			:: !Position
	}

John van Groningen's avatar
John van Groningen committed
465
::	ClassIdent =
466
	{	ci_ident		:: !IdentOrQualifiedIdent
John van Groningen's avatar
John van Groningen committed
467
468
469
	,	ci_arity		:: !Int
	}

470
471
472
473
474
475
::	ClassInstanceMember = 
	{	cim_ident		:: !Ident
	,	cim_arity		:: !Int		// module number if cim_index<0
	,	cim_index		:: !Index	// or -1-index
	}

476
::	Import =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
477
	{	import_module		:: !Ident
478
	,	import_symbols		:: !ImportSymbols [ImportDeclaration]
Martin Wierich's avatar
Martin Wierich committed
479
	,	import_file_position:: !Position	// for error messages
480
	,	import_qualified	:: !ImportQualified
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
481
482
	}

483
484
485
486
::	ImportSymbols import_declarations
	= ImportSymbolsAll
	| ImportSymbolsOnly !import_declarations

487
488
::	ImportQualified = NotQualified | Qualified

489
instance toString Import, AttributeVar, TypeAttribute, Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
490

491
::	ParsedImport		:== Import
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
492

493
494
495
496
497
::	ImportDeclaration	= ID_Function !Ident
						| ID_Class !Ident !(Optional [Ident])
						| ID_Type !Ident !(Optional [Ident])
						| ID_Record !Ident !(Optional [Ident])
						| ID_Instance !Ident !Ident !(![Type],![TypeContext])
498
						| ID_Generic !Ident !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
499
500
501

cIsImportedLibrary :== True
cIsImportedObject :== False
502

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
503
504
505
506
507
508
509
510
:: ImportedObject =
	{	io_is_library :: !Bool
	,	io_name    :: !{#Char}
	}

::	RecordType =
	{	rt_constructor	:: !DefinedSymbol
	,	rt_fields		:: !{# FieldSymbol}
511
	,	rt_is_boxed_record :: !Bool
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
512
	}
513

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
514
::	FieldSymbol =
515
	{	fs_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
516
517
518
519
520
521
522
	,	fs_var			:: !Ident
	,	fs_index		:: !Index
	}

::	TypeRhs	= AlgType ![DefinedSymbol]
			| SynType !AType
			| RecordType !RecordType
John van Groningen's avatar
John van Groningen committed
523
			| NewType !DefinedSymbol
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
524
			| AbstractType !BITVECT
525
			| AbstractSynType !BITVECT !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
526
527
528
529
530
531
532
533
			| UnknownType

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

cAllBitsClear			:== 0
cIsHyperStrict			:== 1
cIsNonCoercible			:== 2
534
535
536
537
538
539
cIsAnalysed				:== 4

::	GlobalIndex =
	{	gi_module	::!Int
	,	gi_index	::!Int
	}
540
NoGlobalIndex :== {gi_module=NoIndex,gi_index=NoIndex}	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
541
542

::	TypeDef type_rhs =
543
	{	td_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
544
545
546
547
548
549
550
	,	td_index		:: !Int
	,	td_arity		:: !Int
	,	td_args			:: ![ATypeVar]
	,	td_attrs		:: ![AttributeVar]
	,	td_rhs			:: !type_rhs
	,	td_attribute	:: !TypeAttribute
	,	td_pos			:: !Position
551
	,	td_used_types	:: ![GlobalIndex]
552
	,	td_fun_index	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
553
554
555
556
557
	}

::	TypeDefInfo =
	{	tdi_kinds			:: ![TypeKind]
	,	tdi_properties		:: !BITVECT
558
	,	tdi_group			:: ![GlobalIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
559
560
561
	,	tdi_group_nr		:: !Int
	,	tdi_group_vars		:: ![Int]
	,	tdi_cons_vars		:: ![Int]
562
	,	tdi_index_in_group	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
563
	,	tdi_classification	:: !TypeClassification
564
	,	tdi_gen_rep 		:: !Optional GenericTypeRep
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
565
566
	}

567
568
569
570
571
572
573
// type structure is used to specialize a generic to a type
:: GenTypeStruct 
	= GTSAppCons TypeKind [GenTypeStruct]
	| GTSAppVar TypeVar [GenTypeStruct] 
	| GTSVar TypeVar
 	| GTSCons DefinedSymbol GenTypeStruct
 	| GTSField DefinedSymbol GenTypeStruct
Artem Alimarine's avatar
Artem Alimarine committed
574
 	| GTSObject DefinedSymbol GenTypeStruct
575
576
	| GTSPair !GenTypeStruct !GenTypeStruct		// for optimizing bimaps
	| GTSEither !GenTypeStruct !GenTypeStruct	// for optimizing bimaps
577
	| GTSArrow GenTypeStruct GenTypeStruct		// for optimizing bimaps
578
 	| GTSE
579
580
	| GTSAppConsBimapKindConst					// for optimizing bimaps
	| GTSAppBimap TypeKind [GenTypeStruct]		// for optimizing bimaps
581
	| GTSAppConsSimpleType !(Global Index) !TypeKind ![GenTypeStruct]	// for optimizing bimaps
582

583
:: GenericTypeRep = 
584
	{ gtr_type :: GenTypeStruct		// generic structure type
585
586
587
	, gtr_iso  :: !DefinedSymbol	// the conversion isomorphism
	, gtr_to   :: !DefinedSymbol
	, gtr_from :: !DefinedSymbol
588
589
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
590
591
592
::	TypeDefInfos :== {# .{# TypeDefInfo}}

::	FunType =
593
	{	ft_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
594
595
596
597
	,	ft_arity		:: !Int
	,	ft_priority		:: !Priority
	,	ft_type			:: !SymbolType
	,	ft_pos			:: !Position
598
	,	ft_specials		:: !FunSpecials
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
599
600
601
602
603
	,	ft_type_ptr		:: !VarInfoPtr
	}

::	FreeVar =
	{	fv_def_level	:: !Level
604
	,	fv_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
605
606
607
	,	fv_info_ptr		:: !VarInfoPtr
	,	fv_count		:: !Int
	}
608
609
610
611

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

612
613
614
615
::	FunCall	= FunCall !Index !Level
			| MacroCall !ModuleIndex !Index Level
			| DclFunCall !ModuleIndex !DclFunctionIndex
			| GeneratedFunCall !Index !FunctionInfoPtr;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
616

617
618
FI_IsMacroFun	:== 1			// whether the function is a local function of a macro
FI_HasTypeSpec	:== 2			// whether the function has u user defined type
619
620
FI_IsNonRecursive :== 4			// used in trans.icl and partition.icl
FI_IsUnboxedListOfRecordsConsOrNil :== 8
621
FI_MemberInstanceRequiresTypeInDefMod :== 16
622

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
623
624
625
626
627
628
629
::	FunInfo =
	{	fi_calls			:: ![FunCall]
	,	fi_group_index		:: !Index
	,	fi_def_level		:: !Level
	,	fi_free_vars		:: ![FreeVar]
	,	fi_local_vars		:: ![FreeVar]
	,	fi_dynamics			:: ![ExprInfoPtr]
630
	,	fi_properties		:: !BITVECT
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
631
632
633
	}

::	ParsedBody =
634
635
636
	{	pb_args		:: ![ParsedExpr]
	,	pb_rhs		:: !Rhs
	,	pb_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
637
638
639
	}

::	CheckedBody =
640
641
	{	cb_args		:: ![FreeVar]
	,	cb_rhs		:: ![CheckedAlternative]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
642
643
	}

644
645
646
647
648
649
::	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
650
651
652
653
654
655
656
657
::	TransformedBody =
	{	tb_args			:: ![FreeVar]
	,	tb_rhs			:: !Expression
	}

::	FunctionBody	= ParsedBody ![ParsedBody]
					| CheckedBody !CheckedBody
	/* The next three constructors are used during macro expansion (module transform) */
658
659
					| PartitioningMacro
					| PartitioningFunction !CheckedBody !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
660
661
662
					| RhsMacroBody !CheckedBody
	/* macro expansion transforms a CheckedBody into a TransformedBody */
					| TransformedBody !TransformedBody
663
					| Expanding ![FreeVar] // the parameters of the newly generated function
664
					| GeneratedBody // the body will be generated automatically - for generics
665
					| NoBody
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
666
667

::	FunDef =
668
	{	fun_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
669
670
671
672
673
	,	fun_arity		:: !Int
	,	fun_priority	:: !Priority
	,	fun_body		:: !FunctionBody
	,	fun_type		:: !Optional SymbolType
	,	fun_pos			:: !Position
674
	,	fun_kind		:: !FunKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
675
676
677
678
679
680
681
682
	,	fun_lifted		:: !Int
	,	fun_info		:: !FunInfo
	}

cIsAGlobalVar	:== True
cIsALocalVar	:== False

::	ConsClasses =
683
	{	cc_size			::!Int
684
	,	cc_args			::![ConsClass]
685
	,	cc_linear_bits	::![#Bool!]
686
	,	cc_producer		::!ProdClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
687
	}
688

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
689
690
::	ConsClass	:== Int

691
692
693
694
::	ProdClass	:== Bool

pIsSafe			:== True

695
696
697
698
::	ImportedConstructors	:== [Global Index]
::	ImportedFunctions		:== [Global Index]
::	ImportedTypes			:== {#{# CheckedTypeDef}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
699
700
701
702
703
704
::	OptionalVariable :== Optional (Bind Ident VarInfoPtr)

:: 	AuxiliaryPattern
		= AP_Algebraic !(Global DefinedSymbol) !Index [AuxiliaryPattern] OptionalVariable
		| AP_Variable !Ident !VarInfoPtr OptionalVariable
		| AP_Basic !BasicValue OptionalVariable
John van Groningen's avatar
John van Groningen committed
705
		| AP_NewType !(Global DefinedSymbol) !Index AuxiliaryPattern OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
706
707
		| AP_Dynamic !AuxiliaryPattern !DynamicType !OptionalVariable
		| AP_Constant !AP_Kind !(Global DefinedSymbol) !Priority
708
		| AP_WildCard !OptionalVariable
709
		| AP_Empty
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
710

John van Groningen's avatar
John van Groningen committed
711
:: AP_Kind = APK_Constructor !Index | APK_NewTypeConstructor !Index | APK_Macro !Bool // is_dcl_macro
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
712

713
714
::	VI_TypeInfo	= VITI_Empty
				| VITI_Coercion		CoercionPosition
715
				| VITI_PatternType	[AType] /*module*/!Index /*constructor*/!Index VI_TypeInfo
716
717

//::	VarInfo  =	VI_Empty | VI_Type !AType !(Optional CoercionPosition) | VI_FAType ![ATypeVar] !AType !(Optional CoercionPosition) |
718
719
::	VarInfo  =	VI_Empty | VI_Type !AType !VI_TypeInfo |
				VI_FAType ![ATypeVar] !AType !VI_TypeInfo |
720
				VI_Occurrence !Occurrence | VI_UsedVar !Ident |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
721
722
				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 */ |
723
				VI_Ref !Bool /* true if the variable is global, false otherwise */ |
724
				VI_AccVar !ConsClass !ArgumentPosition /* used during fusion to determine accumulating parameters of functions */ |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
725
726
				VI_Alias !BoundVar /* used for resolving aliases just before type checking (in transform) */ |
				 /* used during elimination and lifting of cases */
727
728
729
730
				VI_RefFromTupleSel0 !Int |
				VI_RefFromArrayUpdate !Int ![Selection] |
				VI_RefFromArrayUpdateToTupleSelector2 !Int ![Selection] !VarInfoPtr |
				VI_RefFromArrayUpdateOfTupleElem2 !Int ![Selection] |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
731
				VI_FreeVar !Ident !VarInfoPtr !Int !AType | VI_BoundVar !AType | VI_LocalVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
732
733
				VI_ClassVar !Ident !VarInfoPtr !Int | /* to hold dictionary variables during overloading */
				VI_ForwardClassVar !VarInfoPtr | /* to hold the dictionary variable generated during overloading */
734
				VI_Forward !BoundVar | VI_LetVar !LetVarInfo | VI_LetExpression !LetExpressionInfo |
735
				VI_CaseOrStrictLetVar !VarInfoPtr | VI_StrictLetVar |
736
				VI_CorrespondenceNumber !Int | /* it is assumed that this alternative is _only_ used in module comparedefimp */
737
				VI_SequenceNumber !Int | VI_AliasSequenceNumber !BoundVar |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
738
739
740
741
742
				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
743
				VI_TypeCodeVariable !TypeCodeVariableInfo |
744
				VI_DynamicValueAlias !BoundVar |
745
746
				VI_Body !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
				VI_ExpressionOrBody !Expression !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
747
				VI_Dictionary !SymbIdent ![Expression] !Type | /* used during fusion */
Sjaak Smetsers's avatar
Sjaak Smetsers committed
748
				VI_Extended !ExtendedVarInfo !VarInfo |
749
// MdM
750
				VI_CPSExprVar !CheatCompiler /* a pointer to a variable in CleanProverSystem is stored here, using a cast */
751
// ... MdM
752
				| VI_Labelled_Empty !{#Char} // RWS debugging
753
				| VI_LocalLetVar // RWS, mark Let vars during case transformation
754

755
756
757
758
759
::	TypeCodeVariableInfo
	= TCI_TypeVar !Expression
	| TCI_TypePatternVar !Expression
	| TCI_SelectionsTypePatternVar ![(Expression,[Selection])]

760
::	ExtendedVarInfo = EVI_VarType !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
761

762
763
::	ArgumentPosition :== Int

764
::	VarHeap :== Heap VarInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
765
766
767
768
769
::	VarInfoPtr	:== Ptr VarInfo

cNotVarNumber :== -1

::	BoundVar = 
770
	{	var_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
771
772
773
774
775
	,	var_info_ptr	:: !VarInfoPtr
	,	var_expr_ptr	:: !ExprInfoPtr
	}

::	TypeSymbIdent =
776
	{	type_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
777
778
779
780
781
782
783
784
785
786
787
788
789
	,	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)
790
				| SK_IclMacro !Index
791
				| SK_LocalMacroFunction !Index
792
793
				| SK_DclMacro !(Global Index)
				| SK_LocalDclMacroFunction !(Global Index)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
794
795
				| SK_OverloadedFunction !(Global Index)
				| SK_GeneratedFunction !FunctionInfoPtr !Index
796
				| SK_Constructor !(Global Index)
John van Groningen's avatar
John van Groningen committed
797
				| SK_NewTypeConstructor !GlobalIndex
798
				| SK_Generic !(Global Index) !TypeKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
799
800
801
802
803
804
805
806
807
808
809
810
811
812
				| 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
813
				| PR_Function !SymbIdent !Int !Index
Martin Wierich's avatar
Martin Wierich committed
814
				| PR_Class !App ![(BoundVar, Type)] !Type
815
816
817
				| PR_Constructor !SymbIdent !Int ![Expression]
				| PR_GeneratedFunction !SymbIdent !Int !Index
				| PR_Curried !SymbIdent !Int
818
				| PR_Unused
819
				| PR_CurriedFunction !SymbIdent !Int !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

::	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
846
					| EI_Selection 	![Selection] !VarInfoPtr ![Expression]	/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
847
848
849
850
					| EI_Context 	![Expression]							/* intermedediate, used during resolving of overloading */

		/* For handling dynamics */

851
852
853
					| EI_UnmarkedDynamic 		!(Optional DynamicType) ![DynamicPtr]	// in expression
					| EI_Dynamic 				!(Optional DynamicType) ![DynamicPtr]	// in expression
					| EI_DynamicType			!DynamicType ![DynamicPtr]				// in pattern
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
854
855
856
857
858
859
860

		/* Auxiliary, was EI_DynamicType before checking */

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

		/* Auxiliary, used during type checking */

Sjaak Smetsers's avatar
Sjaak Smetsers committed
861
					| EI_TempDynamicType 		!(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
862
					| EI_TempDynamicPattern 	![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
863
864
865

					| EI_TypeOfDynamic 			!TypeCodeExpression						/* Final */
					| EI_TypeOfDynamicPattern 	![VarInfoPtr] !TypeCodeExpression		/* Final */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
866
867
868
869
870
871

					| EI_TypeCode 		!TypeCodeExpression
					| EI_TypeCodes 		![TypeCodeExpression]

					| EI_Attribute !Int

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

875
					| EI_DictionaryType !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
876
877
878
					| EI_CaseType !CaseType
					| EI_LetType ![AType]
					| EI_CaseTypeAndRefCounts !CaseType !RefCountsInCase
879
					| EI_CaseTypeAndSplits !CaseType !SplitsInCase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
880
881
882
883
					| EI_LetTypeAndRefCounts ![AType] ![Int]

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

884

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
885
886
					| EI_Default !Expression !AType !ExprInfoPtr
					| EI_DefaultFunction !SymbIdent ![Expression]
887
					| EI_Extended !ExtendedExprInfo !ExprInfo
888
889
890
891
892

::	ExtendedExprInfo
					= EEI_ActiveCase !ActiveCaseInfo

::	ActiveCaseInfo =
893
894
895
896
	{	aci_params					:: ![FreeVar]
	,	aci_opt_unfolder			:: !(Optional SymbIdent)
	,	aci_free_vars				:: !Optional [BoundVar]
	,	aci_linearity_of_patterns	:: ![[Bool]]
897
	,	aci_safe					:: !Bool
898
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916

/*
	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
*/
John van Groningen's avatar
John van Groningen committed
917

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
918
919
920
921
922
923
924
::	CaseType =
	{	ct_pattern_type	:: !AType
	,	ct_result_type	:: !AType
	,	ct_cons_types 	:: ![[AType]]
	}
		
::	SymbIdent =
925
	{	symb_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
926
927
928
929
	,	symb_kind		:: !SymbKind
	}

::	ConsDef =
930
	{	cons_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
931
932
	,	cons_type			:: !SymbolType
	,	cons_priority		:: !Priority
John van Groningen's avatar
John van Groningen committed
933
	,	cons_number			:: !Index // -2 for newtype constructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
934
935
936
937
938
939
940
	,	cons_type_index		:: !Index
	,	cons_exi_vars		:: ![ATypeVar]
	,	cons_type_ptr		:: !VarInfoPtr
	,	cons_pos			:: !Position
	}

::	SelectorDef =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
941
	{	sd_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
942
943
944
945
946
947
948
949
950
951
952
953
	,	sd_field		:: !Ident
	,	sd_type			:: !SymbolType
	,	sd_exi_vars		:: ![ATypeVar]
	,	sd_field_nr		:: !Int
	,	sd_type_index	:: !Int
	,	sd_type_ptr		:: !VarInfoPtr
	,	sd_pos			:: !Position
	}

::	SymbolType =
	{	st_vars			:: ![TypeVar]
	,	st_args			:: ![AType]
954
	,	st_args_strictness :: !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
955
956
957
958
959
960
961
962
	,	st_arity		:: !Int
	,	st_result		:: !AType
	,	st_context		:: ![TypeContext]
	,	st_attr_vars	:: ![AttributeVar]
	,	st_attr_env		:: ![AttrInequality]
	}

::	TypeContext =
963
	{	tc_class	:: !TCClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
964
965
966
967
	,	tc_types	:: ![Type]
	,	tc_var		:: !VarInfoPtr
	}

968
969
:: TCClass 	= TCClass 		!(Global DefinedSymbol) // Normal class
			| TCGeneric 	!GenericTypeContext		// Generic class
970
			| TCQualifiedIdent !Ident !String
971

John van Groningen's avatar
John van Groningen committed
972
973
:: GenericTypeContext =
	{ gtc_generic 	:: !Global DefinedSymbol
974
	, gtc_kind		:: !TypeKind 
John van Groningen's avatar
John van Groningen committed
975
976
	, gtc_class		:: !Global DefinedSymbol	// generated class
	, gtc_generic_dict :: !GlobalIndex			// HACK: dictionary different from the one contained in the class
977
	}
978

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
979
980
981
982
983
984
985
986
987
988
::	AType =
	{	at_attribute	:: !TypeAttribute
	,	at_type			:: !Type
	}
	
::	TempAttrId		:== Int
::	TempVarId		:== Int


::	Type	=	TA !TypeSymbIdent ![AType]
989
			|	TAS !TypeSymbIdent ![AType] !StrictnessList
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
990
			|	(-->) infixr 9 !AType !AType
991
992
			| 	TArrow							/* (->) */
			| 	TArrow1	!AType					/* ((->) a) */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
993
994
995
			|	(:@:) infixl 9 !ConsVariable ![AType]
			|	TB !BasicType

996
			|	TFA ![ATypeVar] !Type			/* Universally quantified types */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
997
998
999
1000

			| 	GTV !TypeVar
			| 	TV !TypeVar
			|	TempV !TempVarId				/* Auxiliary, used during type checking */
For faster browsing, not all history is shown. View entire blame