eliscript 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +13 -11
  2. package/bootstrap/README.md +13 -8
  3. package/bootstrap/host/build.eli +2 -0
  4. package/bootstrap/host/bun.eli +2 -0
  5. package/bootstrap/host/check-cli-legacy.eli +2 -0
  6. package/bootstrap/host/evaluation-cli.eli +2 -0
  7. package/bootstrap/host/evaluation.eli +2 -0
  8. package/bootstrap/host/format-cli.eli +2 -0
  9. package/bootstrap/host/project-cli-legacy.eli +2 -0
  10. package/bootstrap/host/project-legacy.eli +2 -0
  11. package/bootstrap/host/watch-cli.eli +2 -0
  12. package/bootstrap/host/watch.eli +2 -0
  13. package/browser/README.md +33 -0
  14. package/browser/host.eli +2 -0
  15. package/browser/host.mjs +643 -11
  16. package/browser/worker.eli +2 -0
  17. package/browser/worker.mjs +6 -3
  18. package/dist/browser/host.mjs +643 -11
  19. package/dist/browser/worker.mjs +6 -3
  20. package/dist/compiler-artifact.json +1 -1
  21. package/dist/literal-sources/runtime/core/collection.eli +76 -16
  22. package/dist/literal-sources/runtime/core/metadata.eli +25 -8
  23. package/dist/literal-sources/runtime/core/vector.eli +7 -2
  24. package/dist/literal-sources/stdlib/managed-literal-protocols.eli +18 -7
  25. package/dist/literal-sources/stdlib/managed-literals.eli +121 -66
  26. package/dist/stage3-release.json +1 -1
  27. package/package.json +11 -2
  28. package/platform/README.md +33 -12
  29. package/platform/browser.eli +2 -0
  30. package/platform/http.eli +2 -0
  31. package/platform/worker.eli +2 -0
  32. package/runtime/README.md +34 -14
  33. package/runtime/array-text.eli +2 -0
  34. package/runtime/core/collection-internals.eli +2 -0
  35. package/runtime/core/collection.eli +2 -0
  36. package/runtime/core/collection.mjs +99 -17
  37. package/runtime/core/data-text.eli +2 -0
  38. package/runtime/core/data.eli +2 -0
  39. package/runtime/core/data.mjs +7 -5
  40. package/runtime/core/identifier.eli +2 -0
  41. package/runtime/core/lazy-sequence.eli +2 -0
  42. package/runtime/core/list-internals.eli +2 -0
  43. package/runtime/core/list.eli +2 -0
  44. package/runtime/core/list.mjs +3 -0
  45. package/runtime/core/map-internals.eli +2 -0
  46. package/runtime/core/map.eli +2 -0
  47. package/runtime/core/map.mjs +5 -0
  48. package/runtime/core/metadata-internals.eli +2 -0
  49. package/runtime/core/metadata.eli +2 -0
  50. package/runtime/core/metadata.mjs +14 -0
  51. package/runtime/core/object.eli +2 -0
  52. package/runtime/core/order.eli +2 -0
  53. package/runtime/core/order.mjs +35 -6
  54. package/runtime/core/persistent-kind.eli +2 -0
  55. package/runtime/core/persistent-kind.mjs +6 -0
  56. package/runtime/core/protocol-error.eli +2 -0
  57. package/runtime/core/protocol.eli +2 -0
  58. package/runtime/core/queue-internals.eli +2 -0
  59. package/runtime/core/queue.eli +2 -0
  60. package/runtime/core/queue.mjs +3 -0
  61. package/runtime/core/record.eli +2 -0
  62. package/runtime/core/regex.eli +2 -0
  63. package/runtime/core/sequence.eli +2 -0
  64. package/runtime/core/sequence.mjs +75 -13
  65. package/runtime/core/set-algebra.eli +2 -0
  66. package/runtime/core/set-internals.eli +2 -0
  67. package/runtime/core/set.eli +2 -0
  68. package/runtime/core/sorted-internals.eli +2 -0
  69. package/runtime/core/sorted.eli +2 -0
  70. package/runtime/core/text.eli +2 -0
  71. package/runtime/core/transducer.eli +2 -0
  72. package/runtime/core/transient-internals.eli +2 -0
  73. package/runtime/core/transient.eli +2 -0
  74. package/runtime/core/transient.mjs +59 -10
  75. package/runtime/core/truth.eli +2 -0
  76. package/runtime/core/type.eli +2 -0
  77. package/runtime/core/value-internals.eli +2 -0
  78. package/runtime/core/value.eli +2 -0
  79. package/runtime/core/vector-internals.eli +2 -0
  80. package/runtime/core/vector-internals.mjs +3 -6
  81. package/runtime/core/vector.eli +2 -0
  82. package/runtime/core/vector.mjs +125 -7
  83. package/runtime/literals.eli +2 -0
  84. package/runtime/number-radix.eli +2 -0
  85. package/runtime/source-mapping.eli +2 -0
  86. package/runtime/testing/list.eli +2 -0
  87. package/runtime/testing/map.eli +2 -0
  88. package/runtime/testing/queue.eli +2 -0
  89. package/runtime/testing/set.eli +2 -0
  90. package/runtime/testing/sorted.eli +2 -0
  91. package/runtime/testing/value.eli +2 -0
  92. package/runtime/testing/vector.eli +2 -0
  93. package/runtime/wire/http-rpc.eli +2 -0
  94. package/runtime/wire/markdown.eli +2 -0
  95. package/runtime/wire/schema.eli +2 -0
  96. package/runtime/worker-value-codec.eli +2 -0
  97. package/runtime/worker-value-stream.eli +2 -0
  98. package/runtime/worker.eli +2 -0
  99. package/stdlib/README.md +2 -2
  100. package/stdlib/core/order.eli +36 -10
  101. package/stdlib/core/seq.eli +104 -75
  102. package/stdlib/core/zipper.eli +274 -101
  103. package/stdlib/managed-literal-protocols.eli +18 -7
  104. package/stdlib/managed-literals.eli +121 -66
  105. package/stdlib/managed-runtime-collection.eli +76 -16
  106. package/stdlib/managed-runtime-metadata.eli +25 -8
  107. package/stdlib/managed-runtime-order.eli +32 -10
  108. package/stdlib/managed-runtime-sequence.eli +69 -28
  109. package/stdlib/managed-runtime-vector.eli +7 -2
  110. package/tools/acceptance/check.eli +13 -3
  111. package/tools/backends/compiler-build.mjs +140 -140
  112. package/tools/backends/dist/release-cli.mjs +2 -0
  113. package/tools/backends/dist/release-cli.mjs.map +1 -1
  114. package/tools/backends/stage3-targets.mjs +121 -114
  115. package/bootstrap/host/eliscript-cli-legacy.mjs +0 -37
@@ -1,7 +1,7 @@
1
1
  (module eliscript.core.order
2
2
  (import "../../runtime/core/collection.mjs" reduce)
3
3
  (import "../../runtime/core/order.mjs" :as Runtime)
4
- (import "../../runtime/core/transducer.mjs" into)
4
+ (import "../../runtime/core/transient.mjs" conjBang persistentBang transient)
5
5
  (import "../../runtime/core/truth.mjs" isTruthy)
6
6
  (import "../../runtime/core/vector.mjs" EMPTY_VECTOR)
7
7
  (defconst IComparable Runtime/IComparable)
@@ -22,12 +22,14 @@
22
22
  (defun comparator
23
23
  (comparison)
24
24
  (require-function comparison "comparator comparison")
25
- (lambda
26
- (left right)
27
- (let ((result (funcall comparison left right)))
28
- (if (= (value-type result) "number")
29
- (normalize-comparison-result result "comparator comparison")
30
- (if (isTruthy result) -1 (if (isTruthy (funcall comparison right left)) 1 0))))))
25
+ (if (or (eq comparison compare-values) (eq comparison Runtime/compareValues))
26
+ Runtime/compareValues
27
+ (lambda
28
+ (left right)
29
+ (let ((result (funcall comparison left right)))
30
+ (if (= (value-type result) "number")
31
+ (normalize-comparison-result result "comparator comparison")
32
+ (if (isTruthy result) -1 (if (isTruthy (funcall comparison right left)) 1 0)))))))
31
33
  (defun reverse-comparator
32
34
  (&rest arguments)
33
35
  (let ((length (js-length arguments)))
@@ -66,7 +68,31 @@
66
68
  (left right)
67
69
  (let ((result (funcall comparison (get left :key) (get right :key))))
68
70
  (if (= result 0) (- (get left :index) (get right :index)) result))))
69
- (into EMPTY_VECTOR (js-call values :map (lambda (entry) (get entry :value)))))
71
+ (let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
72
+ (while (< index limit)
73
+ (conjBang builder (get (js-nth index values) :value))
74
+ (setq index (1+ index)))
75
+ (persistentBang builder)))
76
+ (defun collect-values
77
+ (collection)
78
+ (reduce
79
+ collection
80
+ (lambda
81
+ (result value)
82
+ (js-call result :push value)
83
+ result)
84
+ (js-array)))
85
+ (defun sort-values
86
+ (values comparison)
87
+ (js-call values :sort comparison)
88
+ (let ((from-fn (get (get EMPTY_VECTOR :constructor) :from)))
89
+ (if (not (undefined? from-fn))
90
+ (js-call (get EMPTY_VECTOR :constructor) :from values)
91
+ (let ((builder (transient EMPTY_VECTOR)) (index 0) (limit (js-length values)))
92
+ (while (< index limit)
93
+ (conjBang builder (js-nth index values))
94
+ (setq index (1+ index)))
95
+ (persistentBang builder)))))
70
96
  (defun sort
71
97
  (&rest arguments)
72
98
  (let ((length (js-length arguments)))
@@ -78,8 +104,8 @@
78
104
  (let
79
105
  ((comparison (if (= length 1) compare-values (js-nth 0 arguments)))
80
106
  (collection (js-nth (1- length) arguments)))
81
- (sort-decorated
82
- (collect-decorated collection (lambda (value) value))
107
+ (sort-values
108
+ (collect-values collection)
83
109
  (comparator comparison))))))
84
110
  (defun sort-by
85
111
  (key-function &rest arguments)
@@ -43,7 +43,7 @@
43
43
  persistentVector)
44
44
  (defconst not-found (js-object))
45
45
  (defconst sequence-no-partition-pad (js-object))
46
- (defconst sequence-ring (lambda () (new globalThis/Map)))
46
+ (defconst sequence-ring (lambda (limit) (new globalThis/Array limit)))
47
47
  (defconst sequence-array? (js* "Array.isArray"))
48
48
  (defconst sequence-safe-integer? (js* "Number.isSafeInteger"))
49
49
  (defconst sequence-finite? (js* "Number.isFinite"))
@@ -276,14 +276,20 @@
276
276
  limit))
277
277
  (defun first
278
278
  (collection &optional not-found-value)
279
- (let
280
- (
281
- (result
279
+ (cond
280
+ ((isPersistentList collection)
281
+ (if (get collection :isEmpty) not-found-value (js-call collection :first not-found-value)))
282
+ ((isPersistentVector collection)
283
+ (if (= (get collection :count) 0) not-found-value (js-call collection :nth 0)))
284
+ (t
285
+ (let ((found false) (found-value nil))
282
286
  (reduce
283
287
  collection
284
- (lambda (missing value) (reduced (js-object :value value)))
285
- not-found)))
286
- (if (eq result not-found) not-found-value (get result :value))))
288
+ (lambda (missing value)
289
+ (setq found t found-value value)
290
+ (reduced missing))
291
+ nil)
292
+ (if found found-value not-found-value)))))
287
293
  (defun nth-rest
288
294
  (limit collection)
289
295
  (require-non-negative-safe-integer limit "nth-rest limit")
@@ -312,73 +318,98 @@
312
318
  (defun sequence-nth
313
319
  (index collection &optional not-found-value)
314
320
  (require-non-negative-safe-integer index "sequence-nth index")
315
- (let*
316
- ((position 0)
317
- (result
318
- (reduce
319
- collection
320
- (lambda
321
- (missing value)
322
- (if (= position index)
323
- (reduced (js-object :value value))
324
- (progn (setq position (1+ position)) missing)))
325
- not-found)))
326
- (if (eq result not-found) not-found-value (get result :value))))
321
+ (let ((position 0) (found false) (found-value nil))
322
+ (reduce
323
+ collection
324
+ (lambda
325
+ (missing value)
326
+ (if (= position index)
327
+ (progn (setq found t found-value value) (reduced missing))
328
+ (progn (setq position (1+ position)) missing)))
329
+ nil)
330
+ (if found found-value not-found-value)))
327
331
  (defun last
328
332
  (collection &optional not-found-value)
329
- (if (implementsProtocolOperation IReversible "rseq" collection)
330
- (first (rseq collection) not-found-value)
331
- (let
332
- (
333
- (result
334
- (reduce
335
- collection
336
- (lambda (missing value) (js-object :value value))
337
- not-found)))
338
- (if (eq result not-found) not-found-value (get result :value)))))
333
+ (cond
334
+ ((isPersistentVector collection)
335
+ (js-call collection :peek not-found-value))
336
+ ((implementsProtocolOperation IReversible "rseq" collection)
337
+ (first (rseq collection) not-found-value))
338
+ (t
339
+ (let ((found false) (last-value nil))
340
+ (reduce
341
+ collection
342
+ (lambda (missing value) (setq found t last-value value) missing)
343
+ nil)
344
+ (if found last-value not-found-value)))))
339
345
  (defun take-last
340
346
  (limit collection)
341
347
  (require-non-negative-safe-integer limit "take-last limit")
342
348
  (if (= limit 0)
343
349
  EMPTY_VECTOR
344
- (let ((ring (funcall sequence-ring)) (count 0) (start 0))
345
- (reduce
346
- collection
347
- (lambda
348
- (state value)
349
- (if (< count limit)
350
- (progn (js-call ring :set count value) (setq count (1+ count)))
351
- (progn (js-call ring :set start value) (setq start (% (1+ start) limit))))
352
- state)
353
- nil)
354
- (let ((builder (transient EMPTY_VECTOR)) (index 0))
355
- (while (< index count)
356
- (conjBang builder (js-call ring :get (% (+ start index) limit)))
357
- (setq index (1+ index)))
358
- (persistentBang builder)))))
350
+ (if (isPersistentVector collection)
351
+ (let ((total (get collection :count)))
352
+ (if (= total 0)
353
+ EMPTY_VECTOR
354
+ (if (>= limit total)
355
+ collection
356
+ (if (not (undefined? (get collection :sliceVector)))
357
+ (js-call collection :sliceVector (- total limit) total)
358
+ (let ((builder (transient EMPTY_VECTOR)) (index (- total limit)))
359
+ (while (< index total)
360
+ (conjBang builder (js-call collection :nth index))
361
+ (setq index (1+ index)))
362
+ (persistentBang builder))))))
363
+ (let ((ring (funcall sequence-ring limit)) (count 0) (start 0))
364
+ (reduce
365
+ collection
366
+ (lambda
367
+ (state value)
368
+ (if (< count limit)
369
+ (progn (put ring count value) (setq count (1+ count)))
370
+ (progn (put ring start value) (setq start (% (1+ start) limit))))
371
+ state)
372
+ nil)
373
+ (let ((builder (transient EMPTY_VECTOR)) (index 0))
374
+ (while (< index count)
375
+ (conjBang builder (js-nth (% (+ start index) limit) ring))
376
+ (setq index (1+ index)))
377
+ (persistentBang builder))))))
359
378
  (defun drop-last
360
379
  (limit collection)
361
380
  (require-non-negative-safe-integer limit "drop-last limit")
362
381
  (if (= limit 0)
363
- (into EMPTY_VECTOR collection)
364
- (let
365
- ((ring (funcall sequence-ring))
366
- (builder (transient EMPTY_VECTOR))
367
- (count 0)
368
- (start 0))
369
- (reduce
370
- collection
371
- (lambda
372
- (state value)
373
- (if (< count limit)
374
- (progn (js-call ring :set count value) (setq count (1+ count)))
375
- (progn
376
- (conjBang builder (js-call ring :get start))
377
- (js-call ring :set start value)
378
- (setq start (% (1+ start) limit))))
379
- state)
380
- nil)
381
- (persistentBang builder))))
382
+ (if (isPersistentVector collection) collection (into EMPTY_VECTOR collection))
383
+ (if (isPersistentVector collection)
384
+ (let ((total (get collection :count)))
385
+ (if (>= limit total)
386
+ EMPTY_VECTOR
387
+ (let ((keep (- total limit)))
388
+ (if (not (undefined? (get collection :sliceVector)))
389
+ (js-call collection :sliceVector 0 keep)
390
+ (let ((builder (transient EMPTY_VECTOR)) (index 0))
391
+ (while (< index keep)
392
+ (conjBang builder (js-call collection :nth index))
393
+ (setq index (1+ index)))
394
+ (persistentBang builder))))))
395
+ (let
396
+ ((ring (funcall sequence-ring limit))
397
+ (builder (transient EMPTY_VECTOR))
398
+ (count 0)
399
+ (start 0))
400
+ (reduce
401
+ collection
402
+ (lambda
403
+ (state value)
404
+ (if (< count limit)
405
+ (progn (put ring count value) (setq count (1+ count)))
406
+ (progn
407
+ (conjBang builder (js-nth start ring))
408
+ (put ring start value)
409
+ (setq start (% (1+ start) limit))))
410
+ state)
411
+ nil)
412
+ (persistentBang builder)))))
382
413
  (defun butlast (collection) (drop-last 1 collection))
383
414
  (defun split-at
384
415
  (limit collection)
@@ -589,18 +620,16 @@
589
620
  (defun find
590
621
  (predicate collection &optional not-found-value)
591
622
  (require-function predicate "find predicate")
592
- (let
593
- (
594
- (result
595
- (reduce
596
- collection
597
- (lambda
598
- (missing value)
599
- (if (isTruthy (funcall predicate value))
600
- (reduced (js-object :value value))
601
- missing))
602
- not-found)))
603
- (if (eq result not-found) not-found-value (get result :value))))
623
+ (let ((found false) (found-value nil))
624
+ (reduce
625
+ collection
626
+ (lambda
627
+ (missing value)
628
+ (if (isTruthy (funcall predicate value))
629
+ (progn (setq found t found-value value) (reduced missing))
630
+ missing))
631
+ nil)
632
+ (if found found-value not-found-value)))
604
633
  (defun reductions
605
634
  (step initial collection)
606
635
  (require-function step "reductions step")