Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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