# jashhh0908/bytevm architecture

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

- Interactive diagram: https://gitdiagram.com/jashhh0908/bytevm
- Repository: https://github.com/jashhh0908/bytevm

## Overview

byteVM is a C11 implementation of a small programming language. A script is read by the command-line entry point, tokenized, parsed into an AST, compiled to bytecode, then executed by a stack VM. The compiler also tracks lexical scopes and variable slots; the VM uses call frames for functions and recursion. The README documents variables, control flow, functions, and primitive data types. Relationships for the main pipeline are shown in source or documented; unsampled subsystems are not expanded.

Main entry points: [`src/runtime/vm.c`](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/vm.c) (Virtual Machine), [`src/main.c`](https://github.com/jashhh0908/bytevm/blob/main/src/main.c) (Program Entry), [`src/compiler/codegen.c`](https://github.com/jashhh0908/bytevm/blob/main/src/compiler/codegen.c) (Bytecode Compiler), [`src/syntax/parser.c`](https://github.com/jashhh0908/bytevm/blob/main/src/syntax/parser.c) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Front End"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST Model<br/>[ast.c]"]
end

subgraph group_compile["Compilation"]
  node_codegen["Bytecode Compiler<br/>[codegen.c]"]
  node_symbols["Scope Symbols<br/>[symbol_table.c]"]
end

subgraph group_runtime["Runtime"]
  node_chunk["Instruction Chunk<br/>[chunk.c]"]
  node_opcodes["Bytecode Opcodes<br/>[bytecode.h]"]
  node_values["Runtime Values<br/>[value.c]"]
  node_vm["Virtual Machine<br/>[vm.c]"]
  node_frames["Call Frames<br/>[vm.h]"]
end

node_script["Source Script"]
node_cli["Program Entry<br/>[main.c]"]
node_output(("Program Output"))

node_script -->|"provides file"| node_cli
node_cli -->|"initializes"| node_lexer
node_lexer -->|"supplies tokens"| node_parser
node_cli -->|"parses program"| node_parser
node_parser -->|"constructs nodes"| node_ast
node_cli -->|"compiles AST"| node_codegen
node_codegen -->|"tracks scopes"| node_symbols
node_codegen -->|"emits instructions"| node_chunk
node_chunk -->|"stores instructions"| node_opcodes
node_cli -->|"initializes and runs"| node_vm
node_vm -->|"executes bytecode"| node_chunk
node_vm -->|"operates on values"| node_values
node_vm -->|"manages calls"| node_frames
node_vm -->|"prints results"| node_output

click node_cli "https://github.com/jashhh0908/bytevm/blob/main/src/main.c"
click node_lexer "https://github.com/jashhh0908/bytevm/blob/main/src/syntax/lexer.c"
click node_parser "https://github.com/jashhh0908/bytevm/blob/main/src/syntax/parser.c"
click node_ast "https://github.com/jashhh0908/bytevm/blob/main/src/syntax/ast.c"
click node_codegen "https://github.com/jashhh0908/bytevm/blob/main/src/compiler/codegen.c"
click node_symbols "https://github.com/jashhh0908/bytevm/blob/main/src/compiler/symbol_table.c"
click node_chunk "https://github.com/jashhh0908/bytevm/blob/main/src/runtime/chunk.c"
click node_opcodes "https://github.com/jashhh0908/bytevm/blob/main/src/runtime/bytecode.h"
click node_values "https://github.com/jashhh0908/bytevm/blob/main/src/runtime/value.c"
click node_vm "https://github.com/jashhh0908/bytevm/blob/main/src/runtime/vm.c"
click node_frames "https://github.com/jashhh0908/bytevm/blob/main/src/runtime/vm.h"

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_lexer,node_parser,node_ast toneBlue
class node_codegen,node_symbols toneAmber
class node_chunk,node_opcodes,node_values,node_vm,node_frames toneMint
class node_script,node_output toneIndigo
class node_cli toneTeal
```

## Components

### Front End

- [Lexer](https://github.com/jashhh0908/bytevm/blob/main/src/syntax/lexer.c): `src/syntax/lexer.c`
- [Parser](https://github.com/jashhh0908/bytevm/blob/main/src/syntax/parser.c): `src/syntax/parser.c`
- [AST Model](https://github.com/jashhh0908/bytevm/blob/main/src/syntax/ast.c): `src/syntax/ast.c`

### Compilation

- [Bytecode Compiler](https://github.com/jashhh0908/bytevm/blob/main/src/compiler/codegen.c): `src/compiler/codegen.c`
- [Scope Symbols](https://github.com/jashhh0908/bytevm/blob/main/src/compiler/symbol_table.c): `src/compiler/symbol_table.c`

### Runtime

- [Instruction Chunk](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/chunk.c): `src/runtime/chunk.c`
- [Bytecode Opcodes](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/bytecode.h): `src/runtime/bytecode.h`
- [Runtime Values](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/value.c): `src/runtime/value.c`
- [Virtual Machine](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/vm.c): `src/runtime/vm.c`
- [Call Frames](https://github.com/jashhh0908/bytevm/blob/main/src/runtime/vm.h): `src/runtime/vm.h`

### Other components

- **Source Script**
- [Program Entry](https://github.com/jashhh0908/bytevm/blob/main/src/main.c): `src/main.c`
- **Program Output**

## Connections

- Source Script → Program Entry: provides file (evidence: `src/main.c`)
- Program Entry → Lexer: initializes (evidence: `src/main.c`)
- Lexer → Parser: supplies tokens (evidence: `README.md`)
- Program Entry → Parser: parses program (evidence: `src/main.c`)
- Parser → AST Model: constructs nodes (evidence: `src/syntax/parser.c`)
- Program Entry → Bytecode Compiler: compiles AST (evidence: `src/main.c`)
- Bytecode Compiler → Scope Symbols: tracks scopes (evidence: `src/compiler/codegen.c`)
- Bytecode Compiler → Instruction Chunk: emits instructions (evidence: `src/compiler/codegen.c`)
- Instruction Chunk → Bytecode Opcodes: stores instructions
- Program Entry → Virtual Machine: initializes and runs (evidence: `src/main.c`)
- Virtual Machine → Instruction Chunk: executes bytecode
- Virtual Machine → Runtime Values: operates on values (evidence: `src/runtime/vm.c`)
- Virtual Machine → Call Frames: manages calls (evidence: `src/runtime/vm.c`)
- Virtual Machine → Program Output: prints results (evidence: `README.md`)
