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.
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,1173 @@
|
|
|
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_p, program_filename, program_body, ir_kind, ir_span, ir_value, ir_children, ir_property} from "./ir.mjs";
|
|
6
|
+
import {create_source_map} from "./source-map.mjs";
|
|
7
|
+
const literal_runtime_import = "import { hashMap as __eliscript_hash_map, hashSet as __eliscript_hash_set, keyword as __eliscript_keyword, list as __eliscript_list, queue as __eliscript_queue, symbol as __eliscript_symbol, vector as __eliscript_vector } from \"eliscript/runtime/literals.mjs\";\n";
|
|
8
|
+
const collection_runtime_import = "import { count as __eliscript_count, nth as __eliscript_nth } from \"eliscript/runtime/core/collection.mjs\";\n";
|
|
9
|
+
const list_runtime_import = "import { cons as __eliscript_cons, first as __eliscript_first, rest as __eliscript_rest } from \"eliscript/runtime/core/list.mjs\";\n";
|
|
10
|
+
const value_runtime_import = "import { equalValues as __eliscript_equal } from \"eliscript/runtime/core/value.mjs\";\n";
|
|
11
|
+
const binding_runtime = "import { get as __eliscript_get } from \"eliscript/runtime/core/collection.mjs\";\nconst __eliscript_binding_missing = Symbol(\"eliscript.binding.missing\");\nconst __eliscript_binding_get = (value, key, notFound) => { if (value == null) return notFound; const prototype = typeof value === \"object\" ? Object.getPrototypeOf(value) : undefined; if (prototype === Object.prototype || prototype === null) { const type = key && Object.getOwnPropertyDescriptor(key, Symbol.for(\"eliscript.value.type\")); if (type?.value === \"keyword\" || type?.value === \"symbol\") key = key.qualifiedName; } return __eliscript_get(value, key, notFound); };\n";
|
|
12
|
+
const host_identity_token_helper = "const __eliscript_host_identity_token = (() => { const objects = new WeakMap(); const symbols = new Map(); let next = 1; return (value) => { const type = typeof value; if ((type !== \"object\" || value === null) && type !== \"function\" && type !== \"symbol\") throw new TypeError(\"host-identity-token expects an object, function, or symbol\"); const identities = type === \"symbol\" ? symbols : objects; const cached = identities.get(value); if (cached !== undefined) return cached; if (next > Number.MAX_SAFE_INTEGER) throw new RangeError(\"host identity token space exhausted\"); const token = next; next += 1; identities.set(value, token); return token; }; })();\n";
|
|
13
|
+
const fail = (message) => { throw new Error(message); };
|
|
14
|
+
const native_locate = (span, output) => { const fragment = typeof output === "string" ? { text: output, marks: [] } : output; const marks = fragment.marks; if (fragment.text.length === 0 || span == null || span === false || (marks.length > 0 && marks[0].offset === 0)) return fragment; return { text: fragment.text, marks: [{ offset: 0, span }, ...marks] }; };
|
|
15
|
+
let temporary_counter = 0;
|
|
16
|
+
let binding_temporaries = new globalThis.Map();
|
|
17
|
+
function make_fragment(text, marks) {
|
|
18
|
+
return ({"text": text, "marks": marks});
|
|
19
|
+
}
|
|
20
|
+
function text_fragment(text) {
|
|
21
|
+
return make_fragment(text, []);
|
|
22
|
+
}
|
|
23
|
+
function as_fragment(part) {
|
|
24
|
+
return (__eliscript_truthy((typeof part === "string")) ? text_fragment(part) : part);
|
|
25
|
+
}
|
|
26
|
+
function combine(parts) {
|
|
27
|
+
return ((text, marks, part_index, fragment, offset, fragment_marks, mark_index, mark) => {
|
|
28
|
+
(() => {
|
|
29
|
+
while (__eliscript_truthy((part_index < (parts)["length"]))) {
|
|
30
|
+
((fragment = as_fragment(((((parts) ?? [])[part_index]) ?? null))));
|
|
31
|
+
((offset = (text)["length"]));
|
|
32
|
+
((fragment_marks = (fragment)["marks"]));
|
|
33
|
+
((mark_index = 0));
|
|
34
|
+
(() => {
|
|
35
|
+
while (__eliscript_truthy((mark_index < (fragment_marks)["length"]))) {
|
|
36
|
+
((mark = ((((fragment_marks) ?? [])[mark_index]) ?? null)));
|
|
37
|
+
(marks)["push"](({"offset": (offset + (mark)["offset"]), "span": (mark)["span"]}));
|
|
38
|
+
((mark_index = (mark_index + 1)));
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
})();
|
|
42
|
+
((text = (String(text) + String((fragment)["text"]))));
|
|
43
|
+
((part_index = (part_index + 1)));
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
})();
|
|
47
|
+
return make_fragment(text, marks);
|
|
48
|
+
})("", [], 0, null, 0, null, 0, null);
|
|
49
|
+
}
|
|
50
|
+
function join_fragments(parts, separator) {
|
|
51
|
+
return ((joined, index) => {
|
|
52
|
+
(() => {
|
|
53
|
+
while (__eliscript_truthy((index < (parts)["length"]))) {
|
|
54
|
+
(__eliscript_truthy((index > 0)) ? (joined)["push"](separator) : null);
|
|
55
|
+
(joined)["push"](((((parts) ?? [])[index]) ?? null));
|
|
56
|
+
((index = (index + 1)));
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
})();
|
|
60
|
+
return combine(joined);
|
|
61
|
+
})([], 0);
|
|
62
|
+
}
|
|
63
|
+
function reference_indent(fragment) {
|
|
64
|
+
return ((input) => {
|
|
65
|
+
return ((source) => {
|
|
66
|
+
return ((source_marks) => {
|
|
67
|
+
return ((text) => {
|
|
68
|
+
return ((marks) => {
|
|
69
|
+
return ((index) => {
|
|
70
|
+
return ((mark_index) => {
|
|
71
|
+
return ((line_start) => {
|
|
72
|
+
return (() => {
|
|
73
|
+
(() => {
|
|
74
|
+
while (__eliscript_truthy((index < (source)["length"]))) {
|
|
75
|
+
((code) => {
|
|
76
|
+
(__eliscript_truthy(((__eliscript_value_1) => (__eliscript_truthy(__eliscript_value_1) ? (!__eliscript_truthy((code === 10))) : __eliscript_value_1))(line_start)) ? ((text = (String(text) + String(" ")))) : null);
|
|
77
|
+
(() => {
|
|
78
|
+
while (__eliscript_truthy(((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? ((((((source_marks) ?? [])[mark_index]) ?? null))["offset"] === index) : __eliscript_value_2))((mark_index < (source_marks)["length"])))) {
|
|
79
|
+
(marks)["push"](({"offset": (text)["length"], "span": (((((source_marks) ?? [])[mark_index]) ?? null))["span"]}));
|
|
80
|
+
((mark_index = (mark_index + 1)));
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
})();
|
|
84
|
+
((text = (String(text) + String((source)["charAt"](index)))));
|
|
85
|
+
((line_start = (code === 10)));
|
|
86
|
+
return ((index = (index + 1)));
|
|
87
|
+
})((source)["charCodeAt"](index));
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
})();
|
|
91
|
+
return make_fragment(text, marks);
|
|
92
|
+
})();
|
|
93
|
+
})(true);
|
|
94
|
+
})(0);
|
|
95
|
+
})(0);
|
|
96
|
+
})([]);
|
|
97
|
+
})("");
|
|
98
|
+
})((input)["marks"]);
|
|
99
|
+
})((input)["text"]);
|
|
100
|
+
})(as_fragment(fragment));
|
|
101
|
+
}
|
|
102
|
+
function indent(fragment) {
|
|
103
|
+
return ((input) => {
|
|
104
|
+
return ((source) => {
|
|
105
|
+
return ((source_marks) => {
|
|
106
|
+
return ((text_parts) => {
|
|
107
|
+
return ((marks) => {
|
|
108
|
+
return ((source_length) => {
|
|
109
|
+
return ((output_length) => {
|
|
110
|
+
return ((source_index) => {
|
|
111
|
+
return ((mark_index) => {
|
|
112
|
+
return ((mark_count) => {
|
|
113
|
+
return (() => {
|
|
114
|
+
(() => {
|
|
115
|
+
while (__eliscript_truthy((source_index < source_length))) {
|
|
116
|
+
((newline_index) => {
|
|
117
|
+
return ((segment_end) => {
|
|
118
|
+
return ((indented) => {
|
|
119
|
+
return (() => {
|
|
120
|
+
(__eliscript_truthy(indented) ? (() => {
|
|
121
|
+
(text_parts)["push"](" ");
|
|
122
|
+
return ((output_length = (output_length + 2)));
|
|
123
|
+
})() : null);
|
|
124
|
+
(() => {
|
|
125
|
+
while (__eliscript_truthy(((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? ((((((source_marks) ?? [])[mark_index]) ?? null))["offset"] < segment_end) : __eliscript_value_4))(((((((source_marks) ?? [])[mark_index]) ?? null))["offset"] >= source_index)) : __eliscript_value_3))((mark_index < mark_count)))) {
|
|
126
|
+
((mark) => {
|
|
127
|
+
return (marks)["push"](({"offset": (output_length + ((mark)["offset"] - source_index)), "span": (mark)["span"]}));
|
|
128
|
+
})(((((source_marks) ?? [])[mark_index]) ?? null));
|
|
129
|
+
((mark_index = (mark_index + 1)));
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
})();
|
|
133
|
+
(text_parts)["push"]((source)["slice"](source_index, segment_end));
|
|
134
|
+
((output_length = (output_length + (segment_end - source_index))));
|
|
135
|
+
return ((source_index = segment_end));
|
|
136
|
+
})();
|
|
137
|
+
})((!__eliscript_truthy(((source)["charCodeAt"](source_index) === 10))));
|
|
138
|
+
})((__eliscript_truthy((newline_index === -1)) ? source_length : (newline_index + 1)));
|
|
139
|
+
})((source)["indexOf"]("\n", source_index));
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
})();
|
|
143
|
+
return make_fragment((text_parts)["join"](""), marks);
|
|
144
|
+
})();
|
|
145
|
+
})((source_marks)["length"]);
|
|
146
|
+
})(0);
|
|
147
|
+
})(0);
|
|
148
|
+
})(0);
|
|
149
|
+
})((source)["length"]);
|
|
150
|
+
})([]);
|
|
151
|
+
})([]);
|
|
152
|
+
})((input)["marks"]);
|
|
153
|
+
})((input)["text"]);
|
|
154
|
+
})(as_fragment(fragment));
|
|
155
|
+
}
|
|
156
|
+
function reference_locate(node, output) {
|
|
157
|
+
return ((fragment) => {
|
|
158
|
+
return ((marks) => {
|
|
159
|
+
return ((has_start) => {
|
|
160
|
+
return (__eliscript_truthy(((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? __eliscript_value_5 : ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_value_6 : has_start))((!__eliscript_truthy(ir_span(node))))))((((fragment)["text"])["length"] === 0))) ? fragment : ((located) => {
|
|
161
|
+
(marks)["forEach"]((mark) => {
|
|
162
|
+
return (located)["push"](mark);
|
|
163
|
+
});
|
|
164
|
+
return make_fragment((fragment)["text"], located);
|
|
165
|
+
})([({"offset": 0, "span": ir_span(node)})]));
|
|
166
|
+
})((marks)["some"]((mark) => {
|
|
167
|
+
return ((mark)["offset"] === 0);
|
|
168
|
+
}));
|
|
169
|
+
})((fragment)["marks"]);
|
|
170
|
+
})(as_fragment(output));
|
|
171
|
+
}
|
|
172
|
+
function locate(node, output) {
|
|
173
|
+
return native_locate(ir_span(node), output);
|
|
174
|
+
}
|
|
175
|
+
function fresh_name() {
|
|
176
|
+
((temporary_counter = (temporary_counter + 1)));
|
|
177
|
+
return (String("__eliscript_value_") + String(temporary_counter));
|
|
178
|
+
}
|
|
179
|
+
function json_string(value) {
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
}
|
|
182
|
+
function children(node) {
|
|
183
|
+
return ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? __eliscript_value_7 : []))(ir_children(node));
|
|
184
|
+
}
|
|
185
|
+
function require_arity(name, nodes, minimum, maximum) {
|
|
186
|
+
return ((count) => {
|
|
187
|
+
return (__eliscript_truthy(((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? __eliscript_value_8 : ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? (count > maximum) : __eliscript_value_9))(maximum)))((count < minimum))) ? ((expected, plural) => {
|
|
188
|
+
return fail((String(name) + String(" expects ") + String(expected) + String(" argument") + String(plural) + String(", got ") + String(count)));
|
|
189
|
+
})((__eliscript_truthy(((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? (minimum === maximum) : __eliscript_value_10))(maximum)) ? (String(minimum)) : (String(minimum) + String((__eliscript_truthy(maximum) ? (String("..") + String(maximum)) : "+")))), (__eliscript_truthy(((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? (minimum === 1) : __eliscript_value_12))((minimum === maximum)) : __eliscript_value_11))(maximum)) ? "" : "s")) : null);
|
|
190
|
+
})((nodes)["length"]);
|
|
191
|
+
}
|
|
192
|
+
function require_node_arity(node, minimum, maximum) {
|
|
193
|
+
return require_arity(((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? __eliscript_value_13 : ir_kind(node)))(ir_value(node)), children(node), minimum, maximum);
|
|
194
|
+
}
|
|
195
|
+
function emit_binding_name(node) {
|
|
196
|
+
return native_locate(ir_span(node), binding_name(ir_value(node)));
|
|
197
|
+
}
|
|
198
|
+
function emit_array_binding_pattern(node) {
|
|
199
|
+
return ((nodes) => {
|
|
200
|
+
return ((rest) => {
|
|
201
|
+
return ((last_index) => {
|
|
202
|
+
return ((parts) => {
|
|
203
|
+
return ((index) => {
|
|
204
|
+
return ((last_hole) => {
|
|
205
|
+
return (() => {
|
|
206
|
+
(nodes)["forEach"]((child) => {
|
|
207
|
+
((last_hole = (ir_kind(child) === "binding-hole")));
|
|
208
|
+
(parts)["push"]((__eliscript_truthy(((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? (index === last_index) : __eliscript_value_14))(rest)) ? combine(["...", emit_binding_pattern_node(child)]) : (__eliscript_truthy(last_hole) ? "" : emit_binding_pattern_node(child))));
|
|
209
|
+
return ((index = (index + 1)));
|
|
210
|
+
});
|
|
211
|
+
return native_locate(ir_span(node), combine(["[", join_fragments(parts, ", "), (__eliscript_truthy(((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? (!__eliscript_truthy(rest)) : __eliscript_value_15))(last_hole)) ? "," : ""), "]"]));
|
|
212
|
+
})();
|
|
213
|
+
})(false);
|
|
214
|
+
})(0);
|
|
215
|
+
})([]);
|
|
216
|
+
})(((nodes)["length"] - 1));
|
|
217
|
+
})(ir_property(node, "rest"));
|
|
218
|
+
})(children(node));
|
|
219
|
+
}
|
|
220
|
+
function map_binding_pattern_p(node) {
|
|
221
|
+
return ((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? (ir_kind(((((children(node)) ?? [])[0]) ?? null)) === "map-binding-pattern") : __eliscript_value_16))(ir_property(node, "pattern"));
|
|
222
|
+
}
|
|
223
|
+
function binding_temporary(node) {
|
|
224
|
+
return (__eliscript_truthy((binding_temporaries)["has"](node)) ? (binding_temporaries)["get"](node) : ((name) => {
|
|
225
|
+
(binding_temporaries)["set"](node, name);
|
|
226
|
+
return name;
|
|
227
|
+
})(fresh_name()));
|
|
228
|
+
}
|
|
229
|
+
function emit_map_binding_pattern(node, source) {
|
|
230
|
+
return ((nodes) => {
|
|
231
|
+
return ((entry_count) => {
|
|
232
|
+
return ((entries) => {
|
|
233
|
+
return ((as) => {
|
|
234
|
+
return ((parts) => {
|
|
235
|
+
return (() => {
|
|
236
|
+
(__eliscript_truthy(as) ? (parts)["push"](combine(["let ", emit_binding_name(as), " = ", source, ";"])) : null);
|
|
237
|
+
(entries)["forEach"]((entry) => {
|
|
238
|
+
return ((entry_nodes) => {
|
|
239
|
+
return ((target) => {
|
|
240
|
+
return ((key) => {
|
|
241
|
+
return ((default$) => {
|
|
242
|
+
return ((temporary) => {
|
|
243
|
+
return ((resolved) => {
|
|
244
|
+
return (() => {
|
|
245
|
+
(parts)["push"](combine(["const ", temporary, " = __eliscript_binding_get(", source, ", ", emit_expression(key), ", __eliscript_binding_missing);"]));
|
|
246
|
+
return (parts)["push"](emit_pattern_setup(target, resolved));
|
|
247
|
+
})();
|
|
248
|
+
})(combine(["(", temporary, " === __eliscript_binding_missing ? ", (__eliscript_truthy(default$) ? emit_expression(default$) : "null"), " : ", temporary, ")"]));
|
|
249
|
+
})(fresh_name());
|
|
250
|
+
})(((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? ((((entry_nodes) ?? [])[2]) ?? null) : __eliscript_value_18))(ir_property(entry, "default")));
|
|
251
|
+
})(((((entry_nodes) ?? [])[1]) ?? null));
|
|
252
|
+
})(((((entry_nodes) ?? [])[0]) ?? null));
|
|
253
|
+
})(children(entry));
|
|
254
|
+
});
|
|
255
|
+
return join_fragments(parts, "\n");
|
|
256
|
+
})();
|
|
257
|
+
})([]);
|
|
258
|
+
})(((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? ((((nodes) ?? [])[entry_count]) ?? null) : __eliscript_value_17))(ir_property(node, "as")));
|
|
259
|
+
})((nodes)["slice"](0, entry_count));
|
|
260
|
+
})(ir_property(node, "entryCount"));
|
|
261
|
+
})(children(node));
|
|
262
|
+
}
|
|
263
|
+
function emit_pattern_setup(pattern, source) {
|
|
264
|
+
return ((kind) => {
|
|
265
|
+
return (__eliscript_truthy((kind === "binding-name")) ? combine(["let ", emit_binding_name(pattern), " = ", source, ";"]) : (__eliscript_truthy((kind === "array-binding-pattern")) ? combine(["let ", emit_array_binding_pattern(pattern), " = ", source, ";"]) : (__eliscript_truthy((kind === "map-binding-pattern")) ? emit_map_binding_pattern(pattern, source) : fail((String("invalid IR binding setup node: ") + String(kind))))));
|
|
266
|
+
})(ir_kind(pattern));
|
|
267
|
+
}
|
|
268
|
+
function emit_binding_setup(binding) {
|
|
269
|
+
return (__eliscript_truthy(map_binding_pattern_p(binding)) ? emit_map_binding_pattern(((((children(binding)) ?? [])[0]) ?? null), binding_temporary(binding)) : text_fragment(""));
|
|
270
|
+
}
|
|
271
|
+
function emit_binding_setups(bindings) {
|
|
272
|
+
return ((parts) => {
|
|
273
|
+
(bindings)["forEach"]((binding) => {
|
|
274
|
+
return (__eliscript_truthy(map_binding_pattern_p(binding)) ? (parts)["push"](emit_binding_setup(binding)) : null);
|
|
275
|
+
});
|
|
276
|
+
return join_fragments(parts, "\n");
|
|
277
|
+
})([]);
|
|
278
|
+
}
|
|
279
|
+
function binding_default_value(binding) {
|
|
280
|
+
return (__eliscript_truthy(((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? (!__eliscript_truthy(map_binding_pattern_p(binding))) : __eliscript_value_19))(ir_property(binding, "pattern"))) ? "[]" : "null");
|
|
281
|
+
}
|
|
282
|
+
function emit_binding_pattern_node(node) {
|
|
283
|
+
return ((kind) => {
|
|
284
|
+
return (__eliscript_truthy((kind === "binding-name")) ? emit_binding_name(node) : (__eliscript_truthy((kind === "binding-hole")) ? "" : (__eliscript_truthy((kind === "array-binding-pattern")) ? emit_array_binding_pattern(node) : (__eliscript_truthy((kind === "map-binding-pattern")) ? fail("map binding patterns require a generated source binding") : fail((String("invalid IR binding pattern node: ") + String(kind)))))));
|
|
285
|
+
})(ir_kind(node));
|
|
286
|
+
}
|
|
287
|
+
function emit_binding_target(node) {
|
|
288
|
+
return (__eliscript_truthy(map_binding_pattern_p(node)) ? binding_temporary(node) : (__eliscript_truthy(ir_property(node, "pattern")) ? emit_binding_pattern_node(((((children(node)) ?? [])[0]) ?? null)) : emit_binding_name(node)));
|
|
289
|
+
}
|
|
290
|
+
function binding_initializer(node) {
|
|
291
|
+
return ((nodes) => {
|
|
292
|
+
return (((((__eliscript_truthy(ir_property(node, "pattern")) ? (nodes)["slice"](1) : nodes)) ?? [])[0]) ?? null);
|
|
293
|
+
})(children(node));
|
|
294
|
+
}
|
|
295
|
+
function emit_parameter(node) {
|
|
296
|
+
return ((name, kind, pattern) => {
|
|
297
|
+
return (__eliscript_truthy((kind === "optional")) ? combine([name, " = ", (__eliscript_truthy(pattern) ? binding_default_value(node) : "null")]) : (__eliscript_truthy((kind === "rest")) ? combine(["...", name]) : name));
|
|
298
|
+
})(emit_binding_target(node), ir_property(node, "parameterKind"), ir_property(node, "pattern"));
|
|
299
|
+
}
|
|
300
|
+
function emit_arguments(nodes) {
|
|
301
|
+
return join_fragments((nodes)["map"]((node) => {
|
|
302
|
+
return emit_expression(node);
|
|
303
|
+
}), ", ");
|
|
304
|
+
}
|
|
305
|
+
function emit_callee(node) {
|
|
306
|
+
return ((output) => {
|
|
307
|
+
return (__eliscript_truthy((ir_kind(node) === "reference")) ? output : combine(["(", output, ")"]));
|
|
308
|
+
})(emit_expression(node));
|
|
309
|
+
}
|
|
310
|
+
function emit_returning_body(nodes) {
|
|
311
|
+
return (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("return null;") : ((parts, index, last_index) => {
|
|
312
|
+
(() => {
|
|
313
|
+
while (__eliscript_truthy((index < last_index))) {
|
|
314
|
+
(parts)["push"](emit_expression(((((nodes) ?? [])[index]) ?? null)));
|
|
315
|
+
(parts)["push"](";\n");
|
|
316
|
+
((index = (index + 1)));
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
})();
|
|
320
|
+
(parts)["push"]("return ");
|
|
321
|
+
(parts)["push"](emit_expression(((((nodes) ?? [])[last_index]) ?? null)));
|
|
322
|
+
(parts)["push"](";");
|
|
323
|
+
return combine(parts);
|
|
324
|
+
})([], 0, ((nodes)["length"] - 1)));
|
|
325
|
+
}
|
|
326
|
+
function emit_statement_body(nodes) {
|
|
327
|
+
return ((parts) => {
|
|
328
|
+
(nodes)["forEach"]((node) => {
|
|
329
|
+
return (parts)["push"](combine([emit_expression(node), ";"]));
|
|
330
|
+
});
|
|
331
|
+
return join_fragments(parts, "\n");
|
|
332
|
+
})([]);
|
|
333
|
+
}
|
|
334
|
+
function contains_await_p(value) {
|
|
335
|
+
return ((pending, current, kind, nodes, index, found) => {
|
|
336
|
+
(() => {
|
|
337
|
+
while (__eliscript_truthy(((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? ((pending)["length"] > 0) : __eliscript_value_20))((!__eliscript_truthy(found))))) {
|
|
338
|
+
((current = (pending)["pop"]()));
|
|
339
|
+
(__eliscript_truthy(node_p(current)) ? (() => {
|
|
340
|
+
((kind = ir_kind(current)));
|
|
341
|
+
return (__eliscript_truthy((kind === "await-expression")) ? ((found = true)) : (__eliscript_truthy((!__eliscript_truthy((kind === "function-expression")))) ? (() => {
|
|
342
|
+
((nodes = children(current)));
|
|
343
|
+
((index = ((nodes)["length"] - 1)));
|
|
344
|
+
return (() => {
|
|
345
|
+
while (__eliscript_truthy((index >= 0))) {
|
|
346
|
+
(pending)["push"](((((nodes) ?? [])[index]) ?? null));
|
|
347
|
+
((index = (index - 1)));
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
})();
|
|
351
|
+
})() : null));
|
|
352
|
+
})() : (__eliscript_truthy(Array.isArray(current)) ? (() => {
|
|
353
|
+
((index = ((current)["length"] - 1)));
|
|
354
|
+
return (() => {
|
|
355
|
+
while (__eliscript_truthy((index >= 0))) {
|
|
356
|
+
(pending)["push"](((((current) ?? [])[index]) ?? null));
|
|
357
|
+
((index = (index - 1)));
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
})();
|
|
361
|
+
})() : null));
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
})();
|
|
365
|
+
return found;
|
|
366
|
+
})([value], null, null, null, 0, false);
|
|
367
|
+
}
|
|
368
|
+
function emit_iife(parameters, body, invocation, asynchronous) {
|
|
369
|
+
return (__eliscript_truthy(asynchronous) ? combine(["(await (async (", parameters, ") => {\n", body, "\n})(", invocation, "))"]) : combine(["((", parameters, ") => {\n", body, "\n})(", invocation, ")"]));
|
|
370
|
+
}
|
|
371
|
+
function emit_do(nodes) {
|
|
372
|
+
return (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("null") : (__eliscript_truthy(((nodes)["length"] === 1)) ? emit_expression(((((nodes) ?? [])[0]) ?? null)) : emit_iife("", indent(emit_returning_body(nodes)), "", contains_await_p(nodes))));
|
|
373
|
+
}
|
|
374
|
+
function split_counted_children(node, property) {
|
|
375
|
+
return ((all, count) => {
|
|
376
|
+
return [(all)["slice"](0, count), (all)["slice"](count)];
|
|
377
|
+
})(children(node), ir_property(node, property));
|
|
378
|
+
}
|
|
379
|
+
function emit_function(node) {
|
|
380
|
+
return ((parts) => {
|
|
381
|
+
return ((parameters) => {
|
|
382
|
+
return ((body) => {
|
|
383
|
+
return combine([(__eliscript_truthy(ir_property(node, "async")) ? "async " : ""), "(", join_fragments((parameters)["map"]((parameter) => {
|
|
384
|
+
return emit_parameter(parameter);
|
|
385
|
+
}), ", "), ") => {\n", indent(emit_function_body(parameters, body)), "\n}"]);
|
|
386
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
387
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
388
|
+
})(split_counted_children(node, "parameterCount"));
|
|
389
|
+
}
|
|
390
|
+
function contains_recur_target_p(value, target_kind) {
|
|
391
|
+
return ((pending, current, kind, nodes, index, found) => {
|
|
392
|
+
(() => {
|
|
393
|
+
while (__eliscript_truthy(((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? ((pending)["length"] > 0) : __eliscript_value_21))((!__eliscript_truthy(found))))) {
|
|
394
|
+
((current = (pending)["pop"]()));
|
|
395
|
+
(__eliscript_truthy(node_p(current)) ? (() => {
|
|
396
|
+
((kind = ir_kind(current)));
|
|
397
|
+
return (__eliscript_truthy((kind === "recur")) ? (__eliscript_truthy((ir_property(current, "targetKind") === target_kind)) ? ((found = true)) : null) : (__eliscript_truthy((!__eliscript_truthy((kind === "function-expression")))) ? (() => {
|
|
398
|
+
((nodes = children(current)));
|
|
399
|
+
((index = ((nodes)["length"] - 1)));
|
|
400
|
+
return (() => {
|
|
401
|
+
while (__eliscript_truthy((index >= 0))) {
|
|
402
|
+
(pending)["push"](((((nodes) ?? [])[index]) ?? null));
|
|
403
|
+
((index = (index - 1)));
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
})();
|
|
407
|
+
})() : null));
|
|
408
|
+
})() : (__eliscript_truthy(Array.isArray(current)) ? (() => {
|
|
409
|
+
((index = ((current)["length"] - 1)));
|
|
410
|
+
return (() => {
|
|
411
|
+
while (__eliscript_truthy((index >= 0))) {
|
|
412
|
+
(pending)["push"](((((current) ?? [])[index]) ?? null));
|
|
413
|
+
((index = (index - 1)));
|
|
414
|
+
}
|
|
415
|
+
return null;
|
|
416
|
+
})();
|
|
417
|
+
})() : null));
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
})();
|
|
421
|
+
return found;
|
|
422
|
+
})([value], null, null, null, 0, false);
|
|
423
|
+
}
|
|
424
|
+
function emit_rebinding_target(binding, temporary) {
|
|
425
|
+
return ((target) => {
|
|
426
|
+
return (__eliscript_truthy(ir_property(binding, "pattern")) ? combine(["(", target, " = ", temporary, ");"]) : combine([target, " = ", temporary, ";"]));
|
|
427
|
+
})(emit_binding_target(binding));
|
|
428
|
+
}
|
|
429
|
+
function emit_recur_tail(node, target) {
|
|
430
|
+
(__eliscript_truthy((!__eliscript_truthy((ir_property(node, "targetKind") === (target)["kind"])))) ? fail("recur target does not match its enclosing loop") : null);
|
|
431
|
+
return ((args, bindings, temporaries, parts, index) => {
|
|
432
|
+
(() => {
|
|
433
|
+
while (__eliscript_truthy((index < (args)["length"]))) {
|
|
434
|
+
((temporary) => {
|
|
435
|
+
(temporaries)["push"](temporary);
|
|
436
|
+
return (parts)["push"](combine(["const ", temporary, " = ", emit_expression(((((args) ?? [])[index]) ?? null)), ";"]));
|
|
437
|
+
})(fresh_name());
|
|
438
|
+
((index = (index + 1)));
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
})();
|
|
442
|
+
((index = 0));
|
|
443
|
+
(() => {
|
|
444
|
+
while (__eliscript_truthy((index < (bindings)["length"]))) {
|
|
445
|
+
(parts)["push"](emit_rebinding_target(((((bindings) ?? [])[index]) ?? null), ((((temporaries) ?? [])[index]) ?? null)));
|
|
446
|
+
((index = (index + 1)));
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
})();
|
|
450
|
+
(parts)["push"](combine(["continue ", (target)["label"], ";"]));
|
|
451
|
+
return native_locate(ir_span(node), join_fragments(parts, "\n"));
|
|
452
|
+
})(children(node), (target)["bindings"], [], [], 0);
|
|
453
|
+
}
|
|
454
|
+
function emit_tail_body(nodes, target) {
|
|
455
|
+
return (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("return null;") : ((parts, index, last_index) => {
|
|
456
|
+
(() => {
|
|
457
|
+
while (__eliscript_truthy((index < last_index))) {
|
|
458
|
+
(parts)["push"](combine([emit_expression(((((nodes) ?? [])[index]) ?? null)), ";"]));
|
|
459
|
+
((index = (index + 1)));
|
|
460
|
+
}
|
|
461
|
+
return null;
|
|
462
|
+
})();
|
|
463
|
+
(parts)["push"](emit_tail_node(((((nodes) ?? [])[last_index]) ?? null), target));
|
|
464
|
+
return join_fragments(parts, "\n");
|
|
465
|
+
})([], 0, ((nodes)["length"] - 1)));
|
|
466
|
+
}
|
|
467
|
+
function emit_tail_cond(clauses, target) {
|
|
468
|
+
return (__eliscript_truthy(((clauses)["length"] === 0)) ? text_fragment("return null;") : ((clause) => {
|
|
469
|
+
return ((nodes) => {
|
|
470
|
+
return ((test) => {
|
|
471
|
+
return ((body) => {
|
|
472
|
+
return native_locate(ir_span(clause), (__eliscript_truthy(((__eliscript_value_22) => (__eliscript_truthy(__eliscript_value_22) ? (ir_value(test) === true) : __eliscript_value_22))((ir_kind(test) === "literal"))) ? emit_tail_body(body, target) : combine(["if (__eliscript_truthy(", emit_expression(test), ")) {\n", indent(emit_tail_body(body, target)), "\n} else {\n", indent(emit_tail_cond((clauses)["slice"](1), target)), "\n}"])));
|
|
473
|
+
})((nodes)["slice"](1));
|
|
474
|
+
})(((((nodes) ?? [])[0]) ?? null));
|
|
475
|
+
})(children(clause));
|
|
476
|
+
})(((((clauses) ?? [])[0]) ?? null)));
|
|
477
|
+
}
|
|
478
|
+
function emit_tail_let(node, target) {
|
|
479
|
+
return ((parts) => {
|
|
480
|
+
return ((bindings) => {
|
|
481
|
+
return ((body) => {
|
|
482
|
+
return ((sequential) => {
|
|
483
|
+
return ((statements) => {
|
|
484
|
+
return ((temporaries) => {
|
|
485
|
+
return ((index) => {
|
|
486
|
+
return (() => {
|
|
487
|
+
(__eliscript_truthy(sequential) ? (() => {
|
|
488
|
+
while (__eliscript_truthy((index < (bindings)["length"]))) {
|
|
489
|
+
((binding) => {
|
|
490
|
+
return ((initializer) => {
|
|
491
|
+
return (() => {
|
|
492
|
+
(statements)["push"](combine(["let ", emit_binding_target(binding), " = ", (__eliscript_truthy(initializer) ? emit_expression(initializer) : binding_default_value(binding)), ";"]));
|
|
493
|
+
return (__eliscript_truthy(map_binding_pattern_p(binding)) ? (statements)["push"](emit_binding_setup(binding)) : null);
|
|
494
|
+
})();
|
|
495
|
+
})(binding_initializer(binding));
|
|
496
|
+
})(((((bindings) ?? [])[index]) ?? null));
|
|
497
|
+
((index = (index + 1)));
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
})() : (() => {
|
|
501
|
+
(() => {
|
|
502
|
+
while (__eliscript_truthy((index < (bindings)["length"]))) {
|
|
503
|
+
((binding) => {
|
|
504
|
+
return ((initializer) => {
|
|
505
|
+
return ((temporary) => {
|
|
506
|
+
return (() => {
|
|
507
|
+
(temporaries)["push"](temporary);
|
|
508
|
+
return (statements)["push"](combine(["const ", temporary, " = ", (__eliscript_truthy(initializer) ? emit_expression(initializer) : binding_default_value(binding)), ";"]));
|
|
509
|
+
})();
|
|
510
|
+
})(fresh_name());
|
|
511
|
+
})(binding_initializer(binding));
|
|
512
|
+
})(((((bindings) ?? [])[index]) ?? null));
|
|
513
|
+
((index = (index + 1)));
|
|
514
|
+
}
|
|
515
|
+
return null;
|
|
516
|
+
})();
|
|
517
|
+
((index = 0));
|
|
518
|
+
return (() => {
|
|
519
|
+
while (__eliscript_truthy((index < (bindings)["length"]))) {
|
|
520
|
+
(statements)["push"](combine(["let ", emit_binding_target(((((bindings) ?? [])[index]) ?? null)), " = ", ((((temporaries) ?? [])[index]) ?? null), ";"]));
|
|
521
|
+
(__eliscript_truthy(map_binding_pattern_p(((((bindings) ?? [])[index]) ?? null))) ? (statements)["push"](emit_binding_setup(((((bindings) ?? [])[index]) ?? null))) : null);
|
|
522
|
+
((index = (index + 1)));
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
})();
|
|
526
|
+
})());
|
|
527
|
+
(statements)["push"](emit_tail_body(body, target));
|
|
528
|
+
return native_locate(ir_span(node), combine(["{\n", indent(join_fragments(statements, "\n")), "\n}"]));
|
|
529
|
+
})();
|
|
530
|
+
})(0);
|
|
531
|
+
})([]);
|
|
532
|
+
})([]);
|
|
533
|
+
})(ir_property(node, "sequential"));
|
|
534
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
535
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
536
|
+
})(split_counted_children(node, "bindingCount"));
|
|
537
|
+
}
|
|
538
|
+
function emit_tail_short_circuit(nodes, kind, target) {
|
|
539
|
+
return (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment((__eliscript_truthy((kind === "and")) ? "return true;" : "return null;")) : (__eliscript_truthy(((nodes)["length"] === 1)) ? emit_tail_node(((((nodes) ?? [])[0]) ?? null), target) : ((temporary) => {
|
|
540
|
+
return ((first) => {
|
|
541
|
+
return ((rest) => {
|
|
542
|
+
return ((truthy) => {
|
|
543
|
+
return ((falsey) => {
|
|
544
|
+
return combine(["const ", temporary, " = ", first, ";\n", "if (__eliscript_truthy(", temporary, ")) {\n", indent(truthy), "\n} else {\n", indent(falsey), "\n}"]);
|
|
545
|
+
})((__eliscript_truthy((kind === "and")) ? combine(["return ", temporary, ";"]) : emit_tail_short_circuit(rest, kind, target)));
|
|
546
|
+
})((__eliscript_truthy((kind === "and")) ? emit_tail_short_circuit(rest, kind, target) : combine(["return ", temporary, ";"])));
|
|
547
|
+
})((nodes)["slice"](1));
|
|
548
|
+
})(emit_expression(((((nodes) ?? [])[0]) ?? null)));
|
|
549
|
+
})(fresh_name())));
|
|
550
|
+
}
|
|
551
|
+
function emit_tail_node(node, target) {
|
|
552
|
+
return ((kind, nodes) => {
|
|
553
|
+
return (__eliscript_truthy((kind === "recur")) ? emit_recur_tail(node, target) : (__eliscript_truthy((kind === "conditional")) ? combine(["if (__eliscript_truthy(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")) {\n", indent(emit_tail_node(((((nodes) ?? [])[1]) ?? null), target)), "\n} else {\n", indent((__eliscript_truthy(((nodes)["length"] > 2)) ? emit_tail_node(((((nodes) ?? [])[2]) ?? null), target) : text_fragment("return null;"))), "\n}"]) : (__eliscript_truthy((kind === "conditional-sugar")) ? combine(["if (", (__eliscript_truthy((ir_value(node) === "when")) ? "" : "!"), "__eliscript_truthy(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")) {\n", indent(emit_tail_body((nodes)["slice"](1), target)), "\n} else {\n return null;\n}"]) : (__eliscript_truthy((kind === "conditional-chain")) ? emit_tail_cond(nodes, target) : (__eliscript_truthy((kind === "sequence")) ? emit_tail_body(nodes, target) : (__eliscript_truthy((kind === "lexical-bindings")) ? emit_tail_let(node, target) : (__eliscript_truthy((kind === "short-circuit")) ? emit_tail_short_circuit(nodes, ir_value(node), target) : combine(["return ", emit_expression(node), ";"]))))))));
|
|
554
|
+
})(ir_kind(node), children(node));
|
|
555
|
+
}
|
|
556
|
+
function emit_function_body(parameters, body) {
|
|
557
|
+
return ((setups) => {
|
|
558
|
+
return (__eliscript_truthy((!__eliscript_truthy(contains_recur_target_p(body, "function")))) ? (__eliscript_truthy((((setups)["text"])["length"] === 0)) ? emit_returning_body(body) : combine([setups, "\n", emit_returning_body(body)])) : ((label) => {
|
|
559
|
+
return ((target) => {
|
|
560
|
+
return combine([label, ": while (true) {\n", indent((__eliscript_truthy((((setups)["text"])["length"] === 0)) ? emit_tail_body(body, target) : combine([setups, "\n", emit_tail_body(body, target)]))), "\n}"]);
|
|
561
|
+
})(({"kind": "function", "bindings": parameters, "label": label}));
|
|
562
|
+
})(fresh_name()));
|
|
563
|
+
})(emit_binding_setups(parameters));
|
|
564
|
+
}
|
|
565
|
+
function emit_if(nodes) {
|
|
566
|
+
return combine(["(__eliscript_truthy(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ") ? ", emit_expression(((((nodes) ?? [])[1]) ?? null)), " : ", (__eliscript_truthy(((nodes)["length"] > 2)) ? emit_expression(((((nodes) ?? [])[2]) ?? null)) : "null"), ")"]);
|
|
567
|
+
}
|
|
568
|
+
function emit_conditional_sugar(node) {
|
|
569
|
+
return ((nodes) => {
|
|
570
|
+
return ((test) => {
|
|
571
|
+
return ((body) => {
|
|
572
|
+
return (__eliscript_truthy((ir_value(node) === "when")) ? combine(["(__eliscript_truthy(", test, ") ? ", body, " : null)"]) : combine(["(__eliscript_truthy((!__eliscript_truthy(", test, "))) ? ", body, " : null)"]));
|
|
573
|
+
})(emit_do((nodes)["slice"](1)));
|
|
574
|
+
})(emit_expression(((((nodes) ?? [])[0]) ?? null)));
|
|
575
|
+
})(children(node));
|
|
576
|
+
}
|
|
577
|
+
function emit_cond(clauses) {
|
|
578
|
+
return (__eliscript_truthy(((clauses)["length"] === 0)) ? text_fragment("null") : ((clause) => {
|
|
579
|
+
return ((nodes) => {
|
|
580
|
+
return ((test) => {
|
|
581
|
+
return ((body) => {
|
|
582
|
+
return native_locate(ir_span(clause), (__eliscript_truthy(((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? (ir_value(test) === true) : __eliscript_value_23))((ir_kind(test) === "literal"))) ? emit_do(body) : combine(["(__eliscript_truthy(", emit_expression(test), ") ? ", emit_do(body), " : ", emit_cond((clauses)["slice"](1)), ")"])));
|
|
583
|
+
})((nodes)["slice"](1));
|
|
584
|
+
})(((((nodes) ?? [])[0]) ?? null));
|
|
585
|
+
})(children(clause));
|
|
586
|
+
})(((((clauses) ?? [])[0]) ?? null)));
|
|
587
|
+
}
|
|
588
|
+
function emit_throw(node) {
|
|
589
|
+
return ((temporary) => {
|
|
590
|
+
return combine(["((", temporary, ") => { throw ", temporary, "; })(", emit_expression(((((children(node)) ?? [])[0]) ?? null)), ")"]);
|
|
591
|
+
})(fresh_name());
|
|
592
|
+
}
|
|
593
|
+
function emit_catch(node) {
|
|
594
|
+
return ((nodes) => {
|
|
595
|
+
return ((binding) => {
|
|
596
|
+
return ((body) => {
|
|
597
|
+
return native_locate(ir_span(node), combine([" catch (", emit_binding_target(binding), ") {\n", indent((__eliscript_truthy(map_binding_pattern_p(binding)) ? combine([emit_binding_setup(binding), "\n", emit_returning_body(body)]) : emit_returning_body(body))), "\n}"]));
|
|
598
|
+
})((nodes)["slice"](1));
|
|
599
|
+
})(((((nodes) ?? [])[0]) ?? null));
|
|
600
|
+
})(children(node));
|
|
601
|
+
}
|
|
602
|
+
function emit_finally(node) {
|
|
603
|
+
return native_locate(ir_span(node), combine([" finally {\n", indent(emit_statement_body(children(node))), "\n}"]));
|
|
604
|
+
}
|
|
605
|
+
function emit_try(node) {
|
|
606
|
+
return ((parts) => {
|
|
607
|
+
return ((body) => {
|
|
608
|
+
return ((clauses) => {
|
|
609
|
+
return ((catch_clause) => {
|
|
610
|
+
return ((finally_clause) => {
|
|
611
|
+
return ((try_block) => {
|
|
612
|
+
return emit_iife("", indent(try_block), "", contains_await_p(node));
|
|
613
|
+
})(combine(["try {\n", indent(emit_returning_body(body)), "\n}", (__eliscript_truthy(catch_clause) ? emit_catch(catch_clause) : ""), (__eliscript_truthy(finally_clause) ? emit_finally(finally_clause) : "")]));
|
|
614
|
+
})((clauses)["find"]((clause) => {
|
|
615
|
+
return (ir_kind(clause) === "finally-clause");
|
|
616
|
+
}));
|
|
617
|
+
})((clauses)["find"]((clause) => {
|
|
618
|
+
return (ir_kind(clause) === "catch-clause");
|
|
619
|
+
}));
|
|
620
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
621
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
622
|
+
})(split_counted_children(node, "bodyCount"));
|
|
623
|
+
}
|
|
624
|
+
function emit_binding_values(bindings) {
|
|
625
|
+
return ((result) => {
|
|
626
|
+
(bindings)["forEach"]((binding) => {
|
|
627
|
+
return ((initializer) => {
|
|
628
|
+
return (result)["push"]((__eliscript_truthy(initializer) ? emit_expression(initializer) : binding_default_value(binding)));
|
|
629
|
+
})(binding_initializer(binding));
|
|
630
|
+
});
|
|
631
|
+
return result;
|
|
632
|
+
})([]);
|
|
633
|
+
}
|
|
634
|
+
function emit_parallel_let(bindings, body) {
|
|
635
|
+
return ((names) => {
|
|
636
|
+
return ((values) => {
|
|
637
|
+
return ((setups) => {
|
|
638
|
+
return ((body_output) => {
|
|
639
|
+
return emit_iife(names, body_output, values, contains_await_p(body));
|
|
640
|
+
})(indent((__eliscript_truthy((((setups)["text"])["length"] === 0)) ? emit_returning_body(body) : combine([setups, "\n", emit_returning_body(body)]))));
|
|
641
|
+
})(emit_binding_setups(bindings));
|
|
642
|
+
})(join_fragments(emit_binding_values(bindings), ", "));
|
|
643
|
+
})(join_fragments((bindings)["map"]((binding) => {
|
|
644
|
+
return emit_binding_target(binding);
|
|
645
|
+
}), ", "));
|
|
646
|
+
}
|
|
647
|
+
function emit_sequential_let(bindings, body) {
|
|
648
|
+
return (__eliscript_truthy(((bindings)["length"] === 0)) ? emit_do(body) : ((binding) => {
|
|
649
|
+
return ((name) => {
|
|
650
|
+
return ((initializer) => {
|
|
651
|
+
return ((tail) => {
|
|
652
|
+
return emit_iife(name, indent(combine([(__eliscript_truthy(map_binding_pattern_p(binding)) ? combine([emit_binding_setup(binding), "\n"]) : ""), "return ", tail, ";"])), initializer, ((__eliscript_value_24) => (__eliscript_truthy(__eliscript_value_24) ? __eliscript_value_24 : contains_await_p(body)))(contains_await_p((bindings)["slice"](1))));
|
|
653
|
+
})(emit_sequential_let((bindings)["slice"](1), body));
|
|
654
|
+
})(((((emit_binding_values([binding])) ?? [])[0]) ?? null));
|
|
655
|
+
})(emit_binding_target(binding));
|
|
656
|
+
})(((((bindings) ?? [])[0]) ?? null)));
|
|
657
|
+
}
|
|
658
|
+
function emit_let(node) {
|
|
659
|
+
return ((parts) => {
|
|
660
|
+
return ((bindings) => {
|
|
661
|
+
return ((body) => {
|
|
662
|
+
return (__eliscript_truthy(ir_property(node, "sequential")) ? emit_sequential_let(bindings, body) : emit_parallel_let(bindings, body));
|
|
663
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
664
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
665
|
+
})(split_counted_children(node, "bindingCount"));
|
|
666
|
+
}
|
|
667
|
+
function emit_assignment(node) {
|
|
668
|
+
return ((assignments) => {
|
|
669
|
+
(children(node))["forEach"]((pair) => {
|
|
670
|
+
return (assignments)["push"](native_locate(ir_span(pair), combine(["(", emit_binding_name(pair), " = ", emit_expression(((((children(pair)) ?? [])[0]) ?? null)), ")"])));
|
|
671
|
+
});
|
|
672
|
+
return (__eliscript_truthy((ir_value(node) === "set!")) ? ((((assignments) ?? [])[0]) ?? null) : combine(["(", join_fragments(assignments, ", "), ")"]));
|
|
673
|
+
})([]);
|
|
674
|
+
}
|
|
675
|
+
function emit_loop(node) {
|
|
676
|
+
return ((nodes) => {
|
|
677
|
+
return ((test) => {
|
|
678
|
+
return ((body) => {
|
|
679
|
+
return ((test_output) => {
|
|
680
|
+
return ((statements) => {
|
|
681
|
+
return (() => {
|
|
682
|
+
(body)["forEach"]((child) => {
|
|
683
|
+
return (statements)["push"](combine([emit_expression(child), ";"]));
|
|
684
|
+
});
|
|
685
|
+
return emit_iife("", indent(combine(["while (__eliscript_truthy(", test_output, ")) {\n", indent(join_fragments(statements, "\n")), "\n}\nreturn null;"])), "", contains_await_p(nodes));
|
|
686
|
+
})();
|
|
687
|
+
})([]);
|
|
688
|
+
})(emit_expression(test));
|
|
689
|
+
})((nodes)["slice"](1));
|
|
690
|
+
})(((((nodes) ?? [])[0]) ?? null));
|
|
691
|
+
})(children(node));
|
|
692
|
+
}
|
|
693
|
+
function emit_binding_loop(node) {
|
|
694
|
+
return ((parts) => {
|
|
695
|
+
return ((bindings) => {
|
|
696
|
+
return ((body) => {
|
|
697
|
+
return ((label) => {
|
|
698
|
+
return ((target) => {
|
|
699
|
+
return ((parameters) => {
|
|
700
|
+
return ((initializers) => {
|
|
701
|
+
return ((setups) => {
|
|
702
|
+
return emit_iife(parameters, indent(combine([label, ": while (true) {\n", indent((__eliscript_truthy((((setups)["text"])["length"] === 0)) ? emit_tail_body(body, target) : combine([setups, "\n", emit_tail_body(body, target)]))), "\n}"])), initializers, contains_await_p(body));
|
|
703
|
+
})(emit_binding_setups(bindings));
|
|
704
|
+
})(join_fragments((bindings)["map"]((binding) => {
|
|
705
|
+
return emit_expression(binding_initializer(binding));
|
|
706
|
+
}), ", "));
|
|
707
|
+
})(join_fragments((bindings)["map"]((binding) => {
|
|
708
|
+
return emit_binding_target(binding);
|
|
709
|
+
}), ", "));
|
|
710
|
+
})(({"kind": "loop", "bindings": bindings, "label": label}));
|
|
711
|
+
})(fresh_name());
|
|
712
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
713
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
714
|
+
})(split_counted_children(node, "bindingCount"));
|
|
715
|
+
}
|
|
716
|
+
function emit_short_circuit(nodes, kind) {
|
|
717
|
+
return (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment((__eliscript_truthy((kind === "and")) ? "true" : "null")) : (__eliscript_truthy(((nodes)["length"] === 1)) ? emit_expression(((((nodes) ?? [])[0]) ?? null)) : ((temporary, first, rest) => {
|
|
718
|
+
return ((body) => {
|
|
719
|
+
return (__eliscript_truthy(contains_await_p((nodes)["slice"](1))) ? combine(["(await (async (", temporary, ") => ", body, ")(", first, "))"]) : combine(["((", temporary, ") => ", body, ")(", first, ")"]));
|
|
720
|
+
})(combine(["(__eliscript_truthy(", temporary, ") ? ", (__eliscript_truthy((kind === "and")) ? rest : temporary), " : ", (__eliscript_truthy((kind === "and")) ? temporary : rest), ")"]));
|
|
721
|
+
})(fresh_name(), emit_expression(((((nodes) ?? [])[0]) ?? null)), emit_short_circuit((nodes)["slice"](1), kind))));
|
|
722
|
+
}
|
|
723
|
+
function emit_infix(name, nodes, operator, minimum) {
|
|
724
|
+
require_arity(name, nodes, minimum, null);
|
|
725
|
+
return combine(["(", join_fragments((nodes)["map"]((node) => {
|
|
726
|
+
return emit_expression(node);
|
|
727
|
+
}), (String(" ") + String(operator) + String(" "))), ")"]);
|
|
728
|
+
}
|
|
729
|
+
function emit_binary_infix(name, nodes, operator) {
|
|
730
|
+
require_arity(name, nodes, 2, 2);
|
|
731
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " ", operator, " ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
732
|
+
}
|
|
733
|
+
function temporary_names(nodes) {
|
|
734
|
+
return ((result) => {
|
|
735
|
+
(nodes)["forEach"]((_node) => {
|
|
736
|
+
return (result)["push"](fresh_name());
|
|
737
|
+
});
|
|
738
|
+
return result;
|
|
739
|
+
})([]);
|
|
740
|
+
}
|
|
741
|
+
function emit_comparison(name, nodes, operator) {
|
|
742
|
+
require_arity(name, nodes, 2, null);
|
|
743
|
+
return (__eliscript_truthy(((nodes)["length"] === 2)) ? combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " ", operator, " ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]) : ((parameters, comparisons, index) => {
|
|
744
|
+
(() => {
|
|
745
|
+
while (__eliscript_truthy((index < ((parameters)["length"] - 1)))) {
|
|
746
|
+
(comparisons)["push"]((String(((((parameters) ?? [])[index]) ?? null)) + String(" ") + String(operator) + String(" ") + String(((((parameters) ?? [])[(index + 1)]) ?? null))));
|
|
747
|
+
((index = (index + 1)));
|
|
748
|
+
}
|
|
749
|
+
return null;
|
|
750
|
+
})();
|
|
751
|
+
return combine(["((", (parameters)["join"](", "), ") => (", (comparisons)["join"](" && "), "))(", emit_arguments(nodes), ")"]);
|
|
752
|
+
})(temporary_names(nodes), [], 0));
|
|
753
|
+
}
|
|
754
|
+
function emit_distinct(name, nodes) {
|
|
755
|
+
require_arity(name, nodes, 2, null);
|
|
756
|
+
return ((parameters, comparisons, left) => {
|
|
757
|
+
(() => {
|
|
758
|
+
while (__eliscript_truthy((left < (parameters)["length"]))) {
|
|
759
|
+
((right) => {
|
|
760
|
+
return (() => {
|
|
761
|
+
while (__eliscript_truthy((right < (parameters)["length"]))) {
|
|
762
|
+
(comparisons)["push"]((String(((((parameters) ?? [])[left]) ?? null)) + String(" !== ") + String(((((parameters) ?? [])[right]) ?? null))));
|
|
763
|
+
((right = (right + 1)));
|
|
764
|
+
}
|
|
765
|
+
return null;
|
|
766
|
+
})();
|
|
767
|
+
})((left + 1));
|
|
768
|
+
((left = (left + 1)));
|
|
769
|
+
}
|
|
770
|
+
return null;
|
|
771
|
+
})();
|
|
772
|
+
return combine(["((", (parameters)["join"](", "), ") => (", (comparisons)["join"](" && "), "))(", emit_arguments(nodes), ")"]);
|
|
773
|
+
})(temporary_names(nodes), [], 0);
|
|
774
|
+
}
|
|
775
|
+
function emit_intrinsic(node) {
|
|
776
|
+
return ((name, nodes) => {
|
|
777
|
+
return (__eliscript_truthy((name === "not")) ? (() => {
|
|
778
|
+
require_node_arity(node, 1, 1);
|
|
779
|
+
return combine(["(!__eliscript_truthy(", emit_expression(((((nodes) ?? [])[0]) ?? null)), "))"]);
|
|
780
|
+
})() : (__eliscript_truthy((name === "+")) ? (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("0") : combine(["(", join_fragments((nodes)["map"]((node) => {
|
|
781
|
+
return emit_expression(node);
|
|
782
|
+
}), " + "), ")"])) : (__eliscript_truthy((name === "*")) ? (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("1") : combine(["(", join_fragments((nodes)["map"]((node) => {
|
|
783
|
+
return emit_expression(node);
|
|
784
|
+
}), " * "), ")"])) : (__eliscript_truthy((name === "-")) ? (() => {
|
|
785
|
+
require_node_arity(node, 1, null);
|
|
786
|
+
return (__eliscript_truthy(((nodes)["length"] === 1)) ? combine(["(-", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]) : emit_infix("-", nodes, "-", 2));
|
|
787
|
+
})() : (__eliscript_truthy((name === "/")) ? (() => {
|
|
788
|
+
require_node_arity(node, 1, null);
|
|
789
|
+
return (__eliscript_truthy(((nodes)["length"] === 1)) ? combine(["(1 / ", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]) : emit_infix("/", nodes, "/", 2));
|
|
790
|
+
})() : (__eliscript_truthy(((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? __eliscript_value_25 : (name === "mod")))((name === "%"))) ? emit_infix(name, nodes, "%", 2) : (__eliscript_truthy((name === "int32")) ? (() => {
|
|
791
|
+
require_node_arity(node, 1, 1);
|
|
792
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " | 0)"]);
|
|
793
|
+
})() : (__eliscript_truthy((name === "uint32")) ? (() => {
|
|
794
|
+
require_node_arity(node, 1, 1);
|
|
795
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " >>> 0)"]);
|
|
796
|
+
})() : (__eliscript_truthy((name === "imul32")) ? (() => {
|
|
797
|
+
require_node_arity(node, 2, 2);
|
|
798
|
+
return combine(["Math.imul(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
799
|
+
})() : (__eliscript_truthy((name === "bit-and")) ? emit_binary_infix(name, nodes, "&") : (__eliscript_truthy((name === "bit-or")) ? emit_binary_infix(name, nodes, "|") : (__eliscript_truthy((name === "bit-xor")) ? emit_binary_infix(name, nodes, "^") : (__eliscript_truthy((name === "bit-not")) ? (() => {
|
|
800
|
+
require_node_arity(node, 1, 1);
|
|
801
|
+
return combine(["(~", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
802
|
+
})() : (__eliscript_truthy((name === "bit-shift-left")) ? emit_binary_infix(name, nodes, "<<") : (__eliscript_truthy((name === "bit-shift-right")) ? emit_binary_infix(name, nodes, ">>") : (__eliscript_truthy((name === "unsigned-bit-shift-right")) ? emit_binary_infix(name, nodes, ">>>") : (__eliscript_truthy((name === "value-type")) ? (() => {
|
|
803
|
+
require_node_arity(node, 1, 1);
|
|
804
|
+
return combine(["((__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; } })(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
805
|
+
})() : (__eliscript_truthy((name === "host-identity-token")) ? (() => {
|
|
806
|
+
require_node_arity(node, 1, 1);
|
|
807
|
+
return combine(["__eliscript_host_identity_token(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
808
|
+
})() : (__eliscript_truthy((name === "string-code-unit-at")) ? (() => {
|
|
809
|
+
require_node_arity(node, 2, 2);
|
|
810
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ").charCodeAt(", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
811
|
+
})() : (__eliscript_truthy((name === "string-from-code-unit")) ? (() => {
|
|
812
|
+
require_node_arity(node, 1, 1);
|
|
813
|
+
return combine(["String.fromCharCode(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
814
|
+
})() : (__eliscript_truthy((name === "string-to-number")) ? (() => {
|
|
815
|
+
require_node_arity(node, 1, 1);
|
|
816
|
+
return combine(["Number(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
817
|
+
})() : (__eliscript_truthy((name === "string-to-bigint")) ? (() => {
|
|
818
|
+
require_node_arity(node, 1, 1);
|
|
819
|
+
return combine(["((__eliscript_text) => { try { return BigInt(__eliscript_text); } catch { return null; } })(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
820
|
+
})() : (__eliscript_truthy((name === "number-float64-words")) ? (() => {
|
|
821
|
+
require_node_arity(node, 1, 1);
|
|
822
|
+
return combine(["((__eliscript_number) => { const __eliscript_bytes = new DataView(new ArrayBuffer(8)); __eliscript_bytes.setFloat64(0, __eliscript_number === 0 ? 0 : __eliscript_number, true); return [__eliscript_bytes.getUint32(0, true), __eliscript_bytes.getUint32(4, true)]; })(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
823
|
+
})() : (__eliscript_truthy((name === "=")) ? emit_comparison(name, nodes, "===") : (__eliscript_truthy(((__eliscript_value_26) => (__eliscript_truthy(__eliscript_value_26) ? __eliscript_value_26 : (name === "not=")))((name === "/="))) ? emit_distinct(name, nodes) : (__eliscript_truthy((name === "<")) ? emit_comparison(name, nodes, "<") : (__eliscript_truthy((name === "<=")) ? emit_comparison(name, nodes, "<=") : (__eliscript_truthy((name === ">")) ? emit_comparison(name, nodes, ">") : (__eliscript_truthy((name === ">=")) ? emit_comparison(name, nodes, ">=") : (__eliscript_truthy((name === "1+")) ? (() => {
|
|
824
|
+
require_node_arity(node, 1, 1);
|
|
825
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " + 1)"]);
|
|
826
|
+
})() : (__eliscript_truthy((name === "1-")) ? (() => {
|
|
827
|
+
require_node_arity(node, 1, 1);
|
|
828
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " - 1)"]);
|
|
829
|
+
})() : (__eliscript_truthy((name === "eq")) ? (() => {
|
|
830
|
+
require_node_arity(node, 2, 2);
|
|
831
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " === ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
832
|
+
})() : (__eliscript_truthy((name === "equal")) ? (() => {
|
|
833
|
+
require_node_arity(node, 2, 2);
|
|
834
|
+
return combine(["__eliscript_equal(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
835
|
+
})() : (__eliscript_truthy((name === "nil?")) ? (() => {
|
|
836
|
+
require_node_arity(node, 1, 1);
|
|
837
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " === null)"]);
|
|
838
|
+
})() : (__eliscript_truthy((name === "undefined?")) ? (() => {
|
|
839
|
+
require_node_arity(node, 1, 1);
|
|
840
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " === undefined)"]);
|
|
841
|
+
})() : (__eliscript_truthy(((__eliscript_value_27) => (__eliscript_truthy(__eliscript_value_27) ? __eliscript_value_27 : (name === "nullish?")))((name === "null"))) ? (() => {
|
|
842
|
+
require_node_arity(node, 1, 1);
|
|
843
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), " == null)"]);
|
|
844
|
+
})() : (__eliscript_truthy((name === "js-array")) ? combine(["[", emit_arguments(nodes), "]"]) : (__eliscript_truthy((name === "car")) ? (() => {
|
|
845
|
+
require_node_arity(node, 1, 1);
|
|
846
|
+
return combine(["__eliscript_first(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
847
|
+
})() : (__eliscript_truthy((name === "cdr")) ? (() => {
|
|
848
|
+
require_node_arity(node, 1, 1);
|
|
849
|
+
return combine(["__eliscript_rest(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
850
|
+
})() : (__eliscript_truthy((name === "cons")) ? (() => {
|
|
851
|
+
require_node_arity(node, 2, 2);
|
|
852
|
+
return combine(["__eliscript_cons(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
853
|
+
})() : (__eliscript_truthy((name === "js-cons")) ? (() => {
|
|
854
|
+
require_node_arity(node, 2, 2);
|
|
855
|
+
return combine(["[", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", ...((", emit_expression(((((nodes) ?? [])[1]) ?? null)), ") ?? [])]"]);
|
|
856
|
+
})() : (__eliscript_truthy((name === "nth")) ? (() => {
|
|
857
|
+
require_node_arity(node, 2, 2);
|
|
858
|
+
return combine(["__eliscript_nth(", emit_expression(((((nodes) ?? [])[1]) ?? null)), ", ", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", null)"]);
|
|
859
|
+
})() : (__eliscript_truthy((name === "js-nth")) ? (() => {
|
|
860
|
+
require_node_arity(node, 2, 2);
|
|
861
|
+
return combine(["((((", emit_expression(((((nodes) ?? [])[1]) ?? null)), ") ?? [])[", emit_expression(((((nodes) ?? [])[0]) ?? null)), "]) ?? null)"]);
|
|
862
|
+
})() : (__eliscript_truthy((name === "aref")) ? (() => {
|
|
863
|
+
require_node_arity(node, 2, 2);
|
|
864
|
+
return combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")[", emit_property_key(((((nodes) ?? [])[1]) ?? null)), "]"]);
|
|
865
|
+
})() : (__eliscript_truthy((name === "length")) ? (() => {
|
|
866
|
+
require_node_arity(node, 1, 1);
|
|
867
|
+
return combine(["__eliscript_count(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]);
|
|
868
|
+
})() : (__eliscript_truthy((name === "js-length")) ? (() => {
|
|
869
|
+
require_node_arity(node, 1, 1);
|
|
870
|
+
return combine(["((", emit_expression(((((nodes) ?? [])[0]) ?? null)), ") ?? []).length"]);
|
|
871
|
+
})() : (__eliscript_truthy((name === "__eliscript_arity_error")) ? (() => {
|
|
872
|
+
require_node_arity(node, 2, 2);
|
|
873
|
+
return combine(["((label, arity) => { throw new TypeError(label + \" received unsupported arity: \" + arity); })(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ", ", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
874
|
+
})() : (__eliscript_truthy((name === "object-keys")) ? (() => {
|
|
875
|
+
require_node_arity(node, 1, 1);
|
|
876
|
+
return combine(["Object.keys((", emit_expression(((((nodes) ?? [])[0]) ?? null)), ") ?? {})"]);
|
|
877
|
+
})() : (__eliscript_truthy((name === "object-has?")) ? (() => {
|
|
878
|
+
require_node_arity(node, 2, 2);
|
|
879
|
+
return combine(["Object.prototype.hasOwnProperty.call((", emit_expression(((((nodes) ?? [])[0]) ?? null)), ") ?? {}, ", emit_property_key(((((nodes) ?? [])[1]) ?? null)), ")"]);
|
|
880
|
+
})() : (__eliscript_truthy((name === "object-assoc")) ? (() => {
|
|
881
|
+
require_node_arity(node, 3, 3);
|
|
882
|
+
return combine(["({...((", emit_expression(((((nodes) ?? [])[0]) ?? null)), ") ?? {}), [", emit_property_key(((((nodes) ?? [])[1]) ?? null)), "]: ", emit_expression(((((nodes) ?? [])[2]) ?? null)), "})"]);
|
|
883
|
+
})() : fail((String("unknown IR intrinsic: ") + String(name)))))))))))))))))))))))))))))))))))))))))))))))))))));
|
|
884
|
+
})(ir_value(node), children(node));
|
|
885
|
+
}
|
|
886
|
+
function emit_object_properties(properties) {
|
|
887
|
+
return ((result) => {
|
|
888
|
+
(properties)["forEach"]((property) => {
|
|
889
|
+
return ((nodes) => {
|
|
890
|
+
return (result)["push"](native_locate(ir_span(property), (__eliscript_truthy(ir_property(property, "computed")) ? combine(["[", emit_expression(((((nodes) ?? [])[0]) ?? null)), "]: ", emit_expression(((((nodes) ?? [])[1]) ?? null))]) : combine([json_string(ir_value(property)), ": ", emit_expression(((((nodes) ?? [])[0]) ?? null))]))));
|
|
891
|
+
})(children(property));
|
|
892
|
+
});
|
|
893
|
+
return join_fragments(result, ", ");
|
|
894
|
+
})([]);
|
|
895
|
+
}
|
|
896
|
+
function emit_object(node) {
|
|
897
|
+
return combine(["({", emit_object_properties(children(node)), "})"]);
|
|
898
|
+
}
|
|
899
|
+
function literal_kind(node) {
|
|
900
|
+
return ir_property(node, "literalKind");
|
|
901
|
+
}
|
|
902
|
+
function emit_literal(node) {
|
|
903
|
+
return ((value, kind) => {
|
|
904
|
+
return (__eliscript_truthy((kind === "undefined")) ? text_fragment("undefined") : (__eliscript_truthy((kind === "keyword")) ? combine(["__eliscript_keyword(", json_string(value), ")"]) : (__eliscript_truthy((value == null)) ? text_fragment("null") : (__eliscript_truthy((value === true)) ? text_fragment("true") : (__eliscript_truthy((value === false)) ? text_fragment("false") : (__eliscript_truthy((typeof value === "number")) ? (() => {
|
|
905
|
+
(__eliscript_truthy((!__eliscript_truthy(Number.isFinite(value)))) ? fail((String("non-finite numbers are not supported: ") + String(value))) : null);
|
|
906
|
+
return text_fragment((String(value)));
|
|
907
|
+
})() : (__eliscript_truthy((typeof value === "string")) ? text_fragment(json_string(value)) : fail((String("unsupported IR literal: ") + String(value))))))))));
|
|
908
|
+
})(ir_value(node), literal_kind(node));
|
|
909
|
+
}
|
|
910
|
+
function datum_kind(value) {
|
|
911
|
+
return ((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? ((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? (value)["kind"] : __eliscript_value_29))((typeof value === "object")) : __eliscript_value_28))(value);
|
|
912
|
+
}
|
|
913
|
+
function emit_quoted(value) {
|
|
914
|
+
return ((kind) => {
|
|
915
|
+
return (__eliscript_truthy((value == null)) ? text_fragment("__eliscript_list()") : (__eliscript_truthy((value === true)) ? text_fragment("true") : (__eliscript_truthy((value === false)) ? text_fragment("__eliscript_symbol(\"false\")") : (__eliscript_truthy((typeof value === "number")) ? text_fragment((String(value))) : (__eliscript_truthy((typeof value === "string")) ? text_fragment(json_string(value)) : (__eliscript_truthy((kind === "undefined")) ? text_fragment("undefined") : (__eliscript_truthy((kind === "symbol")) ? combine(["__eliscript_symbol(", text_fragment(json_string((value)["name"])), ")"]) : (__eliscript_truthy((kind === "keyword")) ? combine(["__eliscript_keyword(", text_fragment(json_string((value)["name"])), ")"]) : (__eliscript_truthy((kind === "list")) ? combine(["__eliscript_list(", join_fragments(((value)["items"])["map"]((item) => {
|
|
916
|
+
return emit_quoted(item);
|
|
917
|
+
}), ", "), ")"]) : (__eliscript_truthy((kind === "vector")) ? combine(["__eliscript_vector(", join_fragments(((value)["items"])["map"]((item) => {
|
|
918
|
+
return emit_quoted(item);
|
|
919
|
+
}), ", "), ")"]) : fail("cannot emit quoted IR datum")))))))))));
|
|
920
|
+
})(datum_kind(value));
|
|
921
|
+
}
|
|
922
|
+
function quoted_uses_literal_runtime_p(value) {
|
|
923
|
+
return ((kind) => {
|
|
924
|
+
return ((__eliscript_value_30) => (__eliscript_truthy(__eliscript_value_30) ? __eliscript_value_30 : ((__eliscript_value_31) => (__eliscript_truthy(__eliscript_value_31) ? __eliscript_value_31 : ((__eliscript_value_32) => (__eliscript_truthy(__eliscript_value_32) ? __eliscript_value_32 : ((__eliscript_value_33) => (__eliscript_truthy(__eliscript_value_33) ? __eliscript_value_33 : ((__eliscript_value_34) => (__eliscript_truthy(__eliscript_value_34) ? __eliscript_value_34 : (kind === "vector")))((kind === "list"))))((kind === "keyword"))))((kind === "symbol"))))((value === false))))((value == null));
|
|
925
|
+
})(datum_kind(value));
|
|
926
|
+
}
|
|
927
|
+
function emit_property_key(node) {
|
|
928
|
+
return native_locate(ir_span(node), (__eliscript_truthy(((__eliscript_value_35) => (__eliscript_truthy(__eliscript_value_35) ? ((__eliscript_value_36) => (__eliscript_truthy(__eliscript_value_36) ? __eliscript_value_36 : (typeof node.value === "string")))((literal_kind(node) === "keyword")) : __eliscript_value_35))((ir_kind(node) === "literal"))) ? text_fragment(json_string(ir_value(node))) : emit_expression(node)));
|
|
929
|
+
}
|
|
930
|
+
function emit_expression(node) {
|
|
931
|
+
(__eliscript_truthy((!__eliscript_truthy(node_p(node)))) ? fail("expected an IR expression node") : null);
|
|
932
|
+
return ((kind, nodes) => {
|
|
933
|
+
return native_locate(ir_span(node), (__eliscript_truthy((kind === "literal")) ? emit_literal(node) : (__eliscript_truthy((kind === "reference")) ? text_fragment(reference_name(ir_value(node))) : (__eliscript_truthy((kind === "array-literal")) ? combine(["[", emit_arguments(nodes), "]"]) : (__eliscript_truthy((kind === "persistent-list-literal")) ? combine(["__eliscript_list(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "persistent-vector-literal")) ? combine(["__eliscript_vector(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "persistent-map-literal")) ? combine(["__eliscript_hash_map(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "persistent-set-literal")) ? combine(["__eliscript_hash_set(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "persistent-queue-literal")) ? combine(["__eliscript_queue(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "quoted-literal")) ? emit_quoted(ir_value(node)) : (__eliscript_truthy((kind === "function-expression")) ? emit_function(node) : (__eliscript_truthy((kind === "await-expression")) ? combine(["await (", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")"]) : (__eliscript_truthy((kind === "throw-expression")) ? emit_throw(node) : (__eliscript_truthy((kind === "try-expression")) ? emit_try(node) : (__eliscript_truthy((kind === "conditional")) ? emit_if(nodes) : (__eliscript_truthy((kind === "conditional-sugar")) ? emit_conditional_sugar(node) : (__eliscript_truthy((kind === "conditional-chain")) ? emit_cond(nodes) : (__eliscript_truthy((kind === "sequence")) ? emit_do(nodes) : (__eliscript_truthy((kind === "lexical-bindings")) ? emit_let(node) : (__eliscript_truthy((kind === "assignment")) ? emit_assignment(node) : (__eliscript_truthy((kind === "loop")) ? emit_loop(node) : (__eliscript_truthy((kind === "binding-loop")) ? emit_binding_loop(node) : (__eliscript_truthy((kind === "recur")) ? fail("recur is only valid in an analyzed tail position") : (__eliscript_truthy((kind === "short-circuit")) ? emit_short_circuit(nodes, ir_value(node)) : (__eliscript_truthy((kind === "intrinsic")) ? emit_intrinsic(node) : (__eliscript_truthy((kind === "object-literal")) ? emit_object(node) : (__eliscript_truthy((kind === "property-read")) ? ((access) => {
|
|
934
|
+
return (__eliscript_truthy(((nodes)["length"] === 3)) ? combine(["(", access, " ?? ", emit_expression(((((nodes) ?? [])[2]) ?? null)), ")"]) : access);
|
|
935
|
+
})(combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")[", emit_property_key(((((nodes) ?? [])[1]) ?? null)), "]"])) : (__eliscript_truthy((kind === "property-write")) ? combine(["((", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")[", emit_property_key(((((nodes) ?? [])[1]) ?? null)), "] = ", emit_expression(((((nodes) ?? [])[2]) ?? null)), ")"]) : (__eliscript_truthy((kind === "method-call")) ? combine(["(", emit_expression(((((nodes) ?? [])[0]) ?? null)), ")[", emit_property_key(((((nodes) ?? [])[1]) ?? null)), "](", emit_arguments((nodes)["slice"](2)), ")"]) : (__eliscript_truthy((kind === "constructor-call")) ? combine(["new ", emit_expression(((((nodes) ?? [])[0]) ?? null)), "(", emit_arguments((nodes)["slice"](1)), ")"]) : (__eliscript_truthy((kind === "raw-javascript")) ? (() => {
|
|
936
|
+
require_arity("js*", nodes, 1, 1);
|
|
937
|
+
(__eliscript_truthy((!__eliscript_truthy((ir_kind(((((nodes) ?? [])[0]) ?? null)) === "literal")))) ? fail("js* expects a string literal") : null);
|
|
938
|
+
return text_fragment(ir_value(((((nodes) ?? [])[0]) ?? null)));
|
|
939
|
+
})() : (__eliscript_truthy((kind === "print")) ? combine(["console.log(", emit_arguments(nodes), ")"]) : (__eliscript_truthy((kind === "string-concat")) ? (__eliscript_truthy(((nodes)["length"] === 0)) ? text_fragment("\"\"") : ((parts) => {
|
|
940
|
+
(nodes)["forEach"]((child) => {
|
|
941
|
+
return (parts)["push"](combine(["String(", emit_expression(child), ")"]));
|
|
942
|
+
});
|
|
943
|
+
return combine(["(", join_fragments(parts, " + "), ")"]);
|
|
944
|
+
})([])) : (__eliscript_truthy((kind === "invoke")) ? combine([emit_callee(((((nodes) ?? [])[0]) ?? null)), "(", emit_arguments((nodes)["slice"](1)), ")"]) : (__eliscript_truthy((kind === "apply-call")) ? combine([emit_callee(((((nodes) ?? [])[0]) ?? null)), "(...", emit_expression(((((nodes) ?? [])[1]) ?? null)), ")"]) : (__eliscript_truthy((kind === "call")) ? combine([emit_callee(((((nodes) ?? [])[0]) ?? null)), "(", emit_arguments((nodes)["slice"](1)), ")"]) : fail((String("IR node is not valid in expression position: ") + String(kind)))))))))))))))))))))))))))))))))))))));
|
|
945
|
+
})(ir_kind(node), children(node));
|
|
946
|
+
}
|
|
947
|
+
function emit_import(node) {
|
|
948
|
+
return ((default_binding, namespace_binding, named_bindings) => {
|
|
949
|
+
(children(node))["forEach"]((specifier) => {
|
|
950
|
+
return ((name, kind) => {
|
|
951
|
+
return (__eliscript_truthy((kind === "import-default")) ? ((default_binding = name)) : (__eliscript_truthy((kind === "import-namespace")) ? ((namespace_binding = name)) : (__eliscript_truthy((kind === "import-named")) ? (named_bindings)["push"](name) : fail((String("invalid IR import specifier: ") + String(kind))))));
|
|
952
|
+
})(emit_binding_name(specifier), ir_kind(specifier));
|
|
953
|
+
});
|
|
954
|
+
(__eliscript_truthy(((__eliscript_value_37) => (__eliscript_truthy(__eliscript_value_37) ? ((named_bindings)["length"] > 0) : __eliscript_value_37))(namespace_binding)) ? fail("namespace and named imports cannot be combined") : null);
|
|
955
|
+
return ((clauses) => {
|
|
956
|
+
(__eliscript_truthy(default_binding) ? (clauses)["push"](default_binding) : null);
|
|
957
|
+
(__eliscript_truthy(namespace_binding) ? (clauses)["push"](combine(["* as ", namespace_binding])) : null);
|
|
958
|
+
(__eliscript_truthy(((named_bindings)["length"] > 0)) ? (clauses)["push"](combine(["{", join_fragments(named_bindings, ", "), "}"])) : null);
|
|
959
|
+
return (__eliscript_truthy(((clauses)["length"] === 0)) ? text_fragment((String("import ") + String(json_string(ir_value(node))) + String(";"))) : combine(["import ", join_fragments(clauses, ", "), " from ", json_string(ir_value(node)), ";"]));
|
|
960
|
+
})([]);
|
|
961
|
+
})(null, null, []);
|
|
962
|
+
}
|
|
963
|
+
function emit_top_level(node) {
|
|
964
|
+
(__eliscript_truthy((!__eliscript_truthy(node_p(node)))) ? fail("expected a top-level IR node") : null);
|
|
965
|
+
return ((kind, nodes) => {
|
|
966
|
+
return native_locate(ir_span(node), (__eliscript_truthy((kind === "module-declaration")) ? join_fragments((nodes)["map"]((child) => {
|
|
967
|
+
return emit_top_level(child);
|
|
968
|
+
}), "\n") : (__eliscript_truthy((kind === "import-declaration")) ? emit_import(node) : (__eliscript_truthy((kind === "variable-declaration")) ? combine([(__eliscript_truthy(ir_property(node, "mutable")) ? "let " : "const "), binding_name(ir_value(node)), " = ", (__eliscript_truthy(((nodes)["length"] > 0)) ? emit_expression(((((nodes) ?? [])[0]) ?? null)) : "null"), ";"]) : (__eliscript_truthy((kind === "function-declaration")) ? ((parts) => {
|
|
969
|
+
return ((parameters) => {
|
|
970
|
+
return ((body) => {
|
|
971
|
+
return combine([(__eliscript_truthy(ir_property(node, "async")) ? "async " : ""), "function ", binding_name(ir_value(node)), "(", join_fragments((parameters)["map"]((parameter) => {
|
|
972
|
+
return emit_parameter(parameter);
|
|
973
|
+
}), ", "), ") {\n", indent(emit_function_body(parameters, body)), "\n}"]);
|
|
974
|
+
})(((((parts) ?? [])[1]) ?? null));
|
|
975
|
+
})(((((parts) ?? [])[0]) ?? null));
|
|
976
|
+
})(split_counted_children(node, "parameterCount")) : (__eliscript_truthy((kind === "export-declaration")) ? combine(["export {", join_fragments((nodes)["map"]((reference) => {
|
|
977
|
+
return emit_binding_name(reference);
|
|
978
|
+
}), ", "), "};"]) : (__eliscript_truthy((kind === "export-default")) ? combine(["export default ", emit_expression(((((nodes) ?? [])[0]) ?? null)), ";"]) : (__eliscript_truthy((kind === "expression-statement")) ? combine([emit_expression(((((nodes) ?? [])[0]) ?? null)), ";"]) : fail((String("IR node is not valid at module top level: ") + String(kind)))))))))));
|
|
979
|
+
})(ir_kind(node), children(node));
|
|
980
|
+
}
|
|
981
|
+
function node_uses_host_identity_token_p(node) {
|
|
982
|
+
return (__eliscript_truthy(((__eliscript_value_38) => (__eliscript_truthy(__eliscript_value_38) ? (ir_value(node) === "host-identity-token") : __eliscript_value_38))((ir_kind(node) === "intrinsic"))) ? true : ((found) => {
|
|
983
|
+
(children(node))["forEach"]((child) => {
|
|
984
|
+
return (__eliscript_truthy(node_uses_host_identity_token_p(child)) ? ((found = true)) : null);
|
|
985
|
+
});
|
|
986
|
+
return found;
|
|
987
|
+
})(false));
|
|
988
|
+
}
|
|
989
|
+
function node_directly_uses_literal_runtime_p(node) {
|
|
990
|
+
return ((kind) => {
|
|
991
|
+
return ((__eliscript_value_39) => (__eliscript_truthy(__eliscript_value_39) ? __eliscript_value_39 : ((__eliscript_value_40) => (__eliscript_truthy(__eliscript_value_40) ? __eliscript_value_40 : ((__eliscript_value_41) => (__eliscript_truthy(__eliscript_value_41) ? __eliscript_value_41 : ((__eliscript_value_42) => (__eliscript_truthy(__eliscript_value_42) ? __eliscript_value_42 : ((__eliscript_value_43) => (__eliscript_truthy(__eliscript_value_43) ? __eliscript_value_43 : ((__eliscript_value_44) => (__eliscript_truthy(__eliscript_value_44) ? __eliscript_value_44 : ((__eliscript_value_46) => (__eliscript_truthy(__eliscript_value_46) ? (literal_kind(node) === "keyword") : __eliscript_value_46))((kind === "literal"))))(((__eliscript_value_45) => (__eliscript_truthy(__eliscript_value_45) ? quoted_uses_literal_runtime_p(ir_value(node)) : __eliscript_value_45))((kind === "quoted-literal")))))((kind === "persistent-queue-literal"))))((kind === "persistent-set-literal"))))((kind === "persistent-map-literal"))))((kind === "persistent-vector-literal"))))((kind === "persistent-list-literal"));
|
|
992
|
+
})(ir_kind(node));
|
|
993
|
+
}
|
|
994
|
+
function literal_runtime_static_key_index(node) {
|
|
995
|
+
return ((kind) => {
|
|
996
|
+
return (__eliscript_truthy(((__eliscript_value_47) => (__eliscript_truthy(__eliscript_value_47) ? __eliscript_value_47 : ((__eliscript_value_48) => (__eliscript_truthy(__eliscript_value_48) ? __eliscript_value_48 : (kind === "method-call")))((kind === "property-write"))))((kind === "property-read"))) ? 1 : (__eliscript_truthy(((__eliscript_value_49) => (__eliscript_truthy(__eliscript_value_49) ? ((__eliscript_value_50) => (__eliscript_truthy(__eliscript_value_50) ? __eliscript_value_50 : ((__eliscript_value_51) => (__eliscript_truthy(__eliscript_value_51) ? __eliscript_value_51 : (ir_value(node) === "object-assoc")))((ir_value(node) === "object-has?"))))((ir_value(node) === "aref")) : __eliscript_value_49))((kind === "intrinsic"))) ? 1 : null));
|
|
997
|
+
})(ir_kind(node));
|
|
998
|
+
}
|
|
999
|
+
function node_uses_literal_runtime_p(node) {
|
|
1000
|
+
return ((nodes) => {
|
|
1001
|
+
return (__eliscript_truthy(node_directly_uses_literal_runtime_p(node)) ? true : children_use_literal_runtime_p(nodes, literal_runtime_static_key_index(node)));
|
|
1002
|
+
})(children(node));
|
|
1003
|
+
}
|
|
1004
|
+
function children_use_literal_runtime_p(nodes, static_key_index) {
|
|
1005
|
+
return ((found, index) => {
|
|
1006
|
+
(() => {
|
|
1007
|
+
while (__eliscript_truthy((index < (nodes)["length"]))) {
|
|
1008
|
+
((child) => {
|
|
1009
|
+
return (__eliscript_truthy((!__eliscript_truthy(((__eliscript_value_52) => (__eliscript_truthy(__eliscript_value_52) ? ((__eliscript_value_53) => (__eliscript_truthy(__eliscript_value_53) ? ((__eliscript_value_54) => (__eliscript_truthy(__eliscript_value_54) ? (literal_kind(child) === "keyword") : __eliscript_value_54))((ir_kind(child) === "literal")) : __eliscript_value_53))((index === static_key_index)) : __eliscript_value_52))(static_key_index)))) ? (__eliscript_truthy(node_uses_literal_runtime_p(child)) ? ((found = true)) : null) : null);
|
|
1010
|
+
})(((((nodes) ?? [])[index]) ?? null));
|
|
1011
|
+
((index = (index + 1)));
|
|
1012
|
+
}
|
|
1013
|
+
return null;
|
|
1014
|
+
})();
|
|
1015
|
+
return found;
|
|
1016
|
+
})(false, 0);
|
|
1017
|
+
}
|
|
1018
|
+
function node_uses_collection_runtime_p(node) {
|
|
1019
|
+
return (__eliscript_truthy(((__eliscript_value_55) => (__eliscript_truthy(__eliscript_value_55) ? ((__eliscript_value_56) => (__eliscript_truthy(__eliscript_value_56) ? __eliscript_value_56 : (ir_value(node) === "length")))((ir_value(node) === "nth")) : __eliscript_value_55))((ir_kind(node) === "intrinsic"))) ? true : ((found) => {
|
|
1020
|
+
(children(node))["forEach"]((child) => {
|
|
1021
|
+
return (__eliscript_truthy(node_uses_collection_runtime_p(child)) ? ((found = true)) : null);
|
|
1022
|
+
});
|
|
1023
|
+
return found;
|
|
1024
|
+
})(false));
|
|
1025
|
+
}
|
|
1026
|
+
function node_uses_binding_runtime_p(node) {
|
|
1027
|
+
return (__eliscript_truthy((ir_kind(node) === "map-binding-pattern")) ? true : ((found) => {
|
|
1028
|
+
(children(node))["forEach"]((child) => {
|
|
1029
|
+
return (__eliscript_truthy(node_uses_binding_runtime_p(child)) ? ((found = true)) : null);
|
|
1030
|
+
});
|
|
1031
|
+
return found;
|
|
1032
|
+
})(false));
|
|
1033
|
+
}
|
|
1034
|
+
function node_uses_list_runtime_p(node) {
|
|
1035
|
+
return (__eliscript_truthy(((__eliscript_value_57) => (__eliscript_truthy(__eliscript_value_57) ? ((__eliscript_value_58) => (__eliscript_truthy(__eliscript_value_58) ? __eliscript_value_58 : ((__eliscript_value_59) => (__eliscript_truthy(__eliscript_value_59) ? __eliscript_value_59 : (ir_value(node) === "cons")))((ir_value(node) === "cdr"))))((ir_value(node) === "car")) : __eliscript_value_57))((ir_kind(node) === "intrinsic"))) ? true : ((found) => {
|
|
1036
|
+
(children(node))["forEach"]((child) => {
|
|
1037
|
+
return (__eliscript_truthy(node_uses_list_runtime_p(child)) ? ((found = true)) : null);
|
|
1038
|
+
});
|
|
1039
|
+
return found;
|
|
1040
|
+
})(false));
|
|
1041
|
+
}
|
|
1042
|
+
function node_uses_value_runtime_p(node) {
|
|
1043
|
+
return (__eliscript_truthy(((__eliscript_value_60) => (__eliscript_truthy(__eliscript_value_60) ? (ir_value(node) === "equal") : __eliscript_value_60))((ir_kind(node) === "intrinsic"))) ? true : ((found) => {
|
|
1044
|
+
(children(node))["forEach"]((child) => {
|
|
1045
|
+
return (__eliscript_truthy(node_uses_value_runtime_p(child)) ? ((found = true)) : null);
|
|
1046
|
+
});
|
|
1047
|
+
return found;
|
|
1048
|
+
})(false));
|
|
1049
|
+
}
|
|
1050
|
+
function program_uses_host_identity_token_p(program) {
|
|
1051
|
+
return ((found) => {
|
|
1052
|
+
(program_body(program))["forEach"]((node) => {
|
|
1053
|
+
return (__eliscript_truthy(node_uses_host_identity_token_p(node)) ? ((found = true)) : null);
|
|
1054
|
+
});
|
|
1055
|
+
return found;
|
|
1056
|
+
})(false);
|
|
1057
|
+
}
|
|
1058
|
+
function program_uses_literal_runtime_p(program) {
|
|
1059
|
+
return ((found) => {
|
|
1060
|
+
(program_body(program))["forEach"]((node) => {
|
|
1061
|
+
return (__eliscript_truthy(node_uses_literal_runtime_p(node)) ? ((found = true)) : null);
|
|
1062
|
+
});
|
|
1063
|
+
return found;
|
|
1064
|
+
})(false);
|
|
1065
|
+
}
|
|
1066
|
+
function program_uses_collection_runtime_p(program) {
|
|
1067
|
+
return ((found) => {
|
|
1068
|
+
(program_body(program))["forEach"]((node) => {
|
|
1069
|
+
return (__eliscript_truthy(node_uses_collection_runtime_p(node)) ? ((found = true)) : null);
|
|
1070
|
+
});
|
|
1071
|
+
return found;
|
|
1072
|
+
})(false);
|
|
1073
|
+
}
|
|
1074
|
+
function program_uses_binding_runtime_p(program) {
|
|
1075
|
+
return ((found) => {
|
|
1076
|
+
(program_body(program))["forEach"]((node) => {
|
|
1077
|
+
return (__eliscript_truthy(node_uses_binding_runtime_p(node)) ? ((found = true)) : null);
|
|
1078
|
+
});
|
|
1079
|
+
return found;
|
|
1080
|
+
})(false);
|
|
1081
|
+
}
|
|
1082
|
+
function program_uses_list_runtime_p(program) {
|
|
1083
|
+
return ((found) => {
|
|
1084
|
+
(program_body(program))["forEach"]((node) => {
|
|
1085
|
+
return (__eliscript_truthy(node_uses_list_runtime_p(node)) ? ((found = true)) : null);
|
|
1086
|
+
});
|
|
1087
|
+
return found;
|
|
1088
|
+
})(false);
|
|
1089
|
+
}
|
|
1090
|
+
function program_uses_value_runtime_p(program) {
|
|
1091
|
+
return ((found) => {
|
|
1092
|
+
(program_body(program))["forEach"]((node) => {
|
|
1093
|
+
return (__eliscript_truthy(node_uses_value_runtime_p(node)) ? ((found = true)) : null);
|
|
1094
|
+
});
|
|
1095
|
+
return found;
|
|
1096
|
+
})(false);
|
|
1097
|
+
}
|
|
1098
|
+
function reference_runtime_requirements(program) {
|
|
1099
|
+
return ({"hostIdentityToken": program_uses_host_identity_token_p(program), "literal": program_uses_literal_runtime_p(program), "collection": program_uses_collection_runtime_p(program), "binding": program_uses_binding_runtime_p(program), "list": program_uses_list_runtime_p(program), "value": program_uses_value_runtime_p(program)});
|
|
1100
|
+
}
|
|
1101
|
+
function static_literal_key_p(node, index, static_key_index) {
|
|
1102
|
+
return ((__eliscript_value_61) => (__eliscript_truthy(__eliscript_value_61) ? ((__eliscript_value_62) => (__eliscript_truthy(__eliscript_value_62) ? ((__eliscript_value_63) => (__eliscript_truthy(__eliscript_value_63) ? (literal_kind(node) === "keyword") : __eliscript_value_63))((ir_kind(node) === "literal")) : __eliscript_value_62))((index === static_key_index)) : __eliscript_value_61))(static_key_index);
|
|
1103
|
+
}
|
|
1104
|
+
function collect_runtime_requirements(node, requirements, suppress_literal) {
|
|
1105
|
+
((kind, value, nodes, static_key_index, index, child) => {
|
|
1106
|
+
(__eliscript_truthy((kind === "map-binding-pattern")) ? ((requirements)["binding"] = true) : (__eliscript_truthy(((__eliscript_value_64) => (__eliscript_truthy(__eliscript_value_64) ? ((__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 : (kind === "persistent-queue-literal")))((kind === "persistent-set-literal"))))((kind === "persistent-map-literal"))))((kind === "persistent-vector-literal"))))((kind === "persistent-list-literal")) : __eliscript_value_64))((!__eliscript_truthy(suppress_literal)))) ? ((requirements)["literal"] = true) : (__eliscript_truthy(((__eliscript_value_69) => (__eliscript_truthy(__eliscript_value_69) ? ((__eliscript_value_70) => (__eliscript_truthy(__eliscript_value_70) ? quoted_uses_literal_runtime_p(value) : __eliscript_value_70))((kind === "quoted-literal")) : __eliscript_value_69))((!__eliscript_truthy(suppress_literal)))) ? ((requirements)["literal"] = true) : (__eliscript_truthy(((__eliscript_value_71) => (__eliscript_truthy(__eliscript_value_71) ? ((__eliscript_value_72) => (__eliscript_truthy(__eliscript_value_72) ? (literal_kind(node) === "keyword") : __eliscript_value_72))((kind === "literal")) : __eliscript_value_71))((!__eliscript_truthy(suppress_literal)))) ? ((requirements)["literal"] = true) : (__eliscript_truthy((kind === "intrinsic")) ? (__eliscript_truthy((value === "host-identity-token")) ? ((requirements)["hostIdentityToken"] = true) : (__eliscript_truthy(((__eliscript_value_73) => (__eliscript_truthy(__eliscript_value_73) ? __eliscript_value_73 : (value === "length")))((value === "nth"))) ? ((requirements)["collection"] = true) : (__eliscript_truthy(((__eliscript_value_74) => (__eliscript_truthy(__eliscript_value_74) ? __eliscript_value_74 : ((__eliscript_value_75) => (__eliscript_truthy(__eliscript_value_75) ? __eliscript_value_75 : (value === "cons")))((value === "cdr"))))((value === "car"))) ? ((requirements)["list"] = true) : (__eliscript_truthy((value === "equal")) ? ((requirements)["value"] = true) : null)))) : null)))));
|
|
1107
|
+
return (() => {
|
|
1108
|
+
while (__eliscript_truthy((index < (nodes)["length"]))) {
|
|
1109
|
+
((child = ((((nodes) ?? [])[index]) ?? null)));
|
|
1110
|
+
collect_runtime_requirements(child, requirements, ((__eliscript_value_76) => (__eliscript_truthy(__eliscript_value_76) ? __eliscript_value_76 : static_literal_key_p(child, index, static_key_index)))(suppress_literal));
|
|
1111
|
+
((index = (index + 1)));
|
|
1112
|
+
}
|
|
1113
|
+
return null;
|
|
1114
|
+
})();
|
|
1115
|
+
})(ir_kind(node), ir_value(node), children(node), literal_runtime_static_key_index(node), 0, null);
|
|
1116
|
+
return requirements;
|
|
1117
|
+
}
|
|
1118
|
+
function runtime_requirements(program) {
|
|
1119
|
+
return ((requirements) => {
|
|
1120
|
+
(program_body(program))["forEach"]((node) => {
|
|
1121
|
+
return collect_runtime_requirements(node, requirements, false);
|
|
1122
|
+
});
|
|
1123
|
+
return requirements;
|
|
1124
|
+
})(({"hostIdentityToken": false, "literal": false, "collection": false, "binding": false, "list": false, "value": false}));
|
|
1125
|
+
}
|
|
1126
|
+
function collect_portable_metadata(node, portable, exported) {
|
|
1127
|
+
(__eliscript_truthy(((__eliscript_value_77) => (__eliscript_truthy(__eliscript_value_77) ? ir_property(node, "portable") : __eliscript_value_77))((ir_kind(node) === "function-declaration"))) ? (portable)["push"](node) : null);
|
|
1128
|
+
(__eliscript_truthy((ir_kind(node) === "export-declaration")) ? (children(node))["forEach"]((reference) => {
|
|
1129
|
+
return (exported)["push"](ir_value(reference));
|
|
1130
|
+
}) : null);
|
|
1131
|
+
return (children(node))["forEach"]((child) => {
|
|
1132
|
+
return collect_portable_metadata(child, portable, exported);
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
function emit_portable_manifest(program) {
|
|
1136
|
+
return ((portable, exported) => {
|
|
1137
|
+
(program_body(program))["forEach"]((node) => {
|
|
1138
|
+
return collect_portable_metadata(node, portable, exported);
|
|
1139
|
+
});
|
|
1140
|
+
return (__eliscript_truthy(((portable)["length"] === 0)) ? text_fragment("") : ((implicit) => {
|
|
1141
|
+
return combine([(__eliscript_truthy(((implicit)["length"] > 0)) ? combine(["\n\nexport {", join_fragments((implicit)["map"]((node) => {
|
|
1142
|
+
return binding_name(ir_value(node));
|
|
1143
|
+
}), ", "), "};"]) : ""), "\nexport const __eliscript_portable__ = Object.freeze(Object.fromEntries([", join_fragments((portable)["map"]((node) => {
|
|
1144
|
+
return combine(["[", json_string(ir_value(node)), ", ", binding_name(ir_value(node)), "]"]);
|
|
1145
|
+
}), ", "), "]));"]);
|
|
1146
|
+
})((portable)["filter"]((node) => {
|
|
1147
|
+
return (!__eliscript_truthy((exported)["includes"](ir_value(node))));
|
|
1148
|
+
})));
|
|
1149
|
+
})([], []);
|
|
1150
|
+
}
|
|
1151
|
+
function emit_module_artifact(program) {
|
|
1152
|
+
((temporary_counter = 0));
|
|
1153
|
+
((binding_temporaries = new globalThis.Map()));
|
|
1154
|
+
return ((requirements, body) => {
|
|
1155
|
+
return combine(["// Generated by Eliscript. Do not edit.\n", (__eliscript_truthy((requirements)["literal"]) ? literal_runtime_import : ""), (__eliscript_truthy((requirements)["collection"]) ? collection_runtime_import : ""), (__eliscript_truthy((requirements)["binding"]) ? binding_runtime : ""), (__eliscript_truthy((requirements)["list"]) ? list_runtime_import : ""), (__eliscript_truthy((requirements)["value"]) ? value_runtime_import : ""), "const __eliscript_truthy = (value) => value !== false && value != null;\n", (__eliscript_truthy((requirements)["hostIdentityToken"]) ? host_identity_token_helper : ""), "\n", body, emit_portable_manifest(program), "\n"]);
|
|
1156
|
+
})(runtime_requirements(program), join_fragments((program_body(program))["map"]((node) => {
|
|
1157
|
+
return emit_top_level(node);
|
|
1158
|
+
}), "\n\n"));
|
|
1159
|
+
}
|
|
1160
|
+
function emit_module(program) {
|
|
1161
|
+
return (emit_module_artifact(program))["text"];
|
|
1162
|
+
}
|
|
1163
|
+
function emit_module_with_source_map(program, source, generated_name, source_name) {
|
|
1164
|
+
return ((artifact) => {
|
|
1165
|
+
return ((javascript) => {
|
|
1166
|
+
return ((resolved_source_name) => {
|
|
1167
|
+
return ({"javascript": javascript, "sourceMap": create_source_map(javascript, (artifact)["marks"], source, resolved_source_name, generated_name)});
|
|
1168
|
+
})(((__eliscript_value_78) => (__eliscript_truthy(__eliscript_value_78) ? __eliscript_value_78 : ((__eliscript_value_79) => (__eliscript_truthy(__eliscript_value_79) ? __eliscript_value_79 : "<string>"))(program_filename(program))))(source_name));
|
|
1169
|
+
})((artifact)["text"]);
|
|
1170
|
+
})(emit_module_artifact(program));
|
|
1171
|
+
}
|
|
1172
|
+
export {indent, reference_indent, locate, reference_locate, emit_expression, emit_top_level, emit_module_artifact, emit_module, emit_module_with_source_map, runtime_requirements, reference_runtime_requirements};
|
|
1173
|
+
//# sourceMappingURL=emitter.mjs.map
|