eliscript 0.0.1

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.
Files changed (195) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +135 -0
  3. package/bin/eliscript +16 -0
  4. package/bin/eliscript-bootstrap +15 -0
  5. package/bin/eliscript-build +15 -0
  6. package/bin/eliscript-check +15 -0
  7. package/bin/eliscript-eval +15 -0
  8. package/bin/eliscript-format +15 -0
  9. package/bin/eliscript-org +10 -0
  10. package/bin/eliscript-portable +17 -0
  11. package/bin/eliscript-seed +10 -0
  12. package/bin/eliscript-seed-build +10 -0
  13. package/bin/eliscript-watch +15 -0
  14. package/bootstrap/README.md +100 -0
  15. package/bootstrap/compiler/analyzer.eli +1426 -0
  16. package/bootstrap/compiler/compiler.eli +472 -0
  17. package/bootstrap/compiler/emitter.eli +1745 -0
  18. package/bootstrap/compiler/expander.eli +2522 -0
  19. package/bootstrap/compiler/formatter.eli +359 -0
  20. package/bootstrap/compiler/ir.eli +297 -0
  21. package/bootstrap/compiler/lower.eli +661 -0
  22. package/bootstrap/compiler/project.eli +1120 -0
  23. package/bootstrap/compiler/reader.eli +321 -0
  24. package/bootstrap/compiler/source-map.eli +165 -0
  25. package/bootstrap/compiler/symbol.eli +92 -0
  26. package/bootstrap/compiler/syntax.eli +54 -0
  27. package/bootstrap/compiler/transient-analysis.eli +825 -0
  28. package/bootstrap/host/build.mjs +28 -0
  29. package/bootstrap/host/bun.mjs +282 -0
  30. package/bootstrap/host/check-cli.mjs +163 -0
  31. package/bootstrap/host/eliscript-cli.mjs +36 -0
  32. package/bootstrap/host/evaluation-cli.mjs +401 -0
  33. package/bootstrap/host/evaluation.mjs +560 -0
  34. package/bootstrap/host/format-cli.mjs +139 -0
  35. package/bootstrap/host/project-cli.mjs +295 -0
  36. package/bootstrap/host/project.mjs +1080 -0
  37. package/bootstrap/host/watch-cli.mjs +129 -0
  38. package/bootstrap/host/watch.mjs +267 -0
  39. package/browser/host.mjs +357 -0
  40. package/browser/worker.mjs +60 -0
  41. package/compiler/README.md +118 -0
  42. package/compiler/eliscript-analyzer.el +716 -0
  43. package/compiler/eliscript-cli.el +108 -0
  44. package/compiler/eliscript-diagnostic.el +158 -0
  45. package/compiler/eliscript-emitter.el +1351 -0
  46. package/compiler/eliscript-evaluation.el +259 -0
  47. package/compiler/eliscript-expander.el +1630 -0
  48. package/compiler/eliscript-form.el +79 -0
  49. package/compiler/eliscript-ir-emitter.el +1460 -0
  50. package/compiler/eliscript-ir.el +356 -0
  51. package/compiler/eliscript-lower.el +463 -0
  52. package/compiler/eliscript-macro-eval.el +811 -0
  53. package/compiler/eliscript-parameters.el +324 -0
  54. package/compiler/eliscript-portable.el +492 -0
  55. package/compiler/eliscript-project-cli.el +156 -0
  56. package/compiler/eliscript-project.el +1676 -0
  57. package/compiler/eliscript-reader.el +421 -0
  58. package/compiler/eliscript-source-map.el +192 -0
  59. package/compiler/eliscript-symbol.el +101 -0
  60. package/compiler/eliscript-transient-analysis.el +817 -0
  61. package/compiler/eliscript.el +239 -0
  62. package/dist/bootstrap/analyzer.mjs +968 -0
  63. package/dist/bootstrap/analyzer.mjs.map +1 -0
  64. package/dist/bootstrap/compiler.mjs +228 -0
  65. package/dist/bootstrap/compiler.mjs.map +1 -0
  66. package/dist/bootstrap/emitter.mjs +1173 -0
  67. package/dist/bootstrap/emitter.mjs.map +1 -0
  68. package/dist/bootstrap/expander.mjs +1469 -0
  69. package/dist/bootstrap/expander.mjs.map +1 -0
  70. package/dist/bootstrap/formatter.mjs +304 -0
  71. package/dist/bootstrap/formatter.mjs.map +1 -0
  72. package/dist/bootstrap/ir.mjs +193 -0
  73. package/dist/bootstrap/ir.mjs.map +1 -0
  74. package/dist/bootstrap/lower.mjs +344 -0
  75. package/dist/bootstrap/lower.mjs.map +1 -0
  76. package/dist/bootstrap/project.mjs +585 -0
  77. package/dist/bootstrap/project.mjs.map +1 -0
  78. package/dist/bootstrap/reader.mjs +259 -0
  79. package/dist/bootstrap/reader.mjs.map +1 -0
  80. package/dist/bootstrap/source-map.mjs +154 -0
  81. package/dist/bootstrap/source-map.mjs.map +1 -0
  82. package/dist/bootstrap/symbol.mjs +74 -0
  83. package/dist/bootstrap/symbol.mjs.map +1 -0
  84. package/dist/bootstrap/syntax.mjs +38 -0
  85. package/dist/bootstrap/syntax.mjs.map +1 -0
  86. package/dist/bootstrap/transient-analysis.mjs +660 -0
  87. package/dist/bootstrap/transient-analysis.mjs.map +1 -0
  88. package/dist/browser/compiler.js +6491 -0
  89. package/editor/README.md +83 -0
  90. package/editor/eliscript-mode.el +878 -0
  91. package/editor/eliscript-repl.el +501 -0
  92. package/package.json +163 -0
  93. package/platform/README.md +48 -0
  94. package/platform/browser.mjs +204 -0
  95. package/platform/worker.mjs +166 -0
  96. package/runtime/README.md +296 -0
  97. package/runtime/core/collection-internals.mjs +512 -0
  98. package/runtime/core/collection.mjs +645 -0
  99. package/runtime/core/data-text.mjs +532 -0
  100. package/runtime/core/data.mjs +268 -0
  101. package/runtime/core/identifier.mjs +314 -0
  102. package/runtime/core/lazy-sequence.mjs +244 -0
  103. package/runtime/core/list-internals.mjs +18 -0
  104. package/runtime/core/list.mjs +273 -0
  105. package/runtime/core/map-internals.mjs +793 -0
  106. package/runtime/core/map.mjs +394 -0
  107. package/runtime/core/metadata-internals.mjs +14 -0
  108. package/runtime/core/metadata.mjs +44 -0
  109. package/runtime/core/object-impl.mjs +65 -0
  110. package/runtime/core/object-impl.mjs.map +1 -0
  111. package/runtime/core/object.mjs +13 -0
  112. package/runtime/core/order.mjs +234 -0
  113. package/runtime/core/persistent-kind.mjs +43 -0
  114. package/runtime/core/protocol-error.mjs +36 -0
  115. package/runtime/core/protocol-impl.mjs +326 -0
  116. package/runtime/core/protocol-impl.mjs.map +1 -0
  117. package/runtime/core/protocol.mjs +14 -0
  118. package/runtime/core/queue-internals.mjs +27 -0
  119. package/runtime/core/queue.mjs +238 -0
  120. package/runtime/core/record.mjs +346 -0
  121. package/runtime/core/regex.mjs +184 -0
  122. package/runtime/core/sequence.mjs +632 -0
  123. package/runtime/core/set-algebra.mjs +287 -0
  124. package/runtime/core/set-internals.mjs +33 -0
  125. package/runtime/core/set.mjs +378 -0
  126. package/runtime/core/sorted-internals.mjs +215 -0
  127. package/runtime/core/sorted.mjs +598 -0
  128. package/runtime/core/text-impl.mjs +95 -0
  129. package/runtime/core/text-impl.mjs.map +1 -0
  130. package/runtime/core/text.mjs +15 -0
  131. package/runtime/core/transducer.mjs +668 -0
  132. package/runtime/core/transient-internals.mjs +38 -0
  133. package/runtime/core/transient.mjs +53 -0
  134. package/runtime/core/truth.mjs +3 -0
  135. package/runtime/core/type.mjs +262 -0
  136. package/runtime/core/value-internals.mjs +188 -0
  137. package/runtime/core/value.mjs +93 -0
  138. package/runtime/core/vector-internals.mjs +102 -0
  139. package/runtime/core/vector.mjs +951 -0
  140. package/runtime/literals.mjs +34 -0
  141. package/runtime/source-mapping.mjs +220 -0
  142. package/runtime/testing/list.mjs +52 -0
  143. package/runtime/testing/map.mjs +145 -0
  144. package/runtime/testing/queue.mjs +49 -0
  145. package/runtime/testing/set.mjs +61 -0
  146. package/runtime/testing/sorted.mjs +105 -0
  147. package/runtime/testing/value.mjs +17 -0
  148. package/runtime/testing/vector.mjs +102 -0
  149. package/runtime/worker-value-codec.mjs +565 -0
  150. package/runtime/worker-value-stream.mjs +786 -0
  151. package/runtime/worker.mjs +975 -0
  152. package/stdlib/README.md +774 -0
  153. package/stdlib/bit.eli +36 -0
  154. package/stdlib/core/collection.eli +134 -0
  155. package/stdlib/core/data-text.eli +16 -0
  156. package/stdlib/core/data.eli +306 -0
  157. package/stdlib/core/identifier.eli +32 -0
  158. package/stdlib/core/lazy-sequence.eli +63 -0
  159. package/stdlib/core/metadata.eli +20 -0
  160. package/stdlib/core/object.eli +89 -0
  161. package/stdlib/core/order.eli +133 -0
  162. package/stdlib/core/protocol.eli +387 -0
  163. package/stdlib/core/record.eli +16 -0
  164. package/stdlib/core/regex.eli +17 -0
  165. package/stdlib/core/seq.eli +701 -0
  166. package/stdlib/core/set.eli +312 -0
  167. package/stdlib/core/sorted.eli +53 -0
  168. package/stdlib/core/text.eli +103 -0
  169. package/stdlib/core/transducer.eli +59 -0
  170. package/stdlib/core/transient.eli +24 -0
  171. package/stdlib/core/type.eli +19 -0
  172. package/stdlib/core/walk.eli +195 -0
  173. package/stdlib/core/zipper.eli +508 -0
  174. package/stdlib/data-text.eli +1092 -0
  175. package/stdlib/data.eli +42 -0
  176. package/stdlib/deferred.eli +70 -0
  177. package/stdlib/function.eli +120 -0
  178. package/stdlib/hierarchy.eli +245 -0
  179. package/stdlib/identifier.eli +147 -0
  180. package/stdlib/interop/js.eli +616 -0
  181. package/stdlib/json.eli +870 -0
  182. package/stdlib/metadata.eli +56 -0
  183. package/stdlib/multimethod.eli +464 -0
  184. package/stdlib/numeric.eli +193 -0
  185. package/stdlib/object.eli +96 -0
  186. package/stdlib/persistent-list.eli +145 -0
  187. package/stdlib/persistent-map.eli +724 -0
  188. package/stdlib/persistent-queue.eli +32 -0
  189. package/stdlib/persistent-set.eli +236 -0
  190. package/stdlib/persistent-vector.eli +342 -0
  191. package/stdlib/result.eli +141 -0
  192. package/stdlib/sequence.eli +106 -0
  193. package/stdlib/state/atom.eli +265 -0
  194. package/stdlib/text.eli +88 -0
  195. package/stdlib/value.eli +325 -0
@@ -0,0 +1,325 @@
1
+ (module eliscript.value
2
+ (import-portable "./bit.eli" rotate-left)
3
+ (import-portable "./persistent-list.eli"
4
+ persistent-list?
5
+ persistent-list-empty?
6
+ persistent-list-first
7
+ persistent-list-rest)
8
+ (import-portable "./persistent-vector.eli"
9
+ persistent-vector?
10
+ persistent-vector-count
11
+ persistent-vector-nth)
12
+ (import-portable "./persistent-map.eli"
13
+ empty-persistent-map
14
+ persistent-map?
15
+ persistent-map-count
16
+ persistent-map-has?
17
+ persistent-map-get
18
+ persistent-map-reduce
19
+ persistent-map-from-entries)
20
+ (import-portable "./persistent-set.eli"
21
+ empty-persistent-set
22
+ persistent-set?
23
+ persistent-set-count
24
+ persistent-set-has?
25
+ persistent-set-reduce
26
+ persistent-set-from-array)
27
+
28
+ (defconst value-boolean-tag 1260232563)
29
+ (defconst value-number-tag 374761393)
30
+ (defconst value-string-tag 1831565813)
31
+ (defconst value-host-tag 762272397)
32
+ (defconst value-list-tag 793406745)
33
+ (defconst value-vector-tag 1327180861)
34
+ (defconst value-map-tag 1821285621)
35
+ (defconst value-map-entry-tag 982610667)
36
+ (defconst value-set-tag 1374139181)
37
+ (defconst value-keyword-tag 795685287)
38
+ (defconst value-symbol-tag 1908952723)
39
+ (defconst value-unqualified-hash 1251063421)
40
+
41
+ (defconst value-false-hash 423263297)
42
+ (defconst value-true-hash 1911856395)
43
+ (defconst value-null-hash 1108378657)
44
+ (defconst value-undefined-hash 2135587861)
45
+ (defconst value-nan-hash 1490037359)
46
+
47
+ (defportable value-avalanche-hash (value)
48
+ (let ((hash (uint32 value)))
49
+ (setq hash (bit-xor hash (unsigned-bit-shift-right hash 16)))
50
+ (setq hash (imul32 hash 2246822507))
51
+ (setq hash (bit-xor hash (unsigned-bit-shift-right hash 13)))
52
+ (setq hash (imul32 hash 3266489909))
53
+ (setq hash (bit-xor hash (unsigned-bit-shift-right hash 16)))
54
+ (uint32 hash)))
55
+
56
+ (defportable value-mix-hash (hash value)
57
+ (let ((mixed (uint32 (bit-xor hash value))))
58
+ (setq mixed (imul32 mixed 1540483477))
59
+ (setq mixed
60
+ (bit-xor mixed (unsigned-bit-shift-right mixed 15)))
61
+ (uint32 mixed)))
62
+
63
+ (defportable value-finish-hash (hash count)
64
+ (value-avalanche-hash
65
+ (value-mix-hash hash (uint32 count))))
66
+
67
+ (defportable value-hash-string-with-tag (value tag)
68
+ (let ((hash (value-mix-hash tag (js-length value)))
69
+ (index 0))
70
+ (while (< index (js-length value))
71
+ (setq hash
72
+ (value-mix-hash
73
+ hash
74
+ (string-code-unit-at value index))
75
+ index (1+ index)))
76
+ (value-finish-hash hash (js-length value))))
77
+
78
+ (defportable value-hash-number (value)
79
+ (if (not (= value value))
80
+ value-nan-hash
81
+ (let ((words (number-float64-words value)))
82
+ (value-finish-hash
83
+ (value-mix-hash
84
+ (value-mix-hash value-number-tag (js-nth 0 words))
85
+ (js-nth 1 words))
86
+ 2))))
87
+
88
+ (defportable value-list-equal? (left right)
89
+ (let ((left-node left)
90
+ (right-node right)
91
+ (result t))
92
+ (while (and result
93
+ (not (persistent-list-empty? left-node))
94
+ (not (persistent-list-empty? right-node)))
95
+ (setq result
96
+ (value-equal?
97
+ (persistent-list-first left-node nil)
98
+ (persistent-list-first right-node nil)))
99
+ (setq left-node (persistent-list-rest left-node nil)
100
+ right-node (persistent-list-rest right-node nil)))
101
+ (and result
102
+ (persistent-list-empty? left-node)
103
+ (persistent-list-empty? right-node))))
104
+
105
+ (defportable value-vector-equal? (left right)
106
+ (if (not (= (persistent-vector-count left)
107
+ (persistent-vector-count right)))
108
+ false
109
+ (let ((index 0)
110
+ (result t))
111
+ (while (and result (< index (persistent-vector-count left)))
112
+ (setq result
113
+ (value-equal?
114
+ (persistent-vector-nth left index nil)
115
+ (persistent-vector-nth right index nil))
116
+ index (1+ index)))
117
+ result)))
118
+
119
+ (defportable value-identifier-equal? (left right)
120
+ (and (= (get left :namespace) (get right :namespace))
121
+ (= (get left :name) (get right :name))))
122
+
123
+ (defportable value-logical-identifier? (value)
124
+ (let ((namespace (get value :namespace nil))
125
+ (name (get value :name nil)))
126
+ (and (= (value-type name) "string")
127
+ (or (nil? namespace)
128
+ (= (value-type namespace) "string")))))
129
+
130
+ (defportable value-map-equal? (left right)
131
+ (and (= (persistent-map-count left) (persistent-map-count right))
132
+ (persistent-map-reduce
133
+ (lambda (result key value)
134
+ (and result
135
+ (persistent-map-has? right key)
136
+ (value-equal?
137
+ value
138
+ (persistent-map-get right key nil))))
139
+ t
140
+ left)))
141
+
142
+ (defportable value-set-equal? (left right)
143
+ (and (= (persistent-set-count left) (persistent-set-count right))
144
+ (persistent-set-reduce
145
+ (lambda (result value)
146
+ (and result (persistent-set-has? right value)))
147
+ t
148
+ left)))
149
+
150
+ (defportable value-equal? (left right)
151
+ (if (= left right)
152
+ t
153
+ (let ((left-type (value-type left))
154
+ (right-type (value-type right)))
155
+ (if (not (= left-type right-type))
156
+ false
157
+ (cond
158
+ ((= left-type "number")
159
+ (and (not (= left left)) (not (= right right))))
160
+ ((or (= left-type "keyword") (= left-type "symbol"))
161
+ (and (value-logical-identifier? left)
162
+ (value-logical-identifier? right)
163
+ (value-identifier-equal? left right)))
164
+ ((persistent-list? left)
165
+ (and (persistent-list? right)
166
+ (value-list-equal? left right)))
167
+ ((persistent-vector? left)
168
+ (and (persistent-vector? right)
169
+ (value-vector-equal? left right)))
170
+ ((persistent-map? left)
171
+ (and (persistent-map? right)
172
+ (value-map-equal? left right)))
173
+ ((persistent-set? left)
174
+ (and (persistent-set? right)
175
+ (value-set-equal? left right)))
176
+ (t false))))))
177
+
178
+ (defportable value-list-hash (value)
179
+ (let ((hash value-list-tag)
180
+ (count 0)
181
+ (node value))
182
+ (while (not (persistent-list-empty? node))
183
+ (setq hash
184
+ (value-mix-hash
185
+ hash
186
+ (value-hash (persistent-list-first node nil)))
187
+ count (1+ count)
188
+ node (persistent-list-rest node nil)))
189
+ (value-finish-hash hash count)))
190
+
191
+ (defportable value-vector-hash (value)
192
+ (let ((hash value-vector-tag)
193
+ (index 0))
194
+ (while (< index (persistent-vector-count value))
195
+ (setq hash
196
+ (value-mix-hash
197
+ hash
198
+ (value-hash (persistent-vector-nth value index nil)))
199
+ index (1+ index)))
200
+ (value-finish-hash hash index)))
201
+
202
+ (defportable value-identifier-hash (value tag)
203
+ (value-finish-hash
204
+ (value-mix-hash
205
+ (value-mix-hash
206
+ tag
207
+ (if (= (get value :namespace) nil)
208
+ value-unqualified-hash
209
+ (value-hash-string-with-tag
210
+ (get value :namespace)
211
+ value-string-tag)))
212
+ (value-hash-string-with-tag (get value :name) value-string-tag))
213
+ 2))
214
+
215
+ (defportable value-map-entry-hash (key value)
216
+ (value-finish-hash
217
+ (value-mix-hash
218
+ (value-mix-hash value-map-entry-tag (value-hash key))
219
+ (value-hash value))
220
+ 2))
221
+
222
+ (defportable value-map-hash (value)
223
+ (let ((sum 0)
224
+ (xor 0)
225
+ (product 1)
226
+ (count 0))
227
+ (persistent-map-reduce
228
+ (lambda (_result key item-value)
229
+ (let ((hash (value-map-entry-hash key item-value)))
230
+ (setq sum (uint32 (+ sum hash))
231
+ xor
232
+ (uint32
233
+ (bit-xor xor (rotate-left hash (bit-and hash 31))))
234
+ product
235
+ (uint32 (imul32 product (bit-or hash 1)))
236
+ count (1+ count)))
237
+ nil)
238
+ nil
239
+ value)
240
+ (value-finish-hash
241
+ (value-mix-hash
242
+ (value-mix-hash
243
+ (value-mix-hash value-map-tag sum)
244
+ xor)
245
+ product)
246
+ count)))
247
+
248
+ (defportable value-set-hash (value)
249
+ (let ((sum 0)
250
+ (xor 0)
251
+ (product 1)
252
+ (count 0))
253
+ (persistent-set-reduce
254
+ (lambda (_result item-value)
255
+ (let ((hash (value-hash item-value)))
256
+ (setq sum (uint32 (+ sum hash))
257
+ xor
258
+ (uint32
259
+ (bit-xor xor (rotate-left hash (bit-and hash 31))))
260
+ product
261
+ (uint32 (imul32 product (bit-or hash 1)))
262
+ count (1+ count)))
263
+ nil)
264
+ nil
265
+ value)
266
+ (value-finish-hash
267
+ (value-mix-hash
268
+ (value-mix-hash
269
+ (value-mix-hash value-set-tag sum)
270
+ xor)
271
+ product)
272
+ count)))
273
+
274
+ (defportable value-hash-host (value)
275
+ (value-finish-hash
276
+ value-host-tag
277
+ (uint32 (host-identity-token value))))
278
+
279
+ (defportable value-hash (value)
280
+ (let ((type (value-type value)))
281
+ (cond
282
+ ((= type "null") value-null-hash)
283
+ ((= type "undefined") value-undefined-hash)
284
+ ((= type "boolean")
285
+ (value-mix-hash
286
+ value-boolean-tag
287
+ (if value value-true-hash value-false-hash)))
288
+ ((= type "number") (value-hash-number value))
289
+ ((= type "string")
290
+ (value-hash-string-with-tag value value-string-tag))
291
+ ((= type "keyword")
292
+ (if (value-logical-identifier? value)
293
+ (value-identifier-hash value value-keyword-tag)
294
+ (value-hash-host value)))
295
+ ((= type "symbol")
296
+ (if (value-logical-identifier? value)
297
+ (value-identifier-hash value value-symbol-tag)
298
+ (value-hash-host value)))
299
+ ((persistent-list? value) (value-list-hash value))
300
+ ((persistent-vector? value) (value-vector-hash value))
301
+ ((persistent-map? value) (value-map-hash value))
302
+ ((persistent-set? value) (value-set-hash value))
303
+ ((= type "bigint")
304
+ (value-hash-string-with-tag (str value) value-host-tag))
305
+ (t (value-hash-host value)))))
306
+
307
+ (defportable empty-value-map ()
308
+ (empty-persistent-map value-hash value-equal? value-equal?))
309
+
310
+ (defportable value-map-from-entries (entries)
311
+ (persistent-map-from-entries
312
+ value-hash value-equal? value-equal? entries))
313
+
314
+ (defportable empty-value-set ()
315
+ (empty-persistent-set value-hash value-equal?))
316
+
317
+ (defportable value-set-from-array (values)
318
+ (persistent-set-from-array value-hash value-equal? values))
319
+
320
+ (export value-equal?
321
+ value-hash
322
+ empty-value-map
323
+ value-map-from-entries
324
+ empty-value-set
325
+ value-set-from-array))