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,357 @@
1
+ // In-memory compile host for browsers and workers.
2
+ //
3
+ // The command-line host in `bootstrap/host/project.mjs` answers the project
4
+ // planner from the filesystem. This host answers the same questions from a map
5
+ // of sources, so a project compiles without a server process, and it rewrites
6
+ // every specifier the emitted modules carry so they can run from blob URLs.
7
+ //
8
+ // Every import in this file is relative. A worker has no document and therefore
9
+ // no import map, so this module and the compiler bundle it loads must never
10
+ // depend on one.
11
+
12
+ import {
13
+ compile_ir_string,
14
+ emit_ir_string_with_source_map,
15
+ project_plan,
16
+ } from "../dist/browser/compiler.js";
17
+
18
+ const SOURCE_EXTENSION = ".eli";
19
+ const OUTPUT_EXTENSION = ".mjs";
20
+
21
+ /* ------------------------------------------------------------------ paths */
22
+
23
+ function splitPath(path) {
24
+ return path.split("/").filter((part) => part !== "" && part !== ".");
25
+ }
26
+
27
+ export function normalizePath(path) {
28
+ const parts = [];
29
+ for (const part of splitPath(path)) {
30
+ if (part === "..") {
31
+ if (parts.length === 0) {
32
+ throw new Error(`path escapes the project root: ${path}`);
33
+ }
34
+ parts.pop();
35
+ } else {
36
+ parts.push(part);
37
+ }
38
+ }
39
+ return parts.join("/");
40
+ }
41
+
42
+ export function dirname(path) {
43
+ const parts = splitPath(path);
44
+ parts.pop();
45
+ return parts.join("/");
46
+ }
47
+
48
+ export function resolvePath(importer, specifier) {
49
+ const base = dirname(importer);
50
+ return normalizePath(base === "" ? specifier : `${base}/${specifier}`);
51
+ }
52
+
53
+ export function outputPathFor(source) {
54
+ if (!source.endsWith(SOURCE_EXTENSION)) {
55
+ throw new Error(`source module must end with ${SOURCE_EXTENSION}: ${source}`);
56
+ }
57
+ return `${source.slice(0, -SOURCE_EXTENSION.length)}${OUTPUT_EXTENSION}`;
58
+ }
59
+
60
+ export function relativePath(from, to) {
61
+ const fromParts = splitPath(dirname(from));
62
+ const toParts = splitPath(to);
63
+ let common = 0;
64
+ while (common < fromParts.length && common < toParts.length &&
65
+ fromParts[common] === toParts[common]) {
66
+ common += 1;
67
+ }
68
+ const parts = [
69
+ ...fromParts.slice(common).map(() => ".."),
70
+ ...toParts.slice(common),
71
+ ];
72
+ const joined = parts.join("/");
73
+ return joined.startsWith(".") ? joined : `./${joined}`;
74
+ }
75
+
76
+ /* ------------------------------------------------------------------ graph */
77
+
78
+ // The planner hands back discovery order, but a module's imports must exist
79
+ // before it does, so execution needs a dependency-first order.
80
+ export function dependencyOrder(modules) {
81
+ const byId = new Map(modules.map((module) => [module.id, module]));
82
+ const order = [];
83
+ const state = new Map();
84
+ for (const module of modules) visit(module.id);
85
+ return order;
86
+
87
+ function visit(id) {
88
+ const seen = state.get(id);
89
+ if (seen === "done") return;
90
+ if (seen === "visiting") throw new Error(`import cycle through ${id}`);
91
+ state.set(id, "visiting");
92
+ for (const dependency of byId.get(id)?.dependencies ?? []) visit(dependency);
93
+ state.set(id, "done");
94
+ order.push(id);
95
+ }
96
+ }
97
+
98
+ function walkProgram(program, visit) {
99
+ const pending = [...program.body];
100
+ while (pending.length > 0) {
101
+ const node = pending.pop();
102
+ visit(node);
103
+ const children = node.children;
104
+ if (children === undefined || children === null) continue;
105
+ for (let index = children.length - 1; index >= 0; index -= 1) {
106
+ pending.push(children[index]);
107
+ }
108
+ }
109
+ }
110
+
111
+ function localSourceSpecifier(specifier) {
112
+ return specifier.startsWith(".") && specifier.endsWith(SOURCE_EXTENSION);
113
+ }
114
+
115
+ function importSpecifiers(program) {
116
+ const specifiers = [];
117
+ walkProgram(program, (node) => {
118
+ if (node.kind === "import-declaration") specifiers.push(node);
119
+ });
120
+ return specifiers;
121
+ }
122
+
123
+ // A source map names its source relative to the map beside it, which is a bare
124
+ // relative path rather than an import specifier.
125
+ function mapSourcePath(output, source) {
126
+ const path = relativePath(`${output}.map`, source);
127
+ return path.startsWith("./") ? path.slice(2) : path;
128
+ }
129
+
130
+ // The emitter injects runtime imports of its own for literals, collection
131
+ // helpers, list operations, and value equality. Those are not import nodes in
132
+ // the program, so they survive the IR rewrite above and must be resolved in the
133
+ // emitted text or every module that uses a vector keeps a bare specifier.
134
+ function rewriteEmittedExternals(code, source, resolveExternal) {
135
+ if (resolveExternal === undefined) return code;
136
+ const rewrite = (whole, prefix, quoted) => {
137
+ const specifier = quoted.slice(1, -1);
138
+ if (specifier.startsWith(".") || specifier.startsWith("/") ||
139
+ specifier.includes("://")) {
140
+ return whole;
141
+ }
142
+ const external = resolveExternal(specifier, source);
143
+ return typeof external === "string" && external.length > 0
144
+ ? `${prefix}"${external}"`
145
+ : whole;
146
+ };
147
+ return code
148
+ .replace(/(\bfrom\s+)("[^"]+")/gu, rewrite)
149
+ .replace(/(\bimport\s+)("[^"]+")/gu, rewrite);
150
+ }
151
+
152
+ function diagnosticOf(error, filename) {
153
+ return error?.eliscriptDiagnostic ?? {
154
+ format: "eliscript-diagnostic",
155
+ version: 1,
156
+ code: "ELI-BROWSER-0001",
157
+ severity: "error",
158
+ phase: "browser-host",
159
+ message: error?.message ?? String(error),
160
+ location: { file: filename },
161
+ };
162
+ }
163
+
164
+ export class BrowserCompileError extends Error {
165
+ constructor(diagnostics) {
166
+ super(diagnostics.map((diagnostic) => diagnostic.message).join("; "));
167
+ this.name = "BrowserCompileError";
168
+ this.diagnostics = diagnostics;
169
+ }
170
+ }
171
+
172
+ function failure(code, message, filename) {
173
+ return new BrowserCompileError([{
174
+ format: "eliscript-diagnostic",
175
+ version: 1,
176
+ code,
177
+ severity: "error",
178
+ phase: "browser-host",
179
+ message,
180
+ location: { file: filename },
181
+ }]);
182
+ }
183
+
184
+ /* ---------------------------------------------------------------- compile */
185
+
186
+ // Rewrites every specifier an emitted module carries:
187
+ // - a local `.eli` import becomes the relative path of its emitted module;
188
+ // - a bare specifier is offered to `resolveExternal`, so an application can
189
+ // point the runtime at a served directory without an import map;
190
+ // - anything `resolveExternal` declines stays as written, which is what a
191
+ // third-party package import needs.
192
+ function rewriteSpecifiers(program, source, resolveExternal) {
193
+ for (const node of importSpecifiers(program)) {
194
+ const specifier = node.value;
195
+ if (localSourceSpecifier(specifier)) {
196
+ node.value = relativePath(
197
+ outputPathFor(source),
198
+ outputPathFor(resolvePath(source, specifier)),
199
+ );
200
+ continue;
201
+ }
202
+ if (specifier.startsWith(".") || specifier.startsWith("/")) continue;
203
+ const external = resolveExternal?.(specifier, source);
204
+ if (typeof external === "string" && external.length > 0) node.value = external;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Compiles one module.
210
+ *
211
+ * @returns {{ javascript: string, sourceMap: object }}
212
+ */
213
+ export function compileSource(
214
+ source,
215
+ filename = `module${SOURCE_EXTENSION}`,
216
+ options = {},
217
+ ) {
218
+ const program = compile_ir_string(source, filename, options.macroContext ?? null);
219
+ rewriteSpecifiers(program, filename, options.resolveExternal);
220
+ const output = outputPathFor(filename);
221
+ const emission = emit_ir_string_with_source_map(
222
+ program,
223
+ source,
224
+ output,
225
+ mapSourcePath(output, filename),
226
+ );
227
+ return {
228
+ javascript: rewriteEmittedExternals(
229
+ emission.javascript,
230
+ filename,
231
+ options.resolveExternal,
232
+ ),
233
+ sourceMap: emission.sourceMap,
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Compiles a whole project from a map of sources.
239
+ *
240
+ * @param {object} request
241
+ * @param {Record<string, string>} request.files relative `.eli` path to source
242
+ * @param {string} request.entry relative `.eli` path to compile from
243
+ * @returns {{ plan: object, modules: Record<string, object> }}
244
+ */
245
+ export function compileProject({
246
+ files,
247
+ entry,
248
+ macroContext = null,
249
+ resolveExternal,
250
+ }) {
251
+ for (const path of Object.keys(files)) outputPathFor(path);
252
+ if (files[entry] === undefined) {
253
+ throw failure("ELI-BROWSER-0002", `entry is not in the project: ${entry}`, entry);
254
+ }
255
+
256
+ const programs = new Map();
257
+ const programFor = (id) => {
258
+ if (programs.has(id)) return programs.get(id);
259
+ if (files[id] === undefined) {
260
+ throw failure("ELI-BROWSER-0003", `missing source for import: ${id}`, id);
261
+ }
262
+ let program;
263
+ try {
264
+ program = compile_ir_string(files[id], id, macroContext);
265
+ } catch (error) {
266
+ throw new BrowserCompileError([diagnosticOf(error, id)]);
267
+ }
268
+ programs.set(id, program);
269
+ return program;
270
+ };
271
+
272
+ const plan = project_plan([entry], (id) => importSpecifiers(programFor(id))
273
+ .filter((node) => localSourceSpecifier(node.value))
274
+ .map((node) => resolvePath(id, node.value)));
275
+
276
+ const modules = {};
277
+ for (const id of dependencyOrder(plan.modules)) {
278
+ const output = outputPathFor(id);
279
+ const program = programFor(id);
280
+ rewriteSpecifiers(program, id, resolveExternal);
281
+ const emission = emit_ir_string_with_source_map(
282
+ program,
283
+ files[id],
284
+ output,
285
+ mapSourcePath(output, id),
286
+ );
287
+ modules[output] = {
288
+ id,
289
+ source: files[id],
290
+ javascript: rewriteEmittedExternals(emission.javascript, id, resolveExternal),
291
+ sourceMap: emission.sourceMap,
292
+ };
293
+ }
294
+ return { plan, modules };
295
+ }
296
+
297
+ /* ---------------------------------------------------------------- execute */
298
+
299
+ /**
300
+ * Turns compiled modules into importable blob URLs, dependencies first.
301
+ *
302
+ * A blob module has no directory, so its relative imports cannot resolve. Each
303
+ * local specifier was therefore rewritten to a relative path during compilation
304
+ * and is replaced here by the blob URL of the module it names. Only import
305
+ * specifiers are touched, never a string literal that resembles one.
306
+ *
307
+ * @returns {{ entryUrl: string, urls: Record<string, string>, release: () => void }}
308
+ */
309
+ export function moduleGraphUrls(modules, entry) {
310
+ const urls = {};
311
+ const created = [];
312
+ const outputs = Object.keys(modules);
313
+
314
+ const targetOf = (from, specifier) => {
315
+ const parts = splitPath(dirname(from));
316
+ for (const part of specifier.split("/")) {
317
+ if (part === "" || part === ".") continue;
318
+ if (part === "..") parts.pop();
319
+ else parts.push(part);
320
+ }
321
+ return parts.join("/");
322
+ };
323
+ const rewritePattern = (code, from, pattern) => code.replace(
324
+ pattern,
325
+ (whole, prefix, quoted) => {
326
+ const specifier = quoted.slice(1, -1);
327
+ if (!specifier.startsWith(".")) return whole;
328
+ const url = urls[targetOf(from, specifier)];
329
+ return url === undefined ? whole : `${prefix}"${url}"`;
330
+ },
331
+ );
332
+
333
+ for (const outputPath of outputs) {
334
+ let code = modules[outputPath].javascript;
335
+ code = rewritePattern(code, outputPath, /(\bfrom\s+)("[^"]+")/gu);
336
+ code = rewritePattern(code, outputPath, /(\bimport\s+)("[^"]+")/gu);
337
+ urls[outputPath] = URL.createObjectURL(
338
+ new Blob([code], { type: "text/javascript" }),
339
+ );
340
+ created.push(urls[outputPath]);
341
+ }
342
+
343
+ const entryUrl = urls[outputPathFor(entry)];
344
+ if (entryUrl === undefined) {
345
+ for (const url of created) URL.revokeObjectURL(url);
346
+ throw failure("ELI-BROWSER-0004", `compiled entry is missing: ${entry}`, entry);
347
+ }
348
+ const release = () => {
349
+ for (const url of created) URL.revokeObjectURL(url);
350
+ };
351
+ return { entryUrl, urls, release };
352
+ }
353
+
354
+ export const browserHostSurface = Object.freeze({
355
+ sourceExtension: SOURCE_EXTENSION,
356
+ outputExtension: OUTPUT_EXTENSION,
357
+ });
@@ -0,0 +1,60 @@
1
+ // Module worker for the browser compile host.
2
+ //
3
+ // Compilation runs here so an editor stays responsive, and the host is imported
4
+ // by a relative path because a worker realm has no document and therefore no
5
+ // import map. The worker returns plain data: the main thread creates the blob
6
+ // URLs and executes the entry, so no blob URL crosses a realm boundary.
7
+
8
+ import { compileProject, compileSource, outputPathFor } from "./host.mjs";
9
+
10
+ // A function cannot cross the worker boundary, so the caller passes the URL the
11
+ // package is served from and the worker builds the resolver. Pointing the
12
+ // runtime at a URL rather than an import map is what lets compiled output run
13
+ // from blob modules, which have no directory of their own.
14
+ function externalResolver(runtimeBase) {
15
+ if (typeof runtimeBase !== "string" || runtimeBase.length === 0) return undefined;
16
+ const base = new URL(runtimeBase);
17
+ return (specifier) => specifier.startsWith("eliscript/")
18
+ ? new URL(specifier.slice("eliscript/".length), base).href
19
+ : undefined;
20
+ }
21
+
22
+ function compile(request) {
23
+ const resolveExternal = externalResolver(request.runtimeBase);
24
+ if (request.mode === "project") {
25
+ return compileProject({
26
+ files: request.files,
27
+ entry: request.entry,
28
+ resolveExternal,
29
+ });
30
+ }
31
+ const options = resolveExternal === undefined ? {} : { resolveExternal };
32
+ const output = outputPathFor(request.filename);
33
+ return {
34
+ plan: { entries: [request.filename], modules: [{ id: request.filename, dependencies: [] }] },
35
+ modules: {
36
+ [output]: {
37
+ id: request.filename,
38
+ source: request.source,
39
+ ...compileSource(request.source, request.filename, options),
40
+ },
41
+ },
42
+ };
43
+ }
44
+
45
+ self.addEventListener("message", (event) => {
46
+ const { id, request } = event.data ?? {};
47
+ try {
48
+ const result = compile(request);
49
+ self.postMessage({ id, ok: true, plan: result.plan, modules: result.modules });
50
+ } catch (error) {
51
+ self.postMessage({
52
+ id,
53
+ ok: false,
54
+ message: error?.message ?? String(error),
55
+ diagnostics: error?.diagnostics ?? [],
56
+ });
57
+ }
58
+ });
59
+
60
+ self.postMessage({ ready: true });
@@ -0,0 +1,118 @@
1
+ # Compiler
2
+
3
+ [Project README](../README.md) | [Bootstrap compiler](../bootstrap/README.md) |
4
+ [Specifications](../specs/README.md)
5
+
6
+ ## Modules
7
+
8
+ This directory contains the first Emacs Lisp seed compiler:
9
+
10
+ - `eliscript-reader.el` reads one or more `.eli` forms.
11
+ - `eliscript-form.el` carries source spans through front-end phases.
12
+ - `eliscript-diagnostic.el` defines shared compiler condition types.
13
+ - `eliscript-macro-eval.el` interprets the deterministic macro language.
14
+ - `eliscript-expander.el` registers macros and recursively expands their output.
15
+ - `eliscript-symbol.el` owns identifier validation and ECMAScript name mapping.
16
+ - `eliscript-analyzer.el` validates module and lexical bindings.
17
+ - `eliscript-ir.el` defines the explicit, source-located compiler IR.
18
+ - `eliscript-lower.el` lowers analyzed forms into IR nodes.
19
+ - `eliscript-ir-emitter.el` emits standard ECMAScript modules directly from IR.
20
+ - `eliscript-source-map.el` encodes IR span markers as Source Map v3 mappings.
21
+ - `eliscript-emitter.el` retains the original form emitter as a compatibility
22
+ backend and supplies shared formatting helpers.
23
+ - `eliscript.el` exposes the public string and file compilation API.
24
+ - `eliscript-cli.el` implements the batch command used by `bin/eliscript`.
25
+ - `eliscript-project.el` discovers expanded local imports and writes complete
26
+ source-mapped ESM trees.
27
+ - `eliscript-project-cli.el` implements the batch command used by
28
+ `bin/eliscript-build`.
29
+
30
+ ## Project Requests
31
+
32
+ Direct project flags and versioned configuration both produce an
33
+ `eliscript-project-request` and execute it through
34
+ `eliscript-project-execute`. A minimal `eliscript.json` is:
35
+
36
+ ```json
37
+ {
38
+ "schemaVersion": 1,
39
+ "sourceRoot": "src",
40
+ "entry": "main.eli",
41
+ "outDir": "dist"
42
+ }
43
+ ```
44
+
45
+ Run it with `./bin/eliscript-build --config eliscript.json`. Paths in the file
46
+ are relative to the file as defined by specification 0106. Explicit entry,
47
+ root, output, portable-entry, and no-cache flags override configured values.
48
+ Unknown keys and unsupported versions fail with structured diagnostics.
49
+
50
+ Run `./bin/eliscript-check --config eliscript.json --json` to validate the same
51
+ entry closure without writing the configured output directory, manifest, or
52
+ cache. `--stdin-file FILE` checks standard input as the current contents of an
53
+ existing project source for editor integrations.
54
+
55
+ `./bin/eliscript-build --config eliscript.json --stdin-file FILE` performs a
56
+ real build with standard input as the current contents of that existing source.
57
+ Virtual builds disable cache reuse, preserve the canonical source identity in
58
+ diagnostics and Source Maps, and never rewrite the source file.
59
+
60
+ The schema is a compiler project contract. Application framework, bundler,
61
+ publishing, hosting, and development-server options belong in replaceable
62
+ adapters outside this file and outside core maturity evidence.
63
+
64
+ ## Pipeline
65
+
66
+ The current pipeline expands user macros before passing forms through lexical
67
+ analysis and JavaScript emission. Macro environments are isolated per
68
+ compilation, and expanded forms are validated for resolution, mutability,
69
+ exports, duplicate declarations, and output-name collisions. Located forms
70
+ carry source spans through expansion, analysis, IR lowering, direct IR
71
+ emission, and optional Source Map v3 output. The public compiler never
72
+ reconstructs reader-shaped forms after lowering. Public entry points support
73
+ both interactive Emacs use and clean batch builds.
74
+
75
+ The analyzer also tracks recur targets, tail positions, physical function
76
+ parameter slots, and exception boundaries. Lowering preserves binding loops
77
+ and recurrence as distinct IR nodes; the emitter turns valid targets into
78
+ deterministic labeled JavaScript loops with simultaneous temporary-backed
79
+ rebinding.
80
+
81
+ ## Persistent Literal Linking
82
+
83
+ `persistent-list-literal`, `persistent-vector-literal`,
84
+ `persistent-map-literal`, `persistent-set-literal`,
85
+ `persistent-queue-literal`, and evaluated Keyword
86
+ literals emit calls through the package-owned `eliscript/runtime/literals.mjs` ESM
87
+ ABI. The import is inserted once and only when one of those runtime values is
88
+ constructed. Square-bracket expressions, brace Map expressions, `#{...}` Set
89
+ expressions, `#queue [...]`, `(list ...)`, `(vector ...)`, `(hash-map ...)`,
90
+ `(hash-set ...)`, `(queue ...)`, and source `:keywords` use that path;
91
+ `js-array`, `js-cons`, and
92
+ `js-object` remain direct native container forms. Keyword-shaped tokens in
93
+ static host-key positions also remain JavaScript strings and do not link the
94
+ literal runtime by themselves. The reader desugars `{key value ...}` into
95
+ located `hash-map` syntax, `#{...}` into located `hash-set` syntax, and
96
+ `#queue [...]` into located `queue` syntax,
97
+ validates Keyword names, and rejects malformed delimiters or odd Map forms
98
+ before analysis. Language-level `nth` and `length` link the
99
+ collection protocol runtime, while `js-nth` and `js-length` retain direct host
100
+ access without that dependency. `car`, `cdr`, and `cons` link the canonical
101
+ persistent List operations; they no longer imply native Array behavior.
102
+ The former `array` and `object` constructor aliases are not compiler forms;
103
+ without an ordinary user binding they are diagnosed as unbound symbols.
104
+
105
+ ## Application Lowering
106
+
107
+ UI frameworks use the same explicit ESM imports and ordinary function calls as
108
+ any other host library. The compiler reserves no framework-specific forms,
109
+ introduces no framework-specific IR nodes, and injects no framework runtime.
110
+
111
+ This application compatibility surface is independent of persistent literal
112
+ semantics and is not a dependency of the compiler or runtime ABI.
113
+
114
+ ## Source Discipline
115
+
116
+ The Emacs Lisp and self-hosted implementations must share a conformance suite.
117
+ Generated JavaScript is a build artifact and must never become the hand-edited
118
+ source of the self-hosted compiler.