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,401 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createInterface } from "node:readline";
4
+ import { resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ import {
8
+ EvaluationSession,
9
+ evaluationResultFormat,
10
+ evaluationResultVersion,
11
+ readEvaluationFile,
12
+ } from "./evaluation.mjs";
13
+
14
+ const usage = `Usage: eliscript-eval [OPTIONS]
15
+
16
+ Options:
17
+ --repl Run the persistent terminal REPL (default mode)
18
+ --stdio Read and write one JSON record per line
19
+ --eval SOURCE Evaluate one form
20
+ --file FILE Load one complete Eliscript source file
21
+ --root DIRECTORY Set the project root for REPL, --eval, or --file
22
+ --json Print the one-shot result as JSON
23
+ --prompt Always print the REPL banner and prompts
24
+ --no-prompt Never print the REPL banner or prompts
25
+ --help Show this help
26
+ `;
27
+
28
+ const replHelp = `Commands:
29
+ :help Show this command summary
30
+ :load FILE Load one complete source file
31
+ :reload Reload the last successfully loaded file
32
+ :reset Discard the current namespace
33
+ :quit Close the session
34
+ `;
35
+
36
+ const replFilename = "<repl>.eli";
37
+
38
+ function cliError(message) {
39
+ const error = new Error(message);
40
+ error.code = "ELI-C0001";
41
+ return error;
42
+ }
43
+
44
+ function parseArguments(argv) {
45
+ const options = {
46
+ json: false,
47
+ mode: null,
48
+ root: null,
49
+ source: null,
50
+ file: null,
51
+ prompt: "auto",
52
+ };
53
+ const chooseMode = (mode) => {
54
+ if (options.mode !== null) throw cliError("choose exactly one evaluation mode");
55
+ options.mode = mode;
56
+ };
57
+ const choosePrompt = (prompt) => {
58
+ if (options.prompt !== "auto") throw cliError("choose at most one prompt mode");
59
+ options.prompt = prompt;
60
+ };
61
+ for (let index = 0; index < argv.length; index += 1) {
62
+ const argument = argv[index];
63
+ switch (argument) {
64
+ case "--repl":
65
+ chooseMode("repl");
66
+ break;
67
+ case "--stdio":
68
+ chooseMode("stdio");
69
+ break;
70
+ case "--eval":
71
+ chooseMode("evaluate");
72
+ options.source = argv[++index];
73
+ if (options.source === undefined) throw cliError("--eval requires SOURCE");
74
+ break;
75
+ case "--file":
76
+ chooseMode("load");
77
+ options.file = argv[++index];
78
+ if (options.file === undefined) throw cliError("--file requires FILE");
79
+ break;
80
+ case "--root":
81
+ options.root = argv[++index];
82
+ if (options.root === undefined) throw cliError("--root requires DIRECTORY");
83
+ break;
84
+ case "--json": options.json = true; break;
85
+ case "--prompt": choosePrompt("always"); break;
86
+ case "--no-prompt": choosePrompt("never"); break;
87
+ case "--help": chooseMode("help"); break;
88
+ default: throw cliError(`unknown option: ${argument}`);
89
+ }
90
+ }
91
+ if (options.mode === null) options.mode = "repl";
92
+ if (options.mode === "stdio" &&
93
+ (options.json || options.root !== null || options.prompt !== "auto")) {
94
+ throw cliError("--stdio accepts complete request records and no presentation options");
95
+ }
96
+ if (options.mode === "repl" && options.json) {
97
+ throw cliError("--json is available only for one-shot evaluation");
98
+ }
99
+ if (options.mode !== "repl" && options.prompt !== "auto") {
100
+ throw cliError("prompt options are available only in REPL mode");
101
+ }
102
+ if (options.mode === "help" &&
103
+ (options.json || options.root !== null || options.prompt !== "auto")) {
104
+ throw cliError("--help does not accept evaluation or presentation options");
105
+ }
106
+ return options;
107
+ }
108
+
109
+ function protocolFailure(message, revision) {
110
+ return {
111
+ format: evaluationResultFormat,
112
+ version: evaluationResultVersion,
113
+ id: null,
114
+ operation: "unknown",
115
+ revision,
116
+ status: "error",
117
+ diagnostic: {
118
+ format: "eliscript-diagnostic",
119
+ version: 1,
120
+ code: "ELI-E0001",
121
+ severity: "error",
122
+ phase: "evaluation-request",
123
+ message,
124
+ },
125
+ };
126
+ }
127
+
128
+ async function runStdio() {
129
+ const session = await EvaluationSession.create();
130
+ const close = () => session.close();
131
+ process.once("exit", close);
132
+ process.once("SIGINT", () => {
133
+ close();
134
+ process.exit(130);
135
+ });
136
+ process.once("SIGTERM", () => {
137
+ close();
138
+ process.exit(143);
139
+ });
140
+ try {
141
+ const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
142
+ for await (const line of input) {
143
+ if (line.trim() === "") continue;
144
+ let result;
145
+ try {
146
+ result = await session.execute(JSON.parse(line));
147
+ } catch (error) {
148
+ result = protocolFailure(
149
+ error instanceof Error ? error.message : String(error),
150
+ session.revision,
151
+ );
152
+ }
153
+ process.stdout.write(`${JSON.stringify(result)}\n`);
154
+ }
155
+ } finally {
156
+ process.removeListener("exit", close);
157
+ close();
158
+ }
159
+ }
160
+
161
+ function diagnosticText(diagnostic) {
162
+ const location = diagnostic?.location;
163
+ const start = location?.start;
164
+ const prefix = location?.file
165
+ ? `${location.file}:${start?.line ?? location.line ?? 1}:` +
166
+ `${start?.column ?? location.column ?? 1}: `
167
+ : "";
168
+ return `${prefix}${diagnostic?.message ?? "evaluation failed"}`;
169
+ }
170
+
171
+ function renderHuman(result) {
172
+ if (result.status === "error") throw cliError(diagnosticText(result.diagnostic));
173
+ if (result.kind === "expression" || result.kind === "definition") {
174
+ return result.hasValue ? result.value : result.binding;
175
+ }
176
+ if (result.kind === "module") return `loaded ${result.bindings.length} bindings`;
177
+ if (result.kind === "reset") return "session reset";
178
+ if (result.kind === "capabilities") return "session ready";
179
+ throw cliError(`unsupported evaluation result kind: ${result.kind}`);
180
+ }
181
+
182
+ function writeHumanResult(result, recoverable = false) {
183
+ if (result.stdout) process.stdout.write(result.stdout);
184
+ try {
185
+ process.stdout.write(`${renderHuman(result)}\n`);
186
+ return true;
187
+ } catch (error) {
188
+ if (!recoverable) throw error;
189
+ process.stdout.write(`eliscript-eval: ${error.message}\n`);
190
+ return false;
191
+ }
192
+ }
193
+
194
+ function writeRecoverableError(error) {
195
+ const message = error?.eliscriptDiagnostic
196
+ ? diagnosticText(error.eliscriptDiagnostic)
197
+ : error instanceof Error ? error.message : String(error);
198
+ process.stdout.write(`eliscript-eval: ${message}\n`);
199
+ }
200
+
201
+ function replCommand(line) {
202
+ const match = line.trim().match(/^:([^\s]+)(?:\s+(.*))?$/u);
203
+ return match ? { name: match[1], argument: match[2]?.trim() ?? "" } : null;
204
+ }
205
+
206
+ function showPrompt(_input, visible, continuation) {
207
+ if (!visible) return;
208
+ process.stdout.write(continuation ? " ... " : "eliscript=> ");
209
+ }
210
+
211
+ async function runTerminalCommand(command, context) {
212
+ const { session, options } = context;
213
+ switch (command.name) {
214
+ case "help":
215
+ if (command.argument !== "") throw cliError(":help does not accept arguments");
216
+ process.stdout.write(replHelp);
217
+ return false;
218
+ case "load": {
219
+ if (command.argument === "") throw cliError(":load requires FILE");
220
+ const file = readEvaluationFile(command.argument);
221
+ const result = await session.execute({
222
+ id: ++context.nextId,
223
+ operation: "load",
224
+ source: file.source,
225
+ filename: file.filename,
226
+ root: options.root,
227
+ });
228
+ if (writeHumanResult(result, true)) context.lastFile = file.filename;
229
+ return false;
230
+ }
231
+ case "reload": {
232
+ if (command.argument !== "") throw cliError(":reload does not accept arguments");
233
+ if (context.lastFile === null) throw cliError(":reload requires a prior successful :load");
234
+ const file = readEvaluationFile(context.lastFile);
235
+ const result = await session.execute({
236
+ id: ++context.nextId,
237
+ operation: "load",
238
+ source: file.source,
239
+ filename: file.filename,
240
+ root: options.root,
241
+ });
242
+ if (writeHumanResult(result, true)) context.lastFile = file.filename;
243
+ return false;
244
+ }
245
+ case "reset": {
246
+ if (command.argument !== "") throw cliError(":reset does not accept arguments");
247
+ writeHumanResult(await session.execute({
248
+ id: ++context.nextId,
249
+ operation: "reset",
250
+ }), true);
251
+ context.lastFile = null;
252
+ return false;
253
+ }
254
+ case "quit":
255
+ if (command.argument !== "") throw cliError(":quit does not accept arguments");
256
+ return true;
257
+ default:
258
+ throw cliError(`unknown REPL command: :${command.name}`);
259
+ }
260
+ }
261
+
262
+ async function runRepl(options) {
263
+ const session = await EvaluationSession.create();
264
+ const promptVisible = options.prompt === "always" ||
265
+ (options.prompt === "auto" && process.stdin.isTTY && process.stdout.isTTY);
266
+ const input = createInterface({
267
+ input: process.stdin,
268
+ ...(promptVisible ? { output: process.stdout } : {}),
269
+ terminal: promptVisible && Boolean(process.stdin.isTTY),
270
+ crlfDelay: Infinity,
271
+ });
272
+ const context = { session, options, nextId: 0, lastFile: null };
273
+ let source = "";
274
+ let interrupted = false;
275
+ const close = () => session.close();
276
+ const terminate = () => {
277
+ close();
278
+ process.exit(143);
279
+ };
280
+ process.once("exit", close);
281
+ process.once("SIGTERM", terminate);
282
+ input.on("SIGINT", () => {
283
+ if (source !== "") {
284
+ source = "";
285
+ process.stdout.write("^C\n");
286
+ showPrompt(input, promptVisible, false);
287
+ } else {
288
+ interrupted = true;
289
+ input.close();
290
+ }
291
+ });
292
+ try {
293
+ if (promptVisible) {
294
+ process.stdout.write("Eliscript REPL. Type :help for commands.\n");
295
+ showPrompt(input, true, false);
296
+ }
297
+ for await (const line of input) {
298
+ if (source === "") {
299
+ const command = replCommand(line);
300
+ if (command) {
301
+ try {
302
+ if (await runTerminalCommand(command, context)) break;
303
+ } catch (error) {
304
+ writeRecoverableError(error);
305
+ }
306
+ showPrompt(input, promptVisible, false);
307
+ continue;
308
+ }
309
+ }
310
+ source = source === "" ? line : `${source}\n${line}`;
311
+ let description;
312
+ try {
313
+ description = session.compiler.evaluation_input_description(
314
+ source,
315
+ replFilename,
316
+ );
317
+ } catch (error) {
318
+ writeRecoverableError(error);
319
+ source = "";
320
+ showPrompt(input, promptVisible, false);
321
+ continue;
322
+ }
323
+ if (description.status === "incomplete") {
324
+ showPrompt(input, promptVisible, true);
325
+ continue;
326
+ }
327
+ if (description.status === "complete") {
328
+ writeHumanResult(await session.execute({
329
+ id: ++context.nextId,
330
+ operation: "evaluate",
331
+ source,
332
+ filename: replFilename,
333
+ root: options.root,
334
+ }), true);
335
+ }
336
+ source = "";
337
+ showPrompt(input, promptVisible, false);
338
+ }
339
+ if (!interrupted && source !== "") {
340
+ writeHumanResult(await session.execute({
341
+ id: ++context.nextId,
342
+ operation: "evaluate",
343
+ source,
344
+ filename: replFilename,
345
+ root: options.root,
346
+ }), true);
347
+ }
348
+ } finally {
349
+ process.removeListener("exit", close);
350
+ process.removeListener("SIGTERM", terminate);
351
+ input.close();
352
+ close();
353
+ }
354
+ }
355
+
356
+ async function runOneShot(options) {
357
+ const session = await EvaluationSession.create();
358
+ try {
359
+ let request;
360
+ if (options.mode === "load") {
361
+ const file = readEvaluationFile(options.file);
362
+ request = {
363
+ id: 0,
364
+ operation: "load",
365
+ source: file.source,
366
+ filename: file.filename,
367
+ root: options.root,
368
+ };
369
+ } else {
370
+ request = {
371
+ id: 0,
372
+ operation: "evaluate",
373
+ source: options.source,
374
+ filename: "<command-line>.eli",
375
+ root: options.root,
376
+ };
377
+ }
378
+ const result = await session.execute(request);
379
+ if (options.json) process.stdout.write(`${JSON.stringify(result)}\n`);
380
+ else writeHumanResult(result);
381
+ } finally {
382
+ session.close();
383
+ }
384
+ }
385
+
386
+ export async function main(arguments_ = process.argv.slice(2)) {
387
+ try {
388
+ const options = parseArguments(arguments_);
389
+ if (options.mode === "help") process.stdout.write(usage);
390
+ else if (options.mode === "stdio") await runStdio();
391
+ else if (options.mode === "repl") await runRepl(options);
392
+ else await runOneShot(options);
393
+ } catch (error) {
394
+ process.stderr.write(`eliscript-eval: ${error.message}\n`);
395
+ process.exitCode = 1;
396
+ }
397
+ }
398
+
399
+ const isMain = process.argv[1] !== undefined &&
400
+ resolve(process.argv[1]) === fileURLToPath(import.meta.url);
401
+ if (isMain) await main();