eliscript 0.0.2 → 0.0.3
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 +9 -7
- package/browser/host.mjs +643 -11
- 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 +10 -2
- package/stdlib/core/zipper.eli +73 -40
- 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-vector.eli +7 -2
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eliscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "An Emacs Lisp-flavored language that compiles to modern JavaScript.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -45,6 +45,14 @@
|
|
|
45
45
|
"./platform/worker.mjs": "./platform/worker.mjs",
|
|
46
46
|
"./platform/http": "./platform/http.mjs",
|
|
47
47
|
"./platform/http.mjs": "./platform/http.mjs",
|
|
48
|
+
"./runtime/core/*": "./runtime/core/*.mjs",
|
|
49
|
+
"./runtime/core/*.mjs": "./runtime/core/*.mjs",
|
|
50
|
+
"./runtime/wire/*": "./runtime/wire/*.mjs",
|
|
51
|
+
"./runtime/wire/*.mjs": "./runtime/wire/*.mjs",
|
|
52
|
+
"./runtime/testing/*": "./runtime/testing/*.mjs",
|
|
53
|
+
"./runtime/testing/*.mjs": "./runtime/testing/*.mjs",
|
|
54
|
+
"./dist/stdlib/*": "./dist/stdlib/*.mjs",
|
|
55
|
+
"./dist/stdlib/*.mjs": "./dist/stdlib/*.mjs",
|
|
48
56
|
"./*": "./*"
|
|
49
57
|
},
|
|
50
58
|
"scripts": {
|
|
@@ -61,7 +69,7 @@
|
|
|
61
69
|
"check:source-debugging": "bun tools/debugging/check.mjs",
|
|
62
70
|
"check:dogfood:browsers": "bun tools/browser/matrix.mjs --site examples/dogfood/_site --out examples/dogfood/evidence/browser-matrix.json",
|
|
63
71
|
"check:dogfood": "./bin/eliscript --output dist/dogfood-spec-check.mjs examples/dogfood/tools/spec-check.eli && bun dist/dogfood-spec-check.mjs --root examples/dogfood",
|
|
64
|
-
"build:docs-site": "./bin/eliscript --output dist/docs-site/loader.mjs docs/pages/loader.eli && bun build dist/docs-site/loader.mjs --target=browser --format=iife --outfile dist/docs-site/site.js",
|
|
72
|
+
"build:docs-site": "./bin/eliscript --output dist/docs-site/loader.mjs docs/pages/loader.eli && bun build dist/docs-site/loader.mjs --target=browser --format=iife --minify --outfile dist/docs-site/site.js",
|
|
65
73
|
"build:dogfood-browser": "./bin/eliscript-build --root examples/dogfood --out-dir examples/dogfood/dist/dogfood-browser examples/dogfood/src/renderer/browser.eli && bun build examples/dogfood/dist/dogfood-browser/src/renderer/browser.mjs --target=browser --format=iife --outfile examples/dogfood/dist/site/browser.js",
|
|
66
74
|
"build:browser-playground": "./bin/eliscript-build --root examples/browser-playground/src --out-dir dist/browser-playground examples/browser-playground/src/playground.eli && cp examples/browser-playground/index.html examples/browser-playground/site.css dist/browser-playground/",
|
|
67
75
|
"preview": "python3 -m http.server 8787 --bind 127.0.0.1",
|
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,10 +17,15 @@
|
|
|
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)
|
|
20
25
|
(defun zipper-private-array
|
|
21
26
|
(&rest values)
|
|
22
27
|
(js-call zipper-private-tuples :add values)
|
|
23
|
-
(
|
|
28
|
+
(funcall zipper-freeze values))
|
|
24
29
|
(defun zipper-require-function
|
|
25
30
|
(value label)
|
|
26
31
|
(if (= (value-type value) "function")
|
|
@@ -36,7 +41,7 @@
|
|
|
36
41
|
(aref values target-index)
|
|
37
42
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
38
43
|
(if (Collection/isVector values)
|
|
39
|
-
(let ((value (
|
|
44
|
+
(let ((value (js-call values :nth target-index zipper-missing)))
|
|
40
45
|
(if (eq value zipper-missing)
|
|
41
46
|
(throw (new globalThis/TypeError "invalid zipper internal slot"))
|
|
42
47
|
value))
|
|
@@ -53,7 +58,15 @@
|
|
|
53
58
|
(throw (new globalThis/TypeError "invalid zipper internal slot"))
|
|
54
59
|
(get box :value))))))
|
|
55
60
|
(defun zipper-path-value (location) (zipper-slot location 1))
|
|
56
|
-
(defun zipper-config-value
|
|
61
|
+
(defun zipper-config-value
|
|
62
|
+
(location key)
|
|
63
|
+
(let* ((configuration (meta location))
|
|
64
|
+
(callbacks (if (not (nullish? configuration))
|
|
65
|
+
(js-call zipper-config-callbacks :get configuration)
|
|
66
|
+
undefined)))
|
|
67
|
+
(if (not (undefined? callbacks))
|
|
68
|
+
(aref callbacks key)
|
|
69
|
+
(Collection/get configuration key))))
|
|
57
70
|
(defun zipper-location
|
|
58
71
|
(node-value path-value configuration)
|
|
59
72
|
(withMeta (persistentVector node-value path-value) configuration))
|
|
@@ -64,22 +77,22 @@
|
|
|
64
77
|
(zipper-private-array left-values right-values parent-path parent-nodes changed t))
|
|
65
78
|
(defun zipper-compact-array?
|
|
66
79
|
(value)
|
|
67
|
-
(and (
|
|
80
|
+
(and (funcall zipper-is-array value) (= (js-length value) 6)
|
|
68
81
|
(eq (aref value zipper-single-parent-index) t)))
|
|
69
82
|
(defun zipper-path-assoc
|
|
70
83
|
(path-value target-index value)
|
|
71
84
|
(if (or (js-call zipper-private-tuples :has path-value) (zipper-compact-array? path-value))
|
|
72
85
|
(progn
|
|
73
|
-
(unless (and (
|
|
86
|
+
(unless (and (funcall zipper-is-integer target-index) (>= target-index 0) (<= target-index 4))
|
|
74
87
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
75
88
|
;; Copy the five state slots and retain the shared parent holder.
|
|
76
89
|
;; Do not route private work through public persistent-vector assoc.
|
|
77
90
|
(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 (
|
|
91
|
+
(if (= target-index 0) value (aref path-value 0))
|
|
92
|
+
(if (= target-index 1) value (aref path-value 1))
|
|
93
|
+
(if (= target-index 2) value (aref path-value 2))
|
|
94
|
+
(if (= target-index 3) value (aref path-value 3))
|
|
95
|
+
(if (= target-index 4) value (aref path-value 4))))
|
|
83
96
|
(Collection/assoc path-value target-index value)))
|
|
84
97
|
(defun zipper-single-parent?
|
|
85
98
|
(path-value)
|
|
@@ -91,7 +104,7 @@
|
|
|
91
104
|
(path-value)
|
|
92
105
|
(let ((parents (zipper-slot path-value zipper-parent-nodes-index)))
|
|
93
106
|
(if (zipper-single-parent? path-value)
|
|
94
|
-
(if (
|
|
107
|
+
(if (funcall zipper-is-array parents)
|
|
95
108
|
(if (> (js-length parents) 0) (aref parents 0)
|
|
96
109
|
(throw (new globalThis/TypeError "invalid zipper internal slot")))
|
|
97
110
|
(zipper-slot parents 0))
|
|
@@ -100,10 +113,12 @@
|
|
|
100
113
|
(values)
|
|
101
114
|
(if (nullish? values)
|
|
102
115
|
EMPTY_VECTOR
|
|
103
|
-
(Collection/
|
|
116
|
+
(if (and (Collection/isVector values) (nil? (meta values)))
|
|
104
117
|
values
|
|
105
|
-
(
|
|
106
|
-
|
|
118
|
+
(Collection/reduce
|
|
119
|
+
values
|
|
120
|
+
(lambda (result value) (Collection/conj result value))
|
|
121
|
+
EMPTY_VECTOR))))
|
|
107
122
|
(defun zipper-right-list
|
|
108
123
|
(values start-index)
|
|
109
124
|
(let ((result EMPTY_LIST) (index (1- (Collection/count values))))
|
|
@@ -117,18 +132,21 @@
|
|
|
117
132
|
(funcall (zipper-config-value location zipper-children-key) (node location))))
|
|
118
133
|
(defun zipper-rebuild-children
|
|
119
134
|
(left-values node-value right-values)
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
(
|
|
131
|
-
|
|
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))))
|
|
132
150
|
(defun zipper-mark-changed
|
|
133
151
|
(path-value)
|
|
134
152
|
(if (nil? path-value) nil (zipper-path-assoc path-value zipper-changed-index t)))
|
|
@@ -169,6 +187,12 @@
|
|
|
169
187
|
(js-array zipper-branch-key branch-predicate)
|
|
170
188
|
(js-array zipper-children-key child-reader)
|
|
171
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
|
|
192
|
+
(js-object
|
|
193
|
+
"eliscript.zipper/branch" branch-predicate
|
|
194
|
+
"eliscript.zipper/children" child-reader
|
|
195
|
+
"eliscript.zipper/make-node" node-builder))
|
|
172
196
|
(zipper-location root-node nil configuration)))
|
|
173
197
|
(defun vector-zipper
|
|
174
198
|
(root-node)
|
|
@@ -178,15 +202,22 @@
|
|
|
178
202
|
(zipper Collection/isList (lambda (value) value) zipper-list-node root-node))
|
|
179
203
|
(defun zipper?
|
|
180
204
|
(value)
|
|
181
|
-
(if (and (Collection/isVector value) (= (
|
|
205
|
+
(if (and (Collection/isVector value) (= (get value :count) 2))
|
|
182
206
|
(let ((configuration (meta value)))
|
|
183
|
-
(and
|
|
184
|
-
|
|
185
|
-
(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
207
|
+
(if (and (not (nullish? configuration)) (js-call zipper-valid-configs :has configuration))
|
|
208
|
+
t
|
|
209
|
+
(let
|
|
210
|
+
(
|
|
211
|
+
(valid
|
|
212
|
+
(and
|
|
213
|
+
(Collection/isMap configuration)
|
|
214
|
+
(= (value-type (Collection/get configuration zipper-branch-key)) "function")
|
|
215
|
+
(= (value-type (Collection/get configuration zipper-children-key)) "function")
|
|
216
|
+
(=
|
|
217
|
+
(value-type (Collection/get configuration zipper-make-node-key))
|
|
218
|
+
"function"))))
|
|
219
|
+
(when valid (js-call zipper-valid-configs :add configuration))
|
|
220
|
+
valid)))
|
|
190
221
|
false))
|
|
191
222
|
(defun node
|
|
192
223
|
(location)
|
|
@@ -237,11 +268,13 @@
|
|
|
237
268
|
(setq current (zipper-slot current zipper-parent-path-index)))
|
|
238
269
|
;; A caller-created original path keeps its original ancestry;
|
|
239
270
|
;; new descents may use it as an unchanged prefix.
|
|
240
|
-
(
|
|
241
|
-
(setq result (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
(
|
|
271
|
+
(if (nil? current)
|
|
272
|
+
(setq result (js-call PersistentVector :from (js-call pending :reverse)))
|
|
273
|
+
(progn
|
|
274
|
+
(setq result (zipper-materialize (zipper-slot current zipper-parent-nodes-index)))
|
|
275
|
+
(let ((index (js-length pending)))
|
|
276
|
+
(while (> index 0)
|
|
277
|
+
(setq index (1- index) result (Collection/conj result (aref pending index)))))))
|
|
245
278
|
(js-call zipper-public-path-cache :set holder result)
|
|
246
279
|
result)))))))
|
|
247
280
|
(defun lefts
|
|
@@ -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 ((left-slot (aref left VALUE_EQUAL))
|
|
114
|
+
(right-slot (aref right VALUE_EQUAL)))
|
|
115
|
+
(if (and (= (js* "typeof left-slot") "function")
|
|
116
|
+
(or (= (js* "typeof right-slot") "function")
|
|
117
|
+
(implements-protocol-operation? I_EQUIV "equal" right)))
|
|
118
|
+
(eq (js-call left-slot :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))
|
|
@@ -57,7 +57,28 @@
|
|
|
57
57
|
(defconst literal-prototypes-ready (js-object))
|
|
58
58
|
(defconst literal-keywords (new globalThis/Map))
|
|
59
59
|
(defconst literal-transports (new globalThis/Map))
|
|
60
|
-
(defconst literal-
|
|
60
|
+
(defconst literal-object-freeze Object/freeze)
|
|
61
|
+
(defconst literal-object-is-frozen Object/isFrozen)
|
|
62
|
+
(defconst literal-object-has-own Object/hasOwn)
|
|
63
|
+
(defconst literal-object-create Object/create)
|
|
64
|
+
(defconst literal-object-get-prototype-of Object/getPrototypeOf)
|
|
65
|
+
(defconst literal-object-get-own-property-descriptor Object/getOwnPropertyDescriptor)
|
|
66
|
+
(defconst literal-object-prototype (get globalThis/Object :prototype))
|
|
67
|
+
(defconst literal-array-is-array Array/isArray)
|
|
68
|
+
(defconst literal-symbol-iterator (get globalThis/Symbol :iterator))
|
|
69
|
+
(defconst literal-symbol-has-instance (get globalThis/Symbol :hasInstance))
|
|
70
|
+
(defconst literal-symbol-to-string-tag (get globalThis/Symbol :toStringTag))
|
|
71
|
+
(defconst literal-data-descriptor
|
|
72
|
+
(let ((descriptor (funcall literal-object-create nil)))
|
|
73
|
+
(put descriptor :value undefined)
|
|
74
|
+
(put descriptor :writable t)
|
|
75
|
+
(put descriptor :enumerable t)
|
|
76
|
+
(put descriptor :configurable t)
|
|
77
|
+
descriptor))
|
|
78
|
+
(defvar literal-has-transients false)
|
|
79
|
+
(defun literal-node-owner (node)
|
|
80
|
+
(if literal-has-transients (get node :owner nil) nil))
|
|
81
|
+
(defconst literal-token (funcall literal-object-freeze (js-object)))
|
|
61
82
|
(defconst literal-missing (funcall globalThis/Symbol "eliscript.collection.missing"))
|
|
62
83
|
(defconst literal-value-type (js-call globalThis/Symbol :for "eliscript.value.type"))
|
|
63
84
|
(defconst literal-list-state (funcall globalThis/Symbol "eliscript.list.state"))
|
|
@@ -71,7 +92,10 @@
|
|
|
71
92
|
(defun literal-fail (message) (throw (new globalThis/TypeError message)))
|
|
72
93
|
(defun literal-range (message) (throw (new globalThis/RangeError message)))
|
|
73
94
|
(defun literal-own-data (target key value)
|
|
74
|
-
(
|
|
95
|
+
(put literal-data-descriptor :value value)
|
|
96
|
+
(Reflect/defineProperty target key literal-data-descriptor)
|
|
97
|
+
(put literal-data-descriptor :value undefined)
|
|
98
|
+
target)
|
|
75
99
|
(defun literal-install-method (prototype key name arity implementation)
|
|
76
100
|
(let ((method (literal-make-method implementation name)))
|
|
77
101
|
(Object/defineProperty method "length" (js-object :value arity :configurable t))
|
|
@@ -108,27 +132,27 @@
|
|
|
108
132
|
(literal-fail "PersistentList values must be created with persistentList or PersistentList.from"))
|
|
109
133
|
(let ((receiver (js* "this")))
|
|
110
134
|
(literal-own-data receiver literal-list-state
|
|
111
|
-
(
|
|
112
|
-
(
|
|
135
|
+
(funcall literal-object-freeze (js-object :count count :empty empty :value value :rest rest :metadata metadata)))
|
|
136
|
+
(funcall literal-object-freeze receiver)))
|
|
113
137
|
(defun PersistentVector (token count shift root tail &optional metadata)
|
|
114
138
|
(when (not (eq token literal-token))
|
|
115
139
|
(literal-fail "PersistentVector values must be created with persistentVector or PersistentVector.from"))
|
|
116
140
|
(let ((receiver (js* "this")))
|
|
117
141
|
(literal-own-data receiver literal-vector-state
|
|
118
|
-
(
|
|
119
|
-
(
|
|
142
|
+
(funcall literal-object-freeze (js-object :count count :shift shift :root root :tail tail :metadata metadata)))
|
|
143
|
+
(funcall literal-object-freeze receiver)))
|
|
120
144
|
(defun PersistentHashMap (token count root &optional metadata)
|
|
121
145
|
(when (not (eq token literal-token))
|
|
122
146
|
(literal-fail "PersistentHashMap values must be created with persistentHashMap or PersistentHashMap.from"))
|
|
123
147
|
(let ((receiver (js* "this")))
|
|
124
|
-
(literal-own-data receiver literal-map-state (
|
|
125
|
-
(
|
|
148
|
+
(literal-own-data receiver literal-map-state (funcall literal-object-freeze (js-object :count count :root root :metadata metadata)))
|
|
149
|
+
(funcall literal-object-freeze receiver)))
|
|
126
150
|
(defun PersistentHashSet (token map &optional metadata)
|
|
127
151
|
(when (or (not (eq token literal-token)) (not (= (literal-type map) 3)))
|
|
128
152
|
(literal-fail "PersistentHashSet values must be created with persistentHashSet or PersistentHashSet.from"))
|
|
129
153
|
(let ((receiver (js* "this")))
|
|
130
|
-
(literal-own-data receiver literal-set-state (
|
|
131
|
-
(
|
|
154
|
+
(literal-own-data receiver literal-set-state (funcall literal-object-freeze (js-object :map map :metadata metadata)))
|
|
155
|
+
(funcall literal-object-freeze receiver)))
|
|
132
156
|
(defun PersistentQueue (token count front rear &optional metadata)
|
|
133
157
|
(when (not (eq token literal-token))
|
|
134
158
|
(literal-fail "PersistentQueue values must be created with persistentQueue or PersistentQueue.from"))
|
|
@@ -140,38 +164,38 @@
|
|
|
140
164
|
(literal-fail "invalid persistent queue state"))
|
|
141
165
|
(let ((receiver (js* "this")))
|
|
142
166
|
(literal-own-data receiver literal-queue-state
|
|
143
|
-
(
|
|
144
|
-
(
|
|
167
|
+
(funcall literal-object-freeze (js-object :count count :front front :rear rear :metadata metadata)))
|
|
168
|
+
(funcall literal-object-freeze receiver)))
|
|
145
169
|
(defun VectorNode (&optional slots owner)
|
|
146
170
|
(let ((receiver (js* "this")))
|
|
147
171
|
(put receiver :owner owner) (put receiver :slots (if (nil? slots) (js-array) slots))
|
|
148
|
-
(when (nil? owner) (
|
|
172
|
+
(when (nil? owner) (funcall literal-object-freeze (get receiver :slots)) (funcall literal-object-freeze receiver)) receiver))
|
|
149
173
|
(defun MapEntry (key value hash)
|
|
150
174
|
(let ((receiver (js* "this")))
|
|
151
|
-
(put receiver :key key) (put receiver :value value) (put receiver :hash (uint32 hash)) (
|
|
175
|
+
(put receiver :key key) (put receiver :value value) (put receiver :hash (uint32 hash)) (funcall literal-object-freeze receiver)))
|
|
152
176
|
(defun BitmapIndexedNode (&optional bitmap items owner)
|
|
153
177
|
(let ((receiver (js* "this")))
|
|
154
178
|
(put receiver :bitmap (uint32 (if (nil? bitmap) 0 bitmap))) (put receiver :owner owner)
|
|
155
179
|
(put receiver :items (if (nil? items) (js-array) items))
|
|
156
|
-
(when (nil? owner) (
|
|
180
|
+
(when (nil? owner) (funcall literal-object-freeze (get receiver :items)) (funcall literal-object-freeze receiver)) receiver))
|
|
157
181
|
(defun ArrayNode (count children &optional owner)
|
|
158
182
|
(let ((receiver (js* "this")))
|
|
159
183
|
(put receiver :count count) (put receiver :owner owner) (put receiver :children children)
|
|
160
|
-
(when (nil? owner) (
|
|
184
|
+
(when (nil? owner) (funcall literal-object-freeze children) (funcall literal-object-freeze receiver)) receiver))
|
|
161
185
|
(defun HashCollisionNode (hash entries &optional owner)
|
|
162
186
|
(let ((receiver (js* "this")))
|
|
163
187
|
(put receiver :hash (uint32 hash)) (put receiver :owner owner) (put receiver :entries entries)
|
|
164
|
-
(when (nil? owner) (
|
|
188
|
+
(when (nil? owner) (funcall literal-object-freeze entries) (funcall literal-object-freeze receiver)) receiver))
|
|
165
189
|
(defun literal-vector-node-view (node level)
|
|
166
190
|
(let ((cached (js-call literal-node-views :get node)))
|
|
167
191
|
(if (not (undefined? cached))
|
|
168
192
|
(progn
|
|
169
|
-
(unless (nil? (
|
|
193
|
+
(unless (nil? (literal-node-owner node))
|
|
170
194
|
(let ((source (get node :slots)) (slots (get cached :slots)) (index 0))
|
|
171
195
|
(put slots :length (js-length source))
|
|
172
196
|
(while (< index (js-length source))
|
|
173
197
|
(let ((item (get source index)))
|
|
174
|
-
(if (
|
|
198
|
+
(if (funcall literal-object-has-own source index)
|
|
175
199
|
(put slots index (if (and (> level 0) (not (nullish? item)))
|
|
176
200
|
(literal-vector-node-view item (- level 5)) item))
|
|
177
201
|
(Reflect/deleteProperty slots index)))
|
|
@@ -183,14 +207,14 @@
|
|
|
183
207
|
(put values index (if (and (> level 0) (not (nil? value)))
|
|
184
208
|
(literal-vector-node-view value (- level 5)) value))))
|
|
185
209
|
(setq index (1+ index)))
|
|
186
|
-
(let ((view (new VectorNode values (
|
|
210
|
+
(let ((view (new VectorNode values (literal-node-owner node))))
|
|
187
211
|
(js-call literal-node-views :set node view) view)))))
|
|
188
212
|
(defun literal-map-node-view (node)
|
|
189
213
|
(if (nil? node) literal-empty-bitmap
|
|
190
214
|
(let ((cached (js-call literal-node-views :get node)))
|
|
191
215
|
(if (not (undefined? cached))
|
|
192
216
|
(progn
|
|
193
|
-
(unless (or (= (get node :kind) "entry") (nil? (
|
|
217
|
+
(unless (or (= (get node :kind) "entry") (nil? (literal-node-owner node)))
|
|
194
218
|
(let* ((kind (get node :kind)) (field (if (= kind "bitmap") "items" (if (= kind "array") "children" "entries")))
|
|
195
219
|
(source (get node field)) (items (get cached field)) (index 0))
|
|
196
220
|
(put items :length (js-length source))
|
|
@@ -208,9 +232,9 @@
|
|
|
208
232
|
(let ((child (get source index)))
|
|
209
233
|
(put items index (if (nil? child) undefined (literal-map-node-view child))))
|
|
210
234
|
(setq index (1+ index)))
|
|
211
|
-
(cond ((= kind "bitmap") (new BitmapIndexedNode (get node :bitmap) items (
|
|
212
|
-
((= kind "array") (new ArrayNode (get node :count) items (
|
|
213
|
-
(t (new HashCollisionNode (get node :hash) items (
|
|
235
|
+
(cond ((= kind "bitmap") (new BitmapIndexedNode (get node :bitmap) items (literal-node-owner node)))
|
|
236
|
+
((= kind "array") (new ArrayNode (get node :count) items (literal-node-owner node)))
|
|
237
|
+
(t (new HashCollisionNode (get node :hash) items (literal-node-owner node))))))))
|
|
214
238
|
(js-call literal-node-views :set node view) view)))))
|
|
215
239
|
(defun literal-map-root-view (root)
|
|
216
240
|
(if (nil? root) literal-empty-bitmap
|
|
@@ -218,7 +242,7 @@
|
|
|
218
242
|
(let ((child (literal-map-node-view root)) (cached (js-call literal-map-root-views :get root)))
|
|
219
243
|
(if (not (undefined? cached)) cached
|
|
220
244
|
(let ((view (new BitmapIndexedNode (uint32 (bit-shift-left 1 (bit-and (get root :hash) 31)))
|
|
221
|
-
(js-array child) (
|
|
245
|
+
(js-array child) (literal-node-owner root))))
|
|
222
246
|
(js-call literal-map-root-views :set root view) view)))
|
|
223
247
|
(literal-map-node-view root))))
|
|
224
248
|
|
|
@@ -256,8 +280,10 @@
|
|
|
256
280
|
(cond
|
|
257
281
|
((= type 2) (new PersistentVector literal-token (persistent-vector-count data) (get data :shift)
|
|
258
282
|
(literal-vector-node-view (get data :root) (get data :shift))
|
|
259
|
-
(
|
|
260
|
-
(
|
|
283
|
+
(let ((tail (get data :tail)))
|
|
284
|
+
(if (js-call literal-editable-results :has data)
|
|
285
|
+
tail
|
|
286
|
+
(funcall literal-object-freeze tail))) (persistent-vector-meta data)))
|
|
261
287
|
((= type 3) (new PersistentHashMap literal-token (persistent-map-count data)
|
|
262
288
|
(literal-map-root-view (get data :root)) (persistent-map-meta data)))
|
|
263
289
|
((= type 4) (new PersistentHashSet literal-token (literal-wrap 3 (get data :map)) (persistent-set-meta data)))
|
|
@@ -281,7 +307,9 @@
|
|
|
281
307
|
(defun literal-list (&rest values)
|
|
282
308
|
(literal-initialize-prototype 1) (js-call PersistentList :from values))
|
|
283
309
|
(defun literal-vector (&rest values)
|
|
284
|
-
(literal-initialize-prototype 2)
|
|
310
|
+
(literal-initialize-prototype 2)
|
|
311
|
+
(when (<= (js-length values) 32) (funcall literal-object-freeze values))
|
|
312
|
+
(literal-vector-from-array-values values))
|
|
285
313
|
(defun literal-map (&rest values)
|
|
286
314
|
(when (/= (% (js-length values) 2) 0) (literal-fail "hash-map expects complete key/value pairs"))
|
|
287
315
|
(let ((entries (js-array)) (index 0) (pair 0))
|
|
@@ -298,12 +326,27 @@
|
|
|
298
326
|
(let ((type (literal-type collection)))
|
|
299
327
|
(cond ((or (and (>= type 1) (<= type 5)) (= type 8)) (get collection :count))
|
|
300
328
|
((nullish? collection) 0)
|
|
301
|
-
((or (
|
|
329
|
+
((or (funcall literal-array-is-array collection) (= (js* "typeof collection") "string")) (js-length collection))
|
|
302
330
|
((or (literal-instance? collection globalThis/Map) (literal-instance? collection globalThis/Set)) (get collection :size))
|
|
303
|
-
((= (
|
|
331
|
+
((= (funcall literal-object-get-prototype-of collection) literal-object-prototype) (js-length (Object/keys collection)))
|
|
304
332
|
(t (literal-fail "value does not implement ICounted/count")))))
|
|
305
333
|
(defun literal-instance? (value constructor)
|
|
306
|
-
(
|
|
334
|
+
(cond
|
|
335
|
+
((or (eq constructor PersistentVector) (eq constructor PersistentList)
|
|
336
|
+
(eq constructor PersistentHashMap) (eq constructor PersistentHashSet)
|
|
337
|
+
(eq constructor PersistentQueue))
|
|
338
|
+
(if (or (nullish? value) (and (/= (js* "typeof value") "object") (/= (js* "typeof value") "function")))
|
|
339
|
+
false
|
|
340
|
+
(let ((type (literal-type value)))
|
|
341
|
+
(if (> type 0)
|
|
342
|
+
(if (eq constructor PersistentVector)
|
|
343
|
+
(or (= type 2) (= type 8))
|
|
344
|
+
(= type (cond ((eq constructor PersistentList) 1) ((eq constructor PersistentHashMap) 3)
|
|
345
|
+
((eq constructor PersistentHashSet) 4) (t 5))))
|
|
346
|
+
(if (funcall literal-array-is-array value)
|
|
347
|
+
false
|
|
348
|
+
(js-call (get constructor literal-symbol-has-instance) :call constructor value))))))
|
|
349
|
+
(t (js-call (get constructor literal-symbol-has-instance) :call constructor value))))
|
|
307
350
|
(defun literal-nth (collection index &rest not-found)
|
|
308
351
|
(let ((type (literal-type collection)) (fallback (if (and (> (js-length not-found) 0) (not (undefined? (get not-found 0))))
|
|
309
352
|
(get not-found 0) literal-missing)))
|
|
@@ -878,12 +921,12 @@
|
|
|
878
921
|
(let ((out (if (= type 1) (persistent-list-nth data index not-found) (persistent-vector-nth data index not-found))))
|
|
879
922
|
(if (eq out literal-missing)
|
|
880
923
|
(literal-range (str "nth index " (funcall globalThis/String index) " is outside [0, " (literal-data-count type data) ")")) out)))
|
|
881
|
-
(defun literal-list-nth-method (index &
|
|
924
|
+
(defun literal-list-nth-method (index &optional not-found)
|
|
882
925
|
(literal-nth-data 1 (literal-data (js* "this") 1) index
|
|
883
|
-
(if (
|
|
884
|
-
(defun literal-vector-nth-method (index &
|
|
926
|
+
(if (undefined? not-found) literal-missing not-found)))
|
|
927
|
+
(defun literal-vector-nth-method (index &optional not-found)
|
|
885
928
|
(literal-nth-data 2 (literal-data (js* "this") 2) index
|
|
886
|
-
(if (
|
|
929
|
+
(if (undefined? not-found) literal-missing not-found)))
|
|
887
930
|
(defun literal-list-first-method (&optional not-found)
|
|
888
931
|
(let ((state (aref (js* "this") literal-list-state))) (if (get state :empty) not-found (get state :value))))
|
|
889
932
|
(defun literal-list-rest-method ()
|
|
@@ -959,39 +1002,50 @@
|
|
|
959
1002
|
(let ((length (js-length values)))
|
|
960
1003
|
(when (> length 2147483647)
|
|
961
1004
|
(literal-range "persistent collection cannot exceed 2147483647 values"))
|
|
962
|
-
(
|
|
963
|
-
(
|
|
964
|
-
|
|
965
|
-
(let ((value (get values count)))
|
|
966
|
-
(if (< tail-len 32)
|
|
967
|
-
(progn (put tail tail-len value) (setq tail-len (1+ tail-len)))
|
|
968
|
-
(let ((tail-node (js-object :slots tail)))
|
|
969
|
-
(if (> (unsigned-bit-shift-right count 5) (bit-shift-left 1 shift))
|
|
970
|
-
(setq root (js-object :slots (js-array root (literal-vector-new-path shift tail-node)))
|
|
971
|
-
shift (+ shift 5))
|
|
972
|
-
(literal-vector-push-tail-mutable shift root tail-node count))
|
|
973
|
-
(setq tail (js-array value) tail-len 1))))
|
|
974
|
-
(setq count (1+ count)))
|
|
1005
|
+
(cond
|
|
1006
|
+
((= length 0) (literal-vector-empty))
|
|
1007
|
+
((<= length 32)
|
|
975
1008
|
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
976
|
-
:count
|
|
1009
|
+
:count length :shift 5 :root (get literal-empty-vector-data :root)
|
|
1010
|
+
:tail (if (funcall literal-object-is-frozen values) values (funcall literal-object-freeze (js-call values :slice)))
|
|
1011
|
+
:metadata nil)))
|
|
1012
|
+
(t
|
|
1013
|
+
(let ((count 0) (shift 5) (root (js-object :slots (js-array))) (tail (js-array)) (tail-len 0))
|
|
1014
|
+
(while (< count length)
|
|
1015
|
+
(let ((value (get values count)))
|
|
1016
|
+
(if (< tail-len 32)
|
|
1017
|
+
(progn (put tail tail-len value) (setq tail-len (1+ tail-len)))
|
|
1018
|
+
(let ((tail-node (js-object :slots tail)))
|
|
1019
|
+
(if (> (unsigned-bit-shift-right count 5) (bit-shift-left 1 shift))
|
|
1020
|
+
(setq root (js-object :slots (js-array root (literal-vector-new-path shift tail-node)))
|
|
1021
|
+
shift (+ shift 5))
|
|
1022
|
+
(literal-vector-push-tail-mutable shift root tail-node count))
|
|
1023
|
+
(setq tail (js-array value) tail-len 1))))
|
|
1024
|
+
(setq count (1+ count)))
|
|
1025
|
+
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
1026
|
+
:count count :shift shift :root root :tail (funcall literal-object-freeze tail) :metadata nil)))))))
|
|
977
1027
|
(defun literal-vector-from (iterable)
|
|
978
1028
|
(if (or (= (literal-type iterable) 2) (= (literal-type iterable) 8)) iterable
|
|
979
|
-
(
|
|
980
|
-
(literal-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
(
|
|
986
|
-
(
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1029
|
+
(if (and (funcall literal-array-is-array iterable) (not (funcall literal-object-has-own iterable literal-symbol-iterator)))
|
|
1030
|
+
(literal-vector-from-array-values iterable)
|
|
1031
|
+
(let ((count 0) (shift 5) (root (get literal-empty-vector-data :root)) (tail (js-array)) (tail-len 0))
|
|
1032
|
+
(literal-each iterable (lambda (value)
|
|
1033
|
+
(when (= count 2147483647)
|
|
1034
|
+
(literal-range "persistent collection cannot exceed 2147483647 values"))
|
|
1035
|
+
(if (< tail-len 32)
|
|
1036
|
+
(progn (put tail tail-len value) (setq tail-len (1+ tail-len)))
|
|
1037
|
+
(let ((tail-node (js-object :slots tail)))
|
|
1038
|
+
(when (eq root (get literal-empty-vector-data :root))
|
|
1039
|
+
(setq root (js-object :slots (js-array))))
|
|
1040
|
+
(if (> (unsigned-bit-shift-right count 5) (bit-shift-left 1 shift))
|
|
1041
|
+
(setq root (js-object :slots (js-array root (literal-vector-new-path shift tail-node)))
|
|
1042
|
+
shift (+ shift 5))
|
|
1043
|
+
(literal-vector-push-tail-mutable shift root tail-node count))
|
|
1044
|
+
(setq tail (js-array value) tail-len 1)))
|
|
1045
|
+
(setq count (1+ count))))
|
|
1046
|
+
(if (= count 0) (literal-vector-empty)
|
|
1047
|
+
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
1048
|
+
:count count :shift shift :root root :tail (funcall literal-object-freeze tail) :metadata nil)))))))
|
|
995
1049
|
(defun literal-map-from (iterable)
|
|
996
1050
|
(if (= (literal-type iterable) 3) iterable
|
|
997
1051
|
(let ((data literal-empty-map-data))
|
|
@@ -1127,6 +1181,7 @@
|
|
|
1127
1181
|
(put view :tail (get state :tail)))
|
|
1128
1182
|
(put view :root (literal-map-root-view (get state :root)))))) receiver))
|
|
1129
1183
|
(defun literal-transient-build (receiver type source state)
|
|
1184
|
+
(setq literal-has-transients t)
|
|
1130
1185
|
(literal-initialize-transient-prototype type)
|
|
1131
1186
|
(let ((view (if (= type 4)
|
|
1132
1187
|
(js-object :active t :source source :sourceMap (get (aref source literal-set-state) :map)
|
|
@@ -1402,7 +1457,7 @@
|
|
|
1402
1457
|
(js-object :kind "protocol-method" :protocol (get owner :protocol) :operation (get owner :operation))))
|
|
1403
1458
|
(lambda (record) (get (get (get record :protocol) :operations) (get record :operation))))
|
|
1404
1459
|
(defun literal-protocol-for-role (role) (managed-literal-protocol-for-role role))
|
|
1405
|
-
(export literal-list literal-vector literal-map literal-set literal-queue literal-keyword literal-symbol literal-binding-lookup
|
|
1460
|
+
(export literal-list literal-vector literal-vector-from-array-values literal-map literal-set literal-queue literal-keyword literal-symbol literal-binding-lookup
|
|
1406
1461
|
literal-count literal-nth literal-get literal-first literal-rest literal-cons literal-equal literal-hash
|
|
1407
1462
|
literal-mix literal-finish literal-string-hash literal-entry literal-each
|
|
1408
1463
|
literal-conj literal-assoc literal-dissoc literal-disj literal-peek literal-pop literal-meta literal-with-meta
|