Well, it’s the end of the 2024 RetroChallenge and here is the summary of my work.
Sadly, I didn’t have the time to complete the goals, but I do have some lessons learned.
Forth2012 Test Suite
The Forth 2012 Test suite is quite extensive. I managed to get the “preliminary” tests and a substantial amount of the “core” tests running, even if not fully passing.
TLOAD
I’ve managed to get the BLKFILE implemented and loading text files
\ TLOADer
: tload-refill ( -- flag )
blkfile-buffer BLKFILE-BUFFER-SIZE SOURCE-ID @
READLINE-BLKFILE THROW
IF
blkfile-buffer SWAP 'SOURCE 2!
0 >IN ! TRUE
ELSE FALSE THEN ;
: (TLOAD) ( blk -- )
R/O OPEN-BLKFILE THROW ( blkfile-id )
SOURCE-ID !
BEGIN
REFILL IF
INTERPRET
ELSE SOURCE-ID @ CLOSE-BLKFILE THROW EXIT
THEN
AGAIN ;
: TLOAD ( blk -- )
SAVE-INPUT
['] tload-refill REFILLVEC !
(TLOAD)
RESTORE-INPUT ;
Preliminary results
The Preliminary results finally passed without any failures:
330 TLOAD
CR CR SOURCE TYPE ( Preliminary test ) CR
SOURCE ( These lines test SOURCE, TYPE, CR and parenthetic comments ) TYPE CR
( The next line of output should be blank to test CR ) SOURCE TYPE CR CR
( Pass #1: testing 0 >IN +! ) 0 >IN +! SOURCE TYPE CR
( Pass #2: testing 1 >IN +! ) 1 >IN +! xSOURCE TYPE CR
( Pass #3: testing 1+ ) 1 1+ >IN +! xxSOURCE TYPE CR
( Pass #4: testing @ ! BASE ) 0 1+ 1+ BASE ! BASE @ >IN +! xxSOURCE TYPE CR
( Pass #5: testing decimal BASE ) BASE @ >IN +! xxxxxxxxxxSOURCE TYPE CR
( Pass #6: testing : ; ) : .SRC SOURCE TYPE CR ; 6 >IN +! xxxxxx.SRC
( Pass #7: testing number input ) 19 >IN +! xxxxxxxxxxxxxxxxxxx.SRC
( Pass #8: testing VARIABLE ) VARIABLE Y 2 Y ! Y @ >IN +! xx.SRC
( Pass #9: testing WORD COUNT ) 5 MSG abcdef) Y ! Y ! >IN +! xxxxx.SRC
( Pass #10: testing WORD COUNT ) MSG ab) >IN +! xxY ! .SRC
Pass #11: testing WORD COUNT .MSG
Pass #12: testing = returns all 1's for true
Pass #13: testing = returns 0 for false
Pass #14: testing -1 interpreted correctly
Pass #15: testing 2*
Pass #16: testing 2*
Pass #17: testing AND
Pass #18: testing AND
Pass #19: testing AND
Pass #20: testing ?F~ ?~~ Pass Error
Pass #21: testing ?~
Pass #22: testing EMIT
Pass #23: testing S"
Results:
Pass messages #1 to #23 should be displayed above
and no error messages
0 tests failed out of 57 additional tests
--- End of Preliminary Tests ---
OK
Core tests
Core tests failed some FM/MOD calculations that I need to debug. These would be the original CamelForth code. Fuurther on, it then got stuck half way through:
360 TLOAD
TESTING CORE WORDS
TESTING BASIC ASSUMPTIONS
TESTING BOOLEANS: INVERT AND OR XOR
TESTING 2* 2/ LSHIFT RSHIFT
TESTING COMPARISONS: 0= = 0< < > U< MIN MAX
TESTING STACK OPS: 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP
TESTING >R R> R@
TESTING ADD/SUBTRACT: + - 1+ 1- ABS NEGATE
TESTING MULTIPLY: S>D * M* UM*
TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD INCORRECT RESULT: T{ -1 S>D 1 FM/MOD -> 0 -1 }T
INCORRECT RESULT: T{ -2 S>D 1 FM/MOD -> 0 -2 }T
INCORRECT RESULT: T{ 1 S>D -1 FM/MOD -> 0 -1 }T
INCORRECT RESULT: T{ 2 S>D -1 FM/MOD -> 0 -2 }T
INCORRECT RESULT: T{ MIN-INT S>D 1 FM/MOD -> 0 MIN-INT }T
INCORRECT RESULT: T{ 1 MIN-INT M* 1 FM/MOD -> 0 MIN-INT }T
INCORRECT RESULT: T{ 2 MIN-INT M* 2 FM/MOD -> 0 MIN-INT }T
INCORRECT RESULT: T{ MIN-INT MIN-INT M* MIN-INT FM/MOD -> 0 MIN-INT }T
INCORRECT RESULT: T{ MIN-INT MAX-INT M* MAX-INT FM/MOD -> 0 MIN-INT }T
TESTING HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2! ALIGN ALIGNED +! ALLOT
TESTING CHAR [CHAR] [ ] BL S"
TESTING ' ['] FIND EXECUTE IMMEDIATE COUNT LITERAL POSTPONE STATE
TESTING IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE
I believe the issue is down to the esoteric WHILE loop, with multiple exit points, that CamelForth doesn’t handle very well. For example, this GI5 word, as defined in the test suite, mixes BEGIN, WHILE, REPEAT, ELSE and THEN.
: GI5 BEGIN
DUP 2 > WHILE
DUP 5 < WHILE
DUP 1+
REPEAT
123
ELSE
345
THEN ;
Summary
So, even though I didn’t quite meet my goals for this challenge, I did succeed in loading source from “text files” that have been saved as blocks. Which means, I’ve got the beginnings of a comprehensive testing framework to work with, which is the most important part!
However, there are a few things that need to be sorted out to make the RC2014 CamelForth BootROM compliant to just the Core Forth 2012. This is important as people would want to type in standard Forth programs from internet to play with.
But, those aren’t problems, as my old boss would say, just opportunities to excel.