eliscript 0.0.3 → 0.1.0
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 +6 -6
- 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/worker.eli +2 -0
- package/editor/eliscript-abi.el +170 -0
- package/editor/eliscript-async.el +375 -0
- package/editor/eliscript-bind.el +822 -0
- package/editor/eliscript-compat.el +184 -0
- package/editor/eliscript-contract.el +334 -0
- package/editor/eliscript-data.el +1544 -0
- package/editor/eliscript-js.el +318 -0
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-module.el +340 -0
- package/editor/eliscript-repl.el +1 -1
- package/package.json +4 -1
- 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/emacs-compat.eli +2 -0
- package/runtime/emacs-compat.mjs +2507 -0
- 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 +238 -98
- package/stdlib/managed-literal-protocols.eli +5 -5
- package/stdlib/managed-runtime-order.eli +32 -10
- package/stdlib/managed-runtime-sequence.eli +69 -28
- package/tools/acceptance/check.eli +13 -3
- package/tools/backends/compiler-build.mjs +140 -140
package/stdlib/core/zipper.eli
CHANGED
|
@@ -22,29 +22,45 @@
|
|
|
22
22
|
(defconst zipper-freeze Object/freeze)
|
|
23
23
|
(defconst zipper-is-array Array/isArray)
|
|
24
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))))
|
|
25
27
|
(defun zipper-private-array
|
|
26
28
|
(&rest values)
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
+
(if zipper-has-raw-slot
|
|
30
|
+
values
|
|
31
|
+
(funcall zipper-freeze values)))
|
|
29
32
|
(defun zipper-require-function
|
|
30
33
|
(value label)
|
|
31
34
|
(if (= (value-type value) "function")
|
|
32
35
|
value
|
|
33
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))
|
|
34
44
|
(defun zipper-slot
|
|
35
45
|
(values target-index)
|
|
36
46
|
;; Registered work arrays need no structural probe. Compact copies retain
|
|
37
47
|
;; their format marker without a public persistent wrapper or traversal.
|
|
38
48
|
;; Original Vector/List paths retain their existing indexed/reducible path.
|
|
39
|
-
(if (
|
|
40
|
-
(if (
|
|
49
|
+
(if (zipper-compact-array? values)
|
|
50
|
+
(if (if (>= target-index 0) (< target-index (js-length values)) false)
|
|
41
51
|
(aref values target-index)
|
|
42
52
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
43
53
|
(if (Collection/isVector values)
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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)))
|
|
48
64
|
(let ((index 0) (box zipper-missing))
|
|
49
65
|
(Collection/reduce
|
|
50
66
|
values
|
|
@@ -69,21 +85,19 @@
|
|
|
69
85
|
(Collection/get configuration key))))
|
|
70
86
|
(defun zipper-location
|
|
71
87
|
(node-value path-value configuration)
|
|
72
|
-
(
|
|
88
|
+
(if zipper-has-raw-slot
|
|
89
|
+
(js-call PersistentVector :pairWithMeta node-value path-value configuration)
|
|
90
|
+
(withMeta (persistentVector node-value path-value) configuration)))
|
|
73
91
|
(defun zipper-path
|
|
74
92
|
(left-values right-values parent-path parent-nodes changed)
|
|
75
93
|
;; These frozen work arrays stay lazy at a host boundary. A persistent
|
|
76
94
|
;; wrapper here would materialize the entire private parent graph there.
|
|
77
95
|
(zipper-private-array left-values right-values parent-path parent-nodes changed t))
|
|
78
|
-
(defun zipper-compact-array?
|
|
79
|
-
(value)
|
|
80
|
-
(and (funcall zipper-is-array value) (= (js-length value) 6)
|
|
81
|
-
(eq (aref value zipper-single-parent-index) t)))
|
|
82
96
|
(defun zipper-path-assoc
|
|
83
97
|
(path-value target-index value)
|
|
84
|
-
(if (
|
|
98
|
+
(if (zipper-compact-array? path-value)
|
|
85
99
|
(progn
|
|
86
|
-
(unless (
|
|
100
|
+
(unless (if (funcall zipper-is-integer target-index) (if (>= target-index 0) (<= target-index 4) false) false)
|
|
87
101
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
88
102
|
;; Copy the five state slots and retain the shared parent holder.
|
|
89
103
|
;; Do not route private work through public persistent-vector assoc.
|
|
@@ -96,10 +110,13 @@
|
|
|
96
110
|
(Collection/assoc path-value target-index value)))
|
|
97
111
|
(defun zipper-single-parent?
|
|
98
112
|
(path-value)
|
|
99
|
-
(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(
|
|
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)))
|
|
103
120
|
(defun zipper-parent-node
|
|
104
121
|
(path-value)
|
|
105
122
|
(let ((parents (zipper-slot path-value zipper-parent-nodes-index)))
|
|
@@ -113,60 +130,32 @@
|
|
|
113
130
|
(values)
|
|
114
131
|
(if (nullish? values)
|
|
115
132
|
EMPTY_VECTOR
|
|
116
|
-
(if (
|
|
117
|
-
values
|
|
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))
|
|
118
140
|
(Collection/reduce
|
|
119
141
|
values
|
|
120
142
|
(lambda (result value) (Collection/conj result value))
|
|
121
143
|
EMPTY_VECTOR))))
|
|
122
144
|
(defun zipper-right-list
|
|
123
145
|
(values start-index)
|
|
124
|
-
(let ((
|
|
146
|
+
(let* ((count (Collection/count values))
|
|
147
|
+
(result EMPTY_LIST)
|
|
148
|
+
(index (1- count)))
|
|
125
149
|
(while (>= index start-index)
|
|
126
150
|
(setq result (Collection/conj result (zipper-slot values index)))
|
|
127
151
|
(setq index (1- index)))
|
|
128
152
|
result))
|
|
129
|
-
(defun zipper-children-vector
|
|
130
|
-
(location)
|
|
131
|
-
(zipper-materialize
|
|
132
|
-
(funcall (zipper-config-value location zipper-children-key) (node location))))
|
|
133
|
-
(defun zipper-rebuild-children
|
|
134
|
-
(left-values node-value right-values)
|
|
135
|
-
(if (and (Collection/isVector left-values) (= (get left-values :count) 0)
|
|
136
|
-
(Collection/isList right-values) (= (get right-values :count) 0))
|
|
137
|
-
(persistentVector node-value)
|
|
138
|
-
(let
|
|
139
|
-
(
|
|
140
|
-
(result
|
|
141
|
-
(Collection/reduce
|
|
142
|
-
left-values
|
|
143
|
-
(lambda (values value) (Collection/conj values value))
|
|
144
|
-
EMPTY_VECTOR)))
|
|
145
|
-
(setq result (Collection/conj result node-value))
|
|
146
|
-
(Collection/reduce
|
|
147
|
-
right-values
|
|
148
|
-
(lambda (values value) (Collection/conj values value))
|
|
149
|
-
result))))
|
|
150
|
-
(defun zipper-mark-changed
|
|
151
|
-
(path-value)
|
|
152
|
-
(if (nil? path-value) nil (zipper-path-assoc path-value zipper-changed-index t)))
|
|
153
|
-
(defun zipper-active?
|
|
154
|
-
(location)
|
|
155
|
-
(not (= (zipper-path-value location) zipper-end-path)))
|
|
156
|
-
(defun zipper-require-location
|
|
157
|
-
(location label)
|
|
158
|
-
(if (zipper? location)
|
|
159
|
-
location
|
|
160
|
-
(throw (new globalThis/TypeError (str label " requires a zipper location")))))
|
|
161
|
-
(defun zipper-require-active-location
|
|
162
|
-
(location label)
|
|
163
|
-
(zipper-require-location location label)
|
|
164
|
-
(if (zipper-active? location)
|
|
165
|
-
location
|
|
166
|
-
(throw (new globalThis/TypeError (str label " cannot modify the end location")))))
|
|
167
153
|
(defun zipper-vector-node
|
|
168
154
|
(original children-values)
|
|
169
|
-
(
|
|
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))))
|
|
170
159
|
(defun zipper-list-node
|
|
171
160
|
(original children-values)
|
|
172
161
|
(let ((values (js-array)))
|
|
@@ -175,36 +164,26 @@
|
|
|
175
164
|
(lambda (result value) (js-call result :push value) result)
|
|
176
165
|
values)
|
|
177
166
|
(withMeta (apply persistentList values) (meta original))))
|
|
178
|
-
(
|
|
179
|
-
(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
(
|
|
185
|
-
(configuration
|
|
186
|
-
(persistentHashMap
|
|
187
|
-
(js-array zipper-branch-key branch-predicate)
|
|
188
|
-
(js-array zipper-children-key child-reader)
|
|
189
|
-
(js-array zipper-make-node-key node-builder))))
|
|
190
|
-
(js-call zipper-valid-configs :add configuration)
|
|
191
|
-
(js-call zipper-config-callbacks :set configuration
|
|
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
|
|
192
174
|
(js-object
|
|
193
|
-
"eliscript.zipper/branch"
|
|
194
|
-
"eliscript.zipper/children"
|
|
195
|
-
"eliscript.zipper/make-node" node
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
(root-node)
|
|
199
|
-
(zipper Collection/isVector (lambda (value) value) zipper-vector-node root-node))
|
|
200
|
-
(defun list-zipper
|
|
201
|
-
(root-node)
|
|
202
|
-
(zipper Collection/isList (lambda (value) value) zipper-list-node root-node))
|
|
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))
|
|
203
180
|
(defun zipper?
|
|
204
181
|
(value)
|
|
205
|
-
(if (
|
|
182
|
+
(if (if (Collection/isVector value) (= (Collection/count value) 2) false)
|
|
206
183
|
(let ((configuration (meta value)))
|
|
207
|
-
(if (
|
|
184
|
+
(if (if (eq configuration zipper-vector-config)
|
|
185
|
+
t
|
|
186
|
+
(if (not (nullish? configuration)) (js-call zipper-valid-configs :has configuration) false))
|
|
208
187
|
t
|
|
209
188
|
(let
|
|
210
189
|
(
|
|
@@ -219,10 +198,87 @@
|
|
|
219
198
|
(when valid (js-call zipper-valid-configs :add configuration))
|
|
220
199
|
valid)))
|
|
221
200
|
false))
|
|
201
|
+
(defun zipper-mark-changed
|
|
202
|
+
(path-value)
|
|
203
|
+
(if (nil? path-value) nil (zipper-path-assoc path-value zipper-changed-index t)))
|
|
204
|
+
(defun zipper-active?
|
|
205
|
+
(location)
|
|
206
|
+
(not (= (zipper-path-value location) zipper-end-path)))
|
|
207
|
+
(defun zipper-require-location
|
|
208
|
+
(location label)
|
|
209
|
+
(if (zipper? location)
|
|
210
|
+
location
|
|
211
|
+
(throw (new globalThis/TypeError (str label " requires a zipper location")))))
|
|
212
|
+
(defun zipper-require-active-location
|
|
213
|
+
(location label)
|
|
214
|
+
(zipper-require-location location label)
|
|
215
|
+
(if (zipper-active? location)
|
|
216
|
+
location
|
|
217
|
+
(throw (new globalThis/TypeError (str label " cannot modify the end location")))))
|
|
222
218
|
(defun node
|
|
223
219
|
(location)
|
|
224
220
|
(zipper-require-location location "node")
|
|
225
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))))
|
|
250
|
+
(defun zipper
|
|
251
|
+
(branch-predicate child-reader node-builder root-node)
|
|
252
|
+
(zipper-require-function branch-predicate "zipper branch predicate")
|
|
253
|
+
(zipper-require-function child-reader "zipper child reader")
|
|
254
|
+
(zipper-require-function node-builder "zipper node builder")
|
|
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))))
|
|
276
|
+
(defun vector-zipper
|
|
277
|
+
(root-node)
|
|
278
|
+
(zipper-location root-node nil zipper-vector-config))
|
|
279
|
+
(defun list-zipper
|
|
280
|
+
(root-node)
|
|
281
|
+
(zipper Collection/isList zipper-identity zipper-list-node root-node))
|
|
226
282
|
(defun end?
|
|
227
283
|
(location)
|
|
228
284
|
(zipper-require-location location "end?")
|
|
@@ -255,7 +311,7 @@
|
|
|
255
311
|
(location)
|
|
256
312
|
(zipper-require-location location "path")
|
|
257
313
|
(let ((path-value (zipper-path-value location)))
|
|
258
|
-
(if (
|
|
314
|
+
(if (if (nil? path-value) t (= path-value zipper-end-path))
|
|
259
315
|
nil
|
|
260
316
|
(if (not (zipper-single-parent? path-value))
|
|
261
317
|
(zipper-slot path-value zipper-parent-nodes-index)
|
|
@@ -263,13 +319,27 @@
|
|
|
263
319
|
(if (js-call zipper-public-path-cache :has holder)
|
|
264
320
|
(js-call zipper-public-path-cache :get holder)
|
|
265
321
|
(let ((pending (js-array)) (current path-value) (result EMPTY_VECTOR))
|
|
266
|
-
(while (
|
|
267
|
-
(
|
|
268
|
-
|
|
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)))))
|
|
269
335
|
;; A caller-created original path keeps its original ancestry;
|
|
270
336
|
;; new descents may use it as an unchanged prefix.
|
|
271
337
|
(if (nil? current)
|
|
272
|
-
(
|
|
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))))))
|
|
273
343
|
(progn
|
|
274
344
|
(setq result (zipper-materialize (zipper-slot current zipper-parent-nodes-index)))
|
|
275
345
|
(let ((index (js-length pending)))
|
|
@@ -291,10 +361,10 @@
|
|
|
291
361
|
(if (or (nil? path-value) (= path-value zipper-end-path))
|
|
292
362
|
nil
|
|
293
363
|
(zipper-slot path-value zipper-rights-index))))
|
|
294
|
-
(defun down
|
|
364
|
+
(defun down-slow
|
|
295
365
|
(location)
|
|
296
366
|
(zipper-require-location location "down")
|
|
297
|
-
(if (
|
|
367
|
+
(if (if (not (zipper-active? location)) t (not (zipper-branch-value location)))
|
|
298
368
|
nil
|
|
299
369
|
(let*
|
|
300
370
|
((child-values (zipper-children-vector location))
|
|
@@ -308,11 +378,39 @@
|
|
|
308
378
|
(zipper-slot child-values 0)
|
|
309
379
|
(zipper-path
|
|
310
380
|
EMPTY_VECTOR
|
|
311
|
-
(zipper-right-list child-values 1)
|
|
381
|
+
(if (<= child-count 1) EMPTY_LIST (zipper-right-list child-values 1))
|
|
312
382
|
path-value
|
|
313
383
|
next-parent-nodes
|
|
314
384
|
false)
|
|
315
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)))
|
|
316
414
|
(defun up
|
|
317
415
|
(location)
|
|
318
416
|
(zipper-require-location location "up")
|
|
@@ -445,9 +543,51 @@
|
|
|
445
543
|
(zipper-require-location location "root")
|
|
446
544
|
(if (end? location)
|
|
447
545
|
(node location)
|
|
448
|
-
(let ((
|
|
449
|
-
|
|
450
|
-
|
|
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)))
|
|
451
591
|
(defun insert-left
|
|
452
592
|
(location item)
|
|
453
593
|
(zipper-require-active-location location "insert-left")
|
|
@@ -110,12 +110,12 @@
|
|
|
110
110
|
(and (/= (js* "typeof left") "object") (/= (js* "typeof left") "function"))
|
|
111
111
|
(and (/= (js* "typeof right") "object") (/= (js* "typeof right") "function"))) false)
|
|
112
112
|
(t
|
|
113
|
-
(let ((
|
|
114
|
-
(
|
|
115
|
-
(if (and (= (js* "typeof
|
|
116
|
-
(or (= (js* "typeof
|
|
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
117
|
(implements-protocol-operation? I_EQUIV "equal" right)))
|
|
118
|
-
(eq (js-call
|
|
118
|
+
(eq (js-call leftSlot :call left right managed-literal-equal-values) t)
|
|
119
119
|
(if (and (implements-protocol-operation? I_EQUIV "equal" left)
|
|
120
120
|
(implements-protocol-operation? I_EQUIV "equal" right))
|
|
121
121
|
(eq (funcall (protocol-method I_EQUIV "equal") left right managed-literal-equal-values) t)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
(import "./identifier.mjs" Keyword EliscriptSymbol qualifiedIdentifierName)
|
|
4
4
|
(import "./list.mjs" PersistentList)
|
|
5
5
|
(import "./protocol.mjs" defineProtocol extendProtocolCategory extendProtocolType protocolMethod)
|
|
6
|
-
(import "./
|
|
6
|
+
(import "./transient.mjs" conjBang persistentBang transient)
|
|
7
7
|
(import "./vector.mjs" EMPTY_VECTOR PersistentVector)
|
|
8
8
|
(import "../../stdlib/managed-literals.eli" literal-instance?)
|
|
9
9
|
(import "../../stdlib/managed-literal-protocols.eli" managed-literal-register-protocol-role)
|
|
@@ -69,16 +69,22 @@
|
|
|
69
69
|
|
|
70
70
|
(defun compareValues (left right)
|
|
71
71
|
(cond ((or (eq left right) (and (Number/isNaN left) (Number/isNaN right))) 0)
|
|
72
|
+
((and (= (js* "typeof left") "number") (= (js* "typeof right") "number"))
|
|
73
|
+
(if (Number/isNaN left) 1 (if (Number/isNaN right) -1 (if (< left right) -1 1))))
|
|
74
|
+
((and (= (js* "typeof left") "string") (= (js* "typeof right") "string"))
|
|
75
|
+
(if (< left right) -1 1))
|
|
72
76
|
((nil? left) -1) ((nil? right) 1) ((undefined? left) -1) ((undefined? right) 1)
|
|
73
77
|
(t (comparison-result (funcall dispatch-compare left right) "IComparable/compare"))))
|
|
74
78
|
(defun comparator (comparison)
|
|
75
79
|
(require-function comparison "comparator comparison")
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
(if (eq comparison compareValues)
|
|
81
|
+
compareValues
|
|
82
|
+
(lambda (left right)
|
|
83
|
+
(let ((result (funcall comparison left right)))
|
|
84
|
+
(if (= (js* "typeof result") "number") (comparison-result result "comparator comparison")
|
|
85
|
+
(if (and (not (eq result false)) (not (nullish? result))) -1
|
|
86
|
+
(let ((reverse (funcall comparison right left)))
|
|
87
|
+
(if (and (not (eq reverse false)) (not (nullish? reverse))) 1 0))))))))
|
|
82
88
|
(defun reverseComparator (&rest arguments)
|
|
83
89
|
(when (> (js-length arguments) 1)
|
|
84
90
|
(throw (new globalThis/TypeError "reverseComparator expects zero or one comparator")))
|
|
@@ -88,19 +94,35 @@
|
|
|
88
94
|
(js-call values :sort (lambda (left right)
|
|
89
95
|
(let ((result (funcall comparison (get left :key) (get right :key))))
|
|
90
96
|
(if (= result 0) (- (get left :index) (get right :index)) result))))
|
|
91
|
-
(
|
|
97
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
|
|
98
|
+
(while (< index limit)
|
|
99
|
+
(conjBang builder (get (get values index) :value))
|
|
100
|
+
(setq index (1+ index)))
|
|
101
|
+
(persistentBang builder)))
|
|
92
102
|
(defun collect-decorated (collection key-function)
|
|
93
103
|
(let ((values (js-array)))
|
|
94
104
|
(reduce collection (lambda (result value)
|
|
95
105
|
(js-call result :push (js-object :index (js-length result) :key (funcall key-function value) :value value)) result) values)
|
|
96
106
|
values))
|
|
107
|
+
(defun collect-values (collection)
|
|
108
|
+
(let ((values (js-array)))
|
|
109
|
+
(reduce collection (lambda (result value)
|
|
110
|
+
(js-call result :push value) result) values)
|
|
111
|
+
values))
|
|
112
|
+
(defun sort-values (values comparison)
|
|
113
|
+
(js-call values :sort comparison)
|
|
114
|
+
(let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
|
|
115
|
+
(while (< index limit)
|
|
116
|
+
(conjBang builder (get values index))
|
|
117
|
+
(setq index (1+ index)))
|
|
118
|
+
(persistentBang builder)))
|
|
97
119
|
(defun sort (&rest arguments)
|
|
98
120
|
(unless (or (= (js-length arguments) 1) (= (js-length arguments) 2))
|
|
99
121
|
(throw (new globalThis/TypeError "sort expects a collection or comparator and collection")))
|
|
100
122
|
(let ((comparison (if (= (js-length arguments) 1) compareValues (get arguments 0)))
|
|
101
123
|
(collection (get arguments (1- (js-length arguments)))))
|
|
102
|
-
;;
|
|
103
|
-
(sort-
|
|
124
|
+
;; Collection traversal precedes comparator validation.
|
|
125
|
+
(sort-values (collect-values collection) (comparator comparison))))
|
|
104
126
|
(defun sortBy (key-function &rest arguments)
|
|
105
127
|
(require-function key-function "sortBy key function")
|
|
106
128
|
(unless (or (= (js-length arguments) 1) (= (js-length arguments) 2))
|