# robotii/lito architecture

> Architecture diagram of the GitHub repository robotii/lito, 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/robotii/lito
- Repository: https://github.com/robotii/lito

## Overview

##### Main Components

a. Frontend Components:
- Lexer (/compiler/lexer)
- Parser (/compiler/parser)
- AST (Abstract Syntax Tree) (/compiler/ast)

b. Middle-end Components:
- Bytecode Generator (/compiler/bytecode)
- Compiler Core (/compiler)

c. Backend/Runtime Components:
- Virtual Machine (/vm)
- Standard Library (/lib)
- REPL (Read-Eval-Print Loop) (/repl)

##### Component Relationships and Data Flow

**Source Code → Lexer → Parser → AST → Bytecode Generator → VM → Program Output**

##### Detailed Component Breakdown

For each major component, include these elements:

a. Lexer Section:
- Token definitions (/compiler/token)
- Lexical analysis process

b. Parser Section:
- Expression parsing
- Statement parsing
- Error handling
- Precedence rules
- State management

c. Bytecode Generation:
- Instruction set
- Expression generation
- Statement generation
- Local variable management

d. Virtual Machine:
- Object system (various object types in /vm)
- Class system
- Method dispatch
- Runtime environment
- Built-in types (Array, Hash, String, etc.)
- Concurrency features (Thread, Channel, WaitGroup)

##### Implementation Details

Technical aspects:
- FSM (Finite State Machine) integration (/fsm)
- Test infrastructure (/tests, /specs)
- Example code processing flow
- Standard library loading mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SRC[Source Code]
    end

    subgraph Frontend
        LEX[Lexer]:::frontend
        PAR[Parser]:::frontend
        AST[AST]:::frontend
        TOK[Token Definitions]:::frontend
        ERR_F[Error Handling]:::frontend
    end

    subgraph "Middle-end"
        BCG[Bytecode Generator]:::middleend
        COMP[Compiler Core]:::middleend
    end

    subgraph "Backend/Runtime"
        VM[Virtual Machine]:::backend
        
        subgraph "Object System"
            OBJ[Object System]:::object
            CLS[Class System]:::object
            MTHD[Method Dispatch]:::object
        end
        
        subgraph "Runtime Features"
            ENV[Runtime Environment]:::runtime
            
            subgraph "Built-in Types"
                ARR[Array]:::types
                HSH[Hash]:::types
                STR[String]:::types
            end
            
            subgraph "Concurrency"
                THR[Thread]:::concurrency
                CHN[Channel]:::concurrency
                WG[WaitGroup]:::concurrency
            end
        end
    end

    subgraph "Supporting Systems"
        FSM[FSM]:::support
        REPL[REPL]:::support
        STD[Standard Library]:::support
        TEST[Test Infrastructure]:::support
        ERR_B[Error Handling]:::support
    end

    %% Flow
    SRC --> LEX
    LEX --> PAR
    PAR --> AST
    AST --> BCG
    BCG --> COMP
    COMP --> VM
    
    %% Dependencies
    LEX -.-> TOK
    PAR -.-> ERR_F
    VM -.-> ERR_B
    VM -.-> OBJ
    OBJ -.-> CLS
    CLS -.-> MTHD
    VM -.-> ENV
    ENV -.-> ARR & HSH & STR
    ENV -.-> THR & CHN & WG
    REPL -.-> LEX
    VM -.-> STD
    
    %% Styling
    classDef frontend fill:#a8d1f0
    classDef middleend fill:#90EE90
    classDef backend fill:#ffb366
    classDef object fill:#FFE4B5
    classDef runtime fill:#F0E68C
    classDef types fill:#DDA0DD
    classDef concurrency fill:#98FB98
    classDef support fill:#D3D3D3

    %% Click events
    click LEX "https://github.com/robotii/lito/blob/main//compiler/lexer/lexer.go"
    click PAR "https://github.com/robotii/lito/blob/main//compiler/parser/parser.go"
    click AST "https://github.com/robotii/lito/tree/main//compiler/ast/"
    click TOK "https://github.com/robotii/lito/blob/main//compiler/token/token.go"
    click BCG "https://github.com/robotii/lito/blob/main//compiler/bytecode/generator.go"
    click COMP "https://github.com/robotii/lito/blob/main//compiler/compiler.go"
    click VM "https://github.com/robotii/lito/blob/main//vm/vm.go"
    click STD "https://github.com/robotii/lito/blob/main//lib/spec.lito"
    click REPL "https://github.com/robotii/lito/blob/main//repl/repl.go"
    click FSM "https://github.com/robotii/lito/blob/main//fsm/fsm.go"
    click THR "https://github.com/robotii/lito/blob/main//vm/thread.go"
    click CHN "https://github.com/robotii/lito/blob/main//vm/channel.go"
    click OBJ "https://github.com/robotii/lito/blob/main//vm/object.go"
    click CLS "https://github.com/robotii/lito/blob/main//vm/class.go"
    click ERR_F "https://github.com/robotii/lito/blob/main//compiler/parser/errors/errors.go"
    click ERR_B "https://github.com/robotii/lito/blob/main//vm/errors/error.go"
    click TEST "https://github.com/robotii/lito/tree/main//tests/"
    click MTHD "https://github.com/robotii/lito/blob/main//vm/method_object.go"
    click ENV "https://github.com/robotii/lito/blob/main//vm/environment.go"
    click ARR "https://github.com/robotii/lito/blob/main//vm/array.go"
    click HSH "https://github.com/robotii/lito/blob/main//vm/hash.go"
    click STR "https://github.com/robotii/lito/blob/main//vm/string.go"
    click WG "https://github.com/robotii/lito/blob/main//vm/waitgroup.go"
```
