Drast is a statically typed, indentation-scoped systems language that emits C++ for embedded and low-level targets. The compiler is currently focused on Arduino-compatible C++ generation, header emission, and a Rust-inspired ownership/type-checking model that can be enforced before C++ is compiled.
Drast does not own builds or dependency graphs anymore. Use make, xmake,
PlatformIO, Arduino tooling, or plain clang++ around the generated C++.
Prerequisites:
clang++python3- PlatformIO, only for Arduino project validation
- macOS arm64 for the pinned legacy bootstrap seed in this repository
Build the compiler from the repository root:
./tools/bootstrap/bootstrap.sh --checkRun the fast smoke tests:
./tests/run_tests.shRun the native type checker without emitting C++:
./build/bin/drast check path/to/main.drastEmit a single C++ translation unit:
./build/bin/drast transpile tests/basics/single_statement_main.drast -o /tmp/main.cpp
clang++ -std=c++17 -I. -Isrc/library /tmp/main.cpp -o /tmp/mainEmit Arduino-style headers and implementations:
./build/bin/drast headers --out generated path/to/main.drastValidate the local Outpost PlatformIO project:
./tools/generate_headers.py --project ~/Downloads/Outpostuse drast
main, int
println 'Hello from Drast!'
return 0
| Area | Status |
|---|---|
| C++ backend | The only backend. Emits hosted C++17 translation units and Arduino-friendly .h / .cpp pairs. |
| Header manager | Deduplicates system and local includes and emits only headers required by the generated declarations/body plus explicit use headers. |
| Parser | Accepts the current spec surface: mut, trait, func closure types, string interpolation, ~mut[T], *T, tuple[...], postfix [as Type], colon branch shorthand, named constructors, just/nothing/ok/err, and word bitwise operators. |
| Type checker | Enforces fixed-width numeric rules, maybe/result misuse, mut bindings, first-class Result[T,E], generic with T as Trait method gating, enum match exhaustiveness, and minimum-viable move tracking. |
| Borrow checker | Scoped to Drast-declared code. Native C++ calls are treated conservatively at the boundary. |
| Arduino / native interop | use file 'Header.hpp' and use Arduino.h lower to local/system C++ includes. Namespace-qualified static calls and zero-argument native methods are supported. |
| Builds | External. Drast writes C++; your build tool decides flags, libraries, upload targets, and dependency management. |
From an Arduino or PlatformIO project directory, emit drop-in generated files:
drast headers --out src/drast src/main.drastThis writes src/drast/main.h and src/drast/main.cpp. Include the header
from your sketch or native C++ file, then compile the generated .cpp with
the rest of the project.
use file 'Adafruit_MPU6050.h'
mut reading f32 = 0
sample mpu;Adafruit_MPU6050, f32
return reading
The helper script used by this repo for the Outpost project is:
./tools/generate_headers.py --project ~/Downloads/OutpostIt regenerates Drast headers under src/drast and then runs pio run.
src/compiler/lexer/contains token definitions and lexing.src/compiler/parser/contains the thin parser router.src/compiler/features/contains feature-owned AST/parse/emit logic.src/compiler/typechecker/contains semantic analysis.src/compiler/borrowchecker/contains Drast-only ownership/move tracking.src/compiler/backend/contains C++ emission orchestration, header generation, and include management.src/library/contains Drast prelude/runtime support used by generated programs.tests/contains smoke, conformance, interop, and C++ codegen fixtures.docs/drast-spec.mdis the language spec;docs/COMPILER_ARCHITECTURE.mddescribes the active compiler layout.
- Alpha diagnostics are improving, but not every parser/codegen error has final file/line/column quality yet.
- The native type checker still trails the production parser in a few syntax corners, so most transpile/header commands keep type checking opt-in through
--typecheck. - Borrow checking covers Drast-owned values only; C++ calls are treated as conservative boundary operations.
- Closures, first-class function values, full string interpolation coverage, macro annotations, and full generic constraint checking are still planned work.
- The pinned bootstrap seed is macOS/darwin-arm64; other platforms need a prebuilt Drast binary or a new bootstrap seed.