-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Strange Forth is an implementation of Forth, as a scripting language. So, unlike a lot of Forths we don't compile to assembly language but an interpreted byte-code. One side goal is to add a JIT engine at some point, but for now at least, everything is interpreted.
This implementation was inspired by the article Forth: The programming language that writes itself. In particular the simplicity of the Forth language and it's powerful extensibility.
To illustrate this point, large portions of the language implementation are implemented in the standard library, std.f. Typically built in constructs like if, case, or loops are all implemented as forth words.
So, one of the goals of the project was to take Forth and make it interoperable with modern systems. To help towards this goal, the language server for this project itself is written in Strange Forth.
This project is still in it's early stages, there is a roadmap on the main page that will outline further goals for this project.
Start off by cloning the main repo.
git clone git@github.com:cstrainge/sorth.git
On Linux and macOS you need to install a C++ compiler and build tools like Ninja
CMake
, and git
. You will also need to make sure you have libffi
dev installed.
Once your environment is setup you can use cmake
to build the interpreter by running:
mkdir build ; cd build
cmake .. -G Ninja
You need to have VCPKG
, ninja
, cmake
, and a C++ compiler installed. The easiest way is to install the Visual Studio Community Edition and build from a Developer Studio Command Prompt. You can then run cmake with the following:
mkdir build ; cd build
cmake -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\vcpkg\scripts\buildsystems\vcpkg.cmake --preset=default .. -G Ninja
VCPKG
will make sure to install the required libffi automatically.
In the project's root directory. This will generate the interpreter and copy the standard library into the ./dist
directory.
To jump into the sorth repl either add the dist
directory into the path or run:
./dist/sorth
Once running in the repl you should get the standard welcome text:
Strange Forth REPL.
Version: <current-version>
Enter quit, q, or exit to quit the REPL.
Enter .w to show defined words.
Enter show_word <word_name> to list detailed information about a word.
Hit alt + enter to enter multi-line editing mode.
>>
You can also run the interpreter with a pre-written script by passing the path to the script on the command line:
sorth path\to\my\script.f
If you are on a Unix system you can make the script itself executable like other scripting languages. First make sure the executable sorth
is in your path.
Then add the following to the top of your script:
#!/usr/bin/env sorth
Now, normally # is not a comment character in the language. Right now, only brackets separated by spaces are proper comments, ( )
. However #!/usr/bin/env
and sorth
are defined as words in the standard library that do not do anything. This approach allows the language to have it's won comments without having to special case this in the interpreter.
If you are on Windows you can add *.f
to the Windows PATHEXT
environment variable. (This allows you to run the script without typing the .f at the command line. Just like with .exe
files.) Then you need to register the interpreter in the Windows registry under: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
Please visit the following pages for more details about the language.