Taking programming to another planet 🚀
Pluto is a compiled language that aims for the readability of scripting languages with the safety and performance of C/Go. A Go front‑end lowers .pt (code) and .spt (script) to LLVM 21 IR and emits native binaries. Functions are 'Templates' defined in .pt files, and can be compiled for different argument types used in .spt scripts — generics by use. Design highlights include range‑driven auto‑vectorization, safe arrays and slices, scope‑based memory (no nulls, no out‑of‑bounds, no GC), and concurrency by construction.
- Go front‑end, LLVM 21 back‑end; emits native binaries
- Template functions in
.pt: specialized per argument types (generic by use) - Range literals with auto‑vectorized execution
- First‑class arrays (safe slicing) and link semantics
- Scope‑based memory: no nulls, no OOB, no garbage collector
- printf‑style formatting; arrays/ranges printable
- Cross‑platform; GitHub Actions CI (Go 1.25 + LLVM 21)
Hello world (tests/helloworld.spt):
"hello world"
x = "hello 🙏"
x, "👍"
Run it (Pluto compiles directories, not single files):
# compile all scripts in the tests/ folder
./pluto tests
# run the produced binary for helloworld.spt
./tests/helloworld
Code + script (tests/math):
tests/math/math.pt
res = square(x)
res = x * x
tests/math/func.spt
y = square(2)
z = square(5.6)
y
z
Run it:
./pluto tests/math
./tests/math/func
- Build compiler:
go build -o pluto main.go - Run unit tests (race):
go test -race ./lexer ./parser ./compiler - Run full suite:
python3 test.py - New project setup: add a
pt.modat your repo root to define the module path (project root). Minimal example:pt.modfirst non‑comment line:module github.com/you/yourproject- Pluto walks up from the working directory to find
pt.modand treats that directory as the project root.
- Compile a directory:
./pluto [directory](writes binaries next to sources)
- Go
1.25on PATH - LLVM
21tools on PATH:clang,opt,llc,ld.lld - macOS Homebrew paths:
- Apple Silicon:
export PATH=/opt/homebrew/opt/llvm/bin:$PATH - Intel:
export PATH=/usr/local/opt/llvm/bin:$PATH
- Apple Silicon:
Linux/macOS (primary)
- Requirements: Go 1.25+ and LLVM 21 (
opt,llc,clang,ld.lld) - Linux install and set PATH:
- See https://apt.llvm.org for instructions. Typical flow:
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 21sudo apt install lld-21export PATH=/usr/lib/llvm-21/bin:$PATH
- See https://apt.llvm.org for instructions. Typical flow:
- macOS (Homebrew):
brew install llvm- Intel:
export PATH=/usr/local/opt/llvm/bin:$PATH - Apple Silicon:
export PATH=/opt/homebrew/opt/llvm/bin:$PATH
- Build & test end‑to‑end:
python3 test.py
- Unit tests only:
go test -race ./lexer ./parser ./compiler
- Install MSYS2 and use the "MSYS2 UCRT64" shell: https://www.msys2.org
- Packages:
pacman -S --needed mingw-w64-ucrt-x86_64-{go,llvm,clang,lld,python} - Quick build:
python scripts/msys2_build.py→ createspluto.exe - Tests:
python test.py(orpython test.py tests/mathfor a subset) - Manual build/test: ensure
clang,lld, and LLVM 21 libs are active in the UCRT64 env; for BYO LLVM builds you may needGOFLAGS='-tags=byollvm'andCGO_*flags fromllvm-config. - Verify LLVM 21 tools are present (e.g.,
C:\\msys64\\ucrt64\\bin). - The Windows runner automatically applies the correct MSYS2 environment (CGO + LLVM) so
go buildandgo testwork consistently.
Manual go build/test (MSYS2)
- If you want to run
go buildorgo testyourself in the UCRT64 shell, set:export CGO_ENABLED=1export CC=clang CXX=clang++export GOFLAGS='-tags=byollvm'export CGO_CPPFLAGS="$(llvm-config --cflags) -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"export CGO_CXXFLAGS="-std=c++17 $(llvm-config --cxxflags)"export CGO_LDFLAGS="$(llvm-config --ldflags --libs all --system-libs)"export PATH="/ucrt64/bin:$PATH"# already set by the UCRT64 shell- Now:
go test -race ./compilerorgo build -o pluto.exe main.go.
main.go: CLI entry; scans working dir for.ptand.spt, emits binariesast,lexer,parser: Front‑end for the Pluto languagecompiler: Type solving, IR generation, and LLVM emissionruntime: Embedded C runtime linked into final executablestests: End‑to‑end tests (.sptinputs with.expexpected outputs)pt.mod: Module declaration at the repo root
- Two phases: CodeCompiler for
.pt(reusable funcs/consts) → IR; ScriptCompiler for.spt(programs) links code IR. - Pipeline: generate IR → optimize
-O3viaopt→ object viallc→ link with runtime viaclang/lld. - Module resolution: walks up from CWD to find
pt.modand derives module path. - Cache layout:
<PTCACHE>/<module-path>/{code,script}stores IR/objects.
- From a directory with
.pt/.spt:./pluto(or./pluto path/to/dir) - Outputs a native binary for each
.sptnext to the source file.
- Unit tests:
go test -race ./lexer ./parser ./compiler - E2E:
python3 test.pybuilds the compiler, then compiles/executes tests undertests/and compares output to.exp. - Focus a subset:
python3 test.py tests/math
undefined: run_build_shduringgo build/test(Windows):- Ensure
GOFLAGS='-tags=byollvm'and CGO flags fromllvm-configare set (the MSYS2 runner andtest.pyin MSYS2 set these automatically).
- Ensure
- Encoding issues / mojibake in test output (Windows):
- Run from the MSYS2 UCRT64 shell; the runner decodes output as UTF‑8.
- Missing LLVM tools:
- Verify
opt,llc,clang,ld.lldfrom LLVM 21 are on PATH.
- Verify
- Clear Pluto cache if behavior seems stale:
- macOS:
rm -rf "$HOME/Library/Caches/pluto" - Linux:
rm -rf "$HOME/.cache/pluto"(orXDG_CACHE_HOME) - Windows:
rd /s /q %LocalAppData%\pluto
- macOS:
- Override cache location with
PTCACHEenv var.
- On Windows the produced binary is
pluto.exe. - The compiler shells out to LLVM tools (
opt,llc,clang,ld.lld). - The runtime enables
%non UCRT to match POSIXprintfbehavior.
- Go formatting:
go fmt ./...; vet:go vet ./... - Indentation: tabs for leading indentation across the repo (default gofmt behavior).
- Packages: lowercase short names; exports in CamelCase; tests in
*_test.go.
- Conventional Commits (e.g.,
feat(parser): ...,refactor(compiler): ...). - PRs: include a clear description, linked issues, and unit/E2E tests for changes.
- Language overview and design notes: see
CLAUDE.mdfor the philosophy (no nulls, no OOB, vectorization, conditional statements, concurrency model, arrays/links, etc.).
- Pluto is licensed under the MIT License. See
LICENSE. - Vendored third‑party:
runtime/third_party/klib/(klib by Attractive Chaos) is MIT‑licensed; its license is preserved inruntime/third_party/klib/LICENSE.txt.