Step 17b: bytecode-compiled text-layout, WASM library import fix
- text-layout.sx added to WASM bytecode pipeline (9K compiled) - Fix multi-list map calls (map-indexed + nth instead of map fn list1 list2) - pretext-layout-lines and pretext-position-line moved to library exports - Browser load-sxbc: handle VmSuspended for import, copy library exports to global_env after module load (define-library export fix) - compile-modules.js: text-layout in SOURCE_MAP, FILES, and entry deps - Island uses library functions (break-lines, pretext-layout-lines) instead of inlining — runs on bytecode VM when exports resolve Known issue: define-library exports don't propagate to browser global env yet. The load-sxbc import suspension handler resumes correctly but bind_import_set doesn't fire. Needs deeper investigation into how the WASM kernel's define-library registers exports vs how other libraries (adapter-html, tw) make their exports available. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,7 @@ const SOURCE_MAP = {
|
||||
'engine.sx': 'web/engine.sx', 'orchestration.sx': 'web/orchestration.sx',
|
||||
'boot.sx': 'web/boot.sx',
|
||||
'tw-layout.sx': 'web/tw-layout.sx', 'tw-type.sx': 'web/tw-type.sx', 'tw.sx': 'web/tw.sx',
|
||||
'text-layout.sx': 'lib/text-layout.sx',
|
||||
};
|
||||
let synced = 0;
|
||||
for (const [dist, src] of Object.entries(SOURCE_MAP)) {
|
||||
@@ -79,6 +80,7 @@ const FILES = [
|
||||
'page-helpers.sx', 'freeze.sx', 'bytecode.sx', 'compiler.sx', 'vm.sx',
|
||||
'dom.sx', 'browser.sx', 'adapter-html.sx', 'adapter-sx.sx', 'adapter-dom.sx',
|
||||
'tw-layout.sx', 'tw-type.sx', 'tw.sx',
|
||||
'text-layout.sx',
|
||||
'boot-helpers.sx', 'hypersx.sx', 'harness.sx', 'harness-reactive.sx',
|
||||
'harness-web.sx', 'engine.sx', 'orchestration.sx',
|
||||
// Hyperscript modules — loaded on demand via transparent lazy loader
|
||||
@@ -478,6 +480,10 @@ if (entryFile) {
|
||||
for (const m of HS_LAZY) {
|
||||
if (manifest[m] && !lazyDeps.includes(m)) lazyDeps.push(m);
|
||||
}
|
||||
// Text layout library — loaded eagerly for Pretext island
|
||||
if (manifest['sx text-layout'] && !eagerDeps.includes('sx text-layout')) {
|
||||
eagerDeps.push('sx text-layout');
|
||||
}
|
||||
manifest['_entry'] = {
|
||||
file: entryFile.file,
|
||||
deps: eagerDeps,
|
||||
|
||||
@@ -685,8 +685,45 @@ let () =
|
||||
in
|
||||
let module_val = convert_code code_form in
|
||||
let code = Sx_vm.code_from_value module_val in
|
||||
let _result = Sx_vm.execute_module code _vm_globals in
|
||||
(* Use execute_module_safe to handle import suspension.
|
||||
Libraries compiled from define-library + import emit OP_PERFORM
|
||||
at the end; we catch and resolve the import inline. *)
|
||||
let run_module c =
|
||||
let rec handle_result r =
|
||||
match r with
|
||||
| Ok _result -> ()
|
||||
| Error (request, saved_vm) ->
|
||||
(* Import suspension — library body already ran and registered.
|
||||
Copy exports to global env, then resume the VM. *)
|
||||
let lib_spec = Sx_runtime.get_val request (String "library") in
|
||||
(try ignore (Sx_ref.bind_import_set lib_spec (Env global_env))
|
||||
with _ -> ());
|
||||
let next = try Ok (Sx_vm.resume_vm saved_vm Nil)
|
||||
with Sx_vm.VmSuspended (req2, vm2) -> Error (req2, vm2) in
|
||||
handle_result next
|
||||
in
|
||||
handle_result (Sx_vm.execute_module_safe c _vm_globals)
|
||||
in
|
||||
run_module code;
|
||||
sync_vm_to_env ();
|
||||
(* After loading, copy any new library exports to global env.
|
||||
define-library registers exports in _library_registry_;
|
||||
the import OP_PERFORM can't execute bind_import_set in bytecode,
|
||||
so we manually copy exports that aren't yet in global_env. *)
|
||||
(match Sx_ref._library_registry_ with
|
||||
| Dict registry ->
|
||||
Hashtbl.iter (fun _key entry ->
|
||||
(match Sx_runtime.get_val entry (String "exports") with
|
||||
| Dict exports ->
|
||||
Hashtbl.iter (fun name value ->
|
||||
if not (Sx_types.env_has global_env name) then begin
|
||||
ignore (Sx_types.env_bind global_env name value);
|
||||
Hashtbl.replace _vm_globals name value
|
||||
end
|
||||
) exports
|
||||
| _ -> ())
|
||||
) registry
|
||||
| _ -> ());
|
||||
Number (float_of_int (Hashtbl.length _vm_globals))
|
||||
| _ -> raise (Eval_error "load-sxbc: expected (sxbc version hash (code ...))"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user