Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /trunk/src/utilities/calculus/code.c – Rev 2 and 7

Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "calculus.h"
62
#include "calculus.h"
33
#include "code.h"
63
#include "code.h"
34
#include "error.h"
64
#include "error.h"
35
#include "common.h"
65
#include "common.h"
Line 38... Line 68...
38
#include "suffix.h"
68
#include "suffix.h"
39
#include "type_ops.h"
69
#include "type_ops.h"
40
 
70
 
41
 
71
 
42
/*
72
/*
43
    OUTPUT FLAGS
73
 * OUTPUT FLAGS
44
 
74
 *
45
    The flag extra_asserts, if set to true, will cause the C implementation
75
 * The flag extra_asserts, if set to true, will cause the C implementation
46
    of the output to include assertions for run-time checks.  check_null is
76
 * of the output to include assertions for run-time checks.  check_null is
47
    a string used in the assertions output.  extra_headers and map_proto
77
 * a string used in the assertions output.  extra_headers and map_proto
48
    are used for backwards compatibility on extra headers and union map
78
 * are used for backwards compatibility on extra headers and union map
49
    prototypes.
79
 * prototypes.
50
*/
80
 */
51
 
-
 
52
int extra_asserts = 0 ;
-
 
53
int extra_headers = 0 ;
-
 
54
int map_proto = 1 ;
-
 
55
static char *check_null ;
-
 
56
 
-
 
57
 
-
 
58
/*
-
 
59
    PRINT AN ASSIGNMENT COMPONENT
-
 
60
 
81
 
61
    This routine prints the series of assignment operations to assign the
82
int extra_asserts = 0;
62
    value of type t given by nm to an offset p from the variable x%u_.  It
83
int extra_headers = 0;
-
 
84
int map_proto = 1;
63
    returns the offset from x%u_ at the end of these assignments.
85
static char *check_null;
64
*/
-
 
65
 
86
 
-
 
87
 
-
 
88
/*
66
static int assign_component
89
 * PRINT AN ASSIGNMENT COMPONENT
-
 
90
 *
-
 
91
 * This routine prints the series of assignment operations to assign the
-
 
92
 * value of type t given by nm to an offset p from the variable x%u_.  It
67
    PROTO_N ( ( t, p, nm, depth ) )
93
 * returns the offset from x%u_ at the end of these assignments.
-
 
94
 */
-
 
95
 
-
 
96
static int
68
    PROTO_T ( TYPE_P t X int p X char *nm X int depth )
97
assign_component(TYPE_P t, int p, char *nm, int depth)
69
{
98
{
70
    TYPE t0 = DEREF_type ( t ) ;
99
    TYPE t0 = DEREF_type(t);
71
    if ( depth > MAX_TYPE_DEPTH ) {
100
    if (depth > MAX_TYPE_DEPTH) {
72
	error ( ERROR_SERIOUS, "Cyclic type definition involving %s",
101
	error(ERROR_SERIOUS, "Cyclic type definition involving %s",
73
		name_type ( t ) ) ;
102
		name_type(t));
74
	return ( p ) ;
103
	return(p);
75
    }
104
    }
76
 
105
 
77
    if ( IS_type_ident ( t0 ) ) {
106
    if (IS_type_ident(t0)) {
78
	/* Use identity definition */
107
	/* Use identity definition */
79
	IDENTITY_P id = DEREF_ptr ( type_ident_id ( t0 ) ) ;
108
	IDENTITY_P id = DEREF_ptr(type_ident_id(t0));
80
	TYPE_P s = DEREF_ptr ( ident_defn ( id ) ) ;
109
	TYPE_P s = DEREF_ptr(ident_defn(id));
81
	return ( assign_component ( s, p, nm, depth + 1 ) ) ;
110
	return(assign_component(s, p, nm, depth + 1));
82
 
111
 
83
    } else if ( IS_type_structure ( t0 ) ) {
112
    } else if (IS_type_structure(t0)) {
84
	/* Deal with structures componentwise */
113
	/* Deal with structures componentwise */
85
	char buff [500] ;
114
	char buff[500];
86
	STRUCTURE_P str ;
115
	STRUCTURE_P str;
87
	LIST ( COMPONENT_P ) c ;
116
	LIST(COMPONENT_P)c;
88
	str = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
117
	str = DEREF_ptr(type_structure_struc(t0));
89
	c = DEREF_list ( str_defn ( str ) ) ;
118
	c = DEREF_list(str_defn(str));
90
	while ( !IS_NULL_list ( c ) ) {
119
	while (!IS_NULL_list(c)) {
91
	    COMPONENT_P cmp = DEREF_ptr ( HEAD_list ( c ) ) ;
120
	    COMPONENT_P cmp = DEREF_ptr(HEAD_list(c));
92
	    char *c_nm = DEREF_string ( cmp_name ( cmp ) ) ;
121
	    char *c_nm = DEREF_string(cmp_name(cmp));
93
	    TYPE_P c_type = DEREF_ptr ( cmp_type ( cmp ) ) ;
122
	    TYPE_P c_type = DEREF_ptr(cmp_type(cmp));
94
	    int n = ( int ) strlen ( nm ) + ( int ) strlen ( c_nm ) + 8 ;
123
	    int n = (int)strlen(nm) + (int)strlen(c_nm) + 8;
95
	    if ( n > ( int ) sizeof ( buff ) ) {
124
	    if (n > (int)sizeof(buff)) {
96
		error ( ERROR_SERIOUS, "Too many field selectors in type %s",
125
		error(ERROR_SERIOUS, "Too many field selectors in type %s",
97
			name_type ( t ) ) ;
126
			name_type(t));
98
		break ;
127
		break;
99
	    }
128
	    }
100
	    sprintf_v ( buff, "%s.%s", nm, c_nm ) ;
129
	    sprintf_v(buff, "%s.%s", nm, c_nm);
101
	    p = assign_component ( c_type, p, buff, depth + 1 ) ;
130
	    p = assign_component(c_type, p, buff, depth + 1);
102
	    c = TAIL_list ( c ) ;
131
	    c = TAIL_list(c);
103
	}
132
	}
104
	return ( p ) ;
133
	return(p);
105
    }
134
    }
106
 
135
 
107
    /* Other types are simple */
136
    /* Other types are simple */
108
    output ( "\tCOPY_%TM ( x%u_ + %d, %e ) ;\\\n", t, p, nm ) ;
137
    output("\tCOPY_%TM(x%u_ + %d, %e);\\\n", t, p, nm);
109
    return ( p + size_type ( t, 0 ) ) ;
138
    return(p + size_type(t, 0));
110
}
139
}
111
 
140
 
112
 
141
 
113
/*
142
/*
114
    PRINT A DEREFERENCE COMPONENT
143
 * PRINT A DEREFERENCE COMPONENT
115
 
144
 *
116
    This routine prints the series of dereference operations to assign the
145
 * This routine prints the series of dereference operations to assign the
117
    value of type t given by an offset p from the variable x%u_ into nm.  It
146
 * value of type t given by an offset p from the variable x%u_ into nm.  It
118
    returns the offset from x%u_ at the end of these dereferences.  depth is
147
 * returns the offset from x%u_ at the end of these dereferences.  depth is
119
    used to catch cyclic type definitions.
148
 * used to catch cyclic type definitions.
120
*/
149
 */
121
 
150
 
122
static int deref_component
151
static int
123
    PROTO_N ( ( t, p, nm, depth ) )
-
 
124
    PROTO_T ( TYPE_P t X int p X char *nm X int depth )
152
deref_component(TYPE_P t, int p, char *nm, int depth)
125
{
153
{
126
    TYPE t0 = DEREF_type ( t ) ;
154
    TYPE t0 = DEREF_type(t);
127
    if ( depth > MAX_TYPE_DEPTH ) {
155
    if (depth > MAX_TYPE_DEPTH) {
128
	error ( ERROR_SERIOUS, "Cyclic type definition involving %s",
156
	error(ERROR_SERIOUS, "Cyclic type definition involving %s",
129
		name_type ( t ) ) ;
157
		name_type(t));
130
	return ( p ) ;
158
	return(p);
131
    }
159
    }
132
 
160
 
133
    if ( IS_type_ident ( t0 ) ) {
161
    if (IS_type_ident(t0)) {
134
	/* Use identity definition */
162
	/* Use identity definition */
135
	IDENTITY_P id = DEREF_ptr ( type_ident_id ( t0 ) ) ;
163
	IDENTITY_P id = DEREF_ptr(type_ident_id(t0));
136
	TYPE_P s = DEREF_ptr ( ident_defn ( id ) ) ;
164
	TYPE_P s = DEREF_ptr(ident_defn(id));
137
	return ( deref_component ( s, p, nm, depth + 1 ) ) ;
165
	return(deref_component(s, p, nm, depth + 1));
138
 
166
 
139
    } else if ( IS_type_structure ( t0 ) ) {
167
    } else if (IS_type_structure(t0)) {
140
	/* Deal with structures componentwise */
168
	/* Deal with structures componentwise */
141
	char buff [500] ;
169
	char buff[500];
142
	STRUCTURE_P str ;
170
	STRUCTURE_P str;
143
	LIST ( COMPONENT_P ) c ;
171
	LIST(COMPONENT_P)c;
144
	str = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
172
	str = DEREF_ptr(type_structure_struc(t0));
145
	c = DEREF_list ( str_defn ( str ) ) ;
173
	c = DEREF_list(str_defn(str));
146
	while ( !IS_NULL_list ( c ) ) {
174
	while (!IS_NULL_list(c)) {
147
	    COMPONENT_P cmp = DEREF_ptr ( HEAD_list ( c ) ) ;
175
	    COMPONENT_P cmp = DEREF_ptr(HEAD_list(c));
148
	    char *c_nm = DEREF_string ( cmp_name ( cmp ) ) ;
176
	    char *c_nm = DEREF_string(cmp_name(cmp));
149
	    TYPE_P c_type = DEREF_ptr ( cmp_type ( cmp ) ) ;
177
	    TYPE_P c_type = DEREF_ptr(cmp_type(cmp));
150
	    int n = ( int ) strlen ( nm ) + ( int ) strlen ( c_nm ) + 8 ;
178
	    int n = (int)strlen(nm) + (int)strlen(c_nm) + 8;
151
	    if ( n > ( int ) sizeof ( buff ) ) {
179
	    if (n > (int)sizeof(buff)) {
152
		error ( ERROR_SERIOUS, "Too many field selectors in type %s",
180
		error(ERROR_SERIOUS, "Too many field selectors in type %s",
153
			name_type ( t ) ) ;
181
			name_type(t));
154
		break ;
182
		break;
155
	    }
183
	    }
156
	    sprintf_v ( buff, "%s.%s", nm, c_nm ) ;
184
	    sprintf_v(buff, "%s.%s", nm, c_nm);
157
	    p = deref_component ( c_type, p, buff, depth + 1 ) ;
185
	    p = deref_component(c_type, p, buff, depth + 1);
158
	    c = TAIL_list ( c ) ;
186
	    c = TAIL_list(c);
159
	}
187
	}
160
	return ( p ) ;
188
	return(p);
161
    }
189
    }
162
 
190
 
163
    /* Other types are simple */
191
    /* Other types are simple */
164
    if ( is_complex_type ( t ) ) {
192
    if (is_complex_type(t)) {
165
	output ( "\tDEREF_%TM ( x%u_ + %d, %e ) ;\\\n", t, p, nm ) ;
193
	output("\tDEREF_%TM(x%u_ + %d, %e);\\\n", t, p, nm);
166
    } else {
194
    } else {
167
	output ( "\t%e = DEREF_%TM ( x%u_ + %d ) ;\\\n", nm, t, p ) ;
195
	output("\t%e = DEREF_%TM(x%u_ + %d);\\\n", nm, t, p);
168
    }
196
    }
169
    return ( p + size_type ( t, 0 ) ) ;
197
    return(p + size_type(t, 0));
170
}
198
}
171
 
199
 
172
 
200
 
173
/*
201
/*
286
 
294
 
287
/*
295
/*
288
    PRINT RUN-TIME CHECK FUNCTIONS
296
 * PRINT RUN-TIME CHECK FUNCTIONS
-
 
297
 *
-
 
298
 * If the assertion variable is set then these functions will be printed,
-
 
299
 * they are to be used to perform run-time checks on the calculus.
-
 
300
 * These functions are delivered to a special file.
-
 
301
 */
289
 
302
 
290
    If the assertion variable is set then these functions will be printed,
-
 
291
    they are to be used to perform run-time checks on the calculus.
-
 
292
    These functions are delivered to a special file.
-
 
293
*/
303
static void
294
 
-
 
295
void print_assert_fns
304
print_assert_fns(void)
296
    PROTO_Z ()
-
 
297
{
305
{
298
    /* Assertion printing */
306
    /* Assertion printing */
299
    output ( "#ifndef assert_%X\n" ) ;
307
    output("#ifndef assert_%X\n");
300
    output ( "static void assert_%X\n" ) ;
308
    output("static void\n");
301
    output ( "    PROTO_N ( ( s, fn, ln ) )\n" ) ;
-
 
302
    output ( "    PROTO_T ( CONST_S char *s X CONST_S char *fn X int ln )\n" ) ;
309
    output("assert_%X\n(char *s, char *fn, int ln)\n");
303
    output ( "{\n" ) ;
310
    output("{\n");
304
    output ( "    ( void ) fprintf ( stderr, \"Assertion %%s failed, " ) ;
311
    output("    (void)fprintf(stderr, \"Assertion %%s failed, ");
305
    output ( "%%s, line %%d.\\n\", s, fn, ln ) ;\n" ) ;
312
    output("%%s, line %%d.\\n\", s, fn, ln);\n");
306
    output ( "    abort () ;\n" ) ;
313
    output("    abort();\n");
307
    output ( "}\n" ) ;
314
    output("}\n");
308
    output ( "#endif\n\n" ) ;
315
    output("#endif\n\n");
309
 
316
 
310
    /* Null pointer check */
317
    /* Null pointer check */
311
    output ( "%X *check_null_%X\n" ) ;
318
    output("%X *\n");
312
    output ( "    PROTO_N ( ( p, fn, ln ) )\n" ) ;
319
    output("check_null_%X\n");
313
    output ( "    PROTO_T ( %X *p X CONST_S char *fn X int ln )\n" ) ;
320
    output("(%X *p, char *fn, int ln)\n");
314
    output ( "{\n" ) ;
321
    output("{\n");
315
    output ( "    if ( p == NULL ) " ) ;
322
    output("    if (p == NULL) ");
316
    output ( "assert_%X ( \"Null pointer\", fn, ln ) ;\n" ) ;
323
    output("assert_%X(\"Null pointer\", fn, ln);\n");
317
    output ( "    return ( p ) ;\n" ) ;
324
    output("    return(p);\n");
318
    output ( "}\n\n" ) ;
325
    output("}\n\n");
319
 
326
 
320
    /* Union tag check */
327
    /* Union tag check */
321
    output ( "%X *check_tag_%X\n" ) ;
328
    output("%X *\n");
322
    output ( "    PROTO_N ( ( p, t, fn, ln ) )\n" ) ;
329
    output("check_tag_%X\n");
323
    output ( "    PROTO_T ( %X *p X unsigned t X CONST_S char *fn X int ln )\n" ) ;
330
    output("(%X *p, unsigned t, char *fn, int ln)\n");
324
    output ( "{\n" ) ;
331
    output("{\n");
325
    output ( "    p = check_null_%X ( p, fn, ln ) ;\n" ) ;
332
    output("    p = check_null_%X(p, fn, ln);\n");
326
    output ( "    if ( p->ag_tag != t ) " ) ;
333
    output("    if (p->ag_tag != t) ");
327
    output ( "assert_%X ( \"Union tag\", fn, ln ) ;\n" ) ;
334
    output("assert_%X(\"Union tag\", fn, ln);\n");
328
    output ( "    return ( p ) ;\n" ) ;
335
    output("    return(p);\n");
329
    output ( "}\n\n" ) ;
336
    output("}\n\n");
330
 
337
 
331
    /* Union tag range check */
338
    /* Union tag range check */
332
    output ( "%X *check_tag_etc_%X\n" ) ;
339
    output("%X *\n");
333
    output ( "    PROTO_N ( ( p, tl, tb, fn, ln ) )\n" ) ;
340
    output("check_tag_etc_%X\n");
334
    output ( "    PROTO_T ( %X *p X unsigned tl X unsigned tb " ) ;
341
    output("(%X *p, unsigned tl, unsigned tb ");
335
    output ( "X CONST_S char *fn X int ln )\n" ) ;
342
    output("X char *fn X int ln)\n");
336
    output ( "{\n" ) ;
343
    output("{\n");
337
    output ( "    p = check_null_%X ( p, fn, ln ) ;\n" ) ;
344
    output("    p = check_null_%X(p, fn, ln);\n");
338
    output ( "    if ( p->ag_tag < tl || p->ag_tag >= tb ) {\n" ) ;
345
    output("    if (p->ag_tag < tl || p->ag_tag >= tb) {\n");
339
    output ( "\tassert_%X ( \"Union tag\", fn, ln ) ;\n" ) ;
346
    output("\tassert_%X(\"Union tag\", fn, ln);\n");
340
    output ( "    }\n" ) ;
347
    output("    }\n");
341
    output ( "    return ( p ) ;\n" ) ;
348
    output("    return(p);\n");
342
    output ( "}\n\n" ) ;
349
    output("}\n\n");
343
 
350
 
344
    /* Vector trim range check */
351
    /* Vector trim range check */
345
    if ( !allow_vec ) return ;
352
    if (!allow_vec) return;
346
    output ( "int check_int_size\n" ) ;
353
    output("int\n");
347
    output ( "    PROTO_N ( ( n, m, fn, ln ) )\n" ) ;
354
    output("check_int_size\n");
348
    output ( "    PROTO_T ( int n X int m X CONST_S char *fn X int ln )\n" ) ;
355
    output("(int n, int m, char *fn, int ln)\n");
349
    output ( "{\n" ) ;
356
    output("{\n");
350
    output ( "    if ( n > m ) assert_%X ( \"Vector bound\", fn, ln ) ;\n" ) ;
357
    output("    if (n > m) assert_%X(\"Vector bound\", fn, ln);\n");
351
    output ( "    return ( n ) ;\n" ) ;
358
    output("    return(n);\n");
352
    output ( "}\n\n" ) ;
359
    output("}\n\n");
353
    return ;
360
    return;
354
}
361
}
355
 
-
 
356
 
-
 
357
/*
-
 
358
    MAXIMUM ALLOCATION CHUNK
-
 
359
 
-
 
360
    This variable is used to keep track of the largest block used in
-
 
361
    the memory allocation routine.
-
 
362
*/
-
 
363
 
-
 
364
static int gen_max = 0 ;
-
 
365
 
362
 
366
 
363
 
367
/*
364
/*
368
    FIND A MEMORY ALLOCATION INSTRUCTION
365
 * MAXIMUM ALLOCATION CHUNK
369
 
366
 *
370
    This routine returns the instruction for allocating a block of n
367
 * This variable is used to keep track of the largest block used in
371
    objects.  gen_max is also kept up to date.
368
 * the memory allocation routine.
372
*/
369
 */
373
 
370
 
374
static char *gen
371
static int gen_max = 0;
375
    PROTO_N ( ( n, nm ) )
-
 
376
    PROTO_T ( int n X char *nm )
-
 
377
{
-
 
378
    static char gbuff [100] ;
-
 
379
    sprintf_v ( gbuff, "GEN_%%X ( %d, TYPEID_%s )", n, nm ) ;
-
 
380
    if ( n > gen_max ) gen_max = n ;
-
 
381
    return ( gbuff ) ;
-
 
382
}
-
 
383
 
372
 
384
 
373
 
385
/*
374
/*
386
    PRINT SIMPLE LIST CONSTRUCTORS
375
 * FIND A MEMORY ALLOCATION INSTRUCTION
387
 
376
 *
388
    This routine prints the list construction and deconstruction routines
377
 * This routine returns the instruction for allocating a block of n
389
    for the type named nm of size sz.  d is true for simply dereferenced
378
 * objects.  gen_max is also kept up to date.
390
    types.
-
 
391
*/
379
 */
392
 
380
 
-
 
381
static char *
-
 
382
gen(int n, char *nm)
-
 
383
{
393
static void print_simple_cons
384
    static char gbuff[100];
-
 
385
    sprintf_v(gbuff, "GEN_%%X(%d, TYPEID_%s)", n, nm);
394
    PROTO_N ( ( nm, sz, d ) )
386
    if (n > gen_max)gen_max = n;
-
 
387
    return(gbuff);
-
 
388
}
-
 
389
 
-
 
390
 
-
 
391
/*
-
 
392
 * PRINT SIMPLE LIST CONSTRUCTORS
-
 
393
 *
-
 
394
 * This routine prints the list construction and deconstruction routines
-
 
395
 * for the type named nm of size sz.  d is true for simply dereferenced
-
 
396
 * types.
-
 
397
 */
-
 
398
 
-
 
399
static void
395
    PROTO_T ( char *nm X int sz X int d )
400
print_simple_cons(char *nm, int sz, int d)
396
{
401
{
397
    /* CONS routine */
402
    /* CONS routine */
398
    char *g ;
403
    char *g;
399
    output ( "#define CONS_%e( A, B, C )\\\n", nm ) ;
404
    output("#define CONS_%e(A, B, C)\\\n", nm);
400
    output ( "    {\\\n" ) ;
405
    output("    {\\\n");
401
    g = gen ( sz + 1, "list" ) ;
406
    g = gen(sz + 1, "list");
402
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
407
    output("\t%X *x%u_ = %e;\\\n", g);
403
    output ( "\tCOPY_%e ( x%u_ + 1, ( A ) ) ;\\\n", nm ) ;
408
    output("\tCOPY_%e(x%u_ + 1, (A));\\\n", nm);
404
    output ( "\tx%u_->ag_ptr = ( B ) ;\\\n" ) ;
409
    output("\tx%u_->ag_ptr = (B);\\\n");
405
    output ( "\t( C ) = x%u_ ;\\\n" ) ;
410
    output("\t(C) = x%u_;\\\n");
406
    output ( "    }\n\n" ) ;
411
    output("    }\n\n");
407
    unique++ ;
412
    unique++;
408
 
413
 
409
    /* UN_CONS routine */
414
    /* UN_CONS routine */
410
    output ( "#define UN_CONS_%e( A, B, C )\\\n", nm ) ;
415
    output("#define UN_CONS_%e(A, B, C)\\\n", nm);
411
    output ( "    {\\\n" ) ;
416
    output("    {\\\n");
412
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
417
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
413
    if ( d ) {
418
    if (d) {
414
	output ( "\t( A ) = DEREF_%e ( x%u_ + 1 ) ;\\\n", nm ) ;
419
	output("\t(A) = DEREF_%e(x%u_ + 1);\\\n", nm);
415
    } else {
420
    } else {
416
	output ( "\tDEREF_%e ( x%u_ + 1, ( A ) ) ;\\\n", nm ) ;
421
	output("\tDEREF_%e(x%u_ + 1, (A));\\\n", nm);
417
    }
422
    }
418
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
423
    output("\t(B) = x%u_->ag_ptr;\\\n");
419
    output ( "    }\n\n" ) ;
424
    output("    }\n\n");
420
    unique++ ;
425
    unique++;
421
 
426
 
422
    /* DESTROY_CONS routine */
427
    /* DESTROY_CONS routine */
423
    output ( "#define DESTROY_CONS_%e( D, A, B, C )\\\n", nm ) ;
428
    output("#define DESTROY_CONS_%e(D, A, B, C)\\\n", nm);
424
    output ( "    {\\\n" ) ;
429
    output("    {\\\n");
425
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
430
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
426
    if ( d ) {
431
    if (d) {
427
	output ( "\t( A ) = DEREF_%e ( x%u_ + 1 ) ;\\\n", nm ) ;
432
	output("\t(A) = DEREF_%e(x%u_ + 1);\\\n", nm);
428
    } else {
433
    } else {
429
	output ( "\tDEREF_%e ( x%u_ + 1, ( A ) ) ;\\\n", nm ) ;
434
	output("\tDEREF_%e(x%u_ + 1, (A));\\\n", nm);
430
    }
435
    }
431
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
436
    output("\t(B) = x%u_->ag_ptr;\\\n");
432
    output ( "\t( D ) ( x%u_, ( unsigned ) %d ) ;\\\n", sz + 1 ) ;
437
    output("\t(D)(x%u_, (unsigned)%d);\\\n", sz + 1);
433
    output ( "    }\n\n" ) ;
438
    output("    }\n\n");
434
    unique++ ;
439
    unique++;
435
 
440
 
436
    if ( allow_stack ) {
441
    if (allow_stack) {
437
	/* PUSH routine */
442
	/* PUSH routine */
438
	output ( "#define PUSH_%e( A, B )\\\n", nm ) ;
443
	output("#define PUSH_%e(A, B)\\\n", nm);
439
	output ( "    {\\\n" ) ;
444
	output("    {\\\n");
440
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
445
	output("\t%X **r%u_ = &(B);\\\n");
441
	g = gen ( sz + 1, "stack" ) ;
446
	g = gen(sz + 1, "stack");
442
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
447
	output("\t%X *x%u_ = %e;\\\n", g);
443
	output ( "\tCOPY_%e ( x%u_ + 1, ( A ) ) ;\\\n", nm ) ;
448
	output("\tCOPY_%e(x%u_ + 1, (A));\\\n", nm);
444
	output ( "\tx%u_->ag_ptr = *r%u_ ;\\\n" ) ;
449
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
445
	output ( "\t*r%u_ = x%u_ ;\\\n" ) ;
450
	output("\t*r%u_ = x%u_;\\\n");
446
	output ( "    }\n\n" ) ;
451
	output("    }\n\n");
447
	unique++ ;
452
	unique++;
448
 
453
 
449
	/* POP routine */
454
	/* POP routine */
450
	output ( "#define POP_%e( A, B )\\\n", nm ) ;
455
	output("#define POP_%e(A, B)\\\n", nm);
451
	output ( "    {\\\n" ) ;
456
	output("    {\\\n");
452
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
457
	output("\t%X **r%u_ = &(B);\\\n");
453
	output ( "\t%X *x%u_ = %s( *r%u_ ) ;\\\n", check_null ) ;
458
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
454
	if ( d ) {
459
	if (d) {
455
	    output ( "\t( A ) = DEREF_%e ( x%u_ + 1 ) ;\\\n", nm ) ;
460
	    output("\t(A) = DEREF_%e(x%u_ + 1);\\\n", nm);
456
	} else {
461
	} else {
457
	    output ( "\tDEREF_%e ( x%u_ + 1, ( A ) ) ;\\\n", nm ) ;
462
	    output("\tDEREF_%e(x%u_ + 1, (A));\\\n", nm);
458
	}
463
	}
459
	output ( "\t*r%u_ = x%u_->ag_ptr ;\\\n" ) ;
464
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
460
	output ( "\tdestroy_%X ( x%u_, ( unsigned ) %d ) ;\\\n", sz + 1 ) ;
465
	output("\tdestroy_%X(x%u_, (unsigned)%d);\\\n", sz + 1);
461
	output ( "    }\n\n" ) ;
466
	output("    }\n\n");
462
	unique++ ;
467
	unique++;
463
    }
468
    }
464
 
469
 
465
    /* End of routine */
470
    /* End of routine */
466
    output ( "\n" ) ;
471
    output("\n");
467
    return ;
472
    return;
468
}
473
}
469
 
474
 
470
 
475
 
471
/*
476
/*
472
    PRINT STRUCTURE DEFINITIONS
477
 * PRINT STRUCTURE DEFINITIONS
473
 
478
 *
474
    This routine prints all the structure declarations and definitions
479
 * This routine prints all the structure declarations and definitions
475
    and all identity declarations.  Some care needs to be taken with the
480
 * and all identity declarations.  Some care needs to be taken with the
476
    ordering of the structure definitions.  Cyclic structures will have
481
 * ordering of the structure definitions.  Cyclic structures will have
477
    already been detected, so there is no need to worry about them.
482
 * already been detected, so there is no need to worry about them.
478
*/
483
 */
479
 
484
 
-
 
485
void
480
void print_struct_defn
486
print_struct_defn(void)
481
    PROTO_Z ()
-
 
482
{
487
{
483
    int ok ;
488
    int ok;
484
    comment ( "Structure declarations" ) ;
489
    comment("Structure declarations");
485
    LOOP_STRUCTURE {
490
    LOOP_STRUCTURE {
486
	output ( "typedef struct %SM_tag %SN ;\n" ) ;
491
	output("typedef struct %SM_tag %SN;\n");
487
	COPY_int ( str_output ( CRT_STRUCTURE ), 0 ) ;
492
	COPY_int(str_output(CRT_STRUCTURE), 0);
488
    }
493
    }
489
    output ( "\n\n" ) ;
494
    output("\n\n");
490
 
495
 
491
    comment ( "Identity type definitions" ) ;
496
    comment("Identity type definitions");
492
    LOOP_IDENTITY output ( "typedef %IT %IN ;\n" ) ;
497
    LOOP_IDENTITY output("typedef %IT %IN;\n");
493
    output ( "\n\n" ) ;
498
    output("\n\n");
494
 
499
 
495
    comment ( "Structure definitions" ) ;
500
    comment("Structure definitions");
496
    output ( "#ifndef %X_STRUCT_DEFINED\n" ) ;
501
    output("#ifndef %X_STRUCT_DEFINED\n");
497
    output ( "#define %X_STRUCT_DEFINED\n\n" ) ;
502
    output("#define %X_STRUCT_DEFINED\n\n");
498
    do {
503
    do {
499
	ok = 1 ;
504
	ok = 1;
500
	LOOP_STRUCTURE {
505
	LOOP_STRUCTURE {
501
	    int pr = DEREF_int ( str_output ( CRT_STRUCTURE ) ) ;
506
	    int pr = DEREF_int(str_output(CRT_STRUCTURE));
502
	    if ( pr == 0 ) {
507
	    if (pr == 0) {
503
		/* Check if all components have been printed */
508
		/* Check if all components have been printed */
504
		pr = 1 ;
509
		pr = 1;
505
		LOOP_STRUCTURE_COMPONENT {
510
		LOOP_STRUCTURE_COMPONENT {
506
		    TYPE t0 ;
511
		    TYPE t0;
507
		    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
512
		    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
508
		    t0 = DEREF_type ( t ) ;
513
		    t0 = DEREF_type(t);
509
		    while ( IS_type_ident ( t0 ) ) {
514
		    while (IS_type_ident(t0)) {
510
			IDENTITY_P id ;
515
			IDENTITY_P id;
511
			id = DEREF_ptr ( type_ident_id ( t0 ) ) ;
516
			id = DEREF_ptr(type_ident_id(t0));
512
			t = DEREF_ptr ( ident_defn ( id ) ) ;
517
			t = DEREF_ptr(ident_defn(id));
513
			t0 = DEREF_type ( t ) ;
518
			t0 = DEREF_type(t);
514
		    }
519
		    }
515
		    if ( IS_type_structure ( t0 ) ) {
520
		    if (IS_type_structure(t0)) {
516
			STRUCTURE_P str ;
521
			STRUCTURE_P str;
517
			str = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
522
			str = DEREF_ptr(type_structure_struc(t0));
518
			pr = DEREF_int ( str_output ( str ) ) ;
523
			pr = DEREF_int(str_output(str));
519
			if ( pr == 0 ) break ;
524
			if (pr == 0) {
-
 
525
				break;
-
 
526
			}
520
		    }
527
		    }
521
		}
528
		}
522
		if ( pr ) {
529
		if (pr) {
523
		    /* Print structure definition */
530
		    /* Print structure definition */
524
		    output ( "struct %SM_tag {\n" ) ;
531
		    output("struct %SM_tag {\n");
525
		    LOOP_STRUCTURE_COMPONENT output ( "    %CT %CN ;\n" ) ;
532
		    LOOP_STRUCTURE_COMPONENT output("    %CT %CN;\n");
526
		    output ( "} ;\n\n" ) ;
533
		    output("};\n\n");
527
		    COPY_int ( str_output ( CRT_STRUCTURE ), 1 ) ;
534
		    COPY_int(str_output(CRT_STRUCTURE), 1);
528
		} else {
535
		} else {
529
		    /* Structure definition postponed */
536
		    /* Structure definition postponed */
530
		    output ( "/* struct %SM_tag later */\n\n" ) ;
537
		    output("/* struct %SM_tag later */\n\n");
531
		    ok = 0 ;
538
		    ok = 0;
532
		}
539
		}
533
	    }
540
	    }
534
	}
541
	}
535
    } while ( !ok ) ;
542
    } while (!ok);
536
    output ( "#endif /* %X_STRUCT_DEFINED */\n\n\n" ) ;
543
    output("#endif /* %X_STRUCT_DEFINED */\n\n\n");
537
    return ;
544
    return;
538
}
545
}
539
 
546
 
540
 
547
 
541
/*
548
/*
542
    PRINT BASIC TYPES (C VERSION)
549
 * PRINT BASIC TYPES (C VERSION)
-
 
550
 *
-
 
551
 * This routine prints the C versions of the basic type definitions.
-
 
552
 */
543
 
553
 
544
    This routine prints the C versions of the basic type definitions.
-
 
545
*/
-
 
546
 
-
 
547
static void print_types_c
554
static void
548
    PROTO_Z ()
555
print_types_c(void)
549
{
556
{
550
    int n ;
557
    int n;
551
    comment ( "Primitive types" ) ;
558
    comment("Primitive types");
552
    LOOP_PRIMITIVE {
559
    LOOP_PRIMITIVE {
553
	CLASS_ID_P c = DEREF_ptr ( prim_id ( CRT_PRIMITIVE ) ) ;
560
	CLASS_ID_P c = DEREF_ptr(prim_id(CRT_PRIMITIVE));
554
	char *pn = DEREF_string ( cid_name ( c ) ) ;
561
	char *pn = DEREF_string(cid_name(c));
555
	char *pd = DEREF_string ( prim_defn ( CRT_PRIMITIVE ) ) ;
562
	char *pd = DEREF_string(prim_defn(CRT_PRIMITIVE));
-
 
563
	if (!streq(pn, pd)) {
556
	if ( !streq ( pn, pd ) ) output ( "typedef %PD %PN ;\n" ) ;
564
		output("typedef %PD %PN;\n");
-
 
565
	}
-
 
566
    }
-
 
567
    output("\n\n");
-
 
568
 
-
 
569
    comment("Basic types");
-
 
570
    if (allow_vec) {
-
 
571
	    output("typedef unsigned %X_dim;\n\n");
-
 
572
    }
-
 
573
    output("typedef union %X_tag {\n");
-
 
574
    output("    unsigned ag_tag;\n");
-
 
575
    output("    union %X_tag *ag_ptr;\n");
-
 
576
    if (allow_vec) {
-
 
577
	    output("    %X_dim ag_dim;\n");
-
 
578
    }
-
 
579
    output("    unsigned ag_enum;\n");
-
 
580
    output("    unsigned long ag_long_enum;\n");
-
 
581
    LOOP_PRIMITIVE output("    %PN ag_prim_%PM;\n");
-
 
582
    output("} %X;\n\n");
-
 
583
    output("typedef %X *%X_PTR;\n\n");
-
 
584
 
-
 
585
    if (allow_vec) {
-
 
586
	output("typedef struct {\n");
-
 
587
	output("    %X *vec;\n");
-
 
588
	output("    %X *ptr;\n");
-
 
589
	output("} %X_VEC_PTR;\n\n");
-
 
590
 
-
 
591
	output("typedef struct {\n");
-
 
592
	output("    %X_dim dim;\n");
-
 
593
	output("    %X_VEC_PTR elems;\n");
-
 
594
	output("} %X_VEC;\n\n");
-
 
595
    }
-
 
596
 
-
 
597
    output("#ifndef %X_DESTR_DEFINED\n");
-
 
598
    output("#define %X_DESTR_DEFINED\n");
-
 
599
    output("typedef void (*DESTROYER)");
-
 
600
    output("(%X *, unsigned);\n");
-
 
601
    output("#endif\n\n");
-
 
602
 
-
 
603
    output("#define PTR(A)\t%X_PTR\n");
-
 
604
    output("#define LIST(A)\t%X_PTR\n");
-
 
605
    if (allow_stack) {
-
 
606
	output("#define STACK(A)\t%X_PTR\n");
-
 
607
    }
-
 
608
    if (allow_vec) {
-
 
609
	output("#define VEC(A)\t%X_VEC\n");
-
 
610
	output("#define VEC_PTR(A)\t%X_VEC_PTR\n");
557
    }
611
    }
558
    output ( "\n\n" ) ;
612
    output("#define SIZE(A)\tint\n\n\n");
559
 
613
 
560
    comment ( "Basic types" ) ;
-
 
561
    if ( allow_vec ) output ( "typedef unsigned %X_dim ;\n\n" ) ;
-
 
562
    output ( "typedef union %X_tag {\n" ) ;
-
 
563
    output ( "    unsigned ag_tag ;\n" ) ;
-
 
564
    output ( "    union %X_tag *ag_ptr ;\n" ) ;
-
 
565
    if ( allow_vec ) output ( "    %X_dim ag_dim ;\n" ) ;
-
 
566
    output ( "    unsigned ag_enum ;\n" ) ;
-
 
567
    output ( "    unsigned long ag_long_enum ;\n" ) ;
-
 
568
    LOOP_PRIMITIVE output ( "    %PN ag_prim_%PM ;\n" ) ;
-
 
569
    output ( "} %X ;\n\n" ) ;
-
 
570
    output ( "typedef %X *%X_PTR ;\n\n" ) ;
-
 
571
 
-
 
572
    if ( allow_vec ) {
-
 
573
	output ( "typedef struct {\n" ) ;
-
 
574
	output ( "    %X *vec ;\n" ) ;
-
 
575
	output ( "    %X *ptr ;\n" ) ;
-
 
576
	output ( "} %X_VEC_PTR ;\n\n" ) ;
-
 
577
 
-
 
578
	output ( "typedef struct {\n" ) ;
-
 
579
	output ( "    %X_dim dim ;\n" ) ;
-
 
580
	output ( "    %X_VEC_PTR elems ;\n" ) ;
-
 
581
	output ( "} %X_VEC ;\n\n" ) ;
-
 
582
    }
-
 
583
 
-
 
584
    output ( "#ifndef %X_DESTR_DEFINED\n" ) ;
-
 
585
    output ( "#define %X_DESTR_DEFINED\n" ) ;
-
 
586
    output ( "typedef void ( *DESTROYER ) " ) ;
-
 
587
    output ( "PROTO_S ( ( %X *, unsigned ) ) ;\n" ) ;
-
 
588
    output ( "#endif\n\n" ) ;
-
 
589
 
-
 
590
    output ( "#define PTR( A )\t%X_PTR\n" ) ;
-
 
591
    output ( "#define LIST( A )\t%X_PTR\n" ) ;
-
 
592
    if ( allow_stack ) {
-
 
593
	output ( "#define STACK( A )\t%X_PTR\n" ) ;
-
 
594
    }
-
 
595
    if ( allow_vec ) {
-
 
596
	output ( "#define VEC( A )\t%X_VEC\n" ) ;
-
 
597
	output ( "#define VEC_PTR( A )\t%X_VEC_PTR\n" ) ;
-
 
598
    }
-
 
599
    output ( "#define SIZE( A )\tint\n\n\n" ) ;
-
 
600
 
-
 
601
    if ( extra_asserts ) {
614
    if (extra_asserts) {
602
	comment ( "Assertion macros" ) ;
615
	comment("Assertion macros");
603
	print_assert_decs () ;
616
	print_assert_decs();
604
    }
617
    }
605
 
618
 
606
    comment ( "Enumeration definitions" ) ;
619
    comment("Enumeration definitions");
607
    LOOP_ENUM {
620
    LOOP_ENUM {
608
	number m = DEREF_number ( en_order ( CRT_ENUM ) ) ;
621
	number m = DEREF_number(en_order(CRT_ENUM));
609
	if ( m > ( number ) 0x10000 ) {
622
	if (m > (number)0x10000) {
610
	    output ( "typedef unsigned long %EN ;\n" ) ;
623
	    output("typedef unsigned long %EN;\n");
611
	} else {
624
	} else {
612
	    output ( "typedef unsigned %EN ;\n" ) ;
625
	    output("typedef unsigned %EN;\n");
613
	}
626
	}
614
    }
627
    }
615
    output ( "\n\n" ) ;
628
    output("\n\n");
616
 
629
 
617
    comment ( "Union type definitions" ) ;
630
    comment("Union type definitions");
618
    LOOP_UNION output ( "typedef %X *%UN ;\n" ) ;
631
    LOOP_UNION output("typedef %X *%UN;\n");
619
    output ( "\n\n" ) ;
632
    output("\n\n");
620
 
633
 
621
    print_struct_defn () ;
634
    print_struct_defn();
622
 
635
 
623
    comment ( "Function declarations" ) ;
636
    comment("Function declarations");
624
    output ( "extern %X *gen_%X PROTO_S ( ( unsigned ) ) ;\n" ) ;
637
    output("extern %X *gen_%X(unsigned);\n");
625
    output ( "extern void destroy_%X PROTO_S ( ( %X *, unsigned ) ) ;\n" ) ;
638
    output("extern void destroy_%X(%X *, unsigned);\n");
626
    output ( "extern void dummy_destroy_%X " ) ;
639
    output("extern void dummy_destroy_%X ");
627
    output ( "PROTO_S ( ( %X *, unsigned ) ) ;\n" ) ;
640
    output("(%X *, unsigned);\n");
628
    output ( "extern void destroy_%X_list " ) ;
641
    output("extern void destroy_%X_list ");
629
    output ( "PROTO_S ( ( %X *, unsigned ) ) ;\n" ) ;
642
    output("(%X *, unsigned);\n");
630
    output ( "extern %X *append_%X_list PROTO_S ( ( %X *, %X * ) ) ;\n" ) ;
643
    output("extern %X *append_%X_list(%X *, %X *);\n");
631
    output ( "extern %X *end_%X_list PROTO_S ( ( %X * ) ) ;\n" ) ;
644
    output("extern %X *end_%X_list(%X *);\n");
632
    output ( "extern unsigned length_%X_list PROTO_S ( ( %X * ) ) ;\n" ) ;
645
    output("extern unsigned length_%X_list(%X *);\n");
633
    output ( "extern %X *reverse_%X_list PROTO_S ( ( %X * ) ) ;\n" ) ;
646
    output("extern %X *reverse_%X_list(%X *);\n");
-
 
647
    if (allow_vec) {
634
    if ( allow_vec ) output ( "extern %X_VEC empty_%X_vec ;\n" ) ;
648
	    output("extern %X_VEC empty_%X_vec;\n");
-
 
649
    }
635
    output ( "#ifdef %X_IO_ROUTINES\n" ) ;
650
    output("#ifdef %X_IO_ROUTINES\n");
636
    output ( "extern unsigned crt_%X_alias ;\n" ) ;
651
    output("extern unsigned crt_%X_alias;\n");
637
    output ( "extern void set_%X_alias PROTO_S ( ( %X *, unsigned ) ) ;\n" ) ;
652
    output("extern void set_%X_alias(%X *, unsigned);\n");
638
    output ( "extern %X *find_%X_alias PROTO_S ( ( unsigned ) ) ;\n" ) ;
653
    output("extern %X *find_%X_alias(unsigned);\n");
639
    output ( "extern void clear_%X_alias PROTO_S ( ( void ) ) ;\n" ) ;
654
    output("extern void clear_%X_alias(void);\n");
640
    output ( "#endif\n" ) ;
655
    output("#endif\n");
641
    output ( "\n\n" ) ;
656
    output("\n\n");
642
    comment ( "Run-time type information" ) ;
657
    comment("Run-time type information");
643
    output ( "#ifndef GEN_%X\n" ) ;
658
    output("#ifndef GEN_%X\n");
644
    output ( "#define GEN_%X( A, B )%t40gen_%X ( ( unsigned ) ( A ) )\n" ) ;
659
    output("#define GEN_%X(A, B)%t40gen_%X((unsigned)(A))\n");
645
    output ( "#endif\n" ) ;
660
    output("#endif\n");
646
    output ( "#define TYPEID_ptr%t40( ( unsigned ) 0 )\n" ) ;
661
    output("#define TYPEID_ptr%t40((unsigned)0)\n");
647
    output ( "#define TYPEID_list%t40( ( unsigned ) 1 )\n" ) ;
662
    output("#define TYPEID_list%t40((unsigned)1)\n");
648
    output ( "#define TYPEID_stack%t40( ( unsigned ) 2 )\n" ) ;
663
    output("#define TYPEID_stack%t40((unsigned)2)\n");
649
    n = 3 ;
664
    n = 3;
650
    LOOP_UNION {
665
    LOOP_UNION {
651
	output ( "#define TYPEID_%UM%t40( ( unsigned ) %d )\n", n ) ;
666
	output("#define TYPEID_%UM%t40((unsigned)%d)\n", n);
652
	n++ ;
667
	n++;
653
    }
668
    }
654
    output ( "\n\n" ) ;
669
    output("\n\n");
655
    return ;
670
    return;
656
}
671
}
657
 
672
 
658
 
673
 
659
/*
674
/*
660
    PRINT POINTER CONSTRUCTS (C VERSION)
675
 * PRINT POINTER CONSTRUCTS (C VERSION)
-
 
676
 *
-
 
677
 * This routine prints the C versions of the pointer constructs.
-
 
678
 */
661
 
679
 
662
    This routine prints the C versions of the pointer constructs.
-
 
663
*/
-
 
664
 
-
 
665
static void print_ptr_c
680
static void
666
    PROTO_Z ()
681
print_ptr_c(void)
667
{
682
{
668
    /* Pointers */
683
    /* Pointers */
669
    char *g ;
684
    char *g;
670
    comment ( "Definitions for pointers" ) ;
685
    comment("Definitions for pointers");
671
    output ( "#define STEP_ptr( A, B )%t40" ) ;
686
    output("#define STEP_ptr(A, B)%t40");
672
    output ( "( %s( A ) + B )\n", check_null ) ;
687
    output("(%s(A) + B)\n", check_null);
673
    output ( "#define SIZE_ptr( A )%t40%d\n", SIZE_PTR ) ;
688
    output("#define SIZE_ptr(A)%t40%d\n", SIZE_PTR);
674
    output ( "#define NULL_ptr( A )%t40( ( %X * ) 0 )\n" ) ;
689
    output("#define NULL_ptr(A)%t40((%X *)0)\n");
675
    output ( "#define IS_NULL_ptr( A )%t40( ( A ) == 0 )\n" ) ;
690
    output("#define IS_NULL_ptr(A)%t40((A) == 0)\n");
676
    output ( "#define EQ_ptr( A, B )%t40( ( A ) == ( B ) )\n" ) ;
691
    output("#define EQ_ptr(A, B)%t40((A) == (B))\n");
677
    output ( "#define MAKE_ptr( A )%t40GEN_%X ( ( A ), TYPEID_ptr )\n" ) ;
692
    output("#define MAKE_ptr(A)%t40GEN_%X((A), TYPEID_ptr)\n");
678
    output ( "#define DESTROY_ptr( A, B )%t40" ) ;
693
    output("#define DESTROY_ptr(A, B)%t40");
679
    output ( "destroy_%X ( ( A ), ( unsigned ) ( B ) )\n" ) ;
694
    output("destroy_%X((A), (unsigned)(B))\n");
680
    g = gen ( 1, "ptr" ) ;
695
    g = gen(1, "ptr");
681
    output ( "#define UNIQ_ptr( A )%t40%e\n", g ) ;
696
    output("#define UNIQ_ptr(A)%t40%e\n", g);
682
    output ( "#define DESTROY_UNIQ_ptr( A )%t40" ) ;
697
    output("#define DESTROY_UNIQ_ptr(A)%t40");
683
    output ( "destroy_%X ( ( A ), ( unsigned ) 1 )\n" ) ;
698
    output("destroy_%X((A), (unsigned)1)\n");
684
    output ( "#ifdef %X_IO_ROUTINES\n" ) ;
699
    output("#ifdef %X_IO_ROUTINES\n");
685
    output ( "#define VOIDSTAR_ptr( A )%t40( ( void * ) ( A ) )\n" ) ;
700
    output("#define VOIDSTAR_ptr(A)%t40((void *)(A))\n");
686
    output ( "#endif\n\n" ) ;
701
    output("#endif\n\n");
687
 
702
 
688
    /* Assignment and dereference of pointers */
703
    /* Assignment and dereference of pointers */
689
    output ( "#define COPY_ptr( A, B )%t40" ) ;
704
    output("#define COPY_ptr(A, B)%t40");
690
    output ( "( %s( A )->ag_ptr = ( B ) )\n", check_null ) ;
705
    output("(%s(A)->ag_ptr = (B))\n", check_null);
691
    output ( "#define DEREF_ptr( A )%t40" ) ;
706
    output("#define DEREF_ptr(A)%t40");
692
    output ( "( %s( A )->ag_ptr )\n", check_null ) ;
707
    output("(%s(A)->ag_ptr)\n", check_null);
693
 
708
 
694
    /* Pointer list constructor */
709
    /* Pointer list constructor */
695
    output ( "#define CONS_ptr( A, B, C )\\\n" ) ;
710
    output("#define CONS_ptr(A, B, C)\\\n");
696
    output ( "    {\\\n" ) ;
711
    output("    {\\\n");
697
    g = gen ( SIZE_PTR + 1, "list" ) ;
712
    g = gen(SIZE_PTR + 1, "list");
698
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
713
    output("\t%X *x%u_ = %e;\\\n", g);
699
    output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
714
    output("\tx%u_[1].ag_ptr = (A);\\\n");
700
    output ( "\tx%u_->ag_ptr = ( B ) ;\\\n" ) ;
715
    output("\tx%u_->ag_ptr = (B);\\\n");
701
    output ( "\t( C ) = x%u_ ;\\\n" ) ;
716
    output("\t(C) = x%u_;\\\n");
702
    output ( "    }\n\n" ) ;
717
    output("    }\n\n");
703
    unique++ ;
718
    unique++;
704
 
719
 
705
    /* Pointer list deconstructor */
720
    /* Pointer list deconstructor */
706
    output ( "#define UN_CONS_ptr( A, B, C )\\\n" ) ;
721
    output("#define UN_CONS_ptr(A, B, C)\\\n");
707
    output ( "    {\\\n" ) ;
722
    output("    {\\\n");
708
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
723
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
709
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
724
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
710
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
725
    output("\t(B) = x%u_->ag_ptr;\\\n");
711
    output ( "    }\n\n" ) ;
726
    output("    }\n\n");
712
    unique++ ;
727
    unique++;
713
 
728
 
714
    /* Pointer list destructor */
729
    /* Pointer list destructor */
715
    output ( "#define DESTROY_CONS_ptr( D, A, B, C )\\\n" ) ;
730
    output("#define DESTROY_CONS_ptr(D, A, B, C)\\\n");
716
    output ( "    {\\\n" ) ;
731
    output("    {\\\n");
717
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
732
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
718
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
733
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
719
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
734
    output("\t(B) = x%u_->ag_ptr;\\\n");
720
    output ( "\t( D ) ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
735
    output("\t(D)(x%u_, (unsigned)2);\\\n");
721
    output ( "    }\n\n" ) ;
736
    output("    }\n\n");
722
    unique++ ;
737
    unique++;
723
 
738
 
724
    if ( allow_stack ) {
739
    if (allow_stack) {
725
	/* Pointer stack constructor */
740
	/* Pointer stack constructor */
726
	output ( "#define PUSH_ptr( A, B )\\\n" ) ;
741
	output("#define PUSH_ptr(A, B)\\\n");
727
	output ( "    {\\\n" ) ;
742
	output("    {\\\n");
728
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
743
	output("\t%X **r%u_ = &(B);\\\n");
729
	g = gen ( SIZE_PTR + 1, "stack" ) ;
744
	g = gen(SIZE_PTR + 1, "stack");
730
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
745
	output("\t%X *x%u_ = %e;\\\n", g);
731
	output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
746
	output("\tx%u_[1].ag_ptr = (A);\\\n");
732
	output ( "\tx%u_->ag_ptr = *r%u_ ;\\\n" ) ;
747
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
733
	output ( "\t*r%u_ = x%u_ ;\\\n" ) ;
748
	output("\t*r%u_ = x%u_;\\\n");
734
	output ( "    }\n\n" ) ;
749
	output("    }\n\n");
735
	unique++ ;
750
	unique++;
736
 
751
 
737
	/* Pointer stack destructor */
752
	/* Pointer stack destructor */
738
	output ( "#define POP_ptr( A, B )\\\n" ) ;
753
	output("#define POP_ptr(A, B)\\\n");
739
	output ( "    {\\\n" ) ;
754
	output("    {\\\n");
740
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
755
	output("\t%X **r%u_ = &(B);\\\n");
741
	output ( "\t%X *x%u_ = %s( *r%u_ ) ;\\\n", check_null ) ;
756
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
742
	output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
757
	output("\t(A) = x%u_[1].ag_ptr;\\\n");
743
	output ( "\t*r%u_ = x%u_->ag_ptr ;\\\n" ) ;
758
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
744
	output ( "\tdestroy_%X ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
759
	output("\tdestroy_%X(x%u_, (unsigned)2);\\\n");
745
	output ( "    }\n\n" ) ;
760
	output("    }\n\n");
746
	unique++ ;
761
	unique++;
747
    }
762
    }
748
 
763
 
749
    output ( "\n" ) ;
764
    output("\n");
750
    return ;
765
    return;
751
}
766
}
752
 
767
 
753
 
768
 
754
/*
769
/*
755
    PRINT LIST CONSTRUCTS (C VERSION)
770
 * PRINT LIST CONSTRUCTS (C VERSION)
756
 
771
 *
757
    This routine prints the C versions of the list constructs.
772
 * This routine prints the C versions of the list constructs.
758
*/
773
 */
759
 
774
 
760
static void print_list_c
775
static void
761
    PROTO_Z ()
776
print_list_c(void)
762
{
777
{
763
    /* Lists */
778
    /* Lists */
764
    char *g ;
779
    char *g;
765
    comment ( "Definitions for lists" ) ;
780
    comment("Definitions for lists");
766
    output ( "#define HEAD_list( A )%t40" ) ;
781
    output("#define HEAD_list(A)%t40");
767
    output ( "( %s( A ) + 1 )\n", check_null ) ;
782
    output("(%s(A) + 1)\n", check_null);
768
    output ( "#define PTR_TAIL_list( A )%t40" ) ;
783
    output("#define PTR_TAIL_list(A)%t40");
769
    output ( "( %s( A ) )\n", check_null ) ;
784
    output("(%s(A))\n", check_null);
770
    output ( "#define TAIL_list( A )%t40" ) ;
785
    output("#define TAIL_list(A)%t40");
771
    output ( "( %s( A )->ag_ptr )\n", check_null ) ;
786
    output("(%s(A)->ag_ptr)\n", check_null);
-
 
787
 
-
 
788
    output("#define LENGTH_list(A)%t40length_%X_list((A))\n");
-
 
789
    output("#define END_list(A)%t40end_%X_list((A))\n");
-
 
790
    output("#define REVERSE_list(A)%t40reverse_%X_list((A))\n");
-
 
791
    output("#define APPEND_list(A, B)%t40");
-
 
792
    output("append_%X_list((A), (B))\n\n");
-
 
793
    output("#define SIZE_list(A)%t40%d\n", SIZE_LIST);
-
 
794
    output("#define NULL_list(A)%t40((%X *) 0)\n");
-
 
795
    output("#define IS_NULL_list(A)%t40((A) == 0)\n");
-
 
796
    output("#define EQ_list(A, B)%t40((A) == (B))\n");
-
 
797
    g = gen(1, "list");
-
 
798
    output("#define UNIQ_list(A)%t40%e\n", g);
-
 
799
    output("#define DESTROY_UNIQ_list(A)%t40");
-
 
800
    output("destroy_%X((A), (unsigned)1)\n");
-
 
801
    output("#ifdef %X_IO_ROUTINES\n");
-
 
802
    output("#define VOIDSTAR_list(A)%t40((void *)(A))\n");
-
 
803
    output("#endif\n\n");
772
 
804
 
773
    output ( "#define LENGTH_list( A )%t40length_%X_list ( ( A ) )\n" ) ;
-
 
774
    output ( "#define END_list( A )%t40end_%X_list ( ( A ) )\n" ) ;
-
 
775
    output ( "#define REVERSE_list( A )%t40reverse_%X_list ( ( A ) )\n" ) ;
-
 
776
    output ( "#define APPEND_list( A, B )%t40" ) ;
-
 
777
    output ( "append_%X_list ( ( A ), ( B ) )\n\n" ) ;
-
 
778
    output ( "#define SIZE_list( A )%t40%d\n", SIZE_LIST ) ;
-
 
779
    output ( "#define NULL_list( A )%t40( ( %X * ) 0 )\n" ) ;
-
 
780
    output ( "#define IS_NULL_list( A )%t40( ( A ) == 0 )\n" ) ;
-
 
781
    output ( "#define EQ_list( A, B )%t40( ( A ) == ( B ) )\n" ) ;
-
 
782
    g = gen ( 1, "list" ) ;
-
 
783
    output ( "#define UNIQ_list( A )%t40%e\n", g ) ;
-
 
784
    output ( "#define DESTROY_UNIQ_list( A )%t40" ) ;
-
 
785
    output ( "destroy_%X ( ( A ), ( unsigned ) 1 )\n" ) ;
-
 
786
    output ( "#ifdef %X_IO_ROUTINES\n" ) ;
-
 
787
    output ( "#define VOIDSTAR_list( A )%t40( ( void * ) ( A ) )\n" ) ;
-
 
788
    output ( "#endif\n\n" ) ;
-
 
789
 
-
 
790
    /* Destruction of lists */
805
    /* Destruction of lists */
791
    output ( "#define DESTROY_list( A, B )\\\n" ) ;
806
    output("#define DESTROY_list(A, B)\\\n");
792
    output ( "    {\\\n" ) ;
807
    output("    {\\\n");
793
    output ( "\tdestroy_%X_list ( ( A ), ( unsigned ) ( B ) ) ;\\\n" ) ;
808
    output("\tdestroy_%X_list((A), (unsigned)(B));\\\n");
794
    output ( "    }\n\n" ) ;
809
    output("    }\n\n");
795
 
810
 
796
    /* Assignment and dereference of lists */
811
    /* Assignment and dereference of lists */
797
    output ( "#define COPY_list( A, B )%t40" ) ;
812
    output("#define COPY_list(A, B)%t40");
798
    output ( "( %s( A )->ag_ptr = ( B ) )\n", check_null ) ;
813
    output("(%s(A)->ag_ptr = (B))\n", check_null);
799
    output ( "#define DEREF_list( A )%t40" ) ;
814
    output("#define DEREF_list(A)%t40");
800
    output ( "( %s( A )->ag_ptr )\n", check_null ) ;
815
    output("(%s(A)->ag_ptr)\n", check_null);
801
 
816
 
802
    /* List list constructor */
817
    /* List list constructor */
803
    output ( "#define CONS_list( A, B, C )\\\n" ) ;
818
    output("#define CONS_list(A, B, C)\\\n");
804
    output ( "    {\\\n" ) ;
819
    output("    {\\\n");
805
    g = gen ( SIZE_LIST + 1, "list" ) ;
820
    g = gen(SIZE_LIST + 1, "list");
806
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
821
    output("\t%X *x%u_ = %e;\\\n", g);
807
    output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
822
    output("\tx%u_[1].ag_ptr = (A);\\\n");
808
    output ( "\tx%u_->ag_ptr = ( B ) ;\\\n" ) ;
823
    output("\tx%u_->ag_ptr = (B);\\\n");
809
    output ( "\t( C ) = x%u_ ;\\\n" ) ;
824
    output("\t(C) = x%u_;\\\n");
810
    output ( "    }\n\n" ) ;
825
    output("    }\n\n");
811
    unique++ ;
826
    unique++;
812
 
827
 
813
    /* List list deconstructor */
828
    /* List list deconstructor */
814
    output ( "#define UN_CONS_list( A, B, C )\\\n" ) ;
829
    output("#define UN_CONS_list(A, B, C)\\\n");
815
    output ( "    {\\\n" ) ;
830
    output("    {\\\n");
816
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
831
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
817
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
832
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
818
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
833
    output("\t(B) = x%u_->ag_ptr;\\\n");
819
    output ( "    }\n\n" ) ;
834
    output("    }\n\n");
820
    unique++ ;
835
    unique++;
821
 
836
 
822
    /* List list destructor */
837
    /* List list destructor */
823
    output ( "#define DESTROY_CONS_list( D, A, B, C )\\\n" ) ;
838
    output("#define DESTROY_CONS_list(D, A, B, C)\\\n");
824
    output ( "    {\\\n" ) ;
839
    output("    {\\\n");
825
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
840
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
826
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
841
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
827
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
842
    output("\t(B) = x%u_->ag_ptr;\\\n");
828
    output ( "\t( D ) ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
843
    output("\t(D)(x%u_, (unsigned)2);\\\n");
829
    output ( "    }\n\n" ) ;
844
    output("    }\n\n");
830
    unique++ ;
845
    unique++;
831
 
846
 
832
    if ( allow_stack ) {
847
    if (allow_stack) {
833
	/* List stack constructor */
848
	/* List stack constructor */
834
	output ( "#define PUSH_list( A, B )\\\n" ) ;
849
	output("#define PUSH_list(A, B)\\\n");
835
	output ( "    {\\\n" ) ;
850
	output("    {\\\n");
836
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
851
	output("\t%X **r%u_ = &(B);\\\n");
837
	g = gen ( SIZE_LIST + 1, "stack" ) ;
852
	g = gen(SIZE_LIST + 1, "stack");
838
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
853
	output("\t%X *x%u_ = %e;\\\n", g);
839
	output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
854
	output("\tx%u_[1].ag_ptr = (A);\\\n");
840
	output ( "\tx%u_->ag_ptr = *r%u_ ;\\\n" ) ;
855
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
841
	output ( "\t*r%u_ = x%u_ ;\\\n" ) ;
856
	output("\t*r%u_ = x%u_;\\\n");
842
	output ( "    }\n\n" ) ;
857
	output("    }\n\n");
843
	unique++ ;
858
	unique++;
844
 
859
 
845
	/* List stack destructor */
860
	/* List stack destructor */
846
	output ( "#define POP_list( A, B )\\\n" ) ;
861
	output("#define POP_list(A, B)\\\n");
847
	output ( "    {\\\n" ) ;
862
	output("    {\\\n");
848
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
863
	output("\t%X **r%u_ = &(B);\\\n");
849
	output ( "\t%X *x%u_ = %s( *r%u_ ) ;\\\n", check_null ) ;
864
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
850
	output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
865
	output("\t(A) = x%u_[1].ag_ptr;\\\n");
851
	output ( "\t*r%u_ = x%u_->ag_ptr ;\\\n" ) ;
866
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
852
	output ( "\tdestroy_%X ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
867
	output("\tdestroy_%X(x%u_, (unsigned)2);\\\n");
853
	output ( "    }\n\n" ) ;
868
	output("    }\n\n");
854
	unique++ ;
869
	unique++;
855
    }
870
    }
856
 
871
 
857
    output ( "\n" ) ;
872
    output("\n");
858
    return ;
873
    return;
859
}
874
}
860
 
875
 
861
 
876
 
862
/*
877
/*
863
    PRINT STACK CONSTRUCTS (C VERSION)
878
 * PRINT STACK CONSTRUCTS (C VERSION)
864
 
879
 *
865
    This routine prints the C versions of the stack constructs.
880
 * This routine prints the C versions of the stack constructs.
866
*/
881
 */
867
 
882
 
868
static void print_stack_c
883
static void
869
    PROTO_Z ()
884
print_stack_c(void)
870
{
885
{
871
    /* Stacks */
886
    /* Stacks */
872
    char *g ;
887
    char *g;
873
    comment ( "Definitions for stacks" ) ;
888
    comment("Definitions for stacks");
874
    output ( "#define SIZE_stack( A )%t40%d\n", SIZE_STACK ) ;
889
    output("#define SIZE_stack(A)%t40%d\n", SIZE_STACK);
875
    output ( "#define NULL_stack( A )%t40( ( %X * ) 0 )\n" ) ;
890
    output("#define NULL_stack(A)%t40((%X *) 0)\n");
876
    output ( "#define IS_NULL_stack( A )%t40( ( A ) == 0 )\n" ) ;
891
    output("#define IS_NULL_stack(A)%t40((A) == 0)\n");
877
    output ( "#define STACK_list( A )%t40( A )\n" ) ;
892
    output("#define STACK_list(A)%t40(A)\n");
878
    output ( "#define LIST_stack( A )%t40( A )\n\n" ) ;
893
    output("#define LIST_stack(A)%t40(A)\n\n");
879
 
894
 
880
    /* Assignment and dereference of stacks */
895
    /* Assignment and dereference of stacks */
881
    output ( "#define COPY_stack( A, B )%t40" ) ;
896
    output("#define COPY_stack(A, B)%t40");
882
    output ( "( %s( A )->ag_ptr = ( B ) )\n", check_null ) ;
897
    output("(%s(A)->ag_ptr = (B))\n", check_null);
883
    output ( "#define DEREF_stack( A )%t40" ) ;
898
    output("#define DEREF_stack(A)%t40");
884
    output ( "( %s( A )->ag_ptr )\n", check_null ) ;
899
    output("(%s(A)->ag_ptr)\n", check_null);
885
 
900
 
886
    /* Stack list constructor */
901
    /* Stack list constructor */
887
    output ( "#define CONS_stack( A, B, C )\\\n" ) ;
902
    output("#define CONS_stack(A, B, C)\\\n");
888
    output ( "    {\\\n" ) ;
903
    output("    {\\\n");
889
    g = gen ( SIZE_STACK + 1, "list" ) ;
904
    g = gen(SIZE_STACK + 1, "list");
890
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
905
    output("\t%X *x%u_ = %e;\\\n", g);
891
    output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
906
    output("\tx%u_[1].ag_ptr = (A);\\\n");
892
    output ( "\tx%u_->ag_ptr = ( B ) ;\\\n" ) ;
907
    output("\tx%u_->ag_ptr = (B);\\\n");
893
    output ( "\t( C ) = x%u_ ;\\\n" ) ;
908
    output("\t(C) = x%u_;\\\n");
894
    output ( "    }\n\n" ) ;
909
    output("    }\n\n");
895
    unique++ ;
910
    unique++;
896
 
911
 
897
    /* Stack list deconstructor */
912
    /* Stack list deconstructor */
898
    output ( "#define UN_CONS_stack( A, B, C )\\\n" ) ;
913
    output("#define UN_CONS_stack(A, B, C)\\\n");
899
    output ( "    {\\\n" ) ;
914
    output("    {\\\n");
900
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
915
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
901
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
916
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
902
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
917
    output("\t(B) = x%u_->ag_ptr;\\\n");
903
    output ( "    }\n\n" ) ;
918
    output("    }\n\n");
904
    unique++ ;
919
    unique++;
905
 
920
 
906
    /* Stack list destructor */
921
    /* Stack list destructor */
907
    output ( "#define DESTROY_CONS_stack( D, A, B, C )\\\n" ) ;
922
    output("#define DESTROY_CONS_stack(D, A, B, C)\\\n");
908
    output ( "    {\\\n" ) ;
923
    output("    {\\\n");
909
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
924
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
910
    output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
925
    output("\t(A) = x%u_[1].ag_ptr;\\\n");
911
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
926
    output("\t(B) = x%u_->ag_ptr;\\\n");
912
    output ( "\t( D ) ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
927
    output("\t(D)(x%u_, (unsigned)2);\\\n");
913
    output ( "    }\n\n" ) ;
928
    output("    }\n\n");
914
    unique++ ;
929
    unique++;
915
 
930
 
916
    if ( allow_stack ) {
931
    if (allow_stack) {
917
	/* Stack stack constructor */
932
	/* Stack stack constructor */
918
	output ( "#define PUSH_stack( A, B )\\\n" ) ;
933
	output("#define PUSH_stack(A, B)\\\n");
919
	output ( "    {\\\n" ) ;
934
	output("    {\\\n");
920
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
935
	output("\t%X **r%u_ = &(B);\\\n");
921
	g = gen ( SIZE_STACK + 1, "stack" ) ;
936
	g = gen(SIZE_STACK + 1, "stack");
922
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
937
	output("\t%X *x%u_ = %e;\\\n", g);
923
	output ( "\tx%u_ [1].ag_ptr = ( A ) ;\\\n" ) ;
938
	output("\tx%u_[1].ag_ptr = (A);\\\n");
924
	output ( "\tx%u_->ag_ptr = *r%u_ ;\\\n" ) ;
939
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
925
	output ( "\t*r%u_ = x%u_ ;\\\n" ) ;
940
	output("\t*r%u_ = x%u_;\\\n");
926
	output ( "    }\n\n" ) ;
941
	output("    }\n\n");
927
	unique++ ;
942
	unique++;
928
 
943
 
929
	/* Stack stack destructor */
944
	/* Stack stack destructor */
930
	output ( "#define POP_stack( A, B )\\\n" ) ;
945
	output("#define POP_stack(A, B)\\\n");
931
	output ( "    {\\\n" ) ;
946
	output("    {\\\n");
932
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
947
	output("\t%X **r%u_ = &(B);\\\n");
933
	output ( "\t%X *x%u_ = %s( *r%u_ ) ;\\\n", check_null ) ;
948
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
934
	output ( "\t( A ) = x%u_ [1].ag_ptr ;\\\n" ) ;
949
	output("\t(A) = x%u_[1].ag_ptr;\\\n");
935
	output ( "\t*r%u_ = x%u_->ag_ptr ;\\\n" ) ;
950
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
936
	output ( "\tdestroy_%X ( x%u_, ( unsigned ) 2 ) ;\\\n" ) ;
951
	output("\tdestroy_%X(x%u_, (unsigned)2);\\\n");
937
	output ( "    }\n\n" ) ;
952
	output("    }\n\n");
938
	unique++ ;
953
	unique++;
939
    }
954
    }
940
 
955
 
941
    output ( "\n" ) ;
956
    output("\n");
942
    return ;
957
    return;
943
}
958
}
944
 
959
 
945
 
960
 
946
/*
961
/*
947
    PRINT VECTOR CONSTRUCTS (C VERSION)
962
 * PRINT VECTOR CONSTRUCTS (C VERSION)
948
 
963
 *
949
    This routine prints the C versions of the vector constructs.
964
 * This routine prints the C versions of the vector constructs.
950
*/
965
 */
951
 
966
 
952
static void print_vec_c
967
static void
953
    PROTO_Z ()
968
print_vec_c(void)
954
{
969
{
955
    /* Vectors */
970
    /* Vectors */
956
    char *g ;
971
    char *g;
957
    comment ( "Definitions for vectors" ) ;
972
    comment("Definitions for vectors");
958
    output ( "#define DIM_vec( A )%t40( ( A ).dim )\n" ) ;
973
    output("#define DIM_vec(A)%t40((A).dim)\n");
959
    output ( "#define PTR_ptr_vec( A )%t40" ) ;
974
    output("#define PTR_ptr_vec(A)%t40");
960
    output ( "( %s( A ) [2].ag_ptr )\n", check_null ) ;
975
    output("(%s(A)[2].ag_ptr)\n", check_null);
961
    output ( "#define DIM_ptr_vec( A )%t40( ( A )->ag_dim )\n" ) ;
976
    output("#define DIM_ptr_vec(A)%t40((A)->ag_dim)\n");
962
    output ( "#define SIZE_vec( A )%t40%d\n", SIZE_VEC ) ;
977
    output("#define SIZE_vec(A)%t40%d\n", SIZE_VEC);
963
    output ( "#define NULL_vec( A )%t40empty_%X_vec\n\n" ) ;
978
    output("#define NULL_vec(A)%t40empty_%X_vec\n\n");
964
 
979
 
965
    /* Vector creation */
980
    /* Vector creation */
966
    output ( "#define MAKE_vec( SZ, U, RES )\\\n" ) ;
981
    output("#define MAKE_vec(SZ, U, RES)\\\n");
967
    output ( "    {\\\n" ) ;
982
    output("    {\\\n");
968
    output ( "\t%X_VEC x%u_ ;\\\n" ) ;
983
    output("\t%X_VEC x%u_;\\\n");
969
    output ( "\t%X_dim u%u_ = ( U ) ;\\\n" ) ;
984
    output("\t%X_dim u%u_ = (U);\\\n");
970
    output ( "\tx%u_.dim = u%u_ ;\\\n" ) ;
985
    output("\tx%u_.dim = u%u_;\\\n");
971
    output ( "\tif ( u%u_ == 0 ) u%u_ = 1 ;\\\n" ) ;
986
    output("\tif (u%u_ == 0) u%u_ = 1;\\\n");
972
    output ( "\tx%u_.elems.ptr = " ) ;
987
    output("\tx%u_.elems.ptr = ");
973
    output ( "GEN_%X ( ( SZ ) * u%u_, TYPEID_ptr ) ;\\\n" ) ;
988
    output("GEN_%X((SZ)*u%u_, TYPEID_ptr);\\\n");
974
    output ( "\tx%u_.elems.vec = x%u_.elems.ptr ;\\\n" ) ;
989
    output("\tx%u_.elems.vec = x%u_.elems.ptr;\\\n");
975
    output ( "\t( RES ) = x%u_ ;\\\n" ) ;
990
    output("\t(RES) = x%u_;\\\n");
976
    output ( "    }\n\n" ) ;
991
    output("    }\n\n");
977
    unique++ ;
992
    unique++;
978
 
993
 
979
    /* Vector destroyer */
994
    /* Vector destroyer */
980
    output ( "#define DESTROY_vec( V, SZ )\\\n" ) ;
995
    output("#define DESTROY_vec(V, SZ)\\\n");
981
    output ( "    {\\\n" ) ;
996
    output("    {\\\n");
982
    output ( "\t%X_VEC x%u_ ;\\\n" ) ;
997
    output("\t%X_VEC x%u_;\\\n");
983
    output ( "\tx%u_ = ( V ) ;\\\n" ) ;
998
    output("\tx%u_ = (V);\\\n");
984
    output ( "\tdestroy_%X ( x%u_.elems.ptr, " ) ;
999
    output("\tdestroy_%X (x%u_.elems.ptr, ");
985
    output ( "( unsigned ) ( ( SZ ) * x%u_.dim ) ) ;\\\n" ) ;
1000
    output("(unsigned)((SZ)*x%u_.dim));\\\n");
986
    output ( "    }\n\n" ) ;
1001
    output("    }\n\n");
987
    unique++ ;
1002
    unique++;
988
 
1003
 
989
    /* Vector trimmer */
1004
    /* Vector trimmer */
990
    output ( "#define TRIM_vec( V, SZ, L, U, RES )\\\n" ) ;
1005
    output("#define TRIM_vec(V, SZ, L, U, RES)\\\n");
991
    output ( "    {\\\n" ) ;
1006
    output("    {\\\n");
992
    output ( "\t%X_VEC x%u_ ;\\\n" ) ;
1007
    output("\t%X_VEC x%u_;\\\n");
993
    if ( extra_asserts ) {
1008
    if (extra_asserts) {
994
	output ( "\tint u%u_, l%u_ ;\\\n" ) ;
1009
	output("\tint u%u_, l%u_;\\\n");
995
	output ( "\tx%u_ = ( V ) ;\\\n" ) ;
1010
	output("\tx%u_ = (V);\\\n");
996
	output ( "\tu%u_ = CHECK_INT ( ( U ), DIM_vec ( x%u_ ) ) ;\\\n" ) ;
1011
	output("\tu%u_ = CHECK_INT ((U), DIM_vec(x%u_));\\\n");
997
	output ( "\tl%u_ = CHECK_INT ( ( L ), u%u_ ) ;\\\n" ) ;
1012
	output("\tl%u_ = CHECK_INT ((L), u%u_);\\\n");
998
	output ( "\tx%u_.elems.ptr += ( ( SZ ) * l%u_ ) ;\\\n" ) ;
1013
	output("\tx%u_.elems.ptr += ((SZ)*l%u_);\\\n");
999
	output ( "\tx%u_.dim = ( unsigned ) ( u%u_ - l%u_ ) ;\\\n" ) ;
1014
	output("\tx%u_.dim = (unsigned)(u%u_ - l%u_);\\\n");
1000
    } else {
1015
    } else {
1001
	output ( "\tint l%u_ = ( L ) ;\\\n" ) ;
1016
	output("\tint l%u_ = (L);\\\n");
1002
	output ( "\tx%u_ = ( V ) ;\\\n" ) ;
1017
	output("\tx%u_ = (V);\\\n");
1003
	output ( "\tx%u_.elems.ptr += ( ( SZ ) * l%u_ ) ;\\\n" ) ;
1018
	output("\tx%u_.elems.ptr += ((SZ)*l%u_);\\\n");
1004
	output ( "\tx%u_.dim = ( unsigned ) ( ( U ) - l%u_ ) ;\\\n" ) ;
1019
	output("\tx%u_.dim = (unsigned)((U) - l%u_);\\\n");
1005
    }
1020
    }
1006
    output ( "\t( RES ) = x%u_ ;\\\n" ) ;
1021
    output("\t(RES) = x%u_;\\\n");
1007
    output ( "    }\n\n" ) ;
1022
    output("    }\n\n");
1008
    unique++ ;
1023
    unique++;
1009
 
1024
 
1010
    /* Vector assignment */
1025
    /* Vector assignment */
1011
    output ( "#define COPY_vec( A, B )\\\n" ) ;
1026
    output("#define COPY_vec(A, B)\\\n");
1012
    output ( "    {\\\n" ) ;
1027
    output("    {\\\n");
1013
    output ( "\t%X *x%u_ = %s( A ) ;\\\n", check_null ) ;
1028
    output("\t%X *x%u_ = %s(A);\\\n", check_null);
1014
    output ( "\t%X_VEC y%u_ ;\\\n" ) ;
1029
    output("\t%X_VEC y%u_;\\\n");
1015
    output ( "\ty%u_ = ( B ) ;\\\n" ) ;
1030
    output("\ty%u_ = (B);\\\n");
1016
    output ( "\tx%u_ [0].ag_dim = y%u_.dim ;\\\n" ) ;
1031
    output("\tx%u_[0].ag_dim = y%u_.dim;\\\n");
1017
    output ( "\tx%u_ [1].ag_ptr = y%u_.elems.vec ;\\\n" ) ;
1032
    output("\tx%u_[1].ag_ptr = y%u_.elems.vec;\\\n");
1018
    output ( "\tx%u_ [2].ag_ptr = y%u_.elems.ptr ;\\\n" ) ;
1033
    output("\tx%u_[2].ag_ptr = y%u_.elems.ptr;\\\n");
1019
    output ( "    }\n\n" ) ;
1034
    output("    }\n\n");
1020
    unique++ ;
1035
    unique++;
1021
 
1036
 
1022
    /* Vector dereference */
1037
    /* Vector dereference */
1023
    output ( "#define DEREF_vec( A, B )\\\n" ) ;
1038
    output("#define DEREF_vec(A, B)\\\n");
1024
    output ( "    {\\\n" ) ;
1039
    output("    {\\\n");
1025
    output ( "\t%X *x%u_ = %s( A ) ;\\\n", check_null ) ;
1040
    output("\t%X *x%u_ = %s(A);\\\n", check_null);
1026
    output ( "\t%X_VEC *y%u_ = &( B ) ;\\\n" ) ;
1041
    output("\t%X_VEC *y%u_ = &(B);\\\n");
1027
    output ( "\ty%u_->dim = x%u_ [0].ag_dim ;\\\n" ) ;
1042
    output("\ty%u_->dim = x%u_[0].ag_dim;\\\n");
1028
    output ( "\ty%u_->elems.vec = x%u_ [1].ag_ptr ;\\\n" ) ;
1043
    output("\ty%u_->elems.vec = x%u_[1].ag_ptr;\\\n");
1029
    output ( "\ty%u_->elems.ptr = x%u_ [2].ag_ptr ;\\\n" ) ;
1044
    output("\ty%u_->elems.ptr = x%u_[2].ag_ptr;\\\n");
1030
    output ( "    }\n\n" ) ;
1045
    output("    }\n\n");
1031
    unique++ ;
1046
    unique++;
1032
 
1047
 
1033
    /* Vector list constructor */
1048
    /* Vector list constructor */
1034
    output ( "#define CONS_vec( A, B, C )\\\n" ) ;
1049
    output("#define CONS_vec(A, B, C)\\\n");
1035
    output ( "    {\\\n" ) ;
1050
    output("    {\\\n");
1036
    g = gen ( SIZE_VEC + 1, "list" ) ;
1051
    g = gen(SIZE_VEC + 1, "list");
1037
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
1052
    output("\t%X *x%u_ = %e;\\\n", g);
1038
    output ( "\t%X_VEC y%u_ ;\\\n" ) ;
1053
    output("\t%X_VEC y%u_;\\\n");
1039
    output ( "\ty%u_ = ( A ) ;\\\n" ) ;
1054
    output("\ty%u_ = (A);\\\n");
1040
    output ( "\tx%u_ [1].ag_dim = y%u_.dim ;\\\n" ) ;
1055
    output("\tx%u_[1].ag_dim = y%u_.dim;\\\n");
1041
    output ( "\tx%u_ [2].ag_ptr = y%u_.elems.vec ;\\\n" ) ;
1056
    output("\tx%u_[2].ag_ptr = y%u_.elems.vec;\\\n");
1042
    output ( "\tx%u_ [3].ag_ptr = y%u_.elems.ptr ;\\\n" ) ;
1057
    output("\tx%u_[3].ag_ptr = y%u_.elems.ptr;\\\n");
1043
    output ( "\tx%u_->ag_ptr = ( B ) ;\\\n" ) ;
1058
    output("\tx%u_->ag_ptr = (B);\\\n");
1044
    output ( "\t( C ) = x%u_ ;\\\n" ) ;
1059
    output("\t(C) = x%u_;\\\n");
1045
    output ( "    }\n\n" ) ;
1060
    output("    }\n\n");
1046
    unique++ ;
1061
    unique++;
1047
 
1062
 
1048
    /* Vector list deconstructor */
1063
    /* Vector list deconstructor */
1049
    output ( "#define UN_CONS_vec( A, B, C )\\\n" ) ;
1064
    output("#define UN_CONS_vec(A, B, C)\\\n");
1050
    output ( "    {\\\n" ) ;
1065
    output("    {\\\n");
1051
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
1066
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
1052
    output ( "\t%X_VEC *y%u_ = &( A ) ;\\\n" ) ;
1067
    output("\t%X_VEC *y%u_ = &(A);\\\n");
1053
    output ( "\ty%u_->dim = x%u_ [1].ag_dim ;\\\n" ) ;
1068
    output("\ty%u_->dim = x%u_[1].ag_dim;\\\n");
1054
    output ( "\ty%u_->elems.vec = x%u_ [2].ag_ptr ;\\\n" ) ;
1069
    output("\ty%u_->elems.vec = x%u_[2].ag_ptr;\\\n");
1055
    output ( "\ty%u_->elems.ptr = x%u_ [3].ag_ptr ;\\\n" ) ;
1070
    output("\ty%u_->elems.ptr = x%u_[3].ag_ptr;\\\n");
1056
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
1071
    output("\t(B) = x%u_->ag_ptr;\\\n");
1057
    output ( "    }\n\n" ) ;
1072
    output("    }\n\n");
1058
    unique++ ;
1073
    unique++;
1059
 
1074
 
1060
    /* Vector list destructor */
1075
    /* Vector list destructor */
1061
    output ( "#define DESTROY_CONS_vec( D, A, B, C )\\\n" ) ;
1076
    output("#define DESTROY_CONS_vec(D, A, B, C)\\\n");
1062
    output ( "    {\\\n" ) ;
1077
    output("    {\\\n");
1063
    output ( "\t%X *x%u_ = %s( C ) ;\\\n", check_null ) ;
1078
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
1064
    output ( "\t%X_VEC *y%u_ = &( A ) ;\\\n" ) ;
1079
    output("\t%X_VEC *y%u_ = &(A);\\\n");
1065
    output ( "\ty%u_->dim = x%u_ [1].ag_dim ;\\\n" ) ;
1080
    output("\ty%u_->dim = x%u_[1].ag_dim;\\\n");
1066
    output ( "\ty%u_->elems.vec = x%u_ [2].ag_ptr ;\\\n" ) ;
1081
    output("\ty%u_->elems.vec = x%u_[2].ag_ptr;\\\n");
1067
    output ( "\ty%u_->elems.ptr = x%u_ [3].ag_ptr ;\\\n" ) ;
1082
    output("\ty%u_->elems.ptr = x%u_[3].ag_ptr;\\\n");
1068
    output ( "\t( B ) = x%u_->ag_ptr ;\\\n" ) ;
1083
    output("\t(B) = x%u_->ag_ptr;\\\n");
1069
    output ( "\t( D ) ( x%u_, ( unsigned ) 4 ) ;\\\n" ) ;
1084
    output("\t(D)(x%u_, (unsigned)4);\\\n");
1070
    output ( "    }\n\n" ) ;
1085
    output("    }\n\n");
1071
    unique++ ;
1086
    unique++;
1072
 
1087
 
-
 
1088
    if (allow_stack) {
-
 
1089
	/* Vector stack constructor */
-
 
1090
	output("#define PUSH_vec(A, B)\\\n");
-
 
1091
	output("    {\\\n");
-
 
1092
	output("\t%X **r%u_ = &(B);\\\n");
-
 
1093
	g = gen(SIZE_VEC + 1, "stack");
-
 
1094
	output("\t%X *x%u_ = %e;\\\n", g);
-
 
1095
	output("\t%X_VEC y%u_;\\\n");
-
 
1096
	output("\ty%u_ = (A);\\\n");
-
 
1097
	output("\tx%u_[1].ag_dim = y%u_.dim;\\\n");
-
 
1098
	output("\tx%u_[2].ag_ptr = y%u_.elems.vec;\\\n");
-
 
1099
	output("\tx%u_[3].ag_ptr = y%u_.elems.ptr;\\\n");
-
 
1100
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
-
 
1101
	output("\t*r%u_ = x%u_;\\\n");
-
 
1102
	output("    }\n\n");
-
 
1103
	unique++;
-
 
1104
 
-
 
1105
	/* Vector stack destructor */
-
 
1106
	output("#define POP_vec(A, B)\\\n");
-
 
1107
	output("    {\\\n");
-
 
1108
	output("\t%X **r%u_ = &(B);\\\n");
-
 
1109
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
-
 
1110
	output("\t%X_VEC *y%u_ = &(A);\\\n");
-
 
1111
	output("\ty%u_->dim = x%u_[1].ag_dim;\\\n");
-
 
1112
	output("\ty%u_->elems.vec = x%u_[2].ag_ptr;\\\n");
-
 
1113
	output("\ty%u_->elems.ptr = x%u_[3].ag_ptr;\\\n");
-
 
1114
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
-
 
1115
	output("\tdestroy_%X(x%u_, (unsigned)4);\\\n");
-
 
1116
	output("    }\n\n");
-
 
1117
	unique++;
-
 
1118
    }
-
 
1119
 
-
 
1120
    output("\n");
-
 
1121
    return;
-
 
1122
}
-
 
1123
 
-
 
1124
 
-
 
1125
/*
-
 
1126
 * PRINT VECTOR POINTER CONSTRUCTS (C VERSION)
-
 
1127
 *
-
 
1128
 * This routine prints the C versions of the vector pointer constructs.
-
 
1129
 */
-
 
1130
 
-
 
1131
static void
-
 
1132
print_vec_ptr_c(void)
-
 
1133
{
-
 
1134
    /* Vector pointers */
-
 
1135
    char *g;
-
 
1136
    comment("Definitions for vector pointers");
-
 
1137
    output("#define VEC_PTR_vec(A)%t40((A).elems)\n");
-
 
1138
    output("#define PTR_vec_ptr(A)%t40((A).ptr)\n");
-
 
1139
    output("#define SIZE_vec_ptr(A)%t40%d\n\n", SIZE_VEC_PTR);
-
 
1140
 
-
 
1141
    /* Vector pointer assignment */
-
 
1142
    output("#define COPY_vec_ptr(A, B)\\\n");
-
 
1143
    output("    {\\\n");
-
 
1144
    output("\t%X *x%u_ = %s(A);\\\n", check_null);
-
 
1145
    output("\t%X_VEC_PTR y%u_;\\\n");
-
 
1146
    output("\ty%u_ = (B);\\\n");
-
 
1147
    output("\tx%u_->ag_ptr = y%u_.vec;\\\n");
-
 
1148
    output("\tx%u_[1].ag_ptr = y%u_.ptr;\\\n");
-
 
1149
    output("    }\n\n");
-
 
1150
    unique++;
-
 
1151
 
-
 
1152
    /* Vector pointer dereference */
-
 
1153
    output("#define DEREF_vec_ptr(A, B)\\\n");
-
 
1154
    output("    {\\\n");
-
 
1155
    output("\t%X *x%u_ = %s(A);\\\n", check_null);
-
 
1156
    output("\t%X_VEC_PTR *y%u_ = &(B);\\\n");
-
 
1157
    output("\ty%u_->vec = x%u_->ag_ptr;\\\n");
-
 
1158
    output("\ty%u_->ptr = x%u_[1].ag_ptr;\\\n");
-
 
1159
    output("    }\n\n");
-
 
1160
    unique++;
-
 
1161
 
-
 
1162
    /* Vector pointer list constructor */
-
 
1163
    output("#define CONS_vec_ptr(A, B, C)\\\n");
-
 
1164
    output("    {\\\n");
-
 
1165
    g = gen(SIZE_VEC_PTR + 1, "list");
-
 
1166
    output("\t%X *x%u_ = %e;\\\n", g);
-
 
1167
    output("\t%X_VEC_PTR y%u_;\\\n");
-
 
1168
    output("\ty%u_ = (A);\\\n");
-
 
1169
    output("\tx%u_[1].ag_ptr = y%u_.vec;\\\n");
-
 
1170
    output("\tx%u_[2].ag_ptr = y%u_.ptr;\\\n");
-
 
1171
    output("\tx%u_->ag_ptr = (B);\\\n");
-
 
1172
    output("\t(C) = x%u_;\\\n");
-
 
1173
    output("    }\n\n");
-
 
1174
    unique++;
-
 
1175
 
-
 
1176
    /* Vector pointer list deconstructor */
-
 
1177
    output("#define UN_CONS_vec_ptr(A, B, C)\\\n");
-
 
1178
    output("    {\\\n");
-
 
1179
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
-
 
1180
    output("\t%X_VEC_PTR *y%u_ = &(A);\\\n");
-
 
1181
    output("\ty%u_->vec = x%u_[1].ag_ptr;\\\n");
-
 
1182
    output("\ty%u_->ptr = x%u_[2].ag_ptr;\\\n");
-
 
1183
    output("\t(B) = x%u_->ag_ptr;\\\n");
-
 
1184
    output("    }\n\n");
-
 
1185
    unique++;
-
 
1186
 
-
 
1187
    /* Vector pointer list destructor */
-
 
1188
    output("#define DESTROY_CONS_vec_ptr(D, A, B, C)\\\n");
-
 
1189
    output("    {\\\n");
-
 
1190
    output("\t%X *x%u_ = %s(C);\\\n", check_null);
-
 
1191
    output("\t%X_VEC_PTR *y%u_ = &(A);\\\n");
-
 
1192
    output("\ty%u_->vec = x%u_[1].ag_ptr;\\\n");
-
 
1193
    output("\ty%u_->ptr = x%u_[2].ag_ptr;\\\n");
-
 
1194
    output("\t(B) = x%u_->ag_ptr;\\\n");
-
 
1195
    output("\t(D)(x%u_, (unsigned)3);\\\n");
-
 
1196
    output("    }\n\n");
-
 
1197
    unique++;
-
 
1198
 
1073
    if ( allow_stack ) {
1199
    if (allow_stack) {
1074
	/* Vector stack constructor */
1200
	/* Vector stack constructor */
1075
	output ( "#define PUSH_vec( A, B )\\\n" ) ;
1201
	output("#define PUSH_vec_ptr(A, B)\\\n");
1076
	output ( "    {\\\n" ) ;
1202
	output("    {\\\n");
1077
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
1203
	output("\t%X **r%u_ = &(B);\\\n");
1078
	g = gen ( SIZE_VEC + 1, "stack" ) ;
1204
	g = gen(SIZE_VEC_PTR + 1, "stack");
1079
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
1205
	output("\t%X *x%u_ = %e;\\\n", g);
1080
	output ( "\t%X_VEC y%u_ ;\\\n" ) ;
1206
	output("\t%X_VEC_PTR y%u_;\\\n");
1081
	output ( "\ty%u_ = ( A ) ;\\\n" ) ;
1207
	output("\ty%u_ = (A);\\\n");
1082
	output ( "\tx%u_ [1].ag_dim = y%u_.dim ;\\\n" ) ;
1208
	output("\tx%u_[1].ag_ptr = y%u_.vec;\\\n");
1083
	output ( "\tx%u_ [2].ag_ptr = y%u_.elems.vec ;\\\n" ) ;
-
 
1084
	output ( "\tx%u_ [3].ag_ptr = y%u_.elems.ptr ;\\\n" ) ;
1209
	output("\tx%u_[2].ag_ptr = y%u_.ptr;\\\n");
1085
	output ( "\tx%u_->ag_ptr = *r%u_ ;\\\n" ) ;
1210
	output("\tx%u_->ag_ptr = *r%u_;\\\n");
1086
	output ( "\t*r%u_ = x%u_ ;\\\n" ) ;
1211
	output("\t*r%u_ = x%u_;\\\n");
1087
	output ( "    }\n\n" ) ;
1212
	output("    }\n\n");
1088
	unique++ ;
1213
	unique++;
1089
 
1214
 
1090
	/* Vector stack destructor */
1215
	/* Vector stack destructor */
1091
	output ( "#define POP_vec( A, B )\\\n" ) ;
1216
	output("#define POP_vec_ptr(A, B)\\\n");
1092
	output ( "    {\\\n" ) ;
1217
	output("    {\\\n");
1093
	output ( "\t%X **r%u_ = &( B ) ;\\\n" ) ;
1218
	output("\t%X **r%u_ = &(B);\\\n");
1094
	output ( "\t%X *x%u_ = %s( *r%u_ ) ;\\\n", check_null ) ;
1219
	output("\t%X *x%u_ = %s(*r%u_);\\\n", check_null);
1095
	output ( "\t%X_VEC *y%u_ = &( A ) ;\\\n" ) ;
1220
	output("\t%X_VEC *y%u_ = &(A);\\\n");
1096
	output ( "\ty%u_->dim = x%u_ [1].ag_dim ;\\\n" ) ;
1221
	output("\ty%u_->vec = x%u_[1].ag_ptr;\\\n");
1097
	output ( "\ty%u_->elems.vec = x%u_ [2].ag_ptr ;\\\n" ) ;
-
 
1098
	output ( "\ty%u_->elems.ptr = x%u_ [3].ag_ptr ;\\\n" ) ;
1222
	output("\ty%u_->ptr = x%u_[2].ag_ptr;\\\n");
1099
	output ( "\t*r%u_ = x%u_->ag_ptr ;\\\n" ) ;
1223
	output("\t*r%u_ = x%u_->ag_ptr;\\\n");
1100
	output ( "\tdestroy_%X ( x%u_, ( unsigned ) 4 ) ;\\\n" ) ;
1224
	output("\tdestroy_%X(x%u_, (unsigned)3);\\\n");
1101
	output ( "    }\n\n" ) ;
1225
	output("    }\n\n");
1102
	unique++ ;
1226
	unique++;
1103
    }
1227
    }
1104
 
1228
 
1105
    output ( "\n" ) ;
1229
    output("\n");
1106
    return ;
1230
    return;
1107
}
1231
}
1108
 
1232
 
-
 
1233
 
-
 
1234
/*
-
 
1235
 * PRINT SIZE CONSTRUCTS (C VERSION)
-
 
1236
 *
-
 
1237
 * This routine prints the C versions of the size constructs.
-
 
1238
 */
-
 
1239
 
-
 
1240
static void
-
 
1241
print_size_c(void)
-
 
1242
{
-
 
1243
    comment("Definitions for sizes");
-
 
1244
    output("#define SCALE(A, B)%t40((A)*(int)(B))\n\n\n");
-
 
1245
    return;
-
 
1246
}
-
 
1247
 
-
 
1248
 
-
 
1249
/*
-
 
1250
 * PRINT PRIMITIVE CONSTRUCTS (C VERSION)
-
 
1251
 *
-
 
1252
 * This routine prints the C versions of the primitive constructs.
-
 
1253
 */
-
 
1254
 
-
 
1255
static void
-
 
1256
print_prim_c(void)
-
 
1257
{
-
 
1258
    comment("Definitions for primitive %PN");
-
 
1259
    output("#define SIZE_%PM%t40%d\n\n", SIZE_PRIM);
-
 
1260
    output("#define COPY_%PM(A, B)%t40");
-
 
1261
    output("(%s(A)->ag_prim_%PM = (B))\n", check_null);
-
 
1262
    output("#define DEREF_%PM(A)%t40");
-
 
1263
    output("(%s(A)->ag_prim_%PM)\n", check_null);
-
 
1264
    print_simple_cons("%PM", SIZE_PRIM, 1);
-
 
1265
    return;
-
 
1266
}
-
 
1267
 
-
 
1268
 
-
 
1269
/*
-
 
1270
 * PRINT ENUMERATION CONSTANTS
-
 
1271
 *
-
 
1272
 * This routine prints the definitions of the enumeration constants.
-
 
1273
 */
-
 
1274
 
-
 
1275
void
-
 
1276
print_enum_consts(void)
-
 
1277
{
-
 
1278
    number n = DEREF_number(en_order(CRT_ENUM));
-
 
1279
    if (n > (number)0x10000) {
-
 
1280
	output("#ifdef __STDC__\n");
-
 
1281
	LOOP_ENUM_CONST output("#define %EM_%ES%t40((%EN) %EVUL)\n");
-
 
1282
	output("#define ORDER_%EM%t40(%EOUL)\n");
-
 
1283
	output("#else\n");
-
 
1284
    }
-
 
1285
    LOOP_ENUM_CONST output("#define %EM_%ES%t40((%EN) %EV)\n");
-
 
1286
    output("#define ORDER_%EM%t40((unsigned long) %EO)\n");
-
 
1287
    if (n > (number)0x10000) {
-
 
1288
	output("#endif\n");
-
 
1289
    }
-
 
1290
    return;
-
 
1291
}
-
 
1292
 
1109
 
1293
 
1110
/*
1294
/*
1111
    PRINT VECTOR POINTER CONSTRUCTS (C VERSION)
1295
 * PRINT ENUMERATION CONSTRUCTS (C VERSION)
-
 
1296
 *
-
 
1297
 * This routine prints the C versions of the enumeration constructs.
-
 
1298
 */
-
 
1299
 
-
 
1300
static void
-
 
1301
print_enum_c(void)
-
 
1302
{
-
 
1303
    char *fld = "ag_enum";
-
 
1304
    number n = DEREF_number(en_order(CRT_ENUM));
-
 
1305
    if (n > (number)0x10000) {
-
 
1306
	    fld = "ag_long_enum";
-
 
1307
    }
-
 
1308
    comment("Definitions for enumeration %EN");
-
 
1309
    print_enum_consts();
-
 
1310
    output("#define SIZE_%EM%t40%d\n\n", SIZE_ENUM);
-
 
1311
    output("#define COPY_%EM(A, B)%t40");
-
 
1312
    output("(%s(A)->%s = (B))\n", check_null, fld);
-
 
1313
    output("#define DEREF_%EM(A)%t40");
-
 
1314
    output("(%s(A)->%s)\n", check_null, fld);
-
 
1315
    if (DEREF_int(en_lists(CRT_ENUM))) {
-
 
1316
	print_simple_cons("%EM", SIZE_ENUM, 1);
-
 
1317
    } else {
-
 
1318
	output("\n\n");
-
 
1319
    }
-
 
1320
    return;
-
 
1321
}
-
 
1322
 
1112
 
1323
 
-
 
1324
/*
-
 
1325
 * PRINT STRUCTURE CONSTRUCTS (C VERSION)
-
 
1326
 *
1113
    This routine prints the C versions of the vector pointer constructs.
1327
 * This routine prints the C versions of the structure constructs.
1114
*/
1328
 */
1115
 
1329
 
1116
static void print_vec_ptr_c
1330
static void
1117
    PROTO_Z ()
1331
print_struct_c(void)
1118
{
1332
{
1460
 
1481
 
1461
 
1482
 
1462
/*
1483
/*
1463
    PRINT ARGUMENTS FOR A UNION CONSTRUCTOR
1484
 * PRINT ARGUMENTS FOR A UNION CONSTRUCTOR
-
 
1485
 *
-
 
1486
 * This routine prints the list of arguments for a union constructor and
-
 
1487
 * similar functions.
-
 
1488
 */
1464
 
1489
 
1465
    This routine prints the list of arguments for a union constructor and
-
 
1466
    similar functions.
-
 
1467
*/
-
 
1468
 
-
 
1469
static void print_cons_args
1490
static void
1470
    PROTO_N ( ( d, suff ) )
-
 
1471
    PROTO_T ( int d X char *suff )
1491
print_cons_args(int d, char *suff)
1472
{
1492
{
1473
    LOOP_UNION_COMPONENT {
1493
    LOOP_UNION_COMPONENT {
1474
	string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
1494
	string v = DEREF_string(cmp_value(CRT_COMPONENT));
1475
	if ( v == NULL || d == 0 ) output ( "%CN%s, ", suff ) ;
1495
	if (v == NULL || d == 0) {
-
 
1496
		output("%CN%s, ", suff);
-
 
1497
	}
1476
    }
1498
    }
1477
    LOOP_FIELD_COMPONENT {
1499
    LOOP_FIELD_COMPONENT {
1478
	string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
1500
	string v = DEREF_string(cmp_value(CRT_COMPONENT));
1479
	if ( v == NULL || d == 0 ) output ( "%CN%s, ", suff ) ;
1501
	if (v == NULL || d == 0) {
-
 
1502
		output("%CN%s, ", suff);
-
 
1503
	}
1480
    }
1504
    }
1481
    output ( "%X_%UM" ) ;
1505
    output("%X_%UM");
1482
    return ;
1506
    return;
1483
}
1507
}
1484
 
1508
 
1485
 
1509
 
1486
/*
1510
/*
1487
    DOES THE CURRENT FIELD HAVE ANY COMPONENTS?
1511
 * DOES THE CURRENT FIELD HAVE ANY COMPONENTS?
1488
 
1512
 *
1489
    This routine returns 1 if the current field of the current union has
1513
 * This routine returns 1 if the current field of the current union has
1490
    a component, and 0 otherwise.
1514
 * a component, and 0 otherwise.
1491
*/
1515
 */
1492
 
1516
 
-
 
1517
int
1493
int field_not_empty
1518
field_not_empty(void)
1494
    PROTO_Z ()
-
 
1495
{
1519
{
1496
    LIST ( COMPONENT_P ) c ;
1520
    LIST(COMPONENT_P)c;
1497
    c = DEREF_list ( un_s_defn ( CRT_UNION ) ) ;
1521
    c = DEREF_list(un_s_defn(CRT_UNION));
1498
    if ( !IS_NULL_list ( c ) ) return ( 1 ) ;
1522
    if (!IS_NULL_list(c)) {
-
 
1523
	    return(1);
-
 
1524
    }
1499
    c = DEREF_list ( fld_defn ( CRT_FIELD ) ) ;
1525
    c = DEREF_list(fld_defn(CRT_FIELD));
1500
    if ( !IS_NULL_list ( c ) ) return ( 1 ) ;
1526
    if (!IS_NULL_list(c)) {
-
 
1527
	    return(1);
-
 
1528
    }
1501
    return ( 0 ) ;
1529
    return(0);
1502
}
1530
}
1503
 
1531
 
1504
 
1532
 
1505
/*
1533
/*
1506
    PRINT FIELD SELECTOR OPERATIONS
1534
 * PRINT FIELD SELECTOR OPERATIONS
1507
 
1535
 *
1508
    This routine prints the operations on field selectors (C version).
1536
 * This routine prints the operations on field selectors (C version).
1509
    sz gives the size of the common union components.  tag is the field
1537
 * sz gives the size of the common union components.  tag is the field
1510
    tag number (or -1 for untagged unions).  rng gives the number of
1538
 * tag number (or -1 for untagged unions).  rng gives the number of
1511
    elements in the field set (if appropriate).  al is true if the
1539
 * elements in the field set (if appropriate).  al is true if the
1512
    field is aliased.
1540
 * field is aliased.
1513
*/
1541
 */
1514
 
1542
 
1515
static void print_field_c
1543
static void
1516
    PROTO_N ( ( sz, tag, rng, al ) )
-
 
1517
    PROTO_T ( int sz X int tag X int rng X int al )
1544
print_field_c(int sz, int tag, int rng, int al)
1518
{
1545
{
1519
    char *g ;
1546
    char *g;
1520
    int posn = 0 ;
1547
    int posn = 0;
1521
    char *f = ( rng ? "%FN_etc" : "%FN" ) ;
1548
    char *f = (rng ? "%FN_etc" : "%FN");
1522
 
1549
 
1523
    LOOP_FIELD_COMPONENT {
1550
    LOOP_FIELD_COMPONENT {
1524
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
1551
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
1525
	output ( "#define %UM_%e_%CN( P )%t40", f ) ;
1552
	output("#define %UM_%e_%CN(P)%t40", f);
1526
	if ( extra_asserts && tag != -1 ) {
1553
	if (extra_asserts && tag != -1) {
1527
	    if ( rng ) {
1554
	    if (rng) {
1528
		output ( "( CHECK_TAG_ETC ( ( P ), %d, %d ) + %d )\n",
1555
		output("(CHECK_TAG_ETC((P), %d, %d) + %d)\n",
1529
			 tag, tag + rng, sz ) ;
1556
			 tag, tag + rng, sz);
1530
	    } else {
1557
	    } else {
1531
		output ( "( CHECK_TAG ( ( P ), %d ) + %d )\n", tag, sz ) ;
1558
		output("(CHECK_TAG((P), %d) + %d)\n", tag, sz);
1532
	    }
1559
	    }
1533
	} else {
1560
	} else {
1534
	    output ( "( ( P ) + %d )\n", sz ) ;
1561
	    output("((P) + %d)\n", sz);
1535
	}
1562
	}
1536
	sz += size_type ( ct, 0 ) ;
1563
	sz += size_type(ct, 0);
1537
    }
1564
    }
1538
 
1565
 
1539
    /* Component constructor */
1566
    /* Component constructor */
1540
    output ( "\n#define MAKE_%UM_%e( ", f ) ;
1567
    output("\n#define MAKE_%UM_%e(", f);
1541
    if ( rng ) output ( "tag, " ) ;
-
 
1542
    print_cons_args ( 1, "_" ) ;
-
 
1543
    output ( " )\\\n" ) ;
-
 
1544
    output ( "    {\\\n" ) ;
-
 
1545
    g = gen ( sz + al, "%UM" ) ;
-
 
1546
    output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
-
 
1547
    if ( tag != -1 ) {
-
 
1548
	if ( rng ) {
1568
    if (rng) {
1549
	    output ( "\tx%u_->ag_tag = ( tag ) ;\\\n" ) ;
-
 
1550
	} else {
-
 
1551
	    output ( "\tx%u_->ag_tag = %d ;\\\n", tag ) ;
1569
	    output("tag, ");
1552
	}
-
 
1553
	posn = 1 ;
-
 
1554
    }
-
 
1555
    LOOP_UNION_COMPONENT {
-
 
1556
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
-
 
1557
	string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
-
 
1558
	if ( v == NULL ) v = "( %CN_ )" ;
-
 
1559
	posn = assign_component ( ct, posn, v, 0 ) ;
-
 
1560
    }
-
 
1561
    LOOP_FIELD_COMPONENT {
-
 
1562
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
-
 
1563
	string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
-
 
1564
	if ( v == NULL ) v = "( %CN_ )" ;
-
 
1565
	posn = assign_component ( ct, posn, v, 0 ) ;
-
 
1566
    }
1570
    }
-
 
1571
    print_cons_args(1, "_");
-
 
1572
    output(")\\\n");
-
 
1573
    output("    {\\\n");
-
 
1574
    g = gen(sz + al, "%UM");
-
 
1575
    output("\t%X *x%u_ = %e;\\\n", g);
-
 
1576
    if (tag != -1) {
-
 
1577
	if (rng) {
-
 
1578
	    output("\tx%u_->ag_tag = (tag);\\\n");
-
 
1579
	} else {
-
 
1580
	    output("\tx%u_->ag_tag = %d;\\\n", tag);
-
 
1581
	}
-
 
1582
	posn = 1;
-
 
1583
    }
-
 
1584
    LOOP_UNION_COMPONENT {
-
 
1585
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
-
 
1586
	string v = DEREF_string(cmp_value(CRT_COMPONENT));
-
 
1587
	if (v == NULL) {
-
 
1588
		v = "(%CN_)";
-
 
1589
	}
-
 
1590
	posn = assign_component(ct, posn, v, 0);
-
 
1591
    }
-
 
1592
    LOOP_FIELD_COMPONENT {
-
 
1593
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
-
 
1594
	string v = DEREF_string(cmp_value(CRT_COMPONENT));
-
 
1595
	if (v == NULL) {
-
 
1596
		v = "(%CN_)";
-
 
1597
	}
-
 
1598
	posn = assign_component(ct, posn, v, 0);
-
 
1599
    }
-
 
1600
    if (al) {
1567
    if ( al ) output ( "\tx%u_ [%d].ag_tag = 0 ;\\\n", sz ) ;
1601
	    output("\tx%u_[%d].ag_tag = 0;\\\n", sz);
-
 
1602
    }
1568
    if ( rng && extra_asserts ) {
1603
    if (rng && extra_asserts) {
1569
	output ( "\t( %X_%UM ) = CHECK_TAG_ETC ( x%u_, %d, %d ) ;\\\n",
1604
	output("\t(%X_%UM) = CHECK_TAG_ETC(x%u_, %d, %d);\\\n",
1570
		 tag, tag + rng ) ;
1605
		 tag, tag + rng);
1571
    } else {
1606
    } else {
1572
	output ( "\t( %X_%UM ) = x%u_ ;\\\n" ) ;
1607
	output("\t(%X_%UM) = x%u_;\\\n");
1573
    }
1608
    }
1574
    output ( "    }\n\n" ) ;
1609
    output("    }\n\n");
1575
    unique++ ;
1610
    unique++;
1576
 
1611
 
1577
    /* Tag modifier */
1612
    /* Tag modifier */
1578
    if ( rng ) {
1613
    if (rng) {
1579
	output ( "#define MODIFY_%UM_%e( tag, %X_%UM )\\\n", f ) ;
1614
	output("#define MODIFY_%UM_%e(tag, %X_%UM)\\\n", f);
1580
	output ( "    {\\\n" ) ;
1615
	output("    {\\\n");
1581
	if ( extra_asserts ) {
1616
	if (extra_asserts) {
1582
	    output ( "\t%X *x%u_ = CHECK_TAG_ETC" ) ;
1617
	    output("\t%X *x%u_ = CHECK_TAG_ETC");
1583
	    output ( " ( ( %X_%UM ), %d, %d ) ;\\\n", tag, tag + rng ) ;
1618
	    output(" ((%X_%UM), %d, %d);\\\n", tag, tag + rng);
1584
	    output ( "\tx%u_->ag_tag = ( tag ) ;\\\n" ) ;
1619
	    output("\tx%u_->ag_tag = (tag);\\\n");
1585
	    output ( "\t( void ) CHECK_TAG_ETC" ) ;
1620
	    output("\t(void) CHECK_TAG_ETC");
1586
	    output ( " ( x%u_, %d, %d ) ;\\\n", tag, tag + rng ) ;
1621
	    output(" (x%u_, %d, %d);\\\n", tag, tag + rng);
1587
	} else {
1622
	} else {
1588
	    output ( "\t( %X_%UM )->ag_tag = ( tag ) ;\\\n" ) ;
1623
	    output("\t(%X_%UM)->ag_tag = (tag);\\\n");
1589
	}
1624
	}
1590
	output ( "    }\n\n" ) ;
1625
	output("    }\n\n");
1591
	unique++ ;
1626
	unique++;
1592
    }
1627
    }
1593
 
1628
 
1594
    /* Component deconstructor */
1629
    /* Component deconstructor */
1595
    if ( field_not_empty () ) {
1630
    if (field_not_empty()) {
1596
	output ( "#define DECONS_%UM_%e( ", f ) ;
1631
	output("#define DECONS_%UM_%e(", f);
1597
	print_cons_args ( 0, "_" ) ;
1632
	print_cons_args(0, "_");
1598
	output ( " )\\\n" ) ;
1633
	output(")\\\n");
1599
	output ( "    {\\\n" ) ;
1634
	output("    {\\\n");
1600
	output ( "\t%X *x%u_ = " ) ;
1635
	output("\t%X *x%u_ = ");
1601
	if ( tag != -1 ) {
1636
	if (tag != -1) {
1602
	    if ( extra_asserts ) {
1637
	    if (extra_asserts) {
1603
		if ( rng ) {
1638
		if (rng) {
1604
		    output ( "CHECK_TAG_ETC ( ( %X_%UM ), %d, %d ) ;\\\n",
1639
		    output("CHECK_TAG_ETC((%X_%UM), %d, %d);\\\n",
1605
			      tag, tag + rng ) ;
1640
			      tag, tag + rng);
1606
		} else {
1641
		} else {
1607
		    output ( "CHECK_TAG ( ( %X_%UM ), %d ) ;\\\n", tag ) ;
1642
		    output("CHECK_TAG((%X_%UM), %d);\\\n", tag);
1608
		}
1643
		}
1609
	    } else {
1644
	    } else {
1610
		output ( "( %X_%UM ) ;\\\n" ) ;
1645
		output("(%X_%UM);\\\n");
1611
	    }
1646
	    }
1612
	    posn = 1 ;
1647
	    posn = 1;
1613
	} else {
1648
	} else {
1614
	    output ( "( %X_%UM ) ;\\\n" ) ;
1649
	    output("(%X_%UM);\\\n");
1615
	    posn = 0 ;
1650
	    posn = 0;
1616
	}
1651
	}
1617
	LOOP_UNION_COMPONENT {
1652
	LOOP_UNION_COMPONENT {
1618
	    TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
1653
	    TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
1619
	    posn = deref_component ( ct, posn, "( %CN_ )", 0 ) ;
1654
	    posn = deref_component(ct, posn, "(%CN_)", 0);
1620
	}
1655
	}
1621
	LOOP_FIELD_COMPONENT {
1656
	LOOP_FIELD_COMPONENT {
1622
	    TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
1657
	    TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
1623
	    posn = deref_component ( ct, posn, "( %CN_ )", 0 ) ;
1658
	    posn = deref_component(ct, posn, "(%CN_)", 0);
1624
	}
1659
	}
1625
	output ( "    }\n\n" ) ;
1660
	output("    }\n\n");
1626
	unique++ ;
1661
	unique++;
1627
    }
1662
    }
1628
 
1663
 
1629
    /* Component destructor */
1664
    /* Component destructor */
1630
    output ( "#define DESTROY_%UM_%e( destroyer_, ", f ) ;
1665
    output("#define DESTROY_%UM_%e(destroyer_, ", f);
1631
    print_cons_args ( 0, "_" ) ;
1666
    print_cons_args(0, "_");
1632
    output ( " )\\\n" ) ;
1667
    output(")\\\n");
1633
    output ( "    {\\\n" ) ;
1668
    output("    {\\\n");
1634
    output ( "\t%X *x%u_ = " ) ;
1669
    output("\t%X *x%u_ = ");
1635
    if ( tag != -1 ) {
1670
    if (tag != -1) {
1636
	if ( extra_asserts ) {
1671
	if (extra_asserts) {
1637
	    if ( rng ) {
1672
	    if (rng) {
1638
		output ( "CHECK_TAG_ETC ( ( %X_%UM ), %d, %d ) ;\\\n",
1673
		output("CHECK_TAG_ETC((%X_%UM), %d, %d);\\\n",
1639
			 tag, tag + rng ) ;
1674
			 tag, tag + rng);
1640
	    } else {
1675
	    } else {
1641
		output ( "CHECK_TAG ( ( %X_%UM ), %d ) ;\\\n", tag ) ;
1676
		output("CHECK_TAG((%X_%UM), %d);\\\n", tag);
1642
	    }
1677
	    }
1643
	} else {
1678
	} else {
1644
	    output ( "( %X_%UM ) ;\\\n" ) ;
1679
	    output("(%X_%UM);\\\n");
1645
	}
1680
	}
1646
	posn = 1 ;
1681
	posn = 1;
1647
    } else {
1682
    } else {
1648
	output ( "( %X_%UM ) ;\\\n" ) ;
1683
	output("(%X_%UM);\\\n");
1649
	posn = 0 ;
1684
	posn = 0;
1650
    }
1685
    }
1651
    LOOP_UNION_COMPONENT {
1686
    LOOP_UNION_COMPONENT {
1652
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
1687
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
-
 
1688
	posn = deref_component(ct, posn, "(%CN_)", 0);
-
 
1689
    }
-
 
1690
    LOOP_FIELD_COMPONENT {
-
 
1691
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
1653
	posn = deref_component ( ct, posn, "( %CN_ )", 0 ) ;
1692
	posn = deref_component(ct, posn, "(%CN_)", 0);
-
 
1693
    }
-
 
1694
    output("\t(destroyer_)(x%u_, (unsigned)%d);\\\n", sz + al);
-
 
1695
    output("    }\n\n");
-
 
1696
    unique++;
-
 
1697
 
-
 
1698
    /* Aliasing commands */
-
 
1699
    if (al && !rng) {
-
 
1700
	output("#ifdef %X_IO_ROUTINES\n\n");
-
 
1701
	output("#define NEW_ALIAS_%UM_%FN(P, N)\\\n");
-
 
1702
	output("    {\\\n");
-
 
1703
	g = gen(sz + al, "list");
-
 
1704
	output("\t%X *x%u_ = %e;\\\n", g);
-
 
1705
	output("\tunsigned a%u_ = (N);\\\n");
-
 
1706
	if (tag != -1) {
-
 
1707
		output("\tx%u_->ag_tag = %d;\\\n", tag);
-
 
1708
	}
-
 
1709
	output("\tx%u_[%d].ag_tag = a%u_;\\\n", sz);
-
 
1710
	output("\tset_%X_alias(x%u_ + %d, a%u_);\\\n", sz);
-
 
1711
	output("\t(P) = x%u_;\\\n");
-
 
1712
	output("    }\n\n");
-
 
1713
	unique++;
-
 
1714
 
-
 
1715
	output("#define GET_ALIAS_%UM_%FN(P)%t40");
-
 
1716
	output("((%s(P) + %d)->ag_tag)\n", check_null, sz);
-
 
1717
	output("#define SET_ALIAS_%UM_%FN(P, N)%t40");
-
 
1718
	output("set_%X_alias(%s(P) + %d, (N))\n", check_null, sz);
-
 
1719
	output("#define FIND_ALIAS_%UM_%FN(N)%t40");
-
 
1720
	output("(find_%X_alias(N) - %d)\n\n", sz);
-
 
1721
	output("#endif\n\n");
-
 
1722
    }
-
 
1723
    output("\n");
-
 
1724
    return;
-
 
1725
}
-
 
1726
 
-
 
1727
 
-
 
1728
/*
-
 
1729
 * PRINT DECLARATION FOR A UNION MAP TABLE
-
 
1730
 *
-
 
1731
 * This routine prints the type of the current map table.
-
 
1732
 */
-
 
1733
 
-
 
1734
static void
-
 
1735
print_map_table(int d)
-
 
1736
{
-
 
1737
    output("%MR (*%MN_%UM_table[ORDER_%UM])");
-
 
1738
    if (map_proto) {
-
 
1739
	output("\n    (%UN");
-
 
1740
	if (d) {
-
 
1741
		output(", DESTROYER");
-
 
1742
	}
-
 
1743
	LOOP_MAP_ARGUMENT output(", %AT");
-
 
1744
	output(")");
-
 
1745
    } else {
-
 
1746
	output(" ()");
-
 
1747
    }
-
 
1748
    return;
-
 
1749
}
-
 
1750
 
-
 
1751
 
-
 
1752
/*
-
 
1753
 * PRINT ARGUMENTS FOR A UNION MAP
-
 
1754
 *
-
 
1755
 * This routine prints the list of arguments for the current map.  The
-
 
1756
 * argument d, if present, gives the destructor argument.
-
 
1757
 */
-
 
1758
 
-
 
1759
void
-
 
1760
print_map_args(char *d)
-
 
1761
{
-
 
1762
    output("(%X_%UM");
-
 
1763
    if (d) {
-
 
1764
	    output(", %e", d);
-
 
1765
    }
-
 
1766
    LOOP_MAP_ARGUMENT output(", %AN");
-
 
1767
    output(")");
-
 
1768
    return;
-
 
1769
}
-
 
1770
 
-
 
1771
 
-
 
1772
/*
-
 
1773
 * PRINT THE UNION OPERATIONS OUTPUT FILE
-
 
1774
 *
-
 
1775
 * For each union in the calculus there is an operations file.
-
 
1776
 */
-
 
1777
 
-
 
1778
static void
-
 
1779
print_union_ops_c(char *dir, char *un)
-
 
1780
{
-
 
1781
    int sz = 1;
-
 
1782
    int tag = 0;
-
 
1783
    int is_tagged = 1;
-
 
1784
    open_file(dir, un, OPS_SUFFIX);
-
 
1785
    if (extra_headers) {
-
 
1786
	output("#include \"%s%s\"\n", MAIN_PREFIX, MAIN_SUFFIX);
-
 
1787
	output("#include <%s_ops.h>\n\n", MAIN_PREFIX);
1654
    }
1788
    }
1655
    LOOP_FIELD_COMPONENT {
-
 
1656
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
-
 
1657
	posn = deref_component ( ct, posn, "( %CN_ )", 0 ) ;
-
 
1658
    }
-
 
1659
    output ( "\t( destroyer_ ) ( x%u_, ( unsigned ) %d ) ;\\\n", sz + al ) ;
-
 
1660
    output ( "    }\n\n" ) ;
-
 
1661
    unique++ ;
-
 
1662
 
1789
 
1663
    /* Aliasing commands */
1790
    /* Check for unions with one field */
1664
    if ( al && !rng ) {
1791
    LOOP_UNION_FIELD tag++;
1665
	output ( "#ifdef %X_IO_ROUTINES\n\n" ) ;
-
 
1666
	output ( "#define NEW_ALIAS_%UM_%FN( P, N )\\\n" ) ;
-
 
1667
	output ( "    {\\\n" ) ;
1792
    if (tag < 2) {
1668
	g = gen ( sz + al, "list" ) ;
1793
	sz = 0;
1669
	output ( "\t%X *x%u_ = %e ;\\\n", g ) ;
-
 
1670
	output ( "\tunsigned a%u_ = ( N ) ;\\\n" ) ;
-
 
1671
	if ( tag != -1 ) output ( "\tx%u_->ag_tag = %d ;\\\n", tag ) ;
-
 
1672
	output ( "\tx%u_ [%d].ag_tag = a%u_ ;\\\n", sz ) ;
-
 
1673
	output ( "\tset_%X_alias ( x%u_ + %d, a%u_ ) ;\\\n", sz ) ;
-
 
1674
	output ( "\t( P ) = x%u_ ;\\\n" ) ;
-
 
1675
	output ( "    }\n\n" ) ;
1794
	is_tagged = 0;
1676
	unique++ ;
1795
    }
1677
 
1796
 
1678
	output ( "#define GET_ALIAS_%UM_%FN( P )%t40" ) ;
-
 
1679
	output ( "( ( %s( P ) + %d )->ag_tag )\n", check_null, sz ) ;
-
 
1680
	output ( "#define SET_ALIAS_%UM_%FN( P, N )%t40" ) ;
-
 
1681
	output ( "set_%X_alias ( %s( P ) + %d, ( N ) )\n", check_null, sz ) ;
-
 
1682
	output ( "#define FIND_ALIAS_%UM_%FN( N )%t40" ) ;
-
 
1683
	output ( "( find_%X_alias ( N ) - %d )\n\n", sz ) ;
-
 
1684
	output ( "#endif\n\n" ) ;
-
 
1685
    }
-
 
1686
    output ( "\n" ) ;
-
 
1687
    return ;
-
 
1688
}
-
 
1689
 
-
 
1690
 
-
 
1691
/*
-
 
1692
    PRINT DECLARATION FOR A UNION MAP TABLE
-
 
1693
 
-
 
1694
    This routine prints the type of the current map table.
-
 
1695
*/
-
 
1696
 
-
 
1697
static void print_map_table
-
 
1698
    PROTO_N ( ( d ) )
-
 
1699
    PROTO_T ( int d )
-
 
1700
{
-
 
1701
    output ( "%MR ( *%MN_%UM_table [ ORDER_%UM ] )" ) ;
-
 
1702
    if ( map_proto ) {
-
 
1703
	output ( "\n    PROTO_S ( ( %UN" ) ;
-
 
1704
	if ( d ) output ( ", DESTROYER" ) ;
-
 
1705
	LOOP_MAP_ARGUMENT output ( ", %AT" ) ;
-
 
1706
	output ( " ) )" ) ;
-
 
1707
    } else {
-
 
1708
	output ( " ()" ) ;
-
 
1709
    }
-
 
1710
    return ;
-
 
1711
}
-
 
1712
 
-
 
1713
 
-
 
1714
/*
-
 
1715
    PRINT ARGUMENTS FOR A UNION MAP
-
 
1716
 
-
 
1717
    This routine prints the list of arguments for the current map.  The
-
 
1718
    argument d, if present, gives the destructor argument.
-
 
1719
*/
-
 
1720
 
-
 
1721
void print_map_args
-
 
1722
    PROTO_N ( ( d ) )
-
 
1723
    PROTO_T ( char *d )
-
 
1724
{
-
 
1725
    output ( "( %X_%UM" ) ;
-
 
1726
    if ( d ) output ( ", %e", d ) ;
-
 
1727
    LOOP_MAP_ARGUMENT output ( ", %AN" ) ;
-
 
1728
    output ( " )" ) ;
-
 
1729
    return ;
-
 
1730
}
-
 
1731
 
-
 
1732
 
-
 
1733
/*
-
 
1734
    PRINT THE UNION OPERATIONS OUTPUT FILE
-
 
1735
 
-
 
1736
    For each union in the calculus there is an operations file.
-
 
1737
*/
-
 
1738
 
-
 
1739
void print_union_ops_c
-
 
1740
    PROTO_N ( ( dir, un ) )
-
 
1741
    PROTO_T ( char *dir X char *un )
-
 
1742
{
-
 
1743
    int sz = 1 ;
-
 
1744
    int tag = 0 ;
-
 
1745
    int is_tagged = 1 ;
-
 
1746
    open_file ( dir, un, OPS_SUFFIX ) ;
-
 
1747
    if ( extra_headers ) {
-
 
1748
	output ( "#include \"%s%s\"\n", MAIN_PREFIX, MAIN_SUFFIX ) ;
-
 
1749
	output ( "#include <%s_ops.h>\n\n", MAIN_PREFIX ) ;
-
 
1750
    }
-
 
1751
 
-
 
1752
    /* Check for unions with one field */
-
 
1753
    LOOP_UNION_FIELD tag++ ;
-
 
1754
    if ( tag < 2 ) {
-
 
1755
	sz = 0 ;
-
 
1756
	is_tagged = 0 ;
-
 
1757
    }
-
 
1758
 
-
 
1759
    comment ( "Operations for union %UN" ) ;
1797
    comment("Operations for union %UN");
1760
    output ( "#define TAG_%UM( P )%t40", check_null ) ;
1798
    output("#define TAG_%UM(P)%t40", check_null);
1761
    if ( is_tagged ) {
1799
    if (is_tagged) {
1762
	output ( "( %s( P )->ag_tag )\n\n\n", check_null ) ;
1800
	output("(%s(P)->ag_tag)\n\n\n", check_null);
1763
    } else {
1801
    } else {
1764
	output ( "( ( unsigned ) 0 )\n\n\n" ) ;
1802
	output("((unsigned) 0)\n\n\n");
1765
    }
1803
    }
1766
 
1804
 
1767
    /* Operations on common components */
1805
    /* Operations on common components */
1768
    LOOP_UNION_COMPONENT {
1806
    LOOP_UNION_COMPONENT {
1769
	TYPE_P ct = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
1807
	TYPE_P ct = DEREF_ptr(cmp_type(CRT_COMPONENT));
1770
	comment ( "Operations for component %CN of union %UN" ) ;
1808
	comment("Operations for component %CN of union %UN");
1771
	output ( "#define %UM_%CN( P )%t40" ) ;
1809
	output("#define %UM_%CN(P)%t40");
1772
	output ( "( %s( P ) + %d )\n\n\n", check_null, sz ) ;
1810
	output("(%s(P) + %d)\n\n\n", check_null, sz);
1773
	sz += size_type ( ct, 0 ) ;
1811
	sz += size_type(ct, 0);
1774
    }
1812
    }
1775
 
1813
 
1776
    /* Operations on field components */
1814
    /* Operations on field components */
1777
    tag = 0 ;
1815
    tag = 0;
1778
    LOOP_UNION_FIELD {
1816
    LOOP_UNION_FIELD {
1779
	int rng = DEREF_int ( fld_set ( CRT_FIELD ) ) ;
1817
	int rng = DEREF_int(fld_set(CRT_FIELD));
1780
	int hash = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
1818
	int hash = DEREF_int(fld_flag(CRT_FIELD));
1781
	int al = ( hash ? 1 : 0 ) ;
1819
	int al = (hash ? 1 : 0);
1782
 
1820
 
1783
	if ( rng ) {
1821
	if (rng) {
1784
	    comment ( "Operations for field set %FN_etc of union %UN" ) ;
1822
	    comment("Operations for field set %FN_etc of union %UN");
1785
	    output ( "#define %UM_%FN_etc_tag%t40( ( unsigned ) %d )\n",
1823
	    output("#define %UM_%FN_etc_tag%t40((unsigned)%d)\n",
1786
		     tag + rng ) ;
1824
		     tag + rng);
1787
	    output ( "#define IS_%UM_%FN_etc( P )%t40" ) ;
1825
	    output("#define IS_%UM_%FN_etc(P)%t40");
1788
	    output ( "( ( unsigned ) ( %s( P )->ag_tag - %d )",
1826
	    output("((unsigned)(%s(P)->ag_tag - %d)",
1789
		     check_null, tag ) ;
1827
		     check_null, tag);
1790
	    output ( " < ( unsigned ) %d )\n\n", rng ) ;
1828
	    output(" < (unsigned)%d)\n\n", rng);
1791
	    print_field_c ( sz, tag, rng, al ) ;
1829
	    print_field_c(sz, tag, rng, al);
1792
	}
1830
	}
1793
   
1831
 
1794
	comment ( "Operations for field %FN of union %UN" ) ;
1832
	comment("Operations for field %FN of union %UN");
1795
	output ( "#define %UM_%FN_tag%t40( ( unsigned ) %d )\n", tag ) ;
1833
	output("#define %UM_%FN_tag%t40((unsigned)%d)\n", tag);
1796
	output ( "#define IS_%UM_%FN( P )%t40" ) ;
1834
	output("#define IS_%UM_%FN(P)%t40");
1797
	if ( is_tagged ) {
1835
	if (is_tagged) {
1798
	    output ( "( %s( P )->ag_tag == %d )\n\n", check_null, tag ) ;
1836
	    output("(%s(P)->ag_tag == %d)\n\n", check_null, tag);
1799
	    print_field_c ( sz, tag, 0, al ) ;
1837
	    print_field_c(sz, tag, 0, al);
1800
	} else {
1838
	} else {
1801
	    output ( "1\n\n" ) ;
1839
	    output("1\n\n");
1802
	    print_field_c ( sz, -1, 0, al ) ;
1840
	    print_field_c(sz, -1, 0, al);
1803
	}
1841
	}
1804
	ASSERT ( DEREF_int ( fld_tag ( CRT_FIELD ) ) == tag ) ;
1842
	ASSERT(DEREF_int(fld_tag(CRT_FIELD)) == tag);
1805
	tag++ ;
1843
	tag++;
1806
    }
1844
    }
1807
 
1845
 
1808
    /* Map tables */
1846
    /* Map tables */
1809
    LOOP_UNION_MAP {
1847
    LOOP_UNION_MAP {
1810
	int hash = DEREF_int ( map_flag ( CRT_MAP ) ) ;
1848
	int hash = DEREF_int(map_flag(CRT_MAP));
1811
	char *dest = ( hash ? "destroyer" : NULL ) ;
1849
	char *dest = (hash ? "destroyer" : NULL);
1812
	comment ( "Map %MN on union %UN" ) ;
1850
	comment("Map %MN on union %UN");
1813
	output ( "extern " ) ;
1851
	output("extern ");
1814
	print_map_table ( hash ) ;
1852
	print_map_table(hash);
1815
	output ( " ;\n\n#define %MN_%UM" ) ;
1853
	output(";\n\n#define %MN_%UM");
1816
	print_map_args ( dest ) ;
1854
	print_map_args(dest);
1817
	output ( "\\\n    ( ( %MN_%UM_table [ " ) ;
1855
	output("\\\n    ((%MN_%UM_table[");
1818
	if ( is_tagged ) {
1856
	if (is_tagged) {
1819
	    if ( extra_asserts ) {
1857
	    if (extra_asserts) {
1820
		output ( "CHECK_TAG_ETC ( ( %X_%UM ), 0, ORDER_%UM )" ) ;
1858
		output("CHECK_TAG_ETC((%X_%UM), 0, ORDER_%UM)");
1821
	    } else {
1859
	    } else {
1822
		output ( "( %X_%UM )" ) ;
1860
		output("(%X_%UM)");
1823
	    }
1861
	    }
1824
	    output ( "->ag_tag ] ) " ) ;
1862
	    output("->ag_tag]) ");
1825
	} else {
1863
	} else {
1826
	    output ( "0 ] ) " ) ;
1864
	    output("0]) ");
1827
	}
1865
	}
1828
	print_map_args ( dest ) ;
1866
	print_map_args(dest);
1829
	output ( " )\n\n\n" ) ;
1867
	output(")\n\n\n");
1830
    }
1868
    }
1831
 
1869
 
1832
    /* End of file */
1870
    /* End of file */
1833
    close_file () ;
1871
    close_file();
1834
    return ;
1872
    return;
1835
}
1873
}
1836
 
1874
 
1837
 
1875
 
1838
/*
1876
/*
1839
    PRINT A UNION MAPPING TABLE
1877
 * PRINT A UNION MAPPING TABLE
1840
 
1878
 *
1841
    This routine prints a single union mapping table.
1879
 * This routine prints a single union mapping table.
1842
*/
1880
 */
1843
 
1881
 
1844
static void print_func_tab
1882
static void
1845
    PROTO_N ( ( i ) )
-
 
1846
    PROTO_T ( int i )
1883
print_func_tab(int i)
1847
{
1884
{
1848
    int hash = DEREF_int ( map_flag ( CRT_MAP ) ) ;
1885
    int hash = DEREF_int(map_flag(CRT_MAP));
1849
    comment ( "Function table for map %MN on union %UN" ) ;
1886
    comment("Function table for map %MN on union %UN");
-
 
1887
    if (i) {
1850
    if ( i ) output ( "#ifndef IGNORE_%MN_%UM\n\n" ) ;
1888
	    output("#ifndef IGNORE_%MN_%UM\n\n");
-
 
1889
    }
1851
    print_map_table ( hash ) ;
1890
    print_map_table(hash);
1852
    output ( " = {\n" ) ;
1891
    output(" = {\n");
1853
    LOOP_UNION_FIELD output ( "    %MN_%UM_%FN%F,\n" ) ;
1892
    LOOP_UNION_FIELD output("    %MN_%UM_%FN%F,\n");
1854
    output ( "} ;\n\n" ) ;
1893
    output("};\n\n");
-
 
1894
    if (i) {
1855
    if ( i ) output ( "#endif\n\n" ) ;
1895
	    output("#endif\n\n");
-
 
1896
    }
1856
    output ( "\n" ) ;
1897
    output("\n");
1857
    return ;
1898
    return;
1858
}
1899
}
-
 
1900
 
1859
 
1901
 
-
 
1902
/*
-
 
1903
 * PRINT A FUNCTION HEADER
-
 
1904
 *
-
 
1905
 * This routine prints the function headers required in print_union_hdr_c.
-
 
1906
 * The argument d is true if this is the destructor version.  The argument
-
 
1907
 * e is true if this is the header for a field set.
-
 
1908
 */
1860
 
1909
 
1861
/*
-
 
1862
    PRINT A FUNCTION HEADER
-
 
1863
 
-
 
1864
    This routine prints the function headers required in print_union_hdr_c.
-
 
1865
    The argument d is true if this is the destructor version.  The argument
-
 
1866
    e is true if this is the header for a field set.
-
 
1867
*/
-
 
1868
 
-
 
1869
static void print_func_hdr
1910
static void
1870
    PROTO_N ( ( d, e ) )
-
 
1871
    PROTO_T ( int d X int e )
1911
print_func_hdr(int d, int e)
1872
{
1912
{
1873
    int hash = DEREF_int ( map_flag ( CRT_MAP ) ) ;
1913
    int hash = DEREF_int(map_flag(CRT_MAP));
1874
    char *dest = ( d ? "_d_" : "_" ) ;
1914
    char *dest = (d ? "_d_" : "_");
1875
    char *etc = ( e ? "_etc" : "" ) ;
1915
    char *etc = (e ? "_etc" : "");
1876
    output ( "#define HDR_%MN%s%UM_%FN%s\\\n", dest, etc ) ;
1916
    output("#define HDR_%MN%s%UM_%FN%s\\\n", dest, etc);
1877
 
1917
 
1878
    /* Function header */
1918
    /* Function header */
1879
    output ( "    %MR %MN_%UM_%FN\\\n" ) ;
1919
    output("    %MR %MN_%UM_%FN\\\n");
1880
    output ( "\tPROTO_N ( " ) ;
-
 
1881
    print_map_args ( hash ? "destroyer" : NULL ) ;
1920
    print_map_args(hash ? "destroyer" : NULL);
1882
    output ( " )\\\n" ) ;
1921
    output("\\\n");
1883
 
1922
 
1884
    /* Function argument declarations */
1923
    /* Function argument declarations */
1885
    output ( "\tPROTO_T ( %UN %X_%UM" ) ;
1924
    output("\t(%UN %X_%UM");
-
 
1925
    if (hash) {
1886
    if ( hash ) output ( " X DESTROYER destroyer" ) ;
1926
	    output(" X DESTROYER destroyer");
-
 
1927
    }
1887
    LOOP_MAP_ARGUMENT output ( " X %AT %AN" ) ;
1928
    LOOP_MAP_ARGUMENT output(" X %AT %AN");
1888
    output ( " )\\\n    {" ) ;
1929
    output(")\\\n    {");
1889
 
1930
 
1890
    /* Field component declarations */
1931
    /* Field component declarations */
1891
    LOOP_UNION_COMPONENT output ( "\\\n\t%CT %CN ;" ) ;
1932
    LOOP_UNION_COMPONENT output("\\\n\t%CT %CN;");
1892
    LOOP_FIELD_COMPONENT output ( "\\\n\t%CT %CN ;" ) ;
1933
    LOOP_FIELD_COMPONENT output("\\\n\t%CT %CN;");
1893
 
1934
 
1894
    /* Assignment of field components */
1935
    /* Assignment of field components */
1895
    if ( d ) {
1936
    if (d) {
1896
	output ( "\\\n\tDESTROY_%UM_%FN%s ( ", etc ) ;
1937
	output("\\\n\tDESTROY_%UM_%FN%s(", etc);
1897
	output ( hash ? "destroyer, " : "destroy_%X, " ) ;
1938
	output(hash ? "destroyer, " : "destroy_%X, ");
1898
	print_cons_args ( 0, "" ) ;
1939
	print_cons_args(0, "");
1899
	output ( " ) ;" ) ;
1940
	output(");");
1900
    } else {
1941
    } else {
1901
	if ( field_not_empty () ) {
1942
	if (field_not_empty()) {
1902
	    output ( "\\\n\tDECONS_%UM_%FN%s ( ", etc ) ;
1943
	    output("\\\n\tDECONS_%UM_%FN%s(", etc);
1903
	    print_cons_args ( 0, "" ) ;
1944
	    print_cons_args(0, "");
1904
	    output ( " ) ;" ) ;
1945
	    output(");");
1905
	}
1946
	}
1906
    }
1947
    }
1907
    output ( "\n\n" ) ;
1948
    output("\n\n");
1908
    return ;
1949
    return;
1909
}
1950
}
1910
 
1951
 
1911
 
1952
 
1912
/*
1953
/*
1913
    PRINT A UNION MAP OUTPUT FILE
1954
 * PRINT A UNION MAP OUTPUT FILE
1914
 
1955
 *
1915
    For each union with maps in the calculus a file is printed giving the
1956
 * For each union with maps in the calculus a file is printed giving the
1916
    tables which give the actions of each map on each union component.
1957
 * tables which give the actions of each map on each union component.
1917
*/
1958
 */
1918
 
1959
 
1919
void print_union_map_c
1960
void
1920
    PROTO_N ( ( dir, un ) )
-
 
1921
    PROTO_T ( char *dir X char *un )
1961
print_union_map_c(char *dir, char *un)
1922
{
1962
{
1923
    open_file ( dir, un, MAP_SUFFIX ) ;
1963
    open_file(dir, un, MAP_SUFFIX);
1924
    LOOP_UNION_MAP print_func_tab ( 1 ) ;
1964
    LOOP_UNION_MAP print_func_tab(1);
1925
    close_file () ;
1965
    close_file();
1926
    return ;
1966
    return;
1927
}
1967
}
1928
 
1968
 
1929
 
1969
 
1930
/*
1970
/*
1931
    PRINT THE UNION MAPPING HEADERS OUTPUT FILE
1971
 * PRINT THE UNION MAPPING HEADERS OUTPUT FILE
1932
 
1972
 *
1933
    For each union with maps in the calculus a file is printed giving the
1973
 * For each union with maps in the calculus a file is printed giving the
1934
    function headers for the actions in the previous file.  Note that two
1974
 * function headers for the actions in the previous file.  Note that two
1935
    versions of the header are given - a deconstructor and a destructor
1975
 * versions of the header are given - a deconstructor and a destructor
1936
    version.  Also versions are given for any field sets.
1976
 * version.  Also versions are given for any field sets.
1937
*/
1977
 */
1938
 
1978
 
1939
void print_union_hdr_c
1979
void
1940
    PROTO_N ( ( dir, un ) )
-
 
1941
    PROTO_T ( char *dir X char *un )
1980
print_union_hdr_c(char *dir, char *un)
1942
{
1981
{
1943
    open_file ( dir, un, HDR_SUFFIX ) ;
1982
    open_file(dir, un, HDR_SUFFIX);
1944
    LOOP_UNION_MAP {
1983
    LOOP_UNION_MAP {
1945
	comment ( "Function headers for map %MN on union %UN" ) ;
1984
	comment("Function headers for map %MN on union %UN");
1946
	output ( "#ifndef IGNORE_%MN_%UM\n\n" ) ;
1985
	output("#ifndef IGNORE_%MN_%UM\n\n");
1947
	LOOP_UNION_FIELD {
1986
	LOOP_UNION_FIELD {
1948
	    print_func_hdr ( 0, 0 ) ;
1987
	    print_func_hdr(0, 0);
1949
	    print_func_hdr ( 1, 0 ) ;
1988
	    print_func_hdr(1, 0);
1950
	    if ( DEREF_int ( fld_set ( CRT_FIELD ) ) ) {
1989
	    if (DEREF_int(fld_set(CRT_FIELD))) {
1951
		print_func_hdr ( 0, 1 ) ;
1990
		print_func_hdr(0, 1);
1952
		print_func_hdr ( 1, 1 ) ;
1991
		print_func_hdr(1, 1);
1953
	    }
1992
	    }
1954
	}
1993
	}
1955
	output ( "#endif\n\n\n" ) ;
1994
	output("#endif\n\n\n");
1956
    }
1995
    }
1957
    close_file () ;
1996
    close_file();
1958
    return ;
1997
    return;
1959
}
1998
}
1960
 
1999
 
1961
 
2000
 
1962
/*
2001
/*
1963
    MAIN ACTION (C VERSION)
2002
 * MAIN ACTION (C VERSION)
1964
 
2003
 *
1965
    This routine prints all the output files for the calculus (C version).
2004
 * This routine prints all the output files for the calculus (C version).
1966
*/
2005
 */
1967
 
2006
 
1968
void main_action_c
2007
void
1969
    PROTO_N ( ( dir ) )
-
 
1970
    PROTO_T ( char *dir )
2008
main_action_c(char *dir)
1971
{
2009
{
1972
    int ign = 0 ;
2010
    int ign = 0;
1973
    gen_max = 0 ;
2011
    gen_max = 0;
1974
    output_c_code = 1 ;
2012
    output_c_code = 1;
1975
    check_null = ( extra_asserts ? "CHECK_NULL " : "" ) ;
2013
    check_null = (extra_asserts ? "CHECK_NULL" : "");
1976
 
2014
 
1977
    open_file ( dir, MAIN_PREFIX, MAIN_SUFFIX ) ;
2015
    open_file(dir, MAIN_PREFIX, MAIN_SUFFIX);
1978
    print_main_c () ;
2016
    print_main_c();
1979
 
2017
 
1980
    LOOP_UNION {
2018
    LOOP_UNION {
1981
	LIST ( MAP_P ) maps ;
2019
	LIST(MAP_P)maps;
1982
	CLASS_ID_P cid = DEREF_ptr ( un_id ( CRT_UNION ) ) ;
2020
	CLASS_ID_P cid = DEREF_ptr(un_id(CRT_UNION));
1983
	char *un = DEREF_string ( cid_name_aux ( cid ) ) ;
2021
	char *un = DEREF_string(cid_name_aux(cid));
1984
	print_union_ops_c ( dir, un ) ;
2022
	print_union_ops_c(dir, un);
1985
	maps = DEREF_list ( un_map ( CRT_UNION ) ) ;
2023
	maps = DEREF_list(un_map(CRT_UNION));
1986
	if ( !IS_NULL_list ( maps ) ) {
2024
	if (!IS_NULL_list(maps)) {
1987
	    print_union_map_c ( dir, un ) ;
2025
	    print_union_map_c(dir, un);
1988
	    print_union_hdr_c ( dir, un ) ;
2026
	    print_union_hdr_c(dir, un);
1989
	    ign = 1 ;
2027
	    ign = 1;
1990
        }
2028
        }
1991
    }
2029
    }
1992
 
2030
 
1993
    comment ( "Maximum allocation size" ) ;
2031
    comment("Maximum allocation size");
1994
    output ( "#define %X_GEN_MAX%t40%d\n\n", gen_max + 1 ) ;
2032
    output("#define %X_GEN_MAX%t40%d\n\n", gen_max + 1);
1995
    close_file () ;
2033
    close_file();
1996
 
2034
 
1997
    if ( ign ) {
2035
    if (ign) {
1998
	open_file ( dir, IGNORE_PREFIX, DEF_SUFFIX ) ;
2036
	open_file(dir, IGNORE_PREFIX, DEF_SUFFIX);
1999
	comment ( "Map ignore macros" ) ;
2037
	comment("Map ignore macros");
2000
	LOOP_UNION {
2038
	LOOP_UNION {
2001
	    LOOP_UNION_MAP output ( "#define IGNORE_%MN_%UM%t40%d\n", 1 ) ;
2039
	    LOOP_UNION_MAP output("#define IGNORE_%MN_%UM%t40%d\n", 1);
2002
	}
2040
	}
2003
	output ( "\n" ) ;
2041
	output("\n");
2004
	close_file () ;
2042
	close_file();
2005
    }
2043
    }
2006
 
2044
 
2007
    if ( extra_asserts ) {
2045
    if (extra_asserts) {
2008
	open_file ( dir, ASSERT_PREFIX, DEF_SUFFIX ) ;
2046
	open_file(dir, ASSERT_PREFIX, DEF_SUFFIX);
2009
	comment ( "Assertion function definitions" ) ;
2047
	comment("Assertion function definitions");
2010
	print_assert_fns () ;
2048
	print_assert_fns();
2011
	close_file () ;
2049
	close_file();
2012
    }
2050
    }
2013
    return ;
2051
    return;
2014
}
2052
}