# aurimukstis1/python-virtualmachine architecture

> Architecture diagram of the GitHub repository aurimukstis1/python-virtualmachine, 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/aurimukstis1/python-virtualmachine
- Repository: https://github.com/aurimukstis1/python-virtualmachine

## Overview

This repository is a small bytecode virtual machine. Its principal workflow loads a program into a process’s virtual memory, executes instructions on the CPU, and has the main loop respond to halt, error, syscall, and scheduling statuses. The kernel creates processes, handles syscalls, and coordinates context switches; the MMU provides paged address translation and frame allocation. Source excerpts show these core interactions; the README documents the VM’s broader memory, register, arithmetic, and function-call capabilities.

Main entry points: [`kernel.py`](https://github.com/aurimukstis1/python-virtualmachine/blob/main/kernel.py) (Process kernel), [`main.py`](https://github.com/aurimukstis1/python-virtualmachine/blob/main/main.py) (VM runner), [`cpu.py`](https://github.com/aurimukstis1/python-virtualmachine/blob/main/cpu.py) (Bytecode CPU), [`memory.py`](https://github.com/aurimukstis1/python-virtualmachine/blob/main/memory.py) (Paged MMU)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["Execution"]
  node_main["VM runner<br/>[main.py]"]
  node_cpu["Bytecode CPU<br/>[cpu.py]"]
end

subgraph group_kernel["Kernel"]
  node_process["Process state<br/>[process.py]"]
  node_kernel["Process kernel<br/>[kernel.py]"]
end

subgraph group_memory["Memory"]
  node_mmu["Paged MMU<br/>[memory.py]"]
  node_frames[("Physical frames<br/>[memory.py]")]
end

node_user(("Program user"))
node_console(("Console"))

node_user -->|"starts VM"| node_main
node_main -->|"creates system"| node_kernel
node_main -->|"steps instructions"| node_cpu
node_main -->|"loads program"| node_kernel
node_kernel -->|"creates state"| node_process
node_kernel -->|"loads bytes"| node_mmu
node_cpu -->|"reads/writes"| node_mmu
node_mmu -->|"allocates pages"| node_frames
node_main -->|"handles status"| node_kernel
node_kernel -->|"prints syscall"| node_console
node_main -->|"switches process"| node_kernel
node_kernel -->|"syncs registers"| node_cpu

click node_main "https://github.com/aurimukstis1/python-virtualmachine/blob/main/main.py"
click node_cpu "https://github.com/aurimukstis1/python-virtualmachine/blob/main/cpu.py"
click node_process "https://github.com/aurimukstis1/python-virtualmachine/blob/main/process.py"
click node_kernel "https://github.com/aurimukstis1/python-virtualmachine/blob/main/kernel.py"
click node_mmu "https://github.com/aurimukstis1/python-virtualmachine/blob/main/memory.py"
click node_frames "https://github.com/aurimukstis1/python-virtualmachine/blob/main/memory.py"

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_main,node_cpu,node_user toneBlue
class node_process,node_kernel toneAmber
class node_mmu,node_frames toneMint
class node_console toneIndigo
```

## Components

### Execution

- [VM runner](https://github.com/aurimukstis1/python-virtualmachine/blob/main/main.py): `main.py`
- [Bytecode CPU](https://github.com/aurimukstis1/python-virtualmachine/blob/main/cpu.py): `cpu.py`

### Kernel

- [Process state](https://github.com/aurimukstis1/python-virtualmachine/blob/main/process.py): `process.py`
- [Process kernel](https://github.com/aurimukstis1/python-virtualmachine/blob/main/kernel.py): `kernel.py`

### Memory

- [Paged MMU](https://github.com/aurimukstis1/python-virtualmachine/blob/main/memory.py): `memory.py`
- [Physical frames](https://github.com/aurimukstis1/python-virtualmachine/blob/main/memory.py): `memory.py`

### Other components

- **Program user**
- **Console**

## Connections

- Program user → VM runner: starts VM (evidence: `main.py`)
- VM runner → Process kernel: creates system (evidence: `main.py`)
- VM runner → Bytecode CPU: steps instructions (evidence: `main.py`)
- VM runner → Process kernel: loads program (evidence: `main.py`)
- Process kernel → Process state: creates state (evidence: `kernel.py`)
- Process kernel → Paged MMU: loads bytes (evidence: `kernel.py`)
- Bytecode CPU → Paged MMU: reads/writes (evidence: `cpu.py`)
- Paged MMU → Physical frames: allocates pages (evidence: `memory.py`)
- VM runner → Process kernel: handles status (evidence: `main.py`)
- Process kernel → Console: prints syscall (evidence: `kernel.py`)
- VM runner → Process kernel: switches process (evidence: `main.py`)
- Process kernel → Bytecode CPU: syncs registers (evidence: `kernel.py`)
