Targeting Pascal is an exceptional architectural choice. Pascal was explicitly designed by Niklaus Wirth to enforce strict, structured programming, logical clarity, and unambiguous data handling. If a virtual machine is "Pascal-Complete," it possesses all the primitives necessary to reliably execute almost any deterministic, procedural business logic or algorithmic standard. To amend our roadmap to reach Pascal-Completeness, we must expand our Instruction Set Architecture (ISA). The beauty of our stack machine is that we do not need to add complex opcodes for loops (while, repeat, for); those are entirely handled by the compiler using our existing JMP and JMP_FALSE opcodes. What we do need are the missing mathematical, logical, and structured-memory opcodes. Here is the formal amendment to our roadmap to achieve Pascal-Completeness. Amendment: The "Pascal-Complete" Instruction Set To support Pascal's standard logical operations and procedural structures, we must add the following opcodes to our VM registry. 1. Relational & Logical Completeness Pascal requires a full suite of comparisons and boolean logic. * Relational: OP_NEQ (<>), OP_GT (>), OP_LTE (<=), OP_GTE (>=). (We currently only have EQ and LT). * Logical (Eager): OP_AND, OP_OR, OP_NOT. * Short-Circuit Logic: Pascal's and then / or else short-circuiting doesn't need opcodes; the compiler will lower these into JMP_FALSE / JMP chains just like an if statement. 2. Arithmetic Completeness Pascal explicitly separates integer division from real (float) division. * Math: OP_DIV (Integer division, truncating), OP_MOD (Modulo), OP_FDIV (Real/Float division /). 3. Structured Data Access (Arrays and Records) Currently, our VM relies on Lisp-style CONS/HEAD/TAIL linked lists. Pascal uses randomly accessible fixed Arrays and Records. We need index/key-based memory access. * OP_GET_IDX: Pops a key/index and an object/array, pushes the value at that index. * OP_SET_IDX: Pops a value, a key/index, and an object/array, mutates the structure in memory. 4. Pass-by-Reference (var parameters) Pascal allows procedures to mutate outer variables via var parameters. * Because our environment closures use primitive JavaScript values (numbers/booleans), passing an integer to a function copies it by value. * We will need an OP_REF_LOAD and OP_REF_SET to pass pointers to the environment scope rather than raw values. How the Compiler handles Pascal Control Flow To prove how close we already are, consider a Pascal while loop: while n < 10 do n := n + 1; We do not need an OP_WHILE. We just teach the preprocessor/compiler a new while AST structure: ["while", ["<", "n", 10], ["set", "n", ["+", "n", 1]]] The compiler translates this using our existing jump architecture: * [Loop Start Address] * Compile condition ["<", "n", 10] * OP_JMP_FALSE to [End Address] (if n >= 10, exit loop) * Compile body ["set", "n", ["+", "n", 1]] * OP_POP (discard the body's return value to keep the data stack flat) * OP_JMP back to [Loop Start Address] * [End Address] Updated Execution Roadmap * Phase 1-3: MVP VM, Lock-Free Async, Tail Call Optimization (Completed) * Phase 4 (Current): Pascal-Complete ISA Expansion * Add Relational (>, >=, <=, <>) and Arithmetic (DIV, MOD) opcodes. * Add Logical (AND, OR, NOT) opcodes. * Add structured Array/Record access opcodes (GET_IDX, SET_IDX). * Phase 5: Pascal Control Flow AST * Expand the compile() function to natively lower ["while", cond, body], ["repeat", body, cond], and ["for", var, start, end, body] into flat Jump instructions. * Phase 6: Type Safety & Validation * Implement an OP_ASSERT_TYPE to ensure runtime type safety (e.g., throwing an error if trying to ADD a String to a Boolean), honoring Pascal's strongly-typed legacy.