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
@@ -97,8 +97,16 @@
97
97
 
98
98
  (defun first (collection &optional not-found)
99
99
  (when (undefined? not-found) (setq not-found nil))
100
- (let ((result (reduce collection (lambda (missing value) (reduced (js-object :value value))) NOT_FOUND)))
101
- (if (eq result NOT_FOUND) not-found (aref result "value"))))
100
+ (cond
101
+ ((isPersistentList collection)
102
+ (if (aref collection "isEmpty") not-found (js-call collection :first not-found)))
103
+ ((isPersistentVector collection)
104
+ (if (= (aref collection "count") 0) not-found (js-call collection :nth 0)))
105
+ (t
106
+ (let ((found false) (found-value nil))
107
+ (reduce collection (lambda (missing value)
108
+ (setq found t found-value value) (reduced missing)) nil)
109
+ (if found found-value not-found)))))
102
110
  (defun nthRest (limit collection)
103
111
  (require-nonnegative limit "nthRest limit")
104
112
  (if (= limit 0) collection
@@ -119,38 +127,71 @@
119
127
  (defun sequenceNth (index collection &optional not-found)
120
128
  (require-nonnegative index "sequenceNth index")
121
129
  (when (undefined? not-found) (setq not-found nil))
122
- (let ((position 0))
123
- (let ((result (reduce collection (lambda (missing value)
124
- (if (= position index) (reduced (js-object :value value))
125
- (progn (setq position (1+ position)) missing))) NOT_FOUND)))
126
- (if (eq result NOT_FOUND) not-found (aref result "value")))))
130
+ (let ((position 0) (found false) (found-value nil))
131
+ (reduce collection (lambda (missing value)
132
+ (if (= position index)
133
+ (progn (setq found t found-value value) (reduced missing))
134
+ (progn (setq position (1+ position)) missing))) nil)
135
+ (if found found-value not-found)))
127
136
  (defun last (collection &optional not-found)
128
137
  (when (undefined? not-found) (setq not-found nil))
129
- (if (implementsProtocolOperation IReversible "rseq" collection) (first (rseq collection) not-found)
130
- (let ((result (reduce collection (lambda (missing value) (js-object :value value)) NOT_FOUND)))
131
- (if (eq result NOT_FOUND) not-found (aref result "value")))))
138
+ (cond
139
+ ((isPersistentVector collection)
140
+ (js-call collection :peek not-found))
141
+ ((implementsProtocolOperation IReversible "rseq" collection)
142
+ (first (rseq collection) not-found))
143
+ (t
144
+ (let ((found false) (last-value nil))
145
+ (reduce collection (lambda (missing value)
146
+ (setq found t last-value value) missing) nil)
147
+ (if found last-value not-found)))))
132
148
  (defun takeLast (limit collection)
133
149
  (require-nonnegative limit "takeLast limit")
134
- (if (= limit 0) EMPTY_VECTOR
135
- (let ((ring (new globalThis/Array limit)) (length 0) (start 0))
136
- (reduce collection (lambda (state value)
137
- (if (< length limit)
138
- (progn (put ring length value) (setq length (1+ length)))
139
- (progn (put ring start value) (setq start (% (1+ start) limit)))) state) nil)
140
- (let ((builder (transient EMPTY_VECTOR)) (index 0))
141
- (while (< index length)
142
- (conjBang builder (aref ring (% (+ start index) limit))) (setq index (1+ index)))
143
- (persistentBang builder)))))
150
+ (cond
151
+ ((= limit 0) EMPTY_VECTOR)
152
+ ((isPersistentVector collection)
153
+ (let ((total (aref collection "count")))
154
+ (cond
155
+ ((= total 0) EMPTY_VECTOR)
156
+ ((>= limit total) collection)
157
+ (t
158
+ (let ((builder (transient EMPTY_VECTOR)) (index (- total limit)))
159
+ (while (< index total)
160
+ (conjBang builder (js-call collection :nth index))
161
+ (setq index (1+ index)))
162
+ (persistentBang builder))))))
163
+ (t
164
+ (let ((ring (new globalThis/Array limit)) (length 0) (start 0))
165
+ (reduce collection (lambda (state value)
166
+ (if (< length limit)
167
+ (progn (put ring length value) (setq length (1+ length)))
168
+ (progn (put ring start value) (setq start (% (1+ start) limit)))) state) nil)
169
+ (let ((builder (transient EMPTY_VECTOR)) (index 0))
170
+ (while (< index length)
171
+ (conjBang builder (aref ring (% (+ start index) limit))) (setq index (1+ index)))
172
+ (persistentBang builder))))))
144
173
  (defun dropLast (limit collection)
145
174
  (require-nonnegative limit "dropLast limit")
146
- (if (= limit 0) (into EMPTY_VECTOR collection)
147
- (let ((ring (new globalThis/Array limit)) (builder (transient EMPTY_VECTOR)) (length 0) (start 0))
148
- (reduce collection (lambda (state value)
149
- (if (< length limit)
150
- (progn (put ring length value) (setq length (1+ length)))
151
- (progn (conjBang builder (aref ring start)) (put ring start value)
152
- (setq start (% (1+ start) limit)))) state) nil)
153
- (persistentBang builder))))
175
+ (cond
176
+ ((= limit 0)
177
+ (if (isPersistentVector collection) collection (into EMPTY_VECTOR collection)))
178
+ ((isPersistentVector collection)
179
+ (let ((total (aref collection "count")))
180
+ (if (>= limit total)
181
+ EMPTY_VECTOR
182
+ (let ((builder (transient EMPTY_VECTOR)) (keep (- total limit)) (index 0))
183
+ (while (< index keep)
184
+ (conjBang builder (js-call collection :nth index))
185
+ (setq index (1+ index)))
186
+ (persistentBang builder)))))
187
+ (t
188
+ (let ((ring (new globalThis/Array limit)) (builder (transient EMPTY_VECTOR)) (length 0) (start 0))
189
+ (reduce collection (lambda (state value)
190
+ (if (< length limit)
191
+ (progn (put ring length value) (setq length (1+ length)))
192
+ (progn (conjBang builder (aref ring start)) (put ring start value)
193
+ (setq start (% (1+ start) limit)))) state) nil)
194
+ (persistentBang builder)))))
154
195
  (defun butlast (collection) (dropLast 1 collection))
155
196
  (defun splitAt (limit collection)
156
197
  (require-nonnegative limit "splitAt limit")
@@ -1,10 +1,15 @@
1
1
  (module eliscript.managed-runtime-vector
2
2
  (import "../../stdlib/managed-literals.eli"
3
- PersistentVector literal-vector literal-subvec literal-instance? literal-type literal-export-value)
3
+ PersistentVector literal-vector literal-vector-from-array-values literal-subvec literal-instance? literal-type literal-export-value)
4
4
 
5
5
  (defconst EMPTY_VECTOR (literal-vector))
6
6
  (defconst view-states (new globalThis/WeakMap))
7
- (defun persistentVector (&rest values) (js-call PersistentVector :from values))
7
+ (defconst freeze Object/freeze)
8
+ (defun persistentVector (&rest values)
9
+ (if (= (js-length values) 0) EMPTY_VECTOR
10
+ (progn
11
+ (when (<= (js-length values) 32) (funcall freeze values))
12
+ (literal-vector-from-array-values values))))
8
13
  (defun isPersistentVector (value) (literal-instance? value PersistentVector))
9
14
  (defun subvec (vector start &optional end) (literal-subvec vector start end))
10
15
  (defun readPersistentVectorView (value)
@@ -27,6 +27,10 @@
27
27
  ((= filename "tests/compiler-parity-corpus.test.mjs") "tests/eliscript/compiler-parity-corpus.eli")
28
28
  ((= filename "tests/stable-compatibility-corpus.test.mjs") "tests/eliscript/stable-compatibility-corpus.eli")
29
29
  (t undefined)))
30
+ (defun capsule-evidence-source (filename)
31
+ (if (and (= (value-type filename) "string") (js-call filename :endsWith ".mjs"))
32
+ (str (js-call filename :slice 0 -4) ".eli")
33
+ undefined))
30
34
  (defconst run-results (new globalThis.Set (js-array "pass" "incomplete" "fail")))
31
35
  (defun field (object key &rest defaults)
32
36
  (let ((fallback (if (= (js-length defaults) 0) undefined (aref defaults 0))))
@@ -192,15 +196,21 @@
192
196
  ((not (safe-relative filename))
193
197
  (js-call errors :push (str label " has unsafe evidence path " (JSON/stringify filename))))
194
198
  ((not (js-call files :has filename))
195
- (if (undefined? (maintained-evidence-source filename))
196
- (js-call errors :push (str label " evidence is not tracked: " filename))
199
+ (if (not (undefined? (maintained-evidence-source filename)))
197
200
  (progn
198
201
  (unless (js-call generated :has filename)
199
202
  (try
200
203
  (await (authenticate-generated root filename files)) (js-call generated :set filename nil)
201
204
  (catch error (js-call generated :set filename (get error :message)))))
202
205
  (let ((failure (js-call generated :get filename)))
203
- (when failure (js-call errors :push (str label " generated acceptance evidence authentication failed: " filename ": " failure)))))))
206
+ (when failure (js-call errors :push (str label " generated acceptance evidence authentication failed: " filename ": " failure)))))
207
+ (if (and (not (undefined? (capsule-evidence-source filename)))
208
+ (js-call files :has (capsule-evidence-source filename)))
209
+ (try
210
+ (unless (js-call (await (stat (js-call path :join root filename))) :isFile)
211
+ (js-call errors :push (str label " evidence is not a file: " filename)))
212
+ (catch error (js-call errors :push (str label " evidence is missing: " filename))))
213
+ (js-call errors :push (str label " evidence is not tracked: " filename)))))
204
214
  (t (try
205
215
  (unless (js-call (await (stat (js-call path :join root filename))) :isFile)
206
216
  (js-call errors :push (str label " evidence is not a file: " filename)))