How ultimatehaider/plantlang works
Purpose and entry points
PlantLang—Chloroplast is a self-hosted native compiler toolchain. It translates .plant source into C, then relies on GCC plus a C runtime to create executables. The user-facing compiler is bin/Chloroplast; the immutable bootstrap compiler is dist/Chloroplast. Compiler CLI behavior and compilation orchestration originate in src/plantc/main.plant.
Self-hosting build chain
The repository’s central control flow is bootstrap → compile compiler sources → link native compiler → repeat generations and compare artifacts for convergence. Makefile owns this build and self-hosting verification boundary; generated/intermediate compiler generations live under build/, while release-like executable outputs are under bin/ and dist/. Required build infrastructure is local make and gcc; no VM or JavaScript runtime is involved.
Paths: Makefile, dist/Chloroplast, build/plantc_all.plant.
Front end: lexical and syntactic lowering
The compiler is itself PlantLang source. The lexer turns source text into tokens, and the parser constructs/interprets the language’s syntax and AST-level representation, including declarations, control flow, module imports, types, generics, closures, async constructs, and FFI declarations. Parse failures form the primary source-language diagnostic boundary before C emission.
Paths: src/plantc/lexer.plant, src/plantc/parser.plant, src/plantc/main.plant.
C code generation
The code generator maps PlantLang semantics to standalone C: native actions, data shapes/classes/unions, generic monomorphizations, closure environment/function pairs, cooperative async state machines, exception machinery, and external C declarations/calls. Generated C is the boundary between language implementation and platform compiler/linker; it includes or targets runtime APIs rather than embedding their implementation.
Paths: src/plantc/codegen_c.plant, src/plantc/main.plant.
Native runtime and memory model
The compiled program links against a lightweight C runtime that supplies PlantLang’s operational substrate: core value/container/string facilities, deterministic scope-oriented arena allocation, exception/control support, async scheduling/draining, and native service integrations. Runtime headers define the ABI and compatibility/type layer used by generated C. Programs compile with the runtime source and -lm.
Paths: runtime/c/plant_runtime.c, runtime/c/plant_runtime.h, runtime/c/plant_types.h.
External integration boundary
PlantLang code can call native C through declared externals, including reference values, structs, callbacks, varargs, handles, and error reporting. The runtime also exposes built-in native services such as filesystem, JSON, time, math, strings, and collections. Network/server and filesystem behavior is implemented as native capabilities invoked by compiled programs, not as repository-hosted services.
Paths: runtime/c/plant_compat.h, runtime/c/plant_runtime.h, src/plantc/codegen_c.plant.
Verification and executable lifecycle
The primary validation model is compile-and-run native integration coverage: test programs are compiled by Chloroplast, linked to the runtime, and compared with expected outputs. Suites specifically exercise language regressions, FFI/runtime behavior, generics, closures, async, persistence/memory, and performance. Examples provide direct source inputs for the same compiler-to-C-to-native lifecycle.
Paths: tests/regression/run_regression_tests.sh, tests/native/run_native_tests.sh, examples/hello.plant.
Main entry points: Chloroplast Chloroplast · Makefile Make build pipeline · main.plant Compiler CLI and orchestration · plantc_all.plant Combined compiler sources
Components 15
Self-hosting build
- Make build pipeline · Bootstraps, rebuilds, and compares compiler generations.
Makefile - Bootstrap compiler · Immutable compiler seed.
dist/Chloroplast - Combined compiler sources
build/plantc_all.plant - Chloroplast · User-facing self-hosted compiler executable.
bin/Chloroplast
PlantLang compiler
- Compiler CLI and orchestration
src/plantc/main.plant - Lexer
src/plantc/lexer.plant - Parser and diagnostics · Builds syntax representation and reports source parse failures.
src/plantc/parser.plant - C code generator · Lowers language semantics into standalone C.
src/plantc/codegen_c.plant - Generated C · Platform compilation boundary for PlantLang programs.
Native runtime
- Runtime implementation · Provides allocation, exceptions, async, values, and native services.
runtime/c/plant_runtime.c - Runtime ABI · ABI, type, and compatibility contracts used by generated C.
runtime/c/plant_runtime.h - Native integration API · Supports declared C externals and native capability calls.
runtime/c/plant_compat.h
Verification
- Integration test suites · Compile and run language and native-runtime coverage.
tests/regression/run_regression_tests.sh - Example programs
examples/hello.plant
Other components
- Native executable · Generated C linked with the runtime and libm.
Connections 20
- Make build pipeline → Bootstrap compiler: starts from
- Bootstrap compiler → Combined compiler sources: compiles
- Make build pipeline → Combined compiler sources: assembles generations
- Combined compiler sources → Chloroplast: generates and links
- Make build pipeline → Chloroplast: rebuilds and compares
- Compiler CLI and orchestration → Lexer: tokenizes input with
- Compiler CLI and orchestration → Parser and diagnostics: parses with
- Compiler CLI and orchestration → C code generator: emits through
- Parser and diagnostics → C code generator: syntax representation
- C code generator → Generated C: lowers to
- Generated C → Runtime ABI: includes ABI
- Generated C → Native integration API: uses external declarations
- Generated C → Native executable: GCC compiles
- Runtime implementation → Native executable: links into
- Runtime ABI → Runtime implementation: declares
- Native integration API → Runtime ABI: extends integration boundary
- Chloroplast → Generated C: compiles .plant programs
- Integration test suites → Chloroplast: exercise
- Integration test suites → Native executable: runs and checks
- Example programs → Chloroplast: compile input