# tap-lang/tap architecture

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

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

## Overview

tap is a C-implemented, LLVM-backed programming language. Its primary workflow is source input through lexing, parsing, module/prelude loading and language lowering, then LLVM code generation and output or execution. The repository also provides an imported Tap standard library and a C runtime for native programs. The main driver and README document the workflow and compiler modes; several standard-library connections reflect README capabilities because their implementations were not sampled.

Main entry points: [`src/main.c`](https://github.com/tap-lang/tap/blob/main/src/main.c) (CLI driver), [`src/codegen.c`](https://github.com/tap-lang/tap/blob/main/src/codegen.c) (LLVM codegen), [`src/parser.c`](https://github.com/tap-lang/tap/blob/main/src/parser.c) (Parser), [`std/prelude.tp`](https://github.com/tap-lang/tap/blob/main/std/prelude.tp) (Standard prelude)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compiler["Compiler front end"]
  node_cli["CLI driver<br/>[main.c]"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST model<br/>[ast.c]"]
  node_modules["Module loader<br/>[module.c]"]
  node_prelude["Prelude loader<br/>[prelude.c]"]
end

subgraph group_lowering["Language lowering"]
  node_tagged["Enum lowering<br/>[tagged.c]"]
  node_generics["Generic specialization<br/>[generics.c]"]
end

subgraph group_backend["Code generation and execution"]
  node_codegen["LLVM codegen<br/>[codegen.c]"]
  node_runner["Native and lli runner<br/>[run.c]"]
end

subgraph group_libraries["Runtime and libraries"]
  node_runtime["C runtime<br/>[runtime.c]"]
  node_runtimeabi["Runtime ABI<br/>[tap_runtime.h]"]
  node_stdprelude["Standard prelude<br/>[prelude.tp]"]
  node_stdmath["Math library<br/>[math.tp]"]
  node_stdmodules["Standard modules"]
end

node_user(("Program author"))
node_source["Tap source"]
node_llvm["LLVM"]
node_output["IR, object, executable"]
node_program(("Compiled Tap program"))

node_user -->|"writes"| node_source
node_source -->|"submits"| node_cli
node_cli -->|"creates lexer"| node_lexer
node_lexer -->|"provides tokens"| node_parser
node_cli -->|"creates parser"| node_parser
node_parser -->|"builds AST"| node_ast
node_cli -->|"loads imports"| node_modules
node_cli -->|"loads prelude"| node_prelude
node_cli -->|"lowers enums"| node_tagged
node_cli -->|"specializes generics"| node_generics
node_cli -->|"generates code"| node_codegen
node_codegen -->|"builds LLVM IR"| node_llvm
node_cli -->|"selects execution"| node_runner
node_runner -->|"writes or runs"| node_output
node_codegen -->|"emits IR or object"| node_output
node_output -->|"executes"| node_program
node_runtime -->|"implements ABI"| node_runtimeabi
node_stdprelude -.->|"uses runtime functions"| node_runtimeabi
node_stdmath -->|"is imported as"| node_stdmodules
node_stdmodules -->|"imported by"| node_source
node_stdprelude -->|"loaded automatically"| node_source
node_program -.->|"uses runtime services"| node_runtime

click node_cli "https://github.com/tap-lang/tap/blob/main/src/main.c"
click node_lexer "https://github.com/tap-lang/tap/blob/main/src/lexer.c"
click node_parser "https://github.com/tap-lang/tap/blob/main/src/parser.c"
click node_ast "https://github.com/tap-lang/tap/blob/main/src/ast.c"
click node_modules "https://github.com/tap-lang/tap/blob/main/src/module.c"
click node_prelude "https://github.com/tap-lang/tap/blob/main/src/prelude.c"
click node_tagged "https://github.com/tap-lang/tap/blob/main/src/tagged.c"
click node_generics "https://github.com/tap-lang/tap/blob/main/src/generics.c"
click node_codegen "https://github.com/tap-lang/tap/blob/main/src/codegen.c"
click node_runner "https://github.com/tap-lang/tap/blob/main/src/run.c"
click node_runtime "https://github.com/tap-lang/tap/blob/main/runtime/src/runtime.c"
click node_runtimeabi "https://github.com/tap-lang/tap/blob/main/runtime/include/tap_runtime.h"
click node_stdprelude "https://github.com/tap-lang/tap/blob/main/std/prelude.tp"
click node_stdmath "https://github.com/tap-lang/tap/blob/main/std/math.tp"
click node_stdmodules "https://github.com/tap-lang/tap/tree/main/std"

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_cli,node_lexer,node_parser,node_ast,node_modules,node_prelude toneBlue
class node_tagged,node_generics toneAmber
class node_codegen,node_runner toneMint
class node_runtime,node_runtimeabi,node_stdprelude,node_stdmath,node_stdmodules toneRose
class node_user,node_source,node_llvm,node_output,node_program toneIndigo
```

## Components

### Compiler front end

- [CLI driver](https://github.com/tap-lang/tap/blob/main/src/main.c): `src/main.c`
- [Lexer](https://github.com/tap-lang/tap/blob/main/src/lexer.c): `src/lexer.c`
- [Parser](https://github.com/tap-lang/tap/blob/main/src/parser.c): `src/parser.c`
- [AST model](https://github.com/tap-lang/tap/blob/main/src/ast.c): `src/ast.c`
- [Module loader](https://github.com/tap-lang/tap/blob/main/src/module.c): `src/module.c`
- [Prelude loader](https://github.com/tap-lang/tap/blob/main/src/prelude.c): `src/prelude.c`

### Language lowering

- [Enum lowering](https://github.com/tap-lang/tap/blob/main/src/tagged.c): `src/tagged.c`
- [Generic specialization](https://github.com/tap-lang/tap/blob/main/src/generics.c): `src/generics.c`

### Code generation and execution

- [LLVM codegen](https://github.com/tap-lang/tap/blob/main/src/codegen.c): `src/codegen.c`
- [Native and lli runner](https://github.com/tap-lang/tap/blob/main/src/run.c): `src/run.c`

### Runtime and libraries

- [C runtime](https://github.com/tap-lang/tap/blob/main/runtime/src/runtime.c): `runtime/src/runtime.c`
- [Runtime ABI](https://github.com/tap-lang/tap/blob/main/runtime/include/tap_runtime.h): `runtime/include/tap_runtime.h`
- [Standard prelude](https://github.com/tap-lang/tap/blob/main/std/prelude.tp): `std/prelude.tp`
- [Math library](https://github.com/tap-lang/tap/blob/main/std/math.tp): `std/math.tp`
- [Standard modules](https://github.com/tap-lang/tap/tree/main/std): `std`

### Other components

- **Program author**
- **Tap source**
- **LLVM**
- **IR, object, executable**
- **Compiled Tap program**

## Connections

- Program author → Tap source: writes (evidence: `README.md`)
- Tap source → CLI driver: submits (evidence: `README.md`)
- CLI driver → Lexer: creates lexer (evidence: `src/main.c`)
- Lexer → Parser: provides tokens (evidence: `src/parser.c`)
- CLI driver → Parser: creates parser (evidence: `src/main.c`)
- Parser → AST model: builds AST (evidence: `src/parser.c`)
- CLI driver → Module loader: loads imports (evidence: `src/main.c`)
- CLI driver → Prelude loader: loads prelude (evidence: `src/main.c`)
- CLI driver → Enum lowering: lowers enums (evidence: `src/main.c`)
- CLI driver → Generic specialization: specializes generics (evidence: `src/main.c`)
- CLI driver → LLVM codegen: generates code (evidence: `src/main.c`)
- LLVM codegen → LLVM: builds LLVM IR (evidence: `README.md`)
- CLI driver → Native and lli runner: selects execution (evidence: `src/main.c`)
- Native and lli runner → IR, object, executable: writes or runs
- LLVM codegen → IR, object, executable: emits IR or object
- IR, object, executable → Compiled Tap program: executes (evidence: `README.md`)
- C runtime → Runtime ABI: implements ABI (evidence: `runtime/src/runtime.c`)
- Standard prelude → Runtime ABI: uses runtime functions
- Math library → Standard modules: is imported as (evidence: `README.md`)
- Standard modules → Tap source: imported by (evidence: `README.md`)
- Standard prelude → Tap source: loaded automatically (evidence: `README.md`)
- Compiled Tap program → C runtime: uses runtime services
