# prismio-lang/prismio architecture

> Architecture diagram of the GitHub repository prismio-lang/prismio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prismio-lang/prismio
- Repository: https://github.com/prismio-lang/prismio

## Overview

#### 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: [`src/sema/checker.psm`](https://github.com/prismio-lang/prismio/blob/main/src/sema/checker.psm) (Semantic checker), [`src/sema/ownership.psm`](https://github.com/prismio-lang/prismio/blob/main/src/sema/ownership.psm) (Ownership analysis), [`src/driver/imports.psm`](https://github.com/prismio-lang/prismio/blob/main/src/driver/imports.psm) (Import resolver), [`src/aif/walk.psm`](https://github.com/prismio-lang/prismio/blob/main/src/aif/walk.psm) (Allocation inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compiler["Compiler pipeline"]
  node_source[".psm source<br/>language input"]
  node_scanner["Scanner<br/>lexer<br/>[scanner.psm]"]
  node_parser["Parser<br/>[parser.psm]"]
  node_ast["Untyped AST<br/>syntax model<br/>[nodes.psm]"]
  node_imports["Import resolver<br/>frontend driver<br/>[imports.psm]"]
  node_sema["Semantic checker<br/>type and validity analysis<br/>[checker.psm]"]
  node_ownership["Ownership analysis<br/>move/borrow/drop rules<br/>[ownership.psm]"]
  node_diagnostics["Diagnostics<br/>compiler reporting<br/>[diagnostics.psm]"]
  node_aif["Allocation inference<br/>storage and layout analysis<br/>[walk.psm]"]
  node_lowering["LLVM IR lowering<br/>IR generation<br/>[expr.psm]"]
  node_bridge{{"LLVM bridge<br/>C-ABI backend boundary<br/>[bridge.psm]"}}
end

subgraph group_native["Native boundary"]
  node_llvm_backend["LLVM C backend<br/>native backend<br/>[llvm-api-backend.c]"]
  node_llvm["LLVM llc<br/>object-code generator"]
  node_linker["Clang linker<br/>native linker"]
  node_runtime["Prismio runtime<br/>native language support<br/>[lang_runtime.c]"]
  node_binary["Native binary<br/>compiler output"]
end

subgraph group_build["Build and bootstrap"]
  node_ums["UMS project subsystem<br/>manifest and build orchestration<br/>[ums.psm]"]
  node_build_plan["Build planner<br/>target planning<br/>[build_plan.psm]"]
  node_bootstrap["Bootstrap seed and promotion<br/>compiler generation control<br/>[prismio-seed.ll]"]
end

subgraph group_ecosystem["Library and validation"]
  node_stdlib["Standard library<br/>compiler-consumed library<br/>[vec.psm]"]
  node_validation["Regression and benchmarks<br/>validation harnesses<br/>[test_runner.py]"]
  node_aif_spec["AIF specification<br/>research record<br/>[SPEC.md]"]
end

node_source -->|"scan"| node_scanner
node_scanner -->|"tokens"| node_parser
node_parser -->|"builds"| node_ast
node_ast -->|"resolve imports"| node_imports
node_imports -->|"flattened AST"| node_sema
node_sema -->|"typed program"| node_ownership
node_sema -.->|"invalid program"| node_diagnostics
node_ownership -.->|"ownership errors"| node_diagnostics
node_ownership -->|"checked program"| node_aif
node_aif -->|"allocation annotations"| node_lowering
node_aif_spec -.->|"specifies"| node_aif
node_lowering -->|"LLVM IR calls"| node_bridge
node_bridge -->|"C ABI"| node_llvm_backend
node_llvm_backend -->|"emits IR"| node_llvm
node_llvm -->|"object code"| node_linker
node_runtime -->|"runtime objects"| node_linker
node_linker -->|"links"| node_binary
node_ums -->|"creates"| node_build_plan
node_build_plan -.->|"compiler targets"| node_source
node_bootstrap -->|"seed compiler"| node_ums
node_stdlib -.->|"language facilities"| node_imports
node_validation -.->|"drives builds"| node_ums

click node_scanner "https://github.com/prismio-lang/prismio/blob/main/src/lexer/scanner.psm"
click node_parser "https://github.com/prismio-lang/prismio/blob/main/src/parse/parser.psm"
click node_ast "https://github.com/prismio-lang/prismio/blob/main/src/ast/nodes.psm"
click node_imports "https://github.com/prismio-lang/prismio/blob/main/src/driver/imports.psm"
click node_sema "https://github.com/prismio-lang/prismio/blob/main/src/sema/checker.psm"
click node_ownership "https://github.com/prismio-lang/prismio/blob/main/src/sema/ownership.psm"
click node_diagnostics "https://github.com/prismio-lang/prismio/blob/main/src/common/diagnostics.psm"
click node_aif "https://github.com/prismio-lang/prismio/blob/main/src/aif/walk.psm"
click node_lowering "https://github.com/prismio-lang/prismio/blob/main/src/ir/expr.psm"
click node_bridge "https://github.com/prismio-lang/prismio/blob/main/src/ir/bridge.psm"
click node_llvm_backend "https://github.com/prismio-lang/prismio/blob/main/runtime/llvm-api-backend.c"
click node_runtime "https://github.com/prismio-lang/prismio/blob/main/runtime/lang_runtime.c"
click node_ums "https://github.com/prismio-lang/prismio/blob/main/ums/ums.psm"
click node_build_plan "https://github.com/prismio-lang/prismio/blob/main/ums/builder/build_plan.psm"
click node_bootstrap "https://github.com/prismio-lang/prismio/blob/main/bootstrap/prismio-seed.ll"
click node_stdlib "https://github.com/prismio-lang/prismio/blob/main/std/vec.psm"
click node_validation "https://github.com/prismio-lang/prismio/blob/main/tests/test_runner.py"
click node_aif_spec "https://github.com/prismio-lang/prismio/blob/main/aif/spec/SPEC.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_source,node_scanner,node_parser,node_ast,node_imports,node_sema,node_ownership,node_diagnostics,node_aif,node_lowering,node_bridge toneBlue
class node_llvm_backend,node_llvm,node_linker,node_runtime,node_binary toneAmber
class node_ums,node_build_plan,node_bootstrap toneMint
class node_stdlib,node_validation,node_aif_spec toneRose
```

## Components

### Compiler pipeline

Source-to-native compilation stages.

- **.psm source**: language input
- [Scanner](https://github.com/prismio-lang/prismio/blob/main/src/lexer/scanner.psm): lexer · `src/lexer/scanner.psm`
- [Parser](https://github.com/prismio-lang/prismio/blob/main/src/parse/parser.psm): parser · `src/parse/parser.psm`
- [Untyped AST](https://github.com/prismio-lang/prismio/blob/main/src/ast/nodes.psm): syntax model · `src/ast/nodes.psm`
- [Import resolver](https://github.com/prismio-lang/prismio/blob/main/src/driver/imports.psm): frontend driver · Recursively resolves and flattens imports. · `src/driver/imports.psm`
- [Semantic checker](https://github.com/prismio-lang/prismio/blob/main/src/sema/checker.psm): type and validity analysis · Establishes names, types, traits, and control-flow validity. · `src/sema/checker.psm`
- [Ownership analysis](https://github.com/prismio-lang/prismio/blob/main/src/sema/ownership.psm): move/borrow/drop rules · `src/sema/ownership.psm`
- [Diagnostics](https://github.com/prismio-lang/prismio/blob/main/src/common/diagnostics.psm): compiler reporting · `src/common/diagnostics.psm`
- [Allocation inference](https://github.com/prismio-lang/prismio/blob/main/src/aif/walk.psm): storage and layout analysis · Assigns allocation tiers and layouts to checked programs. · `src/aif/walk.psm`
- [LLVM IR lowering](https://github.com/prismio-lang/prismio/blob/main/src/ir/expr.psm): IR generation · Lowers typed, allocation-annotated AST constructs. · `src/ir/expr.psm`
- [LLVM bridge](https://github.com/prismio-lang/prismio/blob/main/src/ir/bridge.psm): C-ABI backend boundary · The only Prismio-to-LLVM API boundary. · `src/ir/bridge.psm`

### Native boundary

C ABI, LLVM, and linked runtime.

- [LLVM C backend](https://github.com/prismio-lang/prismio/blob/main/runtime/llvm-api-backend.c): native backend · `runtime/llvm-api-backend.c`
- **LLVM llc**: object-code generator
- **Clang linker**: native linker
- [Prismio runtime](https://github.com/prismio-lang/prismio/blob/main/runtime/lang_runtime.c): native language support · Provides generated-program helpers and platform integration. · `runtime/lang_runtime.c`
- **Native binary**: compiler output

### Build and bootstrap

Project resolution and compiler generation control.

- [UMS project subsystem](https://github.com/prismio-lang/prismio/blob/main/ums/ums.psm): manifest and build orchestration · Resolves workspaces, plans builds, and invokes compiler targets. · `ums/ums.psm`
- [Build planner](https://github.com/prismio-lang/prismio/blob/main/ums/builder/build_plan.psm): target planning · `ums/builder/build_plan.psm`
- [Bootstrap seed and promotion](https://github.com/prismio-lang/prismio/blob/main/bootstrap/prismio-seed.ll): compiler generation control · Committed LLVM seed enables staged self-builds. · `bootstrap/prismio-seed.ll`

### Library and validation

Compiler inputs and behavior validation.

- [Standard library](https://github.com/prismio-lang/prismio/blob/main/std/vec.psm): compiler-consumed library · `std/vec.psm`
- [Regression and benchmarks](https://github.com/prismio-lang/prismio/blob/main/tests/test_runner.py): validation harnesses · Exercises compiler behavior and performance. · `tests/test_runner.py`
- [AIF specification](https://github.com/prismio-lang/prismio/blob/main/aif/spec/SPEC.md): research record · Defines allocation-inference behavior and evidence context. · `aif/spec/SPEC.md`

## Connections

- .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
