# aquice/dim architecture

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

- Interactive diagram: https://gitdiagram.com/aquice/dim
- Repository: https://github.com/aquice/dim

## Overview

##### Project type and purpose
- This is a language implementation ("DIM Programming Language") written in C++. It provides a complete pipeline from reading source code through lexing, parsing, casting (type processing), and finally interpreting/running code.

##### File structure
- Top-level:
- CMakeLists.txt (build config)
- main.dim (sample program)
- master.py (helper/script for running tests or bootstrapping)
- README.md (language spec)
- / and src/ mirror each other and contain four submodules:
- lexer (lexical analysis)
- parser (AST & casting)
- runner/interpreter (execution engine with register and value abstractions)
- utils (shared helpers)
- src/main.cxx ties everything together as the CLI driver.

##### Insights from the README
- Describes language features (data types, operators, control flow).
- No functions yet—everything lives in a global scope.
- Emphasizes that every statement produces a value (important for interpreter design).

##### Main components and their relationships
a. Components:
1) Driver/CLI (main.cxx)
2) Lexer (lexer.cxx / lexer.hxx)
3) Parser & AST (parser.cxx / ast.hxx)
4) Caster/Semantic Pass (cast.cxx / cast.hxx)
5) Interpreter (interprets AST nodes)
- Register module (register.cxx / register.hxx)
- Value module (value.cxx / value.hxx)
6) Utilities (utils.cxx / utils.hxx)
7) Build System (CMake)
8) Runner script (master.py)
9) Sample program (main.dim)

b. Interactions & data flow:
- CLI reads `main.dim` →
- passes source text to Lexer →
- token stream to Parser →
- AST to Caster →
- typed AST to Interpreter →
- Interpreter uses Register & Value modules to evaluate →
- results/output to console.
- Utils are called by lexer/parser/interpreter for shared tasks (e.g., error reporting, I/O).

c. Architectural patterns/design principles:
- Pipeline pattern (lex → parse → semantic → eval)
- Separation of concerns (each stage in its own directory)
- Header/source mirroring for clear API boundaries
- Single-responsibility modules (lexer only lexes, parser only builds AST, etc.)

d. Key technologies/frameworks:
- C++17 (or newer)
- CMake as build/config tool
- Python (master.py) for test harness or bootstrapping
- Custom AST data structures in parser/ast.hxx

##### Detail
- Every module as its own component—even small utility modules—to capture the full architecture.
- How the CMakeLists.txt orchestrates building of all submodules.
- That every stage depends on the previous one’s output type.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Inputs
    MasterPy["master.py"]:::external
    SampleProgram["main.dim"]:::external

    %% Driver
    CLI["Driver/CLI\n(src/main.cxx)"]:::frontend

    %% Pipeline stages
    Lexer["Lexer\n(include/lexer/lexer.hxx\nsrc/lexer/lexer.cxx)"]:::frontend
    Parser["Parser & AST\n(include/parser/parser.hxx\ninclude/parser/ast.hxx\nsrc/parser/parser.cxx\nsrc/parser/ast.cxx)"]:::frontend
    Caster["Caster/Semantic Pass\n(include/parser/cast.hxx\nsrc/parser/cast.cxx)"]:::frontend

    subgraph "Interpreter Stage"
        direction TB
        InterpreterCore["Interpreter\n(include/runner/interpreter/interpreter.hxx\nsrc/runner/interpreter/interpreter.cxx)"]:::backend
        RegisterMod["Register Module\n(include/runner/interpreter/register.hxx\nsrc/runner/interpreter/register.cxx)"]:::backend
        ValueMod["Value Module\n(include/runner/interpreter/value.hxx\nsrc/runner/interpreter/value.cxx)"]:::backend
        InterpreterCore --> RegisterMod
        InterpreterCore --> ValueMod
    end

    Utils["Utilities\n(include/utils/utils.hxx\nsrc/utils/utils.cxx)"]:::utils
    CMake["CMake Build System\n(CMakeLists.txt)"]:::utils

    %% Data Flow
    MasterPy -->|"runs"| CLI
    SampleProgram -->|"input source"| CLI
    CLI -->|"source text"| Lexer
    Lexer -->|"tokens"| Parser
    Parser -->|"AST"| Caster
    Caster -->|"typed AST"| InterpreterCore
    InterpreterCore -->|"results"| CLI
    Utils -.-> Lexer
    Utils -.-> Parser
    Utils -.-> InterpreterCore
    CMake -.-> CLI

    %% Click Events
    click CLI "https://github.com/aquice/dim/blob/main/src/main.cxx"
    click Lexer "https://github.com/aquice/dim/blob/main/include/lexer/lexer.hxx"
    click Lexer "https://github.com/aquice/dim/blob/main/src/lexer/lexer.cxx"
    click Parser "https://github.com/aquice/dim/blob/main/include/parser/parser.hxx"
    click Parser "https://github.com/aquice/dim/blob/main/src/parser/parser.cxx"
    click Parser "https://github.com/aquice/dim/blob/main/include/parser/ast.hxx"
    click Parser "https://github.com/aquice/dim/blob/main/src/parser/ast.cxx"
    click Caster "https://github.com/aquice/dim/blob/main/include/parser/cast.hxx"
    click Caster "https://github.com/aquice/dim/blob/main/src/parser/cast.cxx"
    click InterpreterCore "https://github.com/aquice/dim/blob/main/include/runner/interpreter/interpreter.hxx"
    click InterpreterCore "https://github.com/aquice/dim/blob/main/src/runner/interpreter/interpreter.cxx"
    click RegisterMod "https://github.com/aquice/dim/blob/main/include/runner/interpreter/register.hxx"
    click RegisterMod "https://github.com/aquice/dim/blob/main/src/runner/interpreter/register.cxx"
    click ValueMod "https://github.com/aquice/dim/blob/main/include/runner/interpreter/value.hxx"
    click ValueMod "https://github.com/aquice/dim/blob/main/src/runner/interpreter/value.cxx"
    click Utils "https://github.com/aquice/dim/blob/main/include/utils/utils.hxx"
    click Utils "https://github.com/aquice/dim/blob/main/src/utils/utils.cxx"
    click CMake "https://github.com/aquice/dim/blob/main/CMakeLists.txt"
    click MasterPy "https://github.com/aquice/dim/blob/main/master.py"
    click SampleProgram "https://github.com/aquice/dim/blob/main/main.dim"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,color:#1B4F72;
    classDef backend fill:#ABEBC6,stroke:#239B56,color:#145A32;
    classDef utils fill:#F2F3F4,stroke:#7B7D7D,color:#212F3D;
    classDef external fill:#F9E79F,stroke:#B7950B,color:#7D6608;
```
