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,239 @@
1
+ ;;; eliscript.el --- Eliscript seed compiler -*- lexical-binding: t; -*-
2
+
3
+ ;;; Commentary:
4
+
5
+ ;; Public entry points for compiling Eliscript source with Emacs.
6
+
7
+ ;;; Code:
8
+
9
+ (require 'eliscript-reader)
10
+ (require 'eliscript-expander)
11
+ (require 'eliscript-analyzer)
12
+ (require 'eliscript-lower)
13
+ (require 'eliscript-emitter)
14
+ (require 'eliscript-ir-emitter)
15
+ (require 'eliscript-portable)
16
+
17
+ (defun eliscript--analyzed-string (source filename &optional macro-context)
18
+ "Read, expand, and analyze SOURCE from FILENAME."
19
+ (eliscript-analyze-module
20
+ (eliscript-expand-module
21
+ (eliscript-read-located-string source filename)
22
+ filename macro-context)
23
+ filename))
24
+
25
+ (defun eliscript-compile-ir-string (source &optional filename macro-context)
26
+ "Compile Eliscript SOURCE from FILENAME into an IR program."
27
+ (eliscript-lower-module
28
+ (eliscript--analyzed-string source filename macro-context)
29
+ filename))
30
+
31
+ (defun eliscript-compile-portable-ir-string
32
+ (source entries &optional filename macro-context)
33
+ "Compile portable ENTRIES from Eliscript SOURCE into an IR program."
34
+ (let ((forms (eliscript--analyzed-string source filename macro-context)))
35
+ (eliscript-lower-module
36
+ (eliscript-portable-select-module forms entries filename)
37
+ filename)))
38
+
39
+ (defun eliscript-compile-portable-string (source entries &optional filename)
40
+ "Compile portable ENTRIES and their dependencies from SOURCE to ESM."
41
+ (eliscript-emit-ir-module
42
+ (eliscript-compile-portable-ir-string source entries filename)))
43
+
44
+ (defun eliscript-compile-portable-string-with-source-map
45
+ (source entries &optional filename generated-name source-name)
46
+ "Compile portable ENTRIES from SOURCE with a Source Map v3 document."
47
+ (eliscript-emit-ir-module-with-source-map
48
+ (eliscript-compile-portable-ir-string source entries filename)
49
+ source
50
+ generated-name
51
+ (or source-name filename "<string>")))
52
+
53
+ (defun eliscript-compile-string (source &optional filename)
54
+ "Compile Eliscript SOURCE to an ECMAScript module.
55
+
56
+ FILENAME is used for compiler diagnostics."
57
+ (eliscript-emit-ir-module
58
+ (eliscript-compile-ir-string source filename)))
59
+
60
+ (defun eliscript-compile-string-with-source-map
61
+ (source &optional filename generated-name source-name)
62
+ "Compile SOURCE and return JavaScript plus a Source Map v3 document.
63
+
64
+ FILENAME is used for diagnostics. GENERATED-NAME and SOURCE-NAME identify the
65
+ files recorded in the source map. The return value is an `eliscript-emission'."
66
+ (eliscript-emit-ir-module-with-source-map
67
+ (eliscript-compile-ir-string source filename)
68
+ source
69
+ generated-name
70
+ (or source-name filename "<string>")))
71
+
72
+ (defun eliscript-compile-ir-file (input-file)
73
+ "Compile INPUT-FILE into an IR program."
74
+ (eliscript-lower-module
75
+ (eliscript-analyze-module
76
+ (eliscript-expand-module
77
+ (eliscript-read-located-file input-file)
78
+ input-file)
79
+ input-file)
80
+ input-file))
81
+
82
+ (defun eliscript--same-file-path-p (left right)
83
+ "Return non-nil when LEFT and RIGHT name the same physical file."
84
+ (or (string-equal (file-truename left) (file-truename right))
85
+ (and (file-exists-p left)
86
+ (file-exists-p right)
87
+ (condition-case nil
88
+ (file-equal-p left right)
89
+ (file-error nil)))))
90
+
91
+ (defun eliscript--validate-file-output-paths (input paths)
92
+ "Reject PATHS that alias INPUT or one another before writing files."
93
+ (let ((input-path (expand-file-name input))
94
+ validated)
95
+ (dolist (path paths)
96
+ (let ((output-path (expand-file-name path)))
97
+ (when (eliscript--same-file-path-p input-path output-path)
98
+ (error "generated artifact must not overwrite input file: %s"
99
+ output-path))
100
+ (dolist (previous validated)
101
+ (when (eliscript--same-file-path-p previous output-path)
102
+ (error "generated artifact paths must be physically distinct: %s and %s"
103
+ previous output-path)))
104
+ (push output-path validated)))))
105
+
106
+ (defun eliscript-compile-portable-file (input-file entries &optional output-file)
107
+ "Compile portable ENTRIES from INPUT-FILE, optionally to OUTPUT-FILE."
108
+ (let* ((input-path (expand-file-name input-file))
109
+ (_validated
110
+ (when output-file
111
+ (eliscript--validate-file-output-paths
112
+ input-path (list output-file))))
113
+ (source
114
+ (with-temp-buffer
115
+ (insert-file-contents input-path)
116
+ (buffer-string)))
117
+ (output
118
+ (eliscript-compile-portable-string source entries input-path)))
119
+ (when output-file
120
+ (make-directory (file-name-directory (expand-file-name output-file)) t)
121
+ (with-temp-file output-file
122
+ (insert output)))
123
+ output))
124
+
125
+ (defun eliscript-compile-portable-file-with-source-map
126
+ (input-file entries output-file &optional source-map-file)
127
+ "Compile portable ENTRIES from INPUT-FILE with an external source map."
128
+ (unless output-file
129
+ (error "portable source-map compilation requires OUTPUT-FILE"))
130
+ (let* ((input-path (expand-file-name input-file))
131
+ (output-path (expand-file-name output-file))
132
+ (map-path
133
+ (expand-file-name (or source-map-file (concat output-path ".map"))))
134
+ (_validated
135
+ (eliscript--validate-file-output-paths
136
+ input-path (list output-path map-path)))
137
+ (map-directory (file-name-directory map-path))
138
+ (source
139
+ (with-temp-buffer
140
+ (insert-file-contents input-path)
141
+ (buffer-string)))
142
+ (generated-name (file-relative-name output-path map-directory))
143
+ (source-name (file-relative-name input-path map-directory))
144
+ (emission
145
+ (eliscript-compile-portable-string-with-source-map
146
+ source entries input-path generated-name source-name))
147
+ (map-url
148
+ (file-relative-name map-path (file-name-directory output-path)))
149
+ (javascript
150
+ (concat (eliscript-emission-javascript emission)
151
+ "//# sourceMappingURL=" map-url "\n")))
152
+ (setq emission
153
+ (eliscript-emission-create
154
+ :javascript javascript
155
+ :source-map (eliscript-emission-source-map emission)))
156
+ (make-directory map-directory t)
157
+ (with-temp-file map-path
158
+ (insert (eliscript-emission-source-map emission)))
159
+ (make-directory (file-name-directory output-path) t)
160
+ (with-temp-file output-path
161
+ (insert javascript))
162
+ emission))
163
+
164
+ (defun eliscript-compile-file (input-file &optional output-file)
165
+ "Compile INPUT-FILE and optionally write it to OUTPUT-FILE.
166
+
167
+ Return the generated ECMAScript source."
168
+ (let* ((input-path (expand-file-name input-file))
169
+ (_validated
170
+ (when output-file
171
+ (eliscript--validate-file-output-paths
172
+ input-path (list output-file))))
173
+ (output (eliscript-emit-ir-module
174
+ (eliscript-compile-ir-file input-path))))
175
+ (when output-file
176
+ (make-directory (file-name-directory (expand-file-name output-file)) t)
177
+ (with-temp-file output-file
178
+ (insert output)))
179
+ output))
180
+
181
+ (defun eliscript-compile-file-with-source-map
182
+ (input-file &optional output-file source-map-file)
183
+ "Compile INPUT-FILE with a Source Map v3 document.
184
+
185
+ When OUTPUT-FILE is non-nil, write JavaScript there and write the map to
186
+ SOURCE-MAP-FILE or OUTPUT-FILE with `.map' appended. The JavaScript receives
187
+ an external `sourceMappingURL' comment. Return an `eliscript-emission'."
188
+ (when (and source-map-file (null output-file))
189
+ (error "SOURCE-MAP-FILE requires OUTPUT-FILE"))
190
+ (let* ((input-path (expand-file-name input-file))
191
+ (output-path (and output-file (expand-file-name output-file)))
192
+ (map-path
193
+ (and output-path
194
+ (expand-file-name (or source-map-file
195
+ (concat output-path ".map")))))
196
+ (_validated
197
+ (when output-path
198
+ (eliscript--validate-file-output-paths
199
+ input-path (list output-path map-path))))
200
+ (source
201
+ (with-temp-buffer
202
+ (insert-file-contents input-path)
203
+ (buffer-string)))
204
+ (map-directory
205
+ (and map-path (file-name-directory map-path)))
206
+ (generated-name
207
+ (and output-path
208
+ (file-relative-name output-path map-directory)))
209
+ (source-name
210
+ (if map-directory
211
+ (file-relative-name input-path map-directory)
212
+ input-file))
213
+ (emission
214
+ (eliscript-compile-string-with-source-map
215
+ source input-path generated-name source-name)))
216
+ (when output-path
217
+ (let* ((map-url
218
+ (file-relative-name
219
+ map-path (file-name-directory output-path)))
220
+ (javascript
221
+ (concat (eliscript-emission-javascript emission)
222
+ "//# sourceMappingURL=" map-url "\n")))
223
+ (setq emission
224
+ (eliscript-emission-create
225
+ :javascript javascript
226
+ :source-map (eliscript-emission-source-map emission)))
227
+ (make-directory map-directory t)
228
+ (with-temp-file map-path
229
+ (insert (eliscript-emission-source-map emission)))
230
+ (make-directory (file-name-directory output-path) t)
231
+ (with-temp-file output-path
232
+ (insert javascript))))
233
+ emission))
234
+
235
+ (require 'eliscript-evaluation)
236
+
237
+ (provide 'eliscript)
238
+
239
+ ;;; eliscript.el ends here