How kichman/vmjs works
vmjs is a TypeScript implementation of the Uxn virtual machine. A caller creates a VM with a device, loads program bytes into its RAM, and calls run(); the VM fetches instructions, dispatches base opcodes through a table or immediate opcodes through a special handler, and returns the final program counter when BRK stops execution. Opcode families provide flow, memory, stack, arithmetic, and device operations over shared VM state and stack helpers. The README documents the device contract and DEC/LIT extensions; device-operation wiring is shown only at the contract level because its implementation excerpt was not provided.
Main entry points: opcodes/index.ts Opcode exports · stack.ts Stack helpers · uxn-vm.ts Uxn runtime · src/index.ts Public API
Components 16
Execution core
- Public API
src/index.ts - Uxn runtime
src/uxn-vm.ts - Base opcode table
src/opcode-table.ts
Opcode operations
- LIT and DEC
src/opcodes/immediate-ops.ts - Opcode exports
src/opcodes/index.ts - Flow operations
src/opcodes/flow-ops.ts - Stack operations
src/opcodes/stack-ops.ts - Memory operations
src/opcodes/mem-ops.ts - Algebra operations
src/opcodes/algebra-ops.ts - Device operations
src/opcodes/dev-ops.ts
VM state
- VM state contract
src/uxn-types.ts - Stack helpers
src/stack.ts
Device I/O
- Device contract
src/uxn-types.ts - Console device
src/ConsoleDevice.ts
Other components
- Program caller
- Console output
Connections 19
- Program caller → Public API: uses
README.md - Public API → Uxn runtime: exports
src/index.ts - Public API → Console device: exports
src/index.ts - Uxn runtime → Base opcode table: dispatches base ops
src/uxn-vm.ts - Uxn runtime → LIT and DEC: dispatches immediate ops
src/uxn-vm.ts - Base opcode table → Opcode exports: imports handlers
src/opcode-table.ts - Opcode exports → Flow operations: re-exports
src/opcodes/index.ts - Opcode exports → Stack operations: re-exports
src/opcodes/index.ts - Opcode exports → Memory operations: re-exports
src/opcodes/index.ts - Opcode exports → Algebra operations: re-exports
src/opcodes/index.ts - Opcode exports → Device operations: re-exports
src/opcodes/index.ts - Uxn runtime → VM state contract: implements
src/uxn-vm.ts - Flow operations → Stack helpers: uses
src/opcodes/flow-ops.ts - Stack operations → Stack helpers: uses
src/opcodes/stack-ops.ts - Memory operations → Stack helpers: uses
src/opcodes/mem-ops.ts - Algebra operations → Stack helpers: uses
src/opcodes/algebra-ops.ts - LIT and DEC → Stack helpers: uses
src/opcodes/immediate-ops.ts - Device operations → Device contract: invokes device
src/opcodes/dev-ops.ts - Console device → Console output: writes characters
src/ConsoleDevice.ts