# mightypancake/axo architecture

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

- Interactive diagram: https://gitdiagram.com/mightypancake/axo
- Repository: https://github.com/mightypancake/axo

## Overview

##### Project type and purpose
- This is a domain-specific programming language compiler (“Axo”) that reads `.axo` source files, parses and type-checks them, and emits readable C (and optionally WebAssembly) code. It also bundles a standard library of modules (core, math, io, std, raylib bindings, etc.) and embeds a full Lua interpreter for scripting or extension.

##### File structure
- Top-level build & CI:
- `.github/workflows/*` – CI pipelines for Linux, macOS, Windows
- `makefile`, `shell.nix` – build scripts and reproducible dev environment
- Parser front-end:
- `lex.yy.c`, `scan.l` – Flex scanner
- `axo_gram.tab.c`, `axo_gram.y` – Bison grammar
- Compiler driver & core:
- `src/axo.c`, `src/axo.h`, `src/axo_err.h` – main CLI driver, error handling
- `src/utils/*` – general utilities (hashmaps, string, memory)
- Language runtime & backends:
- `src/wasm.c` / `src/wasm.h` – WebAssembly code generation
- Embedded Lua runtime under `src/lua/src/*` compiled into a static lib
- Standard library modules:
- `modules/*/*.axo` (core, map, dict, math, io, raylib, etc.)
- Some modules include C code (`hashmap.c`), headers, or Lua scripts
- Examples & Tests:
- `examples/` and `tests/` – sample `.axo` programs, resources (audio, models)

##### README for insights
- Emphasizes compiler’s goal: modern C-like syntax → C output, no semicolons, no OOP
- Early-stage, leak-heavy code but focused on performance

##### Main components & relationships
a. Components:
1. CLI Front-End (axo executable)
2. Scanner (Flex) & Parser (Bison)
3. AST & Semantic Analyzer
4. Code Generators:
– C Backend
– WebAssembly Backend
5. Standard Library Loader (modules/…)
6. Embedded Lua Runtime
7. External C Compiler (gcc/clang)
b. Data flow & interactions:
– User invokes `axo` with `.axo` file → CLI reads file → Scanner → Parser → AST
– Semantic Analyzer resolves symbols, types, module imports
– Module Loader pulls in `.axo` modules and C/Lua components
– Code Generators emit C source (and/or WASM)
– CLI invokes external C compiler → final binary or library
c. Architectural patterns / principles:
– Classic compiler pipeline (lex → parse → analyze → codegen)
– Modular design for std library (each module self-contained)
– Backends pluggable (C vs WASM)
– Embedding of external interpreter (Lua) as a subcomponent
d. Key technologies / libraries:
– Flex / Bison for parsing
– Standard C99 for generated code
– Lua 5.x core compiled in
– Optional Raylib bindings for multimedia demos
– GNU Make, Nix for reproducible builds
– GitHub Actions for CI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Input
    FS(["File System (.axo Files)"]):::external
    FS -->|".axo text"| Scanner

    subgraph "Front-End Phases"
        Scanner["Flex Scanner"]:::frontend
        Parser["Bison Parser"]:::frontend
        AST["AST & Semantic Analyzer"]:::frontend
    end

    FS -->|".axo modules"| Loader
    Loader["Standard Library Loader"]:::lib
    Loader -->|"modules AST"| AST

    Scanner -->|"tokens"| Parser
    Parser -->|"AST"| AST

    AST -->|"typed AST"| CGen
    AST -->|"typed AST"| WASM

    subgraph "Back-Ends"
        CGen["C Code Generator"]:::backend
        WASM["WASM Code Generator"]:::backend
    end

    CGen -->|"C source"| CC
    WASM -->|"WASM binary"| CC

    subgraph "Linking & Output"
        CC["External C Compiler"]:::external
        BIN["Final Binary / Library"]:::external
    end

    CC -->|"executable"| BIN

    %% Libraries
    Lua["Embedded Lua Runtime"]:::lib
    AST -->|"link Lua API"| Lua
    CGen -->|"link Lua lib"| Lua

    %% Examples & Tests
    EX["Examples & Tests"]:::external
    EX -->|"sample .axo"| FS

    %% Click Events
    click Scanner "https://github.com/mightypancake/axo/blob/main/scan.l"
    click Parser "https://github.com/mightypancake/axo/blob/main/axo_gram.y"
    click Loader "https://github.com/mightypancake/axo/tree/main/modules/"
    click CGen "https://github.com/mightypancake/axo/blob/main/src/axo.c"
    click WASM "https://github.com/mightypancake/axo/blob/main/src/wasm.c"
    click Lua "https://github.com/mightypancake/axo/tree/main/src/lua/"
    click FS "https://github.com/mightypancake/axo/tree/main/examples/"
    click CC "https://github.com/mightypancake/axo/tree/main/makefile"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef backend fill:#D5F5E3,stroke:#196F3D,stroke-width:1px
    classDef lib fill:#EBEDEF,stroke:#616A6B,stroke-width:1px
    classDef external fill:#FAD7A0,stroke:#7D6608,stroke-width:1px
```
