-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
cipherat edited this page Apr 15, 2026
·
3 revisions
- Python 3.10+
-
uv (
curl -LsSf https://astral.sh/uv/install.sh | sh) - A C compiler (
gcc,clang, orcc) - Linux kernel headers (only for kernel module targets)
git clone https://github.com/scratch2c/scratch2c.git
cd scratch2c
uv syncThis creates a .venv, installs the project and dev dependencies (pytest, mypy), and locks everything in uv.lock.
Transpile a Scratch project to a userspace C program:
uv run scratch2c my_project.sb3 -o build/my_project.c --backend userspaceOr use the Makefile, which also copies scratch_runtime.h into the build directory:
make compile-userspace SB3=my_project.sb3
./build/my_projectmake kbuild SB3=my_project.sb3
sudo insmod build/my_project.ko
journalctl -rk | head -20
sudo rmmod my_projectThis requires linux-headers for your running kernel. On Arch: sudo pacman -S linux-lts-headers. On Debian/Ubuntu: sudo apt install linux-headers-$(uname -r).
scratch2c [-h] [-o OUTPUT] [-b {userspace,kernel}] [--dump-ir] input
| Flag | Description |
|---|---|
input |
Path to .sb3 file or raw project.json
|
-o |
Output file (default: stdout) |
-b |
Backend: userspace or kernel
|
--dump-ir |
Print the IR to stderr instead of generating C |
| Target | Description |
|---|---|
make sync |
Install/update dependencies |
make test |
Run the test suite |
make compile-userspace SB3=... |
Transpile + compile with cc
|
make kbuild SB3=... |
Transpile + build kernel module |
make userspace SB3=... |
Transpile only (no compile) |
make kernel SB3=... |
Transpile only (no compile) |
make lint |
Type-check with mypy |
make clean |
Remove build artifacts |
The SB3 variable defaults to projects/fibonacci.sb3.