tests.fs (6425B)
1 \ this test suite is adapted from the forth standard test suite. not all tests 2 \ are included. 3 4 \ f.3.1 - basic assumptions 5 t{ -> }t \ this test should pass 6 t{ -> 1 }t \ this test should fail 7 8 t{ ( a comment)1234 -> 1234 }t 9 t{ : pc1 ( a comment)1234 ; pc1 -> 1234 }t 10 11 \ f.3.2 - booleans 12 t{ false not -> true }t 13 t{ true not -> false }t 14 15 t{ false false and -> false }t 16 t{ false true and -> false }t 17 t{ true false and -> false }t 18 t{ true true and -> true }t 19 20 t{ false false or -> false }t 21 t{ false true or -> true }t 22 t{ true false or -> true }t 23 t{ true true or -> true }t 24 25 t{ false false xor -> false }t 26 t{ false true xor -> true }t 27 t{ true false xor -> true }t 28 t{ true true xor -> false }t 29 30 \ f.3.3 - shifts 31 hex 32 t{ 1 0 lshift -> 1 }t 33 t{ 1 1 lshift -> 2 }t 34 t{ 1 2 lshift -> 4 }t 35 t{ 1 F lshift -> 8000 }t 36 t{ true 1 lshift 1 xor -> true }t 37 38 t{ 1 0 rshift -> 1 }t 39 t{ 1 1 rshift -> 0 }t 40 t{ 2 1 rshift -> 1 }t 41 t{ 4 2 rshift -> 1 }t 42 t{ 8000 F rshift -> 1 }t 43 44 \ f.3.5 - comparisons 45 0 not constant max-uint 46 0 not 1 rshift constant max-int 47 0 not 1 rshift not constant min-int 48 49 t{ 0 0= -> true }t 50 t{ 1 0= -> false }t 51 t{ 2 0= -> false }t 52 t{ -1 0= -> false }t 53 t{ max-uint 0= -> false }t 54 t{ min-int 0= -> false }t 55 t{ max-int 0= -> false }t 56 57 t{ 0 0 = -> true }t 58 t{ 1 1 = -> true }t 59 t{ -1 -1 = -> true }t 60 t{ 1 0 = -> false }t 61 t{ -1 0 = -> false }t 62 t{ 0 1 = -> false }t 63 t{ 0 -1 = -> false }t 64 t{ 1 -1 = -> false }t 65 t{ -1 1 = -> false }t 66 67 t{ 0 1 < -> true }t 68 t{ 1 2 < -> true }t 69 t{ -1 0 < -> true }t 70 t{ -1 1 < -> true }t 71 t{ 1 0 < -> false }t 72 t{ 2 1 < -> false }t 73 t{ 0 -1 < -> false }t 74 t{ 1 -1 < -> false }t 75 t{ 0 0 < -> false }t 76 t{ 1 1 < -> false }t 77 t{ min-int 0 < -> true }t 78 t{ min-int max-int < -> true }t 79 t{ 0 max-int < -> true }t 80 t{ 0 min-int < -> false }t 81 t{ max-int min-int < -> false }t 82 t{ max-int 0 < -> false }t 83 84 t{ 0 1 > -> false }t 85 t{ 1 2 > -> false }t 86 t{ -1 0 > -> false }t 87 t{ -1 1 > -> false }t 88 t{ 1 0 > -> true }t 89 t{ 2 1 > -> true }t 90 t{ 0 -1 > -> true }t 91 t{ 1 -1 > -> true }t 92 t{ 0 0 > -> false }t 93 t{ 1 1 > -> false }t 94 t{ min-int 0 > -> false }t 95 t{ min-int max-int > -> false }t 96 t{ 0 max-int > -> false }t 97 t{ 0 min-int > -> true }t 98 t{ max-int min-int > -> true }t 99 t{ max-int 0 > -> true }t 100 101 t{ 0 1 min -> 0 }t 102 t{ 1 2 min -> 1 }t 103 t{ -1 0 min -> -1 }t 104 t{ -1 1 min -> -1 }t 105 t{ 1 0 min -> 0 }t 106 t{ 2 1 min -> 1 }t 107 t{ 0 -1 min -> -1 }t 108 t{ 1 -1 min -> -1 }t 109 t{ 0 0 min -> 0 }t 110 t{ 1 1 min -> 1 }t 111 t{ min-int 0 min -> min-int }t 112 t{ min-int max-int min -> min-int }t 113 t{ 0 max-int min -> 0 }t 114 t{ 0 min-int min -> min-int }t 115 t{ max-int min-int min -> min-int }t 116 t{ max-int 0 min -> 0 }t 117 118 t{ 0 1 max -> 1 }t 119 t{ 1 2 max -> 2 }t 120 t{ -1 0 max -> 0 }t 121 t{ -1 1 max -> 1 }t 122 t{ 1 0 max -> 1 }t 123 t{ 2 1 max -> 2 }t 124 t{ 0 -1 max -> 0 }t 125 t{ 1 -1 max -> 1 }t 126 t{ 0 0 max -> 0 }t 127 t{ 1 1 max -> 1 }t 128 t{ min-int 0 max -> 0 }t 129 t{ min-int max-int max -> max-int }t 130 t{ 0 max-int max -> max-int }t 131 t{ 0 min-int max -> 0 }t 132 t{ max-int min-int max -> max-int }t 133 t{ max-int 0 max -> max-int }t 134 135 \ f.3.6 - stack operators 136 t{ 1 2 drop -> 1 }t 137 t{ 0 drop -> }t 138 t{ 1 dup -> 1 1 }t 139 t{ 1 2 over -> 1 2 1 }t 140 t{ 1 2 swap -> 2 1 }t 141 t{ 1 2 nip -> 2 }t 142 t{ 1 2 tuck -> 2 1 2 }t 143 t{ 1 2 3 2drop -> 1 }t 144 t{ 1 2 2drop -> }t 145 t{ 1 2 2dup -> 1 2 1 2 }t 146 147 \ f.3.7 - return stack operators 148 t{ : gr1 >r r> ; -> }t 149 t{ : gr2 >r r@ r> drop ; -> }t 150 t{ 123 gr1 -> 123 }t 151 t{ 123 gr2 -> 123 }t 152 t{ true gr1 -> true }t 153 154 \ f.3.8 - addition and subtraction (and other math operators) 155 t{ 0 5 + -> 5 }t 156 t{ 5 0 + -> 5 }t 157 t{ 0 -5 + -> -5 }t 158 t{ -5 0 + -> -5 }t 159 t{ 1 2 + -> 3 }t 160 t{ 1 -2 + -> -1 }t 161 t{ -1 2 + -> 1 }t 162 t{ -1 -2 + -> -3 }t 163 t{ -1 1 + -> 0 }t 164 165 t{ 0 5 - -> -5 }t 166 t{ 5 0 - -> 5 }t 167 t{ 0 -5 - -> 5 }t 168 t{ -5 0 - -> -5 }t 169 t{ 1 2 - -> -1 }t 170 t{ 1 -2 - -> 3 }t 171 t{ -1 2 - -> -3 }t 172 t{ -1 -2 - -> 1 }t 173 t{ 1 1 - -> 0 }t 174 175 t{ 0 abs -> 0 }t 176 t{ 1 abs -> 1 }t 177 t{ -1 abs -> 1 }t 178 t{ min-int abs -> mid-uint+1 }t 179 180 t{ 0 negate -> 0 }t 181 t{ 1 negate -> -1 }t 182 t{ -1 negate -> 1 }t 183 t{ 2 negate -> -2 }t 184 t{ -2 negate -> 2 }t 185 186 \ f.3.9 - multiplication 187 t{ 0 0 * -> 0 }t 188 t{ 0 1 * -> 0 }t 189 t{ 1 0 * -> 0 }t 190 t{ 1 2 * -> 2 }t 191 t{ 2 1 * -> 2 }t 192 t{ 3 3 * -> 9 }t 193 t{ -3 3 * -> -9 }t 194 t{ 3 -3 * -> -9 }t 195 t{ -3 -3 * -> 9 }t 196 197 \ f.3.11 memory 198 here 1 , 199 here 2 , 200 constant 2nd 201 constant 1st 202 203 t{ 1st 2nd < -> true }t 204 t{ 1st cell+ -> 2nd }t 205 t{ 1st 1 cells + -> 2nd }t 206 t{ 1st @ 2nd @ -> 1 2 }t 207 t{ 5 1st ! -> }t 208 t{ 1st @ 2nd @ -> 5 2 }t 209 t{ 6 2nd ! -> }t 210 t{ 1st @ 2nd @ -> 5 6 }t 211 t{ 1st 2@ -> 6 5 }t 212 t{ 2 1 1st 2! -> }t 213 t{ 1st 2@ -> 2 1 }t 214 t{ true 1st ! 1st @ -> true }t 215 216 t{ 0 1st ! -> }t 217 t{ 1 1st +! -> }t 218 t{ 1st @ -> 1 }t 219 t{ -1 1st +! 1st @ -> 0 }t 220 221 here 1 c, 222 here 2 c, 223 align 224 constant 2nd-c 225 constant 1st-c 226 227 t{ 1st-c 2nd-c < -> true }t 228 t{ 1st-c char+ -> 2nd-c }t 229 t{ 1st-c 1 chars + -> 2nd-c }t 230 t{ 1st-c c@ 2nd-c c@ -> 1 2 }t 231 t{ 3 1st-c c! -> }t 232 t{ 1st-c c@ 2nd-c c@ -> 3 2 }t 233 t{ 4 2nd-c c! -> }t 234 t{ 1st-c c@ 2nd-c c@ -> 3 4 }t 235 236 \ f.3.12 characters 237 t{ bl -> hex 20 }t 238 239 t{ char x -> hex 78 }t 240 t{ char hello -> hex 68 }t 241 242 t{ : gc1 [char] x ; -> }t 243 t{ : gc2 [char] hello ; -> }t 244 t{ gc1 -> hex 78 }t 245 t{ gc2 -> hex 68 }t 246 247 t{ : gc3 [ gc1 ] literal ; -> }t 248 t{ gc3 -> hex 78 }t 249 250 t{ : gc4 " xy" ; -> }t 251 t{ gc4 nip -> 2 }t 252 t{ gc4 drop dup c@ swap char+ c@ -> hex 78 79 }t 253 t{ : gc5 " a string"2drop ; -> }t 254 t{ gc5 -> }t 255 256 \ f.3.14 flow control 257 t{ : gi1 if 123 then ; -> }t 258 t{ : gi2 if 123 else 234 then ; -> }t 259 t{ 0 gi1 -> }t 260 t{ 1 gi1 -> 123 }t 261 t{ -1 gi1 -> 123 }t 262 t{ 0 gi2 -> 234 }t 263 t{ 1 gi2 -> 123 }t 264 t{ -1 gi2 -> 123 }t 265 266 t{ : gi3 begin dup 5 < while dup 1 + repeat ; -> }t 267 t{ 0 gi3 -> 0 1 2 3 4 5 }t 268 t{ 4 gi3 -> 4 5 }t 269 t{ 5 gi3 -> 5 }t 270 t{ 6 gi3 -> 6 }t 271 272 \ f.3.16 defining words 273 t{ : nop : postpone ; ; -> }t 274 t{ nop nop1 nop nop2 -> }t 275 t{ nop1 -> }t 276 t{ nop2 -> }t 277 278 t{ : gdx 123 ; -> }t 279 t{ : gdx gdx 234 ; -> }t 280 t{ gdx -> 123 234 }t 281 282 t{ 123 constant x123 -> }t 283 t{ x123 -> 123 }t 284 t{ : equ constant ; -> }t 285 t{ x123 equ y123 -> }t 286 t{ y123 -> 123 }t 287 288 t{ variable v1 -> }t 289 t{ 123 v1 ! -> }t 290 t{ v1 @ -> 123 }t 291