syntax.dcl 51.3 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
				| STE_Type
				| STE_Constructor
				| STE_Selector ![Global Index]
42
				| STE_Field !Ident // IC_Selector
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
43
44
				| STE_Class
				| STE_Member
45
46
				| STE_Generic
				| STE_GenericCase
47
				| STE_GenericDeriveClass
48
				| STE_Instance
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
49
50
51
52
				| STE_Variable !VarInfoPtr
				| STE_TypeVariable !TypeVarInfoPtr
				| STE_TypeAttribute !AttrVarInfoPtr
				| STE_BoundTypeVariable !STE_BoundTypeVariable
53
				| STE_Imported !STE_Kind !ModuleN
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
54
				| STE_DclFunction
55
				| STE_Module !(Module (CollectedDefinitions ClassInstance))
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
56
				| STE_ClosedModule
57
				| STE_ModuleQualifiedImports !SortedQualifiedImports
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
58
59
60
61
62
				| STE_Empty
					/* for creating class dictionaries */
				| STE_DictType !CheckedTypeDef
				| STE_DictCons !ConsDef
				| STE_DictField !SelectorDef
63
				| STE_Called ![FunctionOrMacroIndex] /* used during macro expansion to indicate that this function is called */
64
				| STE_ExplImpSymbol !Int
65
				| STE_ExplImpComponentNrs ![ComponentNrAndIndex]
66
					/*	stores the numbers of all module components that import the symbol from
67
						the "actual" dcl module.
68
69
					*/
				| STE_BelongingSymbol !Int
70
71
72
73
74
75
				| 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
76
77
				| STE_BelongingSymbolExported
				| STE_BelongingSymbolForExportedSymbol
78
				| STE_TypeExtension
79

80
81
82
83
::	ModuleN:==Int;

::	SortedQualifiedImports	= SortedQualifiedImports !Declaration !SortedQualifiedImports !SortedQualifiedImports
							| EmptySortedQualifiedImports
84

85
86
87
88
89
90
91
::	Declaration = Declaration !DeclarationRecord

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

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

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

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

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

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

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
::	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
142
	,	icl_imported_instances	:: ![!GlobalInstanceIndex!]
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	,	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
161
	,	dcl_has_macro_conversions :: !Bool
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	,	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
183
::	RhsDefsOfType	= ConsList ![ParsedConstructor]
184
					| SelectorList !Ident ![ATypeVar] !Bool /*is_boxed_record*/ ![ParsedSelector]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
185
					| TypeSpec !AType
John van Groningen's avatar
John van Groningen committed
186
					| NewTypeCons !ParsedConstructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
187
					| EmptyRhs !BITVECT
188
					| AbstractTypeSpec !BITVECT !AType
189
					| ExtensibleConses ![ParsedConstructor]
190
					| MoreConses !Ident ![ParsedConstructor]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
191

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

206
207
208
::	CommonDefs :== CommonDefsR DclInstanceMemberTypeAndFunction

::	CommonDefsR member_types_and_functions =
209
210
211
212
213
	{	com_type_defs 		:: !.{# CheckedTypeDef}
	,	com_cons_defs		:: !.{# ConsDef}
	,	com_selector_defs	:: !.{# SelectorDef}
	,	com_class_defs		:: !.{# ClassDef}
	,	com_member_defs		:: !.{# MemberDef}
214
	,	com_instance_defs	:: !.{# ClassInstanceR member_types_and_functions}
215
216
	,	com_generic_defs	:: !.{# GenericDef}
	,	com_gencase_defs 	:: !.{# GenericCaseDef}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
217
218
219
220
221
222
223
	}

::	LocalDefs	= LocalParsedDefs [ParsedDefinition]
				| CollectedLocalDefs CollectedLocalDefs

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

224
225
226
227
228
229
230
::	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
231
232
233
234
235
236
237
238
NoIndex		:== -1


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

::	CollectedLocalDefs =
	{	loc_functions	:: !IndexRange
239
	,	loc_nodes		:: ![NodeDef ParsedExpr]
240
	,	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
241
242
243
244
245
	}

::	NodeDef dst =
	{	nd_dst		::!dst,
		nd_alts		::!OptGuardedAlts,
246
247
		nd_locals	::!LocalDefs,
		nd_position	::!Position		
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
248
249
250
251
252
253
254
255
256
257
258
259
	}

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


cIsAFunction	:== True
cIsNotAFunction :== False

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

275
::	FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_NodeDefOrFunction | FK_Unknown
276

277
278
::	StrictnessList = NotStrict | Strict !Int | StrictList !Int StrictnessList

279
280
cNameNotLocationDependent :== False
cNameLocationDependent :== True
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
281
282

::	ParsedSelector =
283
284
	{	ps_field_ident		:: !Ident
	,	ps_selector_ident	:: !Ident
285
	,	ps_field_annotation	:: !Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
286
287
288
289
290
291
	,	ps_field_type		:: !AType
	,	ps_field_var		:: !Ident
	,	ps_field_pos		:: !Position
	}

::	ParsedConstructor =
292
	{	pc_cons_ident 	:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
293
294
295
	,	pc_cons_arity	:: !Int
	,	pc_exi_vars		:: ![ATypeVar]
	,	pc_arg_types	:: ![AType]
296
	,	pc_args_strictness	:: !StrictnessList
297
	,	pc_context		:: ![TypeContext]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
298
299
300
	,	pc_cons_prio	:: !Priority
	,	pc_cons_pos		:: !Position
	}
301
302

::	ParsedInstance =
303
	{	pi_class 	:: !IdentOrQualifiedIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
304
305
306
307
308
309
310
	,	pi_ident	:: !Ident
	,	pi_types	:: ![Type]
	,	pi_context	:: ![TypeContext]
	,	pi_pos		:: !Position
	,	pi_specials	:: !Specials
	}

311
312
313
314
315
316
317
318
319
320
321
::	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
	}

322
323
324
325
326
::	DclInstanceMemberTypeAndFunction = {
		dim_type			:: !FunType,
		dim_function_index	:: !MacroIndex // optional, -1 if no function
	  }

327
328
329
330
::	IdentOrQualifiedIdent
	= Ident !Ident
	| QualifiedIdent /*module*/!Ident !String

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
331
332
333
334
335
/*
	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 
336
	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
337
338
339
340
341
342
343
	to store the index of the function that has been specialized.
*/

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

347
348
::	FunSpecials
	= FSP_ParsedSubstitutions 	![Env Type TypeVar]
349
	| FSP_Substitutions			![SpecialSubstitution]
350
351
352
353
	| FSP_ContextTypes			![Special]
	| FSP_FunIndex				!Index
	| FSP_None

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

379
380
381
382
383
384
385
::	MacroIndex :== Int;

::	MacroMember = {
		mm_ident :: !Ident,
		mm_index :: !MacroIndex // only valid for class in dcl module
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
386
::	ClassDef =
387
 	{	class_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
388
389
390
391
	,	class_arity			:: !Int
	,	class_args			:: ![TypeVar]
	,	class_context		:: ![TypeContext]
	,	class_members		:: !{# DefinedSymbol}
392
	,	class_macro_members	:: {#MacroMember}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
393
394
395
396
397
	,	class_dictionary	:: !DefinedSymbol
	,	class_pos			:: !Position
	,	class_cons_vars		:: !BITVECT
	}

398
399
::	ClassDefInfos :== {# .{! [TypeKind]}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
400
::	MemberDef =
John van Groningen's avatar
John van Groningen committed
401
	{	me_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
402
403
404
405
406
	,	me_class		:: !Global Index
	,	me_offset		:: !Index
	,	me_type			:: !SymbolType
	,	me_type_ptr		:: !VarInfoPtr
	,	me_class_vars	:: ![TypeVar]
407
	,	me_default_implementation :: !Optional MacroMember
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
408
409
410
411
	,	me_pos			:: !Position
	,	me_priority 	:: !Priority
	}

412
:: GenericDef = 
John van Groningen's avatar
John van Groningen committed
413
	{	gen_ident		:: !Ident		// the generics name in IC_Generic
414
	,	gen_member_ident	:: !Ident	// the generics name in IC_Expression
415
	, 	gen_pos			:: !Position
416
417
	,	gen_type		:: !SymbolType	// Generic type (st_vars include generic type vars)
	,	gen_vars		:: ![TypeVar]	// Generic type variables
418
	,	gen_deps		:: ![GenericDependency]	   // Generic function dependencies
419
	,	gen_info_ptr	:: !GenericInfoPtr
420
	}
Artem Alimarine's avatar
Artem Alimarine committed
421

422
423
424
425
426
427
428
429
430
:: GenericDependency =
	{	gd_ident		:: !IdentOrQualifiedIdent
	, 	gd_index		:: !GlobalIndex
	, 	gd_vars			:: ![TypeVar]
	,	gd_nums			:: ![Int] // Mapping from dependency variable to generic type variable
	}

instance == GenericDependency

431
432
433
434
435
436
437
438
439
440
441
:: 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
442
443
	,	gen_rep_conses	:: !{!GenericRepresentationConstructor}
	//	OBJECT, CONS, RECORD, FIELD, PAIR, EITHER, UNIT
444
	}
445

446
::	GenericRepresentationConstructor =
447
448
449
450
451
452
453
	{	grc_module	:: !Int
	,	grc_index	:: !GenericCaseBody // GCB_FunIndex, GCB_FunAndMacroIndex or GCB_None
	,	grc_local_fun_index :: !Int
	,	grc_ident	:: !Ident
	,	grc_generic_info :: !Int
	,	grc_generic_instance_deps :: !GenericInstanceDependencies
	,	grc_optional_fun_type :: !Optional SymbolType
454
455
	}

456
457
458
459
460
461
462
:: GenericInfoPtr :== Ptr GenericInfo	
:: GenericHeap :== Heap GenericInfo

:: TypeCons 
	= TypeConsSymb TypeSymbIdent 
	| TypeConsBasic BasicType 
	| TypeConsArrow
463
464
	| TypeConsVar TypeVar
	| TypeConsQualifiedIdent !Ident !String 
465

466
467
:: GenericCaseDef =
	{	gc_pos			:: !Position			// position in the source file
468
469
	,	gc_type			:: !Type				// the instance type
	,   gc_type_cons	:: !TypeCons			// type constructor of the type argument
470
	,	gc_gcf			:: !GenericCaseFunctions
471
	}
472
473
474

::	GenericCaseFunctions
	= GCF !Ident !GCF
475
476
	| GCFS ![!GCF!]
	| GCFC !Ident !Ident	// IC_GenericDeriveClass IC_Class
477
478

::	GCF = {
479
		gcf_gident	:: !Ident,	  			// name in IC_Generic namespace
480
481
		gcf_generic	:: !GlobalIndex,		// index of the generic
		gcf_arity	:: !Int,				// arity of the function
482
		gcf_generic_info :: !Int,			// 0 = no, -1 = all, generic info for CONS, OBJECT, RECORD or FIELD
483
		gcf_body	:: !GenericCaseBody,	// the body function or NoIndex
484
485
		gcf_kind	:: !TypeKind,			// kind of the instance type
		gcf_generic_instance_deps :: !GenericInstanceDependencies
486
487
	}

488
489
:: GenericCaseBody 
	= GCB_None 									// to be generated
490
491
492
493
494
495
496
497
498
499
	| GCB_FunIndex !Index
	| GCB_FunAndMacroIndex !Index !Index
	| GCB_MacroIndex !Index
	| GCB_FunDef !FunDef
	| GCB_ParsedBody ![ParsedExpr] !Rhs

::	GenericInstanceDependencies
	= AllGenericInstanceDependencies
	| GenericInstanceDependencies !Int /*n_deps*/ !Int /*deps*/
	| GenericInstanceUsedArgs !Int /*n_deps*/ !Int /*deps*/
500

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
501
502
503
504
505
506
507
::	InstanceType =
	{	it_vars			:: [TypeVar]
	,	it_types		:: ![Type]
	,	it_attr_vars	:: [AttributeVar]
	,	it_context		:: ![TypeContext]
	}

508
509
510
::	ClassInstance :== ClassInstanceR DclInstanceMemberTypeAndFunction

::	ClassInstanceR member_types_and_functions =
John van Groningen's avatar
John van Groningen committed
511
512
 	{	ins_class_index	:: !GlobalIndex
	,	ins_class_ident	:: !ClassIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
513
514
	,	ins_ident		:: !Ident
	,	ins_type		:: !InstanceType
515
	,	ins_member_types_and_functions	:: ![member_types_and_functions]
516
	,	ins_members		:: !{#ClassInstanceMember}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
517
518
519
520
	,	ins_specials	:: !Specials
	,	ins_pos			:: !Position
	}

John van Groningen's avatar
John van Groningen committed
521
::	ClassIdent =
522
	{	ci_ident		:: !IdentOrQualifiedIdent
John van Groningen's avatar
John van Groningen committed
523
524
525
	,	ci_arity		:: !Int
	}

526
527
528
529
530
531
::	ClassInstanceMember = 
	{	cim_ident		:: !Ident
	,	cim_arity		:: !Int		// module number if cim_index<0
	,	cim_index		:: !Index	// or -1-index
	}

532
::	Import =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
533
	{	import_module		:: !Ident
534
	,	import_symbols		:: !ImportSymbols [ImportDeclaration]
Martin Wierich's avatar
Martin Wierich committed
535
	,	import_file_position:: !Position	// for error messages
536
	,	import_qualified	:: !ImportQualified
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
537
538
	}

539
540
541
542
::	ImportSymbols import_declarations
	= ImportSymbolsAll
	| ImportSymbolsOnly !import_declarations

543
544
::	ImportQualified = NotQualified | Qualified

545
instance toString Import, AttributeVar, TypeAttribute, Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
546

547
::	ParsedImport		:== Import
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
548

549
550
551
552
553
::	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])
554
						| ID_Generic !Ident !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
555
556
557

cIsImportedLibrary :== True
cIsImportedObject :== False
558

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
559
560
561
562
563
564
565
566
:: ImportedObject =
	{	io_is_library :: !Bool
	,	io_name    :: !{#Char}
	}

::	RecordType =
	{	rt_constructor	:: !DefinedSymbol
	,	rt_fields		:: !{# FieldSymbol}
567
	,	rt_is_boxed_record :: !Bool
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
568
	}
569

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
570
::	FieldSymbol =
571
572
	{	fs_ident		:: !Ident // IC_Field
	,	fs_var			:: !Ident // IC_Expression
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
573
574
575
576
577
578
	,	fs_index		:: !Index
	}

::	TypeRhs	= AlgType ![DefinedSymbol]
			| SynType !AType
			| RecordType !RecordType
John van Groningen's avatar
John van Groningen committed
579
			| NewType !DefinedSymbol
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
580
			| AbstractType !BITVECT
581
			| AbstractSynType !BITVECT !AType
582
			| ExtensibleAlgType ![DefinedSymbol]
583
584
			| AlgConses ![DefinedSymbol] !GlobalIndex
			| UncheckedAlgConses !Ident ![DefinedSymbol]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
585
586
587
588
589
590
591
592
			| UnknownType

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

cAllBitsClear			:== 0
cIsHyperStrict			:== 1
cIsNonCoercible			:== 2
593
594
595
596
597
598
cIsAnalysed				:== 4

::	GlobalIndex =
	{	gi_module	::!Int
	,	gi_index	::!Int
	}
599
NoGlobalIndex :== {gi_module=NoIndex,gi_index=NoIndex}	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
600

601
602
603
604
605
::	GlobalInstanceIndex =
	{	gii_module_n ::!Int
	,	gii_instance_n ::!Int
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
606
::	TypeDef type_rhs =
607
	{	td_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
608
609
610
611
612
613
614
	,	td_index		:: !Int
	,	td_arity		:: !Int
	,	td_args			:: ![ATypeVar]
	,	td_attrs		:: ![AttributeVar]
	,	td_rhs			:: !type_rhs
	,	td_attribute	:: !TypeAttribute
	,	td_pos			:: !Position
615
	,	td_used_types	:: ![GlobalIndex]
616
	,	td_fun_index	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
617
618
619
620
621
	}

::	TypeDefInfo =
	{	tdi_kinds			:: ![TypeKind]
	,	tdi_properties		:: !BITVECT
622
	,	tdi_group			:: ![GlobalIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
623
624
625
	,	tdi_group_nr		:: !Int
	,	tdi_group_vars		:: ![Int]
	,	tdi_cons_vars		:: ![Int]
626
	,	tdi_index_in_group	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
627
	,	tdi_classification	:: !TypeClassification
628
	,	tdi_gen_rep 		:: !GenericTypeReps
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
629
630
	}

631
632
633
634
635
// type structure is used to specialize a generic to a type
:: GenTypeStruct 
	= GTSAppCons TypeKind [GenTypeStruct]
	| GTSAppVar TypeVar [GenTypeStruct] 
	| GTSVar TypeVar
636
637
638
639
640
641
642
643
644
 	| GTSCons !DefinedSymbol !GlobalIndex !DefinedSymbol !DefinedSymbol !GenTypeStruct
 	| GTSRecord !DefinedSymbol !GlobalIndex !DefinedSymbol !DefinedSymbol !GenTypeStruct
 	| GTSField !DefinedSymbol !GlobalIndex !DefinedSymbol !GenTypeStruct
 	| GTSObject !DefinedSymbol !GlobalIndex !DefinedSymbol !GenTypeStruct
	| GTSE
	| GTSPair !GenTypeStruct !GenTypeStruct
	| GTSEither !GenTypeStruct !GenTypeStruct
	| GTSUnit
	| GTSArrow GenTypeStruct GenTypeStruct
645
	// the following constructors are used for optimizing bimaps
646
647
648
 	| GTSAppConsBimapKindConst
	| GTSAppBimap TypeKind [GenTypeStruct]
	| GTSAppConsSimpleType !GlobalIndex !TypeKind ![GenTypeStruct]
649
650
651
652
653
654
655
656
 	| GTSCons1Bimap !GenTypeStruct
 	| GTSRecord1Bimap !GenTypeStruct

:: GenericTypeReps
	= NoGenericTypeReps
	| GenericTypeRep !GenericTypeRep
	| GenericBimapTypeRep !GenericTypeRep
	| GenericTypeRepAndBimapTypeRep !GenericTypeRep !GenericTypeRep
657

658
:: GenericTypeRep = 
659
	{ gtr_type :: GenTypeStruct		// generic structure type
660
661
	, gtr_to   :: !DefinedSymbol
	, gtr_from :: !DefinedSymbol
662
663
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
664
665
666
::	TypeDefInfos :== {# .{# TypeDefInfo}}

::	FunType =
667
	{	ft_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
668
669
670
671
	,	ft_arity		:: !Int
	,	ft_priority		:: !Priority
	,	ft_type			:: !SymbolType
	,	ft_pos			:: !Position
672
	,	ft_specials		:: !FunSpecials
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
673
674
675
676
677
	,	ft_type_ptr		:: !VarInfoPtr
	}

::	FreeVar =
	{	fv_def_level	:: !Level
678
	,	fv_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
679
680
681
	,	fv_info_ptr		:: !VarInfoPtr
	,	fv_count		:: !Int
	}
682
683
684
685

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

686
687
688
689
::	FunCall	= FunCall !Index !Level
			| MacroCall !ModuleIndex !Index Level
			| DclFunCall !ModuleIndex !DclFunctionIndex
			| GeneratedFunCall !Index !FunctionInfoPtr;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
690

691
692
FI_IsMacroFun	:== 1			// whether the function is a local function of a macro
FI_HasTypeSpec	:== 2			// whether the function has u user defined type
693
694
FI_IsNonRecursive :== 4			// used in trans.icl and partition.icl
FI_IsUnboxedListOfRecordsConsOrNil :== 8
695
FI_MemberInstanceRequiresTypeInDefMod :== 16
696
697
698
FI_GenericFun :== 32
FI_Unused :== 64				// used in module trans
FI_UnusedUsed :== 128			// used in module trans
699
FI_HasTypeCodes :== 256
700

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
701
702
703
704
705
706
707
::	FunInfo =
	{	fi_calls			:: ![FunCall]
	,	fi_group_index		:: !Index
	,	fi_def_level		:: !Level
	,	fi_free_vars		:: ![FreeVar]
	,	fi_local_vars		:: ![FreeVar]
	,	fi_dynamics			:: ![ExprInfoPtr]
708
	,	fi_properties		:: !BITVECT
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
709
710
711
	}

::	ParsedBody =
712
713
714
	{	pb_args		:: ![ParsedExpr]
	,	pb_rhs		:: !Rhs
	,	pb_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
715
716
717
	}

::	CheckedBody =
718
719
	{	cb_args		:: ![FreeVar]
	,	cb_rhs		:: ![CheckedAlternative]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
720
721
	}

722
723
724
725
726
727
::	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
728
729
730
731
732
733
734
735
::	TransformedBody =
	{	tb_args			:: ![FreeVar]
	,	tb_rhs			:: !Expression
	}

::	FunctionBody	= ParsedBody ![ParsedBody]
					| CheckedBody !CheckedBody
	/* The next three constructors are used during macro expansion (module transform) */
736
737
					| PartitioningMacro
					| PartitioningFunction !CheckedBody !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
738
739
740
					| RhsMacroBody !CheckedBody
	/* macro expansion transforms a CheckedBody into a TransformedBody */
					| TransformedBody !TransformedBody
741
					| Expanding ![FreeVar] // the parameters of the newly generated function
742
					| GeneratedBody // the body will be generated automatically - for generics
743
					| NoBody
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
744
745

::	FunDef =
746
	{	fun_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
747
748
749
750
751
	,	fun_arity		:: !Int
	,	fun_priority	:: !Priority
	,	fun_body		:: !FunctionBody
	,	fun_type		:: !Optional SymbolType
	,	fun_pos			:: !Position
752
	,	fun_kind		:: !FunKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
753
754
755
756
757
758
759
760
	,	fun_lifted		:: !Int
	,	fun_info		:: !FunInfo
	}

cIsAGlobalVar	:== True
cIsALocalVar	:== False

::	ConsClasses =
761
	{	cc_size			::!Int
762
	,	cc_args			::![ConsClass]
763
	,	cc_linear_bits	::![#Bool!]
764
	,	cc_producer		::!ProdClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
765
	}
766

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
767
768
::	ConsClass	:== Int

769
770
771
772
::	ProdClass	:== Bool

pIsSafe			:== True

773
774
775
776
::	ImportedConstructors	:== [Global Index]
::	ImportedFunctions		:== [Global Index]
::	ImportedTypes			:== {#{# CheckedTypeDef}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
777
778
779
::	OptionalVariable :== Optional (Bind Ident VarInfoPtr)

:: 	AuxiliaryPattern
780
		= AP_Algebraic !(Global DefinedSymbol) !GlobalIndex ![AuxiliaryPattern] !OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
781
782
		| AP_Variable !Ident !VarInfoPtr OptionalVariable
		| AP_Basic !BasicValue OptionalVariable
John van Groningen's avatar
John van Groningen committed
783
		| AP_NewType !(Global DefinedSymbol) !Index AuxiliaryPattern OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
784
785
		| AP_Dynamic !AuxiliaryPattern !DynamicType !OptionalVariable
		| AP_Constant !AP_Kind !(Global DefinedSymbol) !Priority
786
		| AP_WildCard !OptionalVariable
787
		| AP_Empty
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
788

789
:: AP_Kind = APK_Constructor !GlobalIndex | APK_NewTypeConstructor !Index | APK_Macro !Bool // is_dcl_macro
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
790

791
792
::	VI_TypeInfo	= VITI_Empty
				| VITI_Coercion		CoercionPosition
793
				| VITI_PatternType	[AType] /*module*/!Index /*constructor*/!Index VI_TypeInfo
794

795
796
::	VarInfo  =	VI_Empty | VI_Type !AType !VI_TypeInfo |
				VI_FAType ![ATypeVar] !AType !VI_TypeInfo |
797
				VI_FATypeC ![ATypeVar] !AType ![TypeContext] !VI_TypeInfo | VI_FPC |
798
				VI_Occurrence !Occurrence | VI_UsedVar !Ident |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
799
800
				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 */ |
801
				VI_AccVar !ConsClass !ArgumentPosition /* used during fusion to determine accumulating parameters of functions */ |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
802
803
				VI_Alias !BoundVar /* used for resolving aliases just before type checking (in transform) */ |
				 /* used during elimination and lifting of cases */
804
805
806
807
				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
808
				VI_FreeVar !Ident !VarInfoPtr !Int !AType | VI_BoundVar !AType | VI_LocalVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
809
				VI_ClassVar !Ident !VarInfoPtr !Int | /* to hold dictionary variables during overloading */
810
				VI_EmptyConstructorClassVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
811
				VI_ForwardClassVar !VarInfoPtr | /* to hold the dictionary variable generated during overloading */
812
				VI_Forward !BoundVar | VI_LetVar !LetVarInfo | VI_LetExpression !LetExpressionInfo |
813
				VI_CaseOrStrictLetVar !VarInfoPtr | VI_StrictLetVar |
814
				VI_CorrespondenceNumber !Int | /* it is assumed that this alternative is _only_ used in module comparedefimp */
815
				VI_SequenceNumber !Int | VI_AliasSequenceNumber !BoundVar |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
816
817
818
				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 */
819
				VI_ExpandedMemberType !SymbolType !VarInfo /* VI_Empty or VI_ExpandedType */ | // only in sd_type_ptr
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
820
821
				VI_Record ![AuxiliaryPattern] |
				VI_Pattern !AuxiliaryPattern |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
822
				VI_TypeCodeVariable !TypeCodeVariableInfo |
823
				VI_DynamicValueAlias !BoundVar |
824
825
				VI_Body !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
				VI_ExpressionOrBody !Expression !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
826
				VI_Dictionary !SymbIdent ![Expression] !Type | /* used during fusion */
Sjaak Smetsers's avatar
Sjaak Smetsers committed
827
				VI_Extended !ExtendedVarInfo !VarInfo |
828
				VI_NotUsed |
829
830
831
				VI_Labelled_Empty !{#Char} | // RWS debugging
				VI_LocalLetVar | // RWS, mark Let vars during case transformation
				..
832

833
834
835
836
837
::	TypeCodeVariableInfo
	= TCI_TypeVar !Expression
	| TCI_TypePatternVar !Expression
	| TCI_SelectionsTypePatternVar ![(Expression,[Selection])]

838
::	ExtendedVarInfo = EVI_VarType !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
839

840
841
::	ArgumentPosition :== Int

842
::	VarHeap :== Heap VarInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
843
844
845
846
847
::	VarInfoPtr	:== Ptr VarInfo

cNotVarNumber :== -1

::	BoundVar = 
848
	{	var_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
849
850
851
852
853
	,	var_info_ptr	:: !VarInfoPtr
	,	var_expr_ptr	:: !ExprInfoPtr
	}

::	TypeSymbIdent =
854
	{	type_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
855
856
857
858
859
860
861
862
863
864
865
866
867
	,	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)
868
				| SK_IclMacro !Index
869
				| SK_LocalMacroFunction !Index
870
871
				| SK_DclMacro !(Global Index)
				| SK_LocalDclMacroFunction !(Global Index)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
872
873
				| SK_OverloadedFunction !(Global Index)
				| SK_GeneratedFunction !FunctionInfoPtr !Index
874
				| SK_Constructor !(Global Index)
John van Groningen's avatar
John van Groningen committed
875
				| SK_NewTypeConstructor !GlobalIndex
876
				| SK_Generic !(Global Index) !TypeKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
877
				| SK_TypeCode
878
879
880
881
				| SK_OverloadedConstructor !(Global Index)
				| SK_TFACVar !ExprInfoPtr
				| SK_VarContexts !(VarContexts TypeContext)
				| SK_TypeCodeAndContexts !(VarContexts TypeContext)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
882
883
884
885
886
887
888
889
890
891
892
893
894

/*	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
895
				| PR_Function !SymbIdent !Int !Index
Martin Wierich's avatar
Martin Wierich committed
896
				| PR_Class !App ![(BoundVar, Type)] !Type
897
898
899
				| PR_Constructor !SymbIdent !Int ![Expression]
				| PR_GeneratedFunction !SymbIdent !Int !Index
				| PR_Curried !SymbIdent !Int
900
				| PR_Unused
901
				| PR_CurriedFunction !SymbIdent !Int !Index
902
903
				| PR_String !{#Char}
				| PR_Int !Int
904
				| PR_Equal
905
				| PR_EqualRemove !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

::	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 */
931
					| EI_OverloadedWithVarContexts !OverloadedCallWithVarContexts /* initial, set by the type checker */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
932
					| EI_Instance 	!(Global DefinedSymbol) ![Expression]	/* intermedediate, used during resolving of overloading */ 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
933
					| EI_Selection 	![Selection] !VarInfoPtr ![Expression]	/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
934
					| EI_Context 	![Expression]							/* intermedediate, used during resolving of overloading */
935
936
					| EI_ContextWithVarContexts ![Expression] !(VarContexts DictionaryAndClassType) /* intermedediate, used during resolving of overloading */
					| EI_FPContext	![Expression] !ExprInfoPtr				/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
937
938
939

		/* For handling dynamics */

940
941
942
					| EI_UnmarkedDynamic 		!(Optional DynamicType) ![DynamicPtr]	// in expression
					| EI_Dynamic 				!(Optional DynamicType) ![DynamicPtr]	// in expression
					| EI_DynamicType			!DynamicType ![DynamicPtr]				// in pattern
943
					| EI_DynamicCopy !ExprInfoPtr !ExprInfo // used in module transform to copy dynamics in macros
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
944
945
946
947
948
949
950

		/* Auxiliary, was EI_DynamicType before checking */

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

		/* Auxiliary, used during type checking */

951
					| EI_TempDynamicType 		!(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] ![TypeContext] !ExprInfoPtr !SymbIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
952
					| EI_TempDynamicPattern 	![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
953
954

					| EI_TypeOfDynamic 			!TypeCodeExpression						/* Final */
955
					| EI_TypeOfDynamicAndTCsToFind !TypeCodeExpression !Ident ![VarInfoPtr]
956
					| EI_TypeOfDynamicPattern 	![VarInfoPtr] !TypeCodeExpression !Bool	/* Final */
957
					| EI_TypeOfDynamicWithContexts !TypeCodeExpression !(VarContexts DictionaryAndClassType)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
958
959
960

					| EI_TypeCode 		!TypeCodeExpression
					| EI_TypeCodes 		![TypeCodeExpression]
961
					| EI_TypeCodesWithContexts ![TypeCodeExpression] !(VarContexts DictionaryAndClassType)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
962
963
964

					| EI_Attribute !Int

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

968
					| EI_DictionaryType !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
969
970
					| EI_CaseType !CaseType
					| EI_LetType ![AType]
971
					| EI_CaseTypeWithContexts !CaseType ![(DefinedSymbol,[TypeContext])]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
972
					| EI_CaseTypeAndRefCounts !CaseType !RefCountsInCase
973
					| EI_CaseTypeAndSplits !CaseType !SplitsInCase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
974
975
976
977
978
979
					| EI_LetTypeAndRefCounts ![AType] ![Int]

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

					| EI_Default !Expression !AType !ExprInfoPtr
					| EI_DefaultFunction !SymbIdent ![Expression]
980
					| EI_Extended !ExtendedExprInfo !ExprInfo
981
982
983
984
985

::	ExtendedExprInfo
					= EEI_ActiveCase !ActiveCaseInfo

::	ActiveCaseInfo =
986
987
988
	{	aci_params					:: ![FreeVar]
	,	aci_opt_unfolder			:: !(Optional SymbIdent)
	,	aci_free_vars				:: !Optional [BoundVar]
989
	,	aci_linearity_of_patterns	:: ![![#Bool!]!]
990
	,	aci_safe					:: !Bool
991
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
992
993
994
995
996
997
998
999
1000
1001
1002
1003

/*
	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]
	}

1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
::	OverloadedCallWithVarContexts = 
	{	ocvc_symbol       :: !SymbIdent
	,	ocvc_context      :: ![TypeContext]
	,	ocvc_var_contexts :: !VarContexts TypeContext
	}

::	DictionaryAndClassType =
	{	dc_var			:: !VarInfoPtr
	,	dc_class_type	:: !AType
	}

::	VarContexts type_contexts
	= VarContext !Int /*arg_n*/ ![type_contexts] !AType !(VarContexts type_contexts)
	| NoVarContexts

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1019
1020
1021
1022
1023
1024
/*
	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
1025

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1026
1027
1028
1029
1030
1031
1032
::	CaseType =
	{	ct_pattern_type	:: !AType
	,	ct_result_type	:: !AType
	,	ct_cons_types 	:: ![[AType]]
	}
		
::	SymbIdent =
1033
	{	symb_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1034
1035
1036
1037
	,	symb_kind		:: !SymbKind
	}

::	ConsDef =
1038
	{	cons_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1039
1040
	,	cons_type			:: !SymbolType
	,	cons_priority		:: !Priority
1041
	,	cons_number			:: !Index // -2 for newtype constructor, -3 for added constructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1042
1043
1044
1045
1046
1047
1048
	,	cons_type_index		:: !Index