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:
@@ -314,7 +314,10 @@
|
||||
(true
|
||||
(let
|
||||
((t (hs-to-sx expr)))
|
||||
(list (quote set!) t (list (quote +) t amount)))))))
|
||||
(list
|
||||
(quote set!)
|
||||
t
|
||||
(list (quote +) (list (quote or) t 0) amount)))))))
|
||||
(define
|
||||
emit-dec
|
||||
(fn
|
||||
@@ -363,7 +366,10 @@
|
||||
(true
|
||||
(let
|
||||
((t (hs-to-sx expr)))
|
||||
(list (quote set!) t (list (quote -) t amount)))))))
|
||||
(list
|
||||
(quote set!)
|
||||
t
|
||||
(list (quote -) (list (quote or) t 0) amount)))))))
|
||||
(define
|
||||
emit-behavior
|
||||
(fn
|
||||
@@ -801,8 +807,23 @@
|
||||
(list (quote hs-query-all) (nth raw-tgt 1)))
|
||||
(list
|
||||
(quote dom-remove-class)
|
||||
(hs-to-sx raw-tgt)
|
||||
(if (nil? raw-tgt) (quote me) (hs-to-sx raw-tgt))
|
||||
(nth ast 1)))))
|
||||
((= head (quote remove-element))
|
||||
(list (quote dom-remove) (hs-to-sx (nth ast 1))))
|
||||
((= head (quote remove-attr))
|
||||
(let
|
||||
((tgt (if (nil? (nth ast 2)) (quote me) (hs-to-sx (nth ast 2)))))
|
||||
(list (quote dom-remove-attr) tgt (nth ast 1))))
|
||||
((= head (quote remove-css))
|
||||
(let
|
||||
((tgt (if (nil? (nth ast 2)) (quote me) (hs-to-sx (nth ast 2))))
|
||||
(props (nth ast 1)))
|
||||
(cons
|
||||
(quote do)
|
||||
(map
|
||||
(fn (p) (list (quote dom-set-style) tgt p ""))
|
||||
props))))
|
||||
((= head (quote toggle-class))
|
||||
(list
|
||||
(quote hs-toggle-class!)
|
||||
|
||||
@@ -727,30 +727,68 @@
|
||||
parse-remove-cmd
|
||||
(fn
|
||||
()
|
||||
(if
|
||||
(= (tp-type) "class")
|
||||
(let
|
||||
((cls (get (adv!) "value")) (extra-classes (list)))
|
||||
(define
|
||||
collect-classes!
|
||||
(fn
|
||||
()
|
||||
(when
|
||||
(= (tp-type) "class")
|
||||
(set!
|
||||
extra-classes
|
||||
(append extra-classes (list (get (adv!) "value"))))
|
||||
(collect-classes!))))
|
||||
(collect-classes!)
|
||||
(cond
|
||||
((= (tp-type) "class")
|
||||
(let
|
||||
((tgt (parse-tgt-kw "from" (list (quote me)))))
|
||||
((cls (get (adv!) "value")) (extra-classes (list)))
|
||||
(define
|
||||
collect-classes!
|
||||
(fn
|
||||
()
|
||||
(when
|
||||
(= (tp-type) "class")
|
||||
(set!
|
||||
extra-classes
|
||||
(append extra-classes (list (get (adv!) "value"))))
|
||||
(collect-classes!))))
|
||||
(collect-classes!)
|
||||
(let
|
||||
((tgt (if (match-kw "from") (parse-expr) nil)))
|
||||
(if
|
||||
(empty? extra-classes)
|
||||
(list (quote remove-class) cls tgt)
|
||||
(cons
|
||||
(quote multi-remove-class)
|
||||
(cons tgt (cons cls extra-classes)))))))
|
||||
((and (= (tp-type) "bracket-open") (= (tp-val) "["))
|
||||
(do
|
||||
(adv!)
|
||||
(if
|
||||
(empty? extra-classes)
|
||||
(list (quote remove-class) cls tgt)
|
||||
(cons
|
||||
(quote multi-remove-class)
|
||||
(cons tgt (cons cls extra-classes))))))
|
||||
nil)))
|
||||
(= (tp-type) "attr")
|
||||
(let
|
||||
((attr-name (get (adv!) "value")))
|
||||
(match-kw "]")
|
||||
(let
|
||||
((tgt (if (match-kw "from") (parse-expr) nil)))
|
||||
(list (quote remove-attr) attr-name tgt)))
|
||||
nil)))
|
||||
((= (tp-val) "{")
|
||||
(do
|
||||
(adv!)
|
||||
(let
|
||||
((props (list)))
|
||||
(define
|
||||
collect-props!
|
||||
(fn
|
||||
()
|
||||
(when
|
||||
(not (= (tp-val) "}"))
|
||||
(when (= (tp-val) ";") (adv!))
|
||||
(when
|
||||
(not (= (tp-val) "}"))
|
||||
(set!
|
||||
props
|
||||
(append props (list (get (adv!) "value"))))
|
||||
(collect-props!)))))
|
||||
(collect-props!)
|
||||
(match-kw "}")
|
||||
(let
|
||||
((tgt (if (match-kw "from") (parse-expr) nil)))
|
||||
(list (quote remove-css) props tgt)))))
|
||||
(true
|
||||
(let
|
||||
((target (parse-expr)))
|
||||
(list (quote remove-element) target))))))
|
||||
(define
|
||||
parse-toggle-cmd
|
||||
(fn
|
||||
@@ -1168,6 +1206,7 @@
|
||||
()
|
||||
(let
|
||||
((target (parse-expr)))
|
||||
(match-kw "then")
|
||||
(let
|
||||
((body (parse-cmd-list)))
|
||||
(match-kw "end")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user