aboutsummaryrefslogtreecommitdiff
path: root/backendC/CleanCompilerSources/checker_2.c
blob: aeb59bde0a2fa98ce9b9ef652f16eeb5176598c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
	Authors:	Sjaak Smetsers & John van Groningen
	Version:	1.2
*/

#pragma segment checker

#define COMPLEX_ABSTYPES
#define MOVE_LIFTED_CONSTANTS
#define OPTIMIZE_APPLIES
#define MOVE_MORE_LIFTED_CONSTANTS
#define MOVE_CURRIED_APPLICATIONS
#define MOVE_FUNCTIONS_IN_LAMBDAS

#include "compiledefines.h"
#include "types.t"
#include "system.h"
#include "syntaxtr.t"
#include "comsupport.h"
#include "sizes.h"
#include "scanner.h"
#include "buildtree.h"
#include "comparser.h"
#include "statesgen.h"
#include "codegen_types.h"
#include "codegen1.h"
#include "codegen2.h"
#include "instructions.h"
#include "typechecker.h"
#include "transform.h"
#include "checksupport.h"
#include "overloading.h"
#include "settings.h"
#include "checker.h"
#ifdef MOVE_FUNCTIONS_IN_LAMBDAS
# include "optimise_lambda.h"
#endif
#ifdef applec
#	include <types.h>
#endif

#undef DEBUG_REF_COUNT

#ifdef DEBUG_REF_COUNT
# define IF_DEBUG_REF_COUNT(a) a
# include "dbprint.h"
#else
# define IF_DEBUG_REF_COUNT(a)
#endif

#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n)

struct def_list {
	Symbol				mod_name;
	Bool				mod_undereval;
	DefMod				mod_body;
	struct def_list *	mod_next;
};

typedef struct def_list *DefModList,DefModElem;

static DefModList OpenDefinitionModules;

void GenDependencyList (void)
{
	DefModList def_mod;

	for_l (def_mod,OpenDefinitionModules,mod_next)
		GenDepend (def_mod->mod_body->dm_name->symb_ident->ident_name
#if WRITE_DCL_MODIFICATION_TIME
					,def_mod->mod_body->dm_modification_time
#endif
					);
}

void ReadInlineCode (void)
{
	DefModList d_mod;

	for_l (d_mod,OpenDefinitionModules,mod_next){
		DefMod def_mod;
		
		def_mod=d_mod->mod_body;
		if (def_mod->dm_system_module){
			Symbol symbol;
			
			for_l (symbol,def_mod->dm_symbols,symb_next)
				if (symbol->symb_kind==definition){
					SymbDef sdef;

					sdef=symbol->symb_def;
					if (sdef->sdef_kind==SYSRULE && sdef->sdef_mark & SDEF_USED_STRICTLY_MASK)
						break;
				}
			
			if (symbol!=NULL && d_mod->mod_name->symb_ident->ident_name!=CurrentModule)
				/* Get the inline instructions of all the rules that are defined in this module */
				ScanInlineFile (d_mod->mod_name->symb_ident->ident_name);
		}
	}
}


Ident AnnotatedId, ListId, TupleId, ConsId, NilId, ApplyId, SelectId,
#ifdef CLEAN2
	DynamicId,
#endif
	DeltaBId, IfId, FailId, AndId, OrId,
	StdArrayId, ArrayFunctionIds [NoArrayFun];

#if SA_RECOGNIZES_ABORT_AND_UNDEF
Ident StdMiscId,abort_id,undef_id;	
#endif

Symbol StartSymbol;

SymbDef ArrayFunctionDefs [NoArrayFun],StdArrayAbortDef;

SymbDef scc_dependency_list;
SymbDef *scc_dependency_list_p;

SymbDef MakeNewSymbolDefinition (char * module, Ident name, int arity, SDefKind kind)
{
	SymbDef def;
	
	def = CompAllocType (SymbDefS);
	
	def->sdef_module = module;
	def->sdef_ident = name;
	def->sdef_arity = arity;
	def->sdef_kind = kind;
	def->sdef_line = 0;

	def->sdef_mark=0;
	def->sdef_over_arity=0;

	def->sdef_exported=False;
	def->sdef_main_dcl=False;
	def->sdef_infix=False;

	def->sdef_arfun				= NoArrayFun;
	
	return def;
}

static NodeDefs FreeDefs;

NodeDefs NewNodeDef (NodeId nid,Node node)
{
	NodeDefs new;

	if (FreeDefs){
		new = FreeDefs;
		FreeDefs = FreeDefs->def_next;
	} else
		new = CompAllocType (NodeDefS);

	new->def_id		= nid;
	new->def_node	= node;
	new->def_mark	= 0;

	return new;
}

static Ident SystemFunctionsId,StdArrayAbortId;

void InitChecker (void)
{
	FreeDefs=NIL;
#ifndef CLEAN2
	free_ldefs=NULL;
	free_depend_macros=NULL;
#endif
	AnnotatedId	= PutStringInHashTable ("_annotated", SymbolIdTable);
	ListId		= PutStringInHashTable ("[...]", SymbolIdTable);
	TupleId		= PutStringInHashTable ("(...)", SymbolIdTable);
	ConsId		= PutStringInHashTable ("[...|...]", SymbolIdTable);
	NilId		= PutStringInHashTable ("[]", SymbolIdTable);
	ApplyId		= PutStringInHashTable ("AP", SymbolIdTable);
	SelectId	= PutStringInHashTable ("_Select", SymbolIdTable);

#ifdef CLEAN2
	DynamicId	= PutStringInHashTable ("Dynamic", SymbolIdTable);
#endif
	
	/* hack RWS */
	IfId		= PutStringInHashTable ("if ", SymbolIdTable);
	IfId->ident_name	= "if";

	FailId		= PutStringInHashTable ("_Fail", SymbolIdTable);

	StartSymbol = NewSymbol (newsymbol);
	StartSymbol -> symb_ident = PutStringInHashTable ("Start", SymbolIdTable);

	AndId		= PutStringInHashTable ("&&", SymbolIdTable);
	OrId		= PutStringInHashTable ("||", SymbolIdTable);

#if SA_RECOGNIZES_ABORT_AND_UNDEF
	abort_id = PutStringInHashTable ("abort",SymbolIdTable);
	undef_id = PutStringInHashTable ("undef",SymbolIdTable);
#endif

	SystemFunctionsId	= PutStringInHashTable ("StdEnum", ModuleIdTable);
	DeltaBId 			= PutStringInHashTable ("StdBool", ModuleIdTable);
	StdArrayId			= PutStringInHashTable ("_SystemArray", ModuleIdTable);

#if SA_RECOGNIZES_ABORT_AND_UNDEF
	StdMiscId = PutStringInHashTable ("StdMisc",ModuleIdTable);
#endif

 	/* Predefined Array functions */
 	
 	StdArrayAbortId						= PutStringInHashTable ("_abortArray", SymbolIdTable);
	ArrayFunctionIds[CreateArrayFun]	= PutStringInHashTable ("createArray", SymbolIdTable);
	ArrayFunctionIds[UnqArraySelectFun]	= PutStringInHashTable ("uselect", SymbolIdTable);
	ArrayFunctionIds[ArrayReplaceFun]	= PutStringInHashTable ("replace", SymbolIdTable);
	ArrayFunctionIds[UnqArraySizeFun]	= PutStringInHashTable ("usize", SymbolIdTable);
	ArrayFunctionIds[ArrayUpdateFun]	= PutStringInHashTable ("update", SymbolIdTable);
	ArrayFunctionIds[ArraySelectFun]	= PutStringInHashTable ("select", SymbolIdTable);
	ArrayFunctionIds[ArraySizeFun]		= PutStringInHashTable ("size", SymbolIdTable);
	ArrayFunctionIds[_CreateArrayFun]	= PutStringInHashTable ("_createArrayc", SymbolIdTable);
	ArrayFunctionIds[_UnqArraySelectFun]= PutStringInHashTable ("_uselectf", SymbolIdTable);
	ArrayFunctionIds[_UnqArraySelectNextFun]= PutStringInHashTable ("_uselectn", SymbolIdTable);
	ArrayFunctionIds[_UnqArraySelectLastFun]= PutStringInHashTable ("_uselectl", SymbolIdTable);
	ArrayFunctionIds[_ArrayUpdateFun]= PutStringInHashTable ("_updatei", SymbolIdTable);

#ifndef CLEAN2
	FunTypeClass.tac_uniprop = ALLBITSCLEAR;
	FunTypeClass.tac_possign = BIT(1);
	FunTypeClass.tac_negsign = BIT(0);

	GeneralTypeClass.tac_uniprop = ALLBITSSET;
	GeneralTypeClass.tac_possign = ALLBITSSET;
	GeneralTypeClass.tac_negsign = ALLBITSCLEAR;
#endif

	OpenDefinitionModules	= NIL;
}

#ifdef CLEAN2
	void ClearOpenDefinitionModules (void)
	{
		OpenDefinitionModules	= NULL;
	}
	
	void AddOpenDefinitionModule (SymbolP moduleNameSymbol, DefMod definitionModule)
	{
		DefModList	openModule;
	
		openModule = CompAllocType (DefModElem);
		openModule->mod_name	= moduleNameSymbol;
		openModule->mod_body	= definitionModule;
		openModule->mod_next	= OpenDefinitionModules;
	
		OpenDefinitionModules  = openModule;
	}
#endif