eliscript 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/bootstrap/README.md +13 -8
- package/bootstrap/host/build.eli +2 -0
- package/bootstrap/host/bun.eli +2 -0
- package/bootstrap/host/check-cli-legacy.eli +2 -0
- package/bootstrap/host/evaluation-cli.eli +2 -0
- package/bootstrap/host/evaluation.eli +2 -0
- package/bootstrap/host/format-cli.eli +2 -0
- package/bootstrap/host/project-cli-legacy.eli +2 -0
- package/bootstrap/host/project-legacy.eli +2 -0
- package/bootstrap/host/watch-cli.eli +2 -0
- package/bootstrap/host/watch.eli +2 -0
- package/browser/README.md +33 -0
- package/browser/host.eli +2 -0
- package/browser/host.mjs +643 -11
- package/browser/worker.eli +2 -0
- package/browser/worker.mjs +6 -3
- package/dist/browser/host.mjs +643 -11
- package/dist/browser/worker.mjs +6 -3
- package/dist/compiler-artifact.json +1 -1
- package/dist/literal-sources/runtime/core/collection.eli +76 -16
- package/dist/literal-sources/runtime/core/metadata.eli +25 -8
- package/dist/literal-sources/runtime/core/vector.eli +7 -2
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +18 -7
- package/dist/literal-sources/stdlib/managed-literals.eli +121 -66
- package/dist/stage3-release.json +1 -1
- package/package.json +11 -2
- package/platform/README.md +33 -12
- package/platform/browser.eli +2 -0
- package/platform/http.eli +2 -0
- package/platform/worker.eli +2 -0
- package/runtime/README.md +34 -14
- package/runtime/array-text.eli +2 -0
- package/runtime/core/collection-internals.eli +2 -0
- package/runtime/core/collection.eli +2 -0
- package/runtime/core/collection.mjs +99 -17
- package/runtime/core/data-text.eli +2 -0
- package/runtime/core/data.eli +2 -0
- package/runtime/core/data.mjs +7 -5
- package/runtime/core/identifier.eli +2 -0
- package/runtime/core/lazy-sequence.eli +2 -0
- package/runtime/core/list-internals.eli +2 -0
- package/runtime/core/list.eli +2 -0
- package/runtime/core/list.mjs +3 -0
- package/runtime/core/map-internals.eli +2 -0
- package/runtime/core/map.eli +2 -0
- package/runtime/core/map.mjs +5 -0
- package/runtime/core/metadata-internals.eli +2 -0
- package/runtime/core/metadata.eli +2 -0
- package/runtime/core/metadata.mjs +14 -0
- package/runtime/core/object.eli +2 -0
- package/runtime/core/order.eli +2 -0
- package/runtime/core/order.mjs +35 -6
- package/runtime/core/persistent-kind.eli +2 -0
- package/runtime/core/persistent-kind.mjs +6 -0
- package/runtime/core/protocol-error.eli +2 -0
- package/runtime/core/protocol.eli +2 -0
- package/runtime/core/queue-internals.eli +2 -0
- package/runtime/core/queue.eli +2 -0
- package/runtime/core/queue.mjs +3 -0
- package/runtime/core/record.eli +2 -0
- package/runtime/core/regex.eli +2 -0
- package/runtime/core/sequence.eli +2 -0
- package/runtime/core/sequence.mjs +75 -13
- package/runtime/core/set-algebra.eli +2 -0
- package/runtime/core/set-internals.eli +2 -0
- package/runtime/core/set.eli +2 -0
- package/runtime/core/sorted-internals.eli +2 -0
- package/runtime/core/sorted.eli +2 -0
- package/runtime/core/text.eli +2 -0
- package/runtime/core/transducer.eli +2 -0
- package/runtime/core/transient-internals.eli +2 -0
- package/runtime/core/transient.eli +2 -0
- package/runtime/core/transient.mjs +59 -10
- package/runtime/core/truth.eli +2 -0
- package/runtime/core/type.eli +2 -0
- package/runtime/core/value-internals.eli +2 -0
- package/runtime/core/value.eli +2 -0
- package/runtime/core/vector-internals.eli +2 -0
- package/runtime/core/vector-internals.mjs +3 -6
- package/runtime/core/vector.eli +2 -0
- package/runtime/core/vector.mjs +125 -7
- package/runtime/literals.eli +2 -0
- package/runtime/number-radix.eli +2 -0
- package/runtime/source-mapping.eli +2 -0
- package/runtime/testing/list.eli +2 -0
- package/runtime/testing/map.eli +2 -0
- package/runtime/testing/queue.eli +2 -0
- package/runtime/testing/set.eli +2 -0
- package/runtime/testing/sorted.eli +2 -0
- package/runtime/testing/value.eli +2 -0
- package/runtime/testing/vector.eli +2 -0
- package/runtime/wire/http-rpc.eli +2 -0
- package/runtime/wire/markdown.eli +2 -0
- package/runtime/wire/schema.eli +2 -0
- package/runtime/worker-value-codec.eli +2 -0
- package/runtime/worker-value-stream.eli +2 -0
- package/runtime/worker.eli +2 -0
- package/stdlib/README.md +2 -2
- package/stdlib/core/order.eli +36 -10
- package/stdlib/core/seq.eli +104 -75
- package/stdlib/core/zipper.eli +274 -101
- package/stdlib/managed-literal-protocols.eli +18 -7
- package/stdlib/managed-literals.eli +121 -66
- package/stdlib/managed-runtime-collection.eli +76 -16
- package/stdlib/managed-runtime-metadata.eli +25 -8
- package/stdlib/managed-runtime-order.eli +32 -10
- package/stdlib/managed-runtime-sequence.eli +69 -28
- package/stdlib/managed-runtime-vector.eli +7 -2
- package/tools/acceptance/check.eli +13 -3
- package/tools/backends/compiler-build.mjs +140 -140
- package/tools/backends/dist/release-cli.mjs +2 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -1
- package/tools/backends/stage3-targets.mjs +121 -114
- package/bootstrap/host/eliscript-cli-legacy.mjs +0 -37
package/stdlib/core/zipper.eli
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
(import "../../runtime/core/list.mjs" EMPTY_LIST first persistentList rest)
|
|
4
4
|
(import "../../runtime/core/map.mjs" persistentHashMap)
|
|
5
5
|
(import "../../runtime/core/metadata.mjs" meta withMeta)
|
|
6
|
-
(import "../../runtime/core/vector.mjs" EMPTY_VECTOR persistentVector)
|
|
6
|
+
(import "../../runtime/core/vector.mjs" EMPTY_VECTOR PersistentVector persistentVector)
|
|
7
7
|
(defconst zipper-branch-key "eliscript.zipper/branch")
|
|
8
8
|
(defconst zipper-children-key "eliscript.zipper/children")
|
|
9
9
|
(defconst zipper-make-node-key "eliscript.zipper/make-node")
|
|
@@ -17,29 +17,50 @@
|
|
|
17
17
|
(defconst zipper-single-parent-index 5)
|
|
18
18
|
(defconst zipper-public-path-cache (new globalThis/WeakMap))
|
|
19
19
|
(defconst zipper-private-tuples (new globalThis/WeakSet))
|
|
20
|
+
(defconst zipper-valid-configs (new globalThis/WeakSet))
|
|
21
|
+
(defconst zipper-config-callbacks (new globalThis/WeakMap))
|
|
22
|
+
(defconst zipper-freeze Object/freeze)
|
|
23
|
+
(defconst zipper-is-array Array/isArray)
|
|
24
|
+
(defconst zipper-is-integer Number/isInteger)
|
|
25
|
+
(defconst zipper-identity (lambda (value) value))
|
|
26
|
+
(defconst zipper-has-raw-slot (not (undefined? (get PersistentVector :rawSlot))))
|
|
20
27
|
(defun zipper-private-array
|
|
21
28
|
(&rest values)
|
|
22
|
-
(
|
|
23
|
-
|
|
29
|
+
(if zipper-has-raw-slot
|
|
30
|
+
values
|
|
31
|
+
(funcall zipper-freeze values)))
|
|
24
32
|
(defun zipper-require-function
|
|
25
33
|
(value label)
|
|
26
34
|
(if (= (value-type value) "function")
|
|
27
35
|
value
|
|
28
36
|
(throw (new globalThis/TypeError (str label " must be a function")))))
|
|
37
|
+
(defun zipper-compact-array?
|
|
38
|
+
(value)
|
|
39
|
+
(if (funcall zipper-is-array value)
|
|
40
|
+
(if (= (js-length value) 6)
|
|
41
|
+
(eq (aref value zipper-single-parent-index) t)
|
|
42
|
+
false)
|
|
43
|
+
false))
|
|
29
44
|
(defun zipper-slot
|
|
30
45
|
(values target-index)
|
|
31
46
|
;; Registered work arrays need no structural probe. Compact copies retain
|
|
32
47
|
;; their format marker without a public persistent wrapper or traversal.
|
|
33
48
|
;; Original Vector/List paths retain their existing indexed/reducible path.
|
|
34
|
-
(if (
|
|
35
|
-
(if (
|
|
49
|
+
(if (zipper-compact-array? values)
|
|
50
|
+
(if (if (>= target-index 0) (< target-index (js-length values)) false)
|
|
36
51
|
(aref values target-index)
|
|
37
52
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
38
53
|
(if (Collection/isVector values)
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
(if (if zipper-has-raw-slot
|
|
55
|
+
(if (<= (get values :count) 32)
|
|
56
|
+
(if (>= target-index 0) (< target-index (get values :count)) false)
|
|
57
|
+
false)
|
|
58
|
+
false)
|
|
59
|
+
(js-call PersistentVector :rawSlot values target-index)
|
|
60
|
+
(let ((value (Collection/nth values target-index zipper-missing)))
|
|
61
|
+
(if (eq value zipper-missing)
|
|
62
|
+
(throw (new globalThis/TypeError "invalid zipper internal slot"))
|
|
63
|
+
value)))
|
|
43
64
|
(let ((index 0) (box zipper-missing))
|
|
44
65
|
(Collection/reduce
|
|
45
66
|
values
|
|
@@ -53,45 +74,54 @@
|
|
|
53
74
|
(throw (new globalThis/TypeError "invalid zipper internal slot"))
|
|
54
75
|
(get box :value))))))
|
|
55
76
|
(defun zipper-path-value (location) (zipper-slot location 1))
|
|
56
|
-
(defun zipper-config-value
|
|
77
|
+
(defun zipper-config-value
|
|
78
|
+
(location key)
|
|
79
|
+
(let* ((configuration (meta location))
|
|
80
|
+
(callbacks (if (not (nullish? configuration))
|
|
81
|
+
(js-call zipper-config-callbacks :get configuration)
|
|
82
|
+
undefined)))
|
|
83
|
+
(if (not (undefined? callbacks))
|
|
84
|
+
(aref callbacks key)
|
|
85
|
+
(Collection/get configuration key))))
|
|
57
86
|
(defun zipper-location
|
|
58
87
|
(node-value path-value configuration)
|
|
59
|
-
(
|
|
88
|
+
(if zipper-has-raw-slot
|
|
89
|
+
(js-call PersistentVector :pairWithMeta node-value path-value configuration)
|
|
90
|
+
(withMeta (persistentVector node-value path-value) configuration)))
|
|
60
91
|
(defun zipper-path
|
|
61
92
|
(left-values right-values parent-path parent-nodes changed)
|
|
62
93
|
;; These frozen work arrays stay lazy at a host boundary. A persistent
|
|
63
94
|
;; wrapper here would materialize the entire private parent graph there.
|
|
64
95
|
(zipper-private-array left-values right-values parent-path parent-nodes changed t))
|
|
65
|
-
(defun zipper-compact-array?
|
|
66
|
-
(value)
|
|
67
|
-
(and (Array/isArray value) (= (js-length value) 6)
|
|
68
|
-
(eq (aref value zipper-single-parent-index) t)))
|
|
69
96
|
(defun zipper-path-assoc
|
|
70
97
|
(path-value target-index value)
|
|
71
|
-
(if (
|
|
98
|
+
(if (zipper-compact-array? path-value)
|
|
72
99
|
(progn
|
|
73
|
-
(unless (
|
|
100
|
+
(unless (if (funcall zipper-is-integer target-index) (if (>= target-index 0) (<= target-index 4) false) false)
|
|
74
101
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
75
102
|
;; Copy the five state slots and retain the shared parent holder.
|
|
76
103
|
;; Do not route private work through public persistent-vector assoc.
|
|
77
104
|
(zipper-path
|
|
78
|
-
(if (= target-index 0) value (
|
|
79
|
-
(if (= target-index 1) value (
|
|
80
|
-
(if (= target-index 2) value (
|
|
81
|
-
(if (= target-index 3) value (
|
|
82
|
-
(if (= target-index 4) value (
|
|
105
|
+
(if (= target-index 0) value (aref path-value 0))
|
|
106
|
+
(if (= target-index 1) value (aref path-value 1))
|
|
107
|
+
(if (= target-index 2) value (aref path-value 2))
|
|
108
|
+
(if (= target-index 3) value (aref path-value 3))
|
|
109
|
+
(if (= target-index 4) value (aref path-value 4))))
|
|
83
110
|
(Collection/assoc path-value target-index value)))
|
|
84
111
|
(defun zipper-single-parent?
|
|
85
112
|
(path-value)
|
|
86
|
-
(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
(
|
|
113
|
+
(if (zipper-compact-array? path-value)
|
|
114
|
+
t
|
|
115
|
+
(if (Collection/isVector path-value)
|
|
116
|
+
(if (= (Collection/count path-value) 6)
|
|
117
|
+
(eq (zipper-slot path-value zipper-single-parent-index) t)
|
|
118
|
+
false)
|
|
119
|
+
false)))
|
|
90
120
|
(defun zipper-parent-node
|
|
91
121
|
(path-value)
|
|
92
122
|
(let ((parents (zipper-slot path-value zipper-parent-nodes-index)))
|
|
93
123
|
(if (zipper-single-parent? path-value)
|
|
94
|
-
(if (
|
|
124
|
+
(if (funcall zipper-is-array parents)
|
|
95
125
|
(if (> (js-length parents) 0) (aref parents 0)
|
|
96
126
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
97
127
|
(zipper-slot parents 0))
|
|
@@ -100,35 +130,74 @@
|
|
|
100
130
|
(values)
|
|
101
131
|
(if (nullish? values)
|
|
102
132
|
EMPTY_VECTOR
|
|
103
|
-
(Collection/
|
|
104
|
-
values
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
(if (Collection/isVector values)
|
|
134
|
+
(if (nil? (meta values))
|
|
135
|
+
values
|
|
136
|
+
(Collection/reduce
|
|
137
|
+
values
|
|
138
|
+
(lambda (result value) (Collection/conj result value))
|
|
139
|
+
EMPTY_VECTOR))
|
|
140
|
+
(Collection/reduce
|
|
141
|
+
values
|
|
142
|
+
(lambda (result value) (Collection/conj result value))
|
|
143
|
+
EMPTY_VECTOR))))
|
|
107
144
|
(defun zipper-right-list
|
|
108
145
|
(values start-index)
|
|
109
|
-
(let ((
|
|
146
|
+
(let* ((count (Collection/count values))
|
|
147
|
+
(result EMPTY_LIST)
|
|
148
|
+
(index (1- count)))
|
|
110
149
|
(while (>= index start-index)
|
|
111
150
|
(setq result (Collection/conj result (zipper-slot values index)))
|
|
112
151
|
(setq index (1- index)))
|
|
113
152
|
result))
|
|
114
|
-
(defun zipper-
|
|
115
|
-
(
|
|
116
|
-
(
|
|
117
|
-
(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(Collection/reduce
|
|
124
|
-
left-values
|
|
125
|
-
(lambda (values value) (Collection/conj values value))
|
|
126
|
-
EMPTY_VECTOR)))
|
|
127
|
-
(setq result (Collection/conj result node-value))
|
|
153
|
+
(defun zipper-vector-node
|
|
154
|
+
(original children-values)
|
|
155
|
+
(let ((m (meta original)))
|
|
156
|
+
(if (if (nil? m) (if (Collection/isVector children-values) (nil? (meta children-values)) false) false)
|
|
157
|
+
children-values
|
|
158
|
+
(withMeta children-values m))))
|
|
159
|
+
(defun zipper-list-node
|
|
160
|
+
(original children-values)
|
|
161
|
+
(let ((values (js-array)))
|
|
128
162
|
(Collection/reduce
|
|
129
|
-
|
|
130
|
-
(lambda (
|
|
131
|
-
|
|
163
|
+
children-values
|
|
164
|
+
(lambda (result value) (js-call result :push value) result)
|
|
165
|
+
values)
|
|
166
|
+
(withMeta (apply persistentList values) (meta original))))
|
|
167
|
+
(defconst zipper-vector-config
|
|
168
|
+
(let ((cfg (persistentHashMap
|
|
169
|
+
(js-array zipper-branch-key Collection/isVector)
|
|
170
|
+
(js-array zipper-children-key zipper-identity)
|
|
171
|
+
(js-array zipper-make-node-key zipper-vector-node))))
|
|
172
|
+
(js-call zipper-valid-configs :add cfg)
|
|
173
|
+
(js-call zipper-config-callbacks :set cfg
|
|
174
|
+
(js-object
|
|
175
|
+
"eliscript.zipper/branch" Collection/isVector
|
|
176
|
+
"eliscript.zipper/children" zipper-identity
|
|
177
|
+
"eliscript.zipper/make-node" zipper-vector-node
|
|
178
|
+
:fastVector t))
|
|
179
|
+
cfg))
|
|
180
|
+
(defun zipper?
|
|
181
|
+
(value)
|
|
182
|
+
(if (if (Collection/isVector value) (= (Collection/count value) 2) false)
|
|
183
|
+
(let ((configuration (meta value)))
|
|
184
|
+
(if (if (eq configuration zipper-vector-config)
|
|
185
|
+
t
|
|
186
|
+
(if (not (nullish? configuration)) (js-call zipper-valid-configs :has configuration) false))
|
|
187
|
+
t
|
|
188
|
+
(let
|
|
189
|
+
(
|
|
190
|
+
(valid
|
|
191
|
+
(and
|
|
192
|
+
(Collection/isMap configuration)
|
|
193
|
+
(= (value-type (Collection/get configuration zipper-branch-key)) "function")
|
|
194
|
+
(= (value-type (Collection/get configuration zipper-children-key)) "function")
|
|
195
|
+
(=
|
|
196
|
+
(value-type (Collection/get configuration zipper-make-node-key))
|
|
197
|
+
"function"))))
|
|
198
|
+
(when valid (js-call zipper-valid-configs :add configuration))
|
|
199
|
+
valid)))
|
|
200
|
+
false))
|
|
132
201
|
(defun zipper-mark-changed
|
|
133
202
|
(path-value)
|
|
134
203
|
(if (nil? path-value) nil (zipper-path-assoc path-value zipper-changed-index t)))
|
|
@@ -146,52 +215,70 @@
|
|
|
146
215
|
(if (zipper-active? location)
|
|
147
216
|
location
|
|
148
217
|
(throw (new globalThis/TypeError (str label " cannot modify the end location")))))
|
|
149
|
-
(defun
|
|
150
|
-
(
|
|
151
|
-
(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
218
|
+
(defun node
|
|
219
|
+
(location)
|
|
220
|
+
(zipper-require-location location "node")
|
|
221
|
+
(zipper-slot location 0))
|
|
222
|
+
(defun zipper-children-vector
|
|
223
|
+
(location)
|
|
224
|
+
(zipper-materialize
|
|
225
|
+
(funcall (zipper-config-value location zipper-children-key) (node location))))
|
|
226
|
+
(defun zipper-rebuild-children
|
|
227
|
+
(left-values node-value right-values)
|
|
228
|
+
(if (if (eq left-values EMPTY_VECTOR)
|
|
229
|
+
(eq right-values EMPTY_LIST)
|
|
230
|
+
(if (Collection/isVector left-values)
|
|
231
|
+
(if (= (Collection/count left-values) 0)
|
|
232
|
+
(if (Collection/isList right-values) (= (Collection/count right-values) 0) false)
|
|
233
|
+
false)
|
|
234
|
+
false))
|
|
235
|
+
(if zipper-has-raw-slot
|
|
236
|
+
(js-call PersistentVector :single node-value)
|
|
237
|
+
(persistentVector node-value))
|
|
238
|
+
(let
|
|
239
|
+
(
|
|
240
|
+
(result
|
|
241
|
+
(Collection/reduce
|
|
242
|
+
left-values
|
|
243
|
+
(lambda (values value) (Collection/conj values value))
|
|
244
|
+
EMPTY_VECTOR)))
|
|
245
|
+
(setq result (Collection/conj result node-value))
|
|
246
|
+
(Collection/reduce
|
|
247
|
+
right-values
|
|
248
|
+
(lambda (values value) (Collection/conj values value))
|
|
249
|
+
result))))
|
|
160
250
|
(defun zipper
|
|
161
251
|
(branch-predicate child-reader node-builder root-node)
|
|
162
252
|
(zipper-require-function branch-predicate "zipper branch predicate")
|
|
163
253
|
(zipper-require-function child-reader "zipper child reader")
|
|
164
254
|
(zipper-require-function node-builder "zipper node builder")
|
|
165
|
-
(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
255
|
+
(if (if (eq branch-predicate Collection/isVector)
|
|
256
|
+
(if (eq child-reader zipper-identity)
|
|
257
|
+
(eq node-builder zipper-vector-node)
|
|
258
|
+
false)
|
|
259
|
+
false)
|
|
260
|
+
(zipper-location root-node nil zipper-vector-config)
|
|
261
|
+
(let
|
|
262
|
+
(
|
|
263
|
+
(configuration
|
|
264
|
+
(persistentHashMap
|
|
265
|
+
(js-array zipper-branch-key branch-predicate)
|
|
266
|
+
(js-array zipper-children-key child-reader)
|
|
267
|
+
(js-array zipper-make-node-key node-builder))))
|
|
268
|
+
(js-call zipper-valid-configs :add configuration)
|
|
269
|
+
(js-call zipper-config-callbacks :set configuration
|
|
270
|
+
(js-object
|
|
271
|
+
"eliscript.zipper/branch" branch-predicate
|
|
272
|
+
"eliscript.zipper/children" child-reader
|
|
273
|
+
"eliscript.zipper/make-node" node-builder
|
|
274
|
+
:fastVector false))
|
|
275
|
+
(zipper-location root-node nil configuration))))
|
|
173
276
|
(defun vector-zipper
|
|
174
277
|
(root-node)
|
|
175
|
-
(zipper
|
|
278
|
+
(zipper-location root-node nil zipper-vector-config))
|
|
176
279
|
(defun list-zipper
|
|
177
280
|
(root-node)
|
|
178
|
-
(zipper Collection/isList
|
|
179
|
-
(defun zipper?
|
|
180
|
-
(value)
|
|
181
|
-
(if (and (Collection/isVector value) (= (Collection/count value) 2))
|
|
182
|
-
(let ((configuration (meta value)))
|
|
183
|
-
(and
|
|
184
|
-
(Collection/isMap configuration)
|
|
185
|
-
(= (value-type (Collection/get configuration zipper-branch-key)) "function")
|
|
186
|
-
(= (value-type (Collection/get configuration zipper-children-key)) "function")
|
|
187
|
-
(=
|
|
188
|
-
(value-type (Collection/get configuration zipper-make-node-key))
|
|
189
|
-
"function")))
|
|
190
|
-
false))
|
|
191
|
-
(defun node
|
|
192
|
-
(location)
|
|
193
|
-
(zipper-require-location location "node")
|
|
194
|
-
(zipper-slot location 0))
|
|
281
|
+
(zipper Collection/isList zipper-identity zipper-list-node root-node))
|
|
195
282
|
(defun end?
|
|
196
283
|
(location)
|
|
197
284
|
(zipper-require-location location "end?")
|
|
@@ -224,7 +311,7 @@
|
|
|
224
311
|
(location)
|
|
225
312
|
(zipper-require-location location "path")
|
|
226
313
|
(let ((path-value (zipper-path-value location)))
|
|
227
|
-
(if (
|
|
314
|
+
(if (if (nil? path-value) t (= path-value zipper-end-path))
|
|
228
315
|
nil
|
|
229
316
|
(if (not (zipper-single-parent? path-value))
|
|
230
317
|
(zipper-slot path-value zipper-parent-nodes-index)
|
|
@@ -232,16 +319,32 @@
|
|
|
232
319
|
(if (js-call zipper-public-path-cache :has holder)
|
|
233
320
|
(js-call zipper-public-path-cache :get holder)
|
|
234
321
|
(let ((pending (js-array)) (current path-value) (result EMPTY_VECTOR))
|
|
235
|
-
(while (
|
|
236
|
-
(
|
|
237
|
-
|
|
322
|
+
(while (if (not (nil? current)) (zipper-single-parent? current) false)
|
|
323
|
+
(if (zipper-compact-array? current)
|
|
324
|
+
(let ((parents (aref current 3)))
|
|
325
|
+
(js-call pending :push
|
|
326
|
+
(if (funcall zipper-is-array parents)
|
|
327
|
+
(if (> (js-length parents) 0)
|
|
328
|
+
(aref parents 0)
|
|
329
|
+
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
330
|
+
(zipper-slot parents 0)))
|
|
331
|
+
(setq current (aref current 2)))
|
|
332
|
+
(progn
|
|
333
|
+
(js-call pending :push (zipper-parent-node current))
|
|
334
|
+
(setq current (zipper-slot current zipper-parent-path-index)))))
|
|
238
335
|
;; A caller-created original path keeps its original ancestry;
|
|
239
336
|
;; new descents may use it as an unchanged prefix.
|
|
240
|
-
(
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
337
|
+
(if (nil? current)
|
|
338
|
+
(if zipper-has-raw-slot
|
|
339
|
+
(setq result (js-call PersistentVector :from (js-call pending :reverse)))
|
|
340
|
+
(let ((index (js-length pending)))
|
|
341
|
+
(while (> index 0)
|
|
342
|
+
(setq index (1- index) result (Collection/conj result (aref pending index))))))
|
|
343
|
+
(progn
|
|
344
|
+
(setq result (zipper-materialize (zipper-slot current zipper-parent-nodes-index)))
|
|
345
|
+
(let ((index (js-length pending)))
|
|
346
|
+
(while (> index 0)
|
|
347
|
+
(setq index (1- index) result (Collection/conj result (aref pending index)))))))
|
|
245
348
|
(js-call zipper-public-path-cache :set holder result)
|
|
246
349
|
result)))))))
|
|
247
350
|
(defun lefts
|
|
@@ -258,10 +361,10 @@
|
|
|
258
361
|
(if (or (nil? path-value) (= path-value zipper-end-path))
|
|
259
362
|
nil
|
|
260
363
|
(zipper-slot path-value zipper-rights-index))))
|
|
261
|
-
(defun down
|
|
364
|
+
(defun down-slow
|
|
262
365
|
(location)
|
|
263
366
|
(zipper-require-location location "down")
|
|
264
|
-
(if (
|
|
367
|
+
(if (if (not (zipper-active? location)) t (not (zipper-branch-value location)))
|
|
265
368
|
nil
|
|
266
369
|
(let*
|
|
267
370
|
((child-values (zipper-children-vector location))
|
|
@@ -275,11 +378,39 @@
|
|
|
275
378
|
(zipper-slot child-values 0)
|
|
276
379
|
(zipper-path
|
|
277
380
|
EMPTY_VECTOR
|
|
278
|
-
(zipper-right-list child-values 1)
|
|
381
|
+
(if (<= child-count 1) EMPTY_LIST (zipper-right-list child-values 1))
|
|
279
382
|
path-value
|
|
280
383
|
next-parent-nodes
|
|
281
384
|
false)
|
|
282
385
|
(meta location)))))))
|
|
386
|
+
(defun down
|
|
387
|
+
(location)
|
|
388
|
+
(if (if zipper-has-raw-slot
|
|
389
|
+
(if (Collection/isVector location) (= (get location :count) 2) false)
|
|
390
|
+
false)
|
|
391
|
+
(let ((configuration (meta location)))
|
|
392
|
+
(if (eq configuration zipper-vector-config)
|
|
393
|
+
(let ((path-value (js-call PersistentVector :rawSlot location 1)))
|
|
394
|
+
(if (= path-value zipper-end-path)
|
|
395
|
+
nil
|
|
396
|
+
(let ((node-value (js-call PersistentVector :rawSlot location 0)))
|
|
397
|
+
(if (if (Collection/isVector node-value) (nil? (meta node-value)) false)
|
|
398
|
+
(let ((child-count (get node-value :count)))
|
|
399
|
+
(if (= child-count 0)
|
|
400
|
+
nil
|
|
401
|
+
(js-call PersistentVector :pairWithMeta
|
|
402
|
+
(js-call PersistentVector :rawSlot node-value 0)
|
|
403
|
+
(js-array
|
|
404
|
+
EMPTY_VECTOR
|
|
405
|
+
(if (= child-count 1) EMPTY_LIST (zipper-right-list node-value 1))
|
|
406
|
+
path-value
|
|
407
|
+
(js-array node-value)
|
|
408
|
+
false
|
|
409
|
+
t)
|
|
410
|
+
configuration)))
|
|
411
|
+
(down-slow location)))))
|
|
412
|
+
(down-slow location)))
|
|
413
|
+
(down-slow location)))
|
|
283
414
|
(defun up
|
|
284
415
|
(location)
|
|
285
416
|
(zipper-require-location location "up")
|
|
@@ -412,9 +543,51 @@
|
|
|
412
543
|
(zipper-require-location location "root")
|
|
413
544
|
(if (end? location)
|
|
414
545
|
(node location)
|
|
415
|
-
(let ((
|
|
416
|
-
|
|
417
|
-
|
|
546
|
+
(let* ((configuration (meta location))
|
|
547
|
+
(fast-vec (if (eq configuration zipper-vector-config)
|
|
548
|
+
t
|
|
549
|
+
(let ((callbacks (if (not (nullish? configuration))
|
|
550
|
+
(js-call zipper-config-callbacks :get configuration)
|
|
551
|
+
undefined)))
|
|
552
|
+
(if (not (undefined? callbacks)) (get callbacks :fastVector) false))))
|
|
553
|
+
(cur-node (zipper-slot location 0))
|
|
554
|
+
(cur-path (zipper-path-value location))
|
|
555
|
+
(changed false))
|
|
556
|
+
(while (not (nil? cur-path))
|
|
557
|
+
(if (if fast-vec (zipper-compact-array? cur-path) false)
|
|
558
|
+
(let* ((parent-path (aref cur-path 2))
|
|
559
|
+
(parents (aref cur-path 3))
|
|
560
|
+
(parent-node (if (funcall zipper-is-array parents)
|
|
561
|
+
(if (> (js-length parents) 0)
|
|
562
|
+
(aref parents 0)
|
|
563
|
+
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
564
|
+
(zipper-slot parents 0)))
|
|
565
|
+
(step-changed (if changed t (aref cur-path 4))))
|
|
566
|
+
(if step-changed
|
|
567
|
+
(let (( rebuilt (zipper-rebuild-children (aref cur-path 0) cur-node (aref cur-path 1)))
|
|
568
|
+
(m (meta parent-node)))
|
|
569
|
+
(setq cur-node (if (nil? m) rebuilt (withMeta rebuilt m))
|
|
570
|
+
changed t))
|
|
571
|
+
(setq cur-node parent-node))
|
|
572
|
+
(setq cur-path parent-path))
|
|
573
|
+
(let ((parent-path (zipper-slot cur-path zipper-parent-path-index))
|
|
574
|
+
(parent-node (zipper-parent-node cur-path))
|
|
575
|
+
(step-changed (if changed t (zipper-slot cur-path zipper-changed-index))))
|
|
576
|
+
(if step-changed
|
|
577
|
+
(setq
|
|
578
|
+
cur-node
|
|
579
|
+
(make-node
|
|
580
|
+
location
|
|
581
|
+
parent-node
|
|
582
|
+
(zipper-rebuild-children
|
|
583
|
+
(zipper-slot cur-path zipper-lefts-index)
|
|
584
|
+
cur-node
|
|
585
|
+
(zipper-slot cur-path zipper-rights-index)))
|
|
586
|
+
changed
|
|
587
|
+
t)
|
|
588
|
+
(setq cur-node parent-node))
|
|
589
|
+
(setq cur-path parent-path))))
|
|
590
|
+
cur-node)))
|
|
418
591
|
(defun insert-left
|
|
419
592
|
(location item)
|
|
420
593
|
(zipper-require-active-location location "insert-left")
|
|
@@ -109,16 +109,27 @@
|
|
|
109
109
|
((or (nil? left) (nil? right)
|
|
110
110
|
(and (/= (js* "typeof left") "object") (/= (js* "typeof left") "function"))
|
|
111
111
|
(and (/= (js* "typeof right") "object") (/= (js* "typeof right") "function"))) false)
|
|
112
|
-
(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
(t
|
|
113
|
+
(let ((leftSlot (aref left VALUE_EQUAL))
|
|
114
|
+
(rightSlot (aref right VALUE_EQUAL)))
|
|
115
|
+
(if (and (= (js* "typeof leftSlot") "function")
|
|
116
|
+
(or (= (js* "typeof rightSlot") "function")
|
|
117
|
+
(implements-protocol-operation? I_EQUIV "equal" right)))
|
|
118
|
+
(eq (js-call leftSlot :call left right managed-literal-equal-values) t)
|
|
119
|
+
(if (and (implements-protocol-operation? I_EQUIV "equal" left)
|
|
120
|
+
(implements-protocol-operation? I_EQUIV "equal" right))
|
|
121
|
+
(eq (funcall (protocol-method I_EQUIV "equal") left right managed-literal-equal-values) t)
|
|
122
|
+
false))))))
|
|
116
123
|
(defun managed-literal-hash-value (value)
|
|
117
124
|
(recordHashValueCall)
|
|
118
125
|
(if (and (not (nil? value))
|
|
119
|
-
(or (= (js* "typeof value") "object") (= (js* "typeof value") "function"))
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
(or (= (js* "typeof value") "object") (= (js* "typeof value") "function")))
|
|
127
|
+
(let ((slot (aref value VALUE_HASH)))
|
|
128
|
+
(if (= (js* "typeof slot") "function")
|
|
129
|
+
(cachedProtocolHash value (lambda () (js-call slot :call value managed-literal-hash-value)))
|
|
130
|
+
(if (implements-protocol-operation? I_HASH "hash" value)
|
|
131
|
+
(cachedProtocolHash value (lambda () (funcall (protocol-method I_HASH "hash") value managed-literal-hash-value)))
|
|
132
|
+
(hashPrimitiveValue value))))
|
|
122
133
|
(hashPrimitiveValue value)))
|
|
123
134
|
(defun managed-literal-is-reduced (value)
|
|
124
135
|
(and (not (nullish? value))
|