Debian Codegraph @

trip/stats.rexx

raw
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992 Anders Christensen <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /*
21 * Following statements are tested otherwhere:
22 *
23 * PULL PUSH QUEUE
24 * --> tested in stack.rexx
25 *
26 */
27
28 written = 0
29
30 /* ============================ GENERAL ============================= */
31 call notify 'general'
32
33 /*----- clauses have precedens before commands ---------------------- */
34 bar = ''
35 call doit true 1 'foo'
36 signal aftertrue
37
38 doit:
39 rc = -1000
40 bar = 'none'
41 one = 1
42 arg(one) bar
43 if (rc^==-1000) then
44 call complain "commands have presedens before keywords"
45 if (bar^==' FOO') then
46 call complain 'ARG didnt work properly wrt the spaces'
47 return
48
49 aftertrue:
50
51 /*----- keywords does not need spaces around them --------------------*/
52 foo = nospace()
53 if foo ^== 4 then
54 call complain 'Something very wrong with parsing of return'
55
56 signal afternospace
57
58 nospace:
59 nop;return(4)
60 call complain "The return clause was not found"
61
62 afternospace:
63
64
65
66
67 /* ===== ADDRESS ============= */
68 call notify 'address'
69
70 /*----- address with command should not change the env. --------------*/
71 address system
72 if (address() ^== 'SYSTEM') then
73 call complain 'Could not set envionment to system'
74 address path 'true'
75 if address() ^== 'SYSTEM' then
76 call complain 'ADDRESS with command changed default environment'
77
78
79 /*----- Just address toggles environments ----*/
80
81 address command
82 if address() ^== 'COMMAND' then
83 call complain 'ADDRESS could not set environment to COMMAND'
84
85 address path
86 address system
87 address
88 if (address() ^== 'PATH') then
89 call complain 'Just ADDRESS does not toggle environments'
90
91
92 /*----- env names is stored over subroutines -------------------------*/
93 address command
94 address system
95 call checkaddr
96 if (address() ^== 'SYSTEM') then
97 call complain 'Env. not stored over function calls'
98
99 address
100 if (address() ^== 'COMMAND') then
101 call complain 'Extra env. name not stored over function calls'
102
103 signal afterchk
104
105 checkaddr:
106 address command
107 return
108
109 afterchk:
110
111
112 /*----- does value work at all? -------------------------------------*/
113
114 env = 'SYSTEM'
115 address command
116 address value env
117 if address()^=='SYSTEM' then
118 call complain 'Env does not seem to work with VALUE'
119
120
121 /*----- can value be defaulted --------------------------------------*/
122
123 env = 'COMMAND'
124 address system
125 address (env)
126 if address()^== 'COMMAND' then
127 call complain 'Env can not be ommitted when it is default'
128
129 address(env)
130 if address()^== 'COMMAND' then
131 call complain 'Env can not be ommitted when it is default without space'
132
133
134 /*----- the environment name should not need space around it --------*/
135 signal after_path
136
137 path: return 1
138
139 after_path:
140 rc = -1000
141 address path('true')
142 if address()=='1' then
143 call complain 'env lower priority than value'
144 if rc ^== 0 then
145 call complain 'Something is very wrong with ADDRESS'
146
147 /*----- can we fool it with no space after VALUE? --------------------*/
148
149 env = 'COMMAND'
150 address system
151 address value(env)
152 if (address() ^== 'COMMAND') then
153 call complain 'Dont differ between VALUE and value()'
154
155 signal aftervalue
156
157 value:
158 return 'foobar'
159
160 aftervalue:
161
162
163
164 /* ============================== ARG =============================== */
165 call notify 'arg'
166
167 /*----- can be called without template? ------------------------------*/
168 arg
169
170
171
172 /* ======================= CALL =============================== */
173 call notify 'call'
174
175 /*----- Is RESULT set correctly? -=======-----------------------------*/
176 result = 'foobar'
177 call center '*', 7
178 if result^==' * ' then
179 call complain 'RESULT not set on CALL to routines that return result'
180
181
182 /*----- Is RESULT dropped when not set? ------------------------------*/
183 result = 'foobar'
184 call noret
185 if symbol('RESULT')^=='LIT' then
186 call complain 'RESULT not dropped on CALL that does not return result'
187
188 signal after_noret
189
190 noret:
191 return
192
193 after_noret:
194
195
196 /*----- Params to call evaluate from left to right -------------------*/
197 call incr 1
198 foo = echoargs( incr(), incr(), incr() incr() )
199 if foo ^== '2 3 4 5' then
200 call complain "Parameters to CALL not evaluate from left to right."
201
202
203 /*----- Empty parameters can be created with extra commas ------------*/
204 call num_params 'one',, 'three',,, 'six'
205 signal after_num_params
206
207 num_params:
208 if arg(1)^=='one' | arg(3)^=='three' | arg(6)^=='six' then
209 call complain 'Parameters not correctly set when some are empth'
210
211 if arg(2)^=='' | arg(4)^=='' | arg(5)^=='' | arg(7)^=='' then
212 call complain 'Empty parameters in CALL not interpreted as empty'
213
214 return
215
216 after_num_params:
217
218
219 /*----- SIGL is set when using CALL ----------------------------------*/
220 sigl = 'foobar'
221 call check_sigl
222 if sigl=='foobar' then
223 call complain 'SIGL was set within the routine, not at an outer level'
224
225 signal after_check_sigl
226
227 check_sigl: procedure
228 if sigl^=='SIGL' then
229 call complain 'SIGL set within routine where it should be unset.'
230 return
231
232 after_check_sigl:
233
234
235 /*----- SIGNAL in subroutine does not effect DO-loops in caller ------*/
236 /* Same goes for ITERATE and LEAVE */
237 foo = 'one'
238 do i = 1 to 1
239 call loop_routine
240 foo = 'two'
241 end
242
243 if foo^=='two' then
244 call complain 'DO loop in caller effected by statements in subroutine'
245
246 signal after_loop_routine
247
248 loop_routine:
249 signal loop_routine_2
250 call complain 'Something is very wrong with SIGNAL'
251
252 loop_routine_2:
253 signal on syntax name loop_routine_3
254 iterate
255 call complain 'Something is wrong with plain ITERATE'
256 loop_routine_3:
257 signal on syntax name loop_routine_4
258 iterate i
259 call complain 'Something is wrong with symbolic ITERATE'
260
261 loop_routine_4:
262 signal on syntax name loop_routine_5
263 leave
264 call complain 'Something is wrong with plain LEAVE'
265 loop_routine_5:
266 signal on syntax name loop_routine_6
267 leave i
268 call complain 'Something is wrong with symbolic LEAVE'
269 loop_routine_6:
270 return
271
272 after_loop_routine:
273
274
275
276 /*----- NUMERIC settings are stored across subroutines --------------*/
277 numeric digits 8
278 numeric fuzz 1
279 numeric form engineering
280 call set_numeric
281
282 if (fuzz()\=1) then
283 call complain 'NUMERIC FUZZ not saved across subroutines'
284 if (form()\='ENGINEERING') then
285 call complain 'NUMERIC FORM not saved across subroutines'
286 if (digits()\=8) then
287 call complain 'NUMERIC DIGITS not saved across subroutines'
288
289 numeric digits 8
290 numeric fuzz 1
291 numeric form engineering
292 junk = set_numeric
293
294 if (fuzz()\=1) then
295 call complain 'NUMERIC FUZZ not saved across subroutines'
296 if (form()\='ENGINEERING') then
297 call complain 'NUMERIC FORM not saved across subroutines'
298 if (digits()\=8) then
299 call complain 'NUMERIC DIGITS not saved across subroutines'
300
301 numeric digits 9
302 numeric fuzz 0
303 numeric form scientific
304 signal after_numeric
305
306 set_numeric:
307 numeric digits 9
308 numeric fuzz 0
309 numeric form scientific
310 return ''
311
312 after_numeric:
313
314
315 /*----- ADDRESS setting are stored across subroutines ----------------*/
316 address Unix
317 address Command
318 call set_address_1
319
320 if (address()\='COMMAND') then
321 call complain 'ADDRESS setting not stored across subroutines'
322 address
323 if (address()\='UNIX') then
324 call complain 'ADDRESS setting not stored across subroutines'
325
326 signal after_address_1
327
328 set_address_1:
329 address
330 return
331
332 after_address_1:
333 address Unix
334 address Command
335 junk = set_address_2()
336
337 if (address()\='COMMAND') then
338 call complain 'ADDRESS setting not stored across subroutines'
339 address
340 if (address()\='UNIX') then
341 call complain 'ADDRESS setting not stored across subroutines'
342
343 signal after_address_2
344
345 set_address_2:
346 address system
347 return ""
348
349 after_address_2:
350
351 /*----- Condition traps/information are stored across subroutines ----*/
352 tag = 0
353 signal on syntax name addr_1
354 call change_it
355 tag = 1
356 interpret 'a = b = c = d'
357 signal after_address_3
358
359 change_it:
360 signal on syntax name addr_2
361 return
362
363 addr_1:
364 tag = 2
365 signal after_address_3
366
367 addr_2:
368 if tag=0 then
369 call complain "SYNTAX handler called out of line"
370 else if tag = 1 then
371 call complain "Condition setting not restored after CALL"
372
373 after_address_3:
374
375 cond_info = condition('c') condition('i') condition('d') condition('s')
376 call change_it_2
377 cond_ifo2 = condition('c') condition('i') condition('d') condition('s')
378 if cond_info\==cond_ifo2 then
379 call complain 'Condition information not properly saved during CALL'
380
381 signal after_address_4
382
383 change_it_2:
384 signal on syntax name ignore_addr
385 interpret 'a==b'
386 call complain "Didn't manage to trigger a SYNTAX!"
387 return
388
389 ignore_addr:
390 return
391
392 after_address_4:
393
394 /*----- Check that the elapse time close is saved --------------------*/
395
396 call time 'r'
397 foo = copies('foo ', 200)
398 do 100
399 call words(foo)
400 end
401
402 recorded = time('e')
403 call check_time
404 new = time('e')
405 if recorded > new then
406 call complain 'The elapse time clock seems to have be reset during CALL'
407
408 call time 'r'
409 new = time('e')
410 if (new > recorded) then
411 call complain 'The elapse time clock doesn''t seem to operate correctly'
412
413 signal after_address_5
414
415 check_time:
416 call time 'r'
417 return
418
419 after_address_5:
420
421
422 /*----- Trace setting saved across CALL -------------------------------*/
423
424 normal = 'Normal'
425 trace normal
426
427 call change_trace
428
429 if trace()\=='N' then
430 call complain 'The trace setting was not saved across CALL'
431
432 signal after_address_6
433
434 change_trace:
435 label = 'Label'
436 trace label
437 return
438
439 after_address_6:
440
441
442 /*
443 * Note: tests for limits (number of arguments and depth of nesting
444 * is performed in limits.rexx
445 */
446
447
448 /* ================================================================== */
449 /* ============================== DO ================================ */
450 /* ================================================================== */
451
452 call notify 'do-loops'
453 /*----- First, try a rather simple do-loop ---------------------------*/
454 signal = ""
455 do = 4
456 end = 5
457 then = 1
458 forever = 6
459 iterate = 1
460 do for = forever to do + end by then while iterate
461 signal = signal for
462 end
463
464 /*----- Check value of control variable ------------------------------*/
465 if for ^= 10 then
466 call complain 'Control variable have incorrect value on exit'
467
468 /*----- Did it loop correct? -----------------------------------------*/
469 if signal^==' 6 7 8 9' then
470 call complain 'Did not perform the loop correct'
471
472
473 j = 1
474 do i=-234 to 234 for 500
475 j = j + 1
476 end
477
478 if j\=470 | i\=235 then
479 call complain "Loop starting on negative number fails"
480
481
482 j = 1
483 do i=-23.4 to 23.5 for 50
484 j = j + 1
485 end
486
487 if j\=48 | i\=23.6 then
488 call complain "Fractal loop starting on negative number fails"
489
490
491 /*----- Can we change the value of the ctrl var? ---------------------*/
492 array = ''
493 do i=1 to 10
494 array = array i
495 if i=3 then
496 i = 8
497 end
498
499 if array\==' 1 2 3 9 10' then
500 call complain 'Changing the ctrl var in loop didn''t work'
501
502 /*----- Can we drop and set the control variable ---------------------*/
503 result = ''
504 do i = 1 to 10
505 result = result i
506 j = i
507 drop i
508 i = j + 2
509 end
510 if result ^== ' 1 4 7 10' then
511 call complain 'Cannot drop and set control variable during looping'
512
513
514 /*----- don't loop if end condition is fullfilled initially ----------*/
515 do i=10 to 9
516 call complain 'Ran loop, even when end condition was fullfilled initially'
517 leave
518 end
519
520
521
522 /*----- Is phrases calculated in correct order? ----------------------*/
523 str = ''
524 do i=1 by func(1) for func(0) to func(2)
525 call complain 'Does not handle for-phrase correct'
526 end
527
528 if str ^==' 1 0 2' then
529 call complain 'Incorrect evaluation order for phrases in do-loops'
530
531
532 str = ''
533 do i=func(1) to func(4) by func(2) for func(5)
534 nop
535 end
536
537 if str^==' 1 4 2 5' then
538 call complain 'Expressions in DO-loops are re-evaluated'
539
540
541 signal afterfunc
542 func:
543 str = str arg(1)
544 return arg(1)
545 afterfunc:
546
547
548 /*----- control var should be set before any other evaluation --------*/
549 i = 1
550 array = ''
551 do i = fff(2) to fff(4)
552 leave
553 end
554
555 if array \== ' 1 2' then
556 call complain 'Ctrl var in DO loop assigned incorrectly'
557 signal after_do_9
558
559 fff:
560 array = array i
561 i = arg(1)
562 return arg(1)+1
563
564 after_do_9:
565
566
567 /*----- Check value of i on first invocation -------------------------*/
568 do i='-01' to 1 until 1
569 if (i \== '-1') then
570 call complain 'loop variable not normalized on first iteration'
571 end
572
573
574 /*----- Can we use while (and until) as control variable? ------------*/
575 do while = 1 for 0
576 end
577
578 if while ^== '1' then
579 call complain 'Could not use while as control variable'
580
581
582 /*----- Can we manipulate the control variable? ---------------------*/
583 j = 0
584 do i=1 to 10
585 if i=4 then i=7
586 j = j + 1
587 end
588
589 if j^==7 then
590 call complain 'Can not change value of control variable'
591
592
593 /*----- Can we change to a new control variable during looping? -----*/
594 i = 0
595 j = 0
596 i. = 0
597 do i.i=i.i to 10
598 i = (i+1)//10
599 j = j + 1
600 end
601
602 if j^==101 then
603 call complain 'Can not swap control variable during looping'
604
605 count = 4
606 do i=1 to 10 while count>0
607 count = count - 1
608 end
609
610 if i^=='5' then
611 call complain 'Incorrect sequence in processing DO-loops (while)'
612
613
614 count = 4
615 do i=1 to 10 until count==0
616 count = count - 1
617 end
618
619 if i^=='4' then
620 call complain 'Incorrect sequence in processing DO-loops (until)'
621
622
623 do i=1 to 10 for 4
624 nop
625 end
626
627 if i^=='5' then
628 call complain 'Incorrect sequence in processing DO-loops (for)'
629
630
631 signal on syntax name there_do_1
632 times = '-2'
633 do times
634 call complain 'Allowed negative number for exprr in DO'
635 signal there_do_1
636 end
637
638 there_do_1:
639 signal on syntax name there_do_2
640 do i=1 to 10 for times
641 call complain 'Allowed negative number for exprf in DO'
642 signal there_do_2
643 end
644
645 there_do_2:
646
647
648 count = 1
649 do i=1 to 10 until 1
650 count = count + 1
651 end
652
653 if count\==2 then
654 call complain 'Loop never executed in an UNTIL loop'
655
656
657 /*----- WHILE resevered within an UNTIL, and vice versa --------------*/
658 signal on syntax name there_do_3
659 until='foo'
660 interpret "do forever while until='foo';",
661 " call complain 'Allowed UNTIL within a WHILE in DO';",
662 " leave; end"
663
664 there_do_3:
665 signal on syntax name there_do_4
666 while = 'foo'
667 interpret "do forever until while\='foo';",
668 " call complain 'Allowed WHILE within an UNTIL in DO';",
669 " leave; end;"
670
671 there_do_4:
672
673
674 /*----- TO FOR and BY reserved only in the first part ----------------*/
675 signal on syntax name there_do_5
676 to = 1
677 for = 2
678 by = 3
679 do i=1 while to + for + by > 0
680 signal after_do_5
681 end
682
683 there_do_5:
684 call complain "TO FOR and/or BY unnecessarily reserved in DO"
685 after_do_5:
686
687
688
689 /*----- a symbol can follow END --------------------------------------*/
690 a = 1
691 signal on syntax name check_end_1
692 string = 'do i=1 to 4 ; a=a+1 ; end i'
693 interpret string
694
695 check_end_1:
696 if a\=5 then
697 call complain 'Didn''t allow symbol after ''END'' '
698
699 signal on syntax name check_end_2
700 string = 'do i=1 to 4 ; a=a+1 ; end j'
701 interpret string
702
703 call complain "Didn't catch incorrect symbol after END"
704 check_end_2:
705 signal on syntax name check_end_3
706 sigl = ''
707 j = 1
708 a=5 /* just to be sure */
709 i.2 = 3
710 string = 'do i.j=1 to 4; a=a+1; if i.j=2 then j=2; end i.j'
711 interpret string
712
713 check_end_3:
714 if sigl\='' then
715 call complain "Didn't like compound symbol after END"
716 else if a\=8 then
717 call complain "Didn't iterate correct number of times"
718
719
720 signal on syntax name check_end_4
721 sigl = ''
722 a = 8
723 j = 1
724 i.2 = 3
725 string = 'do i.j=1 to 4; a=a+1; end i.1'
726 interpret string
727
728 check_end_4:
729 if sigl=='' then
730 call complain "Allowed substitution in compound symbol after END"
731 else if a\=8 then
732 call complain "Didn't iterate correct number of times"
733
734
735
736 /*----- some extra testing -------------------------------------------*/
737 tag = 0
738 signal on syntax name do_while
739 do while=5
740 tag = tag + 1
741 leave
742 end
743
744 if tag=0 then
745 call complain "WHILE incorrectly allowed in exprr"
746
747 signal after_while_1
748
749 do_while:
750 call complain "WHILE not allowed as a name (correct?)"
751
752 after_while_1:
753 signal off syntax
754
755
756
757 /* ============================= DROP =============================== */
758 call notify 'drop'
759
760 foo = 1
761 foo. = 2
762 bar.bar = 3
763 drop foo foo. bar.bar
764
765 if symbol('foo')\=='LIT' then
766 call complain 'DROP didn''t work with simple variables'
767
768 if symbol('foo.')\=='LIT' then
769 call complain 'DROP didn''t work with stem variables'
770
771 if symbol('foo.123')\=='LIT' then
772 call complain 'DROP didn''t work with compound variables'
773
774 if symbol('bar.bar')\=='LIT' then
775 call complain 'DROP didn''t work with compound variables'
776
777 aaa = 1
778 bbb = 2
779 ccc = 3
780 ddd = 4
781 vars = ' aaa bbb ccc ddd'
782 drop foo (vars) bar
783 if symbol('aaa')symbol('aaa')symbol('aaa')symbol('aaa')\=='LITLITLITLIT' then
784 call complain 'Didn''t manage to drop variables indirectly'
785
786 if symbol('vars')\=='VAR' then
787 call complain 'Dropped indirect variable as well, should not'
788
789
790 bar = 'asdf'
791 foo = 'asdf'
792 vars1 = 'foo'
793 vars2 = 'bar'
794 drop vars1 (vars2) (vars1) vars2
795 if symbol('foo')\=='VAR' | symbol('bar')\=='LIT' then
796 call complain 'Variables not dropped strictly in order from left to right'
797
798 foo = 'asdf'
799 drop bar
800 drop bar bar foo foo
801
802
803 foo = 'bar'
804 call test_drop
805 signal after_drop_1
806
807 test_drop:
808 procedure expose foo
809 drop foo
810 return
811
812 if symbol('foo')\=='LIT' then
813 call complain 'EXPOSED variable not dropped in caller'
814
815 after_drop_1:
816
817
818 /*----- drop on a stem drops all its compounds -----------------------*/
819 bar = 'BAR'
820 foo.bar = 'barf'
821 drop foo.
822 if foo.bar == 'barf' then
823 call complain 'Drop on stem does not drop compounds of that stem'
824 else if foo.bar ^== 'FOO.BAR' then
825 call complain 'Something is very wrong about dropping of stems'
826
827
828
829 /* ============================= EXIT =============================== */
830
831
832 /* ================================================================== */
833 /* ============================== IF ================================ */
834 /* ================================================================== */
835 call notify 'if'
836
837 /*----- the ';' can not replace a statement after 'then' ------------ */
838 do i=0 to 1
839 str = ''
840 if i then ;
841 str = 'hepp'
842
843 if str=='hepp' && i then
844 call complain 'Null-clause in THEN-part of IF-statement'
845
846 str = ''
847 if i then
848 a=b
849 else ;
850 str = hepp
851
852 if str=='' && i then
853 call complain 'Null-clause in ELSE-part of IF-statement'
854
855 str = ''
856 if i then nop
857 str = 'hepp'
858
859 if str^=='hepp' then
860 call complain 'NOP is ignored in IF statement'
861
862 str = ''
863 if i then
864 a=b
865 else
866 nop
867 str = 'hepp'
868
869 if str^=='hepp' then
870 call complain 'NOP is ignored in IF statement'
871 end
872
873
874 /*----- does 'else' bind correctly? --------------------------------- */
875 if 0 then
876 if 1 then
877 nop
878 else
879 call complain "ELSE does not bind correctly in IF-statements"
880 nop
881
882
883 /*----- can then be used as variable in extr -------------------------*/
884 then = '2'
885 if '1 2' = 1 then
886 call complain "then may be used in IF-expr as a variable"
887
888 /*----- whitespace handling in non-exact comparisons -----------------*/
889 a = '0a'x
890 b = ' '
891 if a \= b then
892 call complain "non-exact comparison doesn't treat whitespace correctly"
893 OPTIONS STRICT_WHITE_SPACE_COMPARISONS
894 if a = b then
895 call complain "non-exact comparison doesn't treat whitespace correctly"
896 OPTIONS NOSTRICT_WHITE_SPACE_COMPARISONS
897
898
899 /* ===================== INTERPRET ============================ */
900
901 interpret 'interpret "a=1";a=a+1'
902 if a\=2 then
903 call complain "couldn't nest INTERPRET"
904
905 /* ================================================================== */
906 /* ============================ ITERATE ============================= */
907 /* ================================================================== */
908 call notify 'iterate'
909
910 /*----- does iterate work at all ? -------------------------------------*/
911 k = 0
912 do i=1 to 20
913 if i>7 then
914 iterate
915 k = k + 1
916 end
917
918 if k^=='7' then
919 call complain 'ITERATE does not work correctly'
920
921
922 /*----- does it iterate the right level --------------------------------*/
923 k=0
924 do l=1 to 2
925 do i=1 to 10
926 do j=1 to 10
927 if (i>4) & (j>5) then
928 iterate i
929 k = k + 1
930 end
931 end
932 end
933
934 if k^=='140' then
935 call complain 'ITERATE "var" does not leave right level'
936
937
938 /*----- can we fool the interpreter to iterate another loop -----------*/
939
940 k = 0
941 i = 1
942 j = 2
943 do i.i=1 to 10
944 temp = i.i
945 do i.j=1 to 10
946 if (i.i>3) & (i.j>6) then do
947 i.i = temp
948 i = 2
949 iterate i.i
950 end
951 k = k + 1
952 end
953 i.i = temp
954 end
955
956 if k^==54 then
957 call complain 'Substitution suspected in ITERATE variable'
958
959
960 /*----- can we terminate inactive loop ------------------------------*/
961 /*
962 * k = 0
963 * do i=1 to 10
964 * if i=3 then
965 * interpret 'iterate'
966 * k = k + 1
967 * end
968 *
969 * if i^==11 then
970 * call complain 'INTERPRET ITERATE can terminate inactive loop'
971 */
972
973
974 /*----- if two loops use same control variable -----------------------*/
975
976 l = 0
977 do i=1 to 10
978 k = i
979 do i=1 to 10
980 l = l + 1
981 if k>6 then
982 iterate i
983 end
984 i = k
985 end
986
987 if l^==100 then
988 call complain "ITERATE doesn't leave innermost loop when identical ctrlvars"
989
990
991 /*----- can we fool iterate with a non-repetitive loop ----------------*/
992 k = ''
993 do i=1 to 3
994 if i=2 then do
995 nop
996 iterate
997 end
998 k = k i
999 end
1000
1001 if k^==' 1 3' then
1002 call complain 'ITERATE is fooled by a non-repetitive loop'
1003
1004
1005
1006
1007
1008 /* ================================================================== */
1009 /* ============================= LEAVE ============================== */
1010 /* ================================================================== */
1011 call notify 'leave'
1012
1013 /*----- does leave work at all ? -------------------------------------*/
1014 do i=0 to 20
1015 if i==7 then
1016 leave
1017 end
1018
1019 if i^=='7' then
1020 call complain 'LEAVE does not work correctly'
1021
1022
1023 /*----- does it leave the right level --------------------------------*/
1024 k=0
1025 do l=1 to 2
1026 do i=1 to 10
1027 do j=1 to 10
1028 if (i>4) & (j>5) then
1029 leave i
1030 k = k + 1
1031 end
1032 end
1033 end
1034
1035 if k^=='90' then
1036 call complain 'LEAVE "var" does not leave right level'
1037
1038
1039 /*----- can we fool the interpreter to leave another loop -----------*/
1040 k = 0
1041 i = 1
1042 j = 2
1043 do i.i=1 to 10
1044 do i.j=1 to 10
1045 k = k + 1
1046 if (i.i=3) & (i.j=6) then do
1047 i = 2
1048 leave i.i
1049 end
1050 end
1051 end
1052
1053 if k^==26 then
1054 call complain 'Substitution suspected in LEAVE variable'
1055
1056
1057 /*----- can we terminate inactive loop ------------------------------*/
1058 /*
1059 * do i=1 to 10
1060 * if i=3 then
1061 * interpret leave
1062 * end
1063 *
1064 * if i^==11 then
1065 * call complain 'INTERPRET LEAVE can terminate inactive loop'
1066 */
1067
1068
1069 /*----- if two loops use same control variable -----------------------*/
1070 l = 0
1071 do i=1 to 10
1072 k = i
1073 do i=1 to 10
1074 if i=6 then
1075 leave i
1076 l = l + 1
1077 end
1078 i = k
1079 end
1080
1081 if l^==50 then
1082 call complain 'LEAVE does not leave innermost loop when identical ctrlvars'
1083
1084
1085 /*----- can we fool leave with a non-repetitive loop ----------------*/
1086 do i=1 to 10
1087 if i=4 then do
1088 nop
1089 leave
1090 nop
1091 end
1092 end
1093
1094 if i^=='4' then
1095 call complain 'LEAVE is fooled by a non-repetitive loop'
1096
1097
1098
1099 /* ======================== NOP =============================== */
1100 /* ====================== NUMERIC ============================= */
1101 /* ====================== OPTIONS ============================= */
1102
1103
1104 /* ================================================================== */
1105 /* ============================= PARSE ============================== */
1106 /* ================================================================== */
1107 call notify 'parsing'
1108
1109 string1 = 'Det er sikkert mange utlendinger som ikke kan lese dette'
1110
1111 /*----- Test if they work correctly ----------------------------------*/
1112 parse var string1 before 'sikkert' between 9 .
1113 if (before^=='Det er ') then
1114 call complain "litteral patterns can not overlap positional patterns"
1115
1116 parse var string1 -10 all 100
1117 if (all^==string1) then
1118 call complain "confused when offsets are outside string boundaries"
1119
1120 parse value 'hello' with 2 foo +3
1121 if (foo\=='ell') then
1122 call complain "confused by absolute and relative patterns"
1123
1124 parse var string1 . 'sikkert' word 'utlendinger' .
1125 if (word^==' mange ') then
1126 call complain "does not handle spaces between words correctly"
1127
1128 parse var string1 . 'sikkert' word . 'utlendinger' .
1129 if (word^=='mange') then
1130 call complain "does not handle spaces between words correctly"
1131
1132
1133 /*----- can assignment to one var be assigned later in same templ. ---*/
1134 parse var string1 . 'si' tmp 'ert' . (tmp) testing +7 .
1135 if testing^=='kke kan' then
1136 call complain 'Variable assigned in a PARSE can not be references later'
1137
1138 parse var string1 . 'si' tmp 'ert' . (tmp) +0 testing +5 .
1139 if testing^=='kke k' then
1140 call complain 'The pattern +0 does not work in PARSE'
1141
1142 parse value "hepp" with 1 var1 1 var2 1 var3 1
1143 if (var1^=="hepp" | var2^=="hepp" | var3^=="hepp") then
1144 call complain "can't handle multiple assignement"
1145
1146 parse value "hest" with var1 "s" -1 var2 +2 -1 var3
1147 if (var1^=="he" | var2^=="es" | var3^=="st") then
1148 call complain "Something is wrong with relative offsets"
1149
1150
1151 /*----- Stems can be set during parse --------------------------------*/
1152 foo.bar = 'hallo'
1153 foo = 'nope'
1154 parse value 'hepp' with foo. .
1155
1156 if foo. ^== 'hepp' then
1157 call complain 'Parse did not manage to set stem variable.'
1158
1159
1160 /*----- Nullstrings matches End-Of-String ----------------------------*/
1161 foo = "Foo bar"
1162 parse var foo pre '' post
1163 if (foo^=='Foo bar') | (post^=='') then
1164 call complain 'Nullstrings as patterns do not match end-of-string'
1165
1166
1167 /*----- Variable positional patterns ---------------------------------*/
1168 a = 3
1169 b = 4
1170 c = 5
1171 foo = 'foo bar baz'
1172 parse var foo x1 =(a) x2 +(b) x3 -(c) x4
1173 if x1\=='fo' then
1174 call complain 'Variable positional pattern = does not work correctly'
1175
1176 if x2\=='o ba' then
1177 call complain 'Variable positional patterns = or + do not work'
1178
1179 if x3\=='r baz' then
1180 call complain 'Variable positional pattern - does not work'
1181
1182 if x4\=='oo bar baz' then
1183 call complain 'Variable positional pattern - does still not work'
1184
1185
1186 /* ================================================================== */
1187 /* ============================ PROCDURE ============================ */
1188 /* ================================================================== */
1189 call notify 'procecure'
1190
1191 /*--------------------------------------------------------------------*/
1192 /* Test ability to properly expose variables */
1193 /*--------------------------------------------------------------------*/
1194
1195 /*---- check a few things --------------------------------------------*/
1196
1197 a = 'hello'
1198 bar.1 = 'oops'
1199 foo.1 = 'yupp'
1200 test.2 = 'hepp'
1201 test.X.1 = 'foobar'
1202 foo.b = 'nope'
1203 b = 1
1204
1205 call checkit
1206
1207 signal aftercheckit
1208
1209
1210 checkit: procedure expose bar.b b foo.b test. test.1 test.b,
1211 test. test.X.B bbb.123 bbb.
1212
1213 if (foo.1 ^= 'yupp') then
1214 call complain "Don't substitute indexes during expose"
1215
1216 if (test.X.1 ^== "foobar") then
1217 call complain "Don't handle last in a list of exposees"
1218
1219 if (bar.1 ^== 'BAR.1') then
1220 call complain "substitutes too much in indexes during expose"
1221
1222 if (test.2 ^== 'hepp') then
1223 call complain 'Expose of stems does not expose all compounds'
1224
1225 test.1 = 'foo'
1226 test.2 = 'bar'
1227 bbb. = 'baz'
1228 return
1229
1230 aftercheckit:
1231
1232 if (test.1 \=='foo') then
1233 call complain "Didn't properly handle explicit expose for compounds"
1234
1235 if (test.2 \== 'bar') then
1236 call complain "Didn't properly handle implicit expose for compounds"
1237
1238 if bbb.123 \== 'baz' then
1239 call complain "Didn't properly handle expose of stems"
1240
1241 if bbb.1 \== 'baz' then
1242 call complain "Didn't handle var exposed as both stem and compound"
1243
1244 /* ====================== RETURN ============================== */
1245 /* ======================== SAY =============================== */
1246
1247
1248 /* ================================================================== */
1249 /* ============================ SELECT ============================== */
1250 /* ================================================================== */
1251 call notify 'select'
1252
1253 /*----- does it calculate in correct order? --------------------------*/
1254 /*----- last when and the otherwise should be skipped, and -----------*/
1255 /*----- string should have a particular order ------------------------*/
1256 str = ''
1257 select
1258 when func(0)=2 then str=asdf
1259 when func(1)=2 then str=asdf
1260 when func(2)=2 then str=str 'hepp'
1261 when func(3)=2 then str=asdf
1262 otherwise
1263 str=asdf
1264 end
1265
1266 if str^==' 0 1 2 hepp' then
1267 call complain 'SELECT does not operate correctly'
1268
1269 /*----- Can we do without an otherwise? ----------------------------*/
1270 select
1271 when 0 then nop
1272 when 1 then nop
1273 when 0 then nop
1274 end /* this should not result in a syntax error */
1275
1276
1277 /*----- A semicolon should not be interpreted as nop after then -----*/
1278 str = ''
1279 select
1280 when 1 then ;
1281 str = 'hepp'
1282 when 1 then nop
1283 end
1284
1285 if str^=='hepp' then
1286 call complain 'Semi after then in select interpreted as statement'
1287
1288
1289
1290 /* ====================== SIGNAL ============================== */
1291 call notify 'signal'
1292 signal next_sig
1293 call complain 'simple SIGNAL statement failed'
1294
1295 next_sig:
1296 signal off novalue
1297 signal value nextsig2
1298 call complain 'SIGNAL statement with VALUE did not work'
1299
1300 nextsig2:
1301 with = 'NEXT_SIG_3'
1302 signal value with /* hehe ... */
1303 call complain 'WITH has special meaning in SIGNAL VALUE'
1304
1305 next_sig_3:
1306
1307
1308
1309 /* ======================= TRACE ============================== */
1310 call notify 'trace'
1311
1312 /* Only first character counts in trace settings */
1313 trace off
1314 trace offset
1315 trace on
1316 trace o
1317 trace oooooooooooooooooooooooooooooooooooooooooooo
1318
1319
1320 say ' '
1321 exit 0
1322
1323
1324 echoargs:
1325 do i=1 to arg()
1326 if i=1 then
1327 result = arg(1)
1328 else
1329 result = result arg(i)
1330 end
1331 return result
1332
1333
1334 incr:
1335 if arg()>0 then
1336 increment = arg(1)
1337 else
1338 increment = increment + 1
1339 return increment
1340
1341
1342
1343
1344 ch: procedure expose sigl
1345 parse arg first, second
1346 if first ^== second then do
1347 say
1348 say "first= /"first"/"
1349 say "second=/"second"/"
1350 say "FuncTrip: error in " sigl":" sourceline(sigl) ; end
1351 return
1352
1353
1354 notify:
1355 parse arg word .
1356 written = written + length(word) + 2
1357 if written>75 then do
1358 written = length(word)
1359 say ' '
1360 end
1361 call charout , word || ', '
1362 return
1363
1364
1365 error:
1366 say 'Error discovered in function insert()'
1367 return
1368
1369 complain:
1370 say ' ...'
1371 say 'Tripped in line' sigl':' arg(1)'.'
1372 length = charout(,' (')
1373 return
1374
1375
1376