syntax.dcl 50.7 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_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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
::	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
162
	,	dcl_has_macro_conversions :: !Bool
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
	,	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
184
::	RhsDefsOfType	= ConsList ![ParsedConstructor]
185
					| SelectorList !Ident ![ATypeVar] !Bool /*is_boxed_record*/ ![ParsedSelector]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
186
					| TypeSpec !AType
John van Groningen's avatar
John van Groningen committed
187
					| NewTypeCons !ParsedConstructor
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
188
					| EmptyRhs !BITVECT
189
					| AbstractTypeSpec !BITVECT !AType
190
					| ExtensibleConses ![ParsedConstructor]
191
					| MoreConses !Ident ![ParsedConstructor]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
192

193
::	CollectedDefinitions instance_kind =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
194
	{	def_types 			:: ![TypeDef TypeRhs]
195
196
	,	def_constructors	:: ![ConsDef]
	,	def_selectors		:: ![SelectorDef]
197
198
	,	def_macros			:: ![FunDef]
	,	def_macro_indices	:: !IndexRange
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
199
200
201
202
	,	def_classes			:: ![ClassDef]
	,	def_members			:: ![MemberDef]
	,	def_funtypes		:: ![FunType]
	,	def_instances		:: ![instance_kind]
203
204
205
206
207
208
209
210
211
212
213
214
215
	,	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
216
217
218
219
220
221
222
	}

::	LocalDefs	= LocalParsedDefs [ParsedDefinition]
				| CollectedLocalDefs CollectedLocalDefs

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

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


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

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

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

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


cIsAFunction	:== True
cIsNotAFunction :== False

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

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

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

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

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

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

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

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

321
322
323
324
::	IdentOrQualifiedIdent
	= Ident !Ident
	| QualifiedIdent /*module*/!Ident !String

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
325
326
327
328
329
/*
	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 
330
	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
331
332
333
334
335
336
337
	to store the index of the function that has been specialized.
*/

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

341
342
::	FunSpecials
	= FSP_ParsedSubstitutions 	![Env Type TypeVar]
343
	| FSP_Substitutions			![SpecialSubstitution]
344
345
346
347
	| FSP_ContextTypes			![Special]
	| FSP_FunIndex				!Index
	| FSP_None

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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
::	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 =
374
 	{	class_ident			:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
375
376
377
378
379
380
381
382
383
	,	class_arity			:: !Int
	,	class_args			:: ![TypeVar]
	,	class_context		:: ![TypeContext]
	,	class_members		:: !{# DefinedSymbol}
	,	class_dictionary	:: !DefinedSymbol
	,	class_pos			:: !Position
	,	class_cons_vars		:: !BITVECT
	}

384
385
::	ClassDefInfos :== {# .{! [TypeKind]}}

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

397
:: GenericDef = 
John van Groningen's avatar
John van Groningen committed
398
	{	gen_ident		:: !Ident		// the generics name in IC_Generic
399
	,	gen_member_ident	:: !Ident	// the generics name in IC_Expression
400
	, 	gen_pos			:: !Position
401
402
	,	gen_type		:: !SymbolType	// Generic type (st_vars include generic type vars)
	,	gen_vars		:: ![TypeVar]	// Generic type variables
403
	,	gen_deps		:: ![GenericDependency]	   // Generic function dependencies
404
	,	gen_info_ptr	:: !GenericInfoPtr
405
	}
Artem Alimarine's avatar
Artem Alimarine committed
406

407
408
409
410
411
412
413
414
415
:: GenericDependency =
	{	gd_ident		:: !IdentOrQualifiedIdent
	, 	gd_index		:: !GlobalIndex
	, 	gd_vars			:: ![TypeVar]
	,	gd_nums			:: ![Int] // Mapping from dependency variable to generic type variable
	}

instance == GenericDependency

416
417
418
419
420
421
422
423
424
425
426
:: 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
427
428
	,	gen_rep_conses	:: !{!GenericRepresentationConstructor}
	//	OBJECT, CONS, RECORD, FIELD, PAIR, EITHER, UNIT
429
	}
430

431
::	GenericRepresentationConstructor =
432
433
434
435
436
437
438
	{	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
439
440
	}

441
442
443
444
445
446
447
:: GenericInfoPtr :== Ptr GenericInfo	
:: GenericHeap :== Heap GenericInfo

:: TypeCons 
	= TypeConsSymb TypeSymbIdent 
	| TypeConsBasic BasicType 
	| TypeConsArrow
448
449
	| TypeConsVar TypeVar
	| TypeConsQualifiedIdent !Ident !String 
450

451
452
:: GenericCaseDef =
	{	gc_pos			:: !Position			// position in the source file
453
454
	,	gc_type			:: !Type				// the instance type
	,   gc_type_cons	:: !TypeCons			// type constructor of the type argument
455
	,	gc_gcf			:: !GenericCaseFunctions
456
	}
457
458
459

::	GenericCaseFunctions
	= GCF !Ident !GCF
460
461
	| GCFS ![!GCF!]
	| GCFC !Ident !Ident	// IC_GenericDeriveClass IC_Class
462
463

::	GCF = {
464
		gcf_gident	:: !Ident,	  			// name in IC_Generic namespace
465
466
		gcf_generic	:: !GlobalIndex,		// index of the generic
		gcf_arity	:: !Int,				// arity of the function
467
		gcf_generic_info :: !Int,			// 0 = no, -1 = all, generic info for CONS, OBJECT, RECORD or FIELD
468
		gcf_body	:: !GenericCaseBody,	// the body function or NoIndex
469
470
		gcf_kind	:: !TypeKind,			// kind of the instance type
		gcf_generic_instance_deps :: !GenericInstanceDependencies
471
472
	}

473
474
:: GenericCaseBody 
	= GCB_None 									// to be generated
475
476
477
478
479
480
481
482
483
484
	| 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*/
485

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
486
487
488
489
490
491
492
493
::	InstanceType =
	{	it_vars			:: [TypeVar]
	,	it_types		:: ![Type]
	,	it_attr_vars	:: [AttributeVar]
	,	it_context		:: ![TypeContext]
	}

::	ClassInstance =
John van Groningen's avatar
John van Groningen committed
494
495
 	{	ins_class_index	:: !GlobalIndex
	,	ins_class_ident	:: !ClassIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
496
497
	,	ins_ident		:: !Ident
	,	ins_type		:: !InstanceType
498
	,	ins_member_types :: ![FunType]	// for .dcl
499
	,	ins_members		:: !{#ClassInstanceMember}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
500
501
502
503
	,	ins_specials	:: !Specials
	,	ins_pos			:: !Position
	}

John van Groningen's avatar
John van Groningen committed
504
::	ClassIdent =
505
	{	ci_ident		:: !IdentOrQualifiedIdent
John van Groningen's avatar
John van Groningen committed
506
507
508
	,	ci_arity		:: !Int
	}

509
510
511
512
513
514
::	ClassInstanceMember = 
	{	cim_ident		:: !Ident
	,	cim_arity		:: !Int		// module number if cim_index<0
	,	cim_index		:: !Index	// or -1-index
	}

515
::	Import =
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
516
	{	import_module		:: !Ident
517
	,	import_symbols		:: !ImportSymbols [ImportDeclaration]
Martin Wierich's avatar
Martin Wierich committed
518
	,	import_file_position:: !Position	// for error messages
519
	,	import_qualified	:: !ImportQualified
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
520
521
	}

522
523
524
525
::	ImportSymbols import_declarations
	= ImportSymbolsAll
	| ImportSymbolsOnly !import_declarations

526
527
::	ImportQualified = NotQualified | Qualified

528
instance toString Import, AttributeVar, TypeAttribute, Annotation
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
529

530
::	ParsedImport		:== Import
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
531

532
533
534
535
536
::	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])
537
						| ID_Generic !Ident !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
538
539
540

cIsImportedLibrary :== True
cIsImportedObject :== False
541

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
542
543
544
545
546
547
548
549
:: ImportedObject =
	{	io_is_library :: !Bool
	,	io_name    :: !{#Char}
	}

::	RecordType =
	{	rt_constructor	:: !DefinedSymbol
	,	rt_fields		:: !{# FieldSymbol}
550
	,	rt_is_boxed_record :: !Bool
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
551
	}
552

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
553
::	FieldSymbol =
554
	{	fs_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
555
556
557
558
559
560
561
	,	fs_var			:: !Ident
	,	fs_index		:: !Index
	}

::	TypeRhs	= AlgType ![DefinedSymbol]
			| SynType !AType
			| RecordType !RecordType
John van Groningen's avatar
John van Groningen committed
562
			| NewType !DefinedSymbol
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
563
			| AbstractType !BITVECT
564
			| AbstractSynType !BITVECT !AType
565
			| ExtensibleAlgType ![DefinedSymbol]
566
567
			| AlgConses ![DefinedSymbol] !GlobalIndex
			| UncheckedAlgConses !Ident ![DefinedSymbol]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
568
569
570
571
572
573
574
575
			| UnknownType

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

cAllBitsClear			:== 0
cIsHyperStrict			:== 1
cIsNonCoercible			:== 2
576
577
578
579
580
581
cIsAnalysed				:== 4

::	GlobalIndex =
	{	gi_module	::!Int
	,	gi_index	::!Int
	}
582
NoGlobalIndex :== {gi_module=NoIndex,gi_index=NoIndex}	
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
583
584

::	TypeDef type_rhs =
585
	{	td_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
586
587
588
589
590
591
592
	,	td_index		:: !Int
	,	td_arity		:: !Int
	,	td_args			:: ![ATypeVar]
	,	td_attrs		:: ![AttributeVar]
	,	td_rhs			:: !type_rhs
	,	td_attribute	:: !TypeAttribute
	,	td_pos			:: !Position
593
	,	td_used_types	:: ![GlobalIndex]
594
	,	td_fun_index	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
595
596
597
598
599
	}

::	TypeDefInfo =
	{	tdi_kinds			:: ![TypeKind]
	,	tdi_properties		:: !BITVECT
600
	,	tdi_group			:: ![GlobalIndex]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
601
602
603
	,	tdi_group_nr		:: !Int
	,	tdi_group_vars		:: ![Int]
	,	tdi_cons_vars		:: ![Int]
604
	,	tdi_index_in_group	:: !Index
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
605
	,	tdi_classification	:: !TypeClassification
606
	,	tdi_gen_rep 		:: !Optional GenericTypeRep
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
607
608
	}

609
610
611
612
613
// type structure is used to specialize a generic to a type
:: GenTypeStruct 
	= GTSAppCons TypeKind [GenTypeStruct]
	| GTSAppVar TypeVar [GenTypeStruct] 
	| GTSVar TypeVar
614
615
616
617
618
619
620
621
622
623
624
625
626
 	| GTSCons !DefinedSymbol !GlobalIndex !DefinedSymbol !DefinedSymbol !GenTypeStruct
 	| GTSRecord !DefinedSymbol !GlobalIndex !DefinedSymbol !DefinedSymbol !GenTypeStruct
 	| GTSField !DefinedSymbol !GlobalIndex !DefinedSymbol !GenTypeStruct
 	| GTSObject !DefinedSymbol !GlobalIndex !DefinedSymbol !GenTypeStruct
	| GTSE
	// the following constructors are used for optimizing bimaps
	| GTSPair !GenTypeStruct !GenTypeStruct
	| GTSEither !GenTypeStruct !GenTypeStruct
	| GTSUnit
	| GTSArrow GenTypeStruct GenTypeStruct
 	| GTSAppConsBimapKindConst
	| GTSAppBimap TypeKind [GenTypeStruct]
	| GTSAppConsSimpleType !GlobalIndex !TypeKind ![GenTypeStruct]
627

628
:: GenericTypeRep = 
629
	{ gtr_type :: GenTypeStruct		// generic structure type
630
631
632
	, gtr_iso  :: !DefinedSymbol	// the conversion isomorphism
	, gtr_to   :: !DefinedSymbol
	, gtr_from :: !DefinedSymbol
633
634
	}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
635
636
637
::	TypeDefInfos :== {# .{# TypeDefInfo}}

::	FunType =
638
	{	ft_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
639
640
641
642
	,	ft_arity		:: !Int
	,	ft_priority		:: !Priority
	,	ft_type			:: !SymbolType
	,	ft_pos			:: !Position
643
	,	ft_specials		:: !FunSpecials
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
644
645
646
647
648
	,	ft_type_ptr		:: !VarInfoPtr
	}

::	FreeVar =
	{	fv_def_level	:: !Level
649
	,	fv_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
650
651
652
	,	fv_info_ptr		:: !VarInfoPtr
	,	fv_count		:: !Int
	}
653
654
655
656

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

657
658
659
660
::	FunCall	= FunCall !Index !Level
			| MacroCall !ModuleIndex !Index Level
			| DclFunCall !ModuleIndex !DclFunctionIndex
			| GeneratedFunCall !Index !FunctionInfoPtr;
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
661

662
663
FI_IsMacroFun	:== 1			// whether the function is a local function of a macro
FI_HasTypeSpec	:== 2			// whether the function has u user defined type
664
665
FI_IsNonRecursive :== 4			// used in trans.icl and partition.icl
FI_IsUnboxedListOfRecordsConsOrNil :== 8
666
FI_MemberInstanceRequiresTypeInDefMod :== 16
667
668
669
FI_GenericFun :== 32
FI_Unused :== 64				// used in module trans
FI_UnusedUsed :== 128			// used in module trans
670
FI_HasTypeCodes :== 256
671

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
672
673
674
675
676
677
678
::	FunInfo =
	{	fi_calls			:: ![FunCall]
	,	fi_group_index		:: !Index
	,	fi_def_level		:: !Level
	,	fi_free_vars		:: ![FreeVar]
	,	fi_local_vars		:: ![FreeVar]
	,	fi_dynamics			:: ![ExprInfoPtr]
679
	,	fi_properties		:: !BITVECT
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
680
681
682
	}

::	ParsedBody =
683
684
685
	{	pb_args		:: ![ParsedExpr]
	,	pb_rhs		:: !Rhs
	,	pb_position	:: !Position
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
686
687
688
	}

::	CheckedBody =
689
690
	{	cb_args		:: ![FreeVar]
	,	cb_rhs		:: ![CheckedAlternative]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
691
692
	}

693
694
695
696
697
698
::	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
699
700
701
702
703
704
705
706
::	TransformedBody =
	{	tb_args			:: ![FreeVar]
	,	tb_rhs			:: !Expression
	}

::	FunctionBody	= ParsedBody ![ParsedBody]
					| CheckedBody !CheckedBody
	/* The next three constructors are used during macro expansion (module transform) */
707
708
					| PartitioningMacro
					| PartitioningFunction !CheckedBody !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
709
710
711
					| RhsMacroBody !CheckedBody
	/* macro expansion transforms a CheckedBody into a TransformedBody */
					| TransformedBody !TransformedBody
712
					| Expanding ![FreeVar] // the parameters of the newly generated function
713
					| GeneratedBody // the body will be generated automatically - for generics
714
					| NoBody
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
715
716

::	FunDef =
717
	{	fun_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
718
719
720
721
722
	,	fun_arity		:: !Int
	,	fun_priority	:: !Priority
	,	fun_body		:: !FunctionBody
	,	fun_type		:: !Optional SymbolType
	,	fun_pos			:: !Position
723
	,	fun_kind		:: !FunKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
724
725
726
727
728
729
730
731
	,	fun_lifted		:: !Int
	,	fun_info		:: !FunInfo
	}

cIsAGlobalVar	:== True
cIsALocalVar	:== False

::	ConsClasses =
732
	{	cc_size			::!Int
733
	,	cc_args			::![ConsClass]
734
	,	cc_linear_bits	::![#Bool!]
735
	,	cc_producer		::!ProdClass
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
736
	}
737

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
738
739
::	ConsClass	:== Int

740
741
742
743
::	ProdClass	:== Bool

pIsSafe			:== True

744
745
746
747
::	ImportedConstructors	:== [Global Index]
::	ImportedFunctions		:== [Global Index]
::	ImportedTypes			:== {#{# CheckedTypeDef}}

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
748
749
750
::	OptionalVariable :== Optional (Bind Ident VarInfoPtr)

:: 	AuxiliaryPattern
751
		= AP_Algebraic !(Global DefinedSymbol) !GlobalIndex ![AuxiliaryPattern] !OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
752
753
		| AP_Variable !Ident !VarInfoPtr OptionalVariable
		| AP_Basic !BasicValue OptionalVariable
John van Groningen's avatar
John van Groningen committed
754
		| AP_NewType !(Global DefinedSymbol) !Index AuxiliaryPattern OptionalVariable
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
755
756
		| AP_Dynamic !AuxiliaryPattern !DynamicType !OptionalVariable
		| AP_Constant !AP_Kind !(Global DefinedSymbol) !Priority
757
		| AP_WildCard !OptionalVariable
758
		| AP_Empty
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
759

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

762
763
::	VI_TypeInfo	= VITI_Empty
				| VITI_Coercion		CoercionPosition
764
				| VITI_PatternType	[AType] /*module*/!Index /*constructor*/!Index VI_TypeInfo
765
766

//::	VarInfo  =	VI_Empty | VI_Type !AType !(Optional CoercionPosition) | VI_FAType ![ATypeVar] !AType !(Optional CoercionPosition) |
767
768
::	VarInfo  =	VI_Empty | VI_Type !AType !VI_TypeInfo |
				VI_FAType ![ATypeVar] !AType !VI_TypeInfo |
769
				VI_FATypeC ![ATypeVar] !AType ![TypeContext] !VI_TypeInfo | VI_FPC |
770
				VI_Occurrence !Occurrence | VI_UsedVar !Ident |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
771
772
				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 */ |
773
				VI_AccVar !ConsClass !ArgumentPosition /* used during fusion to determine accumulating parameters of functions */ |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
774
775
				VI_Alias !BoundVar /* used for resolving aliases just before type checking (in transform) */ |
				 /* used during elimination and lifting of cases */
776
777
778
779
				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
780
				VI_FreeVar !Ident !VarInfoPtr !Int !AType | VI_BoundVar !AType | VI_LocalVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
781
				VI_ClassVar !Ident !VarInfoPtr !Int | /* to hold dictionary variables during overloading */
782
				VI_EmptyConstructorClassVar |
Sjaak Smetsers's avatar
Sjaak Smetsers committed
783
				VI_ForwardClassVar !VarInfoPtr | /* to hold the dictionary variable generated during overloading */
784
				VI_Forward !BoundVar | VI_LetVar !LetVarInfo | VI_LetExpression !LetExpressionInfo |
785
				VI_CaseOrStrictLetVar !VarInfoPtr | VI_StrictLetVar |
786
				VI_CorrespondenceNumber !Int | /* it is assumed that this alternative is _only_ used in module comparedefimp */
787
				VI_SequenceNumber !Int | VI_AliasSequenceNumber !BoundVar |
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
788
789
790
791
792
				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
793
				VI_TypeCodeVariable !TypeCodeVariableInfo |
794
				VI_DynamicValueAlias !BoundVar |
795
796
				VI_Body !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
				VI_ExpressionOrBody !Expression !SymbIdent !TransformedBody ![FreeVar] ![TypeVar] ![TypeVar] | /* used during fusion */
797
				VI_Dictionary !SymbIdent ![Expression] !Type | /* used during fusion */
Sjaak Smetsers's avatar
Sjaak Smetsers committed
798
				VI_Extended !ExtendedVarInfo !VarInfo |
799
				VI_NotUsed |
800
// MdM
801
				VI_CPSExprVar !CheatCompiler /* a pointer to a variable in CleanProverSystem is stored here, using a cast */
802
// ... MdM
803
				| VI_Labelled_Empty !{#Char} // RWS debugging
804
				| VI_LocalLetVar // RWS, mark Let vars during case transformation
805

806
807
808
809
810
::	TypeCodeVariableInfo
	= TCI_TypeVar !Expression
	| TCI_TypePatternVar !Expression
	| TCI_SelectionsTypePatternVar ![(Expression,[Selection])]

811
::	ExtendedVarInfo = EVI_VarType !AType
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
812

813
814
::	ArgumentPosition :== Int

815
::	VarHeap :== Heap VarInfo
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
816
817
818
819
820
::	VarInfoPtr	:== Ptr VarInfo

cNotVarNumber :== -1

::	BoundVar = 
821
	{	var_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
822
823
824
825
826
	,	var_info_ptr	:: !VarInfoPtr
	,	var_expr_ptr	:: !ExprInfoPtr
	}

::	TypeSymbIdent =
827
	{	type_ident		:: !Ident
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
828
829
830
831
832
833
834
835
836
837
838
839
840
	,	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)
841
				| SK_IclMacro !Index
842
				| SK_LocalMacroFunction !Index
843
844
				| SK_DclMacro !(Global Index)
				| SK_LocalDclMacroFunction !(Global Index)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
845
846
				| SK_OverloadedFunction !(Global Index)
				| SK_GeneratedFunction !FunctionInfoPtr !Index
847
				| SK_Constructor !(Global Index)
John van Groningen's avatar
John van Groningen committed
848
				| SK_NewTypeConstructor !GlobalIndex
849
				| SK_Generic !(Global Index) !TypeKind
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
850
				| SK_TypeCode
851
852
853
854
				| SK_OverloadedConstructor !(Global Index)
				| SK_TFACVar !ExprInfoPtr
				| SK_VarContexts !(VarContexts TypeContext)
				| SK_TypeCodeAndContexts !(VarContexts TypeContext)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
855
856
857
858
859
860
861
862
863
864
865
866
867

/*	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
868
				| PR_Function !SymbIdent !Int !Index
Martin Wierich's avatar
Martin Wierich committed
869
				| PR_Class !App ![(BoundVar, Type)] !Type
870
871
872
				| PR_Constructor !SymbIdent !Int ![Expression]
				| PR_GeneratedFunction !SymbIdent !Int !Index
				| PR_Curried !SymbIdent !Int
873
				| PR_Unused
874
				| PR_CurriedFunction !SymbIdent !Int !Index
875
876
877
878
				| PR_String !{#Char}
				| PR_Int !Int
				| PR_Equal !Int
				| PR_EqualRemove !Int
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903

::	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 */
904
					| EI_OverloadedWithVarContexts !OverloadedCallWithVarContexts /* initial, set by the type checker */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
905
					| EI_Instance 	!(Global DefinedSymbol) ![Expression]	/* intermedediate, used during resolving of overloading */ 
Sjaak Smetsers's avatar
Sjaak Smetsers committed
906
					| EI_Selection 	![Selection] !VarInfoPtr ![Expression]	/* intermedediate, used during resolving of overloading */
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
907
					| EI_Context 	![Expression]							/* intermedediate, used during resolving of overloading */
908
909
					| 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
910
911
912

		/* For handling dynamics */

913
914
915
					| 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
916
917
918
919
920
921
922

		/* Auxiliary, was EI_DynamicType before checking */

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

		/* Auxiliary, used during type checking */

923
					| EI_TempDynamicType 		!(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] ![TypeContext] !ExprInfoPtr !SymbIdent
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
924
					| EI_TempDynamicPattern 	![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
925
926

					| EI_TypeOfDynamic 			!TypeCodeExpression						/* Final */
927
					| EI_TypeOfDynamicPattern 	![VarInfoPtr] !TypeCodeExpression !Bool	/* Final */
928
					| EI_TypeOfDynamicWithContexts !TypeCodeExpression !(VarContexts DictionaryAndClassType)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
929
930
931

					| EI_TypeCode 		!TypeCodeExpression
					| EI_TypeCodes 		![TypeCodeExpression]
932
					| EI_TypeCodesWithContexts ![TypeCodeExpression] !(VarContexts DictionaryAndClassType)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
933
934
935

					| EI_Attribute !Int

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

939
					| EI_DictionaryType !Type
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
940
941
					| EI_CaseType !CaseType
					| EI_LetType ![AType]
942
					| EI_CaseTypeWithContexts !CaseType ![(DefinedSymbol,[TypeContext])]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
943
					| EI_CaseTypeAndRefCounts !CaseType !RefCountsInCase
944
					| EI_CaseTypeAndSplits !CaseType !SplitsInCase
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
945
946
947
948
					| EI_LetTypeAndRefCounts ![AType] ![Int]

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

949

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
950
951
					| EI_Default !Expression !AType !ExprInfoPtr
					| EI_DefaultFunction !SymbIdent ![Expression]
952
					| EI_Extended !ExtendedExprInfo !ExprInfo
953
954
955
956
957

::	ExtendedExprInfo
					= EEI_ActiveCase !ActiveCaseInfo

::	ActiveCaseInfo =
958
959
960
	{	aci_params					:: ![FreeVar]
	,	aci_opt_unfolder			:: !(Optional SymbIdent)
	,	aci_free_vars				:: !Optional [BoundVar]
961
	,	aci_linearity_of_patterns	:: ![![#Bool!]!]
962
	,	aci_safe					:: !Bool
963
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
964
965
966
967
968
969
970
971
972
973
974
975

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

976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
::	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
991
992
993
994
995
996
/*
	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
997

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
998
999
1000
::	CaseType =
	{	ct_pattern_type	:: !AType
	,	ct_result_type	:: !AType
For faster browsing, not all history is shown. View entire blame