This is a perfect pivot. By shifting focus entirely to native Node.js
execution, we are taking the training wheels off the AST. We no longer care
how the 2010 C engine buffered strings; we care about semantic
translationbuilding an architecture that natively leverages V8 for object
orientation, closures, and method passing.
This is Phase 9: The Virtual Machine & Inter-Object Communication.
To make tests/call_other.c and tests/call_other_ob.c work seamlessly, we need
to transition our generated JS from a flat script into an Object Blueprint
Factory.
The VM Registry: We will add rt.blueprints and rt.clone_object() to the JS
runtime. When clone_object("call_other_ob") is evaluated, the runtime will
look up the blueprint, instantiate a closure, and run its create() method.
The -> Operator: In LPC, ob->func() maps to call_other(ob, "func"). The AST
already catches the -> operator. We will instruct the JS Code Generator to
rewrite it dynamically: ob->test(123) becomes rt.call_other(ob, "test", 123).
Implicit _args and this_object(): LPC implicitly exposes _args inside
functions. We will inject let _args = Array.from(arguments); at the top of
every generated JS function block, and map this_object() to the closure's
instance reference (_this).
Replace your entire harness.js with this Virtual Machine architecture. You can
now pass multiple files into it!
==
Run node harness.js tests/call_other.c tests/call_other_ob.c. Notice how we
pass both files to the harness now so the VM can cross-communicate!
==
user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/call_other.c
tests/call_other_ob.c
[+] Compiling tests/call_other.c into VM Memory...
[+] Compiling tests/call_other_ob.c into VM Memory...
[+] Launching Javascript V8 Native Environment...
--- BOOTING VM ---
[Object:call_other_ob] test!
[Object:call_other_ob] test!
[Object:call_other_ob] test!
[Object:call_other_ob] fun!
[Object:call_other_ob] fun2!
[CRASH] TypeError: _this.no_fun_here is not a function
at _this.create (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/harness
.js:464:26), <anonymous>:46:9)
at Object.clone_object (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/
harness.js:464:26), <anonymous>:8:27)
at eval (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/harness.js:464:
26), <anonymous>:76:4)
at runVM (/home/user/Downloads/Remote/LPC/GEM/harness.js:465:9)
at Object.<anonymous> (/home/user/Downloads/Remote/LPC/GEM/harness.js:473:1
)
at Module._compile (node:internal/modules/cjs/loader:1871:14)
at Object..js (node:internal/modules/cjs/loader:2002:10)
at Module.load (node:internal/modules/cjs/loader:1594:32)
at Module._load (node:internal/modules/cjs/loader:1396:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
user@elli:~/Downloads/Remote/LPC/GEM$