# yyax13/customvm architecture

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

- Interactive diagram: https://gitdiagram.com/yyax13/customvm
- Repository: https://github.com/yyax13/customvm

## Overview

This repository implements a small C virtual machine: callers supply bytecode, and the VM decodes and executes instructions against registers, stacks, and memory, returning an exit code. Its instruction set includes arithmetic, control flow, memory operations, hashing, and host calls for process I/O and exit. The tree contains assembler-related types, but no assembler implementation or documented assembly-to-bytecode workflow. Some VM interactions are visible only in partial excerpts, so uncertain links are omitted or marked unverified.

Main entry points: [`src/vm/main.c`](https://github.com/yyax13/customvm/blob/main/src/vm/main.c) (Execution loop), [`src/vm/instructions/main.c`](https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.c) (Instruction decoder), [`src/vm/hostcalls/main.c`](https://github.com/yyax13/customvm/blob/main/src/vm/hostcalls/main.c) (Hostcall registry), [`src/vm/instructions/main.h`](https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.h) (Instruction set)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["VM execution"]
  node_vm["Execution loop<br/>[main.c]"]
  node_instruction_set["Instruction set<br/>[main.h]"]
  node_instruction_decoder["Instruction decoder<br/>[main.c]"]
  node_assembler_types["Assembler types<br/>[main.h]"]
  node_program_entry["Program entry<br/>[main.c]"]
end

subgraph group_state["VM state"]
  node_vm_types["VM data types<br/>[main.h]"]
  node_common_types["Common types<br/>[main.h]"]
  node_registers["Registers and state<br/>[main.c]"]
  node_parameter_decoder["Operand decoding<br/>[main.c]"]
end

subgraph group_services["Runtime services"]
  node_hash["FNV hashing<br/>[main.c]"]
  node_hostcall_dispatch["Hostcall registry<br/>[main.c]"]
  node_host_io["Host I/O<br/>[main.c]"]
end

node_caller(("VM caller"))
node_os(("Operating system"))

node_caller -.->|"runs bytecode"| node_vm
node_vm -->|"decodes operands"| node_parameter_decoder
node_vm -->|"checks registers"| node_registers
node_vm -->|"hashes values"| node_hash
node_vm -->|"dispatches hostcalls"| node_hostcall_dispatch
node_vm -.->|"decodes instructions"| node_instruction_decoder
node_instruction_decoder -.->|"uses opcodes"| node_instruction_set
node_hostcall_dispatch -->|"provides handlers"| node_host_io
node_host_io -->|"reads and writes"| node_os

click node_vm "https://github.com/yyax13/customvm/blob/main/src/vm/main.c"
click node_instruction_set "https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.h"
click node_instruction_decoder "https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.c"
click node_assembler_types "https://github.com/yyax13/customvm/blob/main/src/assembler/types/main.h"
click node_vm_types "https://github.com/yyax13/customvm/blob/main/src/vm/types/main.h"
click node_common_types "https://github.com/yyax13/customvm/blob/main/src/types/main.h"
click node_registers "https://github.com/yyax13/customvm/blob/main/src/vm/registers/main.c"
click node_parameter_decoder "https://github.com/yyax13/customvm/blob/main/src/vm/registers/main.c"
click node_hash "https://github.com/yyax13/customvm/blob/main/src/utils/hash/main.c"
click node_hostcall_dispatch "https://github.com/yyax13/customvm/blob/main/src/vm/hostcalls/main.c"
click node_host_io "https://github.com/yyax13/customvm/blob/main/src/vm/hostcalls/main.c"
click node_program_entry "https://github.com/yyax13/customvm/blob/main/src/main.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_vm,node_instruction_set,node_instruction_decoder,node_assembler_types,node_program_entry toneBlue
class node_vm_types,node_common_types,node_registers,node_parameter_decoder toneAmber
class node_hash,node_hostcall_dispatch,node_host_io toneMint
class node_caller,node_os toneIndigo
```

## Components

### VM execution

- [Execution loop](https://github.com/yyax13/customvm/blob/main/src/vm/main.c): `src/vm/main.c`
- [Instruction set](https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.h): `src/vm/instructions/main.h`
- [Instruction decoder](https://github.com/yyax13/customvm/blob/main/src/vm/instructions/main.c): `src/vm/instructions/main.c`
- [Assembler types](https://github.com/yyax13/customvm/blob/main/src/assembler/types/main.h): `src/assembler/types/main.h`
- [Program entry](https://github.com/yyax13/customvm/blob/main/src/main.c): `src/main.c`

### VM state

- [VM data types](https://github.com/yyax13/customvm/blob/main/src/vm/types/main.h): `src/vm/types/main.h`
- [Common types](https://github.com/yyax13/customvm/blob/main/src/types/main.h): `src/types/main.h`
- [Registers and state](https://github.com/yyax13/customvm/blob/main/src/vm/registers/main.c): `src/vm/registers/main.c`
- [Operand decoding](https://github.com/yyax13/customvm/blob/main/src/vm/registers/main.c): `src/vm/registers/main.c`

### Runtime services

- [FNV hashing](https://github.com/yyax13/customvm/blob/main/src/utils/hash/main.c): `src/utils/hash/main.c`
- [Hostcall registry](https://github.com/yyax13/customvm/blob/main/src/vm/hostcalls/main.c): `src/vm/hostcalls/main.c`
- [Host I/O](https://github.com/yyax13/customvm/blob/main/src/vm/hostcalls/main.c): `src/vm/hostcalls/main.c`

### Other components

- **VM caller**
- **Operating system**

## Connections

- VM caller → Execution loop: runs bytecode
- Execution loop → Operand decoding: decodes operands (evidence: `src/vm/main.c`)
- Execution loop → Registers and state: checks registers (evidence: `src/vm/main.c`)
- Execution loop → FNV hashing: hashes values (evidence: `src/vm/main.c`)
- Execution loop → Hostcall registry: dispatches hostcalls (evidence: `src/vm/main.c`)
- Execution loop → Instruction decoder: decodes instructions
- Instruction decoder → Instruction set: uses opcodes (evidence: `src/vm/instructions/main.c`)
- Hostcall registry → Host I/O: provides handlers (evidence: `src/vm/hostcalls/main.c`)
- Host I/O → Operating system: reads and writes (evidence: `src/vm/hostcalls/main.c`)
