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,1469 @@
1
+ // Generated by Eliscript. Do not edit.
2
+ const __eliscript_truthy = (value) => value !== false && value != null;
3
+
4
+ import {literal_node, undefined_node, symbol_node, keyword_node, collection_node, node_kind, node_span, node_value, node_name, node_items} from "./syntax.mjs";
5
+ const maximum_depth = 100;
6
+ const gensym_prefix_pattern = /^[A-Za-z_$][A-Za-z0-9_$?!*+=<>-]*$/;
7
+ const raise_error = (message) => { throw new Error(message); };
8
+ const raise_diagnostic = (diagnostic) => { const p = diagnostic.location.start; const error = new Error(`${diagnostic.location.file}:${p.line}:${p.column}: ${diagnostic.message}`); error.eliscriptDiagnostic = diagnostic; throw error; };
9
+ const guard = (operation, onError) => { try { return operation(); } catch (error) { return onError(error.message); } };
10
+ function expander_fail(context, span, message) {
11
+ return ((file) => {
12
+ return raise_diagnostic(({"format": "eliscript-diagnostic", "version": 1, "code": "ELI-X0001", "severity": "error", "phase": "expansion", "message": message, "location": ({"file": file, "start": ({"offset": (__eliscript_truthy(span) ? (span)["start"] : 0), "line": (__eliscript_truthy(span) ? (span)["line"] : 1), "column": (__eliscript_truthy(span) ? (span)["column"] : 1)}), "end": ({"offset": (__eliscript_truthy(span) ? (span)["end"] : 0), "line": (__eliscript_truthy(span) ? (span)["endLine"] : 1), "column": (__eliscript_truthy(span) ? (span)["endColumn"] : 1)})})}));
13
+ })(((__eliscript_value_1) => (__eliscript_truthy(__eliscript_value_1) ? __eliscript_value_1 : ((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? __eliscript_value_2 : "<input>"))(((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? (span)["filename"] : __eliscript_value_3))(span))))((context)["filename"]));
14
+ }
15
+ function symbol_node_p(node) {
16
+ return ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? (node_kind(node) === "symbol") : __eliscript_value_4))(node);
17
+ }
18
+ function keyword_node_p(node) {
19
+ return ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? (node_kind(node) === "keyword") : __eliscript_value_5))(node);
20
+ }
21
+ function literal_node_p(node) {
22
+ return ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? (node_kind(node) === "literal") : __eliscript_value_6))(node);
23
+ }
24
+ function null_node_p(node) {
25
+ return ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? (node_value(node) == null) : __eliscript_value_7))(literal_node_p(node));
26
+ }
27
+ function list_node_p(node) {
28
+ return ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? __eliscript_value_8 : ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? (node_kind(node) === "list") : __eliscript_value_9))(node)))(null_node_p(node));
29
+ }
30
+ function vector_node_p(node) {
31
+ return ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? (node_kind(node) === "vector") : __eliscript_value_10))(node);
32
+ }
33
+ function map_node_p(node) {
34
+ return ((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? ((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? ((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? (node_name(((((node_items(node)) ?? [])[0]) ?? null)) === "hash-map") : __eliscript_value_14))(symbol_node_p(((((node_items(node)) ?? [])[0]) ?? null))) : __eliscript_value_13))(((node_items(node))["length"] > 0)) : __eliscript_value_12))((node_kind(node) === "list")) : __eliscript_value_11))(node);
35
+ }
36
+ function list_items(node) {
37
+ return (__eliscript_truthy(null_node_p(node)) ? [] : (__eliscript_truthy(((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? (node_kind(node) === "list") : __eliscript_value_15))(node)) ? node_items(node) : undefined));
38
+ }
39
+ function sequence_items(node) {
40
+ return (__eliscript_truthy(null_node_p(node)) ? [] : (__eliscript_truthy(((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? __eliscript_value_16 : ((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? (node_kind(node) === "vector") : __eliscript_value_18))(node)))(((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? (node_kind(node) === "list") : __eliscript_value_17))(node))) ? node_items(node) : undefined));
41
+ }
42
+ function make_list(items, span) {
43
+ return (__eliscript_truthy(((items)["length"] === 0)) ? literal_node(null, span) : collection_node("list", items, span));
44
+ }
45
+ function rebuild_collection(source, items) {
46
+ return (__eliscript_truthy((node_kind(source) === "list")) ? make_list(items, node_span(source)) : collection_node(node_kind(source), items, node_span(source)));
47
+ }
48
+ function locate_generated(node, span) {
49
+ return (__eliscript_truthy((node_kind(node) === "literal")) ? literal_node(node_value(node), span) : (__eliscript_truthy((node_kind(node) === "undefined")) ? undefined_node(span) : (__eliscript_truthy((node_kind(node) === "symbol")) ? symbol_node(node_name(node), span) : (__eliscript_truthy((node_kind(node) === "keyword")) ? keyword_node(node_name(node), span) : (__eliscript_truthy(((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? __eliscript_value_19 : (node_kind(node) === "vector")))((node_kind(node) === "list"))) ? ((items) => {
50
+ (node_items(node))["forEach"]((item) => {
51
+ return (items)["push"](locate_generated(item, span));
52
+ });
53
+ return (__eliscript_truthy((node_kind(node) === "list")) ? make_list(items, span) : collection_node("vector", items, span));
54
+ })([]) : raise_error("macro produced an unsupported value"))))));
55
+ }
56
+ function node_display(node) {
57
+ return (__eliscript_truthy((!__eliscript_truthy(node))) ? "nil" : (__eliscript_truthy((node_kind(node) === "undefined")) ? "undefined" : (__eliscript_truthy((node_kind(node) === "symbol")) ? node_name(node) : (__eliscript_truthy((node_kind(node) === "keyword")) ? (String(":") + String(node_name(node))) : (__eliscript_truthy((node_kind(node) === "literal")) ? ((value) => {
58
+ return (__eliscript_truthy((value == null)) ? "nil" : (__eliscript_truthy((value === true)) ? "t" : (__eliscript_truthy((value === false)) ? "false" : (__eliscript_truthy((typeof value === "string")) ? (JSON)["stringify"](value) : (String(value))))));
59
+ })(node_value(node)) : (__eliscript_truthy(((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? __eliscript_value_20 : (node_kind(node) === "vector")))((node_kind(node) === "list"))) ? ((items) => {
60
+ return ((contents) => {
61
+ return (__eliscript_truthy(((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? ((__eliscript_value_22) => (__eliscript_truthy(__eliscript_value_22) ? ((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? (node_name(((((items) ?? [])[0]) ?? null)) === "quote") : __eliscript_value_23))(symbol_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_22))(((items)["length"] === 2)) : __eliscript_value_21))((node_kind(node) === "list"))) ? (String("'") + String(node_display(((((items) ?? [])[1]) ?? null)))) : (__eliscript_truthy((node_kind(node) === "list")) ? (String("(") + String(contents) + String(")")) : (String("[") + String(contents) + String("]"))));
62
+ })(((items)["map"](node_display))["join"](" "));
63
+ })(node_items(node)) : "<unsupported>"))))));
64
+ }
65
+ function form_operator_p(node, name) {
66
+ return ((items) => {
67
+ return ((__eliscript_value_24) => (__eliscript_truthy(__eliscript_value_24) ? ((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? ((__eliscript_value_26) => (__eliscript_truthy(__eliscript_value_26) ? (node_name(((((items) ?? [])[0]) ?? null)) === name) : __eliscript_value_26))(symbol_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_25))(((items)["length"] > 0)) : __eliscript_value_24))((!__eliscript_truthy((items === undefined))));
68
+ })(list_items(node));
69
+ }
70
+ function make_eval_scope(parent, context = null) {
71
+ return ({"parent": parent, "values": new Map(), "context": ((__eliscript_value_27) => (__eliscript_truthy(__eliscript_value_27) ? __eliscript_value_27 : ((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? (parent)["context"] : __eliscript_value_28))(parent)))(context)});
72
+ }
73
+ function scope_bind(scope, name, value) {
74
+ ((scope)["values"])["set"](name, value);
75
+ return value;
76
+ }
77
+ function scope_find(scope, name) {
78
+ return ((current, found) => {
79
+ (() => {
80
+ while (__eliscript_truthy(((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? (found === undefined) : __eliscript_value_29))(current))) {
81
+ ((values) => {
82
+ return (__eliscript_truthy((values)["has"](name)) ? ((found = ({"scope": current, "value": (values)["get"](name)}))) : null);
83
+ })((current)["values"]);
84
+ ((current = (current)["parent"]));
85
+ }
86
+ return null;
87
+ })();
88
+ return found;
89
+ })(scope, undefined);
90
+ }
91
+ function scope_value(scope, name) {
92
+ return ((found) => {
93
+ return (__eliscript_truthy((found === undefined)) ? raise_error((String("void variable: ") + String(name))) : (found)["value"]);
94
+ })(scope_find(scope, name));
95
+ }
96
+ function scope_set(scope, name, value) {
97
+ return ((found) => {
98
+ return (__eliscript_truthy((found === undefined)) ? raise_error((String("cannot set unbound macro variable: ") + String(name))) : (() => {
99
+ (((found)["scope"])["values"])["set"](name, value);
100
+ return value;
101
+ })());
102
+ })(scope_find(scope, name));
103
+ }
104
+ function reserve_name(scope, name) {
105
+ (((scope)["context"])["reservedNames"])["add"](name);
106
+ return name;
107
+ }
108
+ function gensym_prefix(node) {
109
+ return ((prefix) => {
110
+ (__eliscript_truthy(((__eliscript_value_31) => (__eliscript_truthy(__eliscript_value_31) ? __eliscript_value_31 : (prefix)["startsWith"]("__eliscript_")))((!__eliscript_truthy((gensym_prefix_pattern)["test"](prefix))))) ? raise_error((String("invalid gensym prefix: ") + String(prefix))) : null);
111
+ return prefix;
112
+ })((__eliscript_truthy(symbol_node_p(node)) ? node_name(node) : (__eliscript_truthy(((__eliscript_value_30) => (__eliscript_truthy(__eliscript_value_30) ? (typeof node.value === "string") : __eliscript_value_30))(literal_node_p(node))) ? node_value(node) : raise_error("gensym prefix must be a symbol or string"))));
113
+ }
114
+ function allocate_name(scope, prefix_node) {
115
+ return ((context) => {
116
+ return ((reserved) => {
117
+ return ((prefix) => {
118
+ return ((candidate) => {
119
+ return (() => {
120
+ (() => {
121
+ while (__eliscript_truthy(((__eliscript_value_32) => (__eliscript_truthy(__eliscript_value_32) ? __eliscript_value_32 : (reserved)["has"](candidate)))((candidate === undefined)))) {
122
+ ((context)["gensymCounter"] = ((context)["gensymCounter"] + 1));
123
+ ((candidate = (String(prefix) + String("$G") + String((context)["gensymCounter"]))));
124
+ }
125
+ return null;
126
+ })();
127
+ (reserved)["add"](candidate);
128
+ return symbol_node(candidate, null);
129
+ })();
130
+ })(undefined);
131
+ })(gensym_prefix(prefix_node));
132
+ })((context)["reservedNames"]);
133
+ })((scope)["context"]);
134
+ }
135
+ function auto_gensym(node, scope, names) {
136
+ return ((name) => {
137
+ return (__eliscript_truthy((names)["has"](name)) ? (names)["get"](name) : ((generated) => {
138
+ (names)["set"](name, generated);
139
+ return generated;
140
+ })(allocate_name(scope, literal_node((name)["slice"](0, -1), null))));
141
+ })(node_name(node));
142
+ }
143
+ function truthy_p(node) {
144
+ return (!__eliscript_truthy(((__eliscript_value_33) => (__eliscript_truthy(__eliscript_value_33) ? __eliscript_value_33 : ((__eliscript_value_34) => (__eliscript_truthy(__eliscript_value_34) ? __eliscript_value_34 : ((__eliscript_value_35) => (__eliscript_truthy(__eliscript_value_35) ? (node_value(node) === false) : __eliscript_value_35))(literal_node_p(node))))((node_kind(node) === "undefined"))))(null_node_p(node))));
145
+ }
146
+ function make_boolean(value) {
147
+ return literal_node((__eliscript_truthy(value) ? true : false), null);
148
+ }
149
+ function value_string(node) {
150
+ return (__eliscript_truthy(((__eliscript_value_36) => (__eliscript_truthy(__eliscript_value_36) ? (typeof node.value === "string") : __eliscript_value_36))(literal_node_p(node))) ? node_value(node) : (__eliscript_truthy(symbol_node_p(node)) ? node_name(node) : (__eliscript_truthy(keyword_node_p(node)) ? (String(":") + String(node_name(node))) : (__eliscript_truthy(null_node_p(node)) ? "nil" : (__eliscript_truthy(literal_node_p(node)) ? (String(node_value(node))) : node_display(node))))));
151
+ }
152
+ function require_number(node, operator) {
153
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_37) => (__eliscript_truthy(__eliscript_value_37) ? (typeof node.value === "number") : __eliscript_value_37))(literal_node_p(node))))) ? raise_error((String(operator) + String(" expects numbers, got ") + String(node_display(node)))) : null);
154
+ return node_value(node);
155
+ }
156
+ function nodes_equal(left, right) {
157
+ return (__eliscript_truthy((!__eliscript_truthy((node_kind(left) === node_kind(right))))) ? false : (__eliscript_truthy((node_kind(left) === "literal")) ? (node_value(left) === node_value(right)) : (__eliscript_truthy((node_kind(left) === "undefined")) ? true : (__eliscript_truthy(((__eliscript_value_38) => (__eliscript_truthy(__eliscript_value_38) ? __eliscript_value_38 : (node_kind(left) === "keyword")))((node_kind(left) === "symbol"))) ? (node_name(left) === node_name(right)) : (__eliscript_truthy(((__eliscript_value_39) => (__eliscript_truthy(__eliscript_value_39) ? __eliscript_value_39 : (node_kind(left) === "vector")))((node_kind(left) === "list"))) ? ((left_items, right_items, index, same) => {
158
+ (() => {
159
+ while (__eliscript_truthy(((__eliscript_value_40) => (__eliscript_truthy(__eliscript_value_40) ? (index < (left_items)["length"]) : __eliscript_value_40))(same))) {
160
+ (__eliscript_truthy((!__eliscript_truthy(nodes_equal(((((left_items) ?? [])[index]) ?? null), ((((right_items) ?? [])[index]) ?? null))))) ? ((same = false)) : null);
161
+ ((index = (index + 1)));
162
+ }
163
+ return null;
164
+ })();
165
+ return same;
166
+ })(node_items(left), node_items(right), 0, ((node_items(left))["length"] === (node_items(right))["length"])) : false)))));
167
+ }
168
+ function eval_sequence(forms, scope) {
169
+ return ((result) => {
170
+ (forms)["forEach"]((form) => {
171
+ return ((result = eval_form(form, scope)));
172
+ });
173
+ return result;
174
+ })(literal_node(null, null));
175
+ }
176
+ function eval_args(forms, scope) {
177
+ return ((values) => {
178
+ (forms)["forEach"]((form) => {
179
+ return (values)["push"](eval_form(form, scope));
180
+ });
181
+ return values;
182
+ })([]);
183
+ }
184
+ function eval_if(args, scope) {
185
+ (__eliscript_truthy(((__eliscript_value_41) => (__eliscript_truthy(__eliscript_value_41) ? __eliscript_value_41 : ((args)["length"] > 3)))(((args)["length"] < 2))) ? raise_error("if expects 2..3 arguments") : null);
186
+ return (__eliscript_truthy(truthy_p(eval_form(((((args) ?? [])[0]) ?? null), scope))) ? eval_form(((((args) ?? [])[1]) ?? null), scope) : (__eliscript_truthy(((args)["length"] === 3)) ? eval_form(((((args) ?? [])[2]) ?? null), scope) : literal_node(null, null)));
187
+ }
188
+ function eval_cond(clauses, scope) {
189
+ return ((result, done) => {
190
+ (clauses)["forEach"]((clause) => {
191
+ return (__eliscript_truthy((!__eliscript_truthy(done))) ? ((items) => {
192
+ (__eliscript_truthy(((__eliscript_value_42) => (__eliscript_truthy(__eliscript_value_42) ? __eliscript_value_42 : ((items)["length"] === 0)))((items === undefined))) ? raise_error((String("invalid macro cond clause: ") + String(node_display(clause)))) : null);
193
+ return ((test_value) => {
194
+ return (__eliscript_truthy(truthy_p(test_value)) ? (() => {
195
+ ((result = (__eliscript_truthy(((items)["length"] === 1)) ? test_value : eval_sequence((items)["slice"](1), scope))));
196
+ return ((done = true));
197
+ })() : null);
198
+ })(eval_form(((((items) ?? [])[0]) ?? null), scope));
199
+ })(list_items(clause)) : null);
200
+ });
201
+ return result;
202
+ })(literal_node(null, null), false);
203
+ }
204
+ function parse_eval_binding(binding) {
205
+ return (__eliscript_truthy(symbol_node_p(binding)) ? ({"name": node_name(binding), "value": undefined}) : ((items) => {
206
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_43) => (__eliscript_truthy(__eliscript_value_43) ? ((__eliscript_value_44) => (__eliscript_truthy(__eliscript_value_44) ? ((__eliscript_value_45) => (__eliscript_truthy(__eliscript_value_45) ? symbol_node_p(((((items) ?? [])[0]) ?? null)) : __eliscript_value_45))(((items)["length"] <= 2)) : __eliscript_value_44))(((items)["length"] >= 1)) : __eliscript_value_43))((!__eliscript_truthy((items === undefined))))))) ? raise_error((String("invalid macro let binding: ") + String(node_display(binding)))) : null);
207
+ return ({"name": node_name(((((items) ?? [])[0]) ?? null)), "value": ((((items) ?? [])[1]) ?? null)});
208
+ })(list_items(binding)));
209
+ }
210
+ function eval_let(args, scope, sequential) {
211
+ (__eliscript_truthy(((args)["length"] === 0)) ? raise_error("macro let requires a binding list") : null);
212
+ return ((binding_items) => {
213
+ return ((child) => {
214
+ return (() => {
215
+ (__eliscript_truthy((binding_items === undefined)) ? raise_error("macro let bindings must be a list") : null);
216
+ (__eliscript_truthy(sequential) ? (binding_items)["forEach"]((binding) => {
217
+ return ((parsed) => {
218
+ return ((value_form) => {
219
+ return ((value) => {
220
+ return scope_bind(child, (parsed)["name"], value);
221
+ })((__eliscript_truthy((value_form === undefined)) ? literal_node(null, null) : eval_form(value_form, child)));
222
+ })((parsed)["value"]);
223
+ })(parse_eval_binding(binding));
224
+ }) : ((parsed_bindings) => {
225
+ (binding_items)["forEach"]((binding) => {
226
+ return ((parsed) => {
227
+ return ((value_form) => {
228
+ return ((value) => {
229
+ return (parsed_bindings)["push"](({"name": (parsed)["name"], "value": value}));
230
+ })((__eliscript_truthy((value_form === undefined)) ? literal_node(null, null) : eval_form(value_form, scope)));
231
+ })((parsed)["value"]);
232
+ })(parse_eval_binding(binding));
233
+ });
234
+ return (parsed_bindings)["forEach"]((binding) => {
235
+ return scope_bind(child, (binding)["name"], (binding)["value"]);
236
+ });
237
+ })([]));
238
+ return eval_sequence((args)["slice"](1), child);
239
+ })();
240
+ })(make_eval_scope(scope));
241
+ })(list_items(((((args) ?? [])[0]) ?? null)));
242
+ }
243
+ function eval_setq(args, scope) {
244
+ (__eliscript_truthy(((__eliscript_value_46) => (__eliscript_truthy(__eliscript_value_46) ? __eliscript_value_46 : (((args)["length"] % 2) === 1)))(((args)["length"] === 0))) ? raise_error("macro setq expects name/value pairs") : null);
245
+ return ((index, result) => {
246
+ (() => {
247
+ while (__eliscript_truthy((index < (args)["length"]))) {
248
+ ((name) => {
249
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name)))) ? raise_error("macro setq target must be a symbol") : null);
250
+ ((result = eval_form(((((args) ?? [])[(index + 1)]) ?? null), scope)));
251
+ return scope_set(scope, node_name(name), result);
252
+ })(((((args) ?? [])[index]) ?? null));
253
+ ((index = (index + 2)));
254
+ }
255
+ return null;
256
+ })();
257
+ return result;
258
+ })(0, literal_node(null, null));
259
+ }
260
+ function splice_form_p(node, depth) {
261
+ return ((__eliscript_value_47) => (__eliscript_truthy(__eliscript_value_47) ? form_operator_p(node, ",@") : __eliscript_value_47))((depth === 1));
262
+ }
263
+ function quasiquote_items(items, scope, depth, auto_gensyms) {
264
+ return ((result) => {
265
+ (items)["forEach"]((item) => {
266
+ return (__eliscript_truthy(splice_form_p(item, depth)) ? ((parts) => {
267
+ return ((value) => {
268
+ return ((spliced) => {
269
+ return (() => {
270
+ (__eliscript_truthy((spliced === undefined)) ? raise_error((String("cannot splice ") + String(node_display(value)))) : null);
271
+ return (spliced)["forEach"]((part) => {
272
+ return (result)["push"](part);
273
+ });
274
+ })();
275
+ })(sequence_items(value));
276
+ })((__eliscript_truthy(((parts)["length"] === 2)) ? eval_form(((((parts) ?? [])[1]) ?? null), scope) : raise_error(",@ expects one value")));
277
+ })(node_items(item)) : (result)["push"](quasiquote_node(item, scope, depth, auto_gensyms)));
278
+ });
279
+ return result;
280
+ })([]);
281
+ }
282
+ function quasiquote_node(node, scope, depth, auto_gensyms) {
283
+ return (__eliscript_truthy(vector_node_p(node)) ? collection_node("vector", quasiquote_items(node_items(node), scope, depth, auto_gensyms), node_span(node)) : (__eliscript_truthy(((__eliscript_value_48) => (__eliscript_truthy(__eliscript_value_48) ? form_operator_p(node, ",") : __eliscript_value_48))((depth === 1))) ? ((items) => {
284
+ return (__eliscript_truthy(((items)["length"] === 2)) ? eval_form(((((items) ?? [])[1]) ?? null), scope) : raise_error(", expects one value"));
285
+ })(node_items(node)) : (__eliscript_truthy(((__eliscript_value_49) => (__eliscript_truthy(__eliscript_value_49) ? form_operator_p(node, ",@") : __eliscript_value_49))((depth === 1))) ? raise_error(",@ is only valid inside a collection") : (__eliscript_truthy(form_operator_p(node, "`")) ? ((items) => {
286
+ return (__eliscript_truthy(((items)["length"] === 2)) ? make_list([((((items) ?? [])[0]) ?? null), quasiquote_node(((((items) ?? [])[1]) ?? null), scope, (depth + 1), auto_gensyms)], node_span(node)) : raise_error("` expects one value"));
287
+ })(node_items(node)) : (__eliscript_truthy(((__eliscript_value_50) => (__eliscript_truthy(__eliscript_value_50) ? form_operator_p(node, ",") : __eliscript_value_50))((depth > 1))) ? ((items) => {
288
+ return make_list([((((items) ?? [])[0]) ?? null), quasiquote_node(((((items) ?? [])[1]) ?? null), scope, (depth - 1), auto_gensyms)], node_span(node));
289
+ })(node_items(node)) : (__eliscript_truthy(list_node_p(node)) ? make_list(quasiquote_items(list_items(node), scope, depth, auto_gensyms), node_span(node)) : (__eliscript_truthy(((__eliscript_value_51) => (__eliscript_truthy(__eliscript_value_51) ? ((__eliscript_value_52) => (__eliscript_truthy(__eliscript_value_52) ? (node_name(node))["endsWith"]("$") : __eliscript_value_52))(symbol_node_p(node)) : __eliscript_value_51))((depth === 1))) ? auto_gensym(node, scope, auto_gensyms) : node)))))));
290
+ }
291
+ function eval_list_operation(operator, values) {
292
+ return (__eliscript_truthy((operator === "list")) ? make_list(values, null) : (__eliscript_truthy((operator === "vector")) ? collection_node("vector", values, null) : (__eliscript_truthy((operator === "car")) ? (() => {
293
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("car expects 1 argument") : null);
294
+ return ((items) => {
295
+ (__eliscript_truthy((items === undefined)) ? raise_error("car expects a list or vector") : null);
296
+ return (__eliscript_truthy(((items)["length"] === 0)) ? literal_node(null, null) : ((((items) ?? [])[0]) ?? null));
297
+ })(sequence_items(((((values) ?? [])[0]) ?? null)));
298
+ })() : (__eliscript_truthy((operator === "cdr")) ? (() => {
299
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("cdr expects 1 argument") : null);
300
+ return ((items) => {
301
+ (__eliscript_truthy((items === undefined)) ? raise_error("cdr expects a list or vector") : null);
302
+ return make_list((items)["slice"](1), null);
303
+ })(sequence_items(((((values) ?? [])[0]) ?? null)));
304
+ })() : (__eliscript_truthy((operator === "nth")) ? (() => {
305
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 2)))) ? raise_error("nth expects 2 arguments") : null);
306
+ return ((index) => {
307
+ return ((items) => {
308
+ return (() => {
309
+ (__eliscript_truthy((items === undefined)) ? raise_error("nth expects a list or vector") : null);
310
+ return (__eliscript_truthy(((__eliscript_value_53) => (__eliscript_truthy(__eliscript_value_53) ? (index < (items)["length"]) : __eliscript_value_53))((index >= 0))) ? ((((items) ?? [])[index]) ?? null) : literal_node(null, null));
311
+ })();
312
+ })(sequence_items(((((values) ?? [])[1]) ?? null)));
313
+ })(require_number(((((values) ?? [])[0]) ?? null), "nth"));
314
+ })() : (__eliscript_truthy((operator === "length")) ? (() => {
315
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("length expects 1 argument") : null);
316
+ return ((items) => {
317
+ return (__eliscript_truthy((!__eliscript_truthy((items === undefined)))) ? literal_node((items)["length"], null) : (__eliscript_truthy(((__eliscript_value_54) => (__eliscript_truthy(__eliscript_value_54) ? (typeof values[0].value === "string") : __eliscript_value_54))(literal_node_p(((((values) ?? [])[0]) ?? null)))) ? literal_node((node_value(((((values) ?? [])[0]) ?? null)))["length"], null) : raise_error("length expects a sequence")));
318
+ })(sequence_items(((((values) ?? [])[0]) ?? null)));
319
+ })() : (__eliscript_truthy((operator === "cons")) ? (() => {
320
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 2)))) ? raise_error("cons expects 2 arguments") : null);
321
+ return ((tail) => {
322
+ (__eliscript_truthy((tail === undefined)) ? raise_error("cons tail must be a list or vector") : null);
323
+ return ((items) => {
324
+ (tail)["forEach"]((item) => {
325
+ return (items)["push"](item);
326
+ });
327
+ return make_list(items, null);
328
+ })([((((values) ?? [])[0]) ?? null)]);
329
+ })(sequence_items(((((values) ?? [])[1]) ?? null)));
330
+ })() : (__eliscript_truthy((operator === "append")) ? ((items) => {
331
+ (values)["forEach"]((value) => {
332
+ return ((parts) => {
333
+ (__eliscript_truthy((parts === undefined)) ? raise_error("append expects lists or vectors") : null);
334
+ return (parts)["forEach"]((part) => {
335
+ return (items)["push"](part);
336
+ });
337
+ })(sequence_items(value));
338
+ });
339
+ return make_list(items, null);
340
+ })([]) : undefined))))))));
341
+ }
342
+ function eval_predicate(operator, values) {
343
+ return (__eliscript_truthy((operator === "not")) ? (() => {
344
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error((String(operator) + String(" expects 1 argument"))) : null);
345
+ return make_boolean((!__eliscript_truthy(truthy_p(((((values) ?? [])[0]) ?? null)))));
346
+ })() : (__eliscript_truthy((operator === "nil?")) ? (() => {
347
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("nil? expects 1 argument") : null);
348
+ return make_boolean(null_node_p(((((values) ?? [])[0]) ?? null)));
349
+ })() : (__eliscript_truthy((operator === "undefined?")) ? (() => {
350
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("undefined? expects 1 argument") : null);
351
+ return make_boolean((node_kind(((((values) ?? [])[0]) ?? null)) === "undefined"));
352
+ })() : (__eliscript_truthy(((__eliscript_value_55) => (__eliscript_truthy(__eliscript_value_55) ? __eliscript_value_55 : (operator === "nullish?")))((operator === "null"))) ? (() => {
353
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error((String(operator) + String(" expects 1 argument"))) : null);
354
+ return make_boolean(((__eliscript_value_56) => (__eliscript_truthy(__eliscript_value_56) ? __eliscript_value_56 : (node_kind(((((values) ?? [])[0]) ?? null)) === "undefined")))(null_node_p(((((values) ?? [])[0]) ?? null))));
355
+ })() : (__eliscript_truthy((operator === "symbolp")) ? (() => {
356
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("symbolp expects 1 argument") : null);
357
+ return make_boolean(symbol_node_p(((((values) ?? [])[0]) ?? null)));
358
+ })() : (__eliscript_truthy((operator === "keywordp")) ? (() => {
359
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("keywordp expects 1 argument") : null);
360
+ return make_boolean(keyword_node_p(((((values) ?? [])[0]) ?? null)));
361
+ })() : (__eliscript_truthy((operator === "listp")) ? (() => {
362
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("listp expects 1 argument") : null);
363
+ return make_boolean(list_node_p(((((values) ?? [])[0]) ?? null)));
364
+ })() : (__eliscript_truthy((operator === "consp")) ? (() => {
365
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("consp expects 1 argument") : null);
366
+ return make_boolean(((__eliscript_value_57) => (__eliscript_truthy(__eliscript_value_57) ? list_node_p(((((values) ?? [])[0]) ?? null)) : __eliscript_value_57))((!__eliscript_truthy(null_node_p(((((values) ?? [])[0]) ?? null))))));
367
+ })() : (__eliscript_truthy((operator === "vectorp")) ? (() => {
368
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("vectorp expects 1 argument") : null);
369
+ return make_boolean(vector_node_p(((((values) ?? [])[0]) ?? null)));
370
+ })() : (__eliscript_truthy((operator === "stringp")) ? (() => {
371
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("stringp expects 1 argument") : null);
372
+ return make_boolean(((__eliscript_value_58) => (__eliscript_truthy(__eliscript_value_58) ? (typeof values[0].value === "string") : __eliscript_value_58))(literal_node_p(((((values) ?? [])[0]) ?? null))));
373
+ })() : (__eliscript_truthy((operator === "numberp")) ? (() => {
374
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("numberp expects 1 argument") : null);
375
+ return make_boolean(((__eliscript_value_59) => (__eliscript_truthy(__eliscript_value_59) ? (typeof values[0].value === "number") : __eliscript_value_59))(literal_node_p(((((values) ?? [])[0]) ?? null))));
376
+ })() : (__eliscript_truthy((operator === "atom")) ? (() => {
377
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error("atom expects 1 argument") : null);
378
+ return make_boolean((!__eliscript_truthy(((__eliscript_value_60) => (__eliscript_truthy(__eliscript_value_60) ? list_node_p(((((values) ?? [])[0]) ?? null)) : __eliscript_value_60))((!__eliscript_truthy(null_node_p(((((values) ?? [])[0]) ?? null))))))));
379
+ })() : (__eliscript_truthy((operator === "eq")) ? (() => {
380
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 2)))) ? raise_error("eq expects 2 arguments") : null);
381
+ return ((left, right) => {
382
+ return make_boolean((__eliscript_truthy(((__eliscript_value_61) => (__eliscript_truthy(__eliscript_value_61) ? symbol_node_p(right) : __eliscript_value_61))(symbol_node_p(left))) ? (node_name(left) === node_name(right)) : (__eliscript_truthy(((__eliscript_value_62) => (__eliscript_truthy(__eliscript_value_62) ? keyword_node_p(right) : __eliscript_value_62))(keyword_node_p(left))) ? (node_name(left) === node_name(right)) : (__eliscript_truthy(((__eliscript_value_63) => (__eliscript_truthy(__eliscript_value_63) ? literal_node_p(right) : __eliscript_value_63))(literal_node_p(left))) ? (node_value(left) === node_value(right)) : (left === right)))));
383
+ })(((((values) ?? [])[0]) ?? null), ((((values) ?? [])[1]) ?? null));
384
+ })() : (__eliscript_truthy((operator === "equal")) ? (() => {
385
+ (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 2)))) ? raise_error("equal expects 2 arguments") : null);
386
+ return make_boolean(nodes_equal(((((values) ?? [])[0]) ?? null), ((((values) ?? [])[1]) ?? null)));
387
+ })() : undefined))))))))))))));
388
+ }
389
+ function eval_arithmetic(operator, values) {
390
+ return (__eliscript_truthy((!__eliscript_truthy((["+", "-", "*", "/", "%", "mod", "1+", "1-", "=", "/=", "<", "<=", ">", ">="])["includes"](operator)))) ? undefined : ((numbers) => {
391
+ (__eliscript_truthy(((__eliscript_value_64) => (__eliscript_truthy(__eliscript_value_64) ? __eliscript_value_64 : (operator === "1-")))((operator === "1+"))) ? (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 1)))) ? raise_error((String(operator) + String(" expects 1 argument"))) : null) : (__eliscript_truthy(((__eliscript_value_65) => (__eliscript_truthy(__eliscript_value_65) ? __eliscript_value_65 : ((__eliscript_value_66) => (__eliscript_truthy(__eliscript_value_66) ? __eliscript_value_66 : ((__eliscript_value_67) => (__eliscript_truthy(__eliscript_value_67) ? __eliscript_value_67 : ((__eliscript_value_68) => (__eliscript_truthy(__eliscript_value_68) ? __eliscript_value_68 : ((__eliscript_value_69) => (__eliscript_truthy(__eliscript_value_69) ? __eliscript_value_69 : ((__eliscript_value_70) => (__eliscript_truthy(__eliscript_value_70) ? __eliscript_value_70 : ((__eliscript_value_71) => (__eliscript_truthy(__eliscript_value_71) ? __eliscript_value_71 : (operator === ">=")))((operator === ">"))))((operator === "<="))))((operator === "<"))))((operator === "/="))))((operator === "="))))((operator === "mod"))))((operator === "%"))) ? (__eliscript_truthy((!__eliscript_truthy(((values)["length"] === 2)))) ? raise_error((String(operator) + String(" expects 2 arguments"))) : null) : (__eliscript_truthy(((__eliscript_value_72) => (__eliscript_truthy(__eliscript_value_72) ? __eliscript_value_72 : (operator === "/")))((operator === "-"))) ? (__eliscript_truthy(((values)["length"] === 0)) ? raise_error((String(operator) + String(" expects one or more numbers"))) : null) : null)));
392
+ (values)["forEach"]((value) => {
393
+ return (numbers)["push"](require_number(value, operator));
394
+ });
395
+ return (__eliscript_truthy((operator === "1+")) ? literal_node((((((numbers) ?? [])[0]) ?? null) + 1), null) : (__eliscript_truthy((operator === "1-")) ? literal_node((((((numbers) ?? [])[0]) ?? null) - 1), null) : (__eliscript_truthy((operator === "+")) ? ((result) => {
396
+ (numbers)["forEach"]((number) => {
397
+ return ((result = (result + number)));
398
+ });
399
+ return literal_node(result, null);
400
+ })(0) : (__eliscript_truthy((operator === "*")) ? ((result) => {
401
+ (numbers)["forEach"]((number) => {
402
+ return ((result = (result * number)));
403
+ });
404
+ return literal_node(result, null);
405
+ })(1) : (__eliscript_truthy((operator === "-")) ? ((result) => {
406
+ (__eliscript_truthy(((numbers)["length"] === 1)) ? ((result = (-result))) : ((index) => {
407
+ return (() => {
408
+ while (__eliscript_truthy((index < (numbers)["length"]))) {
409
+ ((result = (result - ((((numbers) ?? [])[index]) ?? null))));
410
+ ((index = (index + 1)));
411
+ }
412
+ return null;
413
+ })();
414
+ })(1));
415
+ return literal_node(result, null);
416
+ })(((((numbers) ?? [])[0]) ?? null)) : (__eliscript_truthy((operator === "/")) ? ((result, index) => {
417
+ (__eliscript_truthy(((numbers)["length"] === 1)) ? ((result = (1 / result))) : (() => {
418
+ while (__eliscript_truthy((index < (numbers)["length"]))) {
419
+ ((result = (result / ((((numbers) ?? [])[index]) ?? null))));
420
+ ((index = (index + 1)));
421
+ }
422
+ return null;
423
+ })());
424
+ return literal_node(result, null);
425
+ })(((((numbers) ?? [])[0]) ?? null), 1) : (__eliscript_truthy(((__eliscript_value_73) => (__eliscript_truthy(__eliscript_value_73) ? __eliscript_value_73 : (operator === "mod")))((operator === "%"))) ? literal_node((((((numbers) ?? [])[0]) ?? null) % ((((numbers) ?? [])[1]) ?? null)), null) : (__eliscript_truthy((operator === "=")) ? make_boolean((((((numbers) ?? [])[0]) ?? null) === ((((numbers) ?? [])[1]) ?? null))) : (__eliscript_truthy((operator === "/=")) ? make_boolean((!__eliscript_truthy((((((numbers) ?? [])[0]) ?? null) === ((((numbers) ?? [])[1]) ?? null))))) : (__eliscript_truthy((operator === "<")) ? make_boolean((((((numbers) ?? [])[0]) ?? null) < ((((numbers) ?? [])[1]) ?? null))) : (__eliscript_truthy((operator === "<=")) ? make_boolean((((((numbers) ?? [])[0]) ?? null) <= ((((numbers) ?? [])[1]) ?? null))) : (__eliscript_truthy((operator === ">")) ? make_boolean((((((numbers) ?? [])[0]) ?? null) > ((((numbers) ?? [])[1]) ?? null))) : (__eliscript_truthy((operator === ">=")) ? make_boolean((((((numbers) ?? [])[0]) ?? null) >= ((((numbers) ?? [])[1]) ?? null))) : null)))))))))))));
426
+ })([]));
427
+ }
428
+ function eval_call(form, scope) {
429
+ return ((items) => {
430
+ return ((operator_node) => {
431
+ return ((args) => {
432
+ return (() => {
433
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(operator_node)))) ? raise_error("macro call operator must be a symbol") : null);
434
+ return ((operator) => {
435
+ return (__eliscript_truthy((operator === "quote")) ? (() => {
436
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 1)))) ? raise_error("quote expects 1 argument") : null);
437
+ return ((((args) ?? [])[0]) ?? null);
438
+ })() : (__eliscript_truthy((operator === "`")) ? (() => {
439
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 1)))) ? raise_error("` expects 1 argument") : null);
440
+ return quasiquote_node(((((args) ?? [])[0]) ?? null), scope, 1, new Map());
441
+ })() : (__eliscript_truthy((operator === "if")) ? eval_if(args, scope) : (__eliscript_truthy((operator === "when")) ? (__eliscript_truthy(((__eliscript_value_74) => (__eliscript_truthy(__eliscript_value_74) ? truthy_p(eval_form(((((args) ?? [])[0]) ?? null), scope)) : __eliscript_value_74))(((args)["length"] > 0))) ? eval_sequence((args)["slice"](1), scope) : literal_node(null, null)) : (__eliscript_truthy((operator === "unless")) ? (__eliscript_truthy(((__eliscript_value_75) => (__eliscript_truthy(__eliscript_value_75) ? (!__eliscript_truthy(truthy_p(eval_form(((((args) ?? [])[0]) ?? null), scope)))) : __eliscript_value_75))(((args)["length"] > 0))) ? eval_sequence((args)["slice"](1), scope) : literal_node(null, null)) : (__eliscript_truthy(((__eliscript_value_76) => (__eliscript_truthy(__eliscript_value_76) ? __eliscript_value_76 : (operator === "do")))((operator === "progn"))) ? eval_sequence(args, scope) : (__eliscript_truthy((operator === "let")) ? eval_let(args, scope, false) : (__eliscript_truthy((operator === "let*")) ? eval_let(args, scope, true) : (__eliscript_truthy((operator === "setq")) ? eval_setq(args, scope) : (__eliscript_truthy((operator === "cond")) ? eval_cond(args, scope) : (__eliscript_truthy((operator === "and")) ? ((result, index) => {
442
+ (() => {
443
+ while (__eliscript_truthy(((__eliscript_value_77) => (__eliscript_truthy(__eliscript_value_77) ? truthy_p(result) : __eliscript_value_77))((index < (args)["length"])))) {
444
+ ((result = eval_form(((((args) ?? [])[index]) ?? null), scope)));
445
+ ((index = (index + 1)));
446
+ }
447
+ return null;
448
+ })();
449
+ return result;
450
+ })(literal_node(true, null), 0) : (__eliscript_truthy((operator === "or")) ? ((result, index) => {
451
+ (() => {
452
+ while (__eliscript_truthy(((__eliscript_value_78) => (__eliscript_truthy(__eliscript_value_78) ? (!__eliscript_truthy(truthy_p(result))) : __eliscript_value_78))((index < (args)["length"])))) {
453
+ ((result = eval_form(((((args) ?? [])[index]) ?? null), scope)));
454
+ ((index = (index + 1)));
455
+ }
456
+ return null;
457
+ })();
458
+ return result;
459
+ })(literal_node(null, null), 0) : (__eliscript_truthy((operator === "error")) ? (() => {
460
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] > 0)))) ? raise_error("error expects a message") : null);
461
+ return raise_error(value_string(eval_form(((((args) ?? [])[0]) ?? null), scope)));
462
+ })() : (__eliscript_truthy((operator === "gensym")) ? (() => {
463
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] <= 1)))) ? raise_error("gensym expects 0..1 arguments") : null);
464
+ return allocate_name(scope, (__eliscript_truthy(((args)["length"] === 0)) ? literal_node("G", null) : eval_form(((((args) ?? [])[0]) ?? null), scope)));
465
+ })() : (__eliscript_truthy((operator === "macro-read-file")) ? (() => {
466
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 1)))) ? raise_error("macro-read-file expects 1 argument") : null);
467
+ return ((specifier_node) => {
468
+ return ((context) => {
469
+ return (() => {
470
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_79) => (__eliscript_truthy(__eliscript_value_79) ? ((__eliscript_value_80) => (__eliscript_truthy(__eliscript_value_80) ? ((node_value(specifier_node))["length"] > 0) : __eliscript_value_80))((typeof specifier_node.value === "string")) : __eliscript_value_79))(literal_node_p(specifier_node))))) ? raise_error("macro-read-file expects a non-empty string") : null);
471
+ return ((specifier) => {
472
+ (__eliscript_truthy((!__eliscript_truthy(((context)["capabilities"])["has"]("read-file")))) ? raise_error("macro capability is not enabled: read-file") : null);
473
+ (__eliscript_truthy((!__eliscript_truthy(((context)["files"])["has"](specifier)))) ? raise_error((String("macro file dependency is not declared: ") + String(specifier))) : null);
474
+ return literal_node(((context)["files"])["get"](specifier), null);
475
+ })(node_value(specifier_node));
476
+ })();
477
+ })((scope)["context"]);
478
+ })(eval_form(((((args) ?? [])[0]) ?? null), scope));
479
+ })() : ((values) => {
480
+ return ((list_result) => {
481
+ return ((predicate_result) => {
482
+ return ((arithmetic_result) => {
483
+ return (__eliscript_truthy((!__eliscript_truthy((list_result === undefined)))) ? list_result : (__eliscript_truthy((!__eliscript_truthy((predicate_result === undefined)))) ? predicate_result : (__eliscript_truthy((!__eliscript_truthy((arithmetic_result === undefined)))) ? arithmetic_result : (__eliscript_truthy((operator === "symbol-name")) ? (() => {
484
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_82) => (__eliscript_truthy(__eliscript_value_82) ? symbol_node_p(((((values) ?? [])[0]) ?? null)) : __eliscript_value_82))(((values)["length"] === 1))))) ? raise_error("symbol-name expects a symbol") : null);
485
+ return literal_node(node_name(((((values) ?? [])[0]) ?? null)), null);
486
+ })() : (__eliscript_truthy((operator === "intern")) ? (() => {
487
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_83) => (__eliscript_truthy(__eliscript_value_83) ? ((__eliscript_value_84) => (__eliscript_truthy(__eliscript_value_84) ? (typeof values[0].value === "string") : __eliscript_value_84))(literal_node_p(((((values) ?? [])[0]) ?? null))) : __eliscript_value_83))(((values)["length"] === 1))))) ? raise_error("intern expects a string") : null);
488
+ return ((name) => {
489
+ reserve_name(scope, name);
490
+ return symbol_node(name, null);
491
+ })(node_value(((((values) ?? [])[0]) ?? null)));
492
+ })() : (__eliscript_truthy(((__eliscript_value_85) => (__eliscript_truthy(__eliscript_value_85) ? __eliscript_value_85 : (operator === "str")))((operator === "concat"))) ? ((pieces) => {
493
+ (values)["forEach"]((value) => {
494
+ return (pieces)["push"](value_string(value));
495
+ });
496
+ return literal_node((pieces)["join"](""), null);
497
+ })([]) : raise_error((String("unsupported macro function: ") + String(operator)))))))));
498
+ })((__eliscript_truthy(((__eliscript_value_81) => (__eliscript_truthy(__eliscript_value_81) ? (predicate_result === undefined) : __eliscript_value_81))((list_result === undefined))) ? eval_arithmetic(operator, values) : undefined));
499
+ })((__eliscript_truthy((list_result === undefined)) ? eval_predicate(operator, values) : undefined));
500
+ })(eval_list_operation(operator, values));
501
+ })(eval_args(args, scope)))))))))))))))));
502
+ })(node_name(operator_node));
503
+ })();
504
+ })((items)["slice"](1));
505
+ })(((((items) ?? [])[0]) ?? null));
506
+ })(node_items(form));
507
+ }
508
+ function eval_form(form, scope) {
509
+ return (__eliscript_truthy(symbol_node_p(form)) ? scope_value(scope, node_name(form)) : (__eliscript_truthy(((__eliscript_value_86) => (__eliscript_truthy(__eliscript_value_86) ? __eliscript_value_86 : ((__eliscript_value_87) => (__eliscript_truthy(__eliscript_value_87) ? __eliscript_value_87 : ((__eliscript_value_88) => (__eliscript_truthy(__eliscript_value_88) ? __eliscript_value_88 : vector_node_p(form)))((node_kind(form) === "undefined"))))(keyword_node_p(form))))(literal_node_p(form))) ? form : (__eliscript_truthy((node_kind(form) === "list")) ? eval_call(form, scope) : raise_error((String("unsupported macro value: ") + String(node_display(form)))))));
510
+ }
511
+ function parameter_list_display(parameters) {
512
+ return node_display(parameters);
513
+ }
514
+ function parse_parameters(parameters, context, span) {
515
+ return ((items) => {
516
+ (__eliscript_truthy((items === undefined)) ? expander_fail(context, span, (String("macro parameters must be a list: ") + String(parameter_list_display(parameters)))) : null);
517
+ return ((required, optional, rest_name, mode, index) => {
518
+ (() => {
519
+ while (__eliscript_truthy((index < (items)["length"]))) {
520
+ ((parameter) => {
521
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(parameter)))) ? expander_fail(context, span, (String("macro parameters must be symbols: ") + String(parameter_list_display(parameters)))) : null);
522
+ return ((name) => {
523
+ return (__eliscript_truthy((name === "&optional")) ? (() => {
524
+ (__eliscript_truthy(((__eliscript_value_89) => (__eliscript_truthy(__eliscript_value_89) ? __eliscript_value_89 : (!__eliscript_truthy((rest_name === undefined)))))((mode === "rest"))) ? expander_fail(context, span, "invalid macro parameter list") : null);
525
+ return ((mode = "optional"));
526
+ })() : (__eliscript_truthy(((__eliscript_value_90) => (__eliscript_truthy(__eliscript_value_90) ? __eliscript_value_90 : (name === "&body")))((name === "&rest"))) ? (() => {
527
+ (__eliscript_truthy(((__eliscript_value_91) => (__eliscript_truthy(__eliscript_value_91) ? __eliscript_value_91 : (!__eliscript_truthy((rest_name === undefined)))))((mode === "rest"))) ? expander_fail(context, span, "invalid macro parameter list") : null);
528
+ return ((mode = "rest"));
529
+ })() : (__eliscript_truthy((mode === "rest")) ? (() => {
530
+ ((rest_name = name));
531
+ return ((mode = "done"));
532
+ })() : (__eliscript_truthy((mode === "done")) ? expander_fail(context, span, "invalid macro parameter list") : (__eliscript_truthy((mode === "required")) ? (required)["push"](name) : (optional)["push"](name))))));
533
+ })(node_name(parameter));
534
+ })(((((items) ?? [])[index]) ?? null));
535
+ ((index = (index + 1)));
536
+ }
537
+ return null;
538
+ })();
539
+ (__eliscript_truthy((mode === "rest")) ? expander_fail(context, span, "invalid macro parameter list") : null);
540
+ return ({"required": required, "optional": optional, "rest": rest_name});
541
+ })([], [], undefined, "required", 0);
542
+ })(list_items(parameters));
543
+ }
544
+ function register_macro(form, environment, context) {
545
+ return ((items) => {
546
+ return ((args) => {
547
+ return ((span) => {
548
+ return (() => {
549
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] >= 2)))) ? expander_fail(context, span, "defmacro expects a name and parameter list") : null);
550
+ return ((name_node, parameters) => {
551
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? expander_fail(context, span, (String("macro name must be a symbol: ") + String(node_display(name_node)))) : null);
552
+ return ((name) => {
553
+ (__eliscript_truthy((environment)["has"](name)) ? expander_fail(context, span, (String("duplicate macro definition: ") + String(name))) : null);
554
+ return (environment)["set"](name, ({"name": name, "parameters": parse_parameters(parameters, context, span), "body": (args)["slice"](2)}));
555
+ })(node_name(name_node));
556
+ })(((((args) ?? [])[0]) ?? null), ((((args) ?? [])[1]) ?? null));
557
+ })();
558
+ })(node_span(form));
559
+ })((items)["slice"](1));
560
+ })(node_items(form));
561
+ }
562
+ function bind_macro_args(definition, args, context) {
563
+ return ((parameters) => {
564
+ return ((required) => {
565
+ return ((optional) => {
566
+ return ((rest_name) => {
567
+ return ((minimum) => {
568
+ return ((maximum) => {
569
+ return ((count) => {
570
+ return ((scope) => {
571
+ return (() => {
572
+ (__eliscript_truthy((count < minimum)) ? raise_error((String("wrong number of arguments for ") + String((definition)["name"]))) : null);
573
+ (__eliscript_truthy(((__eliscript_value_92) => (__eliscript_truthy(__eliscript_value_92) ? (count > maximum) : __eliscript_value_92))((rest_name === undefined))) ? raise_error((String("wrong number of arguments for ") + String((definition)["name"]))) : null);
574
+ ((index) => {
575
+ (required)["forEach"]((name) => {
576
+ scope_bind(scope, name, ((((args) ?? [])[index]) ?? null));
577
+ return ((index = (index + 1)));
578
+ });
579
+ (optional)["forEach"]((name) => {
580
+ scope_bind(scope, name, (__eliscript_truthy((index < count)) ? ((((args) ?? [])[index]) ?? null) : literal_node(null, null)));
581
+ return ((index = (index + 1)));
582
+ });
583
+ return (__eliscript_truthy((!__eliscript_truthy((rest_name === undefined)))) ? scope_bind(scope, rest_name, make_list((args)["slice"](index), null)) : null);
584
+ })(0);
585
+ return scope;
586
+ })();
587
+ })(make_eval_scope(null, context));
588
+ })((args)["length"]);
589
+ })((minimum + (optional)["length"]));
590
+ })((required)["length"]);
591
+ })((parameters)["rest"]);
592
+ })((parameters)["optional"]);
593
+ })((parameters)["required"]);
594
+ })((definition)["parameters"]);
595
+ }
596
+ function invoke_macro(definition, args, depth, context, span) {
597
+ (__eliscript_truthy((depth >= maximum_depth)) ? expander_fail(context, span, (String("macro expansion exceeded ") + String(maximum_depth) + String(" steps near ") + String((definition)["name"]))) : null);
598
+ return guard(() => {
599
+ return ((scope) => {
600
+ return eval_sequence((definition)["body"], scope);
601
+ })(bind_macro_args(definition, args, context));
602
+ }, (message) => {
603
+ return expander_fail(context, span, (String("macro ") + String((definition)["name"]) + String(" failed: ") + String(message)));
604
+ });
605
+ }
606
+ function expand_sequence(forms, environment, depth, context) {
607
+ return ((result) => {
608
+ (forms)["forEach"]((form) => {
609
+ return (result)["push"](expand_expression(form, environment, depth, context));
610
+ });
611
+ return result;
612
+ })([]);
613
+ }
614
+ function expand_binding(binding, environment, depth, context) {
615
+ return ((items) => {
616
+ return (__eliscript_truthy(((__eliscript_value_93) => (__eliscript_truthy(__eliscript_value_93) ? __eliscript_value_93 : ((items)["length"] === 0)))((items === undefined))) ? binding : ((expanded) => {
617
+ ((items)["slice"](1))["forEach"]((item) => {
618
+ return (expanded)["push"](expand_expression(item, environment, depth, context));
619
+ });
620
+ return make_list(expanded, node_span(binding));
621
+ })([((((items) ?? [])[0]) ?? null)]));
622
+ })(list_items(binding));
623
+ }
624
+ function expand_bindings(args, environment, depth, context) {
625
+ return (__eliscript_truthy(((args)["length"] === 0)) ? args : ((bindings_form) => {
626
+ return ((bindings) => {
627
+ return ((result) => {
628
+ return (() => {
629
+ (__eliscript_truthy((bindings === undefined)) ? (result)["push"](bindings_form) : ((expanded_bindings) => {
630
+ (bindings)["forEach"]((binding) => {
631
+ return (expanded_bindings)["push"](expand_binding(binding, environment, depth, context));
632
+ });
633
+ return (result)["push"](make_list(expanded_bindings, node_span(bindings_form)));
634
+ })([]));
635
+ (expand_sequence((args)["slice"](1), environment, depth, context))["forEach"]((item) => {
636
+ return (result)["push"](item);
637
+ });
638
+ return result;
639
+ })();
640
+ })([]);
641
+ })(list_items(bindings_form));
642
+ })(((((args) ?? [])[0]) ?? null)));
643
+ }
644
+ function expand_alternating(args, environment, depth, context, expand_even, literal_key_mode) {
645
+ return ((result, index) => {
646
+ (args)["forEach"]((item) => {
647
+ ((expand) => {
648
+ (__eliscript_truthy(((__eliscript_value_94) => (__eliscript_truthy(__eliscript_value_94) ? ((__eliscript_value_95) => (__eliscript_truthy(__eliscript_value_95) ? ((__eliscript_value_96) => (__eliscript_truthy(__eliscript_value_96) ? __eliscript_value_96 : ((__eliscript_value_97) => (__eliscript_truthy(__eliscript_value_97) ? __eliscript_value_97 : ((__eliscript_value_98) => (__eliscript_truthy(__eliscript_value_98) ? (typeof item.value === "string") : __eliscript_value_98))(literal_node_p(item))))(symbol_node_p(item))))(keyword_node_p(item)) : __eliscript_value_95))(((index % 2) === 0)) : __eliscript_value_94))(literal_key_mode)) ? ((expand = false)) : null);
649
+ return (result)["push"]((__eliscript_truthy(expand) ? expand_expression(item, environment, depth, context) : item));
650
+ })((__eliscript_truthy(((index % 2) === 0)) ? expand_even : true));
651
+ return ((index = (index + 1)));
652
+ });
653
+ return result;
654
+ })([], 0);
655
+ }
656
+ function expand_property_call(args, environment, depth, context) {
657
+ return ((result, index) => {
658
+ (args)["forEach"]((item) => {
659
+ (result)["push"]((__eliscript_truthy(((__eliscript_value_99) => (__eliscript_truthy(__eliscript_value_99) ? ((__eliscript_value_100) => (__eliscript_truthy(__eliscript_value_100) ? __eliscript_value_100 : ((__eliscript_value_101) => (__eliscript_truthy(__eliscript_value_101) ? (typeof item.value === "string") : __eliscript_value_101))(literal_node_p(item))))(keyword_node_p(item)) : __eliscript_value_99))((index === 1))) ? item : expand_expression(item, environment, depth, context)));
660
+ return ((index = (index + 1)));
661
+ });
662
+ return result;
663
+ })([], 0);
664
+ }
665
+ function expand_cond(clauses, environment, depth, context) {
666
+ return ((result) => {
667
+ (clauses)["forEach"]((clause) => {
668
+ return ((items) => {
669
+ return (result)["push"]((__eliscript_truthy((items === undefined)) ? clause : make_list(expand_sequence(items, environment, depth, context), node_span(clause))));
670
+ })(list_items(clause));
671
+ });
672
+ return result;
673
+ })([]);
674
+ }
675
+ function expand_try_clause(clause, environment, depth, context) {
676
+ return ((items) => {
677
+ return ((operator) => {
678
+ return (__eliscript_truthy((operator === "catch")) ? (__eliscript_truthy(((items)["length"] > 1)) ? ((expanded) => {
679
+ (expand_sequence((items)["slice"](2), environment, depth, context))["forEach"]((item) => {
680
+ return (expanded)["push"](item);
681
+ });
682
+ return make_list(expanded, node_span(clause));
683
+ })([((((items) ?? [])[0]) ?? null), ((((items) ?? [])[1]) ?? null)]) : clause) : (__eliscript_truthy((operator === "finally")) ? ((expanded) => {
684
+ (expand_sequence((items)["slice"](1), environment, depth, context))["forEach"]((item) => {
685
+ return (expanded)["push"](item);
686
+ });
687
+ return make_list(expanded, node_span(clause));
688
+ })([((((items) ?? [])[0]) ?? null)]) : expand_expression(clause, environment, depth, context)));
689
+ })(((__eliscript_value_102) => (__eliscript_truthy(__eliscript_value_102) ? ((__eliscript_value_103) => (__eliscript_truthy(__eliscript_value_103) ? ((__eliscript_value_104) => (__eliscript_truthy(__eliscript_value_104) ? node_name(((((items) ?? [])[0]) ?? null)) : __eliscript_value_104))(symbol_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_103))(((items)["length"] > 0)) : __eliscript_value_102))((!__eliscript_truthy((items === undefined)))));
690
+ })(list_items(clause));
691
+ }
692
+ function desugar_defmulti(args, context, span) {
693
+ (__eliscript_truthy(((__eliscript_value_105) => (__eliscript_truthy(__eliscript_value_105) ? __eliscript_value_105 : ((args)["length"] > 3)))(((args)["length"] < 2))) ? expander_fail(context, span, "defmulti expects a name, dispatch function, and optional default value") : null);
694
+ return ((name_node) => {
695
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? expander_fail(context, span, (String("defmulti name must be a symbol: ") + String(node_display(name_node)))) : null);
696
+ return ((call_items) => {
697
+ (__eliscript_truthy(((args)["length"] === 3)) ? (call_items)["push"](((((args) ?? [])[2]) ?? null)) : null);
698
+ return make_list([symbol_node("defconst", span), name_node, make_list(call_items, span)], span);
699
+ })([symbol_node("multi-fn", span), literal_node(node_name(name_node), span), ((((args) ?? [])[1]) ?? null)]);
700
+ })(((((args) ?? [])[0]) ?? null));
701
+ }
702
+ function desugar_defmethod(args, context, span) {
703
+ (__eliscript_truthy(((args)["length"] < 3)) ? expander_fail(context, span, "defmethod expects a multimethod, dispatch value, and parameter list") : null);
704
+ return ((target_node) => {
705
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(target_node)))) ? expander_fail(context, span, (String("defmethod target must be a symbol: ") + String(node_display(target_node)))) : null);
706
+ return ((lambda_items) => {
707
+ ((args)["slice"](3))["forEach"]((item) => {
708
+ return (lambda_items)["push"](item);
709
+ });
710
+ return make_list([symbol_node("add-method!", span), target_node, ((((args) ?? [])[1]) ?? null), make_list(lambda_items, span)], span);
711
+ })([symbol_node("lambda", span), ((((args) ?? [])[2]) ?? null)]);
712
+ })(((((args) ?? [])[0]) ?? null));
713
+ }
714
+ function thread_step(value_node, step_node, position, context, span) {
715
+ return ((step_items) => {
716
+ return (__eliscript_truthy(symbol_node_p(step_node)) ? make_list([step_node, value_node], node_span(step_node)) : (__eliscript_truthy(((__eliscript_value_106) => (__eliscript_truthy(__eliscript_value_106) ? ((step_items)["length"] > 0) : __eliscript_value_106))((!__eliscript_truthy((step_items === undefined))))) ? (__eliscript_truthy((position === "first")) ? make_list(([((((step_items) ?? [])[0]) ?? null), value_node])["concat"]((step_items)["slice"](1)), node_span(step_node)) : make_list((step_items)["concat"]([value_node]), node_span(step_node))) : expander_fail(context, span, (String("thread step must be a symbol or non-empty list: ") + String(node_display(step_node))))));
717
+ })(list_items(step_node));
718
+ }
719
+ function desugar_thread(form_name, args, position, context, span) {
720
+ (__eliscript_truthy(((args)["length"] === 0)) ? expander_fail(context, span, (String(form_name) + String(" expects an initial expression"))) : null);
721
+ return ((result) => {
722
+ ((args)["slice"](1))["forEach"]((step_node) => {
723
+ return ((result = thread_step(result, step_node, position, context, span)));
724
+ });
725
+ return result;
726
+ })(((((args) ?? [])[0]) ?? null));
727
+ }
728
+ function fresh_name_node(prefix, context, span) {
729
+ return symbol_node(node_name(allocate_name(make_eval_scope(null, context), literal_node(prefix, null))), span);
730
+ }
731
+ function make_let_form(name_node, value_node, body_node, span) {
732
+ return ((value_span) => {
733
+ return ((binding) => {
734
+ return ((bindings) => {
735
+ return make_list([symbol_node("let", value_span), bindings, body_node], value_span);
736
+ })(make_list([binding], value_span));
737
+ })(make_list([name_node, value_node], value_span));
738
+ })(((__eliscript_value_107) => (__eliscript_truthy(__eliscript_value_107) ? __eliscript_value_107 : span))(node_span(value_node)));
739
+ }
740
+ function desugar_as_thread(args, context, span) {
741
+ (__eliscript_truthy(((args)["length"] < 3)) ? expander_fail(context, span, "as-> expects an initial expression, binding name, and at least one form") : null);
742
+ return ((initial_node, name_node, step_nodes) => {
743
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? expander_fail(context, span, (String("as-> binding name must be a symbol: ") + String(node_display(name_node)))) : null);
744
+ return ((index, body_node) => {
745
+ (() => {
746
+ while (__eliscript_truthy((index >= 0))) {
747
+ ((body_node = make_let_form(name_node, ((((step_nodes) ?? [])[index]) ?? null), body_node, span)));
748
+ ((index = (index - 1)));
749
+ }
750
+ return null;
751
+ })();
752
+ return make_let_form(name_node, initial_node, body_node, span);
753
+ })(((step_nodes)["length"] - 2), ((((step_nodes) ?? [])[((step_nodes)["length"] - 1)]) ?? null));
754
+ })(((((args) ?? [])[0]) ?? null), ((((args) ?? [])[1]) ?? null), (args)["slice"](2));
755
+ }
756
+ function desugar_cond_thread(form_name, args, position, context, span) {
757
+ (__eliscript_truthy(((args)["length"] === 0)) ? expander_fail(context, span, (String(form_name) + String(" expects an initial expression"))) : null);
758
+ return ((clause_count) => {
759
+ (__eliscript_truthy(((clause_count % 2) === 1)) ? expander_fail(context, span, (String(form_name) + String(" expects test and step pairs"))) : null);
760
+ return (__eliscript_truthy((clause_count === 0)) ? ((((args) ?? [])[0]) ?? null) : ((name_node, body_node, index) => {
761
+ ((body_node = name_node));
762
+ (() => {
763
+ while (__eliscript_truthy((index >= 1))) {
764
+ ((test_node) => {
765
+ return ((step_node) => {
766
+ return ((if_node) => {
767
+ return ((body_node = make_let_form(name_node, if_node, body_node, span)));
768
+ })(make_list([symbol_node("if", span), test_node, thread_step(name_node, step_node, position, context, span), name_node], span));
769
+ })(((((args) ?? [])[(index + 1)]) ?? null));
770
+ })(((((args) ?? [])[index]) ?? null));
771
+ ((index = (index - 2)));
772
+ }
773
+ return null;
774
+ })();
775
+ return make_let_form(name_node, ((((args) ?? [])[0]) ?? null), body_node, span);
776
+ })(fresh_name_node("thread", context, span), undefined, ((args)["length"] - 2)));
777
+ })(((args)["length"] - 1));
778
+ }
779
+ function desugar_some_thread(form_name, args, position, context, span) {
780
+ (__eliscript_truthy(((args)["length"] === 0)) ? expander_fail(context, span, (String(form_name) + String(" expects an initial expression"))) : null);
781
+ return (__eliscript_truthy(((args)["length"] === 1)) ? ((((args) ?? [])[0]) ?? null) : ((name_node, body_node, index) => {
782
+ ((body_node = name_node));
783
+ (() => {
784
+ while (__eliscript_truthy((index >= 1))) {
785
+ ((step_node) => {
786
+ return ((next_node) => {
787
+ return ((body_node = make_list([symbol_node("if", span), conditional_test(name_node, true, span), next_node, literal_node(null, span)], span)));
788
+ })(make_let_form(name_node, thread_step(name_node, step_node, position, context, span), body_node, span));
789
+ })(((((args) ?? [])[index]) ?? null));
790
+ ((index = (index - 1)));
791
+ }
792
+ return null;
793
+ })();
794
+ return make_let_form(name_node, ((((args) ?? [])[0]) ?? null), body_node, span);
795
+ })(fresh_name_node("thread", context, span), undefined, ((args)["length"] - 1)));
796
+ }
797
+ function conditional_binding(form_name, binding_node, context, span) {
798
+ return ((binding_items) => {
799
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_108) => (__eliscript_truthy(__eliscript_value_108) ? ((binding_items)["length"] === 2) : __eliscript_value_108))((!__eliscript_truthy((binding_items === undefined))))))) ? expander_fail(context, span, (String(form_name) + String(" binding must contain a name and initializer: ") + String(node_display(binding_node)))) : null);
800
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(((((binding_items) ?? [])[0]) ?? null))))) ? expander_fail(context, span, (String(form_name) + String(" binding name must be a symbol: ") + String(node_display(((((binding_items) ?? [])[0]) ?? null))))) : null);
801
+ return binding_items;
802
+ })(list_items(binding_node));
803
+ }
804
+ function conditional_test(name_node, some_p, span) {
805
+ return (__eliscript_truthy(some_p) ? make_list([symbol_node("not", span), make_list([symbol_node("nil?", span), name_node], span)], span) : name_node);
806
+ }
807
+ function desugar_if_binding(form_name, args, some_p, context, span) {
808
+ (__eliscript_truthy(((__eliscript_value_109) => (__eliscript_truthy(__eliscript_value_109) ? __eliscript_value_109 : ((args)["length"] > 3)))(((args)["length"] < 2))) ? expander_fail(context, span, (String(form_name) + String(" expects a binding, then form, and optional else form"))) : null);
809
+ return ((binding_items) => {
810
+ return ((name_node) => {
811
+ return ((initializer_node) => {
812
+ return ((else_node) => {
813
+ return ((if_node) => {
814
+ return make_let_form(name_node, initializer_node, if_node, span);
815
+ })(make_list([symbol_node("if", span), conditional_test(name_node, some_p, span), ((((args) ?? [])[1]) ?? null), else_node], span));
816
+ })((__eliscript_truthy(((args)["length"] === 3)) ? ((((args) ?? [])[2]) ?? null) : literal_node(null, span)));
817
+ })(((((binding_items) ?? [])[1]) ?? null));
818
+ })(((((binding_items) ?? [])[0]) ?? null));
819
+ })(conditional_binding(form_name, ((((args) ?? [])[0]) ?? null), context, span));
820
+ }
821
+ function desugar_when_binding(form_name, args, some_p, context, span) {
822
+ (__eliscript_truthy(((args)["length"] < 2)) ? expander_fail(context, span, (String(form_name) + String(" expects a binding and at least one body form"))) : null);
823
+ return ((binding_items) => {
824
+ return ((name_node) => {
825
+ return ((initializer_node) => {
826
+ return ((body_node) => {
827
+ return ((if_node) => {
828
+ return make_let_form(name_node, initializer_node, if_node, span);
829
+ })(make_list([symbol_node("if", span), conditional_test(name_node, some_p, span), body_node, literal_node(null, span)], span));
830
+ })(make_list(([symbol_node("progn", span)])["concat"]((args)["slice"](1)), span));
831
+ })(((((binding_items) ?? [])[1]) ?? null));
832
+ })(((((binding_items) ?? [])[0]) ?? null));
833
+ })(conditional_binding(form_name, ((((args) ?? [])[0]) ?? null), context, span));
834
+ }
835
+ function quoted_value(node, span) {
836
+ return make_list([symbol_node("quote", node_span(node)), node], ((__eliscript_value_110) => (__eliscript_truthy(__eliscript_value_110) ? __eliscript_value_110 : span))(node_span(node)));
837
+ }
838
+ function case_constants(match_node) {
839
+ return ((items) => {
840
+ return (__eliscript_truthy(((__eliscript_value_111) => (__eliscript_truthy(__eliscript_value_111) ? ((items)["length"] > 0) : __eliscript_value_111))((!__eliscript_truthy((items === undefined))))) ? items : [match_node]);
841
+ })(list_items(match_node));
842
+ }
843
+ function desugar_case(args, context, span) {
844
+ (__eliscript_truthy(((args)["length"] < 3)) ? expander_fail(context, span, "case expects a dispatch expression and at least one match/result pair") : null);
845
+ return ((dispatch_node) => {
846
+ return ((remaining) => {
847
+ return ((has_default) => {
848
+ return ((default_node) => {
849
+ return ((pair_limit) => {
850
+ return ((dispatch_name) => {
851
+ return ((seen) => {
852
+ return ((cond_items) => {
853
+ return ((index) => {
854
+ return (() => {
855
+ (() => {
856
+ while (__eliscript_truthy((index < pair_limit))) {
857
+ ((match_node) => {
858
+ return ((result_node) => {
859
+ return ((constants) => {
860
+ return ((comparisons) => {
861
+ return ((constant_index) => {
862
+ return (() => {
863
+ (() => {
864
+ while (__eliscript_truthy((constant_index < (constants)["length"]))) {
865
+ ((constant_node) => {
866
+ return ((identity) => {
867
+ return (() => {
868
+ (__eliscript_truthy((seen)["has"](identity)) ? expander_fail(context, span, (String("case declares duplicate match constant: ") + String(identity))) : null);
869
+ (seen)["add"](identity);
870
+ return (comparisons)["push"](make_list([symbol_node("equal", node_span(constant_node)), dispatch_name, quoted_value(constant_node, span)], ((__eliscript_value_112) => (__eliscript_truthy(__eliscript_value_112) ? __eliscript_value_112 : span))(node_span(constant_node))));
871
+ })();
872
+ })(node_display(constant_node));
873
+ })(((((constants) ?? [])[constant_index]) ?? null));
874
+ ((constant_index = (constant_index + 1)));
875
+ }
876
+ return null;
877
+ })();
878
+ return (cond_items)["push"](make_list([(__eliscript_truthy(((comparisons)["length"] === 1)) ? ((((comparisons) ?? [])[0]) ?? null) : make_list(([symbol_node("or", node_span(match_node))])["concat"](comparisons), ((__eliscript_value_113) => (__eliscript_truthy(__eliscript_value_113) ? __eliscript_value_113 : span))(node_span(match_node)))), result_node], ((__eliscript_value_114) => (__eliscript_truthy(__eliscript_value_114) ? __eliscript_value_114 : span))(node_span(match_node))));
879
+ })();
880
+ })(0);
881
+ })([]);
882
+ })(case_constants(match_node));
883
+ })(((((remaining) ?? [])[(index + 1)]) ?? null));
884
+ })(((((remaining) ?? [])[index]) ?? null));
885
+ ((index = (index + 2)));
886
+ }
887
+ return null;
888
+ })();
889
+ (cond_items)["push"](make_list([literal_node(true, span), default_node], span));
890
+ return make_let_form(dispatch_name, dispatch_node, make_list(([symbol_node("cond", span)])["concat"](cond_items), span), span);
891
+ })();
892
+ })(0);
893
+ })([]);
894
+ })(new Set());
895
+ })(fresh_name_node("case-value", context, span));
896
+ })((__eliscript_truthy(has_default) ? ((remaining)["length"] - 1) : (remaining)["length"]));
897
+ })((__eliscript_truthy(has_default) ? ((((remaining) ?? [])[((remaining)["length"] - 1)]) ?? null) : literal_node(null, span)));
898
+ })((((remaining)["length"] % 2) === 1));
899
+ })((args)["slice"](1));
900
+ })(((((args) ?? [])[0]) ?? null));
901
+ }
902
+ function condp_redirect_p(node) {
903
+ return ((__eliscript_value_115) => (__eliscript_truthy(__eliscript_value_115) ? (node_name(node) === ">>") : __eliscript_value_115))(keyword_node_p(node));
904
+ }
905
+ function condp_no_match_form(span) {
906
+ return make_list([symbol_node("throw", span), make_list([symbol_node("new", span), symbol_node("globalThis/TypeError", span), literal_node("condp found no matching clause", span)], span)], span);
907
+ }
908
+ function desugar_condp(args, context, span) {
909
+ (__eliscript_truthy(((args)["length"] < 4)) ? expander_fail(context, span, "condp expects a predicate, dispatch expression, and at least one clause") : null);
910
+ return ((predicate_node, dispatch_node, remaining, clauses, index) => {
911
+ (() => {
912
+ while (__eliscript_truthy(((index + 1) < (remaining)["length"]))) {
913
+ ((test_node, result_or_marker) => {
914
+ return (__eliscript_truthy(condp_redirect_p(result_or_marker)) ? (() => {
915
+ (__eliscript_truthy(((index + 2) >= (remaining)["length"])) ? expander_fail(context, span, "condp :>> clause requires a result function") : null);
916
+ (clauses)["push"](({"test": test_node, "result": ((((remaining) ?? [])[(index + 2)]) ?? null), "redirect": true}));
917
+ return ((index = (index + 3)));
918
+ })() : (() => {
919
+ (clauses)["push"](({"test": test_node, "result": result_or_marker, "redirect": false}));
920
+ return ((index = (index + 2)));
921
+ })());
922
+ })(((((remaining) ?? [])[index]) ?? null), ((((remaining) ?? [])[(index + 1)]) ?? null));
923
+ }
924
+ return null;
925
+ })();
926
+ (__eliscript_truthy(((clauses)["length"] === 0)) ? expander_fail(context, span, "condp expects a predicate, dispatch expression, and at least one clause") : null);
927
+ return ((default_node, predicate_name, dispatch_name, body_node, clause_index) => {
928
+ ((body_node = default_node));
929
+ (() => {
930
+ while (__eliscript_truthy((clause_index >= 0))) {
931
+ ((clause) => {
932
+ return ((test_node) => {
933
+ return ((result_node) => {
934
+ return ((match_name) => {
935
+ return ((predicate_call) => {
936
+ return ((selected_node) => {
937
+ return ((if_node) => {
938
+ return ((body_node = make_let_form(match_name, predicate_call, if_node, span)));
939
+ })(make_list([symbol_node("if", node_span(test_node)), match_name, selected_node, body_node], ((__eliscript_value_118) => (__eliscript_truthy(__eliscript_value_118) ? __eliscript_value_118 : span))(node_span(test_node))));
940
+ })((__eliscript_truthy((clause)["redirect"]) ? make_list([symbol_node("funcall", node_span(result_node)), result_node, match_name], ((__eliscript_value_117) => (__eliscript_truthy(__eliscript_value_117) ? __eliscript_value_117 : span))(node_span(result_node))) : result_node));
941
+ })(make_list([symbol_node("funcall", node_span(test_node)), predicate_name, test_node, dispatch_name], ((__eliscript_value_116) => (__eliscript_truthy(__eliscript_value_116) ? __eliscript_value_116 : span))(node_span(test_node))));
942
+ })(fresh_name_node("condp-result", context, span));
943
+ })((clause)["result"]);
944
+ })((clause)["test"]);
945
+ })(((((clauses) ?? [])[clause_index]) ?? null));
946
+ ((clause_index = (clause_index - 1)));
947
+ }
948
+ return null;
949
+ })();
950
+ return make_let_form(predicate_name, predicate_node, make_let_form(dispatch_name, dispatch_node, body_node, span), span);
951
+ })((__eliscript_truthy((index < (remaining)["length"])) ? ((((remaining) ?? [])[index]) ?? null) : condp_no_match_form(span)), fresh_name_node("condp-predicate", context, span), fresh_name_node("condp-value", context, span), null, ((clauses)["length"] - 1));
952
+ })(((((args) ?? [])[0]) ?? null), ((((args) ?? [])[1]) ?? null), (args)["slice"](2), [], 0);
953
+ }
954
+ function multi_arity_clause_p(node) {
955
+ return ((items) => {
956
+ return ((__eliscript_value_119) => (__eliscript_truthy(__eliscript_value_119) ? ((__eliscript_value_120) => (__eliscript_truthy(__eliscript_value_120) ? ((__eliscript_value_121) => (__eliscript_truthy(__eliscript_value_121) ? (!__eliscript_truthy(map_node_p(((((items) ?? [])[0]) ?? null)))) : __eliscript_value_121))(list_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_120))(((items)["length"] > 0)) : __eliscript_value_119))((!__eliscript_truthy((items === undefined))));
957
+ })(list_items(node));
958
+ }
959
+ function multi_arity_layout(parameters, context, span) {
960
+ return ((items, required, variadic, index) => {
961
+ (__eliscript_truthy((items === undefined)) ? expander_fail(context, span, "multi-arity clause parameters must be a list") : null);
962
+ (() => {
963
+ while (__eliscript_truthy((index < (items)["length"]))) {
964
+ ((parameter) => {
965
+ return ((name) => {
966
+ return (__eliscript_truthy(((__eliscript_value_123) => (__eliscript_truthy(__eliscript_value_123) ? __eliscript_value_123 : (name === "&body")))((name === "&optional"))) ? expander_fail(context, ((__eliscript_value_124) => (__eliscript_truthy(__eliscript_value_124) ? __eliscript_value_124 : span))(node_span(parameter)), (String("multi-arity clauses do not support ") + String(name))) : (__eliscript_truthy((name === "&rest")) ? ((rest_node) => {
967
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_125) => (__eliscript_truthy(__eliscript_value_125) ? ((__eliscript_value_126) => (__eliscript_truthy(__eliscript_value_126) ? (!__eliscript_truthy((["&optional", "&rest", "&body"])["includes"](node_name(rest_node)))) : __eliscript_value_126))(symbol_node_p(rest_node)) : __eliscript_value_125))(((index + 2) === (items)["length"]))))) ? expander_fail(context, ((__eliscript_value_127) => (__eliscript_truthy(__eliscript_value_127) ? __eliscript_value_127 : span))(node_span(parameter)), "multi-arity clause requires one final &rest symbol") : null);
968
+ ((variadic = true));
969
+ return ((index = (items)["length"]));
970
+ })(((((items) ?? [])[(index + 1)]) ?? null)) : (() => {
971
+ ((required = (required + 1)));
972
+ return ((index = (index + 1)));
973
+ })()));
974
+ })(((__eliscript_value_122) => (__eliscript_truthy(__eliscript_value_122) ? node_name(parameter) : __eliscript_value_122))(symbol_node_p(parameter)));
975
+ })(((((items) ?? [])[index]) ?? null));
976
+ }
977
+ return null;
978
+ })();
979
+ return ({"required": required, "variadic": variadic});
980
+ })(list_items(parameters), 0, false, 0);
981
+ }
982
+ function multi_arity_clauses(forms, context, span) {
983
+ (__eliscript_truthy(((forms)["length"] < 2)) ? expander_fail(context, span, "multi-arity function requires at least two clauses") : null);
984
+ return ((fixed, fixed_arities, variadic, variadic_minimum, clauses, index) => {
985
+ (() => {
986
+ while (__eliscript_truthy((index < (forms)["length"]))) {
987
+ ((form) => {
988
+ return ((items) => {
989
+ return (() => {
990
+ (__eliscript_truthy(((__eliscript_value_128) => (__eliscript_truthy(__eliscript_value_128) ? __eliscript_value_128 : ((__eliscript_value_129) => (__eliscript_truthy(__eliscript_value_129) ? __eliscript_value_129 : (!__eliscript_truthy(list_node_p(((((items) ?? [])[0]) ?? null))))))(((items)["length"] < 2))))((items === undefined))) ? expander_fail(context, ((__eliscript_value_130) => (__eliscript_truthy(__eliscript_value_130) ? __eliscript_value_130 : span))(node_span(form)), "multi-arity clause requires a parameter list and body") : null);
991
+ return ((layout) => {
992
+ return ((required) => {
993
+ return ((variadic_clause) => {
994
+ return ((clause) => {
995
+ return (() => {
996
+ (__eliscript_truthy(variadic_clause) ? (() => {
997
+ (__eliscript_truthy(variadic) ? expander_fail(context, ((__eliscript_value_132) => (__eliscript_truthy(__eliscript_value_132) ? __eliscript_value_132 : span))(node_span(form)), "multi-arity function declares more than one variadic clause") : null);
998
+ ((variadic = true));
999
+ return ((variadic_minimum = required));
1000
+ })() : (() => {
1001
+ (__eliscript_truthy((fixed)["has"](required)) ? expander_fail(context, ((__eliscript_value_133) => (__eliscript_truthy(__eliscript_value_133) ? __eliscript_value_133 : span))(node_span(form)), (String("multi-arity function declares duplicate fixed arity: ") + String(required))) : null);
1002
+ (fixed)["add"](required);
1003
+ return (fixed_arities)["push"](required);
1004
+ })());
1005
+ return (clauses)["push"](clause);
1006
+ })();
1007
+ })(({"form": form, "parameters": ((((items) ?? [])[0]) ?? null), "body": (items)["slice"](1), "required": required, "variadic": variadic_clause}));
1008
+ })((layout)["variadic"]);
1009
+ })((layout)["required"]);
1010
+ })(multi_arity_layout(((((items) ?? [])[0]) ?? null), context, ((__eliscript_value_131) => (__eliscript_truthy(__eliscript_value_131) ? __eliscript_value_131 : span))(node_span(form))));
1011
+ })();
1012
+ })(list_items(form));
1013
+ })(((((forms) ?? [])[index]) ?? null));
1014
+ ((index = (index + 1)));
1015
+ }
1016
+ return null;
1017
+ })();
1018
+ (__eliscript_truthy(variadic) ? ((arity_index) => {
1019
+ return (() => {
1020
+ while (__eliscript_truthy((arity_index < (fixed_arities)["length"]))) {
1021
+ ((arity) => {
1022
+ return (__eliscript_truthy((arity >= variadic_minimum)) ? expander_fail(context, span, (String("multi-arity fixed arity ") + String(arity) + String(" is unreachable behind variadic arity ") + String(variadic_minimum))) : null);
1023
+ })(((((fixed_arities) ?? [])[arity_index]) ?? null));
1024
+ ((arity_index = (arity_index + 1)));
1025
+ }
1026
+ return null;
1027
+ })();
1028
+ })(0) : null);
1029
+ return clauses;
1030
+ })(new Set(), [], false, null, [], 0);
1031
+ }
1032
+ function desugar_multi_arity(operator_node, name_node, clause_forms, source_node, context, span) {
1033
+ return ((operator) => {
1034
+ return ((clauses) => {
1035
+ return ((arguments_name) => {
1036
+ return ((arity_name) => {
1037
+ return ((branch_operator) => {
1038
+ return ((label) => {
1039
+ return ((cond_clauses) => {
1040
+ return ((index) => {
1041
+ return (() => {
1042
+ (() => {
1043
+ while (__eliscript_truthy((index < (clauses)["length"]))) {
1044
+ ((clause) => {
1045
+ return ((clause_node) => {
1046
+ return ((clause_span) => {
1047
+ return ((comparison) => {
1048
+ return ((branch_items) => {
1049
+ return ((branch) => {
1050
+ return ((selected) => {
1051
+ return (() => {
1052
+ ((clause)["body"])["forEach"]((body_node) => {
1053
+ return (branch_items)["push"](body_node);
1054
+ });
1055
+ ((branch = make_list(branch_items, clause_span)));
1056
+ ((selected = make_list([symbol_node("apply", clause_span), branch, arguments_name], clause_span)));
1057
+ return (cond_clauses)["push"](make_list([comparison, selected], clause_span));
1058
+ })();
1059
+ })(null);
1060
+ })(null);
1061
+ })([symbol_node(branch_operator, clause_span), (clause)["parameters"]]);
1062
+ })(make_list([symbol_node((__eliscript_truthy((clause)["variadic"]) ? ">=" : "="), clause_span), arity_name, literal_node((clause)["required"], clause_span)], clause_span));
1063
+ })(((__eliscript_value_135) => (__eliscript_truthy(__eliscript_value_135) ? __eliscript_value_135 : span))(node_span(clause_node)));
1064
+ })((clause)["form"]);
1065
+ })(((((clauses) ?? [])[index]) ?? null));
1066
+ ((index = (index + 1)));
1067
+ }
1068
+ return null;
1069
+ })();
1070
+ (cond_clauses)["push"](make_list([literal_node(true, span), make_list([symbol_node("__eliscript_arity_error", span), literal_node(label, span), arity_name], span)], span));
1071
+ return ((arity_value) => {
1072
+ return ((dispatch) => {
1073
+ return ((parameters) => {
1074
+ return ((result_items) => {
1075
+ return (() => {
1076
+ (__eliscript_truthy(name_node) ? (result_items)["push"](name_node) : null);
1077
+ (result_items)["push"](parameters);
1078
+ (result_items)["push"](dispatch);
1079
+ return make_list(result_items, node_span(source_node));
1080
+ })();
1081
+ })([operator_node]);
1082
+ })(make_list([symbol_node("&rest", span), arguments_name], span));
1083
+ })(make_let_form(arity_name, arity_value, make_list(([symbol_node("cond", span)])["concat"](cond_clauses), span), span));
1084
+ })(make_list([symbol_node("js-length", span), arguments_name], span));
1085
+ })();
1086
+ })(0);
1087
+ })([]);
1088
+ })((__eliscript_truthy(name_node) ? node_display(name_node) : "anonymous function"));
1089
+ })((__eliscript_truthy(((__eliscript_value_134) => (__eliscript_truthy(__eliscript_value_134) ? __eliscript_value_134 : (operator === "defasync")))((operator === "async"))) ? "async" : "lambda"));
1090
+ })(fresh_name_node("arity-count", context, span));
1091
+ })(fresh_name_node("arity-arguments", context, span));
1092
+ })(multi_arity_clauses(clause_forms, context, span));
1093
+ })(node_name(operator_node));
1094
+ }
1095
+ function desugar_letfn(args, source_node, context, span) {
1096
+ (__eliscript_truthy(((args)["length"] === 0)) ? expander_fail(context, span, "letfn requires a binding list") : null);
1097
+ (__eliscript_truthy(((args)["length"] === 1)) ? expander_fail(context, span, "letfn requires at least one body form") : null);
1098
+ return ((bindings_node) => {
1099
+ return ((declarations) => {
1100
+ return ((bindings) => {
1101
+ return ((assignments) => {
1102
+ return (() => {
1103
+ (__eliscript_truthy((declarations === undefined)) ? expander_fail(context, span, "letfn bindings must be a list") : null);
1104
+ (declarations)["forEach"]((declaration) => {
1105
+ return ((declaration_span) => {
1106
+ return ((items) => {
1107
+ return (() => {
1108
+ (__eliscript_truthy(((__eliscript_value_137) => (__eliscript_truthy(__eliscript_value_137) ? __eliscript_value_137 : ((items)["length"] < 3)))((items === undefined))) ? expander_fail(context, declaration_span, "letfn declaration requires a name, parameter list, and body") : null);
1109
+ return ((name_node) => {
1110
+ return ((marker_node) => {
1111
+ return ((async_function) => {
1112
+ return ((function_forms) => {
1113
+ return ((operator_node) => {
1114
+ return ((parameters) => {
1115
+ return ((function_node) => {
1116
+ return (() => {
1117
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? expander_fail(context, declaration_span, (String("letfn name must be a symbol: ") + String(node_display(name_node)))) : null);
1118
+ (__eliscript_truthy((!__eliscript_truthy(list_node_p(parameters)))) ? expander_fail(context, declaration_span, "letfn declaration requires a parameter list") : null);
1119
+ ((function_node = (__eliscript_truthy(multi_arity_clause_p(parameters)) ? ((named) => {
1120
+ return ((named_items) => {
1121
+ return make_list(([((((named_items) ?? [])[0]) ?? null)])["concat"]((named_items)["slice"](2)), node_span(named));
1122
+ })(node_items(named));
1123
+ })(desugar_multi_arity(operator_node, name_node, function_forms, declaration, context, declaration_span)) : (() => {
1124
+ (__eliscript_truthy(((function_forms)["length"] === 1)) ? expander_fail(context, declaration_span, "letfn declaration requires a function body") : null);
1125
+ return make_list(([operator_node])["concat"](function_forms), declaration_span);
1126
+ })())));
1127
+ (bindings)["push"](make_list([name_node, literal_node(null, declaration_span)], declaration_span));
1128
+ return (assignments)["push"](make_list([symbol_node("set!", declaration_span), name_node, function_node], declaration_span));
1129
+ })();
1130
+ })(null);
1131
+ })(((((function_forms) ?? [])[0]) ?? null));
1132
+ })(symbol_node((__eliscript_truthy(async_function) ? "async" : "lambda"), declaration_span));
1133
+ })((items)["slice"]((__eliscript_truthy(async_function) ? 2 : 1)));
1134
+ })(((__eliscript_value_138) => (__eliscript_truthy(__eliscript_value_138) ? (node_name(marker_node) === "async") : __eliscript_value_138))(symbol_node_p(marker_node)));
1135
+ })(((((items) ?? [])[1]) ?? null));
1136
+ })(((((items) ?? [])[0]) ?? null));
1137
+ })();
1138
+ })(list_items(declaration));
1139
+ })(((__eliscript_value_136) => (__eliscript_truthy(__eliscript_value_136) ? __eliscript_value_136 : span))(node_span(declaration)));
1140
+ });
1141
+ return make_list(([symbol_node("let", span), make_list(bindings, span)])["concat"](assignments, (args)["slice"](1)), node_span(source_node));
1142
+ })();
1143
+ })([]);
1144
+ })([]);
1145
+ })(list_items(bindings_node));
1146
+ })(((((args) ?? [])[0]) ?? null));
1147
+ }
1148
+ function desugar_defprotocol(args, context, span) {
1149
+ (__eliscript_truthy(((args)["length"] < 2)) ? expander_fail(context, span, "defprotocol expects a name and at least one operation") : null);
1150
+ return ((name_node) => {
1151
+ return ((operation_nodes) => {
1152
+ return ((seen) => {
1153
+ return ((operation_names) => {
1154
+ return ((forms) => {
1155
+ return (() => {
1156
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? expander_fail(context, span, (String("defprotocol name must be a symbol: ") + String(node_display(name_node)))) : null);
1157
+ (operation_nodes)["forEach"]((operation_node) => {
1158
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(operation_node)))) ? expander_fail(context, span, (String("defprotocol operation must be a symbol: ") + String(node_display(operation_node)))) : null);
1159
+ return ((operation_name) => {
1160
+ (__eliscript_truthy((seen)["has"](operation_name)) ? expander_fail(context, span, (String("defprotocol declares duplicate operation: ") + String(operation_name))) : null);
1161
+ (seen)["add"](operation_name);
1162
+ return (operation_names)["push"](literal_node(operation_name, node_span(operation_node)));
1163
+ })(node_name(operation_node));
1164
+ });
1165
+ (forms)["push"](make_list([symbol_node("defconst", span), name_node, make_list([symbol_node("define-protocol", span), literal_node(node_name(name_node), node_span(name_node)), make_list(([symbol_node("js-array", span)])["concat"](operation_names), span)], span)], span));
1166
+ (operation_nodes)["forEach"]((operation_node) => {
1167
+ return (forms)["push"](make_list([symbol_node("defconst", span), operation_node, make_list([symbol_node("protocol-method", span), name_node, literal_node(node_name(operation_node), node_span(operation_node))], span)], span));
1168
+ });
1169
+ return forms;
1170
+ })();
1171
+ })([]);
1172
+ })([]);
1173
+ })(new Set());
1174
+ })((args)["slice"](1));
1175
+ })(((((args) ?? [])[0]) ?? null));
1176
+ }
1177
+ function desugar_defrecord(args, context, span) {
1178
+ (__eliscript_truthy(((__eliscript_value_139, __eliscript_value_140) => (__eliscript_value_139 !== __eliscript_value_140))((args)["length"], 2)) ? expander_fail(context, span, "defrecord expects a name and field vector") : null);
1179
+ return ((name_node) => {
1180
+ return ((fields_node) => {
1181
+ return ((seen) => {
1182
+ return ((field_nodes) => {
1183
+ return ((field_names) => {
1184
+ return ((forms) => {
1185
+ return (() => {
1186
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_141) => (__eliscript_truthy(__eliscript_value_141) ? (!__eliscript_truthy((node_name(name_node))["includes"]("/"))) : __eliscript_value_141))(symbol_node_p(name_node))))) ? expander_fail(context, span, (String("defrecord name must be an unqualified symbol: ") + String(node_display(name_node)))) : null);
1187
+ (__eliscript_truthy((!__eliscript_truthy(vector_node_p(fields_node)))) ? expander_fail(context, span, (String("defrecord fields must be a vector: ") + String(node_display(fields_node)))) : null);
1188
+ (node_items(fields_node))["forEach"]((field_node) => {
1189
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_142) => (__eliscript_truthy(__eliscript_value_142) ? (!__eliscript_truthy((node_name(field_node))["includes"]("/"))) : __eliscript_value_142))(symbol_node_p(field_node))))) ? expander_fail(context, span, (String("defrecord fields must be unqualified symbols: ") + String(node_display(field_node)))) : null);
1190
+ return ((field_name) => {
1191
+ (__eliscript_truthy((seen)["has"](field_name)) ? expander_fail(context, span, (String("defrecord declares duplicate field: ") + String(field_name))) : null);
1192
+ (seen)["add"](field_name);
1193
+ (field_nodes)["push"](field_node);
1194
+ return (field_names)["push"](literal_node(field_name, node_span(field_node)));
1195
+ })(node_name(field_node));
1196
+ });
1197
+ ((name) => {
1198
+ return ((constructor_node) => {
1199
+ return ((map_constructor_node) => {
1200
+ return ((predicate_node) => {
1201
+ return ((source_node) => {
1202
+ return ((value_node) => {
1203
+ return (() => {
1204
+ (forms)["push"](make_list([symbol_node("defconst", span), name_node, make_list([symbol_node("define-record-type", span), literal_node(name, node_span(name_node)), make_list(([symbol_node("js-array", span)])["concat"](field_names), span)], span)], span));
1205
+ (forms)["push"](make_list([symbol_node("defconst", span), constructor_node, make_list([symbol_node("lambda", span), make_list(field_nodes, node_span(fields_node)), make_list(([symbol_node("js-call", span), name_node, keyword_node("create", span)])["concat"](field_nodes), span)], span)], span));
1206
+ (forms)["push"](make_list([symbol_node("defconst", span), map_constructor_node, make_list([symbol_node("lambda", span), make_list([source_node], span), make_list([symbol_node("js-call", span), name_node, keyword_node("fromMap", span), source_node], span)], span)], span));
1207
+ return (forms)["push"](make_list([symbol_node("defconst", span), predicate_node, make_list([symbol_node("lambda", span), make_list([value_node], span), make_list([symbol_node("js-call", span), name_node, keyword_node("isInstance", span), value_node], span)], span)], span));
1208
+ })();
1209
+ })(symbol_node("value", node_span(name_node)));
1210
+ })(symbol_node("source", node_span(fields_node)));
1211
+ })(symbol_node((String(name) + String("?")), node_span(name_node)));
1212
+ })(symbol_node((String("map->") + String(name)), node_span(name_node)));
1213
+ })(symbol_node((String("->") + String(name)), node_span(name_node)));
1214
+ })(node_name(name_node));
1215
+ return forms;
1216
+ })();
1217
+ })([]);
1218
+ })([]);
1219
+ })([]);
1220
+ })(new Set());
1221
+ })(((((args) ?? [])[1]) ?? null));
1222
+ })(((((args) ?? [])[0]) ?? null));
1223
+ }
1224
+ function protocol_method_object(form_name, method_nodes, context, span, require_receiver = null) {
1225
+ (__eliscript_truthy(((method_nodes)["length"] === 0)) ? expander_fail(context, span, (String(form_name) + String(" expects at least one method"))) : null);
1226
+ return ((seen, object_items) => {
1227
+ (method_nodes)["forEach"]((method_node) => {
1228
+ return ((method_items) => {
1229
+ (__eliscript_truthy(((__eliscript_value_143) => (__eliscript_truthy(__eliscript_value_143) ? __eliscript_value_143 : ((method_items)["length"] < 2)))((method_items === undefined))) ? expander_fail(context, span, (String(form_name) + String(" method must contain an operation and parameter list: ") + String(node_display(method_node)))) : null);
1230
+ (__eliscript_truthy(require_receiver) ? ((parameter_items) => {
1231
+ return (__eliscript_truthy(((__eliscript_value_144) => (__eliscript_truthy(__eliscript_value_144) ? __eliscript_value_144 : ((parameter_items)["length"] === 0)))((parameter_items === undefined))) ? expander_fail(context, span, (String(form_name) + String(" method must declare a receiver parameter: ") + String(node_display(method_node)))) : null);
1232
+ })(list_items(((((method_items) ?? [])[1]) ?? null))) : null);
1233
+ return ((operation_node) => {
1234
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(operation_node)))) ? expander_fail(context, span, (String(form_name) + String(" method operation must be a symbol: ") + String(node_display(operation_node)))) : null);
1235
+ return ((operation_name) => {
1236
+ (__eliscript_truthy((seen)["has"](operation_name)) ? expander_fail(context, span, (String(form_name) + String(" declares duplicate method: ") + String(operation_name))) : null);
1237
+ (seen)["add"](operation_name);
1238
+ (object_items)["push"](literal_node(operation_name, node_span(operation_node)));
1239
+ return (object_items)["push"](make_list(([symbol_node("lambda", node_span(method_node))])["concat"]((method_items)["slice"](1)), node_span(method_node)));
1240
+ })(node_name(operation_node));
1241
+ })(((((method_items) ?? [])[0]) ?? null));
1242
+ })(list_items(method_node));
1243
+ });
1244
+ return make_list(object_items, span);
1245
+ })(new Set(), [symbol_node("js-object", span)]);
1246
+ }
1247
+ function protocol_implementation_plans(form_name, implementation_nodes, context, span, allow_empty = null) {
1248
+ (__eliscript_truthy(((__eliscript_value_145) => (__eliscript_truthy(__eliscript_value_145) ? ((implementation_nodes)["length"] === 0) : __eliscript_value_145))((!__eliscript_truthy(allow_empty)))) ? expander_fail(context, span, (String(form_name) + String(" expects at least one protocol implementation"))) : null);
1249
+ return ((seen, plans, index) => {
1250
+ (() => {
1251
+ while (__eliscript_truthy((index < (implementation_nodes)["length"]))) {
1252
+ ((protocol_node) => {
1253
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(protocol_node)))) ? expander_fail(context, span, (String(form_name) + String(" protocol must be a symbol: ") + String(node_display(protocol_node)))) : null);
1254
+ return ((protocol_name, method_nodes) => {
1255
+ (__eliscript_truthy((seen)["has"](protocol_name)) ? expander_fail(context, span, (String(form_name) + String(" declares duplicate protocol: ") + String(protocol_name))) : null);
1256
+ (seen)["add"](protocol_name);
1257
+ ((index = (index + 1)));
1258
+ (() => {
1259
+ while (__eliscript_truthy(((__eliscript_value_146) => (__eliscript_truthy(__eliscript_value_146) ? (node_kind(((((implementation_nodes) ?? [])[index]) ?? null)) === "list") : __eliscript_value_146))((index < (implementation_nodes)["length"])))) {
1260
+ (method_nodes)["push"](((((implementation_nodes) ?? [])[index]) ?? null));
1261
+ ((index = (index + 1)));
1262
+ }
1263
+ return null;
1264
+ })();
1265
+ (__eliscript_truthy(((method_nodes)["length"] === 0)) ? expander_fail(context, span, (String(form_name) + String(" protocol ") + String(protocol_name) + String(" expects at least one method"))) : null);
1266
+ return (plans)["push"](make_list([symbol_node("js-array", span), protocol_node, protocol_method_object(form_name, method_nodes, context, span, true)], span));
1267
+ })(node_name(protocol_node), []);
1268
+ })(((((implementation_nodes) ?? [])[index]) ?? null));
1269
+ }
1270
+ return null;
1271
+ })();
1272
+ return make_list(plans, span);
1273
+ })(new Set(), [symbol_node("js-array", span)], 0);
1274
+ }
1275
+ function desugar_deftype(args, context, span) {
1276
+ (__eliscript_truthy(((args)["length"] < 2)) ? expander_fail(context, span, "deftype expects a name, field vector, and optional protocol implementations") : null);
1277
+ return ((name_node) => {
1278
+ return ((fields_node) => {
1279
+ return ((seen) => {
1280
+ return ((field_nodes) => {
1281
+ return ((field_names) => {
1282
+ return ((forms) => {
1283
+ return (() => {
1284
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_147) => (__eliscript_truthy(__eliscript_value_147) ? (!__eliscript_truthy((node_name(name_node))["includes"]("/"))) : __eliscript_value_147))(symbol_node_p(name_node))))) ? expander_fail(context, span, (String("deftype name must be an unqualified symbol: ") + String(node_display(name_node)))) : null);
1285
+ (__eliscript_truthy((!__eliscript_truthy(vector_node_p(fields_node)))) ? expander_fail(context, span, (String("deftype fields must be a vector: ") + String(node_display(fields_node)))) : null);
1286
+ (node_items(fields_node))["forEach"]((field_node) => {
1287
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_148) => (__eliscript_truthy(__eliscript_value_148) ? (!__eliscript_truthy((node_name(field_node))["includes"]("/"))) : __eliscript_value_148))(symbol_node_p(field_node))))) ? expander_fail(context, span, (String("deftype fields must be unqualified symbols: ") + String(node_display(field_node)))) : null);
1288
+ return ((field_name) => {
1289
+ (__eliscript_truthy((seen)["has"](field_name)) ? expander_fail(context, span, (String("deftype declares duplicate field: ") + String(field_name))) : null);
1290
+ (seen)["add"](field_name);
1291
+ (field_nodes)["push"](field_node);
1292
+ return (field_names)["push"](literal_node(field_name, node_span(field_node)));
1293
+ })(node_name(field_node));
1294
+ });
1295
+ ((name) => {
1296
+ return ((constructor_node) => {
1297
+ return ((predicate_node) => {
1298
+ return ((value_node) => {
1299
+ return ((plans_node) => {
1300
+ return (() => {
1301
+ (forms)["push"](make_list([symbol_node("defconst", span), name_node, make_list([symbol_node("define-type", span), literal_node(name, node_span(name_node)), make_list(([symbol_node("js-array", span)])["concat"](field_names), span), plans_node], span)], span));
1302
+ (forms)["push"](make_list([symbol_node("defconst", span), constructor_node, make_list([symbol_node("lambda", span), make_list(field_nodes, node_span(fields_node)), make_list(([symbol_node("js-call", span), name_node, keyword_node("create", span)])["concat"](field_nodes), span)], span)], span));
1303
+ return (forms)["push"](make_list([symbol_node("defconst", span), predicate_node, make_list([symbol_node("lambda", span), make_list([value_node], span), make_list([symbol_node("js-call", span), name_node, keyword_node("isInstance", span), value_node], span)], span)], span));
1304
+ })();
1305
+ })(protocol_implementation_plans("deftype", (args)["slice"](2), context, span, true));
1306
+ })(symbol_node("value", node_span(name_node)));
1307
+ })(symbol_node((String(name) + String("?")), node_span(name_node)));
1308
+ })(symbol_node((String("->") + String(name)), node_span(name_node)));
1309
+ })(node_name(name_node));
1310
+ return forms;
1311
+ })();
1312
+ })([]);
1313
+ })([]);
1314
+ })([]);
1315
+ })(new Set());
1316
+ })(((((args) ?? [])[1]) ?? null));
1317
+ })(((((args) ?? [])[0]) ?? null));
1318
+ }
1319
+ function desugar_reify(args, context, span) {
1320
+ return make_list([symbol_node("reify-protocols", span), protocol_implementation_plans("reify", args, context, span, false)], span);
1321
+ }
1322
+ function desugar_extend_type(args, context, span) {
1323
+ (__eliscript_truthy(((args)["length"] < 3)) ? expander_fail(context, span, "extend-type expects a target, protocol, and at least one method") : null);
1324
+ return ((target_node, protocol_node) => {
1325
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(target_node)))) ? expander_fail(context, span, (String("extend-type target must be a symbol: ") + String(node_display(target_node)))) : null);
1326
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(protocol_node)))) ? expander_fail(context, span, (String("extend-type protocol must be a symbol: ") + String(node_display(protocol_node)))) : null);
1327
+ return make_list([symbol_node("extend-protocol-type", span), protocol_node, target_node, protocol_method_object("extend-type", (args)["slice"](2), context, span)], span);
1328
+ })(((((args) ?? [])[0]) ?? null), ((((args) ?? [])[1]) ?? null));
1329
+ }
1330
+ function desugar_extend_category(args, context, span) {
1331
+ (__eliscript_truthy(((args)["length"] < 3)) ? expander_fail(context, span, "extend-category expects a category, protocol, and at least one method") : null);
1332
+ return ((category_node, protocol_node) => {
1333
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_149) => (__eliscript_truthy(__eliscript_value_149) ? ((__eliscript_value_150) => (__eliscript_truthy(__eliscript_value_150) ? ((node_value(category_node))["length"] > 0) : __eliscript_value_150))((((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })(node_value(category_node)) === "string")) : __eliscript_value_149))(literal_node_p(category_node))))) ? expander_fail(context, span, (String("extend-category category must be a non-empty string: ") + String(node_display(category_node)))) : null);
1334
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(protocol_node)))) ? expander_fail(context, span, (String("extend-category protocol must be a symbol: ") + String(node_display(protocol_node)))) : null);
1335
+ return make_list([symbol_node("extend-protocol-category", span), protocol_node, category_node, protocol_method_object("extend-category", (args)["slice"](2), context, span)], span);
1336
+ })(((((args) ?? [])[0]) ?? null), ((((args) ?? [])[1]) ?? null));
1337
+ }
1338
+ function desugar_extend_default(args, context, span) {
1339
+ (__eliscript_truthy(((args)["length"] < 2)) ? expander_fail(context, span, "extend-default expects a protocol and at least one method") : null);
1340
+ return ((protocol_node) => {
1341
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(protocol_node)))) ? expander_fail(context, span, (String("extend-default protocol must be a symbol: ") + String(node_display(protocol_node)))) : null);
1342
+ return make_list([symbol_node("extend-protocol-default", span), protocol_node, protocol_method_object("extend-default", (args)["slice"](1), context, span)], span);
1343
+ })(((((args) ?? [])[0]) ?? null));
1344
+ }
1345
+ function expand_expression(form, environment, depth, context) {
1346
+ return (__eliscript_truthy((node_kind(form) === "vector")) ? collection_node("vector", expand_sequence(node_items(form), environment, depth, context), node_span(form)) : (__eliscript_truthy((!__eliscript_truthy((node_kind(form) === "list")))) ? form : ((items) => {
1347
+ return ((operator_node) => {
1348
+ return ((operator) => {
1349
+ return ((args) => {
1350
+ return ((span) => {
1351
+ return (__eliscript_truthy((operator === "quote")) ? form : (__eliscript_truthy((operator === "defmacro")) ? expander_fail(context, span, "defmacro is only valid at module top level") : (__eliscript_truthy((operator === "defportable")) ? expander_fail(context, span, "defportable is only valid at module top level") : (__eliscript_truthy((operator === "defasync")) ? expander_fail(context, span, "defasync is only valid at module top level") : (__eliscript_truthy((operator === "defmulti")) ? expander_fail(context, span, "defmulti is only valid at module top level") : (__eliscript_truthy((operator === "defmethod")) ? expander_fail(context, span, "defmethod is only valid at module top level") : (__eliscript_truthy(((__eliscript_value_152) => (__eliscript_truthy(__eliscript_value_152) ? __eliscript_value_152 : ((__eliscript_value_153) => (__eliscript_truthy(__eliscript_value_153) ? __eliscript_value_153 : ((__eliscript_value_154) => (__eliscript_truthy(__eliscript_value_154) ? __eliscript_value_154 : ((__eliscript_value_155) => (__eliscript_truthy(__eliscript_value_155) ? __eliscript_value_155 : ((__eliscript_value_156) => (__eliscript_truthy(__eliscript_value_156) ? __eliscript_value_156 : (operator === "extend-default")))((operator === "extend-category"))))((operator === "extend-type"))))((operator === "defprotocol"))))((operator === "defrecord"))))((operator === "deftype"))) ? expander_fail(context, span, (String(operator) + String(" is only valid at module top level"))) : (__eliscript_truthy(((__eliscript_value_157) => (__eliscript_truthy(__eliscript_value_157) ? (environment)["has"](operator) : __eliscript_value_157))(operator)) ? expand_expression(locate_generated(invoke_macro((environment)["get"](operator), args, depth, context, span), span), environment, (depth + 1), context) : (__eliscript_truthy((operator === "->")) ? expand_expression(desugar_thread("->", args, "first", context, span), environment, depth, context) : (__eliscript_truthy((operator === "->>")) ? expand_expression(desugar_thread("->>", args, "last", context, span), environment, depth, context) : (__eliscript_truthy((operator === "as->")) ? expand_expression(desugar_as_thread(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "cond->")) ? expand_expression(desugar_cond_thread("cond->", args, "first", context, span), environment, depth, context) : (__eliscript_truthy((operator === "cond->>")) ? expand_expression(desugar_cond_thread("cond->>", args, "last", context, span), environment, depth, context) : (__eliscript_truthy((operator === "some->")) ? expand_expression(desugar_some_thread("some->", args, "first", context, span), environment, depth, context) : (__eliscript_truthy((operator === "some->>")) ? expand_expression(desugar_some_thread("some->>", args, "last", context, span), environment, depth, context) : (__eliscript_truthy((operator === "if-let")) ? expand_expression(desugar_if_binding("if-let", args, false, context, span), environment, depth, context) : (__eliscript_truthy((operator === "when-let")) ? expand_expression(desugar_when_binding("when-let", args, false, context, span), environment, depth, context) : (__eliscript_truthy((operator === "if-some")) ? expand_expression(desugar_if_binding("if-some", args, true, context, span), environment, depth, context) : (__eliscript_truthy((operator === "when-some")) ? expand_expression(desugar_when_binding("when-some", args, true, context, span), environment, depth, context) : (__eliscript_truthy((operator === "case")) ? expand_expression(desugar_case(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "condp")) ? expand_expression(desugar_condp(args, context, span), environment, depth, context) : (__eliscript_truthy(((__eliscript_value_158) => (__eliscript_truthy(__eliscript_value_158) ? ((__eliscript_value_161) => (__eliscript_truthy(__eliscript_value_161) ? multi_arity_clause_p(((((args) ?? [])[0]) ?? null)) : __eliscript_value_161))(((args)["length"] > 0)) : __eliscript_value_158))(((__eliscript_value_159) => (__eliscript_truthy(__eliscript_value_159) ? __eliscript_value_159 : ((__eliscript_value_160) => (__eliscript_truthy(__eliscript_value_160) ? __eliscript_value_160 : (operator === "async")))((operator === "fn"))))((operator === "lambda")))) ? expand_expression(desugar_multi_arity(operator_node, null, args, form, context, span), environment, depth, context) : (__eliscript_truthy((operator === "reify")) ? expand_expression(desugar_reify(args, context, span), environment, depth, context) : ((expanded) => {
1352
+ (__eliscript_truthy(((__eliscript_value_162) => (__eliscript_truthy(__eliscript_value_162) ? __eliscript_value_162 : ((__eliscript_value_163) => (__eliscript_truthy(__eliscript_value_163) ? __eliscript_value_163 : (operator === "async")))((operator === "fn"))))((operator === "lambda"))) ? (__eliscript_truthy(((args)["length"] > 0)) ? (() => {
1353
+ (expanded)["push"](((((args) ?? [])[0]) ?? null));
1354
+ return (expand_sequence((args)["slice"](1), environment, depth, context))["forEach"]((item) => {
1355
+ return (expanded)["push"](item);
1356
+ });
1357
+ })() : null) : (__eliscript_truthy(((__eliscript_value_164) => (__eliscript_truthy(__eliscript_value_164) ? __eliscript_value_164 : (operator === "let*")))((operator === "let"))) ? (expand_bindings(args, environment, depth, context))["forEach"]((item) => {
1358
+ return (expanded)["push"](item);
1359
+ }) : (__eliscript_truthy((operator === "letfn")) ? ((expanded = node_items(expand_expression(desugar_letfn(args, form, context, span), environment, depth, context)))) : (__eliscript_truthy((operator === "setq")) ? (expand_alternating(args, environment, depth, context, false, false))["forEach"]((item) => {
1360
+ return (expanded)["push"](item);
1361
+ }) : (__eliscript_truthy((operator === "set!")) ? (__eliscript_truthy(((args)["length"] > 0)) ? (() => {
1362
+ (expanded)["push"](((((args) ?? [])[0]) ?? null));
1363
+ return (expand_sequence((args)["slice"](1), environment, depth, context))["forEach"]((item) => {
1364
+ return (expanded)["push"](item);
1365
+ });
1366
+ })() : null) : (__eliscript_truthy((operator === "cond")) ? (expand_cond(args, environment, depth, context))["forEach"]((item) => {
1367
+ return (expanded)["push"](item);
1368
+ }) : (__eliscript_truthy((operator === "try")) ? (args)["forEach"]((clause) => {
1369
+ return (expanded)["push"](expand_try_clause(clause, environment, depth, context));
1370
+ }) : (__eliscript_truthy((operator === "js-object")) ? (expand_alternating(args, environment, depth, context, true, true))["forEach"]((item) => {
1371
+ return (expanded)["push"](item);
1372
+ }) : (__eliscript_truthy(((__eliscript_value_165) => (__eliscript_truthy(__eliscript_value_165) ? __eliscript_value_165 : ((__eliscript_value_166) => (__eliscript_truthy(__eliscript_value_166) ? __eliscript_value_166 : (operator === "js-call")))((operator === "put"))))((operator === "get"))) ? (expand_property_call(args, environment, depth, context))["forEach"]((item) => {
1373
+ return (expanded)["push"](item);
1374
+ }) : (() => {
1375
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(operator_node)))) ? ((expanded)[0] = expand_expression(operator_node, environment, depth, context)) : null);
1376
+ return (expand_sequence(args, environment, depth, context))["forEach"]((item) => {
1377
+ return (expanded)["push"](item);
1378
+ });
1379
+ })())))))))));
1380
+ return make_list(expanded, span);
1381
+ })([operator_node]))))))))))))))))))))))));
1382
+ })(node_span(form));
1383
+ })((items)["slice"](1));
1384
+ })(((__eliscript_value_151) => (__eliscript_truthy(__eliscript_value_151) ? node_name(operator_node) : __eliscript_value_151))(symbol_node_p(operator_node)));
1385
+ })(((((items) ?? [])[0]) ?? null));
1386
+ })(node_items(form))));
1387
+ }
1388
+ function expand_top_level(form, environment, depth, context) {
1389
+ return (__eliscript_truthy((!__eliscript_truthy((node_kind(form) === "list")))) ? [expand_expression(form, environment, depth, context)] : ((items) => {
1390
+ return ((operator_node) => {
1391
+ return ((operator) => {
1392
+ return ((args) => {
1393
+ return ((span) => {
1394
+ return (__eliscript_truthy((operator === "defmacro")) ? (() => {
1395
+ register_macro(form, environment, context);
1396
+ return [];
1397
+ })() : (__eliscript_truthy((operator === "defmulti")) ? expand_top_level(desugar_defmulti(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "defmethod")) ? expand_top_level(desugar_defmethod(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "defprotocol")) ? expand_top_level_sequence(desugar_defprotocol(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "deftype")) ? expand_top_level_sequence(desugar_deftype(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "defrecord")) ? expand_top_level_sequence(desugar_defrecord(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "extend-type")) ? expand_top_level(desugar_extend_type(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "extend-category")) ? expand_top_level(desugar_extend_category(args, context, span), environment, depth, context) : (__eliscript_truthy((operator === "extend-default")) ? expand_top_level(desugar_extend_default(args, context, span), environment, depth, context) : (__eliscript_truthy(((__eliscript_value_168) => (__eliscript_truthy(__eliscript_value_168) ? ((__eliscript_value_172) => (__eliscript_truthy(__eliscript_value_172) ? multi_arity_clause_p(((((args) ?? [])[1]) ?? null)) : __eliscript_value_172))(((args)["length"] >= 2)) : __eliscript_value_168))(((__eliscript_value_169) => (__eliscript_truthy(__eliscript_value_169) ? __eliscript_value_169 : ((__eliscript_value_170) => (__eliscript_truthy(__eliscript_value_170) ? __eliscript_value_170 : ((__eliscript_value_171) => (__eliscript_truthy(__eliscript_value_171) ? __eliscript_value_171 : (operator === "defasync")))((operator === "defportable"))))((operator === "defn"))))((operator === "defun")))) ? expand_top_level(desugar_multi_arity(operator_node, ((((args) ?? [])[0]) ?? null), (args)["slice"](1), form, context, span), environment, depth, context) : (__eliscript_truthy(((__eliscript_value_173) => (__eliscript_truthy(__eliscript_value_173) ? (environment)["has"](operator) : __eliscript_value_173))(operator)) ? expand_top_level(locate_generated(invoke_macro((environment)["get"](operator), args, depth, context, span), span), environment, (depth + 1), context) : ((expanded) => {
1398
+ (__eliscript_truthy((operator === "module")) ? (__eliscript_truthy(((args)["length"] > 0)) ? (() => {
1399
+ (expanded)["push"](((((args) ?? [])[0]) ?? null));
1400
+ return (expand_top_level_sequence((args)["slice"](1), environment, depth, context))["forEach"]((item) => {
1401
+ return (expanded)["push"](item);
1402
+ });
1403
+ })() : null) : (__eliscript_truthy(((__eliscript_value_174) => (__eliscript_truthy(__eliscript_value_174) ? __eliscript_value_174 : ((__eliscript_value_175) => (__eliscript_truthy(__eliscript_value_175) ? __eliscript_value_175 : ((__eliscript_value_176) => (__eliscript_truthy(__eliscript_value_176) ? __eliscript_value_176 : (operator === "defasync")))((operator === "defportable"))))((operator === "defn"))))((operator === "defun"))) ? (__eliscript_truthy(((args)["length"] >= 2)) ? (() => {
1404
+ (expanded)["push"](((((args) ?? [])[0]) ?? null));
1405
+ (expanded)["push"](((((args) ?? [])[1]) ?? null));
1406
+ return (expand_sequence((args)["slice"](2), environment, depth, context))["forEach"]((item) => {
1407
+ return (expanded)["push"](item);
1408
+ });
1409
+ })() : ((expanded = items))) : (__eliscript_truthy(((__eliscript_value_177) => (__eliscript_truthy(__eliscript_value_177) ? __eliscript_value_177 : (operator === "defconst")))((operator === "defvar"))) ? (__eliscript_truthy(((args)["length"] > 0)) ? (() => {
1410
+ (expanded)["push"](((((args) ?? [])[0]) ?? null));
1411
+ return (expand_sequence((args)["slice"](1), environment, depth, context))["forEach"]((item) => {
1412
+ return (expanded)["push"](item);
1413
+ });
1414
+ })() : null) : (__eliscript_truthy(((__eliscript_value_178) => (__eliscript_truthy(__eliscript_value_178) ? __eliscript_value_178 : ((__eliscript_value_179) => (__eliscript_truthy(__eliscript_value_179) ? __eliscript_value_179 : (operator === "export")))((operator === "import-portable"))))((operator === "import"))) ? ((expanded = items)) : (__eliscript_truthy((operator === "export-default")) ? (expand_sequence(args, environment, depth, context))["forEach"]((item) => {
1415
+ return (expanded)["push"](item);
1416
+ }) : ((expanded = node_items(expand_expression(form, environment, depth, context)))))))));
1417
+ return [make_list(expanded, span)];
1418
+ })([operator_node]))))))))))));
1419
+ })(node_span(form));
1420
+ })((items)["slice"](1));
1421
+ })(((__eliscript_value_167) => (__eliscript_truthy(__eliscript_value_167) ? node_name(operator_node) : __eliscript_value_167))(symbol_node_p(operator_node)));
1422
+ })(((((items) ?? [])[0]) ?? null));
1423
+ })(node_items(form)));
1424
+ }
1425
+ function expand_top_level_sequence(forms, environment, depth, context) {
1426
+ return ((result) => {
1427
+ (forms)["forEach"]((form) => {
1428
+ return (expand_top_level(form, environment, depth, context))["forEach"]((expanded) => {
1429
+ return (result)["push"](expanded);
1430
+ });
1431
+ });
1432
+ return result;
1433
+ })([]);
1434
+ }
1435
+ function collect_symbol_names(node, names) {
1436
+ ((pending, current, kind, items, index) => {
1437
+ return (() => {
1438
+ while (__eliscript_truthy(((pending)["length"] > 0))) {
1439
+ ((current = (pending)["pop"]()));
1440
+ (__eliscript_truthy(symbol_node_p(current)) ? (names)["add"](node_name(current)) : (() => {
1441
+ ((kind = node_kind(current)));
1442
+ return (__eliscript_truthy(((__eliscript_value_180) => (__eliscript_truthy(__eliscript_value_180) ? __eliscript_value_180 : (kind === "vector")))((kind === "list"))) ? (() => {
1443
+ ((items = node_items(current)));
1444
+ ((index = ((items)["length"] - 1)));
1445
+ return (() => {
1446
+ while (__eliscript_truthy((index >= 0))) {
1447
+ (pending)["push"](((((items) ?? [])[index]) ?? null));
1448
+ ((index = (index - 1)));
1449
+ }
1450
+ return null;
1451
+ })();
1452
+ })() : null);
1453
+ })());
1454
+ }
1455
+ return null;
1456
+ })();
1457
+ })([node], null, null, null, 0);
1458
+ return names;
1459
+ }
1460
+ function expand_module(forms, filename, macro_context = null) {
1461
+ return ((reserved_names) => {
1462
+ (forms)["forEach"]((form) => {
1463
+ return collect_symbol_names(form, reserved_names);
1464
+ });
1465
+ return expand_top_level_sequence(forms, new Map(), 0, ({"filename": filename, "gensymCounter": 0, "reservedNames": reserved_names, "capabilities": (__eliscript_truthy(macro_context) ? (macro_context)["capabilities"] : new Set()), "files": (__eliscript_truthy(macro_context) ? (macro_context)["files"] : new Map())}));
1466
+ })(new Set());
1467
+ }
1468
+ export {expand_module};
1469
+ //# sourceMappingURL=expander.mjs.map