# ashinn/chibi-scheme architecture

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

- Interactive diagram: https://gitdiagram.com/ashinn/chibi-scheme
- Repository: https://github.com/ashinn/chibi-scheme

## Overview

##### Main Components

a. Core Runtime Components:
- VM Engine (vm.c)
- Memory Management (gc.c, gc_heap.c)
- Evaluator (eval.c)
- S-Expression Handler (sexp.c)

b. Language Implementation Layers:
- R7RS Small Base Implementation
- Standard Library Modules (lib/scheme/*)
- SRFI Implementations (lib/srfi/*)
- Extension Modules (lib/chibi/*)

c. Foreign Function Interface:
- FFI System
- Native Bindings
- Stub Generators

d. Build & Integration Systems:
- Build System (CMake support)
- Package Management (Snow)
- Testing Framework

##### Component Relationships

**[Core Runtime Layer]**

- [VM Engine] ←→ [Memory Management]
- ↑
- [Evaluator] ←→ [S-Expression Handler]
- ↑

**[Language Implementation Layer]**
- ↑
- [R7RS Base] ←→ [Standard Library]
- ↑
- [SRFI Modules] ←→ [Extension Modules]
- ↑
**[Integration Layer]**
- ↑
- [FFI System] ←→ [Native Bindings]
- ↑
- [Build System] ←→ [Package Manager]

##### Important Design Elements to Highlight

a. Isolation Features:
- VM-based threads
- Isolated heaps per VM
- Multi-threading support

b. Language Features:
- Full numeric tower
- Unicode support
- Hygienic macros
- Module system

c. Integration Points:
- C program embedding
- FFI system
- Platform-specific adaptations

##### Cross-cutting Concerns

- Memory Management
- Thread Safety
- Platform Compatibility
- Error Handling

##### Implementation Details

**[VM Engine]**
- Thread Management
- Instruction Set
- State Management

**[Memory Management]**
- Garbage Collection
- Heap Isolation
- Resource Tracking

**[Language Features]**
- Numeric Tower
- Unicode Support
- Macro System
- Module System

##### External Interfaces

- C API for embedding
- Command-line REPL
- Package management interface
- Build system integration

##### Integration interfaces

This design captures both the minimal nature of the implementation while showing its extensibility and robustness for use as an embedded language system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#ffcccc,stroke:#ff0000
    classDef lang fill:#cce5ff,stroke:#0066cc
    classDef integration fill:#d9f2d9,stroke:#006600
    classDef testing fill:#fff2cc,stroke:#ffcc00

    %% Core Runtime Layer
    subgraph CoreRuntime
        VM["VM Engine"]
        MM["Memory Management"]
        EV["Evaluator"]
        SE["S-Expression Handler"]
        
        VM <--> MM
        EV <--> SE
        VM --> EV
    end

    %% Language Implementation Layer
    subgraph LangImpl
        R7RS["R7RS Base"]
        StdLib["Standard Library"]
        SRFI["SRFI Modules"]
        Ext["Extension Modules"]
        
        R7RS <--> StdLib
        SRFI <--> Ext
        R7RS --> SRFI
    end

    %% Integration Layer
    subgraph Integration
        FFI["FFI System"]
        Native["Native Bindings"]
        Build["Build System"]
        Pack["Package Manager"]
        REPL["REPL"]
        
        FFI <--> Native
        Build <--> Pack
        FFI --> Build
        REPL --> FFI
    end

    %% Testing Layer
    subgraph Testing
        Test["Testing Framework"]
    end

    %% Cross-layer Relationships
    CoreRuntime --> LangImpl
    LangImpl --> Integration
    Integration --> Testing

    %% Component Classifications
    class VM,MM,EV,SE core
    class R7RS,StdLib,SRFI,Ext lang
    class FFI,Native,Build,Pack,REPL integration
    class Test testing

    %% Click Events
    click VM "https://github.com/ashinn/chibi-scheme/blob/master/vm.c"
    click MM "https://github.com/ashinn/chibi-scheme/blob/master/gc.c"
    click EV "https://github.com/ashinn/chibi-scheme/blob/master/eval.c"
    click SE "https://github.com/ashinn/chibi-scheme/blob/master/sexp.c"
    click R7RS "https://github.com/ashinn/chibi-scheme/blob/master/lib/scheme/base.sld"
    click StdLib "https://github.com/ashinn/chibi-scheme/tree/master/lib/scheme"
    click SRFI "https://github.com/ashinn/chibi-scheme/tree/master/lib/srfi"
    click Ext "https://github.com/ashinn/chibi-scheme/tree/master/lib/chibi"
    click FFI "https://github.com/ashinn/chibi-scheme/tree/master/tools/chibi-ffi"
    click Pack "https://github.com/ashinn/chibi-scheme/tree/master/lib/chibi/snow"
    click Build "https://github.com/ashinn/chibi-scheme/blob/master/CMakeLists.txt"
    click Test "https://github.com/ashinn/chibi-scheme/blob/master/lib/chibi/test.sld"
    click REPL "https://github.com/ashinn/chibi-scheme/blob/master/lib/chibi/repl.sld"
```
