# nim-lang/nimony architecture

> Architecture diagram of the GitHub repository nim-lang/nimony, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nim-lang/nimony
- Repository: https://github.com/nim-lang/nimony

## Overview

##### Main Components Identification

a) Core Compiler Components (src/nimony/):
- Semantic Analysis (sem*.nim files)
- Type System (typeprops.nim, builtintypes.nim)
- Symbol Management (symtabs.nim)
- Expression Evaluation (expreval.nim)
- Dependencies Handler (deps.nim)

b) Supporting Tools:
- NIFC (Native Interface Compiler) (src/nifc/)
- Gear2/3 (Code Generation Tools) (src/gear2/, src/gear3/)
- NIFLER (Configuration Tool) (src/nifler/)
- XELIM (Transformation Tool) (src/xelim/)

**Top Level:**
**[Source Code] -> [Nimony Compiler] -> [Compiled Output]**

**Detailed Level:**
**[Source Code] -> [Parser] -> [Semantic Analyzer] -> [Type Checker] ->**
**[Code Generator] -> [Native Code]**

##### Component Relationships

a) Frontend Pipeline:
- How source code flows through semantic analysis (sem.nim)
- Type checking process (typeprops.nim, builtintypes.nim)
- Symbol table interactions (symtabs.nim)

b) Backend Pipeline:
- Code generation flow through NIFC
- How Gear2/3 interfaces with the compilation process
- AMD64 code generation path (src/nifc/amd64/)

##### Detailed Components

Frontend:
**[Source Files] -> [Parser]**
- ↓
**[Symbol Tables] <- [Semantic Analyzer]**
- ↓
**[Type Checker] <- [Generic Instantiation]**

Backend:
**[NIFC] -> [Intermediate Representation]**
- ↓
**[AMD64 Generator] -> [Native Code]**

##### Additional Elements

Subsystems for:
- Library management (src/lib/)
- Test infrastructure (tests/)
- Build configuration (config.nims)

This architecture should reflect the project's focus on creating a minimal but feature-rich Nim dialect with emphasis on incremental compilation and flexible module dependencies.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    subgraph Frontend
        Source[Source Code]:::input
        Parser[Parser]:::frontend
        SemAnalyzer[Semantic Analyzer]:::frontend
        TypeChecker[Type Checker]:::frontend
        SymbolTables[Symbol Tables]:::frontend
    end

    subgraph Core
        ExprEval[Expression Evaluator]:::core
        DepsHandler[Dependencies Handler]:::core
        GenericInst[Generic Instantiation]:::core
    end

    subgraph Backend
        NIFC[NIFC]:::backend
        IR[Intermediate Representation]:::backend
        AMD64[AMD64 Generator]:::backend
        NativeCode[Native Code]:::output
    end

    subgraph "Supporting Tools"
        Gear2[Gear2]:::tool
        Gear3[Gear3]:::tool
        NIFLER[NIFLER]:::tool
        XELIM[XELIM]:::tool
    end

    subgraph "Core Libraries"
        GenericTrees[Generic Trees]:::lib
        PackedTrees[Packed Trees]:::lib
        NifStreams[NIF Streams]:::lib
    end

    %% Relationships
    Source --> Parser
    Parser --> SemAnalyzer
    SemAnalyzer <--> SymbolTables
    SemAnalyzer --> TypeChecker
    TypeChecker --> GenericInst
    
    ExprEval --> SemAnalyzer
    DepsHandler --> SemAnalyzer
    
    GenericInst --> NIFC
    NIFC --> IR
    IR --> AMD64
    AMD64 --> NativeCode
    
    Gear2 --> NIFC
    Gear3 --> NIFC
    NIFLER --> NIFC
    XELIM --> SemAnalyzer

    %% Click Events
    click SemAnalyzer "https://github.com/nim-lang/nimony/blob/master/src/nimony/sem.nim"
    click TypeChecker "https://github.com/nim-lang/nimony/blob/master/src/nimony/typeprops.nim"
    click SymbolTables "https://github.com/nim-lang/nimony/blob/master/src/nimony/symtabs.nim"
    click ExprEval "https://github.com/nim-lang/nimony/blob/master/src/nimony/expreval.nim"
    click DepsHandler "https://github.com/nim-lang/nimony/blob/master/src/nimony/deps.nim"
    click NIFC "https://github.com/nim-lang/nimony/blob/master/src/nifc/nifc.nim"
    click Gear2 "https://github.com/nim-lang/nimony/blob/master/src/gear2/gear2.nim"
    click Gear3 "https://github.com/nim-lang/nimony/blob/master/src/gear3/gear3.nim"
    click NIFLER "https://github.com/nim-lang/nimony/blob/master/src/nifler/nifler.nim"
    click XELIM "https://github.com/nim-lang/nimony/blob/master/src/xelim/xelim.nim"
    click GenericTrees "https://github.com/nim-lang/nimony/blob/master/src/lib/generictrees.nim"
    click PackedTrees "https://github.com/nim-lang/nimony/blob/master/src/lib/packedtrees.nim"
    click NifStreams "https://github.com/nim-lang/nimony/blob/master/src/lib/nifstreams.nim"
    click AMD64 "https://github.com/nim-lang/nimony/tree/master/src/nifc/amd64"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#e74c3c,stroke:#c0392b,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef tool fill:#f1c40f,stroke:#f39c12,color:black
    classDef lib fill:#9b59b6,stroke:#8e44ad,color:white
    classDef input fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef output fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend_L[Frontend]:::frontend
        Core_L[Core]:::core
        Backend_L[Backend]:::backend
        Tool_L[Tools]:::tool
        Lib_L[Libraries]:::lib
        IO_L[Input/Output]:::input
    end
```
