Download Game! Currently 80 players and visitors. Last logged in:PaziOnniferPereTohvu

Blitzer's Blog >> 71857

Back to blogs index
Posted: 30 Aug 2026 05:04 [ permalink ]
user@elli:~/GD$ pwd
user@elli:~/GD$ ls -ltra
total 72
-rw-r--r--B 1 user user 1710 Aug 29 21:39 mvp.js
-rw-r--r--B 1 user user 5516 Aug 29 22:37 GlobalHandleLedger.js
-rw-r--r--B 1 user user 3896 Aug 29 22:55 stringManager.js
-rw-r--r--B 1 user userB 943 Aug 29 22:55 day1.js
drwxr-sr-x 18 user user 4096 Aug 29 22:57 ..
-rw-r--r--B 1 user user 4656 Aug 29 22:58 phase2.txt
-rw-r--r--B 1 user user 2492 Aug 30 04:20 day2.js
-rw-r--r--B 1 user userB 670 Aug 30 04:41 ctx.js
-rw-r--r--B 1 user userB 561 Aug 30 04:41 scheduler.js
-rw-r--r--B 1 user user 2615 Aug 30 04:46 day3.js
-rw-r--r--B 1 user user 7074 Aug 30 04:55 LPCVirtualMachine.js~
drwxr-sr-xB 2 user user 4096 Aug 30 04:56 .
-rw-r--r--B 1 user user 6950 Aug 30 04:59 LPCVirtualMachine.js
-rw-r--r--B 1 user user 1992 Aug 30 04:59 day4.js
user@elli:~/GD$ node day4.jsB
Player HP after attack: 85
user@elli:~/GD$B

You have officially achieved cross-object dynamic dispatch! The output showing
the player's HP reducing from 100 to 85 confirms that the `ECALL` instruction
successfully transitions the execution context between the `monster` and the
`player`. Furthermore, your logic addition to the `RETURN` opcode in
`LPCVirtualMachine.js`restoring `ctx.bytecode` and `ctx.constantPool`
alongside the `R0` preservationwas brilliant and structurally necessary for
the context switch to unwind safely.

### Phase 4: The Compilation Pipeline

Writing 32-bit hex arrays by hand, such as `0x11021234` to trigger an `ECALL`,
is officially retired. We must now build the JavaScript MVP Compiler. This
compiler will translate human-readable LPC text into a strict JSON Abstract
Syntax Tree (AST), and ultimately into our binary Blueprint format.

### The AST Specification

The AST must be completely JSON-serializable. Every node requires a `type`
identifier to allow for recursive descent traversal during code generation.
Here is the core architectural mapping:

* **Program Node:** The root of the tree, containing an array of
`FunctionDeclaration` and `VariableDeclaration` nodes.
* **FunctionDeclaration Node:** Defines the function name, its arguments, and
a `BlockStatement` containing the internal logic.
* **ExpressionStatement Node:** Wraps executable logic like assignments (`hp =
85`) or arithmetic.
* **CallExpression / MemberExpression Nodes:** Maps high-level function calls
directly to our `SYSCALL` and `ECALL` opcodes.

### The Compiler Modules

To maintain isolation and testability, the compiler will be strictly divided
into three stages:

* **The Lexer (Tokenizer):** Consumes the `.c` source text and outputs a flat
array of categorized tokens (e.g., `Keyword`, `Identifier`, `Number`,
`Operator`).
* **The Parser:** Consumes the token array and recursively constructs the
nested JSON AST based on LPC grammar rules.
* **The Code Generator (Codegen):** Walks the AST, extracts static strings
into a local Constant Pool, calculates relative jump offsets for loops,
assigns local variables to `R3-R7`, and emits the final `Uint32Array` bytecode
and VTable mapping.



For the Lexer, do you prefer a Regex-based tokenization approach (faster to
prototype in JS) or a strict character-by-character state machine (more
isomorphic to an eventual C-based compiler)?