2 !! Simple program to test various z-machine stuff.
3 !! Placed in the public domain by Evin Robertson.
6 [ assert actual expected a op b;
7 if(expected ~= actual) {
9 @check_arg_count 5 ?binary;
15 print a, (string) op, b;
18 print " expected ", expected, "; got ", actual, "^";
25 [ do_check_check_arg_count a b c d e f g n;
26 for(n = 1: n <= count: n++) {
27 @check_arg_count n ?~bad;
30 @check_arg_count n ?bad;
36 print "^claimed argument ", n, " was ";
38 print "not given when it was.^";
40 print "given when it was not.^";
46 ![ list_arguments a b c d e f g h i j k l m n o;
47 ! for(mycount = 1: mycount <= 15: mycount++) {
48 ! @check_arg_count mycount ?~noarg;
52 ! @load [mycount] -> sp;
64 @call_vn2 assert sp expect a "+" b;
69 @call_vn2 assert sp expect a "&" b;
74 @call_vn2 assert sp expect a "<<" b;
79 @call_vn2 assert a expect a "--";
84 @call_vn2 assert sp expect a "/" b;
89 @call_vn2 assert a expect a "++";
94 @call_vn2 assert sp expect a "<<" b;
99 @call_vn2 assert sp expect a "%" b;
104 @call_vn2 assert sp expect a "*" b;
108 @"VAR:56S" a -> sp; ! @not a -> sp; (bug in inform)
109 @call_vn2 assert sp expect a "~";
114 @call_vn2 assert sp expect a "|" b;
119 @call_vn2 assert sp expect a "-" b;
124 ! I couldn't figure out how to do negative numbers in inform assembly, so
125 ! here's constants for the numbers I use
132 Constant n32768 -32768;
134 Constant Rand_Range 60;
136 Array mytable -> 256;
137 Array mysecond -> 256;
143 ! @aread mytable 0 -> n;
147 print "check_arg_count ";
148 count = 0; do_check_check_arg_count();
149 count = 1; do_check_check_arg_count(1);
150 count = 2; do_check_check_arg_count(2, 1);
151 count = 3; do_check_check_arg_count(3, 2, 1);
152 count = 4; do_check_check_arg_count(4, 3, 2, 1);
153 count = 5; do_check_check_arg_count(5, 4, 3, 2, 1);
154 count = 6; do_check_check_arg_count(6, 5, 4, 3, 2, 1);
155 count = 7; do_check_check_arg_count(7, 6, 5, 4, 3, 2, 1);
162 @je 32767 n32768 ?bad;
163 @je n32768 n32768 ?~bad;
192 @dec_chk n 1000 ?~bad; ! 2
193 @dec_chk n 1 ?bad; ! 1
194 @dec_chk n 1 ?~bad; ! 0
195 @dec_chk n 0 ?~bad; ! -1
196 @dec_chk n n2 ?bad; ! -2
197 @dec_chk n n2 ?~bad; ! -3
198 @dec_chk n 1000 ?~bad; ! -4
199 @dec_chk n n500 ?bad; ! -5
203 @inc_chk n n500 ?~bad; ! -5
204 @inc_chk n 1000 ?bad; ! -4
205 @inc_chk n n3 ?bad; ! -3
206 @inc_chk n n3 ?~bad; ! -2
207 @inc_chk n 0 ?bad; ! -1
208 @inc_chk n 1 ?bad; ! 0
209 @inc_chk n 1 ?bad; ! 1
210 @inc_chk n 1 ?~bad; ! 2
211 @inc_chk n 1000 ?bad; ! 3
214 @test $ffff $ffff ?~bad;
216 @test $1234 $4321 ?bad;
225 do_add(32765, 6, -32765);
248 do_dec(-32768, 32767);
260 do_div(32767, -32768, 0);
261 do_div(-32768, 32767, -1);
262 do_div(-32768, -1, -32768);
269 do_inc(32767, -32768);
271 print "loadx/storex ";
272 @loadb mytable 0 -> n;
274 @storeb mytable 0 123;
275 @loadb mytable 0 -> n;
277 @loadw mytable 0 -> n;
279 @storew mytable 0 $1234;
280 @loadw mytable 0 -> n;
282 @loadb mytable 0 -> n;
284 @loadb mytable 1 -> n;
295 do_log(-9, -5, 2047);
307 do_mod(32767, -32768, 32767);
308 do_mod(-32768, 32767, -1);
309 do_mod(-32768, -1, 0);
316 do_mul( 11, -5, -55);
319 do_mul(-32768, -1, -32768);
324 do_not($5555, $aaaa);
325 do_not($aaaa, $5555);
328 do_or($1234, $4321, $5335);
329 do_or($4321, $1234, $5335);
330 do_or($1234, 0, $1234);
331 do_or($1030, $ffff, $ffff);
332 do_or($ffff, $0204, $ffff);
341 do_sub(-32765, 32765, 6);
343 print "output_stream ";
344 @output_stream 3 mytable;
346 @output_stream 3 mysecond;
351 for(n = 0: n < mytable-->0: n++)
352 print (char) mytable->(n+2);
353 for(n = 0: n < mysecond-->0: n++)
354 print (char) mysecond->(n+2);
357 for(n = 1: n <= Rand_Range: n++)
360 for(n = 0: n < 800: n++) {
361 @random Rand_Range -> g;
362 if(g <= 0 || g > Rand_Range) {
363 print "illegal return from result (", g, ").^";
373 for(n = 1: n <= Rand_Range: n++) {
374 if(mytable-->n > max)
378 for(g = max: g > 0: g--) {
379 for(n = 1: n < Rand_Range: n++) {