# didrikmunther/rost architecture

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

## Overview

##### Project Type Analysis
This is a compiler project with multiple backends (Python, WebAssembly) and includes an LSP server implementation. The project consists of several major components:
- Core compiler (rost directory)
- Language Server Protocol implementation (rost_lsp)
- Web demo interface (demo directory)
- VSCode extension (lsp-client)
- WebAssembly integration (rost_wasm)

##### Main Components

A. Source Code Processing Pipeline:
**[Source Code] -> [Lexer] -> [Parser] -> [IR] -> [Backend Generators]**

B. Backend Systems:
**[IR] -> [Python Backend]**
- > [WebAssembly Backend]
- > [NASM Backend] (in development)

C. Development Tools:
**[LSP Server] <-> [VSCode Extension]**
**[Web Demo Interface] <-> [WebAssembly Backend]**

**Top Layer: Source Code Input**
**Middle Layer: Processing Pipeline**
**Bottom Layer: Output Generation**

##### Component Details

a) Lexer Section:
- Token generation
- Error handling
- System components (keywords, identifiers, literals)

b) Parser Section:
- AST generation
- Type checking
- Scope management
- Error reporting

c) IR (Intermediate Representation):
- Program structure
- Symbol table
- Type system
- Debug information

d) Backends:
- Stack machine implementation (Python)
- WebAssembly generation
- Native code generation (NASM)

##### Integration Points

Clear connections between:
- LSP server and compiler components
- Web demo and WebAssembly backend
- IR and each backend implementation
- Error handling system across components

##### Additional Elements

- Built-in functions
- Type system
- Generic support
- Error handling
- Debug information flow

- Blue: Core compiler components
- Green: Active backends
- Yellow: In-development features
- Purple: Development tools
- Red: Error handling system

**→ : Data flow**
**⟷ : Bidirectional communication**
- > : Optional/future path

##### Notes Section

Notes indicating:
- Current implementation status
- Future development paths
- Integration points
- Performance considerations

Remember to include version information and mark features as implemented/planned according to the roadmap in the README.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Core Components]:::core
        L2[Active Backends]:::active
        L3[In Development]:::indev
        L4[Development Tools]:::devtools
        L5[Error Handling]:::error
    end

    subgraph "Source Input"
        SRC[Source Code]
    end

    subgraph "Core Compiler"
        LEX[Lexer]:::core
        PAR[Parser]:::core
        IR[Intermediate Representation]:::core
        TS[Type System]:::core
        ST[Symbol Table]:::core
        EH[Error Handler]:::error
        PB[Program Builder]:::core
        EXP[Expression Handler]:::core
    end

    subgraph "Backend Systems"
        PY[Python Backend]:::active
        WASM[WebAssembly Backend]:::active
        NASM[NASM Backend]:::indev
        
        subgraph "Code Generators"
            PYG[Python Generator]:::active
            WASMG[WASM Generator]:::active
            NASMG[NASM Generator]:::indev
        end
    end

    subgraph "Development Tools"
        LSP[LSP Server]:::devtools
        VSC[VSCode Extension]:::devtools
        DEMO[Web Demo Interface]:::devtools
    end

    %% Core Flow
    SRC --> LEX
    LEX --> PAR
    PAR --> IR
    IR --> PB
    PB --> EXP
    IR --> TS
    IR --> ST

    %% Backend Connections
    IR --> PY
    IR --> WASM
    IR --> NASM
    PY --> PYG
    WASM --> WASMG
    NASM --> NASMG

    %% Error Handling
    EH -.-> LEX
    EH -.-> PAR
    EH -.-> IR

    %% Development Tools
    LSP <--> VSC
    DEMO <--> WASM

    %% Click Events
    click LEX "https://github.com/didrikmunther/rost/tree/develop/rost/src/lexer/"
    click PAR "https://github.com/didrikmunther/rost/tree/develop/rost/src/parser/"
    click IR "https://github.com/didrikmunther/rost/blob/develop/rost/src/compiler/program/ir.rs"
    click PY "https://github.com/didrikmunther/rost/tree/develop/rost/src/backend/python/"
    click WASM "https://github.com/didrikmunther/rost/tree/develop/rost/src/backend/wasm/"
    click NASM "https://github.com/didrikmunther/rost/tree/develop/rost/src/nasm/"
    click LSP "https://github.com/didrikmunther/rost/tree/develop/rost_lsp/"
    click VSC "https://github.com/didrikmunther/rost/tree/develop/lsp-client/"
    click DEMO "https://github.com/didrikmunther/rost/tree/develop/demo/"
    click TS "https://github.com/didrikmunther/rost/blob/develop/rost/src/compiler/program/typ.rs"
    click ST "https://github.com/didrikmunther/rost/blob/develop/rost/src/compiler/program/scope.rs"
    click EH "https://github.com/didrikmunther/rost/blob/develop/rost/src/error/mod.rs"
    click PYG "https://github.com/didrikmunther/rost/blob/develop/rost/src/backend/python/generator.rs"
    click WASMG "https://github.com/didrikmunther/rost/blob/develop/rost/src/backend/wasm/generator.rs"
    click NASMG "https://github.com/didrikmunther/rost/blob/develop/rost/src/nasm/generator.rs"
    click PB "https://github.com/didrikmunther/rost/blob/develop/rost/src/compiler/program/builder.rs"
    click EXP "https://github.com/didrikmunther/rost/tree/develop/rost/src/compiler/program/expression/"

    classDef core fill:#a8d1f0,stroke:#333
    classDef active fill:#90EE90,stroke:#333
    classDef indev fill:#FFE5B4,stroke:#333
    classDef devtools fill:#DDA0DD,stroke:#333
    classDef error fill:#FFB6C1,stroke:#333
```
