# wren-lang/wren architecture

> Architecture diagram of the GitHub repository wren-lang/wren, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wren-lang/wren
- Repository: https://github.com/wren-lang/wren

## Overview

Wren is an embeddable, class-based scripting language with a single-pass compiler, bytecode VM, core library, and lightweight fibers. Its principal workflow is a host embedding the C API, supplying or compiling Wren modules, and executing them in the VM. The graph also preserves value/heap management, core primitives, debugging, and optional meta/random modules. Some internal connections are based on the source index or README rather than complete source excerpts; those limits are reflected by omitting uncertain links.

Main entry points: [`src/vm/wren_vm.c`](https://github.com/wren-lang/wren/blob/main/src/vm/wren_vm.c) (VM Interpreter), [`src/include/wren.h`](https://github.com/wren-lang/wren/blob/main/src/include/wren.h) (C Embedding API), [`src/vm/wren_compiler.c`](https://github.com/wren-lang/wren/blob/main/src/vm/wren_compiler.c) (Single-Pass Compiler), [`src/vm/wren_core.c`](https://github.com/wren-lang/wren/blob/main/src/vm/wren_core.c) (Core Classes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_embedding["Embedding"]
  node_api["C Embedding API<br/>[wren.h]"]
  node_modulehost["Module Callbacks<br/>[wren.h]"]
end

subgraph group_language["Language Runtime"]
  node_compiler["Single-Pass Compiler<br/>[wren_compiler.c]"]
  node_bytecode["Bytecode Opcodes<br/>[wren_opcodes.h]"]
  node_vm["VM Interpreter<br/>[wren_vm.c]"]
  node_values["Values and Objects<br/>[wren_value.c]"]
end

subgraph group_library["Built-in Library"]
  node_core["Core Classes<br/>[wren_core.c]"]
  node_primitives["Primitive Methods<br/>[wren_primitive.c]"]
  node_metamodule["Meta Module<br/>[wren_opt_meta.c]"]
  node_randommodule["Random Module<br/>[wren_opt_random.c]"]
end

subgraph group_support["Runtime Support"]
  node_debug["Errors and Debugging<br/>[wren_debug.c]"]
  node_memory["Allocation Utilities<br/>[wren_utils.c]"]
end

node_host(("Host Application"))

node_host -->|"embeds through"| node_api
node_host -->|"provides callbacks"| node_modulehost
node_api -->|"configures and invokes"| node_vm
node_vm -->|"compiles modules"| node_compiler
node_compiler -->|"emits instructions"| node_bytecode
node_vm -->|"dispatches instructions"| node_bytecode
node_vm -->|"manages runtime values"| node_values
node_core -->|"binds primitives"| node_primitives
node_vm -.->|"initializes core"| node_core
node_vm -->|"loads modules"| node_modulehost
node_vm -->|"loads optional module"| node_metamodule
node_vm -->|"loads optional module"| node_randommodule
node_vm -.->|"reports runtime errors"| node_debug
node_vm -.->|"allocates runtime memory"| node_memory

click node_api "https://github.com/wren-lang/wren/blob/main/src/include/wren.h"
click node_modulehost "https://github.com/wren-lang/wren/blob/main/src/include/wren.h"
click node_compiler "https://github.com/wren-lang/wren/blob/main/src/vm/wren_compiler.c"
click node_bytecode "https://github.com/wren-lang/wren/blob/main/src/vm/wren_opcodes.h"
click node_vm "https://github.com/wren-lang/wren/blob/main/src/vm/wren_vm.c"
click node_values "https://github.com/wren-lang/wren/blob/main/src/vm/wren_value.c"
click node_core "https://github.com/wren-lang/wren/blob/main/src/vm/wren_core.c"
click node_primitives "https://github.com/wren-lang/wren/blob/main/src/vm/wren_primitive.c"
click node_metamodule "https://github.com/wren-lang/wren/blob/main/src/optional/wren_opt_meta.c"
click node_randommodule "https://github.com/wren-lang/wren/blob/main/src/optional/wren_opt_random.c"
click node_debug "https://github.com/wren-lang/wren/blob/main/src/vm/wren_debug.c"
click node_memory "https://github.com/wren-lang/wren/blob/main/src/vm/wren_utils.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_modulehost toneBlue
class node_compiler,node_bytecode,node_vm,node_values toneAmber
class node_core,node_primitives,node_metamodule,node_randommodule toneMint
class node_debug,node_memory toneRose
class node_host toneIndigo
```

## Components

### Embedding

- [C Embedding API](https://github.com/wren-lang/wren/blob/main/src/include/wren.h): `src/include/wren.h`
- [Module Callbacks](https://github.com/wren-lang/wren/blob/main/src/include/wren.h): `src/include/wren.h`

### Language Runtime

- [Single-Pass Compiler](https://github.com/wren-lang/wren/blob/main/src/vm/wren_compiler.c): `src/vm/wren_compiler.c`
- [Bytecode Opcodes](https://github.com/wren-lang/wren/blob/main/src/vm/wren_opcodes.h): `src/vm/wren_opcodes.h`
- [VM Interpreter](https://github.com/wren-lang/wren/blob/main/src/vm/wren_vm.c): `src/vm/wren_vm.c`
- [Values and Objects](https://github.com/wren-lang/wren/blob/main/src/vm/wren_value.c): `src/vm/wren_value.c`

### Built-in Library

- [Core Classes](https://github.com/wren-lang/wren/blob/main/src/vm/wren_core.c): `src/vm/wren_core.c`
- [Primitive Methods](https://github.com/wren-lang/wren/blob/main/src/vm/wren_primitive.c): `src/vm/wren_primitive.c`
- [Meta Module](https://github.com/wren-lang/wren/blob/main/src/optional/wren_opt_meta.c): `src/optional/wren_opt_meta.c`
- [Random Module](https://github.com/wren-lang/wren/blob/main/src/optional/wren_opt_random.c): `src/optional/wren_opt_random.c`

### Runtime Support

- [Errors and Debugging](https://github.com/wren-lang/wren/blob/main/src/vm/wren_debug.c): `src/vm/wren_debug.c`
- [Allocation Utilities](https://github.com/wren-lang/wren/blob/main/src/vm/wren_utils.c): `src/vm/wren_utils.c`

### Other components

- **Host Application**

## Connections

- Host Application → C Embedding API: embeds through (evidence: `README.md`)
- Host Application → Module Callbacks: provides callbacks (evidence: `src/include/wren.h`)
- C Embedding API → VM Interpreter: configures and invokes (evidence: `src/vm/wren_vm.c`)
- VM Interpreter → Single-Pass Compiler: compiles modules (evidence: `src/vm/wren_vm.c`)
- Single-Pass Compiler → Bytecode Opcodes: emits instructions (evidence: `src/vm/wren_compiler.c`)
- VM Interpreter → Bytecode Opcodes: dispatches instructions (evidence: `src/vm/wren_vm.c`)
- VM Interpreter → Values and Objects: manages runtime values (evidence: `src/vm/wren_vm.c`)
- Core Classes → Primitive Methods: binds primitives (evidence: `src/vm/wren_core.c`)
- VM Interpreter → Core Classes: initializes core
- VM Interpreter → Module Callbacks: loads modules (evidence: `src/vm/wren_vm.c`)
- VM Interpreter → Meta Module: loads optional module (evidence: `src/vm/wren_vm.c`)
- VM Interpreter → Random Module: loads optional module (evidence: `src/vm/wren_vm.c`)
- VM Interpreter → Errors and Debugging: reports runtime errors
- VM Interpreter → Allocation Utilities: allocates runtime memory
