# moarvm/moarvm architecture

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

## Overview

##### Main Components

a) Core Runtime Components:
- Virtual Machine Core (src/core/)
- Memory Management System (src/gc/)
- Just-In-Time Compiler (src/jit/)
- Specialized Optimizer (src/spesh/)
- Input/Output System (src/io/)

b) Object System Components:
- 6model Implementation (src/6model/)
- Representation System (src/6model/reprs/)
- Object Types and Containers

c) Language Support:
- Unicode Processing (src/strings/)
- Mathematical Operations (src/math/)
- Native Call Interface
- Bytecode Interpreter

**┌─────────────────────────────────────────────────────┐**
- Language Runtime                    │
- (NQP/Rakudo/Other Compilers using NQP toolchain)    │
- ┤
- MoarVM Interface                    │
- ┤
- High-Level Runtime Services               │
- ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────┐  │
- 6model   │ │  Spesh   │ │   JIT    │ │  I/O  │  │
- ┘ └──────────┘ └──────────┘ └───────┘  │
- ┤
- Core Runtime Services                  │
- ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────┐  │
- GC     │ │Interpreter│ │ Threading│ │ Debug │  │
- ┘ └──────────┘ └──────────┘ └───────┘  │
- ┤
- Platform Abstraction Layer              │
- ┘

##### Important Details

a) Runtime Features:
- Generational GC
- JIT compilation paths
- Specialization optimizer
- Bytecode interpreter

b) Integration Points:
- Native call interface
- Debugging interface
- I/O subsystem
- Threading model

c) Special Annotations:
- Parallel GC capabilities
- JIT compilation paths
- Specialization feedback loops
- Cross-platform abstractions

##### Optimization Flow

**Bytecode → Spesh Analysis → JIT Compilation → Optimized Code**
- ↑______________________________________________|
- (Deoptimization Path)

##### Implementation Notes

- Notes about platform-specific implementations
- Version/configuration-dependent features

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef lang fill:#90EE90,stroke:#333
    classDef opt fill:#FFB366,stroke:#333
    classDef io fill:#DDA0DD,stroke:#333
    classDef platform fill:#E6E6E6,stroke:#333

    %% Language Runtime Layer
    subgraph LangRuntime["Language Runtime Layer"]
        NQP["NQP/Rakudo"]
        OtherComp["Other NQP-based Compilers"]
    end

    %% MoarVM Interface Layer
    subgraph VMInterface["MoarVM Interface Layer"]
        VMCore["Virtual Machine Core"]:::core
        NativeCall["Native Call Interface"]:::core
    end

    %% High-Level Runtime Services
    subgraph HighLevel["High-Level Runtime Services"]
        Model6["6model System"]:::core
        Spesh["Specialized Optimizer"]:::opt
        JIT["JIT Compiler"]:::opt
        IO["I/O System"]:::io
        Unicode["Unicode Processing"]:::lang
        Math["Mathematical Operations"]:::lang
        Repr["Representation System"]:::core
        ObjCont["Object Containers"]:::core
    end

    %% Core Runtime Services
    subgraph CoreServices["Core Runtime Services"]
        GC["Memory Management/GC"]:::core
        Interp["Bytecode Interpreter"]:::core
        Thread["Threading System"]:::core
        Debug["Debugging Interface"]:::core
    end

    %% Platform Layer
    subgraph PlatformLayer["Platform Abstraction Layer"]
        Platform["Platform-Specific Implementations"]:::platform
    end

    %% Relationships
    LangRuntime --> VMInterface
    VMInterface --> HighLevel
    HighLevel --> CoreServices
    CoreServices --> PlatformLayer

    %% Optimization Pipeline
    Interp --> Spesh
    Spesh --> JIT
    JIT -.-> Interp

    %% Component Interactions
    Model6 <--> Repr
    Model6 <--> ObjCont
    GC --> Thread
    VMCore --> NativeCall
    IO --> Platform
    
    %% Legend
    subgraph Legend
        CoreComp["Core Components"]:::core
        LangComp["Language Support"]:::lang
        OptComp["Optimization"]:::opt
        IOComp["I/O Components"]:::io
        PlatComp["Platform-Specific"]:::platform
    end

    %% Click events for component mapping
    click VMCore "https://github.com/MoarVM/MoarVM/tree/main/src/core/"
    click GC "https://github.com/MoarVM/MoarVM/tree/main/src/gc/"
    click JIT "https://github.com/MoarVM/MoarVM/tree/main/src/jit/"
    click Spesh "https://github.com/MoarVM/MoarVM/tree/main/src/spesh/"
    click IO "https://github.com/MoarVM/MoarVM/tree/main/src/io/"
    click Model6 "https://github.com/MoarVM/MoarVM/tree/main/src/6model/"
    click Repr "https://github.com/MoarVM/MoarVM/tree/main/src/6model/reprs/"
    click ObjCont "https://github.com/MoarVM/MoarVM/blob/main/src/6model/containers.c"
    click Unicode "https://github.com/MoarVM/MoarVM/tree/main/src/strings/"
    click Math "https://github.com/MoarVM/MoarVM/tree/main/src/math/"
    click NativeCall "https://github.com/MoarVM/MoarVM/blob/main/src/core/nativecall.c"
    click Interp "https://github.com/MoarVM/MoarVM/blob/main/src/core/bytecode.c"
    click Platform "https://github.com/MoarVM/MoarVM/tree/main/src/platform/"
    click Debug "https://github.com/MoarVM/MoarVM/tree/main/src/debug/"
    click Thread "https://github.com/MoarVM/MoarVM/blob/main/src/core/threads.c"
```
