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:
2026-04-03 21:48:54 +00:00
parent 397d0f39c0
commit 2d7dd7d582
26 changed files with 858 additions and 14 deletions

View File

@@ -1,4 +1,21 @@
;; Deterministic serialization for content addressing
(define-library (sx canonical)
(export
canonical-serialize
canonical-number
canonical-dict
content-id
content-id-short
make-bytecode-module
bytecode-module?
bytecode-module-version
bytecode-module-source-hash
bytecode-module-code
make-code-object
make-provenance)
(begin
(define
canonical-serialize
:effects ()
@@ -127,3 +144,9 @@
:bytecode-cid bytecode-cid
:compiler-cid compiler-cid
:timestamp timestamp)))
)) ;; end define-library
;; Re-export to global namespace for backward compatibility
(import (sx canonical))

View File

@@ -1469,9 +1469,7 @@
(let
((lib-spec (first args)) (decls (rest args)))
(let
((lib-env (env-extend (make-env)))
(exports (list))
(body-forms (list)))
((lib-env (env-extend env)) (exports (list)) (body-forms (list)))
(for-each
(fn
(decl)

View File

@@ -1,4 +1,30 @@
;; Assert condition is truthy, error with message
(define-library (sx harness)
(export
assert
assert=
default-platform
make-harness
harness-reset!
harness-log
harness-get
harness-set!
make-interceptor
install-interceptors
io-calls
io-call-count
io-call-nth
io-call-args
io-call-result
assert-io-called
assert-no-io
assert-io-count
assert-io-args
assert-io-result
assert-state)
(begin
(define assert (fn (condition msg) (when (not condition) (error (or msg "Assertion failed")))))
;; Assert two values are equal
@@ -60,3 +86,9 @@
;; Assert a state key has the expected value
(define assert-state :effects () (fn (session key expected) (let ((actual (harness-get session key))) (assert (equal? actual expected) (str "Expected state " key " to be " (str expected) " but got " (str actual))))))
)) ;; end define-library
;; Re-export to global namespace for backward compatibility
(import (sx harness))

View File

@@ -1,4 +1,24 @@
;; Registry of all valid HTML tag names
(define-library (sx render)
(export
HTML_TAGS
VOID_ELEMENTS
BOOLEAN_ATTRS
*definition-form-extensions*
definition-form?
parse-element-args
render-attrs
eval-cond
eval-cond-scheme
eval-cond-clojure
process-bindings
is-render-expr?
merge-spread-attrs
escape-html
escape-attr)
(begin
(define
HTML_TAGS
(list
@@ -413,3 +433,9 @@
;; Escape special chars for HTML attribute values
(define escape-attr (fn (s) (escape-html s)))
)) ;; end define-library
;; Re-export to global namespace for backward compatibility
(import (sx render))

View File

@@ -1,3 +1,32 @@
(define-library (sx signals)
(export
make-signal
signal?
signal-value
signal-set-value!
signal-subscribers
signal-add-sub!
signal-remove-sub!
signal-deps
signal-set-deps!
signal
deref
reset!
swap!
computed
effect
*batch-depth*
*batch-queue*
batch
notify-subscribers
flush-subscribers
dispose-computed
with-island-scope
register-in-scope)
(begin
(define
make-signal
(fn
@@ -193,3 +222,9 @@
(let
((collector (scope-peek "sx-island-scope")))
(when collector (cek-call collector (list disposable))))))
)) ;; end define-library
;; Re-export to global namespace for backward compatibility
(import (sx signals))