Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/**********************************************************************
62
$Author: release $
63
$Date: 1998/01/17 15:55:47 $
64
$Revision: 1.1.1.1 $
65
$Log: me_fns.c,v $
66
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.4  1996/10/29  10:10:51  currie
70
 * 512 bit alignment for hppa
71
 *
72
 * Revision 1.3  1995/07/05  09:26:35  currie
73
 * continue wrong
74
 *
75
 * Revision 1.2  1995/05/05  08:10:56  currie
76
 * initial_value + signtures
77
 *
78
 * Revision 1.1  1995/04/06  10:44:05  currie
79
 * Initial revision
80
 *
81
***********************************************************************/
82
 
83
#include "config.h"
84
#include "common_types.h"
85
#include "exp.h"
86
#include "expmacs.h"
87
#include "table_fns.h"
88
#include "externs.h"
89
#include "installglob.h"
90
#include "tags.h"
91
#include "install_fns.h"
92
#include "check.h"
93
#include "messages_c.h"
94
#include "shapemacs.h"
95
#include "basicread.h"
96
#include "natmacs.h"
97
#include "me_fns.h"
98
 
7 7u83 99
/* a collection of useful procedures for makeing up exps */
2 7u83 100
 
101
/* PROCEDURES */
102
 
7 7u83 103
exp
104
me_obtain(exp id)
2 7u83 105
{
7 7u83 106
	shape sha = (son(id) == nilexp) ? sh(id) : sh(son(id));
107
	exp n;
108
	n = getexp((isvar(id)) ? f_pointer(align_of(sha)) : sha, nilexp, 0, id,
109
		   pt(id), 0, 0, name_tag);
110
	++no(id);
111
	pt(id) = n;
112
	return n;
2 7u83 113
}
114
 
7 7u83 115
 
116
exp
117
me_startid(shape sha, exp def, int isv)
2 7u83 118
{
7 7u83 119
	exp r = getexp(sha, nilexp, 0, def, nilexp, 0, 0, ident_tag);
120
	if (isv) {
121
		setvar(r);
122
	}
123
	return r;
2 7u83 124
}
125
 
7 7u83 126
 
127
exp
128
me_start_clearvar(shape sha, shape shb)
2 7u83 129
{
7 7u83 130
	exp init = getexp(shb, nilexp, 0, nilexp, nilexp, 0, 0, clear_tag);
131
	exp var = getexp(sha, nilexp, 0, init, nilexp, 0, 0, ident_tag);
132
	setvar(var);
133
	return var;
2 7u83 134
}
135
 
7 7u83 136
 
137
exp
138
me_complete_id(exp id, exp body)
2 7u83 139
{
7 7u83 140
	clearlast(son(id));
141
	bro(son(id)) = body;
142
	setlast(body);
143
	bro(body) = id;
144
	sh(id) = sh(body);
145
	return hold_check(id);
2 7u83 146
}
147
 
7 7u83 148
 
149
exp
150
me_u1(error_treatment ov_err, exp arg1, unsigned char nm)
2 7u83 151
{
7 7u83 152
	exp r = getexp(sh(arg1), nilexp, 0, arg1, nilexp, 0, 0, nm);
153
	seterrhandle(r, ov_err.err_code);
154
	if (isov(r)) {
155
		setjmp_dest(r, get_lab(ov_err.jmp_dest));
156
	}
157
	setfather(r, arg1);
158
	return r;
2 7u83 159
}
160
 
7 7u83 161
 
162
exp
163
me_u2(exp arg1, unsigned char nm)
2 7u83 164
{
7 7u83 165
	exp r = getexp(sh(arg1), nilexp, 0, arg1, nilexp, 0, 0, nm);
166
	setfather(r, arg1);
167
	return r;
2 7u83 168
}
169
 
7 7u83 170
 
171
exp
172
me_u3(shape sha, exp arg1, unsigned char nm)
2 7u83 173
{
7 7u83 174
	exp r = getexp(sha, nilexp, 0, arg1, nilexp, 0, 0, nm);
175
	setfather(r, arg1);
176
	return r;
2 7u83 177
}
178
 
7 7u83 179
 
180
exp
181
me_b1(error_treatment ov_err, exp arg1, exp arg2, unsigned char nm)
2 7u83 182
{
7 7u83 183
	exp r = getexp(sh(arg1), nilexp, 0, arg1, nilexp, 0, 0, nm);
184
	seterrhandle(r, ov_err.err_code);
185
	setbro(arg1, arg2);
186
	clearlast(arg1);
187
	if (isov(r)) {
188
		setjmp_dest(r, get_lab(ov_err.jmp_dest));
189
	}
190
	setfather(r, arg2);
191
	return r;
2 7u83 192
}
193
 
7 7u83 194
 
195
exp
196
me_b2(exp arg1, exp arg2, unsigned char nm)
2 7u83 197
{
7 7u83 198
	exp r = getexp(sh(arg1), nilexp, 0, arg1, nilexp, 0, 0, nm);
199
	setbro(arg1, arg2);
200
	clearlast(arg1);
201
	setfather(r, arg2);
202
	return r;
2 7u83 203
}
204
 
7 7u83 205
 
206
exp
207
me_b3(shape sha, exp arg1, exp arg2, unsigned char nm)
2 7u83 208
{
7 7u83 209
	exp r = getexp(sha, nilexp, 0, arg1, nilexp, 0, 0, nm);
210
	setbro(arg1, arg2);
211
	clearlast(arg1);
212
	setfather(r, arg2);
213
	return r;
2 7u83 214
}
215
 
7 7u83 216
 
217
exp
218
me_c1(shape sha, error_treatment ov_err, exp arg1, unsigned char nm)
2 7u83 219
{
7 7u83 220
	exp r = getexp(sha, nilexp, 0, arg1, nilexp, 0, 0, nm);
221
	seterrhandle(r, ov_err.err_code);
222
	if (isov(r)) {
223
		setjmp_dest(r, get_lab(ov_err.jmp_dest));
224
	}
225
	setfather(r, arg1);
226
	return r;
2 7u83 227
}
228
 
7 7u83 229
 
230
exp
231
me_c2(shape sha, exp arg1, unsigned char nm)
2 7u83 232
{
7 7u83 233
	exp r = getexp(sha, nilexp, 0, arg1, nilexp, 0, 0, nm);
234
	setfather(r, arg1);
235
	return r;
2 7u83 236
}
237
 
7 7u83 238
 
239
exp
240
me_l1(shape s, unsigned char nm)
2 7u83 241
{
7 7u83 242
	exp r = getexp(s, nilexp, 0, nilexp, nilexp, 0, 0, nm);
243
	return r;
2 7u83 244
}
245
 
246
 
7 7u83 247
exp
248
me_q1_aux(nat_option prob, ntest nt, exp lab, exp arg1, exp arg2,
249
	  unsigned char nm)
2 7u83 250
{
7 7u83 251
	exp r;
252
	r = getexp(f_top, nilexp, 0, arg1, lab, 0, 0, nm);
253
	no(r) = (prob.present) ? natint(prob.val) : 1000;
254
	settest_number(r, nt);
255
	setbro(arg1, arg2);
256
	clearlast(arg1);
257
	++no(son(lab));
258
	setfather(r, arg2);
259
	return r;
2 7u83 260
}
261
 
7 7u83 262
 
263
exp
264
me_q1(nat_option prob, ntest nt, label dest, exp arg1, exp arg2,
265
      unsigned char nm)
2 7u83 266
{
7 7u83 267
	return me_q1_aux(prob, nt, get_lab(dest), arg1, arg2, nm);
2 7u83 268
}
269
 
7 7u83 270
 
271
exp
272
me_q2_aux(nat_option prob, error_treatment err, ntest nt, exp lab, exp arg1,
273
	  exp arg2, unsigned char nm)
2 7u83 274
{
7 7u83 275
	exp r;
276
	UNUSED(err);
277
	r = getexp(f_top, nilexp, 0, arg1, lab, 0, 0, nm);
278
	no(r) = (prob.present) ? natint(prob.val) : 1000;
279
	settest_number(r, nt);
280
	setbro(arg1, arg2);
281
	clearlast(arg1);
282
	++no(son(lab));
283
	setfather(r, arg2);
2 7u83 284
 
7 7u83 285
	return r;
2 7u83 286
}
287
 
7 7u83 288
 
289
exp
290
me_q2(nat_option prob, error_treatment err, ntest nt, label dest, exp arg1,
291
      exp arg2, unsigned char nm)
2 7u83 292
{
7 7u83 293
	return me_q2_aux(prob, err, nt, get_lab(dest), arg1, arg2, nm);
2 7u83 294
}
295
 
7 7u83 296
 
297
exp
298
me_shint(shape sha, int i)
2 7u83 299
{
7 7u83 300
	return getexp(sha, nilexp, 0, nilexp, nilexp, 0, i, val_tag);
2 7u83 301
}
302
 
7 7u83 303
 
304
exp
305
me_null(shape sha, int i, unsigned char nm)
2 7u83 306
{
7 7u83 307
	return getexp(sha, nilexp, 0, nilexp, nilexp, 0, i, nm);
2 7u83 308
}
309
 
7 7u83 310
 
311
exp
312
me_b4(error_treatment div0_err, error_treatment ov_err, exp arg1, exp arg2,
313
      unsigned char nm)
2 7u83 314
{
7 7u83 315
	exp id, tst, divexp, seq;
2 7u83 316
 
7 7u83 317
	if (div0_err.err_code != 4) {
318
		return me_b1(ov_err, arg1, arg2, nm);
319
	}
2 7u83 320
 
7 7u83 321
	id = me_startid(sh(arg1), arg2, 0);
322
	divexp = me_b1(ov_err, arg1, me_obtain(id), nm);
323
	tst = me_q1(no_nat_option, f_not_equal, div0_err.jmp_dest,
324
		    me_obtain(id), me_shint(sh(arg1), 0), test_tag);
325
	seq = me_b2(me_u2(tst, 0), divexp, seq_tag);
326
	return me_complete_id(id, seq);
2 7u83 327
}
328
 
7 7u83 329
 
330
void
331
note_repeat(exp r)
2 7u83 332
{
7 7u83 333
	if (crt_repeat != nilexp) {
334
		++no(crt_repeat);
335
	}
336
	repeat_list = getexp(f_top, crt_repeat, 0, nilexp, repeat_list, 1, 0,
337
			     0);
338
	crt_repeat = repeat_list;
2 7u83 339
 
7 7u83 340
	pt(r) = crt_repeat;
2 7u83 341
 
7 7u83 342
	son(crt_repeat) = r;
343
	crt_repeat = bro(crt_repeat);
344
	return;
2 7u83 345
}
346
 
7 7u83 347
 
348
/* the result is an alignment for something of which the addresses must be
349
 * divisible by n bits */
350
alignment
351
long_to_al(int n)
2 7u83 352
{
7 7u83 353
	switch (n) {
354
	case 0:
355
	case 1:
356
		return const_al1;
357
	case 8:
358
		return const_al8;
359
	case 16:
360
		return const_al16;
361
	case 32:
362
		return const_al32;
363
	case 64:
364
		return const_al64;
365
	case 512:
366
		return const_al512;
367
	default:
368
		failer(BAD_LONG_AL);
369
		return const_al32;
370
	}
2 7u83 371
}
372
 
7 7u83 373
 
374
/* the shape describes an integer */
375
int
376
is_integer(shape s)
2 7u83 377
{
7 7u83 378
	return name(s) >= scharhd && name(s) <= u64hd;
2 7u83 379
}
380
 
7 7u83 381
 
382
/* the shape describes a floating point number */
383
int
384
is_float(shape s)
2 7u83 385
{
7 7u83 386
	return name(s) >= shrealhd && name(s) <= doublehd;
2 7u83 387
}
388
 
7 7u83 389
 
390
int
391
is_complex(shape s)
2 7u83 392
{
393
#if substitute_complex
7 7u83 394
	return(name(s) == cpdhd);
2 7u83 395
#else
7 7u83 396
	return name(s) >= shcomplexhd && name(s) <= complexdoublehd;
2 7u83 397
#endif
398
}
399
 
7 7u83 400
 
401
floating_variety
402
float_to_complex_var(floating_variety f)
2 7u83 403
{
7 7u83 404
	return f+3;
2 7u83 405
}
406
 
7 7u83 407
 
408
floating_variety
409
complex_to_float_var(floating_variety f)
2 7u83 410
{
7 7u83 411
	return f-3;
2 7u83 412
}