I am pleased to announce the (pre) release of v0.1.0 of the Little Haskell Compiler, or LHC for short.
The Little Haskell Compiler is a lightweight functional virtual machine based on Peter Landin’s SECD machine, which was was used to implement the homoiconic dialect of Pure Lisp. I am using it now to implement a homoiconic dialect of Haskell that has first-class access to low-level memory primitives, making it suitable for browser applications or embedded environments!
Check out the web demo, there are presets and tutorials to show you how it works! I suggest running the quickstart!
- It is small
- It can run in just a few kilobytes of memory (the web demo is hardcoded to 1 megabyte)
- It compiles for native and for wasi-wasm
- It compiles and runs code in my browser and on my phone
- It is 100% compliant with the original SECD machine
- It was designed to make compiling lambda calculus trivial, which it does
- It can be easily extended with new opcodes, machine procedures, and language features
- It is designed to be relocatable in memory by using relative addressing instead of pointers
In just over 2600 lines of C, it includes:
- A full application lifecycle with logging and an event loop
- An assembler
- A pretty printer
- A repl with commands
- The virtual machine itself
LHC’s assembly syntax is 100% Haskell-compatible syntax (think of it as the SECD monad, which, coming soon…), and will eventually be extended upwards with more language features as I bootstrap things. Simulataneously, the implementation is currently written in pure C, and will be rewritten in 100% Haskell using the memalloc library when I bootstrap things far enough.
A link to the source code is at the bottom of the page (its just a single C file right now, behold my strange C style that everybody disagrees with), and is an AI Disclaimer (tl;dr 100% human, no autonomous AI agents were used)
–
Coming soon:
- let and letrec syntax
- DeBruiijn expression syntax
- tuple syntax
- Negative integers
- Escapable character literals
- EOF symbol
- Constructor-mnemonics
- Top-level environment accessor
–
Helpful resources in developing this:
Please report any discovered issues.
Known issues include:
- Application timer is disabled (causes WASM crashes, no throttling until fixed)
- WASM Command mode is broken
- Larger programs can crash the stack on mobile browsers (if that happens, try clicking reset and run again, as the wasm runtime may allocate a larger stack after it crashes with OOM / stack limit a first time)
- Logging uses recursive functions that can blow the stack
- Logging dominates CPU time and memory, even when piped to /dev/nul
- Excessive logging (Hello world can generate up to a half-megabyte of logs)
- Textfields don’t resize properly on mobile
- Autogc sometimes gets skipped (is not currently turned on though - use :gc to force garbage collection, or set auto_gc to 1 to run every frame