6 |
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 |
Tokdec BASE:[EXP]EXP;
|
|
|
32 |
Tokdec STRIDE:[EXP]EXP;
|
|
|
33 |
Tokdec SIZE:[EXP]EXP;
|
|
|
34 |
/* Token declarations with defs in CAPSULE B */
|
|
|
35 |
|
|
|
36 |
Tokdec A1_EXP_AUX : [NAT, SHAPE,TOKEN[NAT]EXP,TOKEN[TOKEN[NAT]EXP]EXP,
|
|
|
37 |
TOKEN[NAT]EXP
|
|
|
38 |
]EXP;
|
|
|
39 |
/* Declaration of recursive token */
|
|
|
40 |
|
|
|
41 |
Tokdef A1_EXP_AUX = [ NoArrs:NAT, /* the number of arrays involved.. */
|
|
|
42 |
Sh:SHAPE, /* ...the shape of their elements */
|
|
|
43 |
Arrs:TOKEN[NAT]EXP,
|
|
|
44 |
/* delivers array descs [1:NoArrs] */
|
|
|
45 |
Action:TOKEN[TOKEN[NAT]EXP]EXP,
|
|
|
46 |
/* expansion of this is body of loop */
|
|
|
47 |
Map:TOKEN[NAT]EXP
|
|
|
48 |
/* the mapping for parameter of Action */
|
|
|
49 |
] EXP
|
|
|
50 |
EXP ?( + NoArrs(Int) - 1(Int),
|
|
|
51 |
/* if more than one array, expand to this :*/
|
|
|
52 |
Var p:Ptr Sh = BASE[Arrs[NoArrs]]
|
|
|
53 |
/* introduce p to access elements of
|
|
|
54 |
last array...*/
|
|
|
55 |
{ A1_EXP_AUX[ /* scope of p is recursive expansion ...*/
|
|
|
56 |
computed_nat(+ NoArrs(Int) - 1(Int)),
|
|
|
57 |
/* ... with one less array ... */
|
|
|
58 |
Sh,
|
|
|
59 |
Arrs,
|
|
|
60 |
Use [Elem:TOKEN[NAT]EXP]EXP
|
|
|
61 |
{ Action[Elem];
|
|
|
62 |
p = (* p *+. STRIDE[Arrs[NoArrs]])
|
|
|
63 |
/* ... adding increment to p ... */
|
|
|
64 |
},
|
|
|
65 |
Use [n:NAT]EXP
|
|
|
66 |
EXP ? ( + n(Int) - + NoArrs(Int),
|
|
|
67 |
Map[n],
|
|
|
68 |
* p
|
|
|
69 |
)
|
|
|
70 |
/* ... and giving p as the mapping to
|
|
|
71 |
be used for Elem below*/
|
|
|
72 |
]
|
|
|
73 |
},
|
|
|
74 |
/* if only one array, expand to this */
|
|
|
75 |
Var q:Ptr Sh = BASE[Arrs[1]]
|
|
|
76 |
Let lim = * q *+. SIZE[Arrs[1]]
|
|
|
77 |
/* one element beyond the end of the 1st array*/
|
|
|
78 |
Rep {
|
|
|
79 |
Action[Use [n:NAT]EXP
|
|
|
80 |
EXP ? ( + n(Int) - 1(Int),
|
|
|
81 |
Map[n],
|
|
|
82 |
* q
|
|
|
83 |
)
|
|
|
84 |
]; /* This is where the action of the loop is
|
|
|
85 |
expanded, including all the increments
|
|
|
86 |
*/
|
|
|
87 |
|
|
|
88 |
q = (* q *+. STRIDE[Arrs[1]]);
|
|
|
89 |
*?( * q >= lim)
|
|
|
90 |
/* continue loop until condition satisfied */
|
|
|
91 |
}
|
|
|
92 |
);
|
|
|
93 |
|
|
|
94 |
Tokdef A1_EXP = [ NoArrs1:NAT,
|
|
|
95 |
Sh1:SHAPE,
|
|
|
96 |
Arrs1:TOKEN[NAT]EXP,
|
|
|
97 |
Action1:TOKEN[TOKEN[NAT]EXP]EXP
|
|
|
98 |
] EXP
|
|
|
99 |
/* must introduce aux token to provide mappings for parameter
|
|
|
100 |
of Action */
|
|
|
101 |
A1_EXP_AUX[NoArrs1, Sh1, Arrs1, Action1,
|
|
|
102 |
Use [n:NAT]EXP #"This array does not exist"
|
|
|
103 |
];
|
|
|
104 |
|
|
|
105 |
Keep (A1_EXP)
|