All Projects → Reschivon → movForth

Reschivon / movForth

Licence: MIT license
LLVM frontend for the Forth Language

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to movForth

sycl
SYCL for Vitis: Experimental fusion of triSYCL with Intel SYCL oneAPI DPC++ up-streaming effort into Clang/LLVM
Stars: ✭ 80 (+12.68%)
Mutual labels:  llvm
evm llvm
Official repo of the EVM LLVM project
Stars: ✭ 72 (+1.41%)
Mutual labels:  llvm
lhc
The LLVM LHC Haskell Optimization System
Stars: ✭ 194 (+173.24%)
Mutual labels:  llvm
LLVMTemplate
LLVM + Swift template Xcode project
Stars: ✭ 12 (-83.1%)
Mutual labels:  llvm
adorad
Fast, Expressive, & High-Performance Programming Language for those who dare
Stars: ✭ 54 (-23.94%)
Mutual labels:  llvm
code runner.nvim
Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
Stars: ✭ 234 (+229.58%)
Mutual labels:  executable
flextool
C++ compile-time programming (serialization, reflection, code modification, enum to string, better enum, enum to json, extend or parse language, etc.)
Stars: ✭ 32 (-54.93%)
Mutual labels:  llvm
compiler lab
Some toy labs for compiler course
Stars: ✭ 49 (-30.99%)
Mutual labels:  llvm
pa.llvm
Program Analysis for LLVM
Stars: ✭ 37 (-47.89%)
Mutual labels:  llvm
clad
clad -- automatic differentiation for C/C++
Stars: ✭ 161 (+126.76%)
Mutual labels:  llvm
juce faustllvm
JUCE Module for the libfaust JIT compiler
Stars: ✭ 32 (-54.93%)
Mutual labels:  llvm
FPChecker
A dynamic analysis tool to detect floating-point errors in HPC applications.
Stars: ✭ 26 (-63.38%)
Mutual labels:  llvm
pacxx-llvm
Programming Accelerators with C++ (PACXX)
Stars: ✭ 57 (-19.72%)
Mutual labels:  llvm
rain
A programming language.
Stars: ✭ 20 (-71.83%)
Mutual labels:  llvm
Grimheart
Torture your LLVM Obfuscation
Stars: ✭ 29 (-59.15%)
Mutual labels:  llvm
U-00DC-Sprache
"Ü" programming language development
Stars: ✭ 43 (-39.44%)
Mutual labels:  llvm
ebpfault
A BPF-based syscall fault injector
Stars: ✭ 65 (-8.45%)
Mutual labels:  llvm
los
Los是一个c/c++语言编译型的虚拟机。它使用llvm/clang作为其前端,losld做后端对源代码进行编译,生成los指令文件。Los is a c/c++-compiled virtual machine. It uses llvm/clang as its front end, losld does the backend to compile the source code, and generates the los directive file.
Stars: ✭ 46 (-35.21%)
Mutual labels:  llvm
alon
Remix for Solana.
Stars: ✭ 87 (+22.54%)
Mutual labels:  llvm
kotlin-native
Kotlin/Native infrastructure
Stars: ✭ 7,066 (+9852.11%)
Mutual labels:  llvm

MovForth

GitHub release (latest by date including pre-releases) GitHub

MovForth compiles Forth source code to executable binaries. Using LLVM IR as an intermediate target, it is an experiment in adapting Forth for modern compiler libraries and modern architectures.

Forth 2020 Presentation Recording

  • Bottom-up compilation; no dictionary or interpreter remains in final executable
  • Compile time evaluation for immediate words allows programmers to use meta-compilation without fear
  • Compiling to LLVM IR allows for compilation to pretty much any architecture
  • Modern LLVM optimization passes used on Forth code

You can find Forth source and its corresponding compiled forms in Examples/

Installation

  • Have LLVM installed (LLVM-10 and above). For Ubuntu/Debian-based distros, simply run:
sudo apt install llvm
  • Clone the repository
git clone https://github.com/Reschivon/movForth
  • Build as CMake project
cd movForth
mkdir build && cd build
cmake ..
make -j4
  • Optionally, you can install clang++. MovForth uses clang++ to link the generated assembly file with stdlibc++ and produce a binary. If clang++ is not installed, you can link and assemble the .S file manually.

Alternatively, you can check Releases for precompiled binaries, but it is highly unlikely I will remember to update them.

Running

The main.cpp file compiles into a simple command line utility for movForth. The syntax is:

movForth [source file]

An example usage, assuming you have a cmake build directory named build, is:

build/movForth Examples/fibonacci/source.fs

Do check out the Examples/ folder. In the likely scenario that you encounter a bug or crash, feel free to create an issue.

Concept

MovForth achieves LLVM IR generation in three steps

  1. The immediate (compile-time) portion of Forth source is run, and a dictionary is generated
  2. Data flow and control flow graphs are built for the words in the dictionary. This process computes the number of parameters and returns for each word, and allocates unique registers for each element passed on the stack.
  3. The graphs from the previous step are used to generate LLVM Basic Blocks and registers. Optimization passes are run and machine code for a target of choice is produced.

Future features:

  • Benchmarks
  • Standardizing movForth to be as close to "regular" Forth as possible
  • Dynamic linking so you can have an interactive Forth with certain compiled words
  • Interfacing with libraries that follow the C ABI

Supported Primitives

MovForth is powerful because operations that are immediate in a traditional interpreted Forth are run during compile time. Therefore, meta-compilation words like IF, DO, and COLON incur no runtime penalty.

Words available during immediate mode:

< = + - * / SWAP ROT DUP DROP . SHOW ' , SEE [ ] IMMEDIATE ALLOT @ ! BRANCH BRANCHIF LITERAL HERE CREATE

Words available during runtime:

< = + - * / BRANCH BRANCHIF . DUP DROP LITERAL ! @ MALLOC

Locals can be used in both compile and runtime, and compile to the exact same machine code as their stack-based counterpart. They use the word to for assignment.

Push 42 to local named "life" (creation of locals is implicit):

42 to life

Push the value stored in local "life" to stack:

life

Contribute

I welcome all tips, comments, or help! I'll do my best to respond in a timely manner.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].