# toteload/gamma architecture

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

- Interactive diagram: https://gitdiagram.com/toteload/gamma
- Repository: https://github.com/toteload/gamma

## Overview

##### Component Relationships

a. Data Flow Direction:
Source Code → Tokens → AST → Annotated AST → LLVM IR

- String Interner (src/string_interner.rs)
- Type Interner (src/type_interner.rs)
- Scope Stack (src/scope_stack.rs)
- Error Handling (src/error.rs)

##### Detailed Component Breakdown

- Break/Continue Validation
- Main Function Validation
- Symbol Usage Validation

- Type Annotation
- Type Node Annotation
- Type Checking
- Type Coercion

##### Visitor Pattern Implementation
- Visitor
- VisitorMut
- VisitorWithContext
- VisitorMutWithContext

##### Testing Infrastructure
A separate section showing:
- Snapshot Testing System
- Sample Programs
- Test Generation

Key Considerations:

##### A small note about the project's scope
- Single-file compilation
- No module system
- Goal-oriented feature set (Tetris with SDL2)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        direction TB
        L1[Frontend Component]:::frontend
        L2[Middle-end Component]:::middleend
        L3[Backend Component]:::backend
        L4[Support System]:::support
        L5[Testing Component]:::testing
    end

    subgraph Frontend["Frontend (Source Processing)"]
        direction TB
        Tokenizer["Tokenizer"]:::frontend
        Parser["Parser"]:::frontend
        AST["AST Generation"]:::frontend
        
        Tokenizer --> Parser
        Parser --> AST
    end

    subgraph MiddleEnd["Middle-end (Analysis & Transformation)"]
        direction TB
        subgraph SemanticAnalysis["Semantic Analysis"]
            direction TB
            BreakContinue["Break/Continue Validation"]:::middleend
            MainFunction["Main Function Validation"]:::middleend
            SymbolUsage["Symbol Usage Validation"]:::middleend
        end

        subgraph TypeSystem["Type System"]
            direction TB
            TypeAnnotation["Type Annotation"]:::middleend
            TypeNodeAnnotation["Type Node Annotation"]:::middleend
            TypeChecking["Type Checking"]:::middleend
            TypeCoercion["Type Coercion"]:::middleend
            TypesDef["Types Definition"]:::middleend
        end

        ASTTransform["AST Transformation"]:::middleend
    end

    subgraph Backend["Backend (Code Generation)"]
        direction TB
        LLVMGen["LLVM IR Generation"]:::backend
    end

    subgraph Support["Support Systems"]
        direction TB
        StringInterner["String Interner"]:::support
        TypeInterner["Type Interner"]:::support
        ScopeStack["Scope Stack"]:::support
        ErrorHandling["Error Handling"]:::support
    end

    subgraph Visitors["Visitor Pattern"]
        direction TB
        Visitor["Visitor"]:::support
        VisitorMut["VisitorMut"]:::support
        VisitorWithContext["VisitorWithContext"]:::support
        VisitorMutWithContext["VisitorMutWithContext"]:::support
    end

    subgraph Testing["Testing Infrastructure"]
        direction TB
        SnapshotTests["Snapshot Tests"]:::testing
        SamplePrograms["Sample Programs"]:::testing
    end

    Frontend --> SemanticAnalysis
    Frontend --> TypeSystem
    SemanticAnalysis --> ASTTransform
    TypeSystem --> ASTTransform
    ASTTransform --> LLVMGen

    %% Component Mappings
    click Tokenizer "https://github.com/toteload/gamma/blob/main/src/tokenizer.rs"
    click Parser "https://github.com/toteload/gamma/blob/main/src/parser.rs"
    click AST "https://github.com/toteload/gamma/blob/main/src/ast.rs"
    click TypeChecking "https://github.com/toteload/gamma/blob/main/src/type_checking.rs"
    click TypeCoercion "https://github.com/toteload/gamma/blob/main/src/type_coercion.rs"
    click ASTTransform "https://github.com/toteload/gamma/blob/main/src/ast_transform.rs"
    click LLVMGen "https://github.com/toteload/gamma/blob/main/src/ink_codegen.rs"
    click StringInterner "https://github.com/toteload/gamma/blob/main/src/string_interner.rs"
    click TypeInterner "https://github.com/toteload/gamma/blob/main/src/type_interner.rs"
    click ScopeStack "https://github.com/toteload/gamma/blob/main/src/scope_stack.rs"
    click ErrorHandling "https://github.com/toteload/gamma/blob/main/src/error.rs"
    click Visitor "https://github.com/toteload/gamma/blob/main/src/visitor.rs"
    click VisitorMut "https://github.com/toteload/gamma/blob/main/src/visitor_mut.rs"
    click VisitorWithContext "https://github.com/toteload/gamma/blob/main/src/visitor_with_context.rs"
    click VisitorMutWithContext "https://github.com/toteload/gamma/blob/main/src/visitor_mut_with_context.rs"
    click BreakContinue "https://github.com/toteload/gamma/blob/main/src/semantics/break_and_continue_in_loop.rs"
    click MainFunction "https://github.com/toteload/gamma/blob/main/src/semantics/has_main.rs"
    click SymbolUsage "https://github.com/toteload/gamma/blob/main/src/semantics/validate_symbol_use.rs"
    click TypeAnnotation "https://github.com/toteload/gamma/blob/main/src/type_annotation.rs"
    click TypeNodeAnnotation "https://github.com/toteload/gamma/blob/main/src/type_node_annotation.rs"
    click TypesDef "https://github.com/toteload/gamma/blob/main/src/types.rs"
    click SnapshotTests "https://github.com/toteload/gamma/tree/main/tests/snapshots"
    click SamplePrograms "https://github.com/toteload/gamma/tree/main/tests/valid_samples"

    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef middleend fill:#FFC107,stroke:#FFA000,color:black
    classDef backend fill:#4CAF50,stroke:#388E3C,color:white
    classDef support fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef testing fill:#FF5722,stroke:#E64A19,color:white
```
