Incorrect code generation for TAGBODY with multiple GOs
CL-Forth is an implementation of Forth in Common Lisp which runs under several Lisp implementations. I received a pull request to add ECL support but I'm seeing incorrect behavior running the test suite under ECL that appears to be an ECL compiler bug.
It seems that the code generated for a Forth DO loop causes the entire Forth function to terminate when the loop terminates. This behavior causes numerous test failures.
Here's a transcript of a simplified version of one of the tests which involves nested DO loops.
CL-Forth Version 1.5
Running under ECL 24.5.10
optimizer on
OK.
: test 4 1 do 1 0 do j loop ." Outer " loop .s ;
OK.
test
OK.
bye
In this session:
1 definition created
CL-Forth generates the following Lisp code.
(DEFUN FORTH-WORDS::TEST (FS PARAMETERS)
(DECLARE (IGNORABLE PARAMETERS))
(WITH-FORTH-SYSTEM (FS)
(TAGBODY (LET ((N2 1) (N1 4))
(DECLARE (IGNORABLE N2 N1))
(STACK-PUSH LOOP-STACK 4)
(STACK-PUSH LOOP-STACK 1))
:DO484 (LET ((N2 0) (N1 1))
(DECLARE (IGNORABLE N2 N1))
(STACK-PUSH LOOP-STACK 1)
(STACK-PUSH LOOP-STACK 0))
:DO486 (WHEN (< (STACK-DEPTH LOOP-STACK) 4)
(FORTH-EXCEPTION :NO-LOOP-PARAMETERS
"J not inside DO ... DO ... LOOP ... LOOP"))
(STACK-PUSH DATA-STACK (STACK-CELL LOOP-STACK 2))
(INCF (STACK-CELL LOOP-STACK 0))
(WHEN (< (STACK-CELL LOOP-STACK 0) (STACK-CELL LOOP-STACK 1)) (GO :DO486))
(STACK-POP LOOP-STACK)
(STACK-POP LOOP-STACK)
:DO487 (WRITE-STRING "Outer ")
(INCF (STACK-CELL LOOP-STACK 0))
(WHEN (< (STACK-CELL LOOP-STACK 0) (STACK-CELL LOOP-STACK 1)) (GO :DO484))
(STACK-POP LOOP-STACK)
(STACK-POP LOOP-STACK)
:DO485 (SHOW-STACK DATA-STACK BASE)
:EXIT)))
Here's the same test run under one of the other Lisps that CL-Forth supports.
CL-Forth Version 1.5
Running under LispWorks 8.0.1
optimizer on
OK.
: test 4 1 do 1 0 do j loop ." Outer " loop .s ;
OK.
test
Outer Outer Outer
Contents of data stack:
0: 3
1: 2
2: 1
OK.
bye
In this session:
1 definition created
112 bytes of object code generated
Provide details regarding ECL version (or preferably commit), operating system and if revelant the build options and versions of the build tools.
VERSION "24.5.10"
VCS-ID "c235a57ded2569e33a40a1b51949fe0a099bebc5"
OS "Darwin"
OS-VERSION "24.1.0"
MACHINE-TYPE "arm64"
FEATURES (CFFI-FEATURES:FLAT-NAMESPACE CFFI-FEATURES:UNIX
CFFI-FEATURES:DARWIN :CFFI CFFI-SYS::FLAT-NAMESPACE :64-BIT
:ARM64 :SWANK :SERVE-EVENT :QUICKLISP :ASDF-PACKAGE-SYSTEM
:ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-MACOSX :OS-UNIX
:NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :WALKER :CDR-6
:GRAY-STREAMS-MODULE :CDR-1 :CDR-5 :DARWIN :FORMATTER :CDR-7
:C-COMPATIBLE-VARIADIC-DISPATCH :ECL-WEAK-HASH :LITTLE-ENDIAN
:LONG-LONG :UINT64-T :UINT32-T :UINT16-T :COMPLEX-FLOAT
:LONG-FLOAT :UNICODE :DFFI :CLOS-STREAMS :CMU-FORMAT :UNIX
:ECL-PDE :DLOPEN :CLOS :THREADS :BOEHM-GC :ANSI-CL :COMMON-LISP
:FLOATING-POINT-EXCEPTIONS :IEEE-FLOATING-POINT
:PACKAGE-LOCAL-NICKNAMES :CDR-14 :PREFIXED-API :FFI :AARCH64
:COMMON :ECL)
Some additional notes.