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,968 @@
1
+ // Generated by Eliscript. Do not edit.
2
+ const __eliscript_truthy = (value) => value !== false && value != null;
3
+
4
+ import {binding_name, reference_name} from "./symbol.mjs";
5
+ import {node_kind, node_span, node_value, node_name, node_items} from "./syntax.mjs";
6
+ import {analyze_transients} from "./transient-analysis.mjs";
7
+ const builtin_operators = ["if", "when", "unless", "progn", "do", "while", "loop", "recur", "and", "or", "not", "+", "*", "-", "/", "%", "mod", "=", "/=", "not=", "<", "<=", ">", ">=", "1+", "1-", "eq", "equal", "null", "nil?", "undefined?", "nullish?", "int32", "uint32", "imul32", "bit-and", "bit-or", "bit-xor", "bit-not", "bit-shift-left", "bit-shift-right", "unsigned-bit-shift-right", "value-type", "host-identity-token", "string-code-unit-at", "string-from-code-unit", "string-to-number", "string-to-bigint", "number-float64-words", "list", "vector", "hash-map", "hash-set", "queue", "js-array", "car", "cdr", "cons", "js-cons", "nth", "js-nth", "aref", "length", "js-length", "new", "print", "str", "object-keys", "object-has?", "object-assoc", "__eliscript_arity_error", "funcall", "apply"];
8
+ const portable_forbidden_operators = ["js*", "print", "put", "js-call", "new", "async", "await", "throw", "try"];
9
+ const fail = (diagnostic) => { const p = diagnostic.location.start; const error = new Error(`${diagnostic.location.file}:${p.line}:${p.column}: ${diagnostic.message}`); error.eliscriptDiagnostic = diagnostic; throw error; };
10
+ const guard = (operation, onError) => { try { return operation(); } catch (error) { return onError(error.message); } };
11
+ function compiler_fail(context, span, code, phase, message) {
12
+ return ((file) => {
13
+ return fail(({"format": "eliscript-diagnostic", "version": 1, "code": code, "severity": "error", "phase": phase, "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)})})}));
14
+ })(((__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"]));
15
+ }
16
+ function analyzer_fail(context, span, message) {
17
+ return compiler_fail(context, span, "ELI-A0001", "analysis", message);
18
+ }
19
+ function portable_fail(context, span, message) {
20
+ return compiler_fail(context, span, "ELI-P0001", "portable-analysis", message);
21
+ }
22
+ function symbol_node_p(node) {
23
+ return ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? (node_kind(node) === "symbol") : __eliscript_value_4))(node);
24
+ }
25
+ function keyword_node_p(node) {
26
+ return ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? (node_kind(node) === "keyword") : __eliscript_value_5))(node);
27
+ }
28
+ function vector_node_p(node) {
29
+ return ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? (node_kind(node) === "vector") : __eliscript_value_6))(node);
30
+ }
31
+ function map_node_p(node) {
32
+ return ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? (node_name(((((node_items(node)) ?? [])[0]) ?? null)) === "hash-map") : __eliscript_value_10))(symbol_node_p(((((node_items(node)) ?? [])[0]) ?? null))) : __eliscript_value_9))(((node_items(node))["length"] > 0)) : __eliscript_value_8))((node_kind(node) === "list")) : __eliscript_value_7))(node);
33
+ }
34
+ function string_node_p(node) {
35
+ return ((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? (typeof node.value === "string") : __eliscript_value_12))((node_kind(node) === "literal")) : __eliscript_value_11))(node);
36
+ }
37
+ function null_node_p(node) {
38
+ return ((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? ((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? (node_value(node) == null) : __eliscript_value_14))((node_kind(node) === "literal")) : __eliscript_value_13))(node);
39
+ }
40
+ function list_items(node) {
41
+ return (__eliscript_truthy(((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? (node_kind(node) === "list") : __eliscript_value_15))(node)) ? node_items(node) : (__eliscript_truthy(null_node_p(node)) ? [] : undefined));
42
+ }
43
+ function binding_marker_p(name) {
44
+ return (["&optional", "&rest", "&body"])["includes"](name);
45
+ }
46
+ function split_binding_name(name) {
47
+ return ((slash) => {
48
+ return (__eliscript_truthy((slash < 0)) ? ({"namespace": undefined, "local": name}) : ({"namespace": (name)["slice"](0, slash), "local": (name)["slice"]((slash + 1))}));
49
+ })((name)["lastIndexOf"]("/"));
50
+ }
51
+ function map_binding_shortcut(node) {
52
+ return (__eliscript_truthy(keyword_node_p(node)) ? ((parts) => {
53
+ return ((kind) => {
54
+ return (__eliscript_truthy((["keys", "strs", "syms"])["includes"](kind)) ? ({"kind": kind, "namespace": (parts)["namespace"]}) : null);
55
+ })((parts)["local"]);
56
+ })(split_binding_name(node_name(node))) : null);
57
+ }
58
+ function shortcut_entry(shortcut, name_node) {
59
+ return ((name) => {
60
+ return ((parts) => {
61
+ return ((local) => {
62
+ return ((namespace) => {
63
+ return ((kind) => {
64
+ return ((qualified) => {
65
+ return ({"target": ({"kind": "symbol", "name": local, "span": node_span(name_node)}), "keyKind": kind, "keyName": (__eliscript_truthy((kind === "strs")) ? name : qualified)});
66
+ })((__eliscript_truthy(namespace) ? (String(namespace) + String("/") + String(local)) : local));
67
+ })((shortcut)["kind"]);
68
+ })(((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? __eliscript_value_16 : (parts)["namespace"]))((shortcut)["namespace"]));
69
+ })((parts)["local"]);
70
+ })(split_binding_name(name));
71
+ })(node_name(name_node));
72
+ }
73
+ function map_binding_key_p(node) {
74
+ return ((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? __eliscript_value_17 : ((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? ((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? ((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? __eliscript_value_20 : (typeof node.value === "number")))((typeof node.value === "string")) : __eliscript_value_19))((node_kind(node) === "literal")) : __eliscript_value_18))(node)))(keyword_node_p(node));
75
+ }
76
+ function map_binding_spec(pattern, context) {
77
+ return ((items, entries, defaults, as, shortcuts_seen, or_seen, as_seen, index) => {
78
+ (() => {
79
+ while (__eliscript_truthy((index < (items)["length"]))) {
80
+ ((left) => {
81
+ return ((right) => {
82
+ return ((directive) => {
83
+ return ((shortcut) => {
84
+ return (__eliscript_truthy(shortcut) ? ((kind) => {
85
+ (__eliscript_truthy((shortcuts_seen)["has"](directive)) ? analyzer_fail(context, node_span(left), (String("map binding pattern accepts :") + String(directive) + String(" once"))) : null);
86
+ (shortcuts_seen)["add"](directive);
87
+ (__eliscript_truthy((!__eliscript_truthy(vector_node_p(right)))) ? analyzer_fail(context, node_span(right), (String("map binding :") + String(kind) + String(" value must be a vector"))) : null);
88
+ return (node_items(right))["forEach"]((name_node) => {
89
+ return ((name) => {
90
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? ((__eliscript_value_24) => (__eliscript_truthy(__eliscript_value_24) ? (((split_binding_name(name))["local"])["length"] > 0) : __eliscript_value_24))((!__eliscript_truthy(binding_marker_p(name)))) : __eliscript_value_23))(name)))) ? analyzer_fail(context, node_span(name_node), (String("map binding :") + String(kind) + String(" entries must be symbols"))) : null);
91
+ return (entries)["push"](shortcut_entry(shortcut, name_node));
92
+ })(((__eliscript_value_22) => (__eliscript_truthy(__eliscript_value_22) ? node_name(name_node) : __eliscript_value_22))(symbol_node_p(name_node)));
93
+ });
94
+ })((shortcut)["kind"]) : (__eliscript_truthy((directive === "or")) ? (() => {
95
+ (__eliscript_truthy(or_seen) ? analyzer_fail(context, node_span(left), "map binding pattern accepts :or once") : null);
96
+ ((or_seen = true));
97
+ (__eliscript_truthy((!__eliscript_truthy(map_node_p(right)))) ? analyzer_fail(context, node_span(right), "map binding :or value must be a map") : null);
98
+ return ((pairs, default_index) => {
99
+ return (() => {
100
+ while (__eliscript_truthy((default_index < (pairs)["length"]))) {
101
+ ((name_node) => {
102
+ return ((default$) => {
103
+ return ((name) => {
104
+ return (() => {
105
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_26) => (__eliscript_truthy(__eliscript_value_26) ? (!__eliscript_truthy(binding_marker_p(name))) : __eliscript_value_26))(name)))) ? analyzer_fail(context, node_span(name_node), "map binding :or keys must be binding symbols") : null);
106
+ (__eliscript_truthy((defaults)["has"](name)) ? analyzer_fail(context, node_span(name_node), "duplicate map binding :or default") : null);
107
+ return (defaults)["set"](name, default$);
108
+ })();
109
+ })(((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? node_name(name_node) : __eliscript_value_25))(symbol_node_p(name_node)));
110
+ })(((((pairs) ?? [])[(default_index + 1)]) ?? null));
111
+ })(((((pairs) ?? [])[default_index]) ?? null));
112
+ ((default_index = (default_index + 2)));
113
+ }
114
+ return null;
115
+ })();
116
+ })((node_items(right))["slice"](1), 0);
117
+ })() : (__eliscript_truthy((directive === "as")) ? (() => {
118
+ (__eliscript_truthy(as_seen) ? analyzer_fail(context, node_span(left), "map binding pattern accepts :as once") : null);
119
+ ((as_seen = true));
120
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_27) => (__eliscript_truthy(__eliscript_value_27) ? (!__eliscript_truthy(binding_marker_p(node_name(right)))) : __eliscript_value_27))(symbol_node_p(right))))) ? analyzer_fail(context, node_span(right), "map binding :as value must be a symbol") : null);
121
+ return ((as = right));
122
+ })() : (__eliscript_truthy(directive) ? analyzer_fail(context, node_span(left), (String("unknown map binding directive: :") + String(directive))) : (() => {
123
+ (__eliscript_truthy((!__eliscript_truthy(binding_pattern_p(left)))) ? analyzer_fail(context, node_span(left), "map binding entry target must be a binding pattern") : null);
124
+ (__eliscript_truthy((!__eliscript_truthy(map_binding_key_p(right)))) ? analyzer_fail(context, node_span(right), "map binding entry key must be a keyword, string, or number") : null);
125
+ return (entries)["push"](({"target": left, "key": right}));
126
+ })()))));
127
+ })(map_binding_shortcut(left));
128
+ })(((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? node_name(left) : __eliscript_value_21))(keyword_node_p(left)));
129
+ })(((((items) ?? [])[(index + 1)]) ?? null));
130
+ })(((((items) ?? [])[index]) ?? null));
131
+ ((index = (index + 2)));
132
+ }
133
+ return null;
134
+ })();
135
+ (defaults)["forEach"]((default$, name) => {
136
+ return ((entry) => {
137
+ (__eliscript_truthy((!__eliscript_truthy(entry))) ? analyzer_fail(context, node_span(default$), (String("map binding :or has no scalar target: ") + String(name))) : null);
138
+ ((entry)["default"] = default$);
139
+ return ((entry)["hasDefault"] = true);
140
+ })((entries)["find"]((candidate) => {
141
+ return ((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? (node_name((candidate)["target"]) === name) : __eliscript_value_28))(symbol_node_p((candidate)["target"]));
142
+ }));
143
+ });
144
+ return ({"entries": entries, "as": as});
145
+ })((node_items(pattern))["slice"](1), [], new globalThis.Map(), undefined, new globalThis.Set(), false, false, 0);
146
+ }
147
+ function binding_nodes(pattern, context) {
148
+ return (__eliscript_truthy(symbol_node_p(pattern)) ? (__eliscript_truthy(binding_marker_p(node_name(pattern))) ? analyzer_fail(context, node_span(pattern), "invalid binding pattern marker") : [pattern]) : (__eliscript_truthy(vector_node_p(pattern)) ? ((result, rest_seen, rest_done) => {
149
+ (node_items(pattern))["forEach"]((element) => {
150
+ return ((name) => {
151
+ return (__eliscript_truthy((name === "&rest")) ? (() => {
152
+ (__eliscript_truthy(((__eliscript_value_30) => (__eliscript_truthy(__eliscript_value_30) ? __eliscript_value_30 : rest_done))(rest_seen)) ? analyzer_fail(context, node_span(element), "invalid vector binding pattern") : null);
153
+ return ((rest_seen = true));
154
+ })() : (__eliscript_truthy(rest_seen) ? (() => {
155
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_31) => (__eliscript_truthy(__eliscript_value_31) ? (!__eliscript_truthy(binding_marker_p(name))) : __eliscript_value_31))(name)))) ? analyzer_fail(context, node_span(element), "vector &rest binding must be a symbol") : null);
156
+ (result)["push"](element);
157
+ ((rest_seen = false));
158
+ return ((rest_done = true));
159
+ })() : (__eliscript_truthy(rest_done) ? analyzer_fail(context, node_span(element), "vector &rest binding must be final") : (__eliscript_truthy(null_node_p(element)) ? null : (binding_nodes(element, context))["forEach"]((binding) => {
160
+ return (result)["push"](binding);
161
+ })))));
162
+ })(((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? node_name(element) : __eliscript_value_29))(symbol_node_p(element)));
163
+ });
164
+ (__eliscript_truthy(rest_seen) ? analyzer_fail(context, node_span(pattern), "vector &rest requires a binding") : null);
165
+ return result;
166
+ })([], false, false) : (__eliscript_truthy(map_node_p(pattern)) ? ((spec) => {
167
+ return ((result) => {
168
+ return (() => {
169
+ ((spec)["entries"])["forEach"]((entry) => {
170
+ return (binding_nodes((entry)["target"], context))["forEach"]((binding) => {
171
+ return (result)["push"](binding);
172
+ });
173
+ });
174
+ (__eliscript_truthy((spec)["as"]) ? (result)["push"]((spec)["as"]) : null);
175
+ return result;
176
+ })();
177
+ })([]);
178
+ })(map_binding_spec(pattern, context)) : analyzer_fail(context, ((__eliscript_value_32) => (__eliscript_truthy(__eliscript_value_32) ? node_span(pattern) : __eliscript_value_32))(pattern), (String("binding pattern must be a symbol, vector, or map: ") + String(node_display(pattern)))))));
179
+ }
180
+ function binding_pattern_p(node) {
181
+ return ((__eliscript_value_33) => (__eliscript_truthy(__eliscript_value_33) ? __eliscript_value_33 : ((__eliscript_value_35) => (__eliscript_truthy(__eliscript_value_35) ? __eliscript_value_35 : map_node_p(node)))(vector_node_p(node))))(((__eliscript_value_34) => (__eliscript_truthy(__eliscript_value_34) ? (!__eliscript_truthy(binding_marker_p(node_name(node)))) : __eliscript_value_34))(symbol_node_p(node)));
182
+ }
183
+ function function_parameters(parameters, context) {
184
+ return ((items, parsed, mode, index) => {
185
+ (__eliscript_truthy((items === undefined)) ? analyzer_fail(context, node_span(parameters), "function arguments must be a list") : null);
186
+ (() => {
187
+ while (__eliscript_truthy((index < (items)["length"]))) {
188
+ ((parameter) => {
189
+ return ((name) => {
190
+ return (__eliscript_truthy((name === "&optional")) ? (() => {
191
+ (__eliscript_truthy((!__eliscript_truthy((mode === "required")))) ? analyzer_fail(context, node_span(parameter), "invalid function parameter list") : null);
192
+ return ((mode = "optional"));
193
+ })() : (__eliscript_truthy((name === "&rest")) ? (() => {
194
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_37) => (__eliscript_truthy(__eliscript_value_37) ? __eliscript_value_37 : (mode === "optional")))((mode === "required"))))) ? analyzer_fail(context, node_span(parameter), "invalid function parameter list") : null);
195
+ return ((mode = "rest"));
196
+ })() : (__eliscript_truthy((name === "&body")) ? analyzer_fail(context, node_span(parameter), "invalid function parameter list") : (__eliscript_truthy((mode === "rest")) ? (() => {
197
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_38) => (__eliscript_truthy(__eliscript_value_38) ? (!__eliscript_truthy(binding_marker_p(name))) : __eliscript_value_38))(name)))) ? analyzer_fail(context, node_span(parameter), "function &rest parameter must be a symbol") : null);
198
+ (parsed)["push"](({"kind": "rest", "node": parameter, "bindings": [parameter]}));
199
+ return ((mode = "done"));
200
+ })() : (__eliscript_truthy((mode === "done")) ? analyzer_fail(context, node_span(parameter), "invalid function parameter list") : (__eliscript_truthy(binding_pattern_p(parameter)) ? (parsed)["push"](({"kind": mode, "node": parameter, "bindings": binding_nodes(parameter, context)})) : analyzer_fail(context, node_span(parameter), (String("function arguments must be symbols, vectors, or maps: ") + String(node_display(parameters))))))))));
201
+ })(((__eliscript_value_36) => (__eliscript_truthy(__eliscript_value_36) ? node_name(parameter) : __eliscript_value_36))(symbol_node_p(parameter)));
202
+ })(((((items) ?? [])[index]) ?? null));
203
+ ((index = (index + 1)));
204
+ }
205
+ return null;
206
+ })();
207
+ (__eliscript_truthy((mode === "rest")) ? analyzer_fail(context, node_span(parameters), "invalid function parameter list") : null);
208
+ return parsed;
209
+ })(list_items(parameters), [], "required", 0);
210
+ }
211
+ function node_display(node) {
212
+ 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) => {
213
+ 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))))));
214
+ })(node_value(node)) : (__eliscript_truthy(((__eliscript_value_39) => (__eliscript_truthy(__eliscript_value_39) ? __eliscript_value_39 : (node_kind(node) === "vector")))((node_kind(node) === "list"))) ? ((items) => {
215
+ return ((contents) => {
216
+ return (__eliscript_truthy(((__eliscript_value_40) => (__eliscript_truthy(__eliscript_value_40) ? ((__eliscript_value_41) => (__eliscript_truthy(__eliscript_value_41) ? ((__eliscript_value_42) => (__eliscript_truthy(__eliscript_value_42) ? (node_name(((((items) ?? [])[0]) ?? null)) === "quote") : __eliscript_value_42))(symbol_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_41))(((items)["length"] === 2)) : __eliscript_value_40))((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("]"))));
217
+ })(((items)["map"](node_display))["join"](" "));
218
+ })(node_items(node)) : "<unsupported>"))))));
219
+ }
220
+ function make_scope(parent, function_context = null) {
221
+ return ({"parent": parent, "names": new Map(), "outputs": new Map(), "functionContext": function_context});
222
+ }
223
+ function async_function_p(scope) {
224
+ return ((current, function_context) => {
225
+ (() => {
226
+ while (__eliscript_truthy(((__eliscript_value_43) => (__eliscript_truthy(__eliscript_value_43) ? (!__eliscript_truthy(function_context)) : __eliscript_value_43))(current))) {
227
+ ((function_context = (current)["functionContext"]));
228
+ ((current = (current)["parent"]));
229
+ }
230
+ return null;
231
+ })();
232
+ return (function_context === "async");
233
+ })(scope, null);
234
+ }
235
+ function guarded_binding_name(name, context, span) {
236
+ return guard(() => {
237
+ return binding_name(name);
238
+ }, (message) => {
239
+ return analyzer_fail(context, span, message);
240
+ });
241
+ }
242
+ function guarded_reference_name(name, context, span) {
243
+ return guard(() => {
244
+ return reference_name(name);
245
+ }, (message) => {
246
+ return analyzer_fail(context, span, message);
247
+ });
248
+ }
249
+ function declare_binding(scope, name_node, kind, mutable, context) {
250
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? analyzer_fail(context, ((__eliscript_value_44) => (__eliscript_truthy(__eliscript_value_44) ? node_span(name_node) : __eliscript_value_44))(name_node), (String("expected binding name, got ") + String(node_display(name_node)))) : null);
251
+ return ((name) => {
252
+ return ((span) => {
253
+ return ((names) => {
254
+ return ((outputs) => {
255
+ return ((output_name) => {
256
+ return ((existing_name) => {
257
+ return ((existing_output) => {
258
+ return (() => {
259
+ (__eliscript_truthy(existing_name) ? analyzer_fail(context, span, (String("duplicate ") + String(kind) + String(" binding: ") + String(name))) : null);
260
+ (__eliscript_truthy(existing_output) ? analyzer_fail(context, span, (String("binding ") + String(name) + String(" emits ") + String(output_name) + String(", which collides with ") + String((existing_output)["name"]))) : null);
261
+ return ((binding) => {
262
+ (names)["set"](name, binding);
263
+ (outputs)["set"](output_name, binding);
264
+ return binding;
265
+ })(({"name": name, "outputName": output_name, "kind": kind, "mutable": mutable}));
266
+ })();
267
+ })((outputs)["get"](output_name));
268
+ })((names)["get"](name));
269
+ })(guarded_binding_name(name, context, span));
270
+ })((scope)["outputs"]);
271
+ })((scope)["names"]);
272
+ })(node_span(name_node));
273
+ })(node_name(name_node));
274
+ }
275
+ function declare_pattern(scope, pattern, kind, mutable, context) {
276
+ return (binding_nodes(pattern, context))["forEach"]((binding) => {
277
+ return declare_binding(scope, binding, kind, mutable, context);
278
+ });
279
+ }
280
+ function lookup_binding(scope, name) {
281
+ return ((current, binding) => {
282
+ (() => {
283
+ while (__eliscript_truthy(((__eliscript_value_45) => (__eliscript_truthy(__eliscript_value_45) ? (!__eliscript_truthy(binding)) : __eliscript_value_45))(current))) {
284
+ ((binding = ((current)["names"])["get"](name)));
285
+ ((current = (current)["parent"]));
286
+ }
287
+ return null;
288
+ })();
289
+ return binding;
290
+ })(scope, undefined);
291
+ }
292
+ function require_binding(scope, node, context) {
293
+ return ((name) => {
294
+ return ((binding) => {
295
+ return ((__eliscript_value_46) => (__eliscript_truthy(__eliscript_value_46) ? __eliscript_value_46 : analyzer_fail(context, node_span(node), (String("unbound symbol: ") + String(name)))))(binding);
296
+ })(lookup_binding(scope, name));
297
+ })(node_name(node));
298
+ }
299
+ function qualified_name_p(name) {
300
+ return ((__eliscript_value_47) => (__eliscript_truthy(__eliscript_value_47) ? __eliscript_value_47 : (name)["includes"]("/")))((name)["includes"]("."));
301
+ }
302
+ function analyze_sequence(forms, scope, context) {
303
+ return ((tail_position, index) => {
304
+ (() => {
305
+ while (__eliscript_truthy((index < (forms)["length"]))) {
306
+ ((context)["tailPosition"] = ((__eliscript_value_48) => (__eliscript_truthy(__eliscript_value_48) ? (index === ((forms)["length"] - 1)) : __eliscript_value_48))(tail_position));
307
+ analyze_expression(((((forms) ?? [])[index]) ?? null), scope, context);
308
+ ((index = (index + 1)));
309
+ }
310
+ return null;
311
+ })();
312
+ return ((context)["tailPosition"] = tail_position);
313
+ })((context)["tailPosition"], 0);
314
+ }
315
+ function analyze_non_tail(form, scope, context) {
316
+ return ((tail_position) => {
317
+ ((context)["tailPosition"] = false);
318
+ analyze_expression(form, scope, context);
319
+ return ((context)["tailPosition"] = tail_position);
320
+ })((context)["tailPosition"]);
321
+ }
322
+ function analyze_pattern_defaults(pattern, scope, context) {
323
+ return (__eliscript_truthy(vector_node_p(pattern)) ? (node_items(pattern))["forEach"]((element) => {
324
+ return (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_49) => (__eliscript_truthy(__eliscript_value_49) ? __eliscript_value_49 : ((__eliscript_value_50) => (__eliscript_truthy(__eliscript_value_50) ? (node_name(element) === "&rest") : __eliscript_value_50))(symbol_node_p(element))))(null_node_p(element))))) ? analyze_pattern_defaults(element, scope, context) : null);
325
+ }) : (__eliscript_truthy(map_node_p(pattern)) ? ((spec) => {
326
+ return ((spec)["entries"])["forEach"]((entry) => {
327
+ (__eliscript_truthy((entry)["hasDefault"]) ? analyze_non_tail((entry)["default"], scope, context) : null);
328
+ return analyze_pattern_defaults((entry)["target"], scope, context);
329
+ });
330
+ })(map_binding_spec(pattern, context)) : null));
331
+ }
332
+ function analyze_non_tail_sequence(forms, scope, context) {
333
+ return ((tail_position) => {
334
+ ((context)["tailPosition"] = false);
335
+ analyze_sequence(forms, scope, context);
336
+ return ((context)["tailPosition"] = tail_position);
337
+ })((context)["tailPosition"]);
338
+ }
339
+ function binding_pair(binding, context) {
340
+ return (__eliscript_truthy(binding_pattern_p(binding)) ? (() => {
341
+ binding_nodes(binding, context);
342
+ return [binding, undefined];
343
+ })() : ((items) => {
344
+ return (__eliscript_truthy(((__eliscript_value_51) => (__eliscript_truthy(__eliscript_value_51) ? ((__eliscript_value_52) => (__eliscript_truthy(__eliscript_value_52) ? ((__eliscript_value_53) => (__eliscript_truthy(__eliscript_value_53) ? binding_pattern_p(((((items) ?? [])[0]) ?? null)) : __eliscript_value_53))(((items)["length"] <= 2)) : __eliscript_value_52))(((items)["length"] >= 1)) : __eliscript_value_51))((!__eliscript_truthy((items === undefined))))) ? (() => {
345
+ binding_nodes(((((items) ?? [])[0]) ?? null), context);
346
+ return [((((items) ?? [])[0]) ?? null), ((((items) ?? [])[1]) ?? null)];
347
+ })() : analyzer_fail(context, node_span(binding), (String("invalid let binding: ") + String(node_display(binding)))));
348
+ })(list_items(binding)));
349
+ }
350
+ function analyze_let(args, scope, sequential, context, form_span) {
351
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, (String((__eliscript_truthy(sequential) ? "let*" : "let")) + String(" requires a binding list"))) : null);
352
+ return ((bindings_form) => {
353
+ return ((bindings) => {
354
+ return ((body) => {
355
+ return ((child) => {
356
+ return (() => {
357
+ (__eliscript_truthy((bindings === undefined)) ? analyzer_fail(context, node_span(bindings_form), "let bindings must be a list") : null);
358
+ (__eliscript_truthy(sequential) ? (bindings)["forEach"]((binding) => {
359
+ return ((pair) => {
360
+ analyze_non_tail(((((pair) ?? [])[1]) ?? null), child, context);
361
+ analyze_pattern_defaults(((((pair) ?? [])[0]) ?? null), child, context);
362
+ return declare_pattern(child, ((((pair) ?? [])[0]) ?? null), "local", true, context);
363
+ })(binding_pair(binding, context));
364
+ }) : ((parsed) => {
365
+ (parsed)["forEach"]((pair) => {
366
+ analyze_non_tail(((((pair) ?? [])[1]) ?? null), scope, context);
367
+ return analyze_pattern_defaults(((((pair) ?? [])[0]) ?? null), scope, context);
368
+ });
369
+ return (parsed)["forEach"]((pair) => {
370
+ return declare_pattern(child, ((((pair) ?? [])[0]) ?? null), "local", true, context);
371
+ });
372
+ })((bindings)["map"]((binding) => {
373
+ return binding_pair(binding, context);
374
+ })));
375
+ return analyze_sequence(body, child, context);
376
+ })();
377
+ })(make_scope(scope));
378
+ })((args)["slice"](1));
379
+ })(list_items(bindings_form));
380
+ })(((((args) ?? [])[0]) ?? null));
381
+ }
382
+ function analyze_function(parameters, body, scope, context, asynchronous = null) {
383
+ return ((parameter_items) => {
384
+ (parameter_items)["forEach"]((parameter) => {
385
+ return analyze_pattern_defaults((parameter)["node"], scope, context);
386
+ });
387
+ return ((child) => {
388
+ (parameter_items)["forEach"]((parameter) => {
389
+ return ((parameter)["bindings"])["forEach"]((binding) => {
390
+ return declare_binding(child, binding, "parameter", true, context);
391
+ });
392
+ });
393
+ return ((recur_targets, tail_position, recur_barrier) => {
394
+ ((context)["recurTargets"] = [({"kind": "function", "arity": (parameter_items)["length"]})]);
395
+ ((context)["tailPosition"] = true);
396
+ ((context)["recurBarrier"] = false);
397
+ analyze_sequence(body, child, context);
398
+ ((context)["recurTargets"] = recur_targets);
399
+ ((context)["tailPosition"] = tail_position);
400
+ return ((context)["recurBarrier"] = recur_barrier);
401
+ })((context)["recurTargets"], (context)["tailPosition"], (context)["recurBarrier"]);
402
+ })(make_scope(scope, (__eliscript_truthy(asynchronous) ? "async" : "sync")));
403
+ })(function_parameters(parameters, context));
404
+ }
405
+ function analyze_loop(args, scope, context, form_span) {
406
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, "loop requires a binding list") : null);
407
+ return ((bindings_form) => {
408
+ return ((bindings) => {
409
+ return ((body) => {
410
+ return ((child) => {
411
+ return ((parsed) => {
412
+ return (() => {
413
+ (__eliscript_truthy((bindings === undefined)) ? analyzer_fail(context, node_span(bindings_form), "loop bindings must be a list") : null);
414
+ (bindings)["forEach"]((binding) => {
415
+ return ((items) => {
416
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_54) => (__eliscript_truthy(__eliscript_value_54) ? ((items)["length"] === 2) : __eliscript_value_54))((!__eliscript_truthy((items === undefined))))))) ? analyzer_fail(context, node_span(binding), (String("loop bindings require exactly one initializer: ") + String(node_display(binding)))) : null);
417
+ return (parsed)["push"](binding_pair(binding, context));
418
+ })(list_items(binding));
419
+ });
420
+ (parsed)["forEach"]((pair) => {
421
+ analyze_non_tail(((((pair) ?? [])[1]) ?? null), scope, context);
422
+ return analyze_pattern_defaults(((((pair) ?? [])[0]) ?? null), scope, context);
423
+ });
424
+ (parsed)["forEach"]((pair) => {
425
+ return declare_pattern(child, ((((pair) ?? [])[0]) ?? null), "loop", true, context);
426
+ });
427
+ return ((recur_targets, tail_position, recur_barrier, targets) => {
428
+ (targets)["push"](({"kind": "loop", "arity": (parsed)["length"]}));
429
+ (recur_targets)["forEach"]((target) => {
430
+ return (targets)["push"](target);
431
+ });
432
+ ((context)["recurTargets"] = targets);
433
+ ((context)["tailPosition"] = true);
434
+ ((context)["recurBarrier"] = false);
435
+ analyze_sequence(body, child, context);
436
+ ((context)["recurTargets"] = recur_targets);
437
+ ((context)["tailPosition"] = tail_position);
438
+ return ((context)["recurBarrier"] = recur_barrier);
439
+ })((context)["recurTargets"], (context)["tailPosition"], (context)["recurBarrier"], []);
440
+ })();
441
+ })([]);
442
+ })(make_scope(scope));
443
+ })((args)["slice"](1));
444
+ })(list_items(bindings_form));
445
+ })(((((args) ?? [])[0]) ?? null));
446
+ }
447
+ function analyze_recur(args, scope, context, form_span) {
448
+ return ((targets) => {
449
+ return ((target) => {
450
+ return (() => {
451
+ (__eliscript_truthy((!__eliscript_truthy(target))) ? analyzer_fail(context, form_span, "recur is only valid inside a function or loop") : null);
452
+ (__eliscript_truthy((context)["recurBarrier"]) ? analyzer_fail(context, form_span, "recur cannot cross a try boundary") : null);
453
+ (__eliscript_truthy((!__eliscript_truthy((context)["tailPosition"]))) ? analyzer_fail(context, form_span, "recur is only valid in tail position") : null);
454
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === (target)["arity"])))) ? analyzer_fail(context, form_span, (String("recur expects ") + String((target)["arity"]) + String(" arguments for the current ") + String((target)["kind"]) + String(", got ") + String((args)["length"]))) : null);
455
+ return analyze_non_tail_sequence(args, scope, context);
456
+ })();
457
+ })(((__eliscript_value_55) => (__eliscript_truthy(__eliscript_value_55) ? ((((targets) ?? [])[0]) ?? null) : __eliscript_value_55))(((targets)["length"] > 0)));
458
+ })((context)["recurTargets"]);
459
+ }
460
+ function analyze_assignment(args, scope, form_name, context, form_span) {
461
+ (__eliscript_truthy(((__eliscript_value_56) => (__eliscript_truthy(__eliscript_value_56) ? __eliscript_value_56 : (((args)["length"] % 2) === 1)))(((args)["length"] === 0))) ? analyzer_fail(context, form_span, (String(form_name) + String(" expects one or more name/value pairs"))) : null);
462
+ return ((index) => {
463
+ return (() => {
464
+ while (__eliscript_truthy((index < (args)["length"]))) {
465
+ ((name_node) => {
466
+ return ((value) => {
467
+ return (() => {
468
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name_node)))) ? analyzer_fail(context, form_span, (String("assignment target must be a symbol: ") + String(node_display(name_node)))) : null);
469
+ ((binding) => {
470
+ return (__eliscript_truthy((!__eliscript_truthy((binding)["mutable"]))) ? analyzer_fail(context, node_span(name_node), (String("cannot assign to immutable binding: ") + String(node_name(name_node)))) : null);
471
+ })(require_binding(scope, name_node, context));
472
+ return analyze_non_tail(value, scope, context);
473
+ })();
474
+ })(((((args) ?? [])[(index + 1)]) ?? null));
475
+ })(((((args) ?? [])[index]) ?? null));
476
+ ((index = (index + 2)));
477
+ }
478
+ return null;
479
+ })();
480
+ })(0);
481
+ }
482
+ function analyze_object(args, scope, context, form_span, form_name) {
483
+ (__eliscript_truthy((((args)["length"] % 2) === 1)) ? analyzer_fail(context, form_span, (String(form_name) + String(" expects key/value pairs"))) : null);
484
+ return ((index) => {
485
+ return (() => {
486
+ while (__eliscript_truthy((index < (args)["length"]))) {
487
+ ((key, value) => {
488
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_57) => (__eliscript_truthy(__eliscript_value_57) ? __eliscript_value_57 : ((__eliscript_value_58) => (__eliscript_truthy(__eliscript_value_58) ? __eliscript_value_58 : symbol_node_p(key)))(string_node_p(key))))(keyword_node_p(key))))) ? analyze_non_tail(key, scope, context) : null);
489
+ return analyze_non_tail(value, scope, context);
490
+ })(((((args) ?? [])[index]) ?? null), ((((args) ?? [])[(index + 1)]) ?? null));
491
+ ((index = (index + 2)));
492
+ }
493
+ return null;
494
+ })();
495
+ })(0);
496
+ }
497
+ function analyze_property_call(operator, args, scope, context, form_span) {
498
+ (__eliscript_truthy((operator === "get")) ? (__eliscript_truthy(((__eliscript_value_59) => (__eliscript_truthy(__eliscript_value_59) ? __eliscript_value_59 : ((args)["length"] > 3)))(((args)["length"] < 2))) ? analyzer_fail(context, form_span, "get expects 2..3 arguments") : null) : (__eliscript_truthy((operator === "put")) ? (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 3)))) ? analyzer_fail(context, form_span, "put expects 3 arguments") : null) : (__eliscript_truthy((operator === "js-call")) ? (__eliscript_truthy(((args)["length"] < 2)) ? analyzer_fail(context, form_span, "js-call expects 2+ arguments") : null) : null)));
499
+ analyze_non_tail(((((args) ?? [])[0]) ?? null), scope, context);
500
+ ((key) => {
501
+ return (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_60) => (__eliscript_truthy(__eliscript_value_60) ? __eliscript_value_60 : string_node_p(key)))(keyword_node_p(key))))) ? analyze_non_tail(key, scope, context) : null);
502
+ })(((((args) ?? [])[1]) ?? null));
503
+ return analyze_non_tail_sequence((args)["slice"](2), scope, context);
504
+ }
505
+ function analyze_cond(clauses, scope, context) {
506
+ return (clauses)["forEach"]((clause) => {
507
+ return ((items) => {
508
+ (__eliscript_truthy(((__eliscript_value_61) => (__eliscript_truthy(__eliscript_value_61) ? __eliscript_value_61 : ((items)["length"] === 0)))((items === undefined))) ? analyzer_fail(context, node_span(clause), (String("invalid cond clause: ") + String(node_display(clause)))) : null);
509
+ analyze_non_tail(((((items) ?? [])[0]) ?? null), scope, context);
510
+ return analyze_sequence((items)["slice"](1), scope, context);
511
+ })(list_items(clause));
512
+ });
513
+ }
514
+ function clause_operator(form) {
515
+ return ((items) => {
516
+ return ((__eliscript_value_62) => (__eliscript_truthy(__eliscript_value_62) ? ((__eliscript_value_63) => (__eliscript_truthy(__eliscript_value_63) ? ((__eliscript_value_64) => (__eliscript_truthy(__eliscript_value_64) ? node_name(((((items) ?? [])[0]) ?? null)) : __eliscript_value_64))(symbol_node_p(((((items) ?? [])[0]) ?? null))) : __eliscript_value_63))(((items)["length"] > 0)) : __eliscript_value_62))((!__eliscript_truthy((items === undefined))));
517
+ })(list_items(form));
518
+ }
519
+ function analyze_try(args, scope, context, form_span) {
520
+ return ((recur_barrier, clauses_started, catch_seen, finally_seen) => {
521
+ ((context)["recurBarrier"] = true);
522
+ (args)["forEach"]((argument) => {
523
+ return ((operator) => {
524
+ return (__eliscript_truthy((operator === "catch")) ? (() => {
525
+ (__eliscript_truthy(catch_seen) ? analyzer_fail(context, form_span, "try accepts at most one catch clause") : null);
526
+ (__eliscript_truthy(finally_seen) ? analyzer_fail(context, form_span, "catch must precede finally") : null);
527
+ ((clauses_started = true));
528
+ ((catch_seen = true));
529
+ return ((items) => {
530
+ return ((binding) => {
531
+ return (() => {
532
+ (__eliscript_truthy((!__eliscript_truthy(binding_pattern_p(binding)))) ? analyzer_fail(context, node_span(argument), "catch requires a binding symbol, vector, or map") : null);
533
+ analyze_pattern_defaults(binding, scope, context);
534
+ return ((child) => {
535
+ declare_pattern(child, binding, "catch", true, context);
536
+ return analyze_sequence((items)["slice"](2), child, context);
537
+ })(make_scope(scope));
538
+ })();
539
+ })(((((items) ?? [])[1]) ?? null));
540
+ })(list_items(argument));
541
+ })() : (__eliscript_truthy((operator === "finally")) ? (() => {
542
+ (__eliscript_truthy(finally_seen) ? analyzer_fail(context, form_span, "try accepts at most one finally clause") : null);
543
+ ((clauses_started = true));
544
+ ((finally_seen = true));
545
+ return analyze_sequence((list_items(argument))["slice"](1), scope, context);
546
+ })() : (__eliscript_truthy(clauses_started) ? analyzer_fail(context, node_span(argument), "try body forms must precede catch and finally clauses") : analyze_expression(argument, scope, context))));
547
+ })(clause_operator(argument));
548
+ });
549
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_65) => (__eliscript_truthy(__eliscript_value_65) ? __eliscript_value_65 : finally_seen))(catch_seen)))) ? analyzer_fail(context, form_span, "try requires a catch or finally clause") : null);
550
+ return ((context)["recurBarrier"] = recur_barrier);
551
+ })((context)["recurBarrier"], false, false, false);
552
+ }
553
+ function analyze_call(form, scope, context) {
554
+ return ((items) => {
555
+ return ((operator_node) => {
556
+ return ((operator) => {
557
+ return ((args) => {
558
+ return ((form_span) => {
559
+ return (__eliscript_truthy(((__eliscript_value_67) => (__eliscript_truthy(__eliscript_value_67) ? __eliscript_value_67 : (operator === "fn")))((operator === "lambda"))) ? (() => {
560
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, (String(operator) + String(" requires an argument list"))) : null);
561
+ return analyze_function(((((args) ?? [])[0]) ?? null), (args)["slice"](1), scope, context);
562
+ })() : (__eliscript_truthy((operator === "async")) ? (() => {
563
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, "async requires an argument list") : null);
564
+ return analyze_function(((((args) ?? [])[0]) ?? null), (args)["slice"](1), scope, context, true);
565
+ })() : (__eliscript_truthy((operator === "await")) ? (() => {
566
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 1)))) ? analyzer_fail(context, form_span, "await expects 1 argument") : null);
567
+ (__eliscript_truthy((!__eliscript_truthy(async_function_p(scope)))) ? analyzer_fail(context, form_span, "await is only valid inside an async function") : null);
568
+ return analyze_non_tail(((((args) ?? [])[0]) ?? null), scope, context);
569
+ })() : (__eliscript_truthy((operator === "throw")) ? (() => {
570
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 1)))) ? analyzer_fail(context, form_span, "throw expects 1 argument") : null);
571
+ return analyze_non_tail(((((args) ?? [])[0]) ?? null), scope, context);
572
+ })() : (__eliscript_truthy((operator === "try")) ? analyze_try(args, scope, context, form_span) : (__eliscript_truthy(((__eliscript_value_68) => (__eliscript_truthy(__eliscript_value_68) ? __eliscript_value_68 : (operator === "finally")))((operator === "catch"))) ? analyzer_fail(context, form_span, (String(operator) + String(" is only valid as a try clause"))) : (__eliscript_truthy((operator === "let")) ? analyze_let(args, scope, false, context, form_span) : (__eliscript_truthy((operator === "let*")) ? analyze_let(args, scope, true, context, form_span) : (__eliscript_truthy((operator === "loop")) ? analyze_loop(args, scope, context, form_span) : (__eliscript_truthy((operator === "recur")) ? analyze_recur(args, scope, context, form_span) : (__eliscript_truthy((operator === "setq")) ? analyze_assignment(args, scope, "setq", context, form_span) : (__eliscript_truthy((operator === "set!")) ? (() => {
573
+ (__eliscript_truthy((!__eliscript_truthy(((args)["length"] === 2)))) ? analyzer_fail(context, form_span, "set! expects 2 arguments") : null);
574
+ return analyze_assignment(args, scope, "set!", context, form_span);
575
+ })() : (__eliscript_truthy((operator === "cond")) ? analyze_cond(args, scope, context) : (__eliscript_truthy((operator === "if")) ? (() => {
576
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_69) => (__eliscript_truthy(__eliscript_value_69) ? ((args)["length"] <= 3) : __eliscript_value_69))(((args)["length"] >= 2))))) ? analyzer_fail(context, form_span, "if expects 2..3 arguments") : null);
577
+ analyze_non_tail(((((args) ?? [])[0]) ?? null), scope, context);
578
+ return analyze_sequence((args)["slice"](1), scope, context);
579
+ })() : (__eliscript_truthy(((__eliscript_value_70) => (__eliscript_truthy(__eliscript_value_70) ? __eliscript_value_70 : (operator === "unless")))((operator === "when"))) ? (() => {
580
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, (String(operator) + String(" expects 1+ arguments"))) : null);
581
+ analyze_non_tail(((((args) ?? [])[0]) ?? null), scope, context);
582
+ return analyze_sequence((args)["slice"](1), scope, context);
583
+ })() : (__eliscript_truthy(((__eliscript_value_71) => (__eliscript_truthy(__eliscript_value_71) ? __eliscript_value_71 : ((__eliscript_value_72) => (__eliscript_truthy(__eliscript_value_72) ? __eliscript_value_72 : ((__eliscript_value_73) => (__eliscript_truthy(__eliscript_value_73) ? __eliscript_value_73 : (operator === "or")))((operator === "and"))))((operator === "do"))))((operator === "progn"))) ? analyze_sequence(args, scope, context) : (__eliscript_truthy((operator === "while")) ? (() => {
584
+ (__eliscript_truthy(((args)["length"] === 0)) ? analyzer_fail(context, form_span, "while expects 1+ arguments") : null);
585
+ return analyze_non_tail_sequence(args, scope, context);
586
+ })() : (__eliscript_truthy((operator === "quote")) ? null : (__eliscript_truthy((operator === "js-object")) ? analyze_object(args, scope, context, form_span, operator) : (__eliscript_truthy((operator === "hash-map")) ? (() => {
587
+ (__eliscript_truthy((((args)["length"] % 2) === 1)) ? analyzer_fail(context, form_span, "hash-map expects complete key/value pairs") : null);
588
+ return analyze_non_tail_sequence(args, scope, context);
589
+ })() : (__eliscript_truthy(((__eliscript_value_74) => (__eliscript_truthy(__eliscript_value_74) ? __eliscript_value_74 : ((__eliscript_value_75) => (__eliscript_truthy(__eliscript_value_75) ? __eliscript_value_75 : (operator === "js-call")))((operator === "put"))))((operator === "get"))) ? analyze_property_call(operator, args, scope, context, form_span) : (__eliscript_truthy((operator === "js*")) ? null : (__eliscript_truthy((builtin_operators)["includes"](operator)) ? analyze_non_tail_sequence(args, scope, context) : (__eliscript_truthy((["defun", "defn", "defportable", "defasync", "defvar", "defconst", "export", "export-default", "import", "import-portable", "module"])["includes"](operator)) ? analyzer_fail(context, form_span, (String(operator) + String(" is only valid at module top level"))) : (() => {
590
+ analyze_non_tail(operator_node, scope, context);
591
+ return analyze_non_tail_sequence(args, scope, context);
592
+ })()))))))))))))))))))))))));
593
+ })(node_span(form));
594
+ })((items)["slice"](1));
595
+ })(((__eliscript_value_66) => (__eliscript_truthy(__eliscript_value_66) ? node_name(operator_node) : __eliscript_value_66))(symbol_node_p(operator_node)));
596
+ })(((((items) ?? [])[0]) ?? null));
597
+ })(node_items(form));
598
+ }
599
+ function analyze_expression(form, scope, context) {
600
+ return (__eliscript_truthy(form) ? (__eliscript_truthy(((__eliscript_value_76) => (__eliscript_truthy(__eliscript_value_76) ? __eliscript_value_76 : ((__eliscript_value_77) => (__eliscript_truthy(__eliscript_value_77) ? __eliscript_value_77 : (node_kind(form) === "keyword")))((node_kind(form) === "undefined"))))((node_kind(form) === "literal"))) ? null : (__eliscript_truthy((node_kind(form) === "symbol")) ? ((name) => {
601
+ return (__eliscript_truthy(qualified_name_p(name)) ? guarded_reference_name(name, context, node_span(form)) : require_binding(scope, form, context));
602
+ })(node_name(form)) : (__eliscript_truthy((node_kind(form) === "vector")) ? analyze_non_tail_sequence(node_items(form), scope, context) : (__eliscript_truthy((node_kind(form) === "list")) ? analyze_call(form, scope, context) : analyzer_fail(context, node_span(form), (String("unsupported form: ") + String(node_display(form)))))))) : null);
603
+ }
604
+ function import_bindings(args, context, form_span, portable) {
605
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_78) => (__eliscript_truthy(__eliscript_value_78) ? string_node_p(((((args) ?? [])[0]) ?? null)) : __eliscript_value_78))(((args)["length"] > 0))))) ? analyzer_fail(context, form_span, "import module must be a string") : null);
606
+ return ((bindings, index, default_seen, namespace_seen, named_seen) => {
607
+ (() => {
608
+ while (__eliscript_truthy((index < (args)["length"]))) {
609
+ ((specifier) => {
610
+ (__eliscript_truthy(((__eliscript_value_79) => (__eliscript_truthy(__eliscript_value_79) ? (node_name(specifier) === "default") : __eliscript_value_79))(keyword_node_p(specifier))) ? (() => {
611
+ (__eliscript_truthy(portable) ? analyzer_fail(context, form_span, "import-portable only supports named imports") : null);
612
+ (__eliscript_truthy(default_seen) ? analyzer_fail(context, form_span, "duplicate :default import") : null);
613
+ (__eliscript_truthy(((index + 1) >= (args)["length"])) ? analyzer_fail(context, form_span, ":default requires a binding") : null);
614
+ ((default_seen = true));
615
+ ((index = (index + 1)));
616
+ return (bindings)["push"](((((args) ?? [])[index]) ?? null));
617
+ })() : (__eliscript_truthy(((__eliscript_value_80) => (__eliscript_truthy(__eliscript_value_80) ? (node_name(specifier) === "as") : __eliscript_value_80))(keyword_node_p(specifier))) ? (() => {
618
+ (__eliscript_truthy(portable) ? analyzer_fail(context, form_span, "import-portable only supports named imports") : null);
619
+ (__eliscript_truthy(namespace_seen) ? analyzer_fail(context, form_span, "duplicate :as import") : null);
620
+ (__eliscript_truthy(((index + 1) >= (args)["length"])) ? analyzer_fail(context, form_span, ":as requires a namespace binding") : null);
621
+ ((namespace_seen = true));
622
+ ((index = (index + 1)));
623
+ return (bindings)["push"](((((args) ?? [])[index]) ?? null));
624
+ })() : (__eliscript_truthy(symbol_node_p(specifier)) ? (() => {
625
+ ((named_seen = true));
626
+ return (bindings)["push"](specifier);
627
+ })() : analyzer_fail(context, form_span, (String("invalid import specifier: ") + String(node_display(specifier)))))));
628
+ return ((index = (index + 1)));
629
+ })(((((args) ?? [])[index]) ?? null));
630
+ }
631
+ return null;
632
+ })();
633
+ (__eliscript_truthy(((__eliscript_value_81) => (__eliscript_truthy(__eliscript_value_81) ? named_seen : __eliscript_value_81))(namespace_seen)) ? analyzer_fail(context, form_span, "namespace and named imports cannot be combined") : null);
634
+ (__eliscript_truthy(((__eliscript_value_82) => (__eliscript_truthy(__eliscript_value_82) ? ((bindings)["length"] === 0) : __eliscript_value_82))(portable)) ? analyzer_fail(context, form_span, "import-portable expects one or more bindings") : null);
635
+ return bindings;
636
+ })([], 1, false, false, false);
637
+ }
638
+ function append_flattened_modules(forms, result, context) {
639
+ return (forms)["forEach"]((form) => {
640
+ return (__eliscript_truthy(((__eliscript_value_83) => (__eliscript_truthy(__eliscript_value_83) ? ((__eliscript_value_84) => (__eliscript_truthy(__eliscript_value_84) ? (node_name(((((node_items(form)) ?? [])[0]) ?? null)) === "module") : __eliscript_value_84))(symbol_node_p(((((node_items(form)) ?? [])[0]) ?? null))) : __eliscript_value_83))((node_kind(form) === "list"))) ? ((items) => {
641
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_85) => (__eliscript_truthy(__eliscript_value_85) ? symbol_node_p(((((items) ?? [])[1]) ?? null)) : __eliscript_value_85))(((items)["length"] > 1))))) ? analyzer_fail(context, node_span(form), "module name must be a symbol") : null);
642
+ return append_flattened_modules((items)["slice"](2), result, context);
643
+ })(node_items(form)) : (result)["push"](form));
644
+ });
645
+ }
646
+ function flatten_modules(forms, context) {
647
+ return ((result) => {
648
+ append_flattened_modules(forms, result, context);
649
+ return result;
650
+ })([]);
651
+ }
652
+ function predeclare_top_level(forms, scope, context) {
653
+ return (forms)["forEach"]((form) => {
654
+ return (__eliscript_truthy((node_kind(form) === "list")) ? ((items) => {
655
+ return ((operator_node) => {
656
+ return ((operator) => {
657
+ return ((args) => {
658
+ return ((count) => {
659
+ return (__eliscript_truthy(((__eliscript_value_87) => (__eliscript_truthy(__eliscript_value_87) ? __eliscript_value_87 : (operator === "import-portable")))((operator === "import"))) ? (() => {
660
+ (__eliscript_truthy((count === 0)) ? analyzer_fail(context, node_span(form), (String(operator) + String(" expects a module name"))) : null);
661
+ return (import_bindings(args, context, node_span(form), (operator === "import-portable")))["forEach"]((name) => {
662
+ return declare_binding(scope, name, "import", false, context);
663
+ });
664
+ })() : (__eliscript_truthy((operator === "defvar")) ? (() => {
665
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_88) => (__eliscript_truthy(__eliscript_value_88) ? (count <= 2) : __eliscript_value_88))((count >= 1))))) ? analyzer_fail(context, node_span(form), "defvar expects 1..2 arguments") : null);
666
+ return declare_binding(scope, ((((args) ?? [])[0]) ?? null), "variable", true, context);
667
+ })() : (__eliscript_truthy((operator === "defconst")) ? (() => {
668
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_89) => (__eliscript_truthy(__eliscript_value_89) ? (count <= 2) : __eliscript_value_89))((count >= 1))))) ? analyzer_fail(context, node_span(form), "defconst expects 1..2 arguments") : null);
669
+ return declare_binding(scope, ((((args) ?? [])[0]) ?? null), "constant", false, context);
670
+ })() : (__eliscript_truthy(((__eliscript_value_90) => (__eliscript_truthy(__eliscript_value_90) ? __eliscript_value_90 : ((__eliscript_value_91) => (__eliscript_truthy(__eliscript_value_91) ? __eliscript_value_91 : ((__eliscript_value_92) => (__eliscript_truthy(__eliscript_value_92) ? __eliscript_value_92 : (operator === "defasync")))((operator === "defportable"))))((operator === "defn"))))((operator === "defun"))) ? (() => {
671
+ (__eliscript_truthy((!__eliscript_truthy((count >= 2)))) ? analyzer_fail(context, node_span(form), (String(operator) + String(" expects 2+ arguments"))) : null);
672
+ return declare_binding(scope, ((((args) ?? [])[0]) ?? null), "function", false, context);
673
+ })() : null))));
674
+ })((args)["length"]);
675
+ })((items)["slice"](1));
676
+ })(((__eliscript_value_86) => (__eliscript_truthy(__eliscript_value_86) ? node_name(operator_node) : __eliscript_value_86))(symbol_node_p(operator_node)));
677
+ })(((((items) ?? [])[0]) ?? null));
678
+ })(node_items(form)) : null);
679
+ });
680
+ }
681
+ function analyze_top_level(form, scope, context) {
682
+ return (__eliscript_truthy((!__eliscript_truthy((node_kind(form) === "list")))) ? analyze_expression(form, scope, context) : ((items) => {
683
+ return ((operator_node) => {
684
+ return ((operator) => {
685
+ return ((args) => {
686
+ return ((count) => {
687
+ return (__eliscript_truthy(((__eliscript_value_94) => (__eliscript_truthy(__eliscript_value_94) ? __eliscript_value_94 : (operator === "import-portable")))((operator === "import"))) ? null : (__eliscript_truthy(((__eliscript_value_95) => (__eliscript_truthy(__eliscript_value_95) ? __eliscript_value_95 : (operator === "defconst")))((operator === "defvar"))) ? (() => {
688
+ (__eliscript_truthy((count > 2)) ? analyzer_fail(context, node_span(form), (String(operator) + String(" expects 1..2 arguments"))) : null);
689
+ return analyze_expression(((((args) ?? [])[1]) ?? null), scope, context);
690
+ })() : (__eliscript_truthy(((__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) ? __eliscript_value_98 : (operator === "defasync")))((operator === "defportable"))))((operator === "defn"))))((operator === "defun"))) ? (() => {
691
+ (__eliscript_truthy((!__eliscript_truthy((count >= 2)))) ? analyzer_fail(context, node_span(form), (String(operator) + String(" expects 2+ arguments"))) : null);
692
+ return analyze_function(((((args) ?? [])[1]) ?? null), (args)["slice"](2), scope, context, (operator === "defasync"));
693
+ })() : (__eliscript_truthy((operator === "export")) ? (() => {
694
+ (__eliscript_truthy((count === 0)) ? analyzer_fail(context, node_span(form), "export expects one or more bindings") : null);
695
+ return (args)["forEach"]((name) => {
696
+ (__eliscript_truthy((!__eliscript_truthy(symbol_node_p(name)))) ? analyzer_fail(context, node_span(name), (String("export name must be a symbol: ") + String(node_display(name)))) : null);
697
+ return require_binding(scope, name, context);
698
+ });
699
+ })() : (__eliscript_truthy((operator === "export-default")) ? (() => {
700
+ (__eliscript_truthy((!__eliscript_truthy((count === 1)))) ? analyzer_fail(context, node_span(form), "export-default expects 1 argument") : null);
701
+ return analyze_expression(((((args) ?? [])[0]) ?? null), scope, context);
702
+ })() : analyze_expression(form, scope, context))))));
703
+ })((args)["length"]);
704
+ })((items)["slice"](1));
705
+ })(((__eliscript_value_93) => (__eliscript_truthy(__eliscript_value_93) ? node_name(operator_node) : __eliscript_value_93))(symbol_node_p(operator_node)));
706
+ })(((((items) ?? [])[0]) ?? null));
707
+ })(node_items(form)));
708
+ }
709
+ function portable_declarations(forms, context) {
710
+ return ((declarations) => {
711
+ (forms)["forEach"]((form) => {
712
+ return (__eliscript_truthy((node_kind(form) === "list")) ? ((items) => {
713
+ return ((operator_node) => {
714
+ return ((operator) => {
715
+ return ((args) => {
716
+ return (__eliscript_truthy((operator === "defconst")) ? (declarations)["set"](node_name(((((args) ?? [])[0]) ?? null)), ({"kind": "constant", "form": form, "initializer": ((((args) ?? [])[1]) ?? null)})) : (__eliscript_truthy((operator === "defvar")) ? (declarations)["set"](node_name(((((args) ?? [])[0]) ?? null)), ({"kind": "variable", "form": form})) : (__eliscript_truthy(((__eliscript_value_100) => (__eliscript_truthy(__eliscript_value_100) ? __eliscript_value_100 : ((__eliscript_value_101) => (__eliscript_truthy(__eliscript_value_101) ? __eliscript_value_101 : ((__eliscript_value_102) => (__eliscript_truthy(__eliscript_value_102) ? __eliscript_value_102 : (operator === "defasync")))((operator === "defportable"))))((operator === "defn"))))((operator === "defun"))) ? (declarations)["set"](node_name(((((args) ?? [])[0]) ?? null)), ({"kind": (__eliscript_truthy((operator === "defportable")) ? "portable" : "function"), "form": form, "parameters": ((((args) ?? [])[1]) ?? null), "body": (args)["slice"](2)})) : (__eliscript_truthy(((__eliscript_value_103) => (__eliscript_truthy(__eliscript_value_103) ? __eliscript_value_103 : (operator === "import-portable")))((operator === "import"))) ? (import_bindings(args, context, node_span(form), (operator === "import-portable")))["forEach"]((name) => {
717
+ return (declarations)["set"](node_name(name), ({"kind": (__eliscript_truthy((operator === "import-portable")) ? "portable-import" : "import"), "form": form}));
718
+ }) : null))));
719
+ })((items)["slice"](1));
720
+ })(((__eliscript_value_99) => (__eliscript_truthy(__eliscript_value_99) ? node_name(operator_node) : __eliscript_value_99))(symbol_node_p(operator_node)));
721
+ })(((((items) ?? [])[0]) ?? null));
722
+ })(node_items(form)) : null);
723
+ });
724
+ return declarations;
725
+ })(new Map());
726
+ }
727
+ function portable_scope(parameters, context) {
728
+ return ((scope) => {
729
+ (__eliscript_truthy(parameters) ? (function_parameters(parameters, context))["forEach"]((parameter) => {
730
+ return ((parameter)["bindings"])["forEach"]((binding) => {
731
+ return (scope)["add"](node_name(binding));
732
+ });
733
+ }) : null);
734
+ return scope;
735
+ })(new Set());
736
+ }
737
+ function copy_portable_scope(scope) {
738
+ return new Set(scope);
739
+ }
740
+ function add_portable_pattern(pattern, scope, context) {
741
+ return (binding_nodes(pattern, context))["forEach"]((binding) => {
742
+ return (scope)["add"](node_name(binding));
743
+ });
744
+ }
745
+ function portable_reference(node, scope, declarations, dependencies, entry, context) {
746
+ return ((name) => {
747
+ return (__eliscript_truthy((!__eliscript_truthy((scope)["has"](name)))) ? (() => {
748
+ (__eliscript_truthy(qualified_name_p(name)) ? portable_fail(context, node_span(node), (String("portable function ") + String(entry) + String(" uses qualified host reference: ") + String(name))) : null);
749
+ return ((declaration) => {
750
+ return (__eliscript_truthy(declaration) ? ((kind) => {
751
+ return (__eliscript_truthy(((__eliscript_value_104) => (__eliscript_truthy(__eliscript_value_104) ? __eliscript_value_104 : ((__eliscript_value_105) => (__eliscript_truthy(__eliscript_value_105) ? __eliscript_value_105 : (kind === "portable-import")))((kind === "constant"))))((kind === "portable"))) ? (dependencies)["add"](name) : portable_fail(context, node_span(node), (String("portable function ") + String(entry) + String(" depends on non-portable ") + String(kind) + String(": ") + String(name))));
752
+ })((declaration)["kind"]) : null);
753
+ })((declarations)["get"](name));
754
+ })() : null);
755
+ })(node_name(node));
756
+ }
757
+ function portable_sequence(forms, scope, declarations, dependencies, entry, context) {
758
+ return (forms)["forEach"]((form) => {
759
+ return portable_expression(form, scope, declarations, dependencies, entry, context);
760
+ });
761
+ }
762
+ function portable_function_expression(args, scope, declarations, dependencies, entry, context) {
763
+ return ((child) => {
764
+ (function_parameters(((((args) ?? [])[0]) ?? null), context))["forEach"]((parameter) => {
765
+ return ((parameter)["bindings"])["forEach"]((binding) => {
766
+ return (child)["add"](node_name(binding));
767
+ });
768
+ });
769
+ return portable_sequence((args)["slice"](1), child, declarations, dependencies, entry, context);
770
+ })(copy_portable_scope(scope));
771
+ }
772
+ function portable_let_expression(args, scope, sequential, declarations, dependencies, entry, context) {
773
+ return ((bindings, child) => {
774
+ (__eliscript_truthy(sequential) ? (bindings)["forEach"]((binding) => {
775
+ return ((items) => {
776
+ return ((name) => {
777
+ return ((initializer) => {
778
+ return (() => {
779
+ portable_expression(initializer, child, declarations, dependencies, entry, context);
780
+ return add_portable_pattern(name, child, context);
781
+ })();
782
+ })(((__eliscript_value_106) => (__eliscript_truthy(__eliscript_value_106) ? ((((items) ?? [])[1]) ?? null) : __eliscript_value_106))(items));
783
+ })((__eliscript_truthy(items) ? ((((items) ?? [])[0]) ?? null) : binding));
784
+ })(list_items(binding));
785
+ }) : (() => {
786
+ (bindings)["forEach"]((binding) => {
787
+ return ((items) => {
788
+ return (__eliscript_truthy(items) ? portable_expression(((((items) ?? [])[1]) ?? null), scope, declarations, dependencies, entry, context) : null);
789
+ })(list_items(binding));
790
+ });
791
+ return (bindings)["forEach"]((binding) => {
792
+ return ((items) => {
793
+ return add_portable_pattern((__eliscript_truthy(items) ? ((((items) ?? [])[0]) ?? null) : binding), child, context);
794
+ })(list_items(binding));
795
+ });
796
+ })());
797
+ return portable_sequence((args)["slice"](1), child, declarations, dependencies, entry, context);
798
+ })(list_items(((((args) ?? [])[0]) ?? null)), copy_portable_scope(scope));
799
+ }
800
+ function portable_loop_expression(args, scope, declarations, dependencies, entry, context) {
801
+ return ((bindings, child) => {
802
+ (bindings)["forEach"]((binding) => {
803
+ return ((items) => {
804
+ return portable_expression(((((items) ?? [])[1]) ?? null), scope, declarations, dependencies, entry, context);
805
+ })(list_items(binding));
806
+ });
807
+ (bindings)["forEach"]((binding) => {
808
+ return add_portable_pattern(((((list_items(binding)) ?? [])[0]) ?? null), child, context);
809
+ });
810
+ return portable_sequence((args)["slice"](1), child, declarations, dependencies, entry, context);
811
+ })(list_items(((((args) ?? [])[0]) ?? null)), copy_portable_scope(scope));
812
+ }
813
+ function portable_assignment(args, scope, declarations, dependencies, entry, context) {
814
+ return ((index) => {
815
+ return (() => {
816
+ while (__eliscript_truthy((index < (args)["length"]))) {
817
+ ((name, value) => {
818
+ (__eliscript_truthy((!__eliscript_truthy((scope)["has"](node_name(name))))) ? portable_fail(context, node_span(name), (String("portable function ") + String(entry) + String(" may only assign local bindings: ") + String(node_name(name)))) : null);
819
+ return portable_expression(value, scope, declarations, dependencies, entry, context);
820
+ })(((((args) ?? [])[index]) ?? null), ((((args) ?? [])[(index + 1)]) ?? null));
821
+ ((index = (index + 2)));
822
+ }
823
+ return null;
824
+ })();
825
+ })(0);
826
+ }
827
+ function portable_object(args, scope, declarations, dependencies, entry, context) {
828
+ return ((index) => {
829
+ return (() => {
830
+ while (__eliscript_truthy((index < (args)["length"]))) {
831
+ ((key, value) => {
832
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_107) => (__eliscript_truthy(__eliscript_value_107) ? __eliscript_value_107 : ((__eliscript_value_108) => (__eliscript_truthy(__eliscript_value_108) ? __eliscript_value_108 : symbol_node_p(key)))(string_node_p(key))))(keyword_node_p(key))))) ? portable_expression(key, scope, declarations, dependencies, entry, context) : null);
833
+ return portable_expression(value, scope, declarations, dependencies, entry, context);
834
+ })(((((args) ?? [])[index]) ?? null), ((((args) ?? [])[(index + 1)]) ?? null));
835
+ ((index = (index + 2)));
836
+ }
837
+ return null;
838
+ })();
839
+ })(0);
840
+ }
841
+ function portable_host_key_call(args, scope, declarations, dependencies, entry, context) {
842
+ return ((index) => {
843
+ return (() => {
844
+ while (__eliscript_truthy((index < (args)["length"]))) {
845
+ ((argument) => {
846
+ return (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_109) => (__eliscript_truthy(__eliscript_value_109) ? keyword_node_p(argument) : __eliscript_value_109))((index === 1))))) ? portable_expression(argument, scope, declarations, dependencies, entry, context) : null);
847
+ })(((((args) ?? [])[index]) ?? null));
848
+ ((index = (index + 1)));
849
+ }
850
+ return null;
851
+ })();
852
+ })(0);
853
+ }
854
+ function portable_call(form, scope, declarations, dependencies, entry, context) {
855
+ return ((items) => {
856
+ return ((operator_node) => {
857
+ return ((operator) => {
858
+ return ((args) => {
859
+ return (() => {
860
+ (__eliscript_truthy((portable_forbidden_operators)["includes"](operator)) ? portable_fail(context, node_span(form), (String("portable function ") + String(entry) + String(" cannot use ") + String(operator) + String(" (") + String((__eliscript_truthy((operator === "js*")) ? "raw JavaScript" : (__eliscript_truthy((operator === "print")) ? "console output" : (__eliscript_truthy((operator === "put")) ? "object mutation" : (__eliscript_truthy((operator === "js-call")) ? "host method calls" : (__eliscript_truthy((operator === "new")) ? "host constructors" : (__eliscript_truthy((operator === "async")) ? "asynchronous functions" : (__eliscript_truthy((operator === "await")) ? "asynchronous suspension" : (__eliscript_truthy(((__eliscript_value_111) => (__eliscript_truthy(__eliscript_value_111) ? __eliscript_value_111 : (operator === "try")))((operator === "throw"))) ? "exception control flow" : "unsupported host capability"))))))))) + String(")"))) : null);
861
+ return (__eliscript_truthy((operator === "quote")) ? null : (__eliscript_truthy(((__eliscript_value_112) => (__eliscript_truthy(__eliscript_value_112) ? __eliscript_value_112 : (operator === "fn")))((operator === "lambda"))) ? portable_function_expression(args, scope, declarations, dependencies, entry, context) : (__eliscript_truthy((operator === "let")) ? portable_let_expression(args, scope, false, declarations, dependencies, entry, context) : (__eliscript_truthy((operator === "let*")) ? portable_let_expression(args, scope, true, declarations, dependencies, entry, context) : (__eliscript_truthy((operator === "loop")) ? portable_loop_expression(args, scope, declarations, dependencies, entry, context) : (__eliscript_truthy(((__eliscript_value_113) => (__eliscript_truthy(__eliscript_value_113) ? __eliscript_value_113 : (operator === "set!")))((operator === "setq"))) ? portable_assignment(args, scope, declarations, dependencies, entry, context) : (__eliscript_truthy((operator === "js-object")) ? portable_object(args, scope, declarations, dependencies, entry, context) : (__eliscript_truthy(((__eliscript_value_114) => (__eliscript_truthy(__eliscript_value_114) ? __eliscript_value_114 : ((__eliscript_value_115) => (__eliscript_truthy(__eliscript_value_115) ? __eliscript_value_115 : ((__eliscript_value_116) => (__eliscript_truthy(__eliscript_value_116) ? __eliscript_value_116 : (operator === "object-assoc")))((operator === "object-has?"))))((operator === "aref"))))((operator === "get"))) ? portable_host_key_call(args, scope, declarations, dependencies, entry, context) : (() => {
862
+ (__eliscript_truthy((!__eliscript_truthy((builtin_operators)["includes"](operator)))) ? portable_expression(operator_node, scope, declarations, dependencies, entry, context) : null);
863
+ return portable_sequence(args, scope, declarations, dependencies, entry, context);
864
+ })()))))))));
865
+ })();
866
+ })((items)["slice"](1));
867
+ })(((__eliscript_value_110) => (__eliscript_truthy(__eliscript_value_110) ? node_name(operator_node) : __eliscript_value_110))(symbol_node_p(operator_node)));
868
+ })(((((items) ?? [])[0]) ?? null));
869
+ })(node_items(form));
870
+ }
871
+ function portable_expression(form, scope, declarations, dependencies, entry, context) {
872
+ return (__eliscript_truthy(form) ? (__eliscript_truthy(((__eliscript_value_117) => (__eliscript_truthy(__eliscript_value_117) ? __eliscript_value_117 : (node_kind(form) === "undefined")))((node_kind(form) === "literal"))) ? null : (__eliscript_truthy((node_kind(form) === "keyword")) ? null : (__eliscript_truthy((node_kind(form) === "symbol")) ? portable_reference(form, scope, declarations, dependencies, entry, context) : (__eliscript_truthy((node_kind(form) === "vector")) ? portable_sequence(node_items(form), scope, declarations, dependencies, entry, context) : (__eliscript_truthy((node_kind(form) === "list")) ? portable_call(form, scope, declarations, dependencies, entry, context) : null))))) : null);
873
+ }
874
+ function portable_dependencies(declaration, declarations, entry, context) {
875
+ return ((dependencies, scope) => {
876
+ (__eliscript_truthy(((declaration)["kind"] === "portable")) ? portable_sequence((declaration)["body"], scope, declarations, dependencies, entry, context) : portable_expression((declaration)["initializer"], scope, declarations, dependencies, entry, context));
877
+ return dependencies;
878
+ })(new Set(), portable_scope((declaration)["parameters"], context));
879
+ }
880
+ function validate_portable_module(forms, context) {
881
+ return ((declarations, pending, visited) => {
882
+ (declarations)["forEach"]((declaration, name) => {
883
+ return (__eliscript_truthy(((declaration)["kind"] === "portable")) ? (pending)["push"](name) : null);
884
+ });
885
+ (() => {
886
+ while (__eliscript_truthy(((pending)["length"] > 0))) {
887
+ ((name) => {
888
+ return (__eliscript_truthy((!__eliscript_truthy((visited)["has"](name)))) ? (() => {
889
+ (visited)["add"](name);
890
+ return ((declaration) => {
891
+ return (portable_dependencies(declaration, declarations, name, context))["forEach"]((dependency) => {
892
+ return (pending)["push"](dependency);
893
+ });
894
+ })((declarations)["get"](name));
895
+ })() : null);
896
+ })((pending)["pop"]());
897
+ }
898
+ return null;
899
+ })();
900
+ return forms;
901
+ })(portable_declarations(forms, context), [], new Set());
902
+ }
903
+ function select_portable_module(forms, entries, filename, allow_project_imports = null) {
904
+ return ((context) => {
905
+ return ((flattened) => {
906
+ return ((declarations) => {
907
+ return ((pending) => {
908
+ return ((selected) => {
909
+ return (() => {
910
+ (entries)["forEach"]((entry) => {
911
+ return ((declaration) => {
912
+ (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_118) => (__eliscript_truthy(__eliscript_value_118) ? ((declaration)["kind"] === "portable") : __eliscript_value_118))(declaration)))) ? portable_fail(context, null, (String("portable entry ") + String(entry) + String(" is not declared with defportable"))) : null);
913
+ return (pending)["push"](entry);
914
+ })((declarations)["get"](entry));
915
+ });
916
+ (() => {
917
+ while (__eliscript_truthy(((pending)["length"] > 0))) {
918
+ ((name) => {
919
+ return (__eliscript_truthy((!__eliscript_truthy((selected)["has"](name)))) ? (() => {
920
+ (selected)["add"](name);
921
+ return ((declaration) => {
922
+ (__eliscript_truthy(((__eliscript_value_119) => (__eliscript_truthy(__eliscript_value_119) ? (!__eliscript_truthy(allow_project_imports)) : __eliscript_value_119))(((declaration)["kind"] === "portable-import"))) ? portable_fail(context, node_span((declaration)["form"]), (String("portable import ") + String(name) + String(" requires a project build"))) : null);
923
+ return (portable_dependencies(declaration, declarations, name, context))["forEach"]((dependency) => {
924
+ return (pending)["push"](dependency);
925
+ });
926
+ })((declarations)["get"](name));
927
+ })() : null);
928
+ })((pending)["pop"]());
929
+ }
930
+ return null;
931
+ })();
932
+ return (flattened)["filter"]((form) => {
933
+ return (__eliscript_truthy((node_kind(form) === "list")) ? ((items) => {
934
+ return ((operator) => {
935
+ return ((name) => {
936
+ return ((__eliscript_value_123) => (__eliscript_truthy(__eliscript_value_123) ? __eliscript_value_123 : ((__eliscript_value_126) => (__eliscript_truthy(__eliscript_value_126) ? ((items)["slice"](2))["some"]((imported) => {
937
+ return (selected)["has"](node_name(imported));
938
+ }) : __eliscript_value_126))((operator === "import-portable"))))(((__eliscript_value_124) => (__eliscript_truthy(__eliscript_value_124) ? (selected)["has"](name) : __eliscript_value_124))(((__eliscript_value_125) => (__eliscript_truthy(__eliscript_value_125) ? __eliscript_value_125 : (operator === "defportable")))((operator === "defconst"))));
939
+ })(((__eliscript_value_121) => (__eliscript_truthy(__eliscript_value_121) ? ((__eliscript_value_122) => (__eliscript_truthy(__eliscript_value_122) ? node_name(((((items) ?? [])[1]) ?? null)) : __eliscript_value_122))(symbol_node_p(((((items) ?? [])[1]) ?? null))) : __eliscript_value_121))(((items)["length"] > 1)));
940
+ })(((__eliscript_value_120) => (__eliscript_truthy(__eliscript_value_120) ? node_name(((((items) ?? [])[0]) ?? null)) : __eliscript_value_120))(symbol_node_p(((((items) ?? [])[0]) ?? null))));
941
+ })(node_items(form)) : null);
942
+ });
943
+ })();
944
+ })(new Set());
945
+ })([]);
946
+ })(portable_declarations(flattened, context));
947
+ })(flatten_modules(forms, context));
948
+ })(({"filename": filename}));
949
+ }
950
+ function analyze_module(forms, filename) {
951
+ return ((context) => {
952
+ return ((flattened) => {
953
+ return ((scope) => {
954
+ return (() => {
955
+ predeclare_top_level(flattened, scope, context);
956
+ (flattened)["forEach"]((form) => {
957
+ return analyze_top_level(form, scope, context);
958
+ });
959
+ analyze_transients(forms, filename);
960
+ validate_portable_module(flattened, context);
961
+ return forms;
962
+ })();
963
+ })(make_scope(null));
964
+ })(flatten_modules(forms, context));
965
+ })(({"filename": filename, "tailPosition": false, "recurTargets": [], "recurBarrier": false}));
966
+ }
967
+ export {analyze_module, select_portable_module};
968
+ //# sourceMappingURL=analyzer.mjs.map