Step 5 piece 6: migrate 23 .sx files to define-library/import
Wraps all core .sx files in R7RS define-library with explicit export lists, plus (import ...) at end for backward-compatible global re-export. Libraries registered: (sx bytecode) — 83 opcode constants (sx render) — 15 tag registries + render helpers (sx signals) — 23 reactive signal primitives (sx r7rs) — 21 R7RS aliases (sx compiler) — 42 compiler functions (sx vm) — 32 VM functions (sx freeze) — 9 freeze/thaw functions (sx content) — 6 content store functions (sx callcc) — 1 call/cc wrapper (sx highlight) — 13 syntax highlighting functions (sx stdlib) — 47 stdlib functions (sx swap) — 13 swap algebra functions (sx render-trace) — 8 render trace functions (sx harness) — 21 test harness functions (sx canonical) — 12 canonical serialization functions (web adapter-html) — 13 HTML renderer functions (web adapter-sx) — 13 SX wire format functions (web engine) — 33 hypermedia engine functions (web request-handler) — 4 request handling functions (web page-helpers) — 12 page helper functions (web router) — 36 routing functions (web deps) — 19 dependency analysis functions (web orchestration) — 59 page orchestration functions Key changes: - define-library now inherits parent env (env-extend env instead of env-extend make-env) so library bodies can access platform primitives - sx_server.ml: added resolve_library_path + load_library_file for import resolution (maps library specs to file paths) - cek_run_with_io: handles "import" locally instead of sending to Python bridge 2608/2608 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
|
||||
|
||||
(define-library (web adapter-html)
|
||||
(export
|
||||
render-to-html
|
||||
render-value-to-html
|
||||
RENDER_HTML_FORMS
|
||||
render-html-form?
|
||||
render-list-to-html
|
||||
dispatch-html-form
|
||||
render-lambda-html
|
||||
render-html-component
|
||||
render-html-element
|
||||
render-html-lake
|
||||
render-html-marsh
|
||||
render-html-island
|
||||
serialize-island-state)
|
||||
(begin
|
||||
|
||||
(define
|
||||
render-to-html
|
||||
:effects (render)
|
||||
@@ -589,3 +608,9 @@
|
||||
(fn
|
||||
((kwargs :as dict))
|
||||
(if (empty-dict? kwargs) nil (sx-serialize kwargs))))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web adapter-html))
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
|
||||
|
||||
(define-library (web adapter-sx)
|
||||
(export
|
||||
render-to-sx
|
||||
aser
|
||||
aser-list
|
||||
aser-reserialize
|
||||
aser-fragment
|
||||
aser-call
|
||||
aser-expand-component
|
||||
SPECIAL_FORM_NAMES
|
||||
HO_FORM_NAMES
|
||||
special-form?
|
||||
ho-form?
|
||||
aser-special
|
||||
eval-case-aser)
|
||||
(begin
|
||||
|
||||
(define
|
||||
render-to-sx
|
||||
:effects (render)
|
||||
@@ -570,3 +589,9 @@
|
||||
(= match-val (trampoline (eval-expr test env)))
|
||||
(aser body env)
|
||||
(eval-case-aser match-val (slice clauses 2) env)))))))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web adapter-sx))
|
||||
|
||||
31
web/deps.sx
31
web/deps.sx
@@ -1,3 +1,28 @@
|
||||
|
||||
|
||||
(define-library (web deps)
|
||||
(export
|
||||
scan-refs
|
||||
scan-refs-walk
|
||||
transitive-deps-walk
|
||||
transitive-deps
|
||||
compute-all-deps
|
||||
scan-components-from-source
|
||||
components-needed
|
||||
page-component-bundle
|
||||
page-css-classes
|
||||
scan-io-refs-walk
|
||||
scan-io-refs
|
||||
transitive-io-refs-walk
|
||||
transitive-io-refs
|
||||
compute-all-io-refs
|
||||
component-io-refs-cached
|
||||
component-pure?
|
||||
render-target
|
||||
page-render-plan
|
||||
env-components)
|
||||
(begin
|
||||
|
||||
(define
|
||||
scan-refs
|
||||
:effects ()
|
||||
@@ -335,3 +360,9 @@
|
||||
((k :as string))
|
||||
(let ((v (env-get env k))) (or (component? v) (macro? v))))
|
||||
(keys env))))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web deps))
|
||||
|
||||
@@ -1,3 +1,42 @@
|
||||
|
||||
|
||||
(define-library (web engine)
|
||||
(export
|
||||
ENGINE_VERBS
|
||||
DEFAULT_SWAP
|
||||
parse-time
|
||||
parse-trigger-spec
|
||||
default-trigger
|
||||
get-verb-info
|
||||
build-request-headers
|
||||
process-response-headers
|
||||
parse-swap-spec
|
||||
parse-retry-spec
|
||||
next-retry-ms
|
||||
filter-params
|
||||
resolve-target
|
||||
apply-optimistic
|
||||
revert-optimistic
|
||||
find-oob-swaps
|
||||
morph-node
|
||||
sync-attrs
|
||||
morph-children
|
||||
morph-island-children
|
||||
morph-marsh
|
||||
process-signal-updates
|
||||
swap-dom-nodes
|
||||
insert-remaining-siblings
|
||||
swap-html-string
|
||||
handle-history
|
||||
PRELOAD_TTL
|
||||
preload-cache-get
|
||||
preload-cache-set
|
||||
classify-trigger
|
||||
should-boost-link?
|
||||
should-boost-form?
|
||||
parse-sse-swap)
|
||||
(begin
|
||||
|
||||
(define ENGINE_VERBS (list "get" "post" "put" "delete" "patch"))
|
||||
|
||||
(define DEFAULT_SWAP "outerHTML")
|
||||
@@ -806,3 +845,9 @@
|
||||
parse-sse-swap
|
||||
:effects (io)
|
||||
(fn (el) (or (dom-get-attr el "sx-sse-swap") "message")))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web engine))
|
||||
|
||||
@@ -1,3 +1,68 @@
|
||||
|
||||
|
||||
(define-library (web orchestration)
|
||||
(export
|
||||
_preload-cache
|
||||
dispatch-trigger-events
|
||||
execute-request
|
||||
do-fetch
|
||||
handle-fetch-success
|
||||
flush-collected-styles
|
||||
handle-sx-response
|
||||
handle-html-response
|
||||
handle-retry
|
||||
bind-triggers
|
||||
bind-event
|
||||
post-swap
|
||||
process-settle-hooks
|
||||
activate-scripts
|
||||
process-oob-swaps
|
||||
hoist-head-elements
|
||||
process-boosted
|
||||
boost-descendants
|
||||
_page-data-cache
|
||||
_page-data-cache-ttl
|
||||
page-data-cache-key
|
||||
page-data-cache-get
|
||||
page-data-cache-set
|
||||
invalidate-page-cache
|
||||
invalidate-all-page-cache
|
||||
update-page-cache
|
||||
process-cache-directives
|
||||
_optimistic-snapshots
|
||||
optimistic-cache-update
|
||||
optimistic-cache-revert
|
||||
optimistic-cache-confirm
|
||||
submit-mutation
|
||||
_is-online
|
||||
_offline-queue
|
||||
offline-is-online?
|
||||
offline-set-online!
|
||||
offline-queue-mutation
|
||||
offline-sync
|
||||
offline-pending-count
|
||||
offline-aware-mutation
|
||||
current-page-layout
|
||||
swap-rendered-content
|
||||
resolve-route-target
|
||||
deps-satisfied?
|
||||
try-client-route
|
||||
bind-client-route-link
|
||||
process-sse
|
||||
bind-sse
|
||||
bind-sse-swap
|
||||
bind-inline-handlers
|
||||
bind-preload-for
|
||||
do-preload
|
||||
VERB_SELECTOR
|
||||
process-elements
|
||||
process-one
|
||||
process-emit-elements
|
||||
save-scroll-position
|
||||
handle-popstate
|
||||
engine-init)
|
||||
(begin
|
||||
|
||||
(define _preload-cache (dict))
|
||||
|
||||
(define
|
||||
@@ -1566,3 +1631,9 @@
|
||||
(fn
|
||||
()
|
||||
(do (sx-process-scripts nil) (sx-hydrate nil) (process-elements nil))))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web orchestration))
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
|
||||
|
||||
(define-library (web page-helpers)
|
||||
(export
|
||||
special-form-category-map
|
||||
extract-define-kwargs
|
||||
categorize-special-forms
|
||||
build-ref-items-with-href
|
||||
build-reference-data
|
||||
build-attr-detail
|
||||
build-header-detail
|
||||
build-event-detail
|
||||
build-component-source
|
||||
build-bundle-analysis
|
||||
build-routing-analysis
|
||||
build-affinity-analysis)
|
||||
(begin
|
||||
|
||||
(define special-form-category-map {:defmacro "Functions & Components" :for-each "Higher-Order Forms" :defpage "Domain Definitions" :let "Binding" :filter "Higher-Order Forms" :shift "Continuations" :and "Control Flow" :set! "Binding" :map-indexed "Higher-Order Forms" :dynamic-wind "Guards" :reduce "Higher-Order Forms" :cond "Control Flow" :defquery "Domain Definitions" :-> "Sequencing & Threading" :let* "Binding" :define "Binding" :reset "Continuations" :case "Control Flow" :do "Sequencing & Threading" :map "Higher-Order Forms" :some "Higher-Order Forms" :letrec "Binding" :if "Control Flow" :quote "Quoting" :every? "Higher-Order Forms" :defhandler "Domain Definitions" :fn "Functions & Components" :defstyle "Domain Definitions" :lambda "Functions & Components" :defaction "Domain Definitions" :or "Control Flow" :defcomp "Functions & Components" :quasiquote "Quoting" :when "Control Flow" :begin "Sequencing & Threading"})
|
||||
|
||||
(define
|
||||
@@ -230,3 +248,9 @@
|
||||
(define
|
||||
build-affinity-analysis
|
||||
(fn ((demo-components :as list) (page-plans :as list)) {:components demo-components :page-plans page-plans}))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web page-helpers))
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
|
||||
|
||||
(define-library (web request-handler)
|
||||
(export
|
||||
sx-url-to-expr
|
||||
sx-auto-quote
|
||||
sx-eval-page
|
||||
sx-handle-request)
|
||||
(begin
|
||||
|
||||
(define
|
||||
sx-url-to-expr
|
||||
(fn
|
||||
@@ -66,3 +76,9 @@
|
||||
path
|
||||
(str (slice prefix 0 (- prefix-len 1)) path))))
|
||||
{:page-ast page-ast :nav-path nav-path :is-ajax is-ajax})))))
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web request-handler))
|
||||
|
||||
@@ -17,6 +17,47 @@
|
||||
;; "/" → ()
|
||||
;; "/docs/" → ("docs")
|
||||
|
||||
|
||||
(define-library (web router)
|
||||
(export
|
||||
split-path-segments
|
||||
make-route-segment
|
||||
parse-route-pattern
|
||||
match-route-segments
|
||||
match-route
|
||||
find-matching-route
|
||||
_fn-to-segment
|
||||
sx-url-to-path
|
||||
_count-leading-dots
|
||||
_strip-trailing-close
|
||||
_index-of-safe
|
||||
_last-index-of
|
||||
_pop-sx-url-level
|
||||
_pop-sx-url-levels
|
||||
_split-pos-kw
|
||||
_parse-relative-body
|
||||
_extract-innermost
|
||||
_find-kw-in-tokens
|
||||
_find-keyword-value
|
||||
_replace-kw-in-tokens
|
||||
_set-keyword-in-content
|
||||
_is-delta-value?
|
||||
_apply-delta
|
||||
_apply-kw-pairs
|
||||
_apply-keywords-to-url
|
||||
_normalize-relative
|
||||
resolve-relative-url
|
||||
relative-sx-url?
|
||||
_url-special-forms
|
||||
url-special-form?
|
||||
parse-sx-url
|
||||
url-special-form-name
|
||||
url-special-form-inner
|
||||
url-to-expr
|
||||
auto-quote-unknowns
|
||||
prepare-url-expr)
|
||||
(begin
|
||||
|
||||
(define split-path-segments :effects []
|
||||
(fn ((path :as string))
|
||||
(let ((trimmed (if (starts-with? path "/") (slice path 1) path)))
|
||||
@@ -678,3 +719,9 @@
|
||||
;;
|
||||
;; From parser.sx: sx-parse, sx-serialize
|
||||
;; --------------------------------------------------------------------------
|
||||
|
||||
|
||||
)) ;; end define-library
|
||||
|
||||
;; Re-export to global namespace for backward compatibility
|
||||
(import (web router))
|
||||
|
||||
Reference in New Issue
Block a user