Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra4/src/tools/pl/examples/nonC.pl – Rev 2

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
Struct C (re:Int, im:Int);
32
Iddec strcmp:proc;
33
Iddec printf:proc;
34
Iddec testnl:proc;
35
 
36
Proc addC = C (lv:C, rv:C) 
37
	Let l = * lv
38
	Let r = * rv
39
	{ return(
40
	   Cons[shape_offset(C)] ( .re: re[l] + re[r], .im: im[l] + im[r])
41
	  )
42
	};
43
 
44
String sSTRUCT1 = "Error in STRUCT1; (%d, %d) != (4, 6)\n";
45
String tSTRUCT1 = "STRUCT1 OK\n";
46
 
47
Proc test_STRUCT1 = top()
48
	Let x = Cons[shape_offset(C)] (.re: 1(Int), .im:2(Int)) 
49
	Let y = Cons[shape_offset(C)] (.re: 3(Int), .im:4(Int))
50
	Let z = addC[C](x,y)
51
	?{	?(re[z] == 4(Int));
52
		?(im[z] == 6(Int));
53
		printf[top](tSTRUCT1);
54
		return(make_top)
55
	|
56
		printf[top](sSTRUCT1, re[z], im[z]);
57
		return(make_top)
58
	};
59
 
60
Proc test_NON_LOCALS = top()
61
	Var NL[visible]:Int = 12345(Int)
62
	{	testnl[top](current_env);
63
		return(make_top);
64
	};
65
 
66
String sNON_LOCALS = "Error in NON_LOCALS; %d != 12345\n";
67
String tNON_LOCALS = "NON_LOCALS OK \n";
68
 
69
Let eoNL:offset(locals_alignment,  alignment(Int))
70
	 = env_offset(locals_alignment, alignment(Int), NL);
71
 
72
Proc testnl = top(fp: pointer(locals_alignment))
73
	Let z = *(Int) (* fp *+. env_offset(locals_alignment,alignment(Int), NL))
74
	Let z1 = *(Int) (* fp *+. eoNL)
75
	?{	?( z == 12345(Int));
76
		?( z1 == 12345(Int));
77
		printf[top](tNON_LOCALS);
78
		return(make_top);
79
	|
80
		printf[top](sNON_LOCALS, z);
81
		return(make_top);
82
	};
83
 
84
String sGO_LOCAL_LV = 
85
  "Error in GO_LOCAL_LV; control should never reach here\n";
86
String tGO_LOCAL_LV = "GO_LOCAL_LV OK\n";
87
 
88
Proc test_GO_LOCAL_LV = top()
89
{ Labelled
90
	{
91
	  Let x = make_local_lv(l)
92
	  { goto_local_lv(x)
93
	  }
94
	| :l:
95
	  printf[top](tGO_LOCAL_LV); 
96
	  return(make_top)
97
	};
98
	printf[top](sGO_LOCAL_LV);
99
	return(make_top)
100
};
101
 
102
String sNEVER_PRINT = "This should not be printed\n";
103
 
104
Proc testlj = bottom(env:pointer(locals_alignment), lab:pointer(code_alignment),
105
			p: pointer(alignment(Int)))
106
{
107
 
108
	Var i:Int = 0(Int)
109
	Var j:Int = 0(Int)
110
	Var k: Int = 1(Int)
111
	Rep { i = (* i + 1(Int));
112
	      j = (* i * * i);
113
	      k = (* i + (* j + (* k + * j)));
114
	      ?{ ?(* k < * j); printf[top](sNEVER_PRINT)
115
		| make_top
116
		};
117
	      ?( * k > 0(Int))
118
	    };
119
 
120
	long_jump(* env, * lab)
121
};
122
 
123
String sLONG_JUMP = "Error in LONG_JUMP; control should never reach here\n";
124
String tLONG_JUMP = "LONG_JUMP OK\n";
125
 
126
Proc test_LONG_JUMP = top()
127
{ 
128
	Let x = local_alloc(Sizeof(Int) .* 100(Int))
129
   	Labelled
130
	{
131
	  testlj[bottom](current_env, make_local_lv(l), x)
132
	| :l:
133
	  printf[top](tLONG_JUMP); 
134
	  return(make_top)
135
	};
136
	printf[top](sLONG_JUMP);
137
	return(make_top)
138
};
139
 
140
String sN_COPIES = "Error in N_COPIES; %d != %d  at index %d\n";
141
String tN_COPIES = "N_COPIES OK\n";
142
 
143
Proc testncop = top(i:Int)
144
	Var x:nof(10, Int) = n_copies(10, * i)
145
	Var j:Int = 0(Int)
146
	Var noe:Int = 0(Int)
147
	{ Rep { Let z = 
148
		 *(Int)(x *+. (Sizeof(Int) .* * j))
149
		{
150
	      		?{ ?( z == * i)
151
	      		| printf[top](sN_COPIES, z, * i, * j);
152
			  noe = (* noe + 1(Int)); 
153
	        	  make_top;
154
	      		}
155
		};
156
	      j = (* j + 1(Int));
157
	      ?( * j < 10(Int))
158
	  };
159
	  ?{ ?(* noe == 0(Int));
160
	     printf[top](tN_COPIES)
161
	  | make_top
162
	  };
163
	  return(make_top)
164
	};
165
 
166
Proc test_N_COPIES = top()
167
	{ testncop[top](15(Int));
168
	  return(make_top)
169
	};
170
 
171
String sCONCAT_NOF = "Error in CONCAT_NOF; wrong at index %d or %d\n";
172
String tCONCAT_NOF = "CONCAT_NOF OK\n";
173
 
174
Proc testconcat = top(a:nof(4, Int), b:nof(4, Int))
175
	Var c: nof(8, Int) = concat_nof(* a, * b)
176
	Var i:Int = 0(Int)
177
	Let coff = Sizeof(Int) .* 4(Int)
178
	Var noe:Int = 0(Int)
179
	{ Rep 
180
	  { Let off =  Sizeof(Int) .* * i
181
	  	?{ ?( *(Int)(c *+. off) == *(Int)(a *+. off));
182
	     	   ?( *(Int)(c *+. (off .+. coff)) == *(Int)(b *+. off));
183
	  	| printf[top](sCONCAT_NOF, * i, * i);
184
	    	  noe = (* noe + 1(Int))
185
		};
186
	    i = (* i + 1(Int));
187
	    ?( * i < 4(Int))
188
	  };
189
	  ?{ ?(* noe == 0(Int));
190
	     printf[top](tCONCAT_NOF);
191
	  | make_top
192
	  };
193
	  return(make_top)
194
	};
195
 
196
Proc test_CONCAT_NOF = top()
197
{ testconcat[top](n_copies(4, 5(Int)), n_copies(4, 17(Int)));
198
  return(make_top)
199
};
200
 
201
String TS1 = "abcdef";
202
String SS1 = "aabcde";
203
String TS2 = "abcdef";
204
String SS2 = "bcdeff";
205
String sMOVE_SOME = "Error in MOVE_SOME; %s  !=  %s \n";
206
String tMOVE_SOME = "MOVE_SOME (%d) OK\n";
207
 
208
Proc test_MOVE_SOME = top()
209
{ move_some(overlap, TS1, TS1 *+. Sizeof(Char), Sizeof(Char) .* 5(Int));
210
  ?{ ?(strcmp[Int](TS1, SS1) == 0(Int));
211
     printf[top](tMOVE_SOME, 1(Int))
212
    | printf[top](sMOVE_SOME, TS1, SS1)
213
   }; 
214
 
215
  move_some(overlap, TS2 *+. Sizeof(Char), TS2, Sizeof(Char) .* 5(Int));
216
  ?{ ?(strcmp[Int](TS2, SS2) == 0(Int));
217
     printf[top](tMOVE_SOME, 2(Int))
218
    | printf[top](sMOVE_SOME, TS2, SS2)
219
   };
220
   return(make_top)
221
}; 
222
 
223
String sPOWER = "Error in POWER;  %d != %d\n";
224
String tPOWER = "POWER OK\n";
225
 
226
 
227
 
228
Proc testpower = top(i:Int, j:Unsigned Int, a: Int)
229
	Let z = power(impossible, * i, * j)
230
	{	?{ ?(z == * a);
231
	   	   printf[top](tPOWER)
232
		| printf[top](sPOWER, z, a)
233
		};
234
		return(make_top)
235
	};
236
 
237
Var jmem:Int;
238
Var imem:Unsigned Int;
239
 
240
String sLONG_JUMP_VAR = "Error due to incorrect allocation after LONG_JUMP\n";
241
Proc test_POWER = top()
242
	Var i:Unsigned Int = 0(Unsigned Int)
243
	Var j:Int = 1(Int)
244
	{	Rep{ testpower[top](2(Int), * i, * j);
245
		     j = (* j * 2(Int));
246
		     i = (* i + 1(Unsigned Int));
247
		     jmem = * j;
248
		     imem = * i;
249
		     test_LONG_JUMP[top]();
250
		     ?{ ?(* i == * imem); ?(* j == * jmem)
251
		       | printf[top](sLONG_JUMP_VAR)
252
		      };
253
		     ?( * i > 4(Unsigned Int));
254
		};
255
		return(make_top)
256
	};
257
 
258
String sMAX = "Error in MAX(%d, %d) != %d\n";
259
String sMIN = "Error in MIN(%d, %d) != %d\n";
260
String tMAXMIN = "MAX and MIN ok\n";
261
 
262
Proc testmaxmin = top(i:Int, j:Int)
263
	Let x = maximum(* i,* j)
264
	Let y = minimum(* i,* j)
265
	Var n:Int = 0(Int)
266
	{
267
	   ?{ ?( * i >= * j); 
268
	      ?{ ?(x != * i); 
269
	         printf[top](sMAX, * i, * j, x);
270
	         n = 1(Int)
271
		| make_top
272
               };
273
	       ?{ ?(y != * j); 
274
	          printf[top](sMIN, * i, * j, y);
275
	          n = 1(Int)
276
		|  make_top
277
	        } 
278
 
279
	    | 
280
	      ?{ ?(x != * j); 
281
	         printf[top](sMAX, * i, * j, x);
282
	         n = 1(Int)
283
		| make_top
284
               };
285
	       ?{ ?(y != * i); 
286
	          printf[top](sMIN, * i, * j, y);
287
	          n = 1(Int)
288
		|  make_top
289
	        }
290
	    };
291
	    ?{ ?(* n == 0(Int));
292
		printf[top](tMAXMIN)
293
	     | make_top
294
	    };       
295
 
296
	    return(make_top)
297
	};
298
 
299
Proc test_MAXMIN = top()
300
	Var i:Int = 0(Int)
301
	Var j:Int = 10(Int)
302
	{ Rep { testmaxmin[top](* i, * j);
303
		i = (* i + 1(Int));
304
		j = (* j - 1(Int));
305
		?(* i > 20(Int));
306
	  };
307
	  return(make_top)
308
	};
309
 
310
 
311
Proc main = top()
312
{	test_STRUCT1[top]();
313
	test_NON_LOCALS[top]();
314
	test_GO_LOCAL_LV[top]();
315
	test_LONG_JUMP[top]();
316
	test_N_COPIES[top]();
317
	test_CONCAT_NOF[top]();
318
	test_MOVE_SOME[top]();
319
	test_POWER[top]();
320
	test_MAXMIN[top]();
321
	return(make_top)
322
};
323
 
324
 
325
Keep(main, test_POWER, test_LONG_JUMP)