# abap34/mu architecture

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

- Interactive diagram: https://gitdiagram.com/abap34/mu
- Repository: https://github.com/abap34/mu

## Overview

##### Main components
- Parser Module: The source code under the src/parse directory (files such as ast.jl, builder.jl, parse.jl, rules.jl) is responsible for converting raw code into an abstract syntax tree.
- Lowering/IR Module: Under src/lowering, the files (ir.jl and lowering.jl) indicate the transformation of the parsed AST into an intermediate representation, a key step in many language implementations.
- Interpreter Module: The components in src/interpreter (interpreter.jl, methodtable.jl, nativeinterpreter.jl) implement code execution. This module would take the IR and drive runtime behavior.
- Type Inference and Analysis: The src/typeinf directory, including abstractsemantics.jl, solver.jl, and typeinf.jl files, encapsulates type analysis using abstract interpretation methods to optimize dispatch.
- Builtin Functions and Base Definitions: Directories like src/builtin and src/base provide core language functionality, built-in functions, and basic behaviors (as seen in builtin.jl, impl.jl, tfuncs.jl, etc.).
- Type System Management: Files under src/types (such as conversion.jl, definition.jl, signature.jl, types.jl) manage type definitions and conversions.
- Examples and Tests: The example and test directories are essential for demonstrating usage and ensuring that each component works correctly. Tests also give insight into typical interactions between modules.

##### Relationships and interactions
- The Parser takes input code (e.g., from .mu files) and produces an abstract syntax tree.
- The Lowering module transforms the AST into an intermediate representation (IR) that is easier for subsequent stages to handle.
- The Type Inference component analyzes the IR, ensures type correctness, and optimizes function dispatch via multiple dispatch. It should be shown as interfacing closely with both the parsed representation and the interpreter.
- The Interpreter executes the final, processed IR. A feedback loop (or dependency) might exist between type inference and interpretation, ensuring that operations are executed with known types.
- Builtin and Base modules provide essential functionalities (like base functions, native operations) that are used throughout the parsing, lowering, and interpretation stages.
- The overall architecture is modular, where each component (parsing, lowering, type inference, interpretation) interacts in a pipeline fashion to implement the language execution environment.

##### Architectural Patterns and Design Principles
- Modularity is key – each directory in src represents an isolated concern (e.g., parsing vs. lowering vs. interpretation).
- Pipeline/Layered Architecture – the processing flows from parsing to IR lowering, then type analysis, and finally interpretation.
- Multiple Dispatch & Generic Programming – this is central to mu's functionality and should be noted as it influences how functions are optimized and selected at runtime.
- Abstract Interpretation – indicating dynamic analysis and optimization of dispatch performance.

##### Relevant Technologies, Frameworks, or Libraries
- Julia is the underlying implementation language, with the project configured via Manifest.toml and Project.toml for dependency management.
- GitHub Actions (as seen in the .github/workflows directory) for continuous integration.
- Testing frameworks are implied by test files that exercise each architectural component.

##### Overall Detailed Steps for the Principal Software Engineer
- Parser to the Lowering module, which outputs an IR.
- Type Inference module analyzing the IR and feeding optimizations or type information to the Interpreter.
- Type System management component to indicate handling of type definitions and conversions.
- Finally, include auxiliary components such as CI/CD from GitHub workflows and testing suites to highlight how the system is validated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Pipeline Nodes
    A["Source Code (.mu files)"]:::source
    B["Parser Module"]:::parser
    C["Lowering/IR Module"]:::lowering
    D["Type Inference and Analysis"]:::typeInf
    E["Interpreter Module"]:::interpreter

    %% Core Language Libraries Subgraph
    subgraph "Core Language Libraries"
        F["Builtin Functions"]:::builtin
        G["Base Definitions"]:::builtin
        H["Type System Management"]:::types
    end

    %% Validation Subgraph
    subgraph "Validation"
        I["Examples"]:::validation
        J["Tests"]:::validation
    end

    %% CI/CD Node
    K["GitHub Actions (CI/CD)"]:::ci

    %% Pipeline Flow
    A -->|"parses"| B
    B -->|"lowersToIR"| C
    C -->|"analyzes"| D
    D -->|"executes"| E

    %% Core Libraries dependencies
    F -->|"supports"| B
    F -->|"supports"| C
    F -->|"supports"| E
    G -->|"providesCore"| B
    G -->|"providesCore"| E
    H -->|"feedsTypeData"| D

    %% Validation connections
    E -->|"validatedBy"| I
    E -->|"validatedBy"| J

    %% CI/CD integration
    K -->|"triggers"| J
    K -->|"triggers"| I

    %% Class Definitions for Colouring
    classDef source fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef parser fill:#a8e6cf,stroke:#333,stroke-width:2px;
    classDef lowering fill:#ffd3b6,stroke:#333,stroke-width:2px;
    classDef typeInf fill:#ffaaa5,stroke:#333,stroke-width:2px;
    classDef interpreter fill:#dcedc1,stroke:#333,stroke-width:2px;
    classDef builtin fill:#f3e5ab,stroke:#333,stroke-width:2px;
    classDef types fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef validation fill:#fff9c4,stroke:#333,stroke-width:2px;
    classDef ci fill:#b3e5fc,stroke:#333,stroke-width:2px;

    %% Click Events
    click B "https://github.com/abap34/mu/tree/main/src/parse"
    click C "https://github.com/abap34/mu/tree/main/src/lowering"
    click D "https://github.com/abap34/mu/tree/main/src/typeinf"
    click E "https://github.com/abap34/mu/tree/main/src/interpreter"
    click F "https://github.com/abap34/mu/tree/main/src/builtin"
    click G "https://github.com/abap34/mu/tree/main/src/base"
    click H "https://github.com/abap34/mu/tree/main/src/types"
    click I "https://github.com/abap34/mu/tree/main/example"
    click J "https://github.com/abap34/mu/tree/main/test"
    click K "https://github.com/abap34/mu/tree/main/.github/workflows"
```
