Adopt Step 7 language features across SX codebase
112 conversions across 19 .sx files using match, let-match, and pipe operators: match (17): type/value dispatch replacing cond/if chains - lib/vm.sx: HO form dispatch (for-each/map/filter/reduce/some/every?) - lib/tree-tools.sx: node-display, node-matches?, rename, count, replace, free-symbols - lib/types.sx: narrow-type, substitute-in-type, infer-type, resolve-type - web/engine.sx: default-trigger, resolve-target, classify-trigger - web/deps.sx: scan-refs-walk, scan-io-refs-walk let-match (89): dict destructuring replacing (get d "key") patterns - shared/page-functions.sx (20), blog/admin.sx (17), pub-api.sx (13) - events/ layouts/page/tickets/entries/forms (27 total) - specs-explorer.sx (7), federation/social.sx (3), lib/ small files (3) -> pipes (6): replacing triple-chained gets in lib/vm.sx - frame-closure → closure-code → code-bytecode chains Also: lib/vm.sx accessor upgrades (get vm "sp" → vm-sp vm throughout) 2650/2650 tests pass, zero regressions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,33 +63,28 @@
|
||||
:effects ()
|
||||
(fn
|
||||
(node)
|
||||
(cond
|
||||
(nil? node)
|
||||
"nil"
|
||||
(= (type-of node) "symbol")
|
||||
(symbol-name node)
|
||||
(= (type-of node) "keyword")
|
||||
(str ":" (keyword-name node))
|
||||
(= (type-of node) "string")
|
||||
(let
|
||||
((s (if (> (len node) 40) (str (slice node 0 37) "...") node)))
|
||||
(str "\"" s "\""))
|
||||
(= (type-of node) "number")
|
||||
(str node)
|
||||
(= (type-of node) "boolean")
|
||||
(if node "true" "false")
|
||||
(list? node)
|
||||
(if
|
||||
(empty? node)
|
||||
"()"
|
||||
(str
|
||||
"("
|
||||
(node-display (first node))
|
||||
(if (> (len node) 1) " ..." "")
|
||||
")"))
|
||||
(= (type-of node) "dict")
|
||||
"{...}"
|
||||
:else (str node))))
|
||||
(match
|
||||
(type-of node)
|
||||
("nil" "nil")
|
||||
("symbol" (symbol-name node))
|
||||
("keyword" (str ":" (keyword-name node)))
|
||||
("string"
|
||||
(let
|
||||
((s (if (> (len node) 40) (str (slice node 0 37) "...") node)))
|
||||
(str "\"" s "\"")))
|
||||
("number" (str node))
|
||||
("boolean" (if node "true" "false"))
|
||||
("list"
|
||||
(if
|
||||
(empty? node)
|
||||
"()"
|
||||
(str
|
||||
"("
|
||||
(node-display (first node))
|
||||
(if (> (len node) 1) " ..." "")
|
||||
")")))
|
||||
("dict" "{...}")
|
||||
(_ (str node)))))
|
||||
|
||||
(define
|
||||
summarise
|
||||
@@ -244,17 +239,16 @@
|
||||
:effects ()
|
||||
(fn
|
||||
(node pattern)
|
||||
(cond
|
||||
(= (type-of node) "symbol")
|
||||
(contains? (symbol-name node) pattern)
|
||||
(string? node)
|
||||
(contains? node pattern)
|
||||
(and
|
||||
(list? node)
|
||||
(not (empty? node))
|
||||
(= (type-of (first node)) "symbol"))
|
||||
(contains? (symbol-name (first node)) pattern)
|
||||
:else false)))
|
||||
(match
|
||||
(type-of node)
|
||||
("symbol" (contains? (symbol-name node) pattern))
|
||||
("string" (contains? node pattern))
|
||||
("list"
|
||||
(if
|
||||
(empty? node)
|
||||
false
|
||||
(some (fn (child) (node-matches? child pattern)) node)))
|
||||
(_ false))))
|
||||
|
||||
(define
|
||||
node-summary-short
|
||||
@@ -546,33 +540,33 @@
|
||||
:effects ()
|
||||
(fn
|
||||
(node replacement)
|
||||
(cond
|
||||
(and (= (type-of node) "symbol") (= (symbol-name node) "_"))
|
||||
replacement
|
||||
(list? node)
|
||||
(let
|
||||
((found false)
|
||||
(result
|
||||
(map
|
||||
(fn
|
||||
(child)
|
||||
(if
|
||||
found
|
||||
child
|
||||
(match
|
||||
(type-of node)
|
||||
("symbol" (if (= (symbol-name node) "_") replacement nil))
|
||||
("list"
|
||||
(let
|
||||
((found false)
|
||||
(result
|
||||
(map
|
||||
(fn
|
||||
(child)
|
||||
(if
|
||||
(and
|
||||
(= (type-of child) "symbol")
|
||||
(= (symbol-name child) "_"))
|
||||
(do (set! found true) replacement)
|
||||
found
|
||||
child
|
||||
(if
|
||||
(list? child)
|
||||
(let
|
||||
((sub (replace-placeholder child replacement)))
|
||||
(if (nil? sub) child (do (set! found true) sub)))
|
||||
child))))
|
||||
node)))
|
||||
(if found result nil))
|
||||
:else nil)))
|
||||
(and
|
||||
(= (type-of child) "symbol")
|
||||
(= (symbol-name child) "_"))
|
||||
(do (set! found true) replacement)
|
||||
(if
|
||||
(list? child)
|
||||
(let
|
||||
((sub (replace-placeholder child replacement)))
|
||||
(if (nil? sub) child (do (set! found true) sub)))
|
||||
child))))
|
||||
node)))
|
||||
(if found result nil)))
|
||||
(_ nil))))
|
||||
|
||||
(define
|
||||
tree-set
|
||||
@@ -851,12 +845,13 @@
|
||||
:effects ()
|
||||
(fn
|
||||
(node old-name new-name)
|
||||
(cond
|
||||
(and (= (type-of node) "symbol") (= (symbol-name node) old-name))
|
||||
(make-symbol new-name)
|
||||
(list? node)
|
||||
(map (fn (child) (rename-in-node child old-name new-name)) node)
|
||||
:else node)))
|
||||
(match
|
||||
(type-of node)
|
||||
("symbol"
|
||||
(if (= (symbol-name node) old-name) (make-symbol new-name) node))
|
||||
("list"
|
||||
(map (fn (child) (rename-in-node child old-name new-name)) node))
|
||||
(_ node))))
|
||||
|
||||
(define
|
||||
count-renames
|
||||
@@ -873,12 +868,12 @@
|
||||
:effects ()
|
||||
(fn
|
||||
(node old-name hits)
|
||||
(cond
|
||||
(and (= (type-of node) "symbol") (= (symbol-name node) old-name))
|
||||
(append! hits true)
|
||||
(list? node)
|
||||
(for-each (fn (child) (count-in-node child old-name hits)) node)
|
||||
:else nil)))
|
||||
(match
|
||||
(type-of node)
|
||||
("symbol" (when (= (symbol-name node) old-name) (append! hits true)))
|
||||
("list"
|
||||
(for-each (fn (child) (count-in-node child old-name hits)) node))
|
||||
(_ nil))))
|
||||
|
||||
(define
|
||||
replace-by-pattern
|
||||
@@ -1341,17 +1336,30 @@
|
||||
(walk node (dict))
|
||||
result)))
|
||||
|
||||
(define find-use-declarations :effects ()
|
||||
(fn (nodes)
|
||||
(let ((uses (list)))
|
||||
(for-each (fn (node)
|
||||
(when (and (list? node) (>= (len node) 2)
|
||||
(= (type-of (first node)) "symbol")
|
||||
(= (symbol-name (first node)) "use"))
|
||||
(for-each (fn (arg)
|
||||
(cond
|
||||
(= (type-of arg) "symbol") (append! uses (symbol-name arg))
|
||||
(= (type-of arg) "string") (append! uses arg)))
|
||||
(rest node))))
|
||||
(define
|
||||
find-use-declarations
|
||||
:effects ()
|
||||
(fn
|
||||
(nodes)
|
||||
(let
|
||||
((uses (list)))
|
||||
(for-each
|
||||
(fn
|
||||
(node)
|
||||
(when
|
||||
(and
|
||||
(list? node)
|
||||
(>= (len node) 2)
|
||||
(= (type-of (first node)) "symbol")
|
||||
(= (symbol-name (first node)) "use"))
|
||||
(for-each
|
||||
(fn
|
||||
(arg)
|
||||
(cond
|
||||
(= (type-of arg) "symbol")
|
||||
(append! uses (symbol-name arg))
|
||||
(= (type-of arg) "string")
|
||||
(append! uses arg)))
|
||||
(rest node))))
|
||||
(if (list? nodes) nodes (list nodes)))
|
||||
uses)))
|
||||
|
||||
Reference in New Issue
Block a user