Download Game! Currently 78 players and visitors. Last logged in:DrizzinEndureNafleinUntapped

Blitzer's Blog >> 71853

Back to blogs index
Posted: 29 Aug 2026 22:59 [ permalink ]
We need to design the Master Object Index (MOI), State Arena, and implement
the Blueprint Loader and the LOAD_VAR / STORE_VAR opcodes. This is Phase 2 of
the architecture: Object Model.

We'll extend the existing VM class LPCVirtualMachine with:

current_oid property.

A stateArena as an Int32Array.

An moi as an Int32Array (preallocated).

A blueprintRegistry object mapping blueprint names to blueprint records (with
blueprint_id, var_count, bytecode, vtable, constantPool).

We'll implement clone_object(blueprintName) method that allocates a new object
instance.

We'll add opcodes LOAD_VAR and STORE_VAR (maybe 0x04 and 0x05) to the VM's
run() loop.

We'll write a test that demonstrates allocation, store and load.

Let's design the MOI node layout as per spec: 4 int32 per node (16 bytes):
[blueprint_id, state_offset, var_count, flags].

We'll also need a free list for MOI nodes? For MVP, we can just use a simple
bump allocator for OIDs: next_oid increments. We'll set a maximum number of
objects.

State Arena: also a bump allocator.

Blueprint Registry: a Map from name to { blueprint_id, var_count, bytecode,
vtable, constantPool }.

Implementation plan:

Extend LPCVirtualMachine class with new fields.

Add clone_object(name) method.

Add LOAD_VAR (opcode 0x04) and STORE_VAR (opcode 0x05) decoding in run().

We'll also need to maintain current_oid in the VM (for now). Later it will be
part of CTX.

We'll write a test script that creates a blueprint with 3 vars, clones it,
sets current_oid, and runs a bytecode sequence that uses STORE_VAR and
LOAD_VAR.

We'll also handle Tagged Pointers for integers: store integer 42 as tagged
(<<1 | 1? Actually earlier we had tagged pointers for ints: tag 1, value
shifted left 1? In previous messages, we defined tagged pointer for integers
as (value << 1) | 1. So we need to encode that.

We'll implement the tag functions.

Let's write the code.

We'll create a new file day2.js or extend LPCVirtualMachine.js. Given we want
to keep incremental progress, we'll create a new file objectModel.js or modify
LPCVirtualMachine.js to include these new features.

But the user asked to "write a JS test script that ...". So we can provide the
code for the updated VM and the test script.