# dplassgit/smallest architecture

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

- Interactive diagram: https://gitdiagram.com/dplassgit/smallest
- Repository: https://github.com/dplassgit/smallest

## Overview

#### Purpose and Deliverables
Smallest is a self-hosted compiler for SPL, a deliberately minimal language with 32-bit integers and integer arrays. The repository contains both a Scala implementation used to compile SPL and SPL/assembly artifacts representing the bootstrap and self-hosted compiler stages. Primary artifacts are source programs in `samples/`, generated/handwritten assembly in `src/`, and the Scala compiler implementation in `scala/src/main/scala/`.

#### Compiler Entrypoints
The Scala compiler’s executable entry point is `scala/src/main/scala/Smallestc.scala`. It drives the front end and likely emits the target assembly format consumed by the project runtime/toolchain. Shell wrappers provide operational entry points:
- `scripts/compile`
- `scripts/run`
- `scripts/bootc`

`scala/build.sbt` defines the Scala build, while `scala/README.md` is the local usage reference for this compiler implementation.

#### Front-End: Lexing and Tokens
Source text is converted into the compact single-character-keyword language token stream by:
- `scala/src/main/scala/Lexer.scala`
- `scala/src/main/scala/Token.scala`

This boundary enforces SPL’s lexical restrictions: alphabetic identifiers, integer/character literals, operators, comments, and punctuation-based control/function constructs. Tokens are the interface between raw SPL input and syntax analysis.

#### Parsing and Language Structure
`scala/src/main/scala/Parser.scala` transforms tokens into the compiler’s syntax representation and establishes SPL control flow and expression semantics: assignments, array allocation/indexing, function declarations/calls, conditionals, loops, return, input/output, and termination. It is the semantic shape boundary before symbol resolution and code generation.

Representative inputs exercising this stage are under `samples/`, including:
- `samples/fact.spl`
- `samples/arrayassign.spl`
- `samples/proccall.spl`

#### Symbol and Type-Conventions Layer
`scala/src/main/scala/SymTab.scala` manages identifiers and compiler-visible scope/state. SPL relies on naming conventions rather than explicit type declarations: names beginning with `a` denote arrays, and function names distinguish void/array/int returns by prefix. This component is therefore central to resolving globals, locals, parameters, functions, and storage/code-generation decisions.

#### Bootstrap and Self-Hosting Chain
The repository preserves compiler evolution as SPL and assembly artifacts:
- `src/bootstrap.spl`
- `src/bootstrap.asm`
- `src/selfhosted.asm`

`bootstrap.spl` is SPL source for an early compiler stage; `bootstrap.asm` is its target assembly output or bootstrap-ready representation; `selfhosted.asm` is the resulting self-hosted compiler artifact. `scripts/bootc` is the operational boundary for this bootstrap chain. This enables the compiler to eventually compile its own SPL implementation rather than depending solely on Scala.

#### Runtime and Execution Boundary
The project targets an assembly-level runtime/emulator workflow rather than a web or service deployment. `scripts/run` encapsulates execution of compiled artifacts, and `scripts/compile` connects SPL inputs to compiler output. No external cloud services, databases, or network APIs are indicated; material dependencies are the Scala/SBT runtime for the host compiler and the assembly execution environment implied by the scripts and `.asm` artifacts.

Main entry points: [`scala/src/main/scala/Smallestc.scala`](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Smallestc.scala) (Smallestc), [`scripts/bootc`](https://github.com/dplassgit/smallest/blob/trunk/scripts/bootc) (bootc), [`scala/src/main/scala/Lexer.scala`](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Lexer.scala) (Lexer), [`src/bootstrap.asm`](https://github.com/dplassgit/smallest/blob/trunk/src/bootstrap.asm) (Bootstrap assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Scala host compiler"]
  node_smallestc["Smallestc<br/>compiler entrypoint<br/>[Smallestc.scala]"]
  node_lexer["Lexer<br/>lexical analysis<br/>[Lexer.scala]"]
  node_token["Tokens<br/>token model<br/>[Token.scala]"]
  node_parser["Parser<br/>syntax analysis<br/>[Parser.scala]"]
  node_symtab["SymTab<br/>symbol resolution<br/>[SymTab.scala]"]
  node_scala_build["SBT build<br/>Scala build<br/>[build.sbt]"]
  node_scala_usage["Compiler usage<br/>documentation<br/>[README.md]"]
end

subgraph group_bootstrap["Bootstrap chain"]
  node_bootstrap_spl["Bootstrap compiler<br/>SPL compiler stage<br/>[bootstrap.spl]"]
  node_bootstrap_asm["Bootstrap assembly<br/>bootstrap output<br/>[bootstrap.asm]"]
  node_selfhosted_asm["Self-hosted compiler<br/>self-hosted artifact<br/>[selfhosted.asm]"]
  node_bootc_script["bootc<br/>shell wrapper"]
end

subgraph group_execution["Tooling and execution"]
  node_compile_script["compile<br/>shell wrapper"]
  node_run_script["run<br/>shell wrapper"]
  node_assembly["Assembly artifacts<br/>target assembly"]
end

node_spl_source["SPL programs<br/>source inputs"]

node_scala_build -->|"builds"| node_smallestc
node_scala_usage -.->|"documents"| node_smallestc
node_compile_script -->|"invokes"| node_smallestc
node_spl_source -->|"source text"| node_lexer
node_smallestc -->|"drives"| node_lexer
node_lexer -->|"emits"| node_token
node_token -->|"consumed by"| node_parser
node_parser -->|"resolves names"| node_symtab
node_symtab -->|"guides code generation"| node_assembly
node_smallestc -->|"emits"| node_assembly
node_compile_script -->|"produces"| node_assembly
node_run_script -->|"executes"| node_assembly
node_bootstrap_spl -->|"compiled to"| node_bootstrap_asm
node_bootstrap_asm -->|"bootstraps"| node_selfhosted_asm
node_bootc_script -->|"operates"| node_bootstrap_spl
node_bootc_script -->|"operates"| node_bootstrap_asm
node_bootc_script -->|"produces"| node_selfhosted_asm
node_selfhosted_asm -.->|"can compile SPL to"| node_assembly

click node_smallestc "https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Smallestc.scala"
click node_lexer "https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Lexer.scala"
click node_token "https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Token.scala"
click node_parser "https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Parser.scala"
click node_symtab "https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/SymTab.scala"
click node_scala_build "https://github.com/dplassgit/smallest/blob/trunk/scala/build.sbt"
click node_scala_usage "https://github.com/dplassgit/smallest/blob/trunk/scala/README.md"
click node_compile_script "https://github.com/dplassgit/smallest/blob/trunk/scripts/compile"
click node_run_script "https://github.com/dplassgit/smallest/blob/trunk/scripts/run"
click node_bootstrap_spl "https://github.com/dplassgit/smallest/blob/trunk/src/bootstrap.spl"
click node_bootstrap_asm "https://github.com/dplassgit/smallest/blob/trunk/src/bootstrap.asm"
click node_selfhosted_asm "https://github.com/dplassgit/smallest/blob/trunk/src/selfhosted.asm"
click node_bootc_script "https://github.com/dplassgit/smallest/blob/trunk/scripts/bootc"

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_smallestc,node_lexer,node_token,node_parser,node_symtab,node_scala_build,node_scala_usage toneBlue
class node_bootstrap_spl,node_bootstrap_asm,node_selfhosted_asm,node_bootc_script toneAmber
class node_compile_script,node_run_script,node_assembly toneMint
class node_spl_source toneNeutral
```

## Components

### Scala host compiler

- [Smallestc](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Smallestc.scala): compiler entrypoint · Drives the Scala SPL compilation pipeline. · `scala/src/main/scala/Smallestc.scala`
- [Lexer](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Lexer.scala): lexical analysis · `scala/src/main/scala/Lexer.scala`
- [Tokens](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Token.scala): token model · Interface between source text and parsing. · `scala/src/main/scala/Token.scala`
- [Parser](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/Parser.scala): syntax analysis · Builds SPL syntax and control-flow/expression semantics. · `scala/src/main/scala/Parser.scala`
- [SymTab](https://github.com/dplassgit/smallest/blob/trunk/scala/src/main/scala/SymTab.scala): symbol resolution · Applies SPL naming conventions for scope, storage, and return kinds. · `scala/src/main/scala/SymTab.scala`
- [SBT build](https://github.com/dplassgit/smallest/blob/trunk/scala/build.sbt): Scala build · `scala/build.sbt`
- [Compiler usage](https://github.com/dplassgit/smallest/blob/trunk/scala/README.md): documentation · `scala/README.md`

### Bootstrap chain

- [Bootstrap compiler](https://github.com/dplassgit/smallest/blob/trunk/src/bootstrap.spl): SPL compiler stage · Early compiler implementation written in SPL. · `src/bootstrap.spl`
- [Bootstrap assembly](https://github.com/dplassgit/smallest/blob/trunk/src/bootstrap.asm): bootstrap output · `src/bootstrap.asm`
- [Self-hosted compiler](https://github.com/dplassgit/smallest/blob/trunk/src/selfhosted.asm): self-hosted artifact · Assembly compiler artifact produced by the bootstrap chain. · `src/selfhosted.asm`
- [bootc](https://github.com/dplassgit/smallest/blob/trunk/scripts/bootc): shell wrapper · Operates the bootstrap and self-hosting chain. · `scripts/bootc`

### Tooling and execution

- [compile](https://github.com/dplassgit/smallest/blob/trunk/scripts/compile): shell wrapper · Connects SPL inputs to compiler output. · `scripts/compile`
- [run](https://github.com/dplassgit/smallest/blob/trunk/scripts/run): shell wrapper · Executes compiled assembly artifacts. · `scripts/run`
- **Assembly artifacts**: target assembly · Assembly consumed by the project runtime/emulator workflow.

### Other components

- **SPL programs**: source inputs · Representative SPL programs and compiler-stage source.

## Connections

- SBT build → Smallestc: builds
- Compiler usage → Smallestc: documents
- compile → Smallestc: invokes
- SPL programs → Lexer: source text
- Smallestc → Lexer: drives
- Lexer → Tokens: emits
- Tokens → Parser: consumed by
- Parser → SymTab: resolves names
- SymTab → Assembly artifacts: guides code generation
- Smallestc → Assembly artifacts: emits
- compile → Assembly artifacts: produces
- run → Assembly artifacts: executes
- Bootstrap compiler → Bootstrap assembly: compiled to
- Bootstrap assembly → Self-hosted compiler: bootstraps
- bootc → Bootstrap compiler: operates
- bootc → Bootstrap assembly: operates
- bootc → Self-hosted compiler: produces
- Self-hosted compiler → Assembly artifacts: can compile SPL to
