# phreda4/r3 architecture

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

## Overview

##### Core Language Components
- R3 Virtual Machine (central component)
- Compiler/Parser System
- Memory Management System (64-bit cells with 8,16,32-bit access)
- Dynamic Library Interface

##### Development Environment
- Code Editor/Browser
- File System Interface
- SDL2 Integration Layer
- Platform-specific Components (Windows/Linux)

##### Main Layers (top to bottom)

a. User Interface Layer
- Editor/Browser Interface
- Code Visualization
- File Navigation System

b. Language Processing Layer
- Parser (r3parse.r3)
- Compiler Passes (r3pass1.r3 through r3pass4.r3)
- Code Generation (r3gencod.r3, r3gendat.r3)

c. Execution Layer
- Virtual Machine (r3vm.r3)
- Memory Manager
- Stack System (r3stack.r3)

d. Platform Integration Layer
- SDL2 Bindings
- Dynamic Library Loading
- OS-specific APIs (Win/Linux)

##### Connection Types
- Double lines: Data flow paths

##### Component Grouping

a. Core System:
- [Parser] → [Compiler] → [Code Generator] → [Virtual Machine]
- ↓
- [Memory Manager]

b. Development Tools:
- [Editor] ← [File Browser] → [Code Viewer]
- ↓
- [Compiler Interface]

c. Runtime System:
- [VM Runtime] → [Library Loader]
- ↓
- [Platform APIs] → [Graphics/Sound/Input]

##### Additional Elements

- Version information and platform support indicators
- File extension associations (.r3 files)
- Build/compilation flow

##### Implementation Details

- Use standardized UML notation where applicable
- Clear labels for all components
- Brief descriptions for key interfaces
- Error handling paths

Remember to include bidirectional relationships where appropriate, especially between the development environment and the core language components, as they interact during both development and runtime phases.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#b3d9ff,stroke:#333
    classDef dev fill:#90EE90,stroke:#333
    classDef external fill:#FFD700,stroke:#333
    classDef platform fill:#FFA500,stroke:#333
    classDef lib fill:#DDA0DD,stroke:#333

    %% User Interface Layer
    subgraph UI
        Editor["Code Editor/Browser"]
        FileNav["File Navigation"]
        CodeVis["Code Visualization"]
    end

    %% Language Processing Layer
    subgraph Processing
        Parser["Parser"]
        CompilerSystem["Compiler System"]
        CodeGen["Code Generation"]
    end

    %% Execution Layer
    subgraph Execution
        VM["R3 Virtual Machine"]
        MemMgr["Memory Manager"]
        Stack["Stack System"]
    end

    %% Platform Integration Layer
    subgraph Platform
        SDL["SDL2 Integration"]
        DynLib["Dynamic Library Interface"]
        subgraph OS
            Win["Windows APIs"]
            Linux["Linux/POSIX APIs"]
        end
    end

    %% Relationships
    Editor --> Parser
    FileNav --> Editor
    CodeVis --> Editor
    
    Parser --> CompilerSystem
    CompilerSystem --> CodeGen
    CodeGen --> VM
    
    VM --> MemMgr
    VM --> Stack
    VM --> DynLib
    
    DynLib --> SDL
    DynLib --> Win
    DynLib --> Linux
    
    %% Component Classes
    class VM,Parser,CompilerSystem,CodeGen,Stack,MemMgr core
    class Editor,FileNav,CodeVis dev
    class DynLib external
    class Win,Linux platform
    class SDL lib

    %% Click Events
    click VM "https://github.com/phreda4/r3/blob/main/r3/system/r3vm.r3"
    click Parser "https://github.com/phreda4/r3/blob/main/r3/system/r3parse.r3"
    click CompilerSystem "https://github.com/phreda4/r3/blob/main/r3/system/r3pass1.r3"
    click CodeGen "https://github.com/phreda4/r3/blob/main/r3/system/r3gencod.r3"
    click MemMgr "https://github.com/phreda4/r3/blob/main/r3/lib/mem.r3"
    click Editor "https://github.com/phreda4/r3/blob/main/r3/editor/code-edit.r3"
    click SDL "https://github.com/phreda4/r3/blob/main/r3/lib/sdl2.r3"
    click Stack "https://github.com/phreda4/r3/blob/main/r3/system/r3stack.r3"
    click Win "https://github.com/phreda4/r3/tree/main/r3/lib/win"
    click Linux "https://github.com/phreda4/r3/tree/main/r3/lib/posix"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Development Tools"]:::dev
        L3["External Interfaces"]:::external
        L4["Platform-specific"]:::platform
        L5["Library Bindings"]:::lib
    end
```
