A small forth implementation.
- Highly modular.
- Can export relocatable object files (
*.o). - x86-64 and RV32/64.
This project requires bash, perl, m4, make, gcc (native) and g++ (native).
Additionally, for other architectures, gcc and qemu-user for every target platform (and qemu-system to run some OS-level tests).
This project assumes x86_64 to be native.
A single helper program needs to be compiled once manually:
gcc -o make-elf-writable make-elf-writable.c
To build and test all targets:
./build_all.sh
or to build a specific target (64-bit RISC-V as an example):
./build_all.sh rv64
or for complete control:
make -C arch/rv64 clean INC="..."
make -C arch/rv64 -j12 INC="..."
The example folder showcases compilation to object files, and three simple RV64 OS-kernels running smolforth. These examples act as your tutorial. Sorry.
INC is a space-separated list of word sets and features to include in the executable. By default, all features are enabled.
Read ARCHITECTURE.md for an explanation of the build system.
Start reading reloc-setup.fth for an in-depth explanation of object file compilation.
coreis required.- always provides the Exception Extensions word set.
The following word sets are fully provided:
-
blockprovides the Block Extensions word set. -
doubleprovides the Double-Number Extensions word set. -
fileprovides the File Access Extensions word set. -
floatprovides the Floating-Point Extensions word set. -
memoryprovides the Memory-Allocation word set. -
searchprovides the Search-Order Extensions word set. -
stringprovides the String Extensions word set. -
facilityprovides the Facility word set.
The following word sets are partially provided:
facilityprovides names from the Facility Extensions word set (K-words are missing).
The following word sets sparsely provided:
toolsprovides a few Programming-Tools Extensions words defined intools.fth. Other Programming-Tools Extensions words are provided because smolforth uses them internally (likeSTATE,CS-PICK,CS-ROLL,N>RandNR>), others are provided bysearchinstead (WORDS,NAME>STRING), and some are available in the folderasm/, but only on supported platforms.asmenablesCODEand an assembler if one is available on the platform.
Performant code generation was not the focus of this project. The most basic compiler supported on all platforms is a "dumb" compiler where almost every word turns into a call or push of some kind.
smolforth features three levels of optimizations that are enabled by putting one in INC.
Availability varies between architectures.
To highlight the difference, consider the stack movement words (e.g. SWAP, DROP, ROT, ...).
O0is the default and dumb assembler. Every stack movement word translates to a call to that word.O1is an inlined assembler. Stack movement words are inlined individually.O2is an optimizing compiler. Combinations of stack movement words are optimized together.
O0 is generally the smallest. O1 and O2 increase code size in favor of less function calls.
This project is small in the sense that there are no "nice-to-have" features. Things you might miss from other implementations:
- No bounds checks. Good Luck!
- You cannot set memory size at run-time. It's 16MB, as defined in
main.c. Recompile if you need more. - No FFI, no non-standard words. You can write your own word set, if you read ARCHITECTURE.md. And again, recompile.
- No cross-compiler or device link.
- No image save/restore.
0BSD