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:
2026-04-12 16:37:04 +00:00
parent 676ec6dd2b
commit 699dd5ad69
17 changed files with 2270 additions and 1662 deletions

View File

@@ -13,6 +13,21 @@
;; Knuth-Plass optimal line breaking (DP over break candidates).
;; Liang's hyphenation (trie over character patterns).
(define
pretext-position-line
(fn
(words widths gap-w)
(let
loop
((i 0) (x 0) (acc (list)))
(if
(>= i (len words))
acc
(loop
(+ i 1)
(+ x (nth widths i) gap-w)
(append acc (list {:width (nth widths i) :x x :word (nth words i)})))))))
(define-library
(sx text-layout)
(export
@@ -25,6 +40,8 @@
break-lines-greedy
position-line
position-lines
pretext-position-line
pretext-layout-lines
layout-paragraph
make-hyphenation-trie
find-hyphenation-points
@@ -131,7 +148,7 @@
((starts (cons 0 breaks)))
(let
((ends (append (rest starts) (list n))))
(map (fn (s e) (list s e)) starts ends)))))))
(map-indexed (fn (i s) (list s (nth ends i))) starts)))))))
(define
position-line
(fn
@@ -266,7 +283,7 @@
(let
((starts (cons 0 points))
(ends (append points (list (len word)))))
(map (fn (s e) (slice word s e)) starts ends))))))
(map-indexed (fn (i s) (slice word s (nth ends i))) starts))))))
(define
layout-paragraph
(fn