# arnodel/golua architecture

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

## Overview

##### Main Components

a) Compilation Pipeline:
- Scanner/Lexer (scanner package)
- Parser (parsing package)
- AST (ast package)
- IR Compiler (astcomp package)
- Bytecode Compiler (ircomp package)

b) Runtime System:
- Runtime Environment (runtime package)
- Thread Management
- Value System
- Garbage Collection (runtime/internal/luagc)

c) Standard Library Implementation:
- Core Libraries (lib directory)
- Go Integration (golib package)

**[Source Code] -> [Compilation Pipeline] -> [Runtime System] -> [Program Execution]**

**Where:**

**Compilation Pipeline:**

- Lexer/Scanner  | --> |  Parser  | --> |   AST   | --> | IR Compiler| --> | Code Builder|

**Runtime System:**

- Runtime Environment|

- Thread Management | <-> | Value System   | <-> | Standard Libs |

- Garbage Collection|

##### Important Relationships

a) Compilation Flow:
- Transformation from source code through various compilation stages
- Intermediate representations (AST → IR → Bytecode)

b) Runtime Integration:
- How the runtime interacts with compiled code
- Thread management and coroutine support
- Garbage collection integration

c) Library System:
- How standard libraries connect to the runtime
- Go integration points
- Safety/quota system integration

##### Implementation Details to Note

- No third-party dependencies
- Complete Lua 5.4 implementation
- Safe execution environment support
- Go package import capability
- Standard library implementation status

## Diagram (Mermaid)

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

    subgraph CompilationPipeline["Compilation Pipeline"]
        LEX["Scanner/Lexer"]:::compiler
        PAR["Parser"]:::compiler
        AST["AST"]:::compiler
        IRC["IR Compiler"]:::compiler
        BYC["Bytecode Compiler"]:::compiler

        LEX --> PAR
        PAR --> AST
        AST --> IRC
        IRC --> BYC
    end

    subgraph RuntimeSystem["Runtime System"]
        direction TB
        RE["Runtime Environment"]:::runtime
        
        subgraph ThreadAndValue["Thread & Value Management"]
            TM["Thread Management"]:::runtime
            VS["Value System"]:::runtime
            TM <--> VS
        end
        
        subgraph GC["Memory Management"]
            GCM["Garbage Collection"]:::runtime
        end
        
        subgraph Libraries["Standard Libraries"]
            direction TB
            BL["Base Library"]:::lib
            ML["Math Library"]:::lib
            SL["String Library"]:::lib
            TL["Table Library"]:::lib
            IL["IO Library"]:::lib
            OL["OS Library"]:::lib
            DL["Debug Library"]:::lib
            PL["Package Library"]:::lib
            CL["Coroutine Library"]:::lib
        end
        
        subgraph GoInt["Go Integration"]
            GI["Go Library"]:::golib
        end
        
        subgraph Safety["Safety System"]
            SQ["Safety Quotas"]:::safety
        end
    end

    SRC --> LEX
    BYC --> RE
    RE --> ThreadAndValue
    RE --> GC
    RE --> Libraries
    RE --> GoInt
    SQ -.- RE

    classDef compiler fill:#2374f7,stroke:#fff,stroke-width:2px,color:#fff
    classDef runtime fill:#47d147,stroke:#fff,stroke-width:2px,color:#fff
    classDef lib fill:#ffd700,stroke:#fff,stroke-width:2px,color:#000
    classDef golib fill:#ff6b6b,stroke:#fff,stroke-width:2px,color:#fff
    classDef safety fill:#808080,stroke:#fff,stroke-width:2px,color:#fff

    click LEX "https://github.com/arnodel/golua/blob/lua5.4/scanner/scanner.go"
    click PAR "https://github.com/arnodel/golua/blob/lua5.4/parsing/parser.go"
    click AST "https://github.com/arnodel/golua/tree/lua5.4/ast/"
    click IRC "https://github.com/arnodel/golua/blob/lua5.4/astcomp/astcomp.go"
    click BYC "https://github.com/arnodel/golua/blob/lua5.4/ircomp/ircomp.go"
    click RE "https://github.com/arnodel/golua/blob/lua5.4/runtime/runtime.go"
    click TM "https://github.com/arnodel/golua/blob/lua5.4/runtime/thread.go"
    click VS "https://github.com/arnodel/golua/blob/lua5.4/runtime/value.go"
    click GCM "https://github.com/arnodel/golua/tree/lua5.4/runtime/internal/luagc/"
    click BL "https://github.com/arnodel/golua/tree/lua5.4/lib/base/"
    click ML "https://github.com/arnodel/golua/tree/lua5.4/lib/mathlib/"
    click SL "https://github.com/arnodel/golua/tree/lua5.4/lib/stringlib/"
    click TL "https://github.com/arnodel/golua/tree/lua5.4/lib/tablelib/"
    click IL "https://github.com/arnodel/golua/tree/lua5.4/lib/iolib/"
    click OL "https://github.com/arnodel/golua/tree/lua5.4/lib/oslib/"
    click DL "https://github.com/arnodel/golua/tree/lua5.4/lib/debuglib/"
    click PL "https://github.com/arnodel/golua/tree/lua5.4/lib/packagelib/"
    click CL "https://github.com/arnodel/golua/tree/lua5.4/lib/coroutine/"
    click GI "https://github.com/arnodel/golua/blob/lua5.4/lib/golib/golib.go"
    click SQ "https://github.com/arnodel/golua/blob/lua5.4/runtime/quotas.yaml"
```
