| 1 |
(* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 2, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) |
| 17 |
|
| 18 |
MODULE testsystem ; |
| 19 |
|
| 20 |
FROM SYSTEM IMPORT BITSPERLOC, LOCSPERWORD, |
| 21 |
LOC, BYTE, WORD, ADDRESS, |
| 22 |
ADDADR, SUBADR, DIFADR, MAKEADR, ADR, ROTATE, |
| 23 |
SHIFT, TSIZE ; |
| 24 |
FROM libc IMPORT exit ; |
| 25 |
FROM NumberIO IMPORT WriteCard ; |
| 26 |
FROM StrIO IMPORT WriteString, WriteLn ; |
| 27 |
FROM FIO IMPORT Close, StdOut ; |
| 28 |
|
| 29 |
|
| 30 |
PROCEDURE FindFirstElement (start: CARDINAL; s: LargeSet) : CARDINAL ; |
| 31 |
BEGIN |
| 32 |
WHILE NOT (start IN s) DO |
| 33 |
INC(start) |
| 34 |
END ; |
| 35 |
RETURN( start ) |
| 36 |
END FindFirstElement ; |
| 37 |
|
| 38 |
|
| 39 |
PROCEDURE FindLastElement (start: CARDINAL; s: LargeSet) : CARDINAL ; |
| 40 |
BEGIN |
| 41 |
WHILE (start+1<1024) AND ((start+1) IN s) DO |
| 42 |
INC(start) |
| 43 |
END ; |
| 44 |
RETURN( start ) |
| 45 |
END FindLastElement ; |
| 46 |
|
| 47 |
|
| 48 |
PROCEDURE debug (s: LargeSet) ; |
| 49 |
VAR |
| 50 |
lo, hi: CARDINAL ; |
| 51 |
BEGIN |
| 52 |
IF s=LargeSet{} |
| 53 |
THEN |
| 54 |
WriteString('{}') |
| 55 |
ELSE |
| 56 |
WriteString('{') ; |
| 57 |
lo := FindFirstElement(0, s) ; |
| 58 |
hi := FindLastElement(lo, s) ; |
| 59 |
WHILE hi<1024 DO |
| 60 |
IF hi=lo |
| 61 |
THEN |
| 62 |
WriteCard(lo, 0) |
| 63 |
ELSE |
| 64 |
WriteCard(lo, 0) ; WriteString('..') ; WriteCard(hi, 0) |
| 65 |
END ; |
| 66 |
lo := FindFirstElement(hi+1, s) ; |
| 67 |
hi := FindLastElement(lo, s) ; |
| 68 |
IF hi<1024 |
| 69 |
THEN |
| 70 |
WriteString(', ') |
| 71 |
END |
| 72 |
END ; |
| 73 |
WriteString('}') |
| 74 |
END ; |
| 75 |
WriteLn |
| 76 |
END debug ; |
| 77 |
|
| 78 |
|
| 79 |
(* |
| 80 |
* purpose of testsystem is to check that all ISO SYSTEM functions are |
| 81 |
* implemented, compile and run. |
| 82 |
*) |
| 83 |
|
| 84 |
TYPE |
| 85 |
LargeSet = SET OF [0..1023] ; |
| 86 |
SmallSet = SET OF [0..3] ; |
| 87 |
|
| 88 |
VAR |
| 89 |
a1, a2: ADDRESS ; |
| 90 |
b1, b2: BYTE ; |
| 91 |
s1, s2: BITSET ; |
| 92 |
s3, s4: LargeSet ; |
| 93 |
c1, c2: CARDINAL ; |
| 94 |
w : WORD ; |
| 95 |
l : LOC ; |
| 96 |
array : ARRAY [0..TSIZE(ADDRESS)-1] OF LOC ; |
| 97 |
s5, s6: SmallSet ; |
| 98 |
BEGIN |
| 99 |
a1 := ADR(array) ; |
| 100 |
a2 := ADDADR(a1, TSIZE(LOC)) ; |
| 101 |
IF SUBADR(a2, TSIZE(LOC))#a1 |
| 102 |
THEN |
| 103 |
Close(StdOut) ; |
| 104 |
exit(1) |
| 105 |
END ; |
| 106 |
IF DIFADR(a2, a1) # INTEGER (TSIZE (LOC)) |
| 107 |
THEN |
| 108 |
Close(StdOut) ; |
| 109 |
exit(2) |
| 110 |
END ; |
| 111 |
a1 := MAKEADR (ADDRESS (0)) ; |
| 112 |
IF a1#NIL |
| 113 |
THEN |
| 114 |
Close(StdOut) ; |
| 115 |
exit(3) |
| 116 |
END ; |
| 117 |
|
| 118 |
(* |
| 119 |
#if defined(__x86_64) |
| 120 |
a1 := MAKEADR(BYTE(0ABH), BYTE(0CDH)) ; |
| 121 |
a1 := MAKEADR(BYTE(0FEH), BYTE(0DCH), BYTE(0BAH), BYTE(098H), |
| 122 |
BYTE(076H), BYTE(054H), BYTE(032H), BYTE(010H)) ; |
| 123 |
|
| 124 |
a1 := MAKEADR(CARDINAL(123456789), CARDINAL(987654321)) ; |
| 125 |
#endif |
| 126 |
*) |
| 127 |
s3 := LargeSet{0, 1, 31, 32, 33, 63, 64, 65, 127, 128, 129} ; |
| 128 |
debug(s3) ; |
| 129 |
s4 := SHIFT(s3, -1) ; |
| 130 |
debug(s4) ; |
| 131 |
IF s4#LargeSet{0, 30, 31, 32, 62, 63, 64, 126, 127, 128} |
| 132 |
THEN |
| 133 |
Close(StdOut) ; |
| 134 |
exit(4) |
| 135 |
END ; |
| 136 |
s4 := SHIFT(s4, 1) ; |
| 137 |
debug(s4) ; |
| 138 |
IF s4#LargeSet{1, 31, 32, 33, 63, 64, 65, 127, 128, 129} |
| 139 |
THEN |
| 140 |
Close(StdOut) ; |
| 141 |
exit(5) |
| 142 |
END ; |
| 143 |
s5 := SmallSet{0, 1} ; |
| 144 |
s6 := ROTATE(s5, 1) ; |
| 145 |
IF s6#SmallSet{1, 2} |
| 146 |
THEN |
| 147 |
Close(StdOut) ; |
| 148 |
exit(6) |
| 149 |
END ; |
| 150 |
s5 := SmallSet{0, 1} ; |
| 151 |
s6 := ROTATE(s5, -1) ; |
| 152 |
IF s6#SmallSet{0, 3} |
| 153 |
THEN |
| 154 |
Close(StdOut) ; |
| 155 |
exit(7) |
| 156 |
END ; |
| 157 |
s3 := LargeSet{0, 1, 31, 32, 33, 63, 64, 65, 127, 128, 129} ; |
| 158 |
debug(s3) ; |
| 159 |
s4 := ROTATE(s3, -1) ; |
| 160 |
debug(s4) ; |
| 161 |
IF s4#LargeSet{1023, 0, 30, 31, 32, 62, 63, 64, 126, 127, 128} |
| 162 |
THEN |
| 163 |
Close(StdOut) ; |
| 164 |
exit(8) |
| 165 |
END ; |
| 166 |
s3 := LargeSet{1, 31, 32, 33, 63, 64, 65, 127, 128, 129, 255, 1023} ; |
| 167 |
debug(s3) ; |
| 168 |
s4 := ROTATE(s3, 1) ; |
| 169 |
debug(s4) ; |
| 170 |
IF s4#LargeSet{0, 2, 32, 33, 34, 64, 65, 66, 128, 129, 130, 256} |
| 171 |
THEN |
| 172 |
Close(StdOut) ; |
| 173 |
exit(9) |
| 174 |
END |
| 175 |
END testsystem. |
| 176 |
(* |
| 177 |
* Local variables: |
| 178 |
* compile-command: "gm2 -Wcpp -Wiso -c -g -I. testsystem.mod" |
| 179 |
* End: |
| 180 |
*) |