# svfoxat/turbo-lang architecture

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

- Interactive diagram: https://gitdiagram.com/svfoxat/turbo-lang
- Repository: https://github.com/svfoxat/turbo-lang

## Overview

##### Main Components

a) Input Processing Layer:
- REPL (Interactive Shell)
- Source Code Input

b) Core Pipeline Components:
- Lexer (Token Generation)
- Parser (AST Construction)
- Interpreter (Evaluation)

c) Supporting Components:
- AST (Abstract Syntax Tree)
- Object System
- Environment

##### Component Relationships

**[Source Code Input] ──────┐**
**[REPL Input] ────────────┤**
- ↓
**[Lexer] → [Token Stream] → [Parser] → [AST] → [Interpreter] → [Evaluated Result]**
- ↑          ↑
- [AST Nodes]  [Object System]
- ↑
- [Environment]

##### Detailed Component Descriptions

- REPL: Interactive command-line interface (repl/repl.go)
- Lexer: Converts source code into tokens (lexer/lexer.go)
- Parser: Builds AST from tokens (parser/parser.go)
- Interpreter: Evaluates AST and executes code (interpreter/eval.go)
- Object System: Manages runtime objects and types (object/object.go)
- Environment: Handles variable scoping and bindings (object/environment.go)

##### Implementation Details

Notes about specific implementation files:
- Built-in Functions: interpreter/builtins.go
- Control Flow: interpreter/control_flow.go
- Type-specific Handling: interpreter/boolean.go, numbers.go, string.go

##### Testing Coverage

A separate section showing test coverage:
- Lexer Tests (lexer_test.go)
- Parser Tests (parser_test.go)
- AST Tests (ast_test.go)
- Interpreter Tests (eval_test.go)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SRC[Source Code Input]:::input
        REPL[REPL]:::input
        click REPL "https://github.com/svfoxat/turbo-lang/blob/master/repl/repl.go"
        MAIN[Main Entry]:::input
        click MAIN "https://github.com/svfoxat/turbo-lang/blob/master/main.go"
    end

    subgraph "Core Pipeline"
        LEX[Lexer]:::core
        click LEX "https://github.com/svfoxat/turbo-lang/blob/master/lexer/lexer.go"
        TOK[Token Handler]:::core
        click TOK "https://github.com/svfoxat/turbo-lang/blob/master/token/token.go"
        PAR[Parser]:::core
        click PAR "https://github.com/svfoxat/turbo-lang/blob/master/parser/parser.go"
        AST[AST]:::core
        click AST "https://github.com/svfoxat/turbo-lang/blob/master/ast/ast.go"
        INT[Interpreter]:::core
        click INT "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/eval.go"
    end

    subgraph "Support Systems"
        OBJ[Object System]:::support
        click OBJ "https://github.com/svfoxat/turbo-lang/blob/master/object/object.go"
        ENV[Environment]:::support
        click ENV "https://github.com/svfoxat/turbo-lang/blob/master/object/environment.go"
        
        subgraph "Type Handlers"
            BOOL[Boolean Handler]:::handler
            click BOOL "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/boolean.go"
            NUM[Number Handler]:::handler
            click NUM "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/numbers.go"
            STR[String Handler]:::handler
            click STR "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/string.go"
        end
        
        BF[Built-in Functions]:::support
        click BF "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/builtins.go"
        CF[Control Flow]:::support
        click CF "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/control_flow.go"
    end

    subgraph "Test Suite"
        LT[Lexer Tests]:::test
        click LT "https://github.com/svfoxat/turbo-lang/blob/master/lexer/lexer_test.go"
        PT[Parser Tests]:::test
        click PT "https://github.com/svfoxat/turbo-lang/blob/master/parser/parser_test.go"
        AT[AST Tests]:::test
        click AT "https://github.com/svfoxat/turbo-lang/blob/master/ast/ast_test.go"
        IT[Interpreter Tests]:::test
        click IT "https://github.com/svfoxat/turbo-lang/blob/master/interpreter/eval_test.go"
    end

    SRC --> LEX
    REPL --> LEX
    MAIN --> REPL
    LEX --> TOK
    TOK --> PAR
    PAR --> AST
    AST --> INT
    
    OBJ --> INT
    ENV --> INT
    BOOL --> INT
    NUM --> INT
    STR --> INT
    BF --> INT
    CF --> INT
    
    LT -.-> LEX
    PT -.-> PAR
    AT -.-> AST
    IT -.-> INT

    classDef input fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef support fill:#FFB347,stroke:#333,stroke-width:2px
    classDef handler fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef test fill:#E6E6FA,stroke:#333,stroke-width:2px

    subgraph Legend
        L1[Input Components]:::input
        L2[Core Components]:::core
        L3[Support Systems]:::support
        L4[Type Handlers]:::handler
        L5[Test Components]:::test
    end
```
