# yuriy-chumak/ol architecture

> Architecture diagram of the GitHub repository yuriy-chumak/ol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuriy-chumak/ol
- Repository: https://github.com/yuriy-chumak/ol

## Overview

##### Main Components Identification

a) Core Components:
- Virtual Machine (src/olvm.c)
- Compiler (lang/*.scm)
- REPL Environment
- FFI (Foreign Function Interface)

b) Library System:
- Scheme Core Libraries
- Owl Legacy Libraries
- External Native Library Bindings
- Platform-specific Implementations

**┌─────────────────────────────────────────────┐**
- Applications                 │
- (REPL, Scripts, Embedded Usage)            │
- ┤
- Standard Libraries             │
- ┌─────────┐ ┌─────────┐ ┌───────────────┐ │
- Scheme  │ │  Owl    │ │ External Libs  │ │
- (R7RS)  │ │ Legacy  │ │ (OpenGL, etc.) │ │
- ┘ └─────────┘ └───────────────┘ │
- ┤
- Language Core                   │
- ┌─────────┐ ┌─────────┐ ┌───────────────┐ │
- Compiler │ │  FFI    │ │ VM Extensions  │ │
- ┘ └─────────┘ └───────────────┘ │
- ┤
- Virtual Machine                 │
- ┌─────────────────────────────────────────┐│
- OLVM Core                  ││
- ┘│
- ┘

##### Data Flow Indicators

- Compilation flow (source → bytecode)
- Execution flow (bytecode → VM)
- FFI interactions
- Library dependencies

##### Key Features to Highlight

- Pure functional nature
- R7RS Scheme compatibility
- Cross-platform support
- Embedding capabilities
- FFI system
- Binary script compilation

##### Implementation Details

Notes about:
- Memory management
- Bytecode format
- Library loading mechanism
- Platform-specific adaptations

##### External Interfaces

Connections to:
- Native libraries
- Operating system
- External applications
- Embedded environments

##### The layered architecture that allows for
- Pure functional programming
- Cross-platform compatibility
- Embedding capabilities

##### The separation between
- Core VM implementation
- Language features
- Standard libraries
- External interfaces

##### The flow of
- Source code compilation
- Bytecode execution
- FFI calls
- Library loading

This design reflects Ol's nature as a small, embeddable, and purely functional Lisp implementation while showing its extensive capabilities through libraries and FFI.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        REPL["REPL Environment"]
        Scripts["Scripts"]
        Embedded["Embedded Usage"]
    end

    subgraph "Standard Libraries Layer"
        SchemeLib["Scheme Core (R7RS)"]:::stdlib
        OwlLib["Owl Legacy"]:::stdlib
        ExtLib["External Libraries"]:::stdlib
        
        subgraph "Platform Specific"
            OpenGL["OpenGL Bindings"]:::platform
            Android["Android Support"]:::platform
            Windows["Windows Support"]:::platform
        end
    end

    subgraph "Language Core Layer"
        subgraph "Compiler System"
            Compiler["Compiler Core"]:::compiler
            AST["AST Processing"]:::compiler
            CPS["CPS Transformation"]:::compiler
            Macros["Macro System"]:::compiler
            RegAlloc["Register Allocation"]:::compiler
            Assembly["Assembly"]:::compiler
        end

        subgraph "FFI System"
            FFICore["FFI Core"]:::ffi
            FFILib["FFI Library"]:::ffi
        end

        VMExt["VM Extensions"]:::vm
    end

    subgraph "Virtual Machine Layer"
        OLVM["OLVM Core"]:::vm
        VMUtils["VM Utilities"]:::vm
    end

    %% Relationships
    REPL --> Compiler
    Scripts --> Compiler
    Embedded --> OLVM

    Compiler --> OLVM
    AST --> CPS
    CPS --> RegAlloc
    RegAlloc --> Assembly
    Assembly --> OLVM
    Macros --> Compiler

    FFICore --> OLVM
    FFILib --> FFICore

    SchemeLib --> Compiler
    OwlLib --> Compiler
    ExtLib --> FFICore

    OpenGL --> ExtLib
    Android --> ExtLib
    Windows --> ExtLib

    VMExt --> OLVM
    VMUtils --> OLVM

    %% Click Events
    click OLVM "https://github.com/yuriy-chumak/OL/blob/master/src/olvm.c"
    click VMUtils "https://github.com/yuriy-chumak/OL/blob/master/src/vm.scm"
    click Compiler "https://github.com/yuriy-chumak/OL/tree/master/lang/"
    click AST "https://github.com/yuriy-chumak/OL/blob/master/lang/ast.scm"
    click CPS "https://github.com/yuriy-chumak/OL/blob/master/lang/cps.scm"
    click Macros "https://github.com/yuriy-chumak/OL/blob/master/lang/macro.scm"
    click RegAlloc "https://github.com/yuriy-chumak/OL/blob/master/lang/register.scm"
    click Assembly "https://github.com/yuriy-chumak/OL/blob/master/lang/assemble.scm"
    click FFICore "https://github.com/yuriy-chumak/OL/blob/master/extensions/ffi.c"
    click FFILib "https://github.com/yuriy-chumak/OL/tree/master/libraries/otus/ffi/"
    click SchemeLib "https://github.com/yuriy-chumak/OL/tree/master/libraries/scheme/"
    click OwlLib "https://github.com/yuriy-chumak/OL/tree/master/libraries/owl/"
    click ExtLib "https://github.com/yuriy-chumak/OL/tree/master/libraries/lib/"
    click OpenGL "https://github.com/yuriy-chumak/OL/tree/master/libraries/lib/gl/"
    click Android "https://github.com/yuriy-chumak/OL/tree/master/examples/android/"
    click Windows "https://github.com/yuriy-chumak/OL/tree/master/includes/win32/"

    %% Styling
    classDef vm fill:#a8d1f0
    classDef compiler fill:#90EE90
    classDef ffi fill:#FFB6C1
    classDef stdlib fill:#FFE4B5
    classDef platform fill:#DDA0DD

    %% Legend
    subgraph Legend
        VM["Virtual Machine"]:::vm
        Comp["Compiler Components"]:::compiler
        FFI["FFI Components"]:::ffi
        Std["Standard Libraries"]:::stdlib
        Plat["Platform Specific"]:::platform
    end
```
