From 67d25d837ac55f28a366c0a3b262e439a6e75fc3 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 19 Aug 2017 12:15:28 +0200 Subject: Add AmForth --- .../common/lib/forth2012/tester/anstests.zip | Bin 0 -> 13354 bytes .../common/lib/forth2012/tester/anstests0.9.zip | Bin 0 -> 35058 bytes amforth-6.5/common/lib/forth2012/tester/core.fr | 1002 ++++++++++++++++++++ .../common/lib/forth2012/tester/coreexttest.fth | 322 +++++++ .../common/lib/forth2012/tester/coreplustest.fth | 190 ++++ .../common/lib/forth2012/tester/doubletest.fth | 386 ++++++++ .../common/lib/forth2012/tester/exceptiontest.fth | 96 ++ .../common/lib/forth2012/tester/filetest.fth | 193 ++++ .../common/lib/forth2012/tester/memorytest.fth | 93 ++ .../common/lib/forth2012/tester/postponetest.fs | 379 ++++++++ .../lib/forth2012/tester/searchordertest.fth | 178 ++++ .../lib/forth2012/tester/searchordertest.txt | 184 ++++ .../common/lib/forth2012/tester/stringtest.fth | 161 ++++ .../common/lib/forth2012/tester/tester-amforth.frt | 66 ++ .../common/lib/forth2012/tester/toolstest.fth | 172 ++++ 15 files changed, 3422 insertions(+) create mode 100644 amforth-6.5/common/lib/forth2012/tester/anstests.zip create mode 100644 amforth-6.5/common/lib/forth2012/tester/anstests0.9.zip create mode 100644 amforth-6.5/common/lib/forth2012/tester/core.fr create mode 100644 amforth-6.5/common/lib/forth2012/tester/coreexttest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/coreplustest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/doubletest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/exceptiontest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/filetest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/memorytest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/postponetest.fs create mode 100644 amforth-6.5/common/lib/forth2012/tester/searchordertest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/searchordertest.txt create mode 100644 amforth-6.5/common/lib/forth2012/tester/stringtest.fth create mode 100644 amforth-6.5/common/lib/forth2012/tester/tester-amforth.frt create mode 100644 amforth-6.5/common/lib/forth2012/tester/toolstest.fth (limited to 'amforth-6.5/common/lib/forth2012/tester') diff --git a/amforth-6.5/common/lib/forth2012/tester/anstests.zip b/amforth-6.5/common/lib/forth2012/tester/anstests.zip new file mode 100644 index 0000000..34dc1bd Binary files /dev/null and b/amforth-6.5/common/lib/forth2012/tester/anstests.zip differ diff --git a/amforth-6.5/common/lib/forth2012/tester/anstests0.9.zip b/amforth-6.5/common/lib/forth2012/tester/anstests0.9.zip new file mode 100644 index 0000000..89ad461 Binary files /dev/null and b/amforth-6.5/common/lib/forth2012/tester/anstests0.9.zip differ diff --git a/amforth-6.5/common/lib/forth2012/tester/core.fr b/amforth-6.5/common/lib/forth2012/tester/core.fr new file mode 100644 index 0000000..488db2a --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/core.fr @@ -0,0 +1,1002 @@ +\ From: John Hayes S1I +\ Subject: core.fr +\ Date: Mon, 27 Nov 95 13:10 + +\ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY +\ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS. +\ VERSION 1.2 +\ THIS PROGRAM TESTS THE CORE WORDS OF AN ANS FORTH SYSTEM. +\ THE PROGRAM ASSUMES A TWO'S COMPLEMENT IMPLEMENTATION WHERE +\ THE RANGE OF SIGNED NUMBERS IS -2^(N-1) ... 2^(N-1)-1 AND +\ THE RANGE OF UNSIGNED NUMBERS IS 0 ... 2^(N)-1. +\ I HAVEN'T FIGURED OUT HOW TO TEST KEY, QUIT, ABORT, OR ABORT"... +\ I ALSO HAVEN'T THOUGHT OF A WAY TO TEST ENVIRONMENT?... + +CR +TESTING CORE WORDS +HEX + +\ ------------------------------------------------------------------------ +TESTING BASIC ASSUMPTIONS + +T{ -> }T \ START WITH CLEAN SLATE +( TEST IF ANY BITS ARE SET; ANSWER IN BASE 1 ) +T{ : BITSSET? IF 0 0 ELSE 0 THEN ; -> }T +T{ 0 BITSSET? -> 0 }T ( ZERO IS ALL BITS CLEAR ) +T{ 1 BITSSET? -> 0 0 }T ( OTHER NUMBER HAVE AT LEAST ONE BIT ) +T{ -1 BITSSET? -> 0 0 }T + +\ ------------------------------------------------------------------------ +TESTING BOOLEANS: INVERT AND OR XOR + +T{ 0 0 AND -> 0 }T +T{ 0 1 AND -> 0 }T +T{ 1 0 AND -> 0 }T +T{ 1 1 AND -> 1 }T + +T{ 0 INVERT 1 AND -> 1 }T +T{ 1 INVERT 1 AND -> 0 }T + +0 CONSTANT 0S +0 INVERT CONSTANT 1S + +T{ 0S INVERT -> 1S }T +T{ 1S INVERT -> 0S }T + +T{ 0S 0S AND -> 0S }T +T{ 0S 1S AND -> 0S }T +T{ 1S 0S AND -> 0S }T +T{ 1S 1S AND -> 1S }T + +T{ 0S 0S OR -> 0S }T +T{ 0S 1S OR -> 1S }T +T{ 1S 0S OR -> 1S }T +T{ 1S 1S OR -> 1S }T + +T{ 0S 0S XOR -> 0S }T +T{ 0S 1S XOR -> 1S }T +T{ 1S 0S XOR -> 1S }T +T{ 1S 1S XOR -> 0S }T + +\ ------------------------------------------------------------------------ +TESTING 2* 2/ LSHIFT RSHIFT + +( WE TRUST 1S, INVERT, AND BITSSET?; WE WILL CONFIRM RSHIFT LATER ) +1S 1 RSHIFT INVERT CONSTANT MSB +T{ MSB BITSSET? -> 0 0 }T + +T{ 0S 2* -> 0S }T +T{ 1 2* -> 2 }T +T{ 4000 2* -> 8000 }T +T{ 1S 2* 1 XOR -> 1S }T +T{ MSB 2* -> 0S }T + +T{ 0S 2/ -> 0S }T +T{ 1 2/ -> 0 }T +T{ 4000 2/ -> 2000 }T +T{ 1S 2/ -> 1S }T \ MSB PROPOGATED +T{ 1S 1 XOR 2/ -> 1S }T +T{ MSB 2/ MSB AND -> MSB }T + +T{ 1 0 LSHIFT -> 1 }T +T{ 1 1 LSHIFT -> 2 }T +T{ 1 2 LSHIFT -> 4 }T +T{ 1 F LSHIFT -> 8000 }T \ BIGGEST GUARANTEED SHIFT +T{ 1S 1 LSHIFT 1 XOR -> 1S }T +T{ MSB 1 LSHIFT -> 0 }T + +T{ 1 0 RSHIFT -> 1 }T +T{ 1 1 RSHIFT -> 0 }T +T{ 2 1 RSHIFT -> 1 }T +T{ 4 2 RSHIFT -> 1 }T +T{ 8000 F RSHIFT -> 1 }T \ BIGGEST +T{ MSB 1 RSHIFT MSB AND -> 0 }T \ RSHIFT ZERO FILLS MSBS +T{ MSB 1 RSHIFT 2* -> MSB }T + +\ ------------------------------------------------------------------------ +TESTING COMPARISONS: 0= = 0< < > U< MIN MAX +0 INVERT CONSTANT MAX-UINT +0 INVERT 1 RSHIFT CONSTANT MAX-INT +0 INVERT 1 RSHIFT INVERT CONSTANT MIN-INT +0 INVERT 1 RSHIFT CONSTANT MID-UINT +0 INVERT 1 RSHIFT INVERT CONSTANT MID-UINT+1 + +0S CONSTANT +1S CONSTANT + +T{ 0 0= -> }T +T{ 1 0= -> }T +T{ 2 0= -> }T +T{ -1 0= -> }T +T{ MAX-UINT 0= -> }T +T{ MIN-INT 0= -> }T +T{ MAX-INT 0= -> }T + +T{ 0 0 = -> }T +T{ 1 1 = -> }T +T{ -1 -1 = -> }T +T{ 1 0 = -> }T +T{ -1 0 = -> }T +T{ 0 1 = -> }T +T{ 0 -1 = -> }T + +T{ 0 0< -> }T +T{ -1 0< -> }T +T{ MIN-INT 0< -> }T +T{ 1 0< -> }T +T{ MAX-INT 0< -> }T + +T{ 0 1 < -> }T +T{ 1 2 < -> }T +T{ -1 0 < -> }T +T{ -1 1 < -> }T +T{ MIN-INT 0 < -> }T +T{ MIN-INT MAX-INT < -> }T +T{ 0 MAX-INT < -> }T +T{ 0 0 < -> }T +T{ 1 1 < -> }T +T{ 1 0 < -> }T +T{ 2 1 < -> }T +T{ 0 -1 < -> }T +T{ 1 -1 < -> }T +T{ 0 MIN-INT < -> }T +T{ MAX-INT MIN-INT < -> }T +T{ MAX-INT 0 < -> }T + +T{ 0 1 > -> }T +T{ 1 2 > -> }T +T{ -1 0 > -> }T +T{ -1 1 > -> }T +T{ MIN-INT 0 > -> }T +T{ MIN-INT MAX-INT > -> }T +T{ 0 MAX-INT > -> }T +T{ 0 0 > -> }T +T{ 1 1 > -> }T +T{ 1 0 > -> }T +T{ 2 1 > -> }T +T{ 0 -1 > -> }T +T{ 1 -1 > -> }T +T{ 0 MIN-INT > -> }T +T{ MAX-INT MIN-INT > -> }T +T{ MAX-INT 0 > -> }T + +T{ 0 1 U< -> }T +T{ 1 2 U< -> }T +T{ 0 MID-UINT U< -> }T +T{ 0 MAX-UINT U< -> }T +T{ MID-UINT MAX-UINT U< -> }T +T{ 0 0 U< -> }T +T{ 1 1 U< -> }T +T{ 1 0 U< -> }T +T{ 2 1 U< -> }T +T{ MID-UINT 0 U< -> }T +T{ MAX-UINT 0 U< -> }T +T{ MAX-UINT MID-UINT U< -> }T + +T{ 0 1 MIN -> 0 }T +T{ 1 2 MIN -> 1 }T +T{ -1 0 MIN -> -1 }T +T{ -1 1 MIN -> -1 }T +T{ MIN-INT 0 MIN -> MIN-INT }T +T{ MIN-INT MAX-INT MIN -> MIN-INT }T +T{ 0 MAX-INT MIN -> 0 }T +T{ 0 0 MIN -> 0 }T +T{ 1 1 MIN -> 1 }T +T{ 1 0 MIN -> 0 }T +T{ 2 1 MIN -> 1 }T +T{ 0 -1 MIN -> -1 }T +T{ 1 -1 MIN -> -1 }T +T{ 0 MIN-INT MIN -> MIN-INT }T +T{ MAX-INT MIN-INT MIN -> MIN-INT }T +T{ MAX-INT 0 MIN -> 0 }T + +T{ 0 1 MAX -> 1 }T +T{ 1 2 MAX -> 2 }T +T{ -1 0 MAX -> 0 }T +T{ -1 1 MAX -> 1 }T +T{ MIN-INT 0 MAX -> 0 }T +T{ MIN-INT MAX-INT MAX -> MAX-INT }T +T{ 0 MAX-INT MAX -> MAX-INT }T +T{ 0 0 MAX -> 0 }T +T{ 1 1 MAX -> 1 }T +T{ 1 0 MAX -> 1 }T +T{ 2 1 MAX -> 2 }T +T{ 0 -1 MAX -> 0 }T +T{ 1 -1 MAX -> 1 }T +T{ 0 MIN-INT MAX -> 0 }T +T{ MAX-INT MIN-INT MAX -> MAX-INT }T +T{ MAX-INT 0 MAX -> MAX-INT }T + +\ ------------------------------------------------------------------------ +TESTING STACK OPS: 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP + +T{ 1 2 2DROP -> }T +T{ 1 2 2DUP -> 1 2 1 2 }T +T{ 1 2 3 4 2OVER -> 1 2 3 4 1 2 }T +T{ 1 2 3 4 2SWAP -> 3 4 1 2 }T +T{ 0 ?DUP -> 0 }T +T{ 1 ?DUP -> 1 1 }T +T{ -1 ?DUP -> -1 -1 }T +T{ DEPTH -> 0 }T +T{ 0 DEPTH -> 0 1 }T +T{ 0 1 DEPTH -> 0 1 2 }T +T{ 0 DROP -> }T +T{ 1 2 DROP -> 1 }T +T{ 1 DUP -> 1 1 }T +T{ 1 2 OVER -> 1 2 1 }T +T{ 1 2 3 ROT -> 2 3 1 }T +T{ 1 2 SWAP -> 2 1 }T + +\ ------------------------------------------------------------------------ +TESTING >R R> R@ + +T{ : GR1 >R R> ; -> }T +T{ : GR2 >R R@ R> DROP ; -> }T +T{ 123 GR1 -> 123 }T +T{ 123 GR2 -> 123 }T +T{ 1S GR1 -> 1S }T ( RETURN STACK HOLDS CELLS ) + +\ ------------------------------------------------------------------------ +TESTING ADD/SUBTRACT: + - 1+ 1- ABS NEGATE + +T{ 0 5 + -> 5 }T +T{ 5 0 + -> 5 }T +T{ 0 -5 + -> -5 }T +T{ -5 0 + -> -5 }T +T{ 1 2 + -> 3 }T +T{ 1 -2 + -> -1 }T +T{ -1 2 + -> 1 }T +T{ -1 -2 + -> -3 }T +T{ -1 1 + -> 0 }T +T{ MID-UINT 1 + -> MID-UINT+1 }T + +T{ 0 5 - -> -5 }T +T{ 5 0 - -> 5 }T +T{ 0 -5 - -> 5 }T +T{ -5 0 - -> -5 }T +T{ 1 2 - -> -1 }T +T{ 1 -2 - -> 3 }T +T{ -1 2 - -> -3 }T +T{ -1 -2 - -> 1 }T +T{ 0 1 - -> -1 }T +T{ MID-UINT+1 1 - -> MID-UINT }T + +T{ 0 1+ -> 1 }T +T{ -1 1+ -> 0 }T +T{ 1 1+ -> 2 }T +T{ MID-UINT 1+ -> MID-UINT+1 }T + +T{ 2 1- -> 1 }T +T{ 1 1- -> 0 }T +T{ 0 1- -> -1 }T +T{ MID-UINT+1 1- -> MID-UINT }T + +T{ 0 NEGATE -> 0 }T +T{ 1 NEGATE -> -1 }T +T{ -1 NEGATE -> 1 }T +T{ 2 NEGATE -> -2 }T +T{ -2 NEGATE -> 2 }T + +T{ 0 ABS -> 0 }T +T{ 1 ABS -> 1 }T +T{ -1 ABS -> 1 }T +T{ MIN-INT ABS -> MID-UINT+1 }T + +\ ------------------------------------------------------------------------ +TESTING MULTIPLY: S>D * M* UM* + +T{ 0 S>D -> 0 0 }T +T{ 1 S>D -> 1 0 }T +T{ 2 S>D -> 2 0 }T +T{ -1 S>D -> -1 -1 }T +T{ -2 S>D -> -2 -1 }T +T{ MIN-INT S>D -> MIN-INT -1 }T +T{ MAX-INT S>D -> MAX-INT 0 }T + +T{ 0 0 M* -> 0 S>D }T +T{ 0 1 M* -> 0 S>D }T +T{ 1 0 M* -> 0 S>D }T +T{ 1 2 M* -> 2 S>D }T +T{ 2 1 M* -> 2 S>D }T +T{ 3 3 M* -> 9 S>D }T +T{ -3 3 M* -> -9 S>D }T +T{ 3 -3 M* -> -9 S>D }T +T{ -3 -3 M* -> 9 S>D }T +T{ 0 MIN-INT M* -> 0 S>D }T +T{ 1 MIN-INT M* -> MIN-INT S>D }T +T{ 2 MIN-INT M* -> 0 1S }T +T{ 0 MAX-INT M* -> 0 S>D }T +T{ 1 MAX-INT M* -> MAX-INT S>D }T +T{ 2 MAX-INT M* -> MAX-INT 1 LSHIFT 0 }T +T{ MIN-INT MIN-INT M* -> 0 MSB 1 RSHIFT }T +T{ MAX-INT MIN-INT M* -> MSB MSB 2/ }T +T{ MAX-INT MAX-INT M* -> 1 MSB 2/ INVERT }T + +T{ 0 0 * -> 0 }T \ TEST IDENTITIES +T{ 0 1 * -> 0 }T +T{ 1 0 * -> 0 }T +T{ 1 2 * -> 2 }T +T{ 2 1 * -> 2 }T +T{ 3 3 * -> 9 }T +T{ -3 3 * -> -9 }T +T{ 3 -3 * -> -9 }T +T{ -3 -3 * -> 9 }T + +T{ MID-UINT+1 1 RSHIFT 2 * -> MID-UINT+1 }T +T{ MID-UINT+1 2 RSHIFT 4 * -> MID-UINT+1 }T +T{ MID-UINT+1 1 RSHIFT MID-UINT+1 OR 2 * -> MID-UINT+1 }T + +T{ 0 0 UM* -> 0 0 }T +T{ 0 1 UM* -> 0 0 }T +T{ 1 0 UM* -> 0 0 }T +T{ 1 2 UM* -> 2 0 }T +T{ 2 1 UM* -> 2 0 }T +T{ 3 3 UM* -> 9 0 }T + +T{ MID-UINT+1 1 RSHIFT 2 UM* -> MID-UINT+1 0 }T +T{ MID-UINT+1 2 UM* -> 0 1 }T +T{ MID-UINT+1 4 UM* -> 0 2 }T +T{ 1S 2 UM* -> 1S 1 LSHIFT 1 }T +T{ MAX-UINT MAX-UINT UM* -> 1 1 INVERT }T + +\ ------------------------------------------------------------------------ +TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD + +T{ 0 S>D 1 FM/MOD -> 0 0 }T +T{ 1 S>D 1 FM/MOD -> 0 1 }T +T{ 2 S>D 1 FM/MOD -> 0 2 }T +T{ -1 S>D 1 FM/MOD -> 0 -1 }T +T{ -2 S>D 1 FM/MOD -> 0 -2 }T +T{ 0 S>D -1 FM/MOD -> 0 0 }T +T{ 1 S>D -1 FM/MOD -> 0 -1 }T +T{ 2 S>D -1 FM/MOD -> 0 -2 }T +T{ -1 S>D -1 FM/MOD -> 0 1 }T +T{ -2 S>D -1 FM/MOD -> 0 2 }T +T{ 2 S>D 2 FM/MOD -> 0 1 }T +T{ -1 S>D -1 FM/MOD -> 0 1 }T +T{ -2 S>D -2 FM/MOD -> 0 1 }T +T{ 7 S>D 3 FM/MOD -> 1 2 }T +T{ 7 S>D -3 FM/MOD -> -2 -3 }T +T{ -7 S>D 3 FM/MOD -> 2 -3 }T +T{ -7 S>D -3 FM/MOD -> -1 2 }T +T{ MAX-INT S>D 1 FM/MOD -> 0 MAX-INT }T +T{ MIN-INT S>D 1 FM/MOD -> 0 MIN-INT }T +T{ MAX-INT S>D MAX-INT FM/MOD -> 0 1 }T +T{ MIN-INT S>D MIN-INT FM/MOD -> 0 1 }T +T{ 1S 1 4 FM/MOD -> 3 MAX-INT }T +T{ 1 MIN-INT M* 1 FM/MOD -> 0 MIN-INT }T +T{ 1 MIN-INT M* MIN-INT FM/MOD -> 0 1 }T +T{ 2 MIN-INT M* 2 FM/MOD -> 0 MIN-INT }T +T{ 2 MIN-INT M* MIN-INT FM/MOD -> 0 2 }T +T{ 1 MAX-INT M* 1 FM/MOD -> 0 MAX-INT }T +T{ 1 MAX-INT M* MAX-INT FM/MOD -> 0 1 }T +T{ 2 MAX-INT M* 2 FM/MOD -> 0 MAX-INT }T +T{ 2 MAX-INT M* MAX-INT FM/MOD -> 0 2 }T +T{ MIN-INT MIN-INT M* MIN-INT FM/MOD -> 0 MIN-INT }T +T{ MIN-INT MAX-INT M* MIN-INT FM/MOD -> 0 MAX-INT }T +T{ MIN-INT MAX-INT M* MAX-INT FM/MOD -> 0 MIN-INT }T +T{ MAX-INT MAX-INT M* MAX-INT FM/MOD -> 0 MAX-INT }T + +T{ 0 S>D 1 SM/REM -> 0 0 }T +T{ 1 S>D 1 SM/REM -> 0 1 }T +T{ 2 S>D 1 SM/REM -> 0 2 }T +T{ -1 S>D 1 SM/REM -> 0 -1 }T +T{ -2 S>D 1 SM/REM -> 0 -2 }T +T{ 0 S>D -1 SM/REM -> 0 0 }T +T{ 1 S>D -1 SM/REM -> 0 -1 }T +T{ 2 S>D -1 SM/REM -> 0 -2 }T +T{ -1 S>D -1 SM/REM -> 0 1 }T +T{ -2 S>D -1 SM/REM -> 0 2 }T +T{ 2 S>D 2 SM/REM -> 0 1 }T +T{ -1 S>D -1 SM/REM -> 0 1 }T +T{ -2 S>D -2 SM/REM -> 0 1 }T +T{ 7 S>D 3 SM/REM -> 1 2 }T +T{ 7 S>D -3 SM/REM -> 1 -2 }T +T{ -7 S>D 3 SM/REM -> -1 -2 }T +T{ -7 S>D -3 SM/REM -> -1 2 }T +T{ MAX-INT S>D 1 SM/REM -> 0 MAX-INT }T +T{ MIN-INT S>D 1 SM/REM -> 0 MIN-INT }T +T{ MAX-INT S>D MAX-INT SM/REM -> 0 1 }T +T{ MIN-INT S>D MIN-INT SM/REM -> 0 1 }T +T{ 1S 1 4 SM/REM -> 3 MAX-INT }T +T{ 2 MIN-INT M* 2 SM/REM -> 0 MIN-INT }T +T{ 2 MIN-INT M* MIN-INT SM/REM -> 0 2 }T +T{ 2 MAX-INT M* 2 SM/REM -> 0 MAX-INT }T +T{ 2 MAX-INT M* MAX-INT SM/REM -> 0 2 }T +T{ MIN-INT MIN-INT M* MIN-INT SM/REM -> 0 MIN-INT }T +T{ MIN-INT MAX-INT M* MIN-INT SM/REM -> 0 MAX-INT }T +T{ MIN-INT MAX-INT M* MAX-INT SM/REM -> 0 MIN-INT }T +T{ MAX-INT MAX-INT M* MAX-INT SM/REM -> 0 MAX-INT }T + +T{ 0 0 1 UM/MOD -> 0 0 }T +T{ 1 0 1 UM/MOD -> 0 1 }T +T{ 1 0 2 UM/MOD -> 1 0 }T +T{ 3 0 2 UM/MOD -> 1 1 }T +T{ MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }T +T{ MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }T +T{ MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }T + +: IFFLOORED + [ -3 2 / -2 = INVERT ] LITERAL IF POSTPONE \ THEN ; + +: IFSYM + [ -3 2 / -1 = INVERT ] LITERAL IF POSTPONE \ THEN ; + +\ THE SYSTEM MIGHT DO EITHER FLOORED OR SYMMETRIC DIVISION. +\ SINCE WE HAVE ALREADY TESTED M*, FM/MOD, AND SM/REM WE CAN USE THEM IN TEST. + +IFFLOORED : T/MOD >R S>D R> FM/MOD ; +IFFLOORED : T/ T/MOD SWAP DROP ; +IFFLOORED : TMOD T/MOD DROP ; +IFFLOORED : T*/MOD >R M* R> FM/MOD ; +IFFLOORED : T*/ T*/MOD SWAP DROP ; +IFSYM : T/MOD >R S>D R> SM/REM ; +IFSYM : T/ T/MOD SWAP DROP ; +IFSYM : TMOD T/MOD DROP ; +IFSYM : T*/MOD >R M* R> SM/REM ; +IFSYM : T*/ T*/MOD SWAP DROP ; + +T{ 0 1 /MOD -> 0 1 T/MOD }T +T{ 1 1 /MOD -> 1 1 T/MOD }T +T{ 2 1 /MOD -> 2 1 T/MOD }T +T{ -1 1 /MOD -> -1 1 T/MOD }T +T{ -2 1 /MOD -> -2 1 T/MOD }T +T{ 0 -1 /MOD -> 0 -1 T/MOD }T +T{ 1 -1 /MOD -> 1 -1 T/MOD }T +T{ 2 -1 /MOD -> 2 -1 T/MOD }T +T{ -1 -1 /MOD -> -1 -1 T/MOD }T +T{ -2 -1 /MOD -> -2 -1 T/MOD }T +T{ 2 2 /MOD -> 2 2 T/MOD }T +T{ -1 -1 /MOD -> -1 -1 T/MOD }T +T{ -2 -2 /MOD -> -2 -2 T/MOD }T +T{ 7 3 /MOD -> 7 3 T/MOD }T +T{ 7 -3 /MOD -> 7 -3 T/MOD }T +T{ -7 3 /MOD -> -7 3 T/MOD }T +T{ -7 -3 /MOD -> -7 -3 T/MOD }T +T{ MAX-INT 1 /MOD -> MAX-INT 1 T/MOD }T +T{ MIN-INT 1 /MOD -> MIN-INT 1 T/MOD }T +T{ MAX-INT MAX-INT /MOD -> MAX-INT MAX-INT T/MOD }T +T{ MIN-INT MIN-INT /MOD -> MIN-INT MIN-INT T/MOD }T + +T{ 0 1 / -> 0 1 T/ }T +T{ 1 1 / -> 1 1 T/ }T +T{ 2 1 / -> 2 1 T/ }T +T{ -1 1 / -> -1 1 T/ }T +T{ -2 1 / -> -2 1 T/ }T +T{ 0 -1 / -> 0 -1 T/ }T +T{ 1 -1 / -> 1 -1 T/ }T +T{ 2 -1 / -> 2 -1 T/ }T +T{ -1 -1 / -> -1 -1 T/ }T +T{ -2 -1 / -> -2 -1 T/ }T +T{ 2 2 / -> 2 2 T/ }T +T{ -1 -1 / -> -1 -1 T/ }T +T{ -2 -2 / -> -2 -2 T/ }T +T{ 7 3 / -> 7 3 T/ }T +T{ 7 -3 / -> 7 -3 T/ }T +T{ -7 3 / -> -7 3 T/ }T +T{ -7 -3 / -> -7 -3 T/ }T +T{ MAX-INT 1 / -> MAX-INT 1 T/ }T +T{ MIN-INT 1 / -> MIN-INT 1 T/ }T +T{ MAX-INT MAX-INT / -> MAX-INT MAX-INT T/ }T +T{ MIN-INT MIN-INT / -> MIN-INT MIN-INT T/ }T + +T{ 0 1 MOD -> 0 1 TMOD }T +T{ 1 1 MOD -> 1 1 TMOD }T +T{ 2 1 MOD -> 2 1 TMOD }T +T{ -1 1 MOD -> -1 1 TMOD }T +T{ -2 1 MOD -> -2 1 TMOD }T +T{ 0 -1 MOD -> 0 -1 TMOD }T +T{ 1 -1 MOD -> 1 -1 TMOD }T +T{ 2 -1 MOD -> 2 -1 TMOD }T +T{ -1 -1 MOD -> -1 -1 TMOD }T +T{ -2 -1 MOD -> -2 -1 TMOD }T +T{ 2 2 MOD -> 2 2 TMOD }T +T{ -1 -1 MOD -> -1 -1 TMOD }T +T{ -2 -2 MOD -> -2 -2 TMOD }T +T{ 7 3 MOD -> 7 3 TMOD }T +T{ 7 -3 MOD -> 7 -3 TMOD }T +T{ -7 3 MOD -> -7 3 TMOD }T +T{ -7 -3 MOD -> -7 -3 TMOD }T +T{ MAX-INT 1 MOD -> MAX-INT 1 TMOD }T +T{ MIN-INT 1 MOD -> MIN-INT 1 TMOD }T +T{ MAX-INT MAX-INT MOD -> MAX-INT MAX-INT TMOD }T +T{ MIN-INT MIN-INT MOD -> MIN-INT MIN-INT TMOD }T + +T{ 0 2 1 */ -> 0 2 1 T*/ }T +T{ 1 2 1 */ -> 1 2 1 T*/ }T +T{ 2 2 1 */ -> 2 2 1 T*/ }T +T{ -1 2 1 */ -> -1 2 1 T*/ }T +T{ -2 2 1 */ -> -2 2 1 T*/ }T +T{ 0 2 -1 */ -> 0 2 -1 T*/ }T +T{ 1 2 -1 */ -> 1 2 -1 T*/ }T +T{ 2 2 -1 */ -> 2 2 -1 T*/ }T +T{ -1 2 -1 */ -> -1 2 -1 T*/ }T +T{ -2 2 -1 */ -> -2 2 -1 T*/ }T +T{ 2 2 2 */ -> 2 2 2 T*/ }T +T{ -1 2 -1 */ -> -1 2 -1 T*/ }T +T{ -2 2 -2 */ -> -2 2 -2 T*/ }T +T{ 7 2 3 */ -> 7 2 3 T*/ }T +T{ 7 2 -3 */ -> 7 2 -3 T*/ }T +T{ -7 2 3 */ -> -7 2 3 T*/ }T +T{ -7 2 -3 */ -> -7 2 -3 T*/ }T +T{ MAX-INT 2 MAX-INT */ -> MAX-INT 2 MAX-INT T*/ }T +T{ MIN-INT 2 MIN-INT */ -> MIN-INT 2 MIN-INT T*/ }T + +T{ 0 2 1 */MOD -> 0 2 1 T*/MOD }T +T{ 1 2 1 */MOD -> 1 2 1 T*/MOD }T +T{ 2 2 1 */MOD -> 2 2 1 T*/MOD }T +T{ -1 2 1 */MOD -> -1 2 1 T*/MOD }T +T{ -2 2 1 */MOD -> -2 2 1 T*/MOD }T +T{ 0 2 -1 */MOD -> 0 2 -1 T*/MOD }T +T{ 1 2 -1 */MOD -> 1 2 -1 T*/MOD }T +T{ 2 2 -1 */MOD -> 2 2 -1 T*/MOD }T +T{ -1 2 -1 */MOD -> -1 2 -1 T*/MOD }T +T{ -2 2 -1 */MOD -> -2 2 -1 T*/MOD }T +T{ 2 2 2 */MOD -> 2 2 2 T*/MOD }T +T{ -1 2 -1 */MOD -> -1 2 -1 T*/MOD }T +T{ -2 2 -2 */MOD -> -2 2 -2 T*/MOD }T +T{ 7 2 3 */MOD -> 7 2 3 T*/MOD }T +T{ 7 2 -3 */MOD -> 7 2 -3 T*/MOD }T +T{ -7 2 3 */MOD -> -7 2 3 T*/MOD }T +T{ -7 2 -3 */MOD -> -7 2 -3 T*/MOD }T +T{ MAX-INT 2 MAX-INT */MOD -> MAX-INT 2 MAX-INT T*/MOD }T +T{ MIN-INT 2 MIN-INT */MOD -> MIN-INT 2 MIN-INT T*/MOD }T + +\ ------------------------------------------------------------------------ +TESTING HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2! ALIGN ALIGNED +! ALLOT + +HERE 1 ALLOT +HERE +CONSTANT 2NDA +CONSTANT 1STA +T{ 1STA 2NDA U< -> }T \ HERE MUST GROW WITH ALLOT +T{ 1STA 1+ -> 2NDA }T \ ... BY ONE ADDRESS UNIT +( MISSING TEST: NEGATIVE ALLOT ) + +HERE 1 , +HERE 2 , +CONSTANT 2ND +CONSTANT 1ST +T{ 1ST 2ND U< -> }T \ HERE MUST GROW WITH ALLOT +T{ 1ST CELL+ -> 2ND }T \ ... BY ONE CELL +T{ 1ST 1 CELLS + -> 2ND }T +T{ 1ST @ 2ND @ -> 1 2 }T +T{ 5 1ST ! -> }T +T{ 1ST @ 2ND @ -> 5 2 }T +T{ 6 2ND ! -> }T +T{ 1ST @ 2ND @ -> 5 6 }T +T{ 1ST 2@ -> 6 5 }T +T{ 2 1 1ST 2! -> }T +T{ 1ST 2@ -> 2 1 }T +T{ 1S 1ST ! 1ST @ -> 1S }T \ CAN STORE CELL-WIDE VALUE + +HERE 1 C, +HERE 2 C, +CONSTANT 2NDC +CONSTANT 1STC +T{ 1STC 2NDC U< -> }T \ HERE MUST GROW WITH ALLOT +T{ 1STC CHAR+ -> 2NDC }T \ ... BY ONE CHAR +T{ 1STC 1 CHARS + -> 2NDC }T +T{ 1STC C@ 2NDC C@ -> 1 2 }T +T{ 3 1STC C! -> }T +T{ 1STC C@ 2NDC C@ -> 3 2 }T +T{ 4 2NDC C! -> }T +T{ 1STC C@ 2NDC C@ -> 3 4 }T + +ALIGN 1 ALLOT HERE ALIGN HERE 3 CELLS ALLOT +CONSTANT A-ADDR CONSTANT UA-ADDR +T{ UA-ADDR ALIGNED -> A-ADDR }T +T{ 1 A-ADDR C! A-ADDR C@ -> 1 }T +T{ 1234 A-ADDR ! A-ADDR @ -> 1234 }T +T{ 123 456 A-ADDR 2! A-ADDR 2@ -> 123 456 }T +T{ 2 A-ADDR CHAR+ C! A-ADDR CHAR+ C@ -> 2 }T +T{ 3 A-ADDR CELL+ C! A-ADDR CELL+ C@ -> 3 }T +T{ 1234 A-ADDR CELL+ ! A-ADDR CELL+ @ -> 1234 }T +T{ 123 456 A-ADDR CELL+ 2! A-ADDR CELL+ 2@ -> 123 456 }T + +: BITS ( X -- U ) + 0 SWAP BEGIN DUP WHILE DUP MSB AND IF >R 1+ R> THEN 2* REPEAT DROP ; +( CHARACTERS >= 1 AU, <= SIZE OF CELL, >= 8 BITS ) +T{ 1 CHARS 1 < -> }T +T{ 1 CHARS 1 CELLS > -> }T +( TBD: HOW TO FIND NUMBER OF BITS? ) + +( CELLS >= 1 AU, INTEGRAL MULTIPLE OF CHAR SIZE, >= 16 BITS ) +T{ 1 CELLS 1 < -> }T +T{ 1 CELLS 1 CHARS MOD -> 0 }T +T{ 1S BITS 10 < -> }T + +T{ 0 1ST ! -> }T +T{ 1 1ST +! -> }T +T{ 1ST @ -> 1 }T +T{ -1 1ST +! 1ST @ -> 0 }T + +\ ------------------------------------------------------------------------ +TESTING CHAR [CHAR] [ ] BL S" + +T{ BL -> 20 }T +T{ CHAR X -> 58 }T +T{ CHAR HELLO -> 48 }T +T{ : GC1 [CHAR] X ; -> }T +T{ : GC2 [CHAR] HELLO ; -> }T +T{ GC1 -> 58 }T +T{ GC2 -> 48 }T +T{ : GC3 [ GC1 ] LITERAL ; -> }T +T{ GC3 -> 58 }T +T{ : GC4 S" XY" ; -> }T +T{ GC4 SWAP DROP -> 2 }T +T{ GC4 DROP DUP C@ SWAP CHAR+ C@ -> 58 59 }T + +\ ------------------------------------------------------------------------ +TESTING ' ['] FIND EXECUTE IMMEDIATE COUNT LITERAL POSTPONE STATE + +T{ : GT1 123 ; -> }T +T{ ' GT1 EXECUTE -> 123 }T +T{ : GT2 ['] GT1 ; IMMEDIATE -> }T +T{ GT2 EXECUTE -> 123 }T +HERE 3 C, CHAR G C, CHAR T C, CHAR 1 C, CONSTANT GT1STRING +HERE 3 C, CHAR G C, CHAR T C, CHAR 2 C, CONSTANT GT2STRING +T{ GT1STRING FIND -> ' GT1 -1 }T +T{ GT2STRING FIND -> ' GT2 1 }T +( HOW TO SEARCH FOR NON-EXISTENT WORD? ) +\ T{ : GT3 GT2 LITERAL ; -> }T +\ T{ GT3 -> ' GT1 }T +\ T{ GT1STRING COUNT -> GT1STRING CHAR+ 3 }T + +T{ : GT4 POSTPONE GT1 ; IMMEDIATE -> }T +T{ : GT5 GT4 ; -> }T +T{ GT5 -> 123 }T +T{ : GT6 345 ; IMMEDIATE -> }T +T{ : GT7 POSTPONE GT6 ; -> }T +T{ GT7 -> 345 }T + +T{ : GT8 STATE @ ; IMMEDIATE -> }T +T{ GT8 -> 0 }T +T{ : GT9 GT8 LITERAL ; -> }T +T{ GT9 0= -> }T + +\ ------------------------------------------------------------------------ +TESTING IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE + +T{ : GI1 IF 123 THEN ; -> }T +T{ : GI2 IF 123 ELSE 234 THEN ; -> }T +T{ 0 GI1 -> }T +T{ 1 GI1 -> 123 }T +T{ -1 GI1 -> 123 }T +T{ 0 GI2 -> 234 }T +T{ 1 GI2 -> 123 }T +T{ -1 GI1 -> 123 }T + +T{ : GI3 BEGIN DUP 5 < WHILE DUP 1+ REPEAT ; -> }T +T{ 0 GI3 -> 0 1 2 3 4 5 }T +T{ 4 GI3 -> 4 5 }T +T{ 5 GI3 -> 5 }T +T{ 6 GI3 -> 6 }T + +T{ : GI4 BEGIN DUP 1+ DUP 5 > UNTIL ; -> }T +T{ 3 GI4 -> 3 4 5 6 }T +T{ 5 GI4 -> 5 6 }T +T{ 6 GI4 -> 6 7 }T + +T{ : GI5 BEGIN DUP 2 > WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 THEN ; -> }T +T{ 1 GI5 -> 1 345 }T +T{ 2 GI5 -> 2 345 }T +T{ 3 GI5 -> 3 4 5 123 }T +T{ 4 GI5 -> 4 5 123 }T +T{ 5 GI5 -> 5 123 }T + +T{ : GI6 ( N -- 0,1,..N ) DUP IF DUP >R 1- RECURSE R> THEN ; -> }T +T{ 0 GI6 -> 0 }T +T{ 1 GI6 -> 0 1 }T +T{ 2 GI6 -> 0 1 2 }T +T{ 3 GI6 -> 0 1 2 3 }T +T{ 4 GI6 -> 0 1 2 3 4 }T + +\ ------------------------------------------------------------------------ +TESTING DO LOOP +LOOP I J UNLOOP LEAVE EXIT + +T{ : GD1 DO I LOOP ; -> }T +T{ 4 1 GD1 -> 1 2 3 }T +T{ 2 -1 GD1 -> -1 0 1 }T +T{ MID-UINT+1 MID-UINT GD1 -> MID-UINT }T + +T{ : GD2 DO I -1 +LOOP ; -> }T +T{ 1 4 GD2 -> 4 3 2 1 }T +T{ -1 2 GD2 -> 2 1 0 -1 }T +T{ MID-UINT MID-UINT+1 GD2 -> MID-UINT+1 MID-UINT }T + +T{ : GD3 DO 1 0 DO J LOOP LOOP ; -> }T +T{ 4 1 GD3 -> 1 2 3 }T +T{ 2 -1 GD3 -> -1 0 1 }T +T{ MID-UINT+1 MID-UINT GD3 -> MID-UINT }T + +T{ : GD4 DO 1 0 DO J LOOP -1 +LOOP ; -> }T +T{ 1 4 GD4 -> 4 3 2 1 }T +T{ -1 2 GD4 -> 2 1 0 -1 }T +T{ MID-UINT MID-UINT+1 GD4 -> MID-UINT+1 MID-UINT }T + +T{ : GD5 123 SWAP 0 DO I 4 > IF DROP 234 LEAVE THEN LOOP ; -> }T +T{ 1 GD5 -> 123 }T +T{ 5 GD5 -> 123 }T +T{ 6 GD5 -> 234 }T + +T{ : GD6 ( PAT: T{0 0}T,T{0 0}TT{1 0}TT{1 1}T,T{0 0}TT{1 0}TT{1 1}TT{2 0}TT{2 1}TT{2 2}T ) + 0 SWAP 0 DO + I 1+ 0 DO I J + 3 = IF I UNLOOP I UNLOOP EXIT THEN 1+ LOOP + LOOP ; -> }T +T{ 1 GD6 -> 1 }T +T{ 2 GD6 -> 3 }T +T{ 3 GD6 -> 4 1 2 }T + +\ ------------------------------------------------------------------------ +TESTING DEFINING WORDS: : ; CONSTANT VARIABLE CREATE DOES> >BODY + +T{ 123 CONSTANT X123 -> }T +T{ X123 -> 123 }T +T{ : EQU CONSTANT ; -> }T +T{ X123 EQU Y123 -> }T +T{ Y123 -> 123 }T + +T{ VARIABLE V1 -> }T +T{ 123 V1 ! -> }T +T{ V1 @ -> 123 }T + +T{ : NOP : POSTPONE ; ; -> }T +T{ NOP NOP1 NOP NOP2 -> }T +T{ NOP1 -> }T +T{ NOP2 -> }T + +T{ : DOES1 DOES> @ 1 + ; -> }T +T{ : DOES2 DOES> @ 2 + ; -> }T +T{ CREATE CR1 -> }T +T{ CR1 -> HERE }T +T{ ' CR1 >BODY -> HERE }T +T{ 1 , -> }T +T{ CR1 @ -> 1 }T +T{ DOES1 -> }T +T{ CR1 -> 2 }T +T{ DOES2 -> }T +T{ CR1 -> 3 }T + +T{ : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }T +T{ WEIRD: W1 -> }T +T{ ' W1 >BODY -> HERE }T +T{ W1 -> HERE 1 + }T +T{ W1 -> HERE 2 + }T + +\ ------------------------------------------------------------------------ +TESTING EVALUATE + +: GE1 S" 123" ; IMMEDIATE +: GE2 S" 123 1+" ; IMMEDIATE +: GE3 S" : GE4 345 ;" ; +: GE5 EVALUATE ; IMMEDIATE + +T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE ) +T{ GE2 EVALUATE -> 124 }T +T{ GE3 EVALUATE -> }T +T{ GE4 -> 345 }T + +T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE ) +T{ GE6 -> 123 }T +T{ : GE7 GE2 GE5 ; -> }T +T{ GE7 -> 124 }T + +\ ------------------------------------------------------------------------ +TESTING SOURCE >IN WORD + +: GS1 S" SOURCE" 2DUP EVALUATE + >R SWAP >R = R> R> = ; +T{ GS1 -> }T + +VARIABLE SCANS +: RESCAN? -1 SCANS +! SCANS @ IF 0 >IN ! THEN ; + +T{ 2 SCANS ! +345 RESCAN? +-> 345 345 }T + +: GS2 5 SCANS ! S" 123 RESCAN?" EVALUATE ; +T{ GS2 -> 123 123 123 123 123 }T + +: GS3 WORD COUNT SWAP C@ ; +T{ BL GS3 HELLO -> 5 CHAR H }T +T{ CHAR " GS3 GOODBYE" -> 7 CHAR G }T +T{ BL GS3 +DROP -> 0 }T \ BLANK LINE RETURN ZERO-LENGTH STRING + +: GS4 SOURCE >IN ! DROP ; +T{ GS4 123 456 +-> }T + +\ ------------------------------------------------------------------------ +TESTING <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL + +: S= \ ( ADDR1 C1 ADDR2 C2 -- T/F ) COMPARE TWO STRINGS. + >R SWAP R@ = IF \ MAKE SURE STRINGS HAVE SAME LENGTH + R> ?DUP IF \ IF NON-EMPTY STRINGS + 0 DO + OVER C@ OVER C@ - IF 2DROP UNLOOP EXIT THEN + SWAP CHAR+ SWAP CHAR+ + LOOP + THEN + 2DROP \ IF WE GET HERE, STRINGS MATCH + ELSE + R> DROP 2DROP \ LENGTHS MISMATCH + THEN ; + +: GP1 <# 41 HOLD 42 HOLD 0 0 #> S" BA" S= ; +T{ GP1 -> }T + +: GP2 <# -1 SIGN 0 SIGN -1 SIGN 0 0 #> S" --" S= ; +T{ GP2 -> }T + +: GP3 <# 1 0 # # #> S" 01" S= ; +T{ GP3 -> }T + +: GP4 <# 1 0 #S #> S" 1" S= ; +T{ GP4 -> }T + +24 CONSTANT MAX-BASE \ BASE 2 .. 36 +: COUNT-BITS + 0 0 INVERT BEGIN DUP WHILE >R 1+ R> 2* REPEAT DROP ; +COUNT-BITS 2* CONSTANT #BITS-UD \ NUMBER OF BITS IN UD + +: GP5 + BASE @ + MAX-BASE 1+ 2 DO \ FOR EACH POSSIBLE BASE + I BASE ! \ TBD: ASSUMES BASE WORKS + I 0 <# #S #> S" 10" S= AND + LOOP + SWAP BASE ! ; +T{ GP5 -> }T + +: GP6 + BASE @ >R 2 BASE ! + MAX-UINT MAX-UINT <# #S #> \ MAXIMUM UD TO BINARY + R> BASE ! \ S: C-ADDR U + DUP #BITS-UD = SWAP + 0 DO \ S: C-ADDR FLAG + OVER C@ [CHAR] 1 = AND \ ALL ONES + >R CHAR+ R> + LOOP SWAP DROP ; +T{ GP6 -> }T + +: GP7 + BASE @ >R MAX-BASE BASE ! + + A 0 DO + I 0 <# #S #> + 1 = SWAP C@ I 30 + = AND AND + LOOP + MAX-BASE A DO + I 0 <# #S #> + 1 = SWAP C@ 41 I A - + = AND AND + LOOP + R> BASE ! ; + +T{ GP7 -> }T + +\ >NUMBER TESTS +CREATE GN-BUF 0 C, +: GN-STRING GN-BUF 1 ; +: GN-CONSUMED GN-BUF CHAR+ 0 ; +: GN' [CHAR] ' WORD CHAR+ C@ GN-BUF C! GN-STRING ; + +T{ 0 0 GN' 0' >NUMBER -> 0 0 GN-CONSUMED }T +T{ 0 0 GN' 1' >NUMBER -> 1 0 GN-CONSUMED }T +T{ 1 0 GN' 1' >NUMBER -> BASE @ 1+ 0 GN-CONSUMED }T +T{ 0 0 GN' -' >NUMBER -> 0 0 GN-STRING }T \ SHOULD FAIL TO CONVERT THESE +T{ 0 0 GN' +' >NUMBER -> 0 0 GN-STRING }T +T{ 0 0 GN' .' >NUMBER -> 0 0 GN-STRING }T + +: >NUMBER-BASED + BASE @ >R BASE ! >NUMBER R> BASE ! ; + +T{ 0 0 GN' 2' 10 >NUMBER-BASED -> 2 0 GN-CONSUMED }T +T{ 0 0 GN' 2' 2 >NUMBER-BASED -> 0 0 GN-STRING }T +T{ 0 0 GN' F' 10 >NUMBER-BASED -> F 0 GN-CONSUMED }T +T{ 0 0 GN' G' 10 >NUMBER-BASED -> 0 0 GN-STRING }T +T{ 0 0 GN' G' MAX-BASE >NUMBER-BASED -> 10 0 GN-CONSUMED }T +T{ 0 0 GN' Z' MAX-BASE >NUMBER-BASED -> 23 0 GN-CONSUMED }T + +: GN1 \ ( UD BASE -- UD' LEN ) UD SHOULD EQUAL UD' AND LEN SHOULD BE ZERO. + BASE @ >R BASE ! + <# #S #> + 0 0 2SWAP >NUMBER SWAP DROP \ RETURN LENGTH ONLY + R> BASE ! ; +T{ 0 0 2 GN1 -> 0 0 0 }T +T{ MAX-UINT 0 2 GN1 -> MAX-UINT 0 0 }T +T{ MAX-UINT DUP 2 GN1 -> MAX-UINT DUP 0 }T +T{ 0 0 MAX-BASE GN1 -> 0 0 0 }T +T{ MAX-UINT 0 MAX-BASE GN1 -> MAX-UINT 0 0 }T +T{ MAX-UINT DUP MAX-BASE GN1 -> MAX-UINT DUP 0 }T + +: GN2 \ ( -- 16 10 ) + BASE @ >R HEX BASE @ DECIMAL BASE @ R> BASE ! ; +T{ GN2 -> 10 A }T + +\ ------------------------------------------------------------------------ +TESTING FILL MOVE + +CREATE FBUF 00 C, 00 C, 00 C, +CREATE SBUF 12 C, 34 C, 56 C, +: SEEBUF FBUF C@ FBUF CHAR+ C@ FBUF CHAR+ CHAR+ C@ ; + +T{ FBUF 0 20 FILL -> }T +T{ SEEBUF -> 00 00 00 }T + +T{ FBUF 1 20 FILL -> }T +T{ SEEBUF -> 20 00 00 }T + +T{ FBUF 3 20 FILL -> }T +T{ SEEBUF -> 20 20 20 }T + +T{ FBUF FBUF 3 CHARS MOVE -> }T \ BIZARRE SPECIAL CASE +T{ SEEBUF -> 20 20 20 }T + +T{ SBUF FBUF 0 CHARS MOVE -> }T +T{ SEEBUF -> 20 20 20 }T + +T{ SBUF FBUF 1 CHARS MOVE -> }T +T{ SEEBUF -> 12 20 20 }T + +T{ SBUF FBUF 3 CHARS MOVE -> }T +T{ SEEBUF -> 12 34 56 }T + +T{ FBUF FBUF CHAR+ 2 CHARS MOVE -> }T +T{ SEEBUF -> 12 12 34 }T + +T{ FBUF CHAR+ FBUF 2 CHARS MOVE -> }T +T{ SEEBUF -> 12 34 34 }T + +\ ------------------------------------------------------------------------ +TESTING OUTPUT: . ." CR EMIT SPACE SPACES TYPE U. + +: OUTPUT-TEST + ." YOU SHOULD SEE THE STANDARD GRAPHIC CHARACTERS:" CR + 41 BL DO I EMIT LOOP CR + 61 41 DO I EMIT LOOP CR + 7F 61 DO I EMIT LOOP CR + ." YOU SHOULD SEE 0-9 SEPARATED BY A SPACE:" CR + 9 1+ 0 DO I . LOOP CR + ." YOU SHOULD SEE 0-9 (WITH NO SPACES):" CR + [CHAR] 9 1+ [CHAR] 0 DO I 0 SPACES EMIT LOOP CR + ." YOU SHOULD SEE A-G SEPARATED BY A SPACE:" CR + [CHAR] G 1+ [CHAR] A DO I EMIT SPACE LOOP CR + ." YOU SHOULD SEE 0-5 SEPARATED BY TWO SPACES:" CR + 5 1+ 0 DO I [CHAR] 0 + EMIT 2 SPACES LOOP CR + ." YOU SHOULD SEE TWO SEPARATE LINES:" CR + S" LINE 1" TYPE CR S" LINE 2" TYPE CR + ." YOU SHOULD SEE THE NUMBER RANGES OF SIGNED AND UNSIGNED NUMBERS:" CR + ." SIGNED: " MIN-INT . MAX-INT . CR + ." UNSIGNED: " 0 U. MAX-UINT U. CR +; + +T{ OUTPUT-TEST -> }T + + +\ ------------------------------------------------------------------------ +TESTING INPUT: ACCEPT + +CREATE ABUF 80 CHARS ALLOT + +: ACCEPT-TEST + CR ." PLEASE TYPE UP TO 80 CHARACTERS:" CR + ABUF 80 ACCEPT + CR ." RECEIVED: " [CHAR] " EMIT + ABUF SWAP TYPE [CHAR] " EMIT CR +; + +T{ ACCEPT-TEST -> }T + +\ ------------------------------------------------------------------------ +TESTING DICTIONARY SEARCH RULES + +T{ : GDX 123 ; : GDX GDX 234 ; -> }T + +T{ GDX -> 123 234 }T + +CR .( End of Core word set tests) CR + + diff --git a/amforth-6.5/common/lib/forth2012/tester/coreexttest.fth b/amforth-6.5/common/lib/forth2012/tester/coreexttest.fth new file mode 100644 index 0000000..a7de63d --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/coreexttest.fth @@ -0,0 +1,322 @@ +\ To test some of the ANS Forth Core Extension word set + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.6 1 April 2012 Tests placed in the public domain. +\ SAVE-INPUT & RESTORE-INPUT tests, position +\ of T{ moved so that tests work with ttester.fs +\ CONVERT test deleted - obsolete word removed from Forth 200X +\ IMMEDIATE VALUEs tested +\ RECURSE with :NONAME tested +\ PARSE and .( tested +\ Parsing behaviour of C" added +\ 0.5 14 September 2011 Removed the double [ELSE] from the +\ initial SAVE-INPUT & RESTORE-INPUT test +\ 0.4 30 November 2009 max-int replaced with max-intx to +\ avoid redefinition warnings. +\ 0.3 6 March 2009 { and } replaced with T{ and }T +\ CONVERT test now independent of cell size +\ 0.2 20 April 2007 ANS Forth words changed to upper case +\ Tests qd3 to qd6 by Reinhold Straub +\ 0.1 Oct 2006 First version released +\ ------------------------------------------------------------------------------ +\ This is only a partial test of the core extension words. +\ The tests are based on John Hayes test program for the core word set + +\ Words tested in this file are: +\ TRUE FALSE :NONAME ?DO VALUE TO CASE OF ENDOF ENDCASE PARSE +\ C" CONVERT COMPILE, [COMPILE] SAVE-INPUT RESTORE-INPUT .( +\ ------------------------------------------------------------------------------ +\ Assumptions: +\ - tester.fr or ttester.fs has been included prior to this file +\ ------------------------------------------------------------------------------ +TESTING Core Extension words + +DECIMAL + +0 INVERT 1 RSHIFT CONSTANT max-intx \ 01...1 + + +TESTING TRUE FALSE + +T{ TRUE -> 0 INVERT }T +T{ FALSE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING :NONAME with and without RECURSEs + +VARIABLE nn1 +VARIABLE nn2 +:NONAME 1234 ; nn1 ! +:NONAME 9876 ; nn2 ! +T{ nn1 @ EXECUTE -> 1234 }T +T{ nn2 @ EXECUTE -> 9876 }T + +T{ :NONAME ( n -- 0,1,..n ) DUP IF DUP >R 1- RECURSE R> THEN ; + CONSTANT rn1 -> }T +T{ 0 rn1 EXECUTE -> 0 }T +T{ 4 rn1 EXECUTE -> 0 1 2 3 4 }T + +:NONAME ( n -- n1 ) \ Multiple RECURSEs in one definition + 1- DUP + CASE 0 OF EXIT ENDOF + 1 OF 11 SWAP RECURSE ENDOF + 2 OF 22 SWAP RECURSE ENDOF + 3 OF 33 SWAP RECURSE ENDOF + DROP ABS RECURSE EXIT + ENDCASE +; CONSTANT rn2 + +T{ 1 rn2 EXECUTE -> 0 }T +T{ 2 rn2 EXECUTE -> 11 0 }T +T{ 4 rn2 EXECUTE -> 33 22 11 0 }T +T{ 25 rn2 EXECUTE -> 33 22 11 0 }T + +\ ------------------------------------------------------------------------------ +TESTING ?DO + +: qd ?DO I LOOP ; +T{ 789 789 qd -> }T +T{ -9876 -9876 qd -> }T +T{ 5 0 qd -> 0 1 2 3 4 }T + +: qd1 ?DO I 10 +LOOP ; +T{ 50 1 qd1 -> 1 11 21 31 41 }T +T{ 50 0 qd1 -> 0 10 20 30 40 }T + +: qd2 ?DO I 3 > IF LEAVE ELSE I THEN LOOP ; +T{ 5 -1 qd2 -> -1 0 1 2 3 }T + +: qd3 ?DO I 1 +LOOP ; +T{ 4 4 qd3 -> }T +T{ 4 1 qd3 -> 1 2 3 }T +T{ 2 -1 qd3 -> -1 0 1 }T + +: qd4 ?DO I -1 +LOOP ; +T{ 4 4 qd4 -> }T +T{ 1 4 qd4 -> 4 3 2 1 }T +T{ -1 2 qd4 -> 2 1 0 -1 }T + +: qd5 ?DO I -10 +LOOP ; +T{ 1 50 qd5 -> 50 40 30 20 10 }T +T{ 0 50 qd5 -> 50 40 30 20 10 0 }T +T{ -25 10 qd5 -> 10 0 -10 -20 }T + +VARIABLE iters +VARIABLE incrmnt + +: qd6 ( limit start increment -- ) + incrmnt ! + 0 iters ! + ?DO + 1 iters +! + I + iters @ 6 = IF LEAVE THEN + incrmnt @ + +LOOP iters @ +; + +T{ 4 4 -1 qd6 -> 0 }T +T{ 1 4 -1 qd6 -> 4 3 2 1 4 }T +T{ 4 1 -1 qd6 -> 1 0 -1 -2 -3 -4 6 }T +T{ 4 1 0 qd6 -> 1 1 1 1 1 1 6 }T +T{ 0 0 0 qd6 -> 0 }T +T{ 1 4 0 qd6 -> 4 4 4 4 4 4 6 }T +T{ 1 4 1 qd6 -> 4 5 6 7 8 9 6 }T +T{ 4 1 1 qd6 -> 1 2 3 3 }T +T{ 4 4 1 qd6 -> 0 }T +T{ 2 -1 -1 qd6 -> -1 -2 -3 -4 -5 -6 6 }T +T{ -1 2 -1 qd6 -> 2 1 0 -1 4 }T +T{ 2 -1 0 qd6 -> -1 -1 -1 -1 -1 -1 6 }T +T{ -1 2 0 qd6 -> 2 2 2 2 2 2 6 }T +T{ -1 2 1 qd6 -> 2 3 4 5 6 7 6 }T +T{ 2 -1 1 qd6 -> -1 0 1 3 }T + +\ ------------------------------------------------------------------------------ +TESTING VALUE TO + +T{ 111 VALUE val1 -999 VALUE val2 -> }T +T{ val1 -> 111 }T +T{ val2 -> -999 }T +T{ 222 TO val1 -> }T +T{ val1 -> 222 }T +T{ : vd1 val1 ; -> }T +T{ vd1 -> 222 }T +T{ : vd2 TO val2 ; -> }T +T{ val2 -> -999 }T +T{ -333 vd2 -> }T +T{ val2 -> -333 }T +T{ val1 -> 222 }T +T{ 123 VALUE val3 IMMEDIATE val3 -> 123 }T +T{ : vd3 val3 LITERAL ; vd3 -> 123 }T + +\ ------------------------------------------------------------------------------ +TESTING CASE OF ENDOF ENDCASE + +: cs1 CASE 1 OF 111 ENDOF + 2 OF 222 ENDOF + 3 OF 333 ENDOF + >R 999 R> + ENDCASE +; + +T{ 1 cs1 -> 111 }T +T{ 2 cs1 -> 222 }T +T{ 3 cs1 -> 333 }T +T{ 4 cs1 -> 999 }T + +: cs2 >R CASE -1 OF CASE R@ 1 OF 100 ENDOF + 2 OF 200 ENDOF + >R -300 R> + ENDCASE + ENDOF + -2 OF CASE R@ 1 OF -99 ENDOF + >R -199 R> + ENDCASE + ENDOF + >R 299 R> + ENDCASE R> DROP +; + +T{ -1 1 cs2 -> 100 }T +T{ -1 2 cs2 -> 200 }T +T{ -1 3 cs2 -> -300 }T +T{ -2 1 cs2 -> -99 }T +T{ -2 2 cs2 -> -199 }T +T{ 0 2 cs2 -> 299 }T + +\ ------------------------------------------------------------------------------ +TESTING C" + +T{ : cq1 C" 123" ; -> }T +T{ cq1 COUNT EVALUATE -> 123 }T +T{ : cq2 C" " ; -> }T +T{ cq2 COUNT EVALUATE -> }T +T{ : cq3 C" 2345"COUNT EVALUATE ; cq3 -> 2345 }T + +\ ------------------------------------------------------------------------------ +TESTING COMPILE, [COMPILE] + +:NONAME DUP + ; CONSTANT dup+ +T{ : q dup+ COMPILE, ; -> }T +T{ : as1 [ q ] ; -> }T +T{ 123 as1 -> 246 }T + +T{ : [c1] [COMPILE] DUP ; IMMEDIATE -> }T +T{ 123 [c1] -> 123 123 }T \ With default compilation semantics +T{ : [c2] [COMPILE] [c1] ; -> }T +T{ 234 [c2] -> 234 234 }T \ With an immediate word +T{ : [cif] [COMPILE] IF ; IMMEDIATE -> }T +T{ : [c3] [cif] 111 ELSE 222 THEN ; -> }T \ With special compilation semantics +T{ -1 [c3] -> 111 }T +T{ 0 [c3] -> 222 }T + +\ ------------------------------------------------------------------------------ +\ Cannot automatically test SAVE-INPUT and RESTORE-INPUT from a console source + +TESTING SAVE-INPUT and RESTORE-INPUT with a file source + +VARIABLE siv -1 siv ! + +: NeverExecuted + ." This should never be executed" ABORT +; + +T{ 11111 SAVE-INPUT + +siv @ + +[IF] + 0 siv ! + RESTORE-INPUT + NeverExecuted +[ELSE] + +TESTING the -[ELSE]- part is executed +22222 + +[THEN] + + -> 11111 0 22222 }T \ 0 comes from RESTORE-INPUT + +TESTING SAVE-INPUT and RESTORE-INPUT with a string source + +VARIABLE si_inc 0 si_inc ! + +: si1 + si_inc @ >IN +! + 15 si_inc ! +; + +: s$ S" SAVE-INPUT si1 RESTORE-INPUT 12345" ; + +T{ s$ EVALUATE si_inc @ -> 0 2345 15 }T + +TESTING nested SAVE-INPUT and RESTORE-INPUT + +: read_a_line + REFILL 0= + ABORT" REFILL failed" +; + +0 si_inc ! + +2VARIABLE 2res -1. 2res 2! + +: si2 + read_a_line + read_a_line + SAVE-INPUT + read_a_line + read_a_line + s$ EVALUATE 2res 2! + RESTORE-INPUT +; + +\ WARNING: do not delete or insert lines of text after si2 is called +\ otherwise the next test will fail + +T{ si2 +33333 \ This line should be ignored +2res 2@ 44444 \ RESTORE-INPUT should return to this line + +55555 +TESTING the nested results + -> 0 0 2345 44444 55555 }T + +\ End of warning + +\ ------------------------------------------------------------------------------ +TESTING .( + +T{ S" A string"2DROP -> }T +T{ CR .( You should see -9876: ) -9876 . -> }T +T{ CR .( Repeated: ).( -9876)CR -> }T + +\ ------------------------------------------------------------------------------ +TESTING PARSE + +T{ CHAR | PARSE 1234| DUP ROT ROT EVALUATE -> 4 1234 }T +T{ CHAR ^ PARSE 23 45 ^ DUP ROT ROT EVALUATE -> 7 23 45 }T +: pa1 [CHAR] $ PARSE DUP >R PAD SWAP CHARS MOVE PAD R> ; +T{ pa1 3456 + DUP ROT ROT EVALUATE -> 4 3456 }T +T{ CHAR a PARSE a SWAP DROP -> 0 }T +T{ CHAR z PARSE + SWAP DROP -> 0 }T +T{ CHAR " PARSE 4567 "DUP ROT ROT EVALUATE -> 5 4567 }T + +\ ------------------------------------------------------------------------------ + +CR .( End of Core Extension word tests) CR + + diff --git a/amforth-6.5/common/lib/forth2012/tester/coreplustest.fth b/amforth-6.5/common/lib/forth2012/tester/coreplustest.fth new file mode 100644 index 0000000..ff165d4 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/coreplustest.fth @@ -0,0 +1,190 @@ +\ Additional tests on the the ANS Forth Core word set + +\ This program was written by Gerry Jackson in 2007, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.3 1 April 2012 Tests placed in the public domain. +\ Testing multiple ELSE's. +\ Further tests on DO +LOOPs. +\ Ackermann function added to test RECURSE. +\ >IN manipulation in interpreter mode +\ Immediate CONSTANTs, VARIABLEs and CREATEd words tests. +\ :NONAME with RECURSE moved to core extension tests. +\ Parsing behaviour of S" ." and ( tested +\ 0.2 6 March 2009 { and } replaced with T{ and }T +\ Added extra RECURSE tests +\ 0.1 20 April 2007 Created +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ +\ This file provides some more tests on Core words where the original Hayes +\ tests are thought to be incomplete +\ +\ Words tested in this file are: +\ DO +LOOP RECURSE ELSE >IN IMMEDIATE +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - core.fr has been loaded so that constants MAX-INT, MIN-INT and +\ MAX-UINT are defined +\ ------------------------------------------------------------------------------ + +DECIMAL + +TESTING DO +LOOP with run-time increment, negative increment, infinite loop +\ Contributed by Reinhold Straub + +VARIABLE iterations +VARIABLE increment +: gd7 ( limit start increment -- ) + increment ! + 0 iterations ! + DO + 1 iterations +! + I + iterations @ 6 = IF LEAVE THEN + increment @ + +LOOP iterations @ +; + +T{ 4 4 -1 gd7 -> 4 1 }T +T{ 1 4 -1 gd7 -> 4 3 2 1 4 }T +T{ 4 1 -1 gd7 -> 1 0 -1 -2 -3 -4 6 }T +T{ 4 1 0 gd7 -> 1 1 1 1 1 1 6 }T +T{ 0 0 0 gd7 -> 0 0 0 0 0 0 6 }T +T{ 1 4 0 gd7 -> 4 4 4 4 4 4 6 }T +T{ 1 4 1 gd7 -> 4 5 6 7 8 9 6 }T +T{ 4 1 1 gd7 -> 1 2 3 3 }T +T{ 4 4 1 gd7 -> 4 5 6 7 8 9 6 }T +T{ 2 -1 -1 gd7 -> -1 -2 -3 -4 -5 -6 6 }T +T{ -1 2 -1 gd7 -> 2 1 0 -1 4 }T +T{ 2 -1 0 gd7 -> -1 -1 -1 -1 -1 -1 6 }T +T{ -1 2 0 gd7 -> 2 2 2 2 2 2 6 }T +T{ -1 2 1 gd7 -> 2 3 4 5 6 7 6 }T +T{ 2 -1 1 gd7 -> -1 0 1 3 }T +T{ -20 30 -10 gd7 -> 30 20 10 0 -10 -20 6 }T +T{ -20 31 -10 gd7 -> 31 21 11 1 -9 -19 6 }T +T{ -20 29 -10 gd7 -> 29 19 9 -1 -11 5 }T + +\ ------------------------------------------------------------------------------ +TESTING DO +LOOP with large and small increments + +\ Contributed by Andrew Haley + +MAX-UINT 8 RSHIFT 1+ CONSTANT ustep +ustep NEGATE CONSTANT -ustep +MAX-INT 7 RSHIFT 1+ CONSTANT step +step NEGATE CONSTANT -step + +VARIABLE bump + +T{ : gd8 bump ! DO 1+ bump @ +LOOP ; -> }T + +T{ 0 MAX-UINT 0 ustep gd8 -> 256 }T +T{ 0 0 MAX-UINT -ustep gd8 -> 256 }T + +T{ 0 MAX-INT MIN-INT step gd8 -> 256 }T +T{ 0 MIN-INT MAX-INT -step gd8 -> 256 }T + +\ Two's complement arithmetic, wraps around modulo wordsize +\ Only tested if the Forth system does wrap around, use of conditional +\ compilation deliberately avoided + +MAX-INT 1+ MIN-INT = CONSTANT +wrap? +MIN-INT 1- MAX-INT = CONSTANT -wrap? +MAX-UINT 1+ 0= CONSTANT +uwrap? +0 1- MAX-UINT = CONSTANT -uwrap? + +: gd9 ( n limit start step f result -- ) + >R IF gd8 ELSE 2DROP 2DROP R@ THEN -> R> }T +; + +T{ 0 0 0 ustep +uwrap? 256 gd9 +T{ 0 0 0 -ustep -uwrap? 1 gd9 +T{ 0 MIN-INT MAX-INT step +wrap? 1 gd9 +T{ 0 MAX-INT MIN-INT -step -wrap? 1 gd9 + +\ ------------------------------------------------------------------------------ +TESTING DO +LOOP with maximum and minimum increments + +: (-mi) MAX-INT DUP NEGATE + 0= IF MAX-INT NEGATE ELSE -32767 THEN ; +(-mi) CONSTANT -max-int + +T{ 0 1 0 MAX-INT gd8 -> 1 }T +T{ 0 -max-int NEGATE -max-int OVER gd8 -> 2 }T + +T{ 0 MAX-INT 0 MAX-INT gd8 -> 1 }T +T{ 0 MAX-INT 1 MAX-INT gd8 -> 1 }T +T{ 0 MAX-INT -1 MAX-INT gd8 -> 2 }T +T{ 0 MAX-INT dup 1- MAX-INT gd8 -> 1 }T + +T{ 0 MIN-INT 1+ 0 MIN-INT gd8 -> 1 }T +T{ 0 MIN-INT 1+ -1 MIN-INT gd8 -> 1 }T +T{ 0 MIN-INT 1+ 1 MIN-INT gd8 -> 2 }T +T{ 0 MIN-INT 1+ DUP MIN-INT gd8 -> 1 }T + +\ ------------------------------------------------------------------------------ +TESTING multiple RECURSEs in one colon definition + +: ack ( m n -- u ) \ Ackermann function, from Rosetta Code + OVER 0= IF NIP 1+ EXIT THEN \ ack(0, n) = n+1 + SWAP 1- SWAP ( -- m-1 n ) + DUP 0= IF 1+ RECURSE EXIT THEN \ ack(m, 0) = ack(m-1, 1) + 1- OVER 1+ SWAP RECURSE RECURSE \ ack(m, n) = ack(m-1, ack(m,n-1)) +; + +T{ 0 0 ack -> 1 }T +T{ 3 0 ack -> 5 }T +T{ 2 4 ack -> 11 }T + +\ ------------------------------------------------------------------------------ +TESTING multiple ELSE's in an IF statement +\ Discussed on comp.lang.forth and accepted as valid ANS Forth + +: melse IF 1 ELSE 2 ELSE 3 ELSE 4 ELSE 5 THEN ; +T{ 0 melse -> 2 4 }T +T{ -1 melse -> 1 3 5 }T + +\ ------------------------------------------------------------------------------ +TESTING manipulation of >IN in interpreter mode + +T{ 123456 depth over 9 < 35 and + 3 + >in ! -> 123456 23456 3456 456 56 6 }T +T{ 14145 8115 ?dup 0= 34 and >in +! tuck mod 14 >in ! GCD calculation -> 15 }T + +\ ------------------------------------------------------------------------------ +TESTING IMMEDIATE with CONSTANT VARIABLE and CREATE [ ... DOES> ] + +T{ 123 CONSTANT iw1 IMMEDIATE iw1 -> 123 }T +T{ : iw2 iw1 LITERAL ; iw2 -> 123 }T +T{ VARIABLE iw3 IMMEDIATE 234 iw3 ! iw3 @ -> 234 }T +T{ : iw4 iw3 [ @ ] LITERAL ; iw4 -> 234 }T +T{ :noname [ 345 ] iw3 [ ! ] ; DROP iw3 @ -> 345 }T +T{ CREATE iw5 456 , IMMEDIATE -> }T +T{ :noname iw5 [ @ iw3 ! ] ; DROP iw3 @ -> 456 }T +T{ : iw6 CREATE , IMMEDIATE DOES> @ 1+ ; -> }T +T{ 111 iw6 iw7 iw7 -> 112 }T +T{ : iw8 iw7 LITERAL 1+ ; iw8 -> 113 }T +T{ : iw9 CREATE , DOES> @ 2 + IMMEDIATE ; -> }T +: find-iw bl word find nip ; ( -- 0 | 1 | -1 ) +T{ 222 iw9 iw10 find-iw iw10 -> -1 }T \ iw10 is not immediate +T{ iw10 find-iw iw10 -> 224 1 }T \ iw10 becomes immediate + +\ ------------------------------------------------------------------------------ +TESTING parsing behaviour of S" ." and ( +\ which should parse to just beyond the terminating character no space needed + +T{ S" A string"2DROP -> }T +T{ ( A comment)1234 -> 1234 }T +T{ : pb1 cr ." You should see 2345: "." 2345"( A comment); pb1 -> }T + +\ ------------------------------------------------------------------------------ + +CR .( End of additional Core tests) CR diff --git a/amforth-6.5/common/lib/forth2012/tester/doubletest.fth b/amforth-6.5/common/lib/forth2012/tester/doubletest.fth new file mode 100644 index 0000000..523b110 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/doubletest.fth @@ -0,0 +1,386 @@ +\ To test the ANS Forth Double-Number word set and double number extensions + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct +\ ------------------------------------------------------------------------------ +\ Version 0.6 1 April 2012 Tests placed in the public domain. +\ Immediate 2CONSTANTs and 2VARIABLEs tested +\ 0.5 20 November 2009 Various constants renamed to avoid +\ redefinition warnings. and replaced +\ with TRUE and FALSE +\ 0.4 6 March 2009 { and } replaced with T{ and }T +\ Tests rewritten to be independent of word size and +\ tests re-ordered +\ 0.3 20 April 2007 ANS Forth words changed to upper case +\ 0.2 30 Oct 2006 Updated following GForth test to include +\ various constants from core.fr +\ 0.1 Oct 2006 First version released +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set + +\ Words tested in this file are: +\ 2CONSTANT 2LITERAL 2VARIABLE D+ D- D. D.R D0< D0= D2* D2/ +\ D< D= D>S DABS DMAX DMIN DNEGATE M*/ M+ 2ROT DU< +\ Also tests the interpreter and compiler reading a double number +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - tester.fr or ttester.fs has been included prior to this file +\ - core words and core extension words have been tested +\ ------------------------------------------------------------------------------ +\ Constant definitions + +DECIMAL +0 INVERT CONSTANT 1sd +1sd 1 RSHIFT CONSTANT max-intd \ 01...1 +max-intd INVERT CONSTANT min-intd \ 10...0 +max-intd 2/ CONSTANT hi-int \ 001...1 +min-intd 2/ CONSTANT lo-int \ 110...1 + +\ ------------------------------------------------------------------------------ +TESTING interpreter and compiler reading a double number + +T{ 1. -> 1 0 }T +T{ -2. -> -2 -1 }T +T{ : rdl1 3. ; rdl1 -> 3 0 }T +T{ : rdl2 -4. ; rdl2 -> -4 -1 }T + +\ ------------------------------------------------------------------------------ +TESTING 2CONSTANT + +T{ 1 2 2CONSTANT 2c1 -> }T +T{ 2c1 -> 1 2 }T +T{ : cd1 2c1 ; -> }T +T{ cd1 -> 1 2 }T +T{ : cd2 2CONSTANT ; -> }T +T{ -1 -2 cd2 2c2 -> }T +T{ 2c2 -> -1 -2 }T +T{ 4 5 2CONSTANT 2c3 IMMEDIATE 2c3 -> 4 5 }T +T{ : cd6 2c3 2LITERAL ; cd6 -> 4 5 }T + +\ ------------------------------------------------------------------------------ +\ Some 2CONSTANTs for the following tests + +1sd max-intd 2CONSTANT max-2int \ 01...1 +0 min-intd 2CONSTANT min-2int \ 10...0 +max-2int 2/ 2CONSTANT hi-2int \ 001...1 +min-2int 2/ 2CONSTANT lo-2int \ 110...0 + +\ ------------------------------------------------------------------------------ +TESTING DNEGATE + +T{ 0. DNEGATE -> 0. }T +T{ 1. DNEGATE -> -1. }T +T{ -1. DNEGATE -> 1. }T +T{ max-2int DNEGATE -> min-2int SWAP 1+ SWAP }T +T{ min-2int SWAP 1+ SWAP DNEGATE -> max-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D+ with small integers + +T{ 0. 5. D+ -> 5. }T +T{ -5. 0. D+ -> -5. }T +T{ 1. 2. D+ -> 3. }T +T{ 1. -2. D+ -> -1. }T +T{ -1. 2. D+ -> 1. }T +T{ -1. -2. D+ -> -3. }T +T{ -1. 1. D+ -> 0. }T + +TESTING D+ with mid range integers + +T{ 0 0 0 5 D+ -> 0 5 }T +T{ -1 5 0 0 D+ -> -1 5 }T +T{ 0 0 0 -5 D+ -> 0 -5 }T +T{ 0 -5 -1 0 D+ -> -1 -5 }T +T{ 0 1 0 2 D+ -> 0 3 }T +T{ -1 1 0 -2 D+ -> -1 -1 }T +T{ 0 -1 0 2 D+ -> 0 1 }T +T{ 0 -1 -1 -2 D+ -> -1 -3 }T +T{ -1 -1 0 1 D+ -> -1 0 }T +T{ min-intd 0 2DUP D+ -> 0 1 }T +T{ min-intd S>D min-intd 0 D+ -> 0 0 }T + +TESTING D+ with large double integers + +T{ hi-2int 1. D+ -> 0 hi-int 1+ }T +T{ hi-2int 2DUP D+ -> 1sd 1- max-intd }T +T{ max-2int min-2int D+ -> -1. }T +T{ max-2int lo-2int D+ -> hi-2int }T +T{ hi-2int min-2int D+ 1. D+ -> lo-2int }T +T{ lo-2int 2DUP D+ -> min-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D- with small integers + +T{ 0. 5. D- -> -5. }T +T{ 5. 0. D- -> 5. }T +T{ 0. -5. D- -> 5. }T +T{ 1. 2. D- -> -1. }T +T{ 1. -2. D- -> 3. }T +T{ -1. 2. D- -> -3. }T +T{ -1. -2. D- -> 1. }T +T{ -1. -1. D- -> 0. }T + +TESTING D- with mid-range integers + +T{ 0 0 0 5 D- -> 0 -5 }T +T{ -1 5 0 0 D- -> -1 5 }T +T{ 0 0 -1 -5 D- -> 1 4 }T +T{ 0 -5 0 0 D- -> 0 -5 }T +T{ -1 1 0 2 D- -> -1 -1 }T +T{ 0 1 -1 -2 D- -> 1 2 }T +T{ 0 -1 0 2 D- -> 0 -3 }T +T{ 0 -1 0 -2 D- -> 0 1 }T +T{ 0 0 0 1 D- -> 0 -1 }T +T{ min-intd 0 2DUP D- -> 0. }T +T{ min-intd S>D max-intd 0 D- -> 1 1sd }T + +TESTING D- with large integers + +T{ max-2int max-2int D- -> 0. }T +T{ min-2int min-2int D- -> 0. }T +T{ max-2int hi-2int D- -> lo-2int DNEGATE }T +T{ hi-2int lo-2int D- -> max-2int }T +T{ lo-2int hi-2int D- -> min-2int 1. D+ }T +T{ min-2int min-2int D- -> 0. }T +T{ min-2int lo-2int D- -> lo-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D0< D0= + +T{ 0. D0< -> FALSE }T +T{ 1. D0< -> FALSE }T +T{ min-intd 0 D0< -> FALSE }T +T{ 0 max-intd D0< -> FALSE }T +T{ max-2int D0< -> FALSE }T +T{ -1. D0< -> TRUE }T +T{ min-2int D0< -> TRUE }T + +T{ 1. D0= -> FALSE }T +T{ min-intd 0 D0= -> FALSE }T +T{ max-2int D0= -> FALSE }T +T{ -1 max-intd D0= -> FALSE }T +T{ 0. D0= -> TRUE }T +T{ -1. D0= -> FALSE }T +T{ 0 min-intd D0= -> FALSE }T + +\ ------------------------------------------------------------------------------ +TESTING D2* D2/ + +T{ 0. D2* -> 0. D2* }T +T{ min-intd 0 D2* -> 0 1 }T +T{ hi-2int D2* -> max-2int 1. D- }T +T{ lo-2int D2* -> min-2int }T + +T{ 0. D2/ -> 0. }T +T{ 1. D2/ -> 0. }T +T{ 0 1 D2/ -> min-intd 0 }T +T{ max-2int D2/ -> hi-2int }T +T{ -1. D2/ -> -1. }T +T{ min-2int D2/ -> lo-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D< D= + +T{ 0. 1. D< -> TRUE }T +T{ 0. 0. D< -> FALSE }T +T{ 1. 0. D< -> FALSE }T +T{ -1. 1. D< -> TRUE }T +T{ -1. 0. D< -> TRUE }T +T{ -2. -1. D< -> TRUE }T +T{ -1. -2. D< -> FALSE }T +T{ -1. max-2int D< -> TRUE }T +T{ min-2int max-2int D< -> TRUE }T +T{ max-2int -1. D< -> FALSE }T +T{ max-2int min-2int D< -> FALSE }T +T{ max-2int 2DUP -1. D+ D< -> FALSE }T +T{ min-2int 2DUP 1. D+ D< -> TRUE }T + +T{ -1. -1. D= -> TRUE }T +T{ -1. 0. D= -> FALSE }T +T{ -1. 1. D= -> FALSE }T +T{ 0. -1. D= -> FALSE }T +T{ 0. 0. D= -> TRUE }T +T{ 0. 1. D= -> FALSE }T +T{ 1. -1. D= -> FALSE }T +T{ 1. 0. D= -> FALSE }T +T{ 1. 1. D= -> TRUE }T + +T{ 0 -1 0 -1 D= -> TRUE }T +T{ 0 -1 0 0 D= -> FALSE }T +T{ 0 -1 0 1 D= -> FALSE }T +T{ 0 0 0 -1 D= -> FALSE }T +T{ 0 0 0 0 D= -> TRUE }T +T{ 0 0 0 1 D= -> FALSE }T +T{ 0 1 0 -1 D= -> FALSE }T +T{ 0 1 0 0 D= -> FALSE }T +T{ 0 1 0 1 D= -> TRUE }T + +T{ max-2int min-2int D= -> FALSE }T +T{ max-2int 0. D= -> FALSE }T +T{ max-2int max-2int D= -> TRUE }T +T{ max-2int hi-2int D= -> FALSE }T +T{ max-2int min-2int D= -> FALSE }T +T{ min-2int min-2int D= -> TRUE }T +T{ min-2int lo-2int D= -> FALSE }T +T{ min-2int max-2int D= -> FALSE }T + +\ ------------------------------------------------------------------------------ +TESTING 2LITERAL 2VARIABLE + +T{ : cd3 [ max-2int ] 2LITERAL ; -> }T +T{ cd3 -> max-2int }T +T{ 2VARIABLE 2v1 -> }T +T{ 0. 2v1 2! -> }T +T{ 2v1 2@ -> 0. }T +T{ -1 -2 2v1 2! -> }T +T{ 2v1 2@ -> -1 -2 }T +T{ : cd4 2VARIABLE ; -> }T +T{ cd4 2v2 -> }T +T{ : cd5 2v2 2! ; -> }T +T{ -2 -1 cd5 -> }T +T{ 2v2 2@ -> -2 -1 }T +T{ 2VARIABLE 2v3 IMMEDIATE 5 6 2v3 2! -> }T +T{ 2v3 2@ -> 5 6 }T +T{ : cd7 2v3 [ 2@ ] 2LITERAL ; cd7 -> 5 6 }T +T{ : cd8 [ 6 7 ] 2v3 [ 2! ] ; 2v3 2@ -> 6 7 }T + +\ ------------------------------------------------------------------------------ +TESTING DMAX DMIN + +T{ 1. 2. DMAX -> 2. }T +T{ 1. 0. DMAX -> 1. }T +T{ 1. -1. DMAX -> 1. }T +T{ 1. 1. DMAX -> 1. }T +T{ 0. 1. DMAX -> 1. }T +T{ 0. -1. DMAX -> 0. }T +T{ -1. 1. DMAX -> 1. }T +T{ -1. -2. DMAX -> -1. }T + +T{ max-2int hi-2int DMAX -> max-2int }T +T{ max-2int min-2int DMAX -> max-2int }T +T{ min-2int max-2int DMAX -> max-2int }T +T{ min-2int lo-2int DMAX -> lo-2int }T + +T{ max-2int 1. DMAX -> max-2int }T +T{ max-2int -1. DMAX -> max-2int }T +T{ min-2int 1. DMAX -> 1. }T +T{ min-2int -1. DMAX -> -1. }T + + +T{ 1. 2. DMIN -> 1. }T +T{ 1. 0. DMIN -> 0. }T +T{ 1. -1. DMIN -> -1. }T +T{ 1. 1. DMIN -> 1. }T +T{ 0. 1. DMIN -> 0. }T +T{ 0. -1. DMIN -> -1. }T +T{ -1. 1. DMIN -> -1. }T +T{ -1. -2. DMIN -> -2. }T + +T{ max-2int hi-2int DMIN -> hi-2int }T +T{ max-2int min-2int DMIN -> min-2int }T +T{ min-2int max-2int DMIN -> min-2int }T +T{ min-2int lo-2int DMIN -> min-2int }T + +T{ max-2int 1. DMIN -> 1. }T +T{ max-2int -1. DMIN -> -1. }T +T{ min-2int 1. DMIN -> min-2int }T +T{ min-2int -1. DMIN -> min-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D>S DABS + +T{ 1234 0 D>S -> 1234 }T +T{ -1234 -1 D>S -> -1234 }T +T{ max-intd 0 D>S -> max-intd }T +T{ min-intd -1 D>S -> min-intd }T + +T{ 1. DABS -> 1. }T +T{ -1. DABS -> 1. }T +T{ max-2int DABS -> max-2int }T +T{ min-2int 1. D+ DABS -> max-2int }T + +\ ------------------------------------------------------------------------------ +TESTING M+ M*/ + +T{ hi-2int 1 M+ -> hi-2int 1. D+ }T +T{ max-2int -1 M+ -> max-2int -1. D+ }T +T{ min-2int 1 M+ -> min-2int 1. D+ }T +T{ lo-2int -1 M+ -> lo-2int -1. D+ }T + +\ To correct the result if the division is floored, only used when +\ necessary i.e. negative quotient and remainder <> 0 + +: ?floored [ -3 2 / -2 = ] LITERAL IF 1. D- THEN ; + +T{ 5. 7 11 M*/ -> 3. }T +T{ 5. -7 11 M*/ -> -3. ?floored }T \ floored -4. +T{ -5. 7 11 M*/ -> -3. ?floored }T \ floored -4. +T{ -5. -7 11 M*/ -> 3. }T +T{ max-2int 8 16 M*/ -> hi-2int }T +T{ max-2int -8 16 M*/ -> hi-2int DNEGATE ?floored }T \ floored subtract 1 +T{ min-2int 8 16 M*/ -> lo-2int }T +T{ min-2int -8 16 M*/ -> lo-2int DNEGATE }T +T{ max-2int max-intd max-intd M*/ -> max-2int }T +T{ max-2int max-intd 2/ max-intd M*/ -> max-intd 1- hi-2int NIP }T +T{ min-2int lo-2int NIP DUP NEGATE M*/ -> min-2int }T +T{ min-2int lo-2int NIP 1- max-intd M*/ -> min-intd 3 + hi-2int NIP 2 + }T +T{ max-2int lo-2int NIP DUP NEGATE M*/ -> max-2int DNEGATE }T +T{ min-2int max-intd DUP M*/ -> min-2int }T + +\ ------------------------------------------------------------------------------ +TESTING D. D.R + +\ Create some large double numbers +max-2int 71 73 M*/ 2CONSTANT dbl1 +min-2int 73 79 M*/ 2CONSTANT dbl2 + +: d>ascii ( d -- caddr u ) + DUP >R <# DABS #S R> SIGN #> ( -- caddr1 u ) + HERE SWAP 2DUP 2>R CHARS DUP ALLOT MOVE 2R> +; + +dbl1 d>ascii 2CONSTANT "dbl1" +dbl2 d>ascii 2CONSTANT "dbl2" + +: DoubleOutput + CR ." You should see lines duplicated:" CR + 5 SPACES "dbl1" TYPE CR + 5 SPACES dbl1 D. CR + 8 SPACES "dbl1" DUP >R TYPE CR + 5 SPACES dbl1 R> 3 + D.R CR + 5 SPACES "dbl2" TYPE CR + 5 SPACES dbl2 D. CR + 10 SPACES "dbl2" DUP >R TYPE CR + 5 SPACES dbl2 R> 5 + D.R CR +; + +T{ DoubleOutput -> }T + +\ ------------------------------------------------------------------------------ +TESTING 2ROT DU< (Double Number extension words) + +T{ 1. 2. 3. 2ROT -> 2. 3. 1. }T +T{ max-2int min-2int 1. 2ROT -> min-2int 1. max-2int }T + +T{ 1. 1. DU< -> FALSE }T +T{ 1. -1. DU< -> TRUE }T +T{ -1. 1. DU< -> FALSE }T +T{ -1. -2. DU< -> FALSE }T + +T{ max-2int hi-2int DU< -> FALSE }T +T{ hi-2int max-2int DU< -> TRUE }T +T{ max-2int min-2int DU< -> TRUE }T +T{ min-2int max-2int DU< -> FALSE }T +T{ min-2int lo-2int DU< -> TRUE }T + +\ ------------------------------------------------------------------------------ + +CR .( End of Double-Number word tests) CR + diff --git a/amforth-6.5/common/lib/forth2012/tester/exceptiontest.fth b/amforth-6.5/common/lib/forth2012/tester/exceptiontest.fth new file mode 100644 index 0000000..7b612bf --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/exceptiontest.fth @@ -0,0 +1,96 @@ +\ To test the ANS Forth Exception word set and extension words + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.4 1 April 2012 Tests placed in the public domain. +\ 0.3 6 March 2009 { and } replaced with T{ and }T +\ 0.2 20 April 2007 ANS Forth words changed to upper case +\ 0.1 Oct 2006 First version released + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ +\ Words tested in this file are: +\ CATCH THROW ABORT ABORT" +\ +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - the forth system under test throws an exception with throw +\ code -13 for a word not found by the text interpreter. The +\ undefined word used is $$qweqweqwert$$, if this happens to be +\ a valid word in your system change the definition of t7 below +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - CASE, OF, ENDOF and ENDCASE from the core extension wordset +\ are present and work correctly +\ ------------------------------------------------------------------------------ +TESTING CATCH THROW + +DECIMAL + +: t1 9 ; +: c1 1 2 3 ['] t1 CATCH ; +T{ c1 -> 1 2 3 9 0 }T \ No THROW executed + +: t2 8 0 THROW ; +: c2 1 2 ['] t2 CATCH ; +T{ c2 -> 1 2 8 0 }T \ 0 THROW does nothing + +: t3 7 8 9 99 THROW ; +: c3 1 2 ['] t3 CATCH ; +T{ c3 -> 1 2 99 }T \ Restores stack to CATCH depth + +: t4 1- DUP 0> IF RECURSE ELSE 999 THROW -222 THEN ; +: c4 3 4 5 10 ['] t4 CATCH -111 ; +T{ c4 -> 3 4 5 0 999 -111 }T \ Test return stack unwinding + +: t5 2DROP 2DROP 9999 THROW ; +: c5 1 2 3 4 ['] t5 CATCH \ Test depth restored correctly + DEPTH >R DROP 2DROP 2DROP R> ; \ after stack has been emptied +T{ c5 -> 5 }T + +\ ------------------------------------------------------------------------------ +TESTING ABORT ABORT" + +-1 CONSTANT exc_abort +-2 CONSTANT exc_abort" +-13 CONSTANT exc_undef +: t6 ABORT ; + +\ The 77 in t10 is necessary for the second ABORT" test as the data stack +\ is restored to a depth of 2 when THROW is executed. The 77 ensures the top +\ of stack value is known for the results check + +: t10 77 SWAP ABORT" This should not be displayed" ; +: c6 CATCH + CASE exc_abort OF 11 ENDOF + exc_abort" OF 12 ENDOF + exc_undef OF 13 ENDOF + ENDCASE +; + +T{ 1 2 ' t6 c6 -> 1 2 11 }T \ Test that ABORT is caught +T{ 3 0 ' t10 c6 -> 3 77 }T \ ABORT" does nothing +T{ 4 5 ' t10 c6 -> 4 77 12 }T \ ABORT" caught, no message + +\ ------------------------------------------------------------------------------ +TESTING a system generated exception + +: t7 S" 333 $$qweqweqwert$$ 334" EVALUATE 335 ; +: t8 S" 222 t7 223" EVALUATE 224 ; +: t9 S" 111 112 t8 113" EVALUATE 114 ; + +T{ 6 7 ' t9 c6 3 -> 6 7 13 3 }T \ Test unlinking of sources + +\ ------------------------------------------------------------------------------ + +CR .( End of Exception word tests) CR + diff --git a/amforth-6.5/common/lib/forth2012/tester/filetest.fth b/amforth-6.5/common/lib/forth2012/tester/filetest.fth new file mode 100644 index 0000000..0364360 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/filetest.fth @@ -0,0 +1,193 @@ +\ To test the ANS File Access word set and extension words + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.5 1 April 2012 Tests placed in the public domain. +\ 0.4 22 March 2009 { and } replaced with T{ and }T +\ 0.3 20 April 2007 ANS Forth words changed to upper case. +\ Removed directory test from the filenames. +\ 0.2 30 Oct 2006 updated following GForth tests to remove +\ system dependency on file size, to allow for file +\ buffering and to allow for PAD moving around. +\ 0.1 Oct 2006 First version released. + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ and requires those files to have been loaded + +\ Words tested in this file are: +\ ( BIN CLOSE-FILE CREATE-FILE DELETE-FILE FILE-POSITION FILE-SIZE +\ OPEN-FILE R/O R/W READ-FILE READ-LINE REPOSITION-FILE RESIZE-FILE +\ S" SOURCE-ID W/O WRITE-FILE WRITE-LINE +\ FILE-STATUS FLUSH-FILE RENAME-FILE + +\ Words not tested: +\ REFILL INCLUDED INCLUDE-FILE (as these will likely have been +\ tested in the execution of the test files) +\ ------------------------------------------------------------------------------ +\ Assumptions, dependencies and notes: +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - These tests create files in the current directory, if all goes +\ well these will be deleted. If something fails they may not be +\ deleted. If this is a problem ensure you set a suitable +\ directory before running this test. There is no ANS standard +\ way of doing this. Also be aware of the file names used below +\ which are: fatest1.txt, fatest2.txt and fatest3.txt +\ - TRUE and FALSE are present from the Core extension word set +\ ------------------------------------------------------------------------------ + +TESTING File Access word set + +DECIMAL + +\ ------------------------------------------------------------------------------ +TESTING CREATE-FILE CLOSE-FILE + +: fn1 S" fatest1.txt" ; +VARIABLE fid1 + +T{ fn1 R/W CREATE-FILE SWAP fid1 ! -> 0 }T +T{ fid1 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING OPEN-FILE W/O WRITE-LINE + +: line1 S" Line 1" ; + +T{ fn1 W/O OPEN-FILE SWAP fid1 ! -> 0 }T +T{ line1 fid1 @ WRITE-LINE -> 0 }T +T{ fid1 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING R/O FILE-POSITION (simple) READ-LINE + +200 CONSTANT bsize +CREATE buf bsize ALLOT +VARIABLE #chars + +T{ fn1 R/O OPEN-FILE SWAP fid1 ! -> 0 }T +T{ fid1 @ FILE-POSITION -> 0. 0 }T +T{ buf 100 fid1 @ READ-LINE ROT DUP #chars ! -> TRUE 0 line1 SWAP DROP }T +T{ buf #chars @ line1 COMPARE -> 0 }T +T{ fid1 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING R/W WRITE-FILE REPOSITION-FILE READ-FILE FILE-POSITION S" + +: line2 S" Line 2 blah blah blah" ; +: rl1 buf 100 fid1 @ READ-LINE ; +2VARIABLE fp + +T{ fn1 R/W OPEN-FILE SWAP fid1 ! -> 0 }T +T{ fid1 @ FILE-SIZE DROP fid1 @ REPOSITION-FILE -> 0 }T +T{ fid1 @ FILE-SIZE -> fid1 @ FILE-POSITION }T +T{ line2 fid1 @ WRITE-FILE -> 0 }T +T{ 10. fid1 @ REPOSITION-FILE -> 0 }T +T{ fid1 @ FILE-POSITION -> 10. 0 }T +T{ 0. fid1 @ REPOSITION-FILE -> 0 }T +T{ rl1 -> line1 SWAP DROP TRUE 0 }T +T{ rl1 ROT DUP #chars ! -> TRUE 0 line2 SWAP DROP }T +T{ buf #chars @ line2 COMPARE -> 0 }T +T{ rl1 -> 0 FALSE 0 }T +T{ fid1 @ FILE-POSITION ROT ROT fp 2! -> 0 }T +T{ fp 2@ fid1 @ FILE-SIZE DROP D= -> TRUE }T +T{ S" " fid1 @ WRITE-LINE -> 0 }T +T{ S" " fid1 @ WRITE-LINE -> 0 }T +T{ fp 2@ fid1 @ REPOSITION-FILE -> 0 }T +T{ rl1 -> 0 TRUE 0 }T +T{ rl1 -> 0 TRUE 0 }T +T{ rl1 -> 0 FALSE 0 }T +T{ fid1 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING BIN READ-FILE FILE-SIZE + +: cbuf buf bsize 0 FILL ; +: fn2 S" fatest2.txt" ; +VARIABLE fid2 +: setpad PAD 50 0 DO I OVER C! CHAR+ LOOP DROP ; + +setpad \ If anything else is defined setpad must be called again + \ as pad may move + +T{ fn2 R/W BIN CREATE-FILE SWAP fid2 ! -> 0 }T +T{ PAD 50 fid2 @ WRITE-FILE fid2 @ FLUSH-FILE -> 0 0 }T +T{ fid2 @ FILE-SIZE -> 50. 0 }T +T{ 0. fid2 @ REPOSITION-FILE -> 0 }T +T{ cbuf buf 29 fid2 @ READ-FILE -> 29 0 }T +T{ PAD 29 buf 29 COMPARE -> 0 }T +T{ PAD 30 buf 30 COMPARE -> 1 }T +T{ cbuf buf 29 fid2 @ READ-FILE -> 21 0 }T +T{ PAD 29 + 21 buf 21 COMPARE -> 0 }T +T{ fid2 @ FILE-SIZE DROP fid2 @ FILE-POSITION DROP D= -> TRUE }T +T{ buf 10 fid2 @ READ-FILE -> 0 0 }T +T{ fid2 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING RESIZE-FILE + +T{ fn2 R/W BIN OPEN-FILE SWAP fid2 ! -> 0 }T +T{ 37. fid2 @ RESIZE-FILE -> 0 }T +T{ fid2 @ FILE-SIZE -> 37. 0 }T +T{ 0. fid2 @ REPOSITION-FILE -> 0 }T +T{ cbuf buf 100 fid2 @ READ-FILE -> 37 0 }T +T{ PAD 37 buf 37 COMPARE -> 0 }T +T{ PAD 38 buf 38 COMPARE -> 1 }T +T{ 500. fid2 @ RESIZE-FILE -> 0 }T +T{ fid2 @ FILE-SIZE -> 500. 0 }T +T{ 0. fid2 @ REPOSITION-FILE -> 0 }T +T{ cbuf buf 100 fid2 @ READ-FILE -> 100 0 }T +T{ PAD 37 buf 37 COMPARE -> 0 }T +T{ fid2 @ CLOSE-FILE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING DELETE-FILE + +T{ fn2 DELETE-FILE -> 0 }T +T{ fn2 R/W BIN OPEN-FILE SWAP DROP 0= -> FALSE }T +T{ fn2 DELETE-FILE 0= -> FALSE }T + +\ ------------------------------------------------------------------------------ +TESTING multi-line ( comments + +T{ ( 1 2 3 +4 5 6 +7 8 9 ) 11 22 33 -> 11 22 33 }T + +\ ------------------------------------------------------------------------------ +TESTING SOURCE-ID (can only test it does not return 0 or -1) + +T{ SOURCE-ID DUP -1 = SWAP 0= OR -> FALSE }T + +\ ------------------------------------------------------------------------------ +TESTING RENAME-FILE FILE-STATUS FLUSH-FILE + +: fn3 S" fatest3.txt" ; +: >end fid1 @ FILE-SIZE DROP fid1 @ REPOSITION-FILE ; + + +T{ fn3 DELETE-FILE DROP -> }T +T{ fn1 fn3 RENAME-FILE 0= -> TRUE }T +T{ fn1 FILE-STATUS SWAP DROP 0= -> FALSE }T +T{ fn3 FILE-STATUS SWAP DROP 0= -> TRUE }T \ Return value is undefined +T{ fn3 R/W OPEN-FILE SWAP fid1 ! -> 0 }T +T{ >end -> 0 }T +T{ S" Final line" fid1 @ WRITE-LINE -> 0 }T +T{ fid1 @ FLUSH-FILE -> 0 }T \ Can only test FLUSH-FILE doesn't fail +T{ fid1 @ CLOSE-FILE -> 0 }T + +\ Tidy the test folder +T{ fn3 DELETE-FILE DROP -> }T + +\ ------------------------------------------------------------------------------ + +CR .( End of File-Access word tests) CR diff --git a/amforth-6.5/common/lib/forth2012/tester/memorytest.fth b/amforth-6.5/common/lib/forth2012/tester/memorytest.fth new file mode 100644 index 0000000..1967fc3 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/memorytest.fth @@ -0,0 +1,93 @@ +\ To test the ANS Forth Memory-Allocation word set + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.7 1 April 2012 Tests placed in the public domain. +\ 0.6 30 January 2011 CHECKMEM modified to work with ttester.fs +\ 0.5 30 November 2009 replaced with FALSE +\ 0.4 9 March 2009 Aligned test improved and data space pointer tested +\ 0.3 6 March 2009 { and } replaced with T{ and }T +\ 0.2 20 April 2007 ANS Forth words changed to upper case +\ 0.1 October 2006 First version released + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ and requires those files to have been loaded + +\ Words tested in this file are: +\ ALLOCATE FREE RESIZE +\ +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - that 'addr -1 ALLOCATE' and 'addr -1 RESIZE' will return an error +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - testing FREE failing is not done as it is likely to crash the +\ system +\ ------------------------------------------------------------------------------ + +TESTING Memory-Allocation word set + +DECIMAL + +\ ------------------------------------------------------------------------------ +TESTING ALLOCATE FREE RESIZE + +VARIABLE addr1 +VARIABLE datsp + +HERE datsp ! +T{ 100 ALLOCATE SWAP addr1 ! -> 0 }T +T{ addr1 @ ALIGNED -> addr1 @ }T \ Test address is aligned +T{ HERE -> datsp @ }T \ Check data space pointer is unchanged +T{ addr1 @ FREE -> 0 }T + +T{ 99 ALLOCATE SWAP addr1 ! -> 0 }T +T{ addr1 @ ALIGNED -> addr1 @ }T +T{ addr1 @ FREE -> 0 }T + +T{ 50 ALLOCATE SWAP addr1 ! -> 0 }T + +: writemem 0 DO I 1+ OVER C! 1+ LOOP DROP ; ( ad n -- ) + +\ checkmem is defined this way to maintain compatibility with both +\ tester.fr and ttester.fs which differ in their definitions of T{ + +: checkmem ( ad n --- ) + 0 + DO + >R + T{ R@ C@ -> R> I 1+ SWAP >R }T + R> 1+ + LOOP + DROP +; + +addr1 @ 50 writemem addr1 @ 50 checkmem + +T{ addr1 @ 28 RESIZE SWAP addr1 ! -> 0 }T +addr1 @ 28 checkmem + +T{ addr1 @ 200 RESIZE SWAP addr1 ! -> 0 }T +addr1 @ 28 checkmem + +\ ------------------------------------------------------------------------------ +TESTING failure of RESIZE and ALLOCATE (unlikely to be enough memory) + +T{ addr1 @ -1 RESIZE 0= -> addr1 @ FALSE }T + +T{ addr1 @ FREE -> 0 }T + +T{ -1 ALLOCATE SWAP DROP 0= -> FALSE }T \ Memory allocate failed + +\ ------------------------------------------------------------------------------ + +CR .( End of Memory-Allocation word tests) CR diff --git a/amforth-6.5/common/lib/forth2012/tester/postponetest.fs b/amforth-6.5/common/lib/forth2012/tester/postponetest.fs new file mode 100644 index 0000000..b178be6 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/postponetest.fs @@ -0,0 +1,379 @@ +\ checks that postpone works correctly with words with special +\ compilation semantics + +\ by M. Anton Ertl 1996 + +\ This file is based on John Hayes' core.fr (coretest.fs), which has +\ the following copyright notice: + +\ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY +\ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS. + +\ my contributions to this file are in the public domain + +\ you have to load John Hayes' tester.fs (=tester.fr) and coretest.fs +\ (core.fr) first + +\ These tests are especially useful for showing that state-smart +\ implementations of words with special compilation semantics, +\ combined with a straight-forward implementation of POSTPONE (and +\ [COMPILE]) do not conform to the ANS Forth standard. The essential +\ sentences in the standad are: + +\ 6.1.2033 POSTPONE CORE +\ ... +\ Compilation: ( name -- ) + +\ Skip leading space delimiters. Parse name delimited by a space. Find +\ name. Append the compilation semantics of name to the current +\ definition. + +\ 6.2.2530 [COMPILE] bracket-compile CORE EXT +\ ... +\ Compilation: ( name -- ) + +\ Skip leading space delimiters. Parse name delimited by a space. Find +\ name. If name has other than default compilation semantics, append +\ them to the current definition;... + + +\ Note that the compilation semantics are appended, not some +\ state-dependent semantics. + +\ first I test against a non-ANS solution suggested by Bernd Paysan + +: STATE@-NOW ( -- F ) + STATE @ ; IMMEDIATE + +: STATE@ ( -- F ) + POSTPONE STATE@-NOW ; + +t{ STATE@ -> STATE @ }t + +0 INVERT CONSTANT MAX-UINT +0 INVERT 1 RSHIFT CONSTANT MAX-INT +0 INVERT 1 RSHIFT INVERT CONSTANT MIN-INT +0 INVERT 1 RSHIFT CONSTANT MID-UINT +0 INVERT 1 RSHIFT INVERT CONSTANT MID-UINT+1 + +\ here I test POSTPONE with all core words with special compilation +\ semantics. + +TESTING POSTPONE +LOOP + +: POSTPONE-+LOOP + POSTPONE +LOOP ; + +t{ : PGD2 DO I -1 [ POSTPONE-+LOOP ] ; -> }t +t{ 1 4 PGD2 -> 4 3 2 1 }t +t{ -1 2 PGD2 -> 2 1 0 -1 }t +t{ MID-UINT MID-UINT+1 PGD2 -> MID-UINT+1 MID-UINT }t + +t{ : PGD4 DO 1 0 DO J LOOP -1 [ POSTPONE-+LOOP ] ; -> }t +t{ 1 4 PGD4 -> 4 3 2 1 }t +t{ -1 2 PGD4 -> 2 1 0 -1 }t +t{ MID-UINT MID-UINT+1 PGD4 -> MID-UINT+1 MID-UINT }t + +TESTING POSTPONE ." + +: POSTPONE-." + POSTPONE ." ; + +: PDQ2 [ POSTPONE-." YOU SHOULD SEE THIS LATER. " ] CR ; +: PDQ1 [ POSTPONE-." YOU SHOULD SEE THIS FIRST. " ] CR ; +t{ PDQ1 PDQ2 -> }t + +TESTING POSTPONE ; +: POSTPONE-; + POSTPONE ; ; + +t{ : PSC [ POSTPONE-; -> }t +t{ PSC -> }t + +TESTING POSTPONE ABORT" + +: POSTPONE-ABORT" + POSTPONE ABORT" ; + +t{ : PAQ1 [ POSTPONE-ABORT" THIS SHOULD NOT ABORT" ] ; -> }t + +TESTING POSTPONE BEGIN +: POSTPONE-BEGIN + POSTPONE BEGIN ; + +t{ : PB3 [ POSTPONE-BEGIN ] DUP 5 < WHILE DUP 1+ REPEAT ; -> }t +t{ 0 PB3 -> 0 1 2 3 4 5 }t +t{ 4 PB3 -> 4 5 }t +t{ 5 PB3 -> 5 }t +t{ 6 PB3 -> 6 }t + +t{ : PB4 [ POSTPONE-BEGIN ] DUP 1+ DUP 5 > UNTIL ; -> }t +t{ 3 PB4 -> 3 4 5 6 }t +t{ 5 PB4 -> 5 6 }t +t{ 6 PB4 -> 6 7 }t + +t{ : PB5 [ POSTPONE-BEGIN ] DUP 2 > WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 THEN ; -> }t +t{ 1 PB5 -> 1 345 }t +t{ 2 PB5 -> 2 345 }t +t{ 3 PB5 -> 3 4 5 123 }t +t{ 4 PB5 -> 4 5 123 }t +t{ 5 PB5 -> 5 123 }t + +TESTING POSTPONE DO +: POSTPONE-DO + POSTPONE DO ; + +t{ : PDO1 [ POSTPONE-DO ] I LOOP ; -> }t +t{ 4 1 PDO1 -> 1 2 3 }t +t{ 2 -1 PDO1 -> -1 0 1 }t +t{ MID-UINT+1 MID-UINT PDO1 -> MID-UINT }t + +t{ : PDO2 [ POSTPONE-DO ] I -1 +LOOP ; -> }t +t{ 1 4 PDO2 -> 4 3 2 1 }t +t{ -1 2 PDO2 -> 2 1 0 -1 }t +t{ MID-UINT MID-UINT+1 PDO2 -> MID-UINT+1 MID-UINT }t + +t{ : PDO3 [ POSTPONE-DO ] 1 0 [ POSTPONE-DO ] J LOOP LOOP ; -> }t +t{ 4 1 PDO3 -> 1 2 3 }t +t{ 2 -1 PDO3 -> -1 0 1 }t +t{ MID-UINT+1 MID-UINT PDO3 -> MID-UINT }t + +t{ : PDO4 [ POSTPONE-DO ] 1 0 [ POSTPONE-DO ] J LOOP -1 +LOOP ; -> }t +t{ 1 4 PDO4 -> 4 3 2 1 }t +t{ -1 2 PDO4 -> 2 1 0 -1 }t +t{ MID-UINT MID-UINT+1 PDO4 -> MID-UINT+1 MID-UINT }t + +t{ : PDO5 123 SWAP 0 [ POSTPONE-DO ] I 4 > IF DROP 234 LEAVE THEN LOOP ; -> }t +t{ 1 PDO5 -> 123 }t +t{ 5 PDO5 -> 123 }t +t{ 6 PDO5 -> 234 }t + +t{ : PDO6 ( PAT: {0 0},{0 0}{1 0}{1 1},{0 0}{1 0}{1 1}{2 0}{2 1}{2 2} ) + 0 SWAP 0 [ POSTPONE-DO ] + I 1+ 0 [ POSTPONE-DO ] I J + 3 = IF I UNLOOP I UNLOOP EXIT THEN 1+ LOOP + LOOP ; -> }t +t{ 1 PDO6 -> 1 }t +t{ 2 PDO6 -> 3 }t +t{ 3 PDO6 -> 4 1 2 }t + +TESTING POSTPONE DOES> +: POSTPONE-DOES> + POSTPONE DOES> ; + +t{ : PDOES1 [ POSTPONE-DOES> ] @ 1 + ; -> }t +t{ : PDOES2 [ POSTPONE-DOES> ] @ 2 + ; -> }t +t{ CREATE PCR1 -> }t +t{ PCR1 -> HERE }t +t{ ' PCR1 >BODY -> HERE }t +t{ 1 , -> }t +t{ PCR1 @ -> 1 }t +t{ PDOES1 -> }t +t{ PCR1 -> 2 }t +t{ PDOES2 -> }t +t{ PCR1 -> 3 }t + +t{ : PWEIRD: CREATE [ POSTPONE-DOES> ] 1 + [ POSTPONE-DOES> ] 2 + ; -> }t +t{ PWEIRD: PW1 -> }t +t{ ' PW1 >BODY -> HERE }t +t{ PW1 -> HERE 1 + }t +t{ PW1 -> HERE 2 + }t + +TESTING POSTPONE ELSE +: POSTPONE-ELSE + POSTPONE ELSE ; + +t{ : PELSE1 IF 123 [ POSTPONE-ELSE ] 234 THEN ; -> }t +t{ 0 PELSE1 -> 234 }t +t{ 1 PELSE1 -> 123 }t + +t{ : PELSE2 BEGIN DUP 2 > WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 [ POSTPONE-ELSE ] 345 THEN ; -> }t +t{ 1 PELSE2 -> 1 345 }t +t{ 2 PELSE2 -> 2 345 }t +t{ 3 PELSE2 -> 3 4 5 123 }t +t{ 4 PELSE2 -> 4 5 123 }t +t{ 5 PELSE2 -> 5 123 }t + +TESTING POSTPONE IF +: POSTPONE-IF + POSTPONE IF ; + +t{ : PIF1 [ POSTPONE-IF ] 123 THEN ; -> }t +t{ : PIF2 [ POSTPONE-IF ] 123 ELSE 234 THEN ; -> }t +t{ 0 PIF1 -> }t +t{ 1 PIF1 -> 123 }t +t{ -1 PIF1 -> 123 }t +t{ 0 PIF2 -> 234 }t +t{ 1 PIF2 -> 123 }t +t{ -1 PIF1 -> 123 }t + +t{ : PIF6 ( N -- 0,1,..N ) DUP [ POSTPONE-IF ] DUP >R 1- RECURSE R> THEN ; -> }t +t{ 0 PIF6 -> 0 }t +t{ 1 PIF6 -> 0 1 }t +t{ 2 PIF6 -> 0 1 2 }t +t{ 3 PIF6 -> 0 1 2 3 }t +t{ 4 PIF6 -> 0 1 2 3 4 }t + +TESTING POSTPONE LITERAL +: POSTPONE-LITERAL + POSTPONE LITERAL ; + +t{ : PLIT [ 42 POSTPONE-LITERAL ] ; -> }t +t{ PLIT -> 42 }t + +TESTING POSTPONE LOOP +: POSTPONE-LOOP + POSTPONE LOOP ; + +t{ : PLOOP1 DO I [ POSTPONE-LOOP ] ; -> }t +t{ 4 1 PLOOP1 -> 1 2 3 }t +t{ 2 -1 PLOOP1 -> -1 0 1 }t +t{ MID-UINT+1 MID-UINT PLOOP1 -> MID-UINT }t + +t{ : PLOOP3 DO 1 0 DO J [ POSTPONE-LOOP ] [ POSTPONE-LOOP ] ; -> }t +t{ 4 1 PLOOP3 -> 1 2 3 }t +t{ 2 -1 PLOOP3 -> -1 0 1 }t +t{ MID-UINT+1 MID-UINT PLOOP3 -> MID-UINT }t + +t{ : PLOOP4 DO 1 0 DO J [ POSTPONE-LOOP ] -1 +LOOP ; -> }t +t{ 1 4 PLOOP4 -> 4 3 2 1 }t +t{ -1 2 PLOOP4 -> 2 1 0 -1 }t +t{ MID-UINT MID-UINT+1 PLOOP4 -> MID-UINT+1 MID-UINT }t + +t{ : PLOOP5 123 SWAP 0 DO I 4 > IF DROP 234 LEAVE THEN [ POSTPONE-LOOP ] ; -> }t +t{ 1 PLOOP5 -> 123 }t +t{ 5 PLOOP5 -> 123 }t +t{ 6 PLOOP5 -> 234 }t + +t{ : PLOOP6 ( PAT: {0 0},{0 0}{1 0}{1 1},{0 0}{1 0}{1 1}{2 0}{2 1}{2 2} ) + 0 SWAP 0 DO + I 1+ 0 DO I J + 3 = IF I UNLOOP I UNLOOP EXIT THEN 1+ [ POSTPONE-LOOP ] + [ POSTPONE-LOOP ] ; -> }t +t{ 1 PLOOP6 -> 1 }t +t{ 2 PLOOP6 -> 3 }t +t{ 3 PLOOP6 -> 4 1 2 }t + +TESTING POSTPONE POSTPONE +: POSTPONE-POSTPONE + POSTPONE POSTPONE ; + +t{ : PPP1 123 ; -> }t +t{ : PPP4 [ POSTPONE-POSTPONE PPP1 ] ; IMMEDIATE -> }t +t{ : PPP5 PPP4 ; -> }t +t{ PPP5 -> 123 }t +t{ : PPP6 345 ; IMMEDIATE -> }t +t{ : PPP7 [ POSTPONE-POSTPONE PPP6 ] ; -> }t +t{ PPP7 -> 345 }t + +TESTING POSTPONE RECURSE +: POSTPONE-RECURSE + POSTPONE RECURSE ; + +t{ : GREC ( N -- 0,1,..N ) DUP IF DUP >R 1- [ POSTPONE-RECURSE ] R> THEN ; -> }t +t{ 0 GREC -> 0 }t +t{ 1 GREC -> 0 1 }t +t{ 2 GREC -> 0 1 2 }t +t{ 3 GREC -> 0 1 2 3 }t +t{ 4 GREC -> 0 1 2 3 4 }t + +TESTING POSTPONE REPEAT +: POSTPONE-REPEAT + POSTPONE REPEAT ; + +t{ : PREP3 BEGIN DUP 5 < WHILE DUP 1+ [ POSTPONE-REPEAT ] ; -> }t +t{ 0 PREP3 -> 0 1 2 3 4 5 }t +t{ 4 PREP3 -> 4 5 }t +t{ 5 PREP3 -> 5 }t +t{ 6 PREP3 -> 6 }t + +t{ : PREP5 BEGIN DUP 2 > WHILE DUP 5 < WHILE DUP 1+ [ POSTPONE-REPEAT ] 123 ELSE 345 THEN ; -> }t +t{ 1 PREP5 -> 1 345 }t +t{ 2 PREP5 -> 2 345 }t +t{ 3 PREP5 -> 3 4 5 123 }t +t{ 4 PREP5 -> 4 5 123 }t +t{ 5 PREP5 -> 5 123 }t + +TESTING POSTPONE S" +: POSTPONE-S" + POSTPONE S" ; + +t{ : PSQ4 [ POSTPONE-S" XY" ] ; -> }t +t{ PSQ4 SWAP DROP -> 2 }t +t{ PSQ4 DROP DUP C@ SWAP CHAR+ C@ -> 58 59 }t + +TESTING POSTPONE THEN +: POSTPONE-THEN + POSTPONE THEN ; + +t{ : PTH1 IF 123 [ POSTPONE-THEN ] ; -> }t +t{ : PTH2 IF 123 ELSE 234 [ POSTPONE-THEN ] ; -> }t +t{ 0 PTH1 -> }t +t{ 1 PTH1 -> 123 }t +t{ -1 PTH1 -> 123 }t +t{ 0 PTH2 -> 234 }t +t{ 1 PTH2 -> 123 }t +t{ -1 PTH1 -> 123 }t + +t{ : PTH5 BEGIN DUP 2 > WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 [ POSTPONE-THEN ] ; -> }t +t{ 1 PTH5 -> 1 345 }t +t{ 2 PTH5 -> 2 345 }t +t{ 3 PTH5 -> 3 4 5 123 }t +t{ 4 PTH5 -> 4 5 123 }t +t{ 5 PTH5 -> 5 123 }t + +t{ : PTH6 ( N -- 0,1,..N ) DUP IF DUP >R 1- RECURSE R> [ POSTPONE-THEN ] ; -> }t +t{ 0 PTH6 -> 0 }t +t{ 1 PTH6 -> 0 1 }t +t{ 2 PTH6 -> 0 1 2 }t +t{ 3 PTH6 -> 0 1 2 3 }t +t{ 4 PTH6 -> 0 1 2 3 4 }t + +TESTING POSTPONE UNTIL +: POSTPONE-UNTIL + POSTPONE UNTIL ; + +t{ : PUNT4 BEGIN DUP 1+ DUP 5 > [ POSTPONE-UNTIL ] ; -> }t +t{ 3 PUNT4 -> 3 4 5 6 }t +t{ 5 PUNT4 -> 5 6 }t +t{ 6 PUNT4 -> 6 7 }t + +TESTING POSTPONE WHILE +: POSTPONE-WHILE + POSTPONE WHILE ; + +t{ : PWH3 BEGIN DUP 5 < [ POSTPONE-WHILE ] DUP 1+ REPEAT ; -> }t +t{ 0 PWH3 -> 0 1 2 3 4 5 }t +t{ 4 PWH3 -> 4 5 }t +t{ 5 PWH3 -> 5 }t +t{ 6 PWH3 -> 6 }t + +t{ : PWH5 BEGIN DUP 2 > [ POSTPONE-WHILE ] DUP 5 < [ POSTPONE-WHILE ] DUP 1+ REPEAT 123 ELSE 345 THEN ; -> }t +t{ 1 PWH5 -> 1 345 }t +t{ 2 PWH5 -> 2 345 }t +t{ 3 PWH5 -> 3 4 5 123 }t +t{ 4 PWH5 -> 4 5 123 }t +t{ 5 PWH5 -> 5 123 }t + + +TESTING POSTPONE [ +: POSTPONE-[ + POSTPONE [ ; + +t{ HERE POSTPONE-[ -> HERE }t + +TESTING POSTPONE ['] +: POSTPONE-['] + POSTPONE ['] ; + +t{ : PTICK1 123 ; -> }t +t{ : PTICK2 [ POSTPONE-['] PTICK1 ] ; IMMEDIATE -> }t +t{ PTICK2 EXECUTE -> 123 }t + +TESTING POSTPONE [CHAR] +: POSTPONE-[CHAR] + POSTPONE [CHAR] ; + +t{ : PCHAR1 [ POSTPONE-[CHAR] X ] ; -> }t +t{ : PCHAR2 [ POSTPONE-[CHAR] HELLO ] ; -> }t +t{ PCHAR1 -> 58 }t +t{ PCHAR2 -> 48 }t + diff --git a/amforth-6.5/common/lib/forth2012/tester/searchordertest.fth b/amforth-6.5/common/lib/forth2012/tester/searchordertest.fth new file mode 100644 index 0000000..79f9de9 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/searchordertest.fth @@ -0,0 +1,178 @@ +\ To test the ANS Forth search-order word set and search order extensions + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.5 1 April 2012 Tests placed in the public domain. +\ 0.4 6 March 2009 { and } replaced with T{ and }T +\ 0.3 20 April 2007 ANS Forth words changed to upper case +\ 0.2 30 Oct 2006 updated following GForth tests to get +\ initial search order into a known state +\ 0.1 Oct 2006 First version released + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ and requires those files to have been loaded + +\ Words tested in this file are: +\ FORTH-WORDLIST GET-ORDER SET-ORDER ALSO ONLY FORTH GET-CURRENT +\ SET-CURRENT DEFINITIONS PREVIOUS SEARCH-WORDLIST WORDLIST FIND +\ Words not fully tested: +\ ORDER only tests that it executes, display is implementation +\ dependent and should be visually inspected + +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - that ONLY FORTH DEFINITIONS will work at the start of the file +\ to ensure the search order is in a known state +\ ------------------------------------------------------------------------------ + +ONLY FORTH DEFINITIONS + +TESTING Search-order word set + +DECIMAL + +VARIABLE wid1 VARIABLE wid2 + +: save-orderlist ( widn ... wid1 n -> ) DUP , 0 ?DO , LOOP ; + +\ ------------------------------------------------------------------------------ +TESTING FORTH-WORDLIST GET-ORDER SET-ORDER + +T{ FORTH-WORDLIST wid1 ! -> }T + +CREATE order-list + +T{ GET-ORDER save-orderlist -> }T + +: get-orderlist ( -- widn ... wid1 n ) + order-list DUP @ CELLS ( -- ad n ) + OVER + ( -- ad ad' ) + ?DO I @ -1 CELLS +LOOP ( -- ) +; + +T{ GET-ORDER OVER -> GET-ORDER wid1 @ }T \ Forth wordlist at top +T{ GET-ORDER SET-ORDER -> }T \ Effectively noop +T{ GET-ORDER -> get-orderlist }T \ Check nothing changed +T{ get-orderlist DROP get-orderlist 2* SET-ORDER -> }T +T{ GET-ORDER -> get-orderlist DROP get-orderlist 2* }T +T{ get-orderlist SET-ORDER GET-ORDER -> get-orderlist }T + +\ ------------------------------------------------------------------------------ +TESTING ALSO ONLY FORTH + +T{ ALSO GET-ORDER -> get-orderlist OVER SWAP 1+ }T +T{ ONLY FORTH GET-ORDER -> get-orderlist }T \ See assumptions above + +\ ------------------------------------------------------------------------------ +TESTING GET-CURRENT SET-CURRENT WORDLIST (simple) + +T{ GET-CURRENT -> wid1 @ }T \ See assumptions above +T{ WORDLIST wid2 ! -> }T +T{ wid2 @ SET-CURRENT -> }T +T{ GET-CURRENT -> wid2 @ }T +T{ wid1 @ SET-CURRENT -> }T + +\ ------------------------------------------------------------------------------ +TESTING minimum search order list contains FORTH-WORDLIST and SET-ORDER + +: so1 SET-ORDER ; \ In case it is unavailable in the forth wordlist + +T{ ONLY FORTH-WORDLIST 1 SET-ORDER get-orderlist so1 -> }T +T{ GET-ORDER -> get-orderlist }T + +\ ------------------------------------------------------------------------------ +TESTING GET-ORDER SET-ORDER with 0 and -1 number of wids argument + +: so2a GET-ORDER get-orderlist SET-ORDER ; \ To recover search order +: so2 0 SET-ORDER so2a ; + +T{ so2 -> 0 }T \ 0 set-order leaves an empty search order + +: so3 -1 SET-ORDER so2a ; +: so4 ONLY so2a ; + +T{ so3 -> so4 }T \ -1 SET-ORDER = ONLY + +\ ------------------------------------------------------------------------------ +TESTING DEFINITIONS PREVIOUS + +T{ ONLY FORTH DEFINITIONS -> }T +T{ GET-CURRENT -> FORTH-WORDLIST }T +T{ GET-ORDER wid2 @ SWAP 1+ SET-ORDER DEFINITIONS GET-CURRENT -> wid2 @ }T +T{ GET-ORDER -> get-orderlist wid2 @ SWAP 1+ }T +T{ PREVIOUS GET-ORDER -> get-orderlist }T +T{ DEFINITIONS GET-CURRENT -> FORTH-WORDLIST }T + +\ ------------------------------------------------------------------------------ +TESTING SEARCH-WORDLIST WORDLIST FIND + +ONLY FORTH DEFINITIONS +VARIABLE xt ' DUP xt ! +VARIABLE xti ' .( xti ! \ Immediate word + +T{ S" DUP" wid1 @ SEARCH-WORDLIST -> xt @ -1 }T +T{ S" .(" wid1 @ SEARCH-WORDLIST -> xti @ 1 }T +T{ S" DUP" wid2 @ SEARCH-WORDLIST -> 0 }T + +: c"dup" C" DUP" ; +: c".(" C" .(" ; +: c"x" C" unknown word" ; + +T{ c"dup" FIND -> xt @ -1 }T +T{ c".(" FIND -> xti @ 1 }T +T{ c"x" FIND -> c"x" 0 }T + +\ ------------------------------------------------------------------------------ +TESTING new definitions are put into the correct wordlist + +: alsowid2 ALSO GET-ORDER wid2 @ ROT DROP SWAP SET-ORDER ; +alsowid2 +: w1 1234 ; +DEFINITIONS +: w1 -9876 ; IMMEDIATE + +ONLY FORTH +T{ w1 -> 1234 }T +DEFINITIONS +T{ w1 -> 1234 }T +alsowid2 +T{ w1 -> -9876 }T +DEFINITIONS +T{ w1 -> -9876 }T + +ONLY FORTH DEFINITIONS + +: so5 DUP IF SWAP EXECUTE THEN ; + +T{ S" w1" wid1 @ SEARCH-WORDLIST so5 -> -1 1234 }T +T{ S" w1" wid2 @ SEARCH-WORDLIST so5 -> 1 -9876 }T + +: c"w1" C" w1" ; +T{ alsowid2 c"w1" FIND so5 -> 1 -9876 }T +T{ PREVIOUS c"w1" FIND so5 -> -1 1234 }T + +\ ------------------------------------------------------------------------------ +TESTING ORDER \ Should display search order and compilation wordlist + +CR .( ONLY FORTH DEFINITIONS search order and compilation list) CR +T{ ONLY FORTH DEFINITIONS ORDER -> }T + +CR .( Plus another unnamed wordlist at the head of the search order) CR +T{ alsowid2 DEFINITIONS ORDER -> }T + +\ ------------------------------------------------------------------------------ + +CR .( End of Search Order word tests) CR + +ONLY FORTH DEFINITIONS \ Leave search order in the standard state diff --git a/amforth-6.5/common/lib/forth2012/tester/searchordertest.txt b/amforth-6.5/common/lib/forth2012/tester/searchordertest.txt new file mode 100644 index 0000000..9018a5d --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/searchordertest.txt @@ -0,0 +1,184 @@ +\ To test the ANS Forth search-order word set and search order extensions + +\ Copyright (C) Gerry Jackson 2006 + +\ This program is free software; you can redistribute it and/or +\ modify it any way. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ -------------------------------------------------------------------- +\ Version 0.1 Oct 2006 First version released + +\ -------------------------------------------------------------------- +\ The tests are based on John Hayes test program for the core word set +\ and requires those files to have been loaded + +\ Words tested in this file are: +\ forth-wordlist get-order set-order also only forth get-current +\ set-current definitions previous search-wordlist wordlist find +\ Words not fully tested: +\ order only tests that it executes, display is implementation +\ dependent + +\ -------------------------------------------------------------------- +\ Assumptions and dependencies: +\ - running on a case insensitive system. Strictly speaking ANS +\ Forth words should be in upper case only, this file is mostly +\ lower case +\ - the forth wordlist is at the head of the search order and is +\ also the compilation wordlist +\ - tester.fr has been loaded prior to this file +\ -------------------------------------------------------------------- + +Testing Search-order word set + +decimal + +variable wid1 variable wid2 + +: save-orderlist ( widn ... wid1 n -> ) dup , 0 ?do , loop ; + +\ -------------------------------------------------------------------- + +Testing forth-wordlist get-order set-order + +{ forth-wordlist wid1 ! -> } + +create order-list + +{ get-order save-orderlist -> } + +: get-orderlist ( -- widn ... wid1 n ) + order-list dup @ cells ( -- ad n ) + over + ( -- ad ad' ) + ?do i @ -1 cells +loop ( -- ) +; + +{ get-order over -> get-order wid1 @ } \ Forth wordlist at top +{ get-order set-order -> } \ Effectively noop +{ get-order -> get-orderlist } \ Check nothing changed +{ get-orderlist drop get-orderList 2* set-order -> } +{ get-order -> get-orderlist drop get-orderList 2* } +{ get-orderlist set-order get-order -> get-orderlist } + +\ -------------------------------------------------------------------- + +Testing also only forth + +{ also get-order -> get-orderlist over swap 1+ } +{ only forth get-order -> get-orderlist } \ See assumptions above + +\ -------------------------------------------------------------------- + +Testing get-current set-current wordlist (simple) + +{ get-current -> wid1 @ } \ See assumptions above +{ wordlist wid2 ! -> } +{ wid2 @ set-current -> } +{ get-current -> wid2 @ } +{ wid1 @ set-current + +\ -------------------------------------------------------------------- + +Testing minimum search order list contains forth-wordlist and set-order + +: so1 set-order ; \ In case it is unavailable in the forth wordlist + +{ only forth-wordlist 1 set-order get-orderlist so1 -> } +{ get-order -> get-orderlist } + +\ -------------------------------------------------------------------- + +Testing get-order set-order with 0 and -1 number of wids argument + +: so2a get-order get-orderlist set-order ; \ To recover search order +: so2 0 set-order so2a ; + +{ so2 -> 0 } \ 0 set-order leaves an empty search order + +: so3 -1 set-order so2a ; +: so4 only so2a ; + +{ so3 -> so4 } \ -1 set-order = only + +\ -------------------------------------------------------------------- + +Testing definitions previous + +{ only forth definitions -> } +{ get-current -> forth-wordlist } +{ get-order wid2 @ swap 1+ set-order definitions get-current -> wid2 @ } +{ get-order -> get-orderlist wid2 @ swap 1+ } +{ previous get-order -> get-orderlist } +{ definitions get-current -> forth-wordlist } + +\ -------------------------------------------------------------------- + +Testing search-wordlist wordlist find + +only forth definitions +variable xt ' dup xt ! +variable xti ' .( xti ! \ Immediate word + +{ s" dup" wid1 @ search-wordlist -> xt @ -1 } +{ s" .(" wid1 @ search-wordlist -> xti @ 1 } +{ s" dup" wid2 @ search-wordlist -> 0 } + +: c"dup" c" dup" ; +: c".(" c" .(" ; +: c"x" c" unknown word" ; + +{ c"dup" find -> xt @ -1 } +{ c".(" find -> xti @ 1 } +{ c"x" find -> c"x" 0 } + +\ -------------------------------------------------------------------- + +Testing new definitions are put into the correct wordlist + +: alsowid2 also get-order wid2 @ rot drop swap set-order ; +alsowid2 +: w1 1234 ; +definitions +: w1 -9876 ; immediate + +only forth +{ w1 -> 1234 } +definitions +{ w1 -> 1234 } +alsowid2 +{ w1 -> -9876 } +definitions +{ w1 -> -9876 } + +only forth definitions + +: so5 dup if swap execute then ; + +{ s" w1" wid1 @ search-wordlist so5 -> -1 1234 } +{ s" w1" wid2 @ search-wordlist so5 -> 1 -9876 } + +: c"w1" c" w1" ; +{ alsowid2 c"w1" find so5 -> 1 -9876 } +{ previous c"w1" find so5 -> -1 1234 } + +\ -------------------------------------------------------------------- + +Testing order \ Should display search order and compilation wordlist + +cr .( ONLY FORTH DEFINITIONS search order and compilation list) cr +{ only forth definitions order -> } + +cr .( Plus another unnamed wordlist at the head of the search order) cr +{ alsowid2 definitions order -> } + +\ -------------------------------------------------------------------- + +cr .( Tests on Search Order words completed successfully) cr + +only forth definitions \ Leave search order in the standard state diff --git a/amforth-6.5/common/lib/forth2012/tester/stringtest.fth b/amforth-6.5/common/lib/forth2012/tester/stringtest.fth new file mode 100644 index 0000000..95e2bfe --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/stringtest.fth @@ -0,0 +1,161 @@ +\ To test the ANS Forth String word set + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.6 1 April 2012 Tests placed in the public domain. +\ 0.5 29 April 2010 Added tests for SEARCH and COMPARE with +\ all strings zero length (suggested by Krishna Myneni). +\ SLITERAL test amended in line with comp.lang.forth +\ discussion +\ 0.4 30 November 2009 and replaced with TRUE +\ and FALSE +\ 0.3 6 March 2009 { and } replaced with T{ and }T +\ 0.2 20 April 2007 ANS Forth words changed to upper case +\ 0.1 Oct 2006 First version released + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program for the core word set +\ and requires those files to have been loaded + +\ Words tested in this file are: +\ -TRAILING /STRING BLANK CMOVE CMOVE> COMPARE SEARCH SLITERAL +\ +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - tester.fr or ttester.fs has been loaded prior to this file +\ - COMPARE is case sensitive +\ ------------------------------------------------------------------------------ + +TESTING String word set + +DECIMAL + +T{ : s1 S" abcdefghijklmnopqrstuvwxyz" ; -> }T +T{ : s2 S" abc" ; -> }T +T{ : s3 S" jklmn" ; -> }T +T{ : s4 S" z" ; -> }T +T{ : s5 S" mnoq" ; -> }T +T{ : s6 S" 12345" ; -> }T +T{ : s7 S" " ; -> }T +T{ : s8 S" abc " ; -> }T +T{ : s9 S" " ; -> }T +T{ : s10 S" a " ; -> }T + +\ ------------------------------------------------------------------------------ +TESTING -TRAILING + +T{ s1 -TRAILING -> s1 }T +T{ s8 -TRAILING -> s8 2 - }T +T{ s7 -TRAILING -> s7 }T +T{ s9 -TRAILING -> s9 DROP 0 }T +T{ s10 -TRAILING -> s10 1- }T + +\ ------------------------------------------------------------------------------ +TESTING /STRING + +T{ s1 5 /STRING -> s1 SWAP 5 + SWAP 5 - }T +T{ s1 10 /STRING -4 /STRING -> s1 6 /STRING }T +T{ s1 0 /STRING -> s1 }T + +\ ------------------------------------------------------------------------------ +TESTING SEARCH + +T{ s1 s2 SEARCH -> s1 TRUE }T +T{ s1 s3 SEARCH -> s1 9 /STRING TRUE }T +T{ s1 s4 SEARCH -> s1 25 /STRING TRUE }T +T{ s1 s5 SEARCH -> s1 FALSE }T +T{ s1 s6 SEARCH -> s1 FALSE }T +T{ s1 s7 SEARCH -> s1 TRUE }T +T{ s7 PAD 0 SEARCH -> s7 TRUE }T + +\ ------------------------------------------------------------------------------ +TESTING COMPARE + +T{ s1 s1 COMPARE -> 0 }T +T{ s1 PAD SWAP CMOVE -> }T +T{ s1 PAD OVER COMPARE -> 0 }T +T{ s1 PAD 6 COMPARE -> 1 }T +T{ PAD 10 s1 COMPARE -> -1 }T +T{ s1 PAD 0 COMPARE -> 1 }T +T{ PAD 0 s1 COMPARE -> -1 }T +T{ s1 s6 COMPARE -> 1 }T +T{ s6 s1 COMPARE -> -1 }T +T{ s7 PAD 0 COMPARE -> 0 }T + +: "abdde" S" abdde" ; +: "abbde" S" abbde" ; +: "abcdf" S" abcdf" ; +: "abcdee" S" abcdee" ; + +T{ s1 "abdde" COMPARE -> -1 }T +T{ s1 "abbde" COMPARE -> 1 }T +T{ s1 "abcdf" COMPARE -> -1 }T +T{ s1 "abcdee" COMPARE -> 1 }T + +: s11 S" 0abc" ; +: s12 S" 0aBc" ; + +T{ s11 s12 COMPARE -> 1 }T +T{ s12 s11 COMPARE -> -1 }T + +\ ------------------------------------------------------------------------------ +TESTING CMOVE and CMOVE> + +PAD 30 CHARS 0 FILL +T{ s1 PAD SWAP CMOVE -> }T +T{ s1 PAD s1 SWAP DROP COMPARE -> 0 }T +T{ s6 PAD 10 CHARS + SWAP CMOVE -> }T +T{ S" abcdefghij12345pqrstuvwxyz" PAD s1 SWAP DROP COMPARE -> 0 }T +T{ PAD 15 CHARS + PAD CHAR+ 6 CMOVE -> }T +T{ S" apqrstuhij12345pqrstuvwxyz" PAD 26 COMPARE -> 0 }T +T{ PAD PAD 3 CHARS + 7 CMOVE -> }T +T{ S" apqapqapqa12345pqrstuvwxyz" PAD 26 COMPARE -> 0 }T +T{ PAD PAD CHAR+ 10 CMOVE -> }T +T{ S" aaaaaaaaaaa2345pqrstuvwxyz" PAD 26 COMPARE -> 0 }T +T{ s7 PAD 14 CHARS + SWAP CMOVE -> }T +T{ S" aaaaaaaaaaa2345pqrstuvwxyz" PAD 26 COMPARE -> 0 }T + +PAD 30 CHARS 0 FILL + +T{ s1 PAD SWAP CMOVE> -> }T +T{ s1 PAD s1 SWAP DROP COMPARE -> 0 }T +T{ s6 PAD 10 CHARS + SWAP CMOVE> -> }T +T{ S" abcdefghij12345pqrstuvwxyz" PAD s1 SWAP DROP COMPARE -> 0 }T +T{ PAD 15 CHARS + PAD CHAR+ 6 CMOVE> -> }T +T{ S" apqrstuhij12345pqrstuvwxyz" PAD 26 COMPARE -> 0 }T +T{ PAD 13 CHARS + PAD 10 CHARS + 7 CMOVE> -> }T +T{ S" apqrstuhijtrstrstrstuvwxyz" PAD 26 COMPARE -> 0 }T +T{ PAD 12 CHARS + PAD 11 CHARS + 10 CMOVE> -> }T +T{ S" apqrstuhijtvvvvvvvvvvvwxyz" PAD 26 COMPARE -> 0 }T +T{ s7 PAD 14 CHARS + SWAP CMOVE> -> }T +T{ S" apqrstuhijtvvvvvvvvvvvwxyz" PAD 26 COMPARE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING BLANK + +: s13 S" aaaaa a" ; \ Don't move this down or might corrupt PAD + +T{ PAD 25 CHAR a FILL -> }T +T{ PAD 5 CHARS + 6 BLANK -> }T +T{ PAD 12 s13 COMPARE -> 0 }T + +\ ------------------------------------------------------------------------------ +TESTING SLITERAL + +T{ HERE DUP s1 DUP ALLOT ROT SWAP CMOVE s1 SWAP DROP 2CONSTANT s1a -> }T +T{ : s14 [ s1a ] SLITERAL ; -> }T +T{ s1a s14 COMPARE -> 0 }T +T{ s1a DROP s14 DROP = -> FALSE }T + +\ ------------------------------------------------------------------------------ + +CR .( End of String word tests) CR diff --git a/amforth-6.5/common/lib/forth2012/tester/tester-amforth.frt b/amforth-6.5/common/lib/forth2012/tester/tester-amforth.frt new file mode 100644 index 0000000..01d3ca5 --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/tester-amforth.frt @@ -0,0 +1,66 @@ +\ From: John Hayes S1I +\ Subject: tester.fr +\ Date: Mon, 27 Nov 95 13:10:09 PST + +\ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY +\ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS. +\ VERSION 1.1 + +\ modified for amforth by Matthias Trute 2007 + +\ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY +\ ALLOW YOU TO TELL WHICH TEST CAUSED YOUR SYSTEM TO HANG. +variable VERBOSE + 0 VERBOSE ! + +variable ACTUAL-DEPTH \ STACK RECORD +variable START-DEPTH + +: EMPTY-STACK \ ( ... -- ) EMPTY STACK: HANDLES UNDERFLOWED STACK TOO. + depth START-DEPTH @ < if + depth START-DEPTH @ swap do 0 loop + then + depth START-DEPTH @ > if + depth START-DEPTH @ do drop loop + then +; + +: ERROR \ ( C-ADDR U -- ) DISPLAY AN ERROR MESSAGE FOLLOWED BY + \ THE LINE THAT HAD THE ERROR. + itype source type cr \ DISPLAY LINE CORRESPONDING TO ERROR + EMPTY-STACK \ THROW AWAY EVERY THING ELSE +; + +variable ACTUAL-DEPTH \ STACK RECORD +variable ACTUAL-RESULTS 20 cells allot \ reserve space in RAM + +: t{ \ ( -- ) SYNTACTIC SUGAR. + depth START-DEPTH ! +; + +: -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK. + depth dup ACTUAL-DEPTH ! \ RECORD DEPTH + START-DEPTH @ > if \ IF THERE IS SOMETHING ON STACK + depth START-DEPTH @ - 0 do ACTUAL-RESULTS i cells + ! loop \ SAVE THEM + then +; + +: }t \ ( ... -- ) COMPARE STACK (EXPECTED) CONTENTS WITH SAVED + depth ACTUAL-DEPTH @ = if \ IF DEPTHS MATCH + depth START-DEPTH @ > if \ IF THERE IS SOMETHING ON THE STACK + depth START-DEPTH @ - 0 do \ FOR EACH STACK ITEM + ACTUAL-RESULTS i cells + @ \ COMPARE ACTUAL WITH EXPECTED + <> if s" INCORRECT RESULT: " ERROR leave then + loop + then + else \ DEPTH MISMATCH + s" WRONG NUMBER OF RESULTS: " ERROR + then +; + +: TESTING \ ( -- ) TALKING COMMENT. + source VERBOSE @ + if dup >r type cr r> >in ! + else >in ! drop + then ; + diff --git a/amforth-6.5/common/lib/forth2012/tester/toolstest.fth b/amforth-6.5/common/lib/forth2012/tester/toolstest.fth new file mode 100644 index 0000000..a35450b --- /dev/null +++ b/amforth-6.5/common/lib/forth2012/tester/toolstest.fth @@ -0,0 +1,172 @@ +\ To test some of the ANS Forth Programming Tools and extension wordset + +\ This program was written by Gerry Jackson in 2006, with contributions from +\ others where indicated, and is in the public domain - it can be distributed +\ and/or modified in any way but please retain this notice. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +\ The tests are not claimed to be comprehensive or correct + +\ ------------------------------------------------------------------------------ +\ Version 0.6 1 April 2012 Tests placed in the public domain. +\ Further tests on [IF] [ELSE] [THEN] +\ 0.5 30 November 2009 and replaced with TRUE and FALSE +\ 0.4 6 March 2009 ENDIF changed to THEN. {...} changed to T{...}T +\ 0.3 20 April 2007 ANS Forth words changed to upper case +\ 0.2 30 Oct 2006 updated following GForth test to avoid +\ changing stack depth during a colon definition +\ 0.1 Oct 2006 First version released + +\ ------------------------------------------------------------------------------ +\ The tests are based on John Hayes test program + +\ Words tested in this file are: +\ AHEAD [IF] [ELSE] [THEN] CS-PICK CS-ROLL +\ + +\ Words not tested: +\ .S ? DUMP SEE WORDS +\ ;CODE ASSEMBLER BYE CODE EDITOR FORGET STATE +\ ------------------------------------------------------------------------------ +\ Assumptions and dependencies: +\ - tester.fr or ttester.fs has been loaded prior to this file +\ ------------------------------------------------------------------------------ + +DECIMAL + +\ ------------------------------------------------------------------------------ +TESTING AHEAD + +T{ : pt1 AHEAD 1111 2222 THEN 3333 ; -> }T +T{ pt1 -> 3333 }T + +\ ------------------------------------------------------------------------------ +TESTING [IF] [ELSE] [THEN] + +T{ TRUE [IF] 111 [ELSE] 222 [THEN] -> 111 }T +T{ FALSE [IF] 111 [ELSE] 222 [THEN] -> 222 }T + +T{ TRUE [IF] 1 \ Code spread over more than 1 line + 2 + [ELSE] + 3 + 4 + [THEN] -> 1 2 }T +T{ FALSE [IF] + 1 2 + [ELSE] + 3 4 + [THEN] -> 3 4 }T + +T{ TRUE [IF] 1 TRUE [IF] 2 [ELSE] 3 [THEN] [ELSE] 4 [THEN] -> 1 2 }T +T{ FALSE [IF] 1 TRUE [IF] 2 [ELSE] 3 [THEN] [ELSE] 4 [THEN] -> 4 }T +T{ TRUE [IF] 1 FALSE [IF] 2 [ELSE] 3 [THEN] [ELSE] 4 [THEN] -> 1 3 }T +T{ FALSE [IF] 1 FALSE [IF] 2 [ELSE] 3 [THEN] [ELSE] 4 [THEN] -> 4 }T + +\ ------------------------------------------------------------------------------ +TESTING immediacy of [IF] [ELSE] [THEN] + +T{ : pt2 [ 0 ] [IF] 1111 [ELSE] 2222 [THEN] ; pt2 -> 2222 }T +T{ : pt3 [ -1 ] [IF] 3333 [ELSE] 4444 [THEN] ; pt3 -> 3333 }T +: pt9 bl WORD FIND ; +T{ pt9 [IF] NIP -> 1 }T +T{ pt9 [ELSE] NIP -> 1 }T +T{ pt9 [THEN] NIP -> 1 }T + +\ ----------------------------------------------------------------------------- +TESTING [IF] and [ELSE] carry out a text scan by parsing and discarding words +\ so that an [ELSE] or [THEN] in a comment or string is recognised + +: pt10 REFILL DROP REFILL DROP ; + +T{ 0 [IF] \ Words ignored up to [ELSE] 2 + [THEN] -> 2 }T +T{ -1 [IF] 2 [ELSE] 3 s" [THEN] 4 pt10 ignored to end of line" + [THEN] \ Precaution in case [THEN] in string isn't recognised + -> 2 4 }T + +\ ------------------------------------------------------------------------------ +TESTING CS-PICK and CS-ROLL + +\ Test pt5 based on example in ANS document p 176. + +: ?repeat + 0 CS-PICK POSTPONE UNTIL +; IMMEDIATE + +VARIABLE pt4 + +T{ : pt5 ( n1 -- ) + pt4 ! + BEGIN + -1 pt4 +! + pt4 @ 4 > 0= ?repeat \ Back to BEGIN if false + 111 + pt4 @ 3 > 0= ?repeat + 222 + pt4 @ 2 > 0= ?repeat + 333 + pt4 @ 1 = + UNTIL +; -> }T + +T{ 6 pt5 -> 111 111 222 111 222 333 111 222 333 }T + + +T{ : ?DONE POSTPONE IF 1 CS-ROLL ; IMMEDIATE -> }T \ Same as WHILE +T{ : pt6 + >R + BEGIN + R@ + ?DONE + R@ + R> 1- >R + REPEAT + R> DROP + ; -> }T + +T{ 5 pt6 -> 5 4 3 2 1 }T + +: mix_up 2 CS-ROLL ; IMMEDIATE \ cs-rot + +: pt7 ( f3 f2 f1 -- ? ) + IF 1111 ROT ROT ( -- 1111 f3 f2 ) ( cs: -- orig1 ) + IF 2222 SWAP ( -- 1111 2222 f3 ) ( cs: -- orig1 orig2 ) + IF ( cs: -- orig1 orig2 orig3 ) + 3333 mix_up ( -- 1111 2222 3333 ) ( cs: -- orig2 orig3 orig1 ) + THEN ( cs: -- orig2 orig3 ) + 4444 \ Hence failure of first IF comes here and falls through + THEN ( cs: -- orig2 ) + 5555 \ Failure of 3rd IF comes here + THEN ( cs: -- ) + 6666 \ Failure of 2nd IF comes here +; + +T{ -1 -1 -1 pt7 -> 1111 2222 3333 4444 5555 6666 }T +T{ 0 -1 -1 pt7 -> 1111 2222 5555 6666 }T +T{ 0 0 -1 pt7 -> 1111 0 6666 }T +T{ 0 0 0 pt7 -> 0 0 4444 5555 6666 }T + +: [1cs-roll] 1 CS-ROLL ; IMMEDIATE + +T{ : pt8 + >R + AHEAD 111 + BEGIN 222 + [1cs-roll] + THEN + 333 + R> 1- >R + R@ 0< + UNTIL + R> DROP + ; -> }T + +T{ 1 pt8 -> 333 222 333 }T + +\ ------------------------------------------------------------------------------ + +CR .( End of Programming Tools word tests) CR -- cgit v1.2.3