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,394 @@
1
+ import {
2
+ MAP_CONSTRUCTOR_TOKEN,
3
+ MAP_NOT_FOUND,
4
+ MAP_STATE,
5
+ TRANSIENT_MAP_CONSTRUCTOR_TOKEN,
6
+ TRANSIENT_MAP_STATE,
7
+ EMPTY_BITMAP_NODE,
8
+ mapAssoc,
9
+ mapAssocTransient,
10
+ mapDissoc,
11
+ mapDissocTransient,
12
+ mapEntries,
13
+ mapFind,
14
+ mapHash,
15
+ recordInvalidTransientMapCall,
16
+ recordTransientMapPersistent,
17
+ } from "./map-internals.mjs";
18
+ import {
19
+ VALUE_EQUAL,
20
+ VALUE_HASH,
21
+ finishHash,
22
+ mixHash,
23
+ unorderedCollectionHash,
24
+ } from "./value-internals.mjs";
25
+ import {
26
+ COLLECTION_COUNT,
27
+ COLLECTION_EMPTY,
28
+ COLLECTION_CONJ,
29
+ COLLECTION_GET,
30
+ COLLECTION_ASSOC,
31
+ COLLECTION_CONTAINS,
32
+ COLLECTION_REDUCE,
33
+ COLLECTION_REDUCE_KV,
34
+ COLLECTION_DISSOC,
35
+ COLLECTION_SEQ,
36
+ isReducedValue,
37
+ reduceIterable,
38
+ readCollectionEntry,
39
+ sequenceView,
40
+ unreducedValue,
41
+ } from "./collection-internals.mjs";
42
+ import {
43
+ EDITABLE_TRANSIENT,
44
+ TRANSIENT_ASSOC,
45
+ TRANSIENT_CONJ,
46
+ TRANSIENT_DISSOC,
47
+ TRANSIENT_PERSISTENT,
48
+ } from "./transient-internals.mjs";
49
+ import {
50
+ METADATA_READ,
51
+ METADATA_WITH,
52
+ } from "./metadata-internals.mjs";
53
+ import {
54
+ PERSISTENT_MAP_HAS_VALUE_KEY,
55
+ PERSISTENT_MAP_KIND,
56
+ persistentMapValueEqual,
57
+ } from "./persistent-kind.mjs";
58
+
59
+ const MAP_HASH_TAG = 0x6c8e_9cf5;
60
+ const MAP_ENTRY_HASH_TAG = 0x3a91_72eb;
61
+
62
+ function makeMap(count, root, metadata = null) {
63
+ return new PersistentHashMap(MAP_CONSTRUCTOR_TOKEN, count, root, metadata);
64
+ }
65
+
66
+ function emptyMapWithMetadata(metadata) {
67
+ return metadata === null
68
+ ? EMPTY_MAP
69
+ : makeMap(0, EMPTY_BITMAP_NODE, metadata);
70
+ }
71
+
72
+ function makeTransientMap(map) {
73
+ return new TransientHashMap(TRANSIENT_MAP_CONSTRUCTOR_TOKEN, map);
74
+ }
75
+
76
+ function activeTransientMapState(map) {
77
+ const state = map[TRANSIENT_MAP_STATE];
78
+ if (!state.active) {
79
+ recordInvalidTransientMapCall();
80
+ throw new TypeError("transient hash map is no longer editable");
81
+ }
82
+ return state;
83
+ }
84
+
85
+ function pairHash(entry, hash) {
86
+ return finishHash(
87
+ mixHash(mixHash(MAP_ENTRY_HASH_TAG, hash(entry.key)), hash(entry.value)),
88
+ 2,
89
+ );
90
+ }
91
+
92
+ class TransientHashMap {
93
+ constructor(token, map) {
94
+ if (token !== TRANSIENT_MAP_CONSTRUCTOR_TOKEN ||
95
+ !(map instanceof PersistentHashMap)) {
96
+ throw new TypeError(
97
+ "transient hash maps must be created from a persistent hash map",
98
+ );
99
+ }
100
+ const source = map[MAP_STATE];
101
+ this[TRANSIENT_MAP_STATE] = {
102
+ active: true,
103
+ changed: false,
104
+ owner: Object.freeze({}),
105
+ source: map,
106
+ count: source.count,
107
+ root: source.root,
108
+ metadata: source.metadata,
109
+ };
110
+ Object.defineProperty(this, "__eliscript_transient__", {
111
+ enumerable: true,
112
+ get() {
113
+ throw new TypeError("transient hash maps cannot be serialized");
114
+ },
115
+ });
116
+ Object.freeze(this);
117
+ }
118
+
119
+ [TRANSIENT_CONJ](entry) {
120
+ const [key, value] = readCollectionEntry(entry);
121
+ return this[TRANSIENT_ASSOC](key, value);
122
+ }
123
+
124
+ [TRANSIENT_ASSOC](key, value) {
125
+ const state = activeTransientMapState(this);
126
+ const result = mapAssocTransient(
127
+ state.root,
128
+ state.owner,
129
+ mapHash(key),
130
+ key,
131
+ value,
132
+ );
133
+ if (result.changed) {
134
+ state.root = result.item;
135
+ state.count += result.added ? 1 : 0;
136
+ state.changed = true;
137
+ }
138
+ return this;
139
+ }
140
+
141
+ [TRANSIENT_DISSOC](key) {
142
+ const state = activeTransientMapState(this);
143
+ const result = mapDissocTransient(
144
+ state.root,
145
+ state.owner,
146
+ mapHash(key),
147
+ key,
148
+ );
149
+ if (result.removed) {
150
+ state.count -= 1;
151
+ state.root = state.count === 0
152
+ ? EMPTY_BITMAP_NODE
153
+ : (result.item ?? EMPTY_BITMAP_NODE);
154
+ state.changed = true;
155
+ }
156
+ return this;
157
+ }
158
+
159
+ [TRANSIENT_PERSISTENT]() {
160
+ const state = activeTransientMapState(this);
161
+ const result = !state.changed
162
+ ? state.source
163
+ : state.count === 0
164
+ ? emptyMapWithMetadata(state.metadata)
165
+ : makeMap(state.count, state.root, state.metadata);
166
+ state.active = false;
167
+ state.owner = null;
168
+ recordTransientMapPersistent();
169
+ return result;
170
+ }
171
+
172
+ toJSON() {
173
+ throw new TypeError("transient hash maps cannot be serialized");
174
+ }
175
+
176
+ get [Symbol.toStringTag]() {
177
+ return "EliscriptTransientHashMap";
178
+ }
179
+ }
180
+
181
+ export class PersistentHashMap {
182
+ constructor(token, count, root, metadata = null) {
183
+ if (token !== MAP_CONSTRUCTOR_TOKEN) {
184
+ throw new TypeError(
185
+ "PersistentHashMap values must be created with persistentHashMap or PersistentHashMap.from",
186
+ );
187
+ }
188
+ this[MAP_STATE] = Object.freeze({ count, root, metadata });
189
+ Object.freeze(this);
190
+ }
191
+
192
+ static empty() {
193
+ return EMPTY_MAP;
194
+ }
195
+
196
+ static from(entries) {
197
+ if (entries instanceof PersistentHashMap) {
198
+ return entries;
199
+ }
200
+ let result = EMPTY_MAP;
201
+ for (const entry of entries) {
202
+ const [key, value] = readCollectionEntry(entry);
203
+ result = result.assoc(key, value);
204
+ }
205
+ return result;
206
+ }
207
+
208
+ get count() {
209
+ return this[MAP_STATE].count;
210
+ }
211
+
212
+ get size() {
213
+ return this[MAP_STATE].count;
214
+ }
215
+
216
+ get(key, notFound = null) {
217
+ return mapFind(
218
+ this[MAP_STATE].root,
219
+ mapHash(key),
220
+ key,
221
+ notFound,
222
+ );
223
+ }
224
+
225
+ has(key) {
226
+ return this.get(key, MAP_NOT_FOUND) !== MAP_NOT_FOUND;
227
+ }
228
+
229
+ assoc(key, value) {
230
+ const state = this[MAP_STATE];
231
+ const result = mapAssoc(state.root, mapHash(key), key, value);
232
+ if (!result.changed) {
233
+ return this;
234
+ }
235
+ return makeMap(
236
+ state.count + (result.added ? 1 : 0),
237
+ result.item,
238
+ state.metadata,
239
+ );
240
+ }
241
+
242
+ dissoc(key) {
243
+ const state = this[MAP_STATE];
244
+ const result = mapDissoc(state.root, mapHash(key), key);
245
+ if (!result.removed) {
246
+ return this;
247
+ }
248
+ if (state.count === 1) {
249
+ return emptyMapWithMetadata(state.metadata);
250
+ }
251
+ return makeMap(
252
+ state.count - 1,
253
+ result.item ?? EMPTY_BITMAP_NODE,
254
+ state.metadata,
255
+ );
256
+ }
257
+
258
+ *entries() {
259
+ for (const entry of mapEntries(this[MAP_STATE].root)) {
260
+ yield Object.freeze([entry.key, entry.value]);
261
+ }
262
+ }
263
+
264
+ *keys() {
265
+ for (const entry of mapEntries(this[MAP_STATE].root)) {
266
+ yield entry.key;
267
+ }
268
+ }
269
+
270
+ *values() {
271
+ for (const entry of mapEntries(this[MAP_STATE].root)) {
272
+ yield entry.value;
273
+ }
274
+ }
275
+
276
+ reduce(reducer, initial) {
277
+ if (typeof reducer !== "function") {
278
+ throw new TypeError("persistent hash map reducer must be a function");
279
+ }
280
+ if (arguments.length < 2) {
281
+ throw new TypeError("persistent hash map reduce requires an initial value");
282
+ }
283
+ let result = initial;
284
+ for (const entry of mapEntries(this[MAP_STATE].root)) {
285
+ result = reducer(result, entry.value, entry.key, this);
286
+ }
287
+ return result;
288
+ }
289
+
290
+ [COLLECTION_COUNT]() {
291
+ return this.count;
292
+ }
293
+
294
+ [COLLECTION_EMPTY]() {
295
+ return emptyMapWithMetadata(this[MAP_STATE].metadata);
296
+ }
297
+
298
+ [COLLECTION_CONJ](entry) {
299
+ const [key, value] = readCollectionEntry(entry);
300
+ return this.assoc(key, value);
301
+ }
302
+
303
+ [COLLECTION_GET](key, notFound = null) {
304
+ return this.get(key, notFound);
305
+ }
306
+
307
+ [COLLECTION_ASSOC](key, value) {
308
+ return this.assoc(key, value);
309
+ }
310
+
311
+ [COLLECTION_CONTAINS](key) {
312
+ return this.has(key);
313
+ }
314
+
315
+ [COLLECTION_DISSOC](key) {
316
+ return this.dissoc(key);
317
+ }
318
+
319
+ [COLLECTION_SEQ]() {
320
+ return this.count === 0
321
+ ? null
322
+ : sequenceView(() => this.entries(), this.count);
323
+ }
324
+
325
+ [COLLECTION_REDUCE](reducer, ...initial) {
326
+ return reduceIterable(this, reducer, ...initial);
327
+ }
328
+
329
+ [COLLECTION_REDUCE_KV](reducer, initial) {
330
+ let result = initial;
331
+ for (const entry of mapEntries(this[MAP_STATE].root)) {
332
+ result = reducer(result, entry.key, entry.value);
333
+ if (isReducedValue(result)) return unreducedValue(result);
334
+ }
335
+ return result;
336
+ }
337
+
338
+ [EDITABLE_TRANSIENT]() {
339
+ return makeTransientMap(this);
340
+ }
341
+
342
+ toMap() {
343
+ return new Map(this.entries());
344
+ }
345
+
346
+ [PERSISTENT_MAP_HAS_VALUE_KEY](key) {
347
+ return this.has(key);
348
+ }
349
+
350
+ get [PERSISTENT_MAP_KIND]() {
351
+ return true;
352
+ }
353
+
354
+ [VALUE_EQUAL](other, equal) {
355
+ return persistentMapValueEqual(this, other, equal);
356
+ }
357
+
358
+ [VALUE_HASH](hash) {
359
+ return unorderedCollectionHash(
360
+ mapEntries(this[MAP_STATE].root),
361
+ (entry) => pairHash(entry, hash),
362
+ MAP_HASH_TAG,
363
+ );
364
+ }
365
+
366
+ [METADATA_READ]() {
367
+ return this[MAP_STATE].metadata;
368
+ }
369
+
370
+ [METADATA_WITH](metadata) {
371
+ const state = this[MAP_STATE];
372
+ return metadata === state.metadata
373
+ ? this
374
+ : makeMap(state.count, state.root, metadata);
375
+ }
376
+
377
+ [Symbol.iterator]() {
378
+ return this.entries();
379
+ }
380
+
381
+ get [Symbol.toStringTag]() {
382
+ return "EliscriptPersistentHashMap";
383
+ }
384
+ }
385
+
386
+ export const EMPTY_MAP = makeMap(0, EMPTY_BITMAP_NODE);
387
+
388
+ export function persistentHashMap(...entries) {
389
+ return PersistentHashMap.from(entries);
390
+ }
391
+
392
+ export function isPersistentHashMap(value) {
393
+ return value instanceof PersistentHashMap;
394
+ }
@@ -0,0 +1,14 @@
1
+ import {
2
+ defineProtocol,
3
+ protocolMethod,
4
+ protocolSlot,
5
+ } from "./protocol.mjs";
6
+
7
+ export const I_META = defineProtocol("IMeta", ["meta"]);
8
+ export const I_WITH_META = defineProtocol("IWithMeta", ["withMeta"]);
9
+
10
+ export const METADATA_READ = protocolSlot(I_META, "meta");
11
+ export const METADATA_WITH = protocolSlot(I_WITH_META, "withMeta");
12
+
13
+ export const dispatchMetadataRead = protocolMethod(I_META, "meta");
14
+ export const dispatchMetadataWith = protocolMethod(I_WITH_META, "withMeta");
@@ -0,0 +1,44 @@
1
+ import { isPersistentHashMap } from "./map.mjs";
2
+ import {
3
+ I_META,
4
+ I_WITH_META,
5
+ dispatchMetadataRead,
6
+ dispatchMetadataWith,
7
+ } from "./metadata-internals.mjs";
8
+ import { implementsProtocolOperation } from "./protocol.mjs";
9
+
10
+ export const IMeta = I_META;
11
+ export const IWithMeta = I_WITH_META;
12
+
13
+ function validateMetadata(metadata) {
14
+ if (metadata !== null && !isPersistentHashMap(metadata)) {
15
+ throw new TypeError("metadata must be null or a persistent hash map");
16
+ }
17
+ return metadata;
18
+ }
19
+
20
+ export function supportsMetadata(value) {
21
+ return implementsProtocolOperation(IMeta, "meta", value) &&
22
+ implementsProtocolOperation(IWithMeta, "withMeta", value);
23
+ }
24
+
25
+ export function meta(value) {
26
+ return implementsProtocolOperation(IMeta, "meta", value)
27
+ ? dispatchMetadataRead(value)
28
+ : null;
29
+ }
30
+
31
+ export function withMeta(value, metadata) {
32
+ validateMetadata(metadata);
33
+ if (!implementsProtocolOperation(IWithMeta, "withMeta", value)) {
34
+ throw new TypeError("value does not support metadata");
35
+ }
36
+ return dispatchMetadataWith(value, metadata);
37
+ }
38
+
39
+ export function varyMeta(value, transform, ...arguments_) {
40
+ if (typeof transform !== "function") {
41
+ throw new TypeError("metadata transform must be a function");
42
+ }
43
+ return withMeta(value, transform(meta(value), ...arguments_));
44
+ }
@@ -0,0 +1,65 @@
1
+ // Generated by Eliscript. Do not edit.
2
+ const __eliscript_truthy = (value) => value !== false && value != null;
3
+
4
+ import * as Collection from "../../runtime/core/collection.mjs";
5
+ import * as Transducer from "../../runtime/core/transducer.mjs";
6
+ import {isTruthy} from "../../runtime/core/truth.mjs";
7
+ import {equalValues} from "../../runtime/core/value.mjs";
8
+ import {EMPTY_VECTOR} from "../../runtime/core/vector.mjs";
9
+ function entry_key(entry) {
10
+ return Collection.nth(entry, 0);
11
+ }
12
+ function entry_value(entry) {
13
+ return Collection.nth(entry, 1);
14
+ }
15
+ function keys(object) {
16
+ return Transducer.into(EMPTY_VECTOR, Transducer.mapping(entry_key), object);
17
+ }
18
+ function has_QMARK_(object, key) {
19
+ return Collection.contains(object, key);
20
+ }
21
+ function assoc(object, key, value, ...key_values) {
22
+ return Collection.assoc(...[object, ...(([key, ...(([value, ...((key_values) ?? [])]) ?? [])]) ?? [])]);
23
+ }
24
+ function key_in_QMARK_(key, key_list) {
25
+ return Collection.reduce(key_list, (matched, current) => {
26
+ return (__eliscript_truthy(equalValues(key, current)) ? Collection.reduced(true) : matched);
27
+ }, false);
28
+ }
29
+ function dissoc(object, key) {
30
+ return (__eliscript_truthy((!__eliscript_truthy(has_QMARK_(object, key)))) ? object : Transducer.into(object, Transducer.filtering((entry) => {
31
+ return (!__eliscript_truthy(equalValues(key, entry_key(entry))));
32
+ }), object));
33
+ }
34
+ function merge(left, right) {
35
+ return Collection.reduce(right, (result, entry) => {
36
+ return Collection.assoc(result, entry_key(entry), entry_value(entry));
37
+ }, left);
38
+ }
39
+ function map_values(function$, object) {
40
+ return Transducer.into(object, Transducer.mapping((entry) => {
41
+ return [entry_key(entry), function$(entry_value(entry))];
42
+ }), object);
43
+ }
44
+ function filter_values(predicate, object) {
45
+ return Transducer.into(object, Transducer.filtering((entry) => {
46
+ return isTruthy(predicate(entry_value(entry)));
47
+ }), object);
48
+ }
49
+ function pick(object, wanted_keys) {
50
+ return Transducer.into(object, Transducer.composeTransducers(Transducer.filtering((key) => {
51
+ return has_QMARK_(object, key);
52
+ }), Transducer.mapping((key) => {
53
+ return [key, Collection.get(object, key)];
54
+ })), wanted_keys);
55
+ }
56
+ function omit(object, omitted_keys) {
57
+ return Transducer.into(object, Transducer.filtering((entry) => {
58
+ return (!__eliscript_truthy(key_in_QMARK_(entry_key(entry), omitted_keys)));
59
+ }), object);
60
+ }
61
+ function update(object, key, function$) {
62
+ return Collection.assoc(object, key, function$(Collection.get(object, key)));
63
+ }
64
+ export {assoc, dissoc, filter_values, has_QMARK_, key_in_QMARK_, keys, map_values, merge, omit, pick, update};
65
+ //# sourceMappingURL=object-impl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-impl.mjs","sources":["../../stdlib/core/object.eli"],"sourcesContent":["(module eliscript.core.object\n (import \"../../runtime/core/collection.mjs\" :as Collection)\n (import \"../../runtime/core/transducer.mjs\" :as Transducer)\n (import \"../../runtime/core/truth.mjs\" isTruthy)\n (import \"../../runtime/core/value.mjs\" equalValues)\n (import \"../../runtime/core/vector.mjs\" EMPTY_VECTOR)\n\n (defun entry-key (entry)\n (Collection/nth entry 0))\n\n (defun entry-value (entry)\n (Collection/nth entry 1))\n\n (defun keys (object)\n (Transducer/into\n EMPTY_VECTOR\n (Transducer/mapping entry-key)\n object))\n\n (defun has? (object key)\n (Collection/contains object key))\n\n (defun assoc (object key value &rest key-values)\n (apply Collection/assoc\n (js-cons object (js-cons key (js-cons value key-values)))))\n\n (defun key-in? (key key-list)\n (Collection/reduce\n key-list\n (lambda (matched current)\n (if (equalValues key current)\n (Collection/reduced t)\n matched))\n false))\n\n (defun dissoc (object key)\n (if (not (has? object key))\n object\n (Transducer/into\n object\n (Transducer/filtering\n (lambda (entry) (not (equalValues key (entry-key entry)))))\n object)))\n\n (defun merge (left right)\n (Collection/reduce\n right\n (lambda (result entry)\n (Collection/assoc result (entry-key entry) (entry-value entry)))\n left))\n\n (defun map-values (function object)\n (Transducer/into\n object\n (Transducer/mapping\n (lambda (entry)\n (js-array (entry-key entry) (funcall function (entry-value entry)))))\n object))\n\n (defun filter-values (predicate object)\n (Transducer/into\n object\n (Transducer/filtering\n (lambda (entry)\n (isTruthy (funcall predicate (entry-value entry)))))\n object))\n\n (defun pick (object wanted-keys)\n (Transducer/into\n object\n (Transducer/composeTransducers\n (Transducer/filtering (lambda (key) (has? object key)))\n (Transducer/mapping\n (lambda (key) (js-array key (Collection/get object key)))))\n wanted-keys))\n\n (defun omit (object omitted-keys)\n (Transducer/into\n object\n (Transducer/filtering\n (lambda (entry) (not (key-in? (entry-key entry) omitted-keys))))\n object))\n\n (defun update (object key function)\n (Collection/assoc\n object key (funcall function (Collection/get object key))))\n\n (export assoc dissoc filter-values has? key-in? keys map-values merge omit\n pick update))\n"],"names":[],"mappings":";;;AACE,YAAgD;AAChD,YAAgD;AAChD,QAAuC;AACvC,QAAuC;AACvC,QAAwC;AAExC,mBAAkB;SACf,eAAe,OAAM;;AAExB,qBAAoB;SACjB,eAAe,OAAM;;AAExB,cAAa;SACV,gBACC,cACC,mBAAmB,YACpB;;AAEJ,oBAAa,QAAO;SACjB,oBAAoB,QAAO;;AAE9B,eAAc,QAAO,KAAI,UAAY;SAC5B,oBACA,CAAS,aAAO,CAAS,UAAI,CAAS,YAAM;;AAErD,uBAAgB,KAAI;SACjB,kBACC,UACA,CAAS,SAAQ;WACf,oBAAK,YAAY,KAAI,YAChB,mBAAmB,QACtB;KACJ;;AAEJ,gBAAe,QAAO;SACpB,oBAAI,qBAAM,WAAK,QAAO,UAClB,SACD,gBACC,QACC,qBACC,CAAS;WAAO,qBAAM,YAAY,KAAK,UAAU;MACnD;;AAEN,eAAc,MAAK;SAChB,kBACC,OACA,CAAS,QAAO;WACb,iBAAiB,QAAQ,UAAU,QAAQ,YAAY;KAC1D;;AAEJ,oBAAmB,WAAS;SACzB,gBACC,QACC,mBACC,CAAS;WACP,CAAW,UAAU,QAAgB,UAAU,YAAY;MAC/D;;AAEJ,uBAAsB,WAAU;SAC7B,gBACC,QACC,qBACC,CAAS;WACN,SAAkB,UAAW,YAAY;MAC9C;;AAEJ,cAAa,QAAO;SACjB,gBACC,QACC,8BACE,qBAAqB,CAAS;WAAM,WAAK,QAAO;MAChD,mBACC,CAAS;WAAK,CAAU,KAAK,eAAe,QAAO;OACvD;;AAEJ,cAAa,QAAO;SACjB,gBACC,QACC,qBACC,CAAS;WAAO,qBAAM,cAAS,UAAU,QAAO;MAClD;;AAEJ,gBAAe,QAAO,KAAI;SACvB,iBACC,QAAO,KAAa,UAAU,eAAe,QAAO;;AAExD,QAAQ,OAAM,QAAO,eAAc,YAAK,eAAQ,MAAK,YAAW,OAAM,MAC9D,MAAK"}
@@ -0,0 +1,13 @@
1
+ export {
2
+ assoc,
3
+ dissoc,
4
+ filter_values as filterValues,
5
+ has_QMARK_ as has,
6
+ key_in_QMARK_ as keyIn,
7
+ keys,
8
+ map_values as mapValues,
9
+ merge,
10
+ omit,
11
+ pick,
12
+ update,
13
+ } from "./object-impl.mjs";