# anjolaolubusi/toastlang architecture

> Architecture diagram of the GitHub repository anjolaolubusi/toastlang, 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/anjolaolubusi/toastlang
- Repository: https://github.com/anjolaolubusi/toastlang

## Overview

ToastLang is a small language implementation with a command-line REPL and source-file mode. Its main workflow is source input → tokenization and parsing → AST-to-bytecode conversion → VM execution, with VM state printed to standard output. The README documents arithmetic expressions and function definitions; the sampled parser and lexer also show support for constructs such as conditionals, variables, strings, and lists. The code generator is a substantial combined module, so its converter and VM are shown as separate responsibilities sharing one source path.

Main entry points: [`src/main.rs`](https://github.com/anjolaolubusi/toastlang/blob/main/src/main.rs) (REPL and file mode), [`src/parser.rs`](https://github.com/anjolaolubusi/toastlang/blob/main/src/parser.rs) (AST parser), [`src/codegen.rs`](https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs) (Bytecode converter), [`src/lexer.rs`](https://github.com/anjolaolubusi/toastlang/blob/main/src/lexer.rs) (Token lexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["CLI interface"]
  node_cli["REPL and file mode<br/>[main.rs]"]
end

subgraph group_front["Language front end"]
  node_lexer["Token lexer<br/>[lexer.rs]"]
  node_parser["AST parser<br/>[parser.rs]"]
  node_ast["Expression AST<br/>[parser.rs]"]
end

subgraph group_runtime["Bytecode runtime"]
  node_converter["Bytecode converter<br/>[codegen.rs]"]
  node_bytecode["Bytecode program<br/>[codegen.rs]"]
  node_vm["Toast VM<br/>[codegen.rs]"]
  node_state[("VM state<br/>[codegen.rs]")]
end

node_user(("Language user"))
node_source["Toast source"]
node_stdout(("Console output"))

node_user -->|"starts"| node_cli
node_source -->|"supplies source"| node_cli
node_cli -->|"parses source"| node_parser
node_parser -->|"tokenizes with"| node_lexer
node_parser -->|"builds"| node_ast
node_cli -->|"converts AST"| node_converter
node_converter -->|"generates"| node_bytecode
node_cli -->|"executes program"| node_vm
node_vm -->|"updates"| node_state
node_cli -->|"prints VM state"| node_stdout

click node_cli "https://github.com/anjolaolubusi/toastlang/blob/main/src/main.rs"
click node_lexer "https://github.com/anjolaolubusi/toastlang/blob/main/src/lexer.rs"
click node_parser "https://github.com/anjolaolubusi/toastlang/blob/main/src/parser.rs"
click node_ast "https://github.com/anjolaolubusi/toastlang/blob/main/src/parser.rs"
click node_converter "https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs"
click node_bytecode "https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs"
click node_vm "https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs"
click node_state "https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs"

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_user toneBlue
class node_lexer,node_parser,node_ast toneAmber
class node_converter,node_bytecode,node_vm,node_state toneMint
class node_source,node_stdout toneIndigo
```

## Components

### CLI interface

- [REPL and file mode](https://github.com/anjolaolubusi/toastlang/blob/main/src/main.rs): `src/main.rs`

### Language front end

- [Token lexer](https://github.com/anjolaolubusi/toastlang/blob/main/src/lexer.rs): `src/lexer.rs`
- [AST parser](https://github.com/anjolaolubusi/toastlang/blob/main/src/parser.rs): `src/parser.rs`
- [Expression AST](https://github.com/anjolaolubusi/toastlang/blob/main/src/parser.rs): `src/parser.rs`

### Bytecode runtime

- [Bytecode converter](https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs): `src/codegen.rs`
- [Bytecode program](https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs): `src/codegen.rs`
- [Toast VM](https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs): `src/codegen.rs`
- [VM state](https://github.com/anjolaolubusi/toastlang/blob/main/src/codegen.rs): `src/codegen.rs`

### Other components

- **Language user**
- **Toast source**
- **Console output**

## Connections

- Language user → REPL and file mode: starts (evidence: `src/main.rs`)
- Toast source → REPL and file mode: supplies source (evidence: `src/main.rs`)
- REPL and file mode → AST parser: parses source (evidence: `src/main.rs`)
- AST parser → Token lexer: tokenizes with (evidence: `src/parser.rs`)
- AST parser → Expression AST: builds (evidence: `src/parser.rs`)
- REPL and file mode → Bytecode converter: converts AST (evidence: `src/main.rs`)
- Bytecode converter → Bytecode program: generates (evidence: `src/codegen.rs`)
- REPL and file mode → Toast VM: executes program (evidence: `src/main.rs`)
- Toast VM → VM state: updates (evidence: `src/codegen.rs`)
- REPL and file mode → Console output: prints VM state (evidence: `src/main.rs`)
