Toy C compiler implemented in Clojure
  • Clojure 62.2%
  • JavaScript 34%
  • HTML 3.8%
Find a file
2025-07-26 00:25:27 +05:30
.clj-kondo Add code emission for long type 2024-12-14 23:31:06 +05:30
cli Refactor into cli and cljcc-compiler folders 2025-03-16 18:03:26 +05:30
cljcc-compiler Adding clojure-mcp setup 2025-07-26 00:25:27 +05:30
frontend Compile library to WASM using GraalVM. 2025-04-26 01:35:36 +05:30
public Update README to include WASM compilation post. 2025-04-26 02:53:43 +05:30
resources project setup 2024-07-20 22:09:11 +05:30
.gitignore Compile library to WASM using GraalVM. 2025-04-26 01:35:36 +05:30
bb.edn Remove unused bb task 2025-06-21 18:07:30 +05:30
deps.edn Adding clojure-mcp setup 2025-07-26 00:25:27 +05:30
LICENSE project setup 2024-07-20 22:09:11 +05:30
README.md Adding clojure-mcp setup 2025-07-26 00:25:27 +05:30

cljcc

A toy C Compiler implementation in Clojure.

Browser version: cljcc

Follows the book Writing a C Compiler by Nora Sandler.

Post about my experience implementing the book writing-a-c-compiler-in-clojure.

Post on how to compile to WASM compiling-clojure-to-webassembly.

Prerequisites

Only Linux and Mac OS is supported. For Windows, run through WSL.

Tasks

To see all available tasks in the project, run bb tasks:

bb tasks
The following tasks are available:

clean            Removes target folder.
nrepl            Starts a nrepl session.
storm            Starts a nrepl session with storm debugger.
lib:run:main     Run's main only for cljcc library.
lib:build:jar    Builds uberjar only for cljcc lib.
lib:build:wasm   Builds native WASM image.
cli:run:main     Run's main CLI function.
cli:build:jar    Builds uberjar for CLI.
cli:run:jar      Runs CLI jar.
cli:build:native Builds native image for CLI.

Build

To build native image, run:

( This requires having native-image tool installed locally. Use the appropriate JDK distribution. )

bb cli:build:native

This produces a binary cljcc-cli at /target/cli. Pass the path to the C file.

./target/cli/cljcc-cli "path/to/file.c"

Run Jar

bb cli:run:jar

References

Some talks / projects which helped in implementation.