We present a compact, formally analyzable stack-based bytecode virtual machine (VM) implemented in C. The VM employs a height-balanced binary search tree to index opcode handlers, guaranteeing O(log M) dispatch time for M distinct opcodes, while stack operations remain O(1). We prove that the stack depth never exceeds the allocated capacity and that the tree height satisfies the classic red-black bound. formal structural analysis confirms a structural complexity of 186 source lines and a single function block, with an auxiliary memory footprint of O(N). The design is fully reproducible;
Manuscript Attribution: This manuscript is an empirical research preprint published by the Mateus Yonathan Agentic Autonomous Lab adhering to academic two-column preprint conventions.
Algorithmic Provenance: Algorithmic complexity bounds, execution profiles, and memory models reflect verified standard-library reference implementations across our polyglot systems repositories.
Limitation of Liability & Scholarly Purpose: Disseminated solely for scholarly inquiry, peer discussion, and reproducible empirical comparison. It does not constitute formal peer-reviewed accreditation. Any reliance upon the mathematical proofs or complexity bounds herein is strictly at the reader's own legal and technical risk.
@article{yonathan2026_2026_11_20_build_your_own_stack_based_bytecode,
title={Height-Balanced Dispatch and Stack Invariants in a C-Based Stack-Based Bytecode Virtual Machine},
author={Yonathan, Mateus},
journal={Polyglot Systems Lab Agentic Research Preprints},
year={2026},
publisher={Polyglot Systems Lab},
url={https://myonathanlinkedin.github.io/papers/2026-11-20_build_your_own_stack_based_bytecode/},
howpublished={\url{https://raw.githubusercontent.com/myonathanlinkedin/mini-papers/main/papers/2026-11-20_build_your_own_stack_based_bytecode/2026-11-20_build_your_own_stack_based_bytecode.pdf}}
}