syntaxtr.t 20 KB
Newer Older
clean's avatar
clean committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include "compiledefines.h"

#define	new		new_is_keyword

#define STRUCT(struct_name,type_name) \
	typedef struct struct_name type_name##S; \
	typedef struct struct_name *type_name; \
	typedef struct struct_name *type_name##P; \
	struct struct_name

typedef enum {
	TupleState,  ArrayState, RecordState, SimpleState
} StateType;

/* the order of the StateKinds is used by IsLazyState and ExpectsResultNode */
typedef enum {
	OnB, LazyRedirection, StrictRedirection,		/* strict states, no result node */
	StrictOnA,										/* strict state, result node */
	OnA, SemiStrict, Parallel, Undefined, UnderEval	/* lazy states, result node */
} StateKind;

typedef enum {
	UnknownObj,
#if ABSTRACT_OBJECT
	AbstractObj,
#endif
28
	IntObj, BoolObj, CharObj, RealObj, FileObj, unusedObjectKind0/*StringObj*/,
clean's avatar
clean committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	TupleObj, ListObj, RecordObj, ArrayObj, StrictArrayObj, UnboxedArrayObj,
	WorldObj, ProcIdObj, RedIdObj
#ifdef CLEAN2
	,DynamicObj
#endif
	, NrOfObjects
} ObjectKind;

#if ABSTRACT_OBJECT
# define BASIC_ELEMS_STRING "uuibcrfsaaaaaaippa" /* index by ObjectKind */
#else
# define BASIC_ELEMS_STRING "uibcrfsaaaaaaippa" /* index by ObjectKind */
#endif

typedef enum {
	int_type, bool_type, char_type, real_type,
45
	file_type, unusedSymbKind0/*string_type*/, world_type, procid_type,
clean's avatar
clean committed
46
	redid_type,
47
48
49
50
51
#ifdef CLEAN2
	rational_denot,
#else
	Nr_Of_Basic_Types,
#endif
clean's avatar
clean committed
52
	int_denot, bool_denot, char_denot, real_denot,
53
/*	Nr_Of_Basic_Denots, */ integer_denot,
clean's avatar
clean committed
54
55
56
57
58
59
60
	string_denot,
	fun_type, array_type, strict_array_type, unboxed_array_type, list_type, tuple_type, empty_type,
#ifdef CLEAN2
	dynamic_type,
#endif
	Nr_Of_Predef_Types,
	tuple_symb, cons_symb, nil_symb,
John van Groningen's avatar
add seq    
John van Groningen committed
61
	apply_symb, if_symb, fail_symb, seq_symb,
clean's avatar
clean committed
62
63
64
65
66
67
	select_symb,
	Nr_Of_Predef_FunsOrConses,
	definition, newsymbol, instance_symb, empty_symbol, field_symbol_list,
	erroneous_symb
} SymbKind;

68
69
70
71
#ifdef CLEAN2
# define Nr_Of_Basic_Types rational_denot
#endif

clean's avatar
clean committed
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
STRUCT (state,State){
	union {
		struct state *				sd_args;		/* for TupleState and ArrayState */
		struct record_state_descr *	sd_rs;			/* for RecordState */
		unsigned long				sd_unq_type_args; /* for SimpleState with STATE_UNIQUE_TYPE_ARGUMENTS_MASK */
	} state_descr;
	short							state_arity;
	unsigned char 					state_kind:4;	/* StateKind, for SimpleState */
	unsigned char					state_mark:4;
	unsigned char					state_object:6;	/* ObjectKind, for SimpleState */
	unsigned char					state_type:2;	/* StateType */
};

#define state_unq_type_args state_descr.sd_unq_type_args

#define STATE_UNIQUE_TYPE_ARGUMENTS_MASK 8

# define state_record_symbol		state_descr.sd_rs->rs_symb
# define state_record_arguments		state_descr.sd_rs->rs_args
# define state_record_desc			state_descr.sd_rs
# define state_tuple_arguments		state_descr.sd_args
# define state_array_arguments		state_descr.sd_args

typedef struct state		*States;

#define STATE_PARALLEL_MASK 1
#define STATE_UNBOXED_ARRAY_MASK 2				/* for ArrayState */
#define STATE_ELEMENTS_UPDATEABLE_MASK 2		/* for TupleState */
#define STATE_UNIQUE_MASK 4

typedef struct record_state_descr {
	struct symbol_def *		rs_symb;
	StateS					rs_args[1];
} *RecordStateDescr;

typedef enum {
108
	FirstSystemModuleTable, LastSystemModuleTable=0x7fff
clean's avatar
clean committed
109
110
111
112
113
114
115
116
117
118
119
} TableKind;

typedef union symb_value {
	struct ident *					val_ident;
	struct symbol_def *				val_def;
	char *							val_int;
	Bool 							val_bool;
	char *							val_char;
	char *							val_string;
	char *							val_real;
	int								val_arity;
120
121
122
123
#if STRICT_LISTS
	struct state *					val_state_p;		/* element state for unboxed list cons in lhs */
	struct unboxed_cons *			val_unboxed_cons_p;	/* state and symbol definition for unboxed list cons in rhs */
#endif
124
	struct symbol_def *				val_apply_instance_field_def;
clean's avatar
clean committed
125
126
} SymbValue;

127
128
129
130
131
132
133
#if STRICT_LISTS
struct unboxed_cons {
	struct state *					unboxed_cons_state_p;
	struct symbol_def *				unboxed_cons_sdef_p;
};
#endif

clean's avatar
clean committed
134
135
STRUCT (symbol,Symbol) {
	SymbValue			symb_val;
136
137
138
	unsigned			symb_kind:8;			/* SymbKind */
	unsigned			symb_head_strictness:4; /* 0=lazy,1=overloaded,2=strict,3=unboxed overloaded,4=unboxed*/
	unsigned			symb_tail_strictness:2;	/* 0=lazy,1=strict */
clean's avatar
clean committed
139
140
};

141
142
#define symb_instance_apply symb_tail_strictness

143
#if STRICT_LISTS
144
145
146
147
# define symb_state_p symb_val.val_state_p
# define symb_unboxed_cons_p symb_val.val_unboxed_cons_p
# define symb_unboxed_cons_state_p symb_val.val_unboxed_cons_p->unboxed_cons_state_p
# define symb_unboxed_cons_sdef_p symb_val.val_unboxed_cons_p->unboxed_cons_sdef_p
148
149
#endif

clean's avatar
clean committed
150
151
152
153
154
155
156
157
#define symb_ident symb_val.val_ident
#define symb_def symb_val.val_def
#define symb_int symb_val.val_int
#define symb_bool symb_val.val_bool
#define symb_char symb_val.val_char
#define symb_string symb_val.val_string
#define symb_real symb_val.val_real
#define symb_arity symb_val.val_arity
158
#define symb_apply_instance_field_def symb_val.val_apply_instance_field_def
clean's avatar
clean committed
159
160
161

STRUCT(ident,Ident){
	char *				ident_name;
162
	char *				ident_instructions;
clean's avatar
clean committed
163
164
165
166
167
168
	struct ident *		ident_next;
	unsigned char		ident_table; /* TableKind */
	unsigned char		ident_mark;
};
 
#define INLINE_MASK					8
169
#define WARNED_NO_INLINE_CODE		16
clean's avatar
clean committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

/*
	The order in which the annotationkinds appear in the enum type
	determines their priority
*/

typedef enum {
	NoAnnot, StrictAnnot,
	/* parallel annotations: */
	ContinueAnnot, ParallelAnnot,
	LazyParallelAnnot, InterleavedAnnot, LazyInterleavedAnnot,
	ProcessAnnot,ParallelAtAnnot, DeferAnnot, ContInterleavedAnnot, WaitAnnot,
	ParallelNFAnnot, InterleavedNFAnnot
} Annotation;

typedef struct ident_string *IdentStringP;

struct ident_string {
	IdentStringP	left;
	IdentStringP	right;
	Ident			ident;
	char			*string;
};

typedef struct def_repr DefRepr,*DefMod;

typedef struct node_def *NodeDefs;

typedef struct {
	short index_a;
	short index_b;
} Index;

struct _exp;

STRUCT (node_id,NodeId){
	Ident			nid_ident;
	unsigned short	nid_mark;
	unsigned short	nid_mark2;
	int				nid_refcount;
	int				nid_number;
	union {
		struct node_id *				inf2_forward_node_id;
		Index							inf2_index;
		int								inf2_lazy_selector_ref_count;
	} nid_inf2;
	union {
217
		int	inf1_ref_count_copy;
clean's avatar
clean committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
		StateS			inf1_state;
	} nid_inf1;
	int				nid_scope;
	struct node *	nid_node;
	union {
		struct _exp *	u3_exp;
		struct node_id*	u3_lhs_tuple_node_id;
		struct node_id_ref_count_list *	u3_ref_count_element;	/* pattern_match: graph */
	} nid_u3;
	union {
		NodeDefs		u4_node_def;	/* only for rhs */
		struct state *	u4_lhs_state_p;	/* only for lhs */
	} nid_u4;
};

233
#define nid_ref_count_copy		nid_inf1.inf1_ref_count_copy			/* statesgen */
clean's avatar
clean committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#define nid_state 				nid_inf1.inf1_state						/* codegen2,instructions */

#define nid_forward_node_id				nid_inf2.inf2_forward_node_id	/* checker,transform */
#define nid_node_id_ref_count_element	nid_u3.u3_ref_count_element		/* pattern_match */
#define nid_node_id_ref_count_element_	nid_u3.u3_ref_count_element		/* pattern_match */
#define nid_a_index						nid_inf2.inf2_index.index_a		/* codegen2,instructions */
#define nid_b_index 					nid_inf2.inf2_index.index_b		/* codegen2,instructions */

#define nid_lazy_selector_ref_count		nid_inf2.inf2_lazy_selector_ref_count/* statesgen */

#define nid_forward_node_id_			nid_inf2.inf2_forward_node_id	/* checker,transform */
#define nid_a_index_					nid_inf2.inf2_index.index_a		/* codegen2,instructions */
#define nid_b_index_					nid_inf2.inf2_index.index_b		/* codegen2,instructions */

#define nid_exp					nid_u3.u3_exp							/* sa */
#define nid_lhs_tuple_node_id	nid_u3.u3_lhs_tuple_node_id

#define nid_node_def			nid_u4.u4_node_def						/* buildtree,sa,statesgen,optimisations */
#define nid_lhs_state_p			nid_u4.u4_lhs_state_p

#define nid_ref_count_copy_		nid_ref_count_copy
#define nid_ref_count_copy__	nid_ref_count_copy
#define nid_node_def_			nid_node_def
#define nid_state_				nid_state
#define nid_state__				nid_state
#define nid_lhs_tuple_node_id_	nid_lhs_tuple_node_id
#define nid_exp_				nid_exp
#define nid_lhs_state_p_		nid_lhs_state_p

/*	Masks for nid_mark */

#define SHARED_NODES_COLLECTED_MASK				1
#define NID_ALIAS_MASK 							2
#define NID_ALIAS_MARK_MASK						4
#define NID_EXTRA_REFCOUNT_MASK					16
#define ON_A_CYCLE_MASK							128
#define NID_VERIFY_MASK							256		/* macros */
#define NID_THEN_ELSE_NON_LOCAL_NODE_ID			512		/* pattern_match */

#define NID_STRICT_LHS_TUPLE_ELEMENT_MASK		8192	/* codegen1,codegen2 */
274
#define NID_SHARED_SELECTION_NODE_ID			16384	/* optimisations,codegen2 */
clean's avatar
clean committed
275
276
277
278
#define NID_LIFTED_BY_OPTIMISE					32768	/* optimisations */

/* Masks for nid_mark2 */

279
#define NID_SELECTION_NODE_ID				1
280
281
282
283
#if BOXED_RECORDS
# define NID_RECORD_USED_BY_UPDATE			2
# define NID_RECORD_USED_BY_NON_SELECTOR_OR_UPDATES 4
#endif
284
#define NID_FIELD_NAME_MASK					32			/* typechecker */
clean's avatar
clean committed
285
286
287
288
289
290
291
292
293
294
295

#define NID_LHS_PUSHED						4096			/* codegen1 */

#define NID_HAS_LAZY_SELECTOR_COUNTER		8192			/* statesgen */
#define NID_CALL_VIA_LAZY_SELECTIONS_ONLY	16384			/* statesgen */
#define NID_HAS_REFCOUNT_WITHOUT_UPDATES	32768

typedef struct imp_rule *ImpRules;
typedef struct rule_type *RuleTypes;

STRUCT (strict_node_id,StrictNodeId){
296
	NodeId					snid_node_id;
clean's avatar
clean committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
	struct strict_node_id *	snid_next;
#ifdef OBSERVE_ARRAY_SELECTS_IN_PATTERN
	unsigned				snid_array_select_in_pattern:1;
#endif
};

STRUCT (if_node_contents,IfNodeContents){
	NodeDefs		if_then_node_defs;
	union {
		StrictNodeIdP					u_strict_node_ids;
		struct node_id_ref_count_list *	u_node_id_ref_counts;
	} if_then_u;
	NodeDefs		if_else_node_defs;
	union {
		StrictNodeIdP					u_strict_node_ids;
		struct node_id_ref_count_list *	u_node_id_ref_counts;
	} if_else_u;
	int				if_local_scope;
};

#define if_then_strict_node_ids	if_then_u.u_strict_node_ids
#define if_else_strict_node_ids	if_else_u.u_strict_node_ids
#define node_then_node_id_ref_counts node_contents.contents_if->if_then_u.u_node_id_ref_counts
#define node_else_node_id_ref_counts node_contents.contents_if->if_else_u.u_node_id_ref_counts

typedef enum {
323
324
325
	IfNode, NormalNode, SelectorNode, NodeIdNode, UpdateNode, MatchNode,
	SwitchNode, CaseNode, DefaultNode, PushNode, GuardNode, OverloadedCaseNode,
	TupleSelectorsNode, FillUniqueNode
clean's avatar
clean committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
} NodeKind;

#define SELECTOR_U 2
#define SELECTOR_F 3
#define SELECTOR_L 4
#define SELECTOR_N 5 

#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
STRUCT (case_node_contents,CaseNodeContents){
	struct node_id_ref_count_list *	case_node_id_ref_counts;
	StrictNodeIdP					case_strict_node_ids;
};
#endif

STRUCT (node,Node){
	union {
		struct if_node_contents *	contents_if;
		Symbol						contents_symbol;
		NodeId						contents_node_id;
		struct node *				contents_node;
		struct node_id_list_element *contents_node_ids;
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
		StrictNodeIdP				contents_guard_strict_node_ids;
#endif
	} node_contents;

	struct arg *					node_arguments;

	union {
355
		StateS						su_state;
clean's avatar
clean committed
356
357
358
359
360
361
362
363
		struct {
			struct node_def *			 	u_node_defs;		/* for CaseNode,DefaultNode and GuardNode */
#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
			struct case_node_contents	  * u_case;
#else
			struct node_id_ref_count_list *	u_node_id_ref_counts;
#endif
		} su_u;
364
365
		struct {
			SymbolP						push_symbol;
366
#if STRICT_LISTS
367
368
369
370
			union {
				NodeP					pu_decons_node;			/* if overloaded push */
				int						pu_size;				/* if unique non overloaded push */
			} push_pu;
371
372
#else
			int push_size;
373
#endif
374
		} su_push;												/* for PushNode */
clean's avatar
clean committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	} node_su;

	short			node_arity;
	unsigned char	node_kind;		/* NodeKind */
	signed char		node_number:2;	/* statesgen: -1,0 or 1,pattern_match ? */
	Annotation		node_annotation:6;
};

#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
# define node_node_id_ref_counts	node_su.su_u.u_case->case_node_id_ref_counts
# define node_strict_node_ids		node_su.su_u.u_case->case_strict_node_ids
#else
# define node_node_id_ref_counts	node_su.su_u.u_node_id_ref_counts
#endif

#define node_state					node_su.su_state
#define node_node_defs				node_su.su_u.u_node_defs
#define node_symbol					node_contents.contents_symbol
#define node_node_id				node_contents.contents_node_id
#define node_node					node_contents.contents_node
#define node_node_ids				node_contents.contents_node_ids

#ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
#define node_guard_strict_node_ids	node_contents.contents_guard_strict_node_ids
#endif

#define node_then_node_defs			node_contents.contents_if->if_then_node_defs
#define node_then_strict_node_ids	node_contents.contents_if->if_then_strict_node_ids
#define node_else_node_defs			node_contents.contents_if->if_else_node_defs
#define node_else_strict_node_ids	node_contents.contents_if->if_else_strict_node_ids
#define node_if_scope				node_contents.contents_if->if_local_scope

407
#define node_push_symbol			node_su.su_push.push_symbol
408
409
410
#if STRICT_LISTS
# define node_decons_node			node_su.su_push.push_pu.pu_decons_node
# define node_push_size				node_su.su_push.push_pu.pu_size
411
412
#else
# define node_push_size				node_su.su_push.push_size
413
414
#endif

clean's avatar
clean committed
415
416
417
418
419
STRUCT (arg,Arg){
	Node 				arg_node;
	struct arg *		arg_next;
	union {
		StateS			u_state;
John van Groningen's avatar
John van Groningen committed
420
		unsigned long	u_occurrence;
clean's avatar
clean committed
421
422
423
424
425
426
427
428
	} arg_u;
};
typedef struct arg *Args;

#define arg_state arg_u.u_state
#define arg_occurrence arg_u.u_occurrence

STRUCT (node_def,NodeDef){
John van Groningen's avatar
John van Groningen committed
429
	NodeId		def_id;
clean's avatar
clean committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
	Node 		def_node;
	NodeDefs	def_next;
	int			def_mark;
};

#define NODE_DEF_MARKED 8
#define NODE_DEF_SELECT_AND_REMOVE_MASK 32

/*	for implementing calls to C or the OS */

typedef struct parameter Parameter,*Parameters;

struct parameter {
	union {
		NodeId	val_node_id;	/* if par_kind == 0 */
		Ident	val_ident;	/* if par_kind == 1 */
	} par_val;
	Ident		par_loc;
	Parameters	par_next;
	int			par_kind;
};

#define par_node_id par_val.val_node_id
#define par_ident par_val.val_ident

typedef struct instruction Instruction,*Instructions;

struct instruction {
	char *		instr_this;
	Instructions	instr_next;
};

STRUCT (code_block,CodeBlock){
	Parameters	co_parin;
	Parameters	co_parout;
	Instructions	co_instr;
	Bool			co_is_abc_code;
#ifdef CLEAN2
	Bool			co_is_inline;
#endif
};

typedef enum {
	Contractum, ExternalCall
} RhsKind;

typedef struct rule_alt 	*RuleAlts;

STRUCT (rule_alt,RuleAlt){
	Node					alt_lhs_root;	
	NodeDefs				alt_lhs_defs;
	union {
		Node				rhs_root;
		CodeBlock			rhs_code;
	} alt_rhs;
	NodeDefs				alt_rhs_defs;
486
	StrictNodeIdP			alt_strict_node_ids;
clean's avatar
clean committed
487
488
489
490
491
492
493
494
495
	unsigned				alt_line;
	unsigned				alt_kind:3;	/* RhsKind */
};

#define alt_rhs_root alt_rhs.rhs_root
#define alt_rhs_code alt_rhs.rhs_code

typedef enum {
	NEWDEFINITION, ABSTYPE, TYPE, TYPESYN, DEFRULE, IMPRULE,
496
	CONSTRUCTOR, SYSRULE, 
John van Groningen's avatar
John van Groningen committed
497
	RECORDTYPE, FIELDSELECTOR
clean's avatar
clean committed
498
499
500
501
502
} SDefKind;

#define SDefKindSize 5

typedef enum {
John van Groningen's avatar
John van Groningen committed
503
	TypeChecked, ConvertingToState, ConvertedToState
clean's avatar
clean committed
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
} CheckStatus;

typedef enum {
	CreateArrayFun, ArraySelectFun, UnqArraySelectFun, ArrayUpdateFun,
	ArrayReplaceFun, ArraySizeFun, UnqArraySizeFun,
	_CreateArrayFun,_UnqArraySelectFun,_UnqArraySelectNextFun,_UnqArraySelectLastFun,
	_ArrayUpdateFun,
	NoArrayFun 
} ArrayFunKind;

#define ArrayFunKindBitSize 4

#include "syntax_tree_types.h"

STRUCT (imp_rule,ImpRule){
	NodeP 						rule_root;
	RuleAlts 					rule_alts;
	struct type_alt * 			rule_type;
	StateP						rule_state_p;
	ImpRules					rule_next;
	union {
		ImpRuleP				u_next_changed_function;
		ImpRuleP				u_next_used_function;
		ImpRuleP				u_next_function_with_more_arguments;
	} rule_u;
	struct node *				rule_lazy_call_node;
#if STORE_STRICT_CALL_NODES
	struct node *				rule_strict_call_node;
	struct node *				rule_strict_call_node2;
#endif
	unsigned					rule_mark;
};

#define RULE_CAF_MASK					2
#define RULE_LAZY_CALL_NODE_MASK		4
#if STORE_STRICT_CALL_NODES
# define RULE_STRICT_CALL_NODE_MASK		8
# define RULE_STRICT_CALL_NODE2_MASK	16
#endif
#define RULE_HAS_VERSION_WITH_MORE_ARGUMENTS 32
#define RULE_UNBOXED_LAZY_CALL			64

#define RULE_CALL_VIA_LAZY_SELECTIONS_ONLY	1024
547
#define RULE_TAIL_MODULO_CONS_ENTRY_MASK	2048
clean's avatar
clean committed
548
549
550
551
552
553
554
555
556
557
558
559
560
561

#define rule_next_changed_function				rule_u.u_next_changed_function				/* optimisations */
#define rule_next_used_function					rule_u.u_next_used_function					/* optimisations */
#define rule_next_function_with_more_arguments	rule_u.u_next_function_with_more_arguments	/* statesgen */

STRUCT (symbol_def,SymbDef){
	char    	*sdef_module;
	Ident    	 sdef_ident;
	union
	{	Types			u_type;
		RuleTypes		u_rule_type;
		ImpRules		u_rule;
	} sdef_u;
	union
562
	{	StateS			typeinfo_record_state; /* for RECORDTYPE */
clean's avatar
clean committed
563
564
565
		struct
		{	FieldList	fieldinfo_sel_field;
			int			fieldinfo_sel_field_number;
566
		} sdef_fieldinfo; /* for FIELDSELECTOR */
clean's avatar
clean committed
567
		struct constructor_list * typeinfo_constructor;	/* for CONSTRUCTOR */
568
569
		struct symbol_def *typeinfo_dictionary_field; /* for IMPRULE if SDEF_INSTANCE_RULE_WITH_FIELD_P */
		struct symbol_def *typeinfo_instance_rule; /* for IMPRULE if SDEF_RULE_INSTANCE_RULE_P */
clean's avatar
clean committed
570
571
572
573
574
575
576
577
	} sdef_typeinfo;

	unsigned		sdef_number;
	unsigned		sdef_ancestor;
	short			sdef_arity;

	union {
		struct _fun *	u3_sa_fun;					/* sa.c */
578
579
580
#ifdef CLEAN2
		SymbolP			u3_unboxed_cons_symbol;		/* backend.c */
#endif
581
		struct state *	u3_member_states_of_field; /* for FIELDSELECTOR if SDEF_FIELD_HAS_MEMBER_TYPE */
clean's avatar
clean committed
582
583
584
	} sdef_u3;

	struct symbol_def *	sdef_dcl_icl;					/* to dcl if sdef_exported, to icl if sdef_main_dcl */
John van Groningen's avatar
John van Groningen committed
585
	struct symbol_def *	sdef_next_scc;
clean's avatar
clean committed
586
587

	union {
588
589
590
		struct symbol_def *	sdef_u2_next_version;	/* for IMPRULES */
		struct type_alt *	sdef_u2_member_type_of_field; /* for FIELDSELECTOR if SDEF_FIELD_HAS_MEMBER_TYPE */
		struct symbol *		sdef_u2_special_array_function_symbol; /* if SDEF_HAS_SPECIAL_ARRAY_FUNCTION */
clean's avatar
clean committed
591
592
593
594
	} sdef_u2;
	
	int				sdef_mark;

John van Groningen's avatar
John van Groningen committed
595
596
597
	unsigned		sdef_kind:SDefKindSize;
	unsigned		sdef_checkstatus:3;		/* CheckStatus */
	unsigned		sdef_arfun:ArrayFunKindBitSize;			/* ArrayFunKind */
clean's avatar
clean committed
598
599
600
601
	Bool			sdef_isused:1;
	Bool			sdef_returnsnode:1;
	Bool			sdef_calledwithrootnode:1;
	Bool			sdef_strict_constructor:1;		/* for CONSTRUCTOR and RECORDTYPE */
602
	Bool			sdef_boxed_record:1;			/* for RECORDTYPE */
clean's avatar
clean committed
603
604
605
606
607
608
609
610
	Bool			sdef_exported:1;
};

#define sdef_type			sdef_u.u_type
#define sdef_rule_type		sdef_u.u_rule_type
#define sdef_rule			sdef_u.u_rule

#define sdef_sa_fun					sdef_u3.u3_sa_fun
611
612
613
#ifdef CLEAN2
 #define sdef_unboxed_cons_symbol sdef_u3.u3_unboxed_cons_symbol
#endif
614
#define sdef_member_states_of_field sdef_u3.u3_member_states_of_field
clean's avatar
clean committed
615
616
617
618

#define	SDEF_USED_LAZILY_MASK 1
#define SDEF_USED_STRICTLY_MASK 2
#define SDEF_USED_CURRIED_MASK 4
619
#define SDEF_RECORD_R_LABEL_IMPORTED_MASK 8
clean's avatar
clean committed
620
621
622
#define SDEF_NEXT_IMP_RULE_VERSION_MASK 32
#define	SDEF_HAS_IMP_RULE_VERSIONS_MASK 64
#define	SDEF_OPTIMISED_FUNCTION_MASK 128
623
#define SDEF_INLINE_IS_CONSTRUCTOR 4096
624
625
626
#define SDEF_FIELD_HAS_MEMBER_TYPE 1024
#define SDEF_INSTANCE_RULE_WITH_FIELD_P 16384
#define SDEF_RULE_INSTANCE_RULE_P 32768
627
#define SDEF_HAS_SPECIAL_ARRAY_FUNCTION 512
clean's avatar
clean committed
628
629
630
631
632
633

/* some macros to reuse bit fields */

#define sdef_group_number		sdef_ancestor

#define sdef_next_version	sdef_u2.sdef_u2_next_version
634
#define sdef_special_array_function_symbol	sdef_u2.sdef_u2_special_array_function_symbol
635
#define sdef_member_type_of_field	sdef_u2.sdef_u2_member_type_of_field
clean's avatar
clean committed
636
637
638
639
640

#define sdef_constructor sdef_typeinfo.typeinfo_constructor

#define sdef_record_state	sdef_typeinfo.typeinfo_record_state

641
#define sdef_sel_field	sdef_typeinfo.sdef_fieldinfo.fieldinfo_sel_field
clean's avatar
clean committed
642
643
#define sdef_sel_field_number	sdef_typeinfo.sdef_fieldinfo.fieldinfo_sel_field_number

644
645
646
#define sdef_dictionary_field	sdef_typeinfo.typeinfo_dictionary_field
#define sdef_instance_rule	sdef_typeinfo.typeinfo_instance_rule

clean's avatar
clean committed
647
648
649
650
651
652
653
#if IMPORT_OBJ_AND_LIB
struct string_list {
	char *				sl_string;
	struct string_list *sl_next;
};
#endif

John van Groningen's avatar
John van Groningen committed
654
655
struct foreign_export_list {
	SymbolP						fe_symbol_p;
656
	int							fe_stdcall;
John van Groningen's avatar
John van Groningen committed
657
658
659
	struct foreign_export_list *fe_next;
};

660
661
typedef char *ModuleFileTime;

662
663
664
665
666
struct module_function_and_type_symbols {
	int		mfts_n_functions;
	SymbolP	mfts_function_symbol_a;
	int		mfts_n_types;
	SymbolP	mfts_type_symbol_a;
667
};
668

clean's avatar
clean committed
669
typedef struct {
670
	char *				im_name;
671
672
673
	struct module_function_and_type_symbols im_mfts_a;
	int					im_size_dcl_mfts_a;
	struct module_function_and_type_symbols *im_dcl_mfts_a;
clean's avatar
clean committed
674
675
676
677
678
679
680
	ImpRules			im_rules;
	struct symbol_def *	im_start;
	DefMod				im_def_module;
#if IMPORT_OBJ_AND_LIB
	struct string_list *	im_imported_objs;
	struct string_list *	im_imported_libs;
#endif
John van Groningen's avatar
John van Groningen committed
681
	struct foreign_export_list *	im_foreign_exports;
682
	ModuleFileTime		im_modification_time;
clean's avatar
clean committed
683
684
685
} *ImpMod, ImpRepr;

struct def_repr {
686
	char *		dm_name;
687
	int			dm_module_n;
688
689
	int			dm_n_function_symbols;
	SymbolP		dm_function_symbol_a;
clean's avatar
clean committed
690
	Bool		dm_system_module;
691
	ModuleFileTime	dm_modification_time;
clean's avatar
clean committed
692
};