How prismio-lang/prismio works
Purpose and entry points
Prismio is a self-hosted, statically typed systems-language compiler. It compiles .psm source to native binaries through LLVM IR, with explicit allocation and C-ABI FFI. The compiler executable starts at src/main.psm; project-oriented command dispatch is in src/project/ums_cli.psm. Its required build manifest is build.ums.
Frontend: lexing, parsing, AST, imports
Source text is scanned into tokens, parsed into an untyped AST, then imports are recursively resolved and flattened before semantic work. The principal boundary is source/AST: frontend stages do not generate native code.
• src/lexer/scanner.psm
• src/parse/parser.psm
• src/ast/nodes.psm
• src/driver/imports.psm
Semantic analysis and language safety
Semantic analysis establishes names, types, overloads/generics/traits, control-flow validity, and move/borrow/drop ownership rules. This is the correctness boundary before allocation planning and LLVM lowering; invalid programs should stop here with diagnostics.
• src/sema/checker.psm
• src/sema/ownership.psm
• src/sema/types.psm
• src/common/diagnostics.psm
Allocation Inference (AIF)
AIF analyzes the semantically checked program to assign allocation/storage tiers and layouts. Its decisions affect emitted code and can be surfaced through the aif CLI command and stable manifests. The implementation is paired with specification, corpus, and evidence assets that act as a performance/correctness research record.
• src/aif/model.psm
• src/aif/walk.psm
• src/aif/layout.psm
• aif/spec/SPEC.md
IR lowering and LLVM boundary
The IR stage lowers typed, allocation-annotated AST constructs into LLVM IR. Prismio code accesses no LLVM API directly: src/ir/bridge.psm is the explicit FFI boundary to the C backend, allowing backend replacement at link time. LLVM then produces object code; Clang performs final linking.
• src/ir/expr.psm
• src/ir/stmt.psm
• src/ir/types.psm
• src/ir/bridge.psm
• runtime/llvm-api-backend.c
Native runtime and external interfaces
Generated programs link Prismio runtime support plus optional native libraries. Runtime code supplies language support, diagnostics, platform integration, generated-program helpers, and LLVM-backend symbols. C ABI extern fn declarations are the language’s FFI model. Material external dependencies are LLVM 22, llvm-llc, Clang, and platform C/linker facilities.
• runtime/prismio_runtime.h
• runtime/lang_runtime.c
• runtime/program_support.c
• runtime/diagnostics.c
Build, bootstrap, and package resolution
UMS is the project/build subsystem: it parses manifests, discovers dependencies, resolves the workspace, creates a build plan, and invokes compiler targets. The repository bootstraps from a committed LLVM seed, then supports staged self-build/promotion via a local compiler host. This makes compiler generation selection a deliberate control boundary.
• ums/ums.psm
• ums/builder/build_plan.psm
• ums/dependency/resolve.psm
• bootstrap/prismio-seed.ll
• tools/bootstrap.sh
Standard library and validation ecosystem
std/ provides compiler-consumed language facilities such as collections, filesystem, process, strings, and platform APIs. The main regression suite drives compiler behavior; benchmarks compare Prismio with C++ and Rust, while AIF evidence captures codegen and allocation-performance validation.
• std/vec.psm
• std/process.psm
• tests/test_runner.py
• benchmarks/run.py
Main entry points: checker.psm Semantic checker · ownership.psm Ownership analysis · imports.psm Import resolver · walk.psm Allocation inference
Components 22
Compiler pipeline
Source-to-native compilation stages.
- .psm source
- Scanner
src/lexer/scanner.psm - Parser
src/parse/parser.psm - Untyped AST
src/ast/nodes.psm - Import resolver · Recursively resolves and flattens imports.
src/driver/imports.psm - Semantic checker · Establishes names, types, traits, and control-flow validity.
src/sema/checker.psm - Ownership analysis
src/sema/ownership.psm - Diagnostics
src/common/diagnostics.psm - Allocation inference · Assigns allocation tiers and layouts to checked programs.
src/aif/walk.psm - LLVM IR lowering · Lowers typed, allocation-annotated AST constructs.
src/ir/expr.psm - LLVM bridge · The only Prismio-to-LLVM API boundary.
src/ir/bridge.psm
Native boundary
C ABI, LLVM, and linked runtime.
- LLVM C backend
runtime/llvm-api-backend.c - LLVM llc
- Clang linker
- Prismio runtime · Provides generated-program helpers and platform integration.
runtime/lang_runtime.c - Native binary
Build and bootstrap
Project resolution and compiler generation control.
- UMS project subsystem · Resolves workspaces, plans builds, and invokes compiler targets.
ums/ums.psm - Build planner
ums/builder/build_plan.psm - Bootstrap seed and promotion · Committed LLVM seed enables staged self-builds.
bootstrap/prismio-seed.ll
Library and validation
Compiler inputs and behavior validation.
- Standard library
std/vec.psm - Regression and benchmarks · Exercises compiler behavior and performance.
tests/test_runner.py - AIF specification · Defines allocation-inference behavior and evidence context.
aif/spec/SPEC.md
Connections 22
- .psm source → Scanner: scan
- Scanner → Parser: tokens
- Parser → Untyped AST: builds
- Untyped AST → Import resolver: resolve imports
- Import resolver → Semantic checker: flattened AST
- Semantic checker → Ownership analysis: typed program
- Semantic checker → Diagnostics: invalid program
- Ownership analysis → Diagnostics: ownership errors
- Ownership analysis → Allocation inference: checked program
- Allocation inference → LLVM IR lowering: allocation annotations
- AIF specification → Allocation inference: specifies
- LLVM IR lowering → LLVM bridge: LLVM IR calls
- LLVM bridge → LLVM C backend: C ABI
- LLVM C backend → LLVM llc: emits IR
- LLVM llc → Clang linker: object code
- Prismio runtime → Clang linker: runtime objects
- Clang linker → Native binary: links
- UMS project subsystem → Build planner: creates
- Build planner → .psm source: compiler targets
- Bootstrap seed and promotion → UMS project subsystem: seed compiler
- Standard library → Import resolver: language facilities
- Regression and benchmarks → UMS project subsystem: drives builds