Urgent.News

What's breaking now, across thousands of outlets.

Tech

cl-forth: Forth 2012 Standard in CL

CL-Forth is a Common Lisp implementation of the Forth 2012 Standard. It is fully supported by CCL v1.12.2-82 or later, SBCL 2.1.0 or later, and LispWorks 8.0.1 or later. CL-Forth is also compatible with ECL 26.3.27 or later. However, there are currently two failing tests in the String word set tests which remain unresolved. This implementation is supported on macOS, Linux, and Windows.

On macOS, CL-Forth functions correctly on Ventura or later. On Linux, the implementation works on distributions with 5.10.162 kernels or later, and on Windows, it operates on Windows 10 or later. CL-Forth is distributed under the MIT License. The implementation is defined using ASDF and relies on the CFFI and trivial-gray-streams libraries.

Users can obtain CL-Forth and the Forth 2012 Test Suite by fetching the necessary files and configuring them to run only those word sets implemented by CL-Forth. QuickLisp is a convenient method for acquiring the CFFI and trivial-gray-streams libraries. After downloading and installing QuickLisp, users can add it to their Lisp system's initialization file.

To install the libraries, users must evaluate specific forms, a process that only needs to be performed once. CL-Forth can be compiled into a standalone application, creating an executable named cl-forth. Upon running cl-forth, the user is directly placed into the Forth interpreter loop. The application supports various command line arguments.

Notably, CL-Forth does not implement the optional Block and Extended-Character word sets, nor does it include the KEY command from the Core word set. Certain words from the optional Facility and Facility extensions word set are also not implemented. CL-Forth incorporates a foreign function interface (FFI) inspired by the External Library Interface in SwiftForth.

Additional details regarding the FFI can be found in the FFI.md file. The implementation also features an experimental optimizer that aims to simplify the code generated by CL-Forth by minimizing the use of the data stack and eliminating redundant validity checks. This optimization, controlled by the OPTIMIZER variable, can be toggled on or off using the OPTIMIZER ON and OPTIMIZER OFF commands, respectively.

On SBCL, the Forth test suite runs approximately 33% faster and generates around 25% less object code. The optimizer enhances code generation by CL-Forth in various ways, as demonstrated in the following examples. CL-Forth also includes words defined by other implementations that are not part of the Forth 2012 Standard. These words are treated as "Common Usage" in the Forth Programmer's Manual, 3rd Edition.

CL-Forth implements CODE and ;CODE, enabling the definition of words written in Lisp rather than Forth. The terminator for Lisp code blocks is ;ENDCODE.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at github.com →

More in Tech

More from Thursday 6 August →