eliscript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +135 -0
  3. package/bin/eliscript +16 -0
  4. package/bin/eliscript-bootstrap +15 -0
  5. package/bin/eliscript-build +15 -0
  6. package/bin/eliscript-check +15 -0
  7. package/bin/eliscript-eval +15 -0
  8. package/bin/eliscript-format +15 -0
  9. package/bin/eliscript-org +10 -0
  10. package/bin/eliscript-portable +17 -0
  11. package/bin/eliscript-seed +10 -0
  12. package/bin/eliscript-seed-build +10 -0
  13. package/bin/eliscript-watch +15 -0
  14. package/bootstrap/README.md +100 -0
  15. package/bootstrap/compiler/analyzer.eli +1426 -0
  16. package/bootstrap/compiler/compiler.eli +472 -0
  17. package/bootstrap/compiler/emitter.eli +1745 -0
  18. package/bootstrap/compiler/expander.eli +2522 -0
  19. package/bootstrap/compiler/formatter.eli +359 -0
  20. package/bootstrap/compiler/ir.eli +297 -0
  21. package/bootstrap/compiler/lower.eli +661 -0
  22. package/bootstrap/compiler/project.eli +1120 -0
  23. package/bootstrap/compiler/reader.eli +321 -0
  24. package/bootstrap/compiler/source-map.eli +165 -0
  25. package/bootstrap/compiler/symbol.eli +92 -0
  26. package/bootstrap/compiler/syntax.eli +54 -0
  27. package/bootstrap/compiler/transient-analysis.eli +825 -0
  28. package/bootstrap/host/build.mjs +28 -0
  29. package/bootstrap/host/bun.mjs +282 -0
  30. package/bootstrap/host/check-cli.mjs +163 -0
  31. package/bootstrap/host/eliscript-cli.mjs +36 -0
  32. package/bootstrap/host/evaluation-cli.mjs +401 -0
  33. package/bootstrap/host/evaluation.mjs +560 -0
  34. package/bootstrap/host/format-cli.mjs +139 -0
  35. package/bootstrap/host/project-cli.mjs +295 -0
  36. package/bootstrap/host/project.mjs +1080 -0
  37. package/bootstrap/host/watch-cli.mjs +129 -0
  38. package/bootstrap/host/watch.mjs +267 -0
  39. package/browser/host.mjs +357 -0
  40. package/browser/worker.mjs +60 -0
  41. package/compiler/README.md +118 -0
  42. package/compiler/eliscript-analyzer.el +716 -0
  43. package/compiler/eliscript-cli.el +108 -0
  44. package/compiler/eliscript-diagnostic.el +158 -0
  45. package/compiler/eliscript-emitter.el +1351 -0
  46. package/compiler/eliscript-evaluation.el +259 -0
  47. package/compiler/eliscript-expander.el +1630 -0
  48. package/compiler/eliscript-form.el +79 -0
  49. package/compiler/eliscript-ir-emitter.el +1460 -0
  50. package/compiler/eliscript-ir.el +356 -0
  51. package/compiler/eliscript-lower.el +463 -0
  52. package/compiler/eliscript-macro-eval.el +811 -0
  53. package/compiler/eliscript-parameters.el +324 -0
  54. package/compiler/eliscript-portable.el +492 -0
  55. package/compiler/eliscript-project-cli.el +156 -0
  56. package/compiler/eliscript-project.el +1676 -0
  57. package/compiler/eliscript-reader.el +421 -0
  58. package/compiler/eliscript-source-map.el +192 -0
  59. package/compiler/eliscript-symbol.el +101 -0
  60. package/compiler/eliscript-transient-analysis.el +817 -0
  61. package/compiler/eliscript.el +239 -0
  62. package/dist/bootstrap/analyzer.mjs +968 -0
  63. package/dist/bootstrap/analyzer.mjs.map +1 -0
  64. package/dist/bootstrap/compiler.mjs +228 -0
  65. package/dist/bootstrap/compiler.mjs.map +1 -0
  66. package/dist/bootstrap/emitter.mjs +1173 -0
  67. package/dist/bootstrap/emitter.mjs.map +1 -0
  68. package/dist/bootstrap/expander.mjs +1469 -0
  69. package/dist/bootstrap/expander.mjs.map +1 -0
  70. package/dist/bootstrap/formatter.mjs +304 -0
  71. package/dist/bootstrap/formatter.mjs.map +1 -0
  72. package/dist/bootstrap/ir.mjs +193 -0
  73. package/dist/bootstrap/ir.mjs.map +1 -0
  74. package/dist/bootstrap/lower.mjs +344 -0
  75. package/dist/bootstrap/lower.mjs.map +1 -0
  76. package/dist/bootstrap/project.mjs +585 -0
  77. package/dist/bootstrap/project.mjs.map +1 -0
  78. package/dist/bootstrap/reader.mjs +259 -0
  79. package/dist/bootstrap/reader.mjs.map +1 -0
  80. package/dist/bootstrap/source-map.mjs +154 -0
  81. package/dist/bootstrap/source-map.mjs.map +1 -0
  82. package/dist/bootstrap/symbol.mjs +74 -0
  83. package/dist/bootstrap/symbol.mjs.map +1 -0
  84. package/dist/bootstrap/syntax.mjs +38 -0
  85. package/dist/bootstrap/syntax.mjs.map +1 -0
  86. package/dist/bootstrap/transient-analysis.mjs +660 -0
  87. package/dist/bootstrap/transient-analysis.mjs.map +1 -0
  88. package/dist/browser/compiler.js +6491 -0
  89. package/editor/README.md +83 -0
  90. package/editor/eliscript-mode.el +878 -0
  91. package/editor/eliscript-repl.el +501 -0
  92. package/package.json +163 -0
  93. package/platform/README.md +48 -0
  94. package/platform/browser.mjs +204 -0
  95. package/platform/worker.mjs +166 -0
  96. package/runtime/README.md +296 -0
  97. package/runtime/core/collection-internals.mjs +512 -0
  98. package/runtime/core/collection.mjs +645 -0
  99. package/runtime/core/data-text.mjs +532 -0
  100. package/runtime/core/data.mjs +268 -0
  101. package/runtime/core/identifier.mjs +314 -0
  102. package/runtime/core/lazy-sequence.mjs +244 -0
  103. package/runtime/core/list-internals.mjs +18 -0
  104. package/runtime/core/list.mjs +273 -0
  105. package/runtime/core/map-internals.mjs +793 -0
  106. package/runtime/core/map.mjs +394 -0
  107. package/runtime/core/metadata-internals.mjs +14 -0
  108. package/runtime/core/metadata.mjs +44 -0
  109. package/runtime/core/object-impl.mjs +65 -0
  110. package/runtime/core/object-impl.mjs.map +1 -0
  111. package/runtime/core/object.mjs +13 -0
  112. package/runtime/core/order.mjs +234 -0
  113. package/runtime/core/persistent-kind.mjs +43 -0
  114. package/runtime/core/protocol-error.mjs +36 -0
  115. package/runtime/core/protocol-impl.mjs +326 -0
  116. package/runtime/core/protocol-impl.mjs.map +1 -0
  117. package/runtime/core/protocol.mjs +14 -0
  118. package/runtime/core/queue-internals.mjs +27 -0
  119. package/runtime/core/queue.mjs +238 -0
  120. package/runtime/core/record.mjs +346 -0
  121. package/runtime/core/regex.mjs +184 -0
  122. package/runtime/core/sequence.mjs +632 -0
  123. package/runtime/core/set-algebra.mjs +287 -0
  124. package/runtime/core/set-internals.mjs +33 -0
  125. package/runtime/core/set.mjs +378 -0
  126. package/runtime/core/sorted-internals.mjs +215 -0
  127. package/runtime/core/sorted.mjs +598 -0
  128. package/runtime/core/text-impl.mjs +95 -0
  129. package/runtime/core/text-impl.mjs.map +1 -0
  130. package/runtime/core/text.mjs +15 -0
  131. package/runtime/core/transducer.mjs +668 -0
  132. package/runtime/core/transient-internals.mjs +38 -0
  133. package/runtime/core/transient.mjs +53 -0
  134. package/runtime/core/truth.mjs +3 -0
  135. package/runtime/core/type.mjs +262 -0
  136. package/runtime/core/value-internals.mjs +188 -0
  137. package/runtime/core/value.mjs +93 -0
  138. package/runtime/core/vector-internals.mjs +102 -0
  139. package/runtime/core/vector.mjs +951 -0
  140. package/runtime/literals.mjs +34 -0
  141. package/runtime/source-mapping.mjs +220 -0
  142. package/runtime/testing/list.mjs +52 -0
  143. package/runtime/testing/map.mjs +145 -0
  144. package/runtime/testing/queue.mjs +49 -0
  145. package/runtime/testing/set.mjs +61 -0
  146. package/runtime/testing/sorted.mjs +105 -0
  147. package/runtime/testing/value.mjs +17 -0
  148. package/runtime/testing/vector.mjs +102 -0
  149. package/runtime/worker-value-codec.mjs +565 -0
  150. package/runtime/worker-value-stream.mjs +786 -0
  151. package/runtime/worker.mjs +975 -0
  152. package/stdlib/README.md +774 -0
  153. package/stdlib/bit.eli +36 -0
  154. package/stdlib/core/collection.eli +134 -0
  155. package/stdlib/core/data-text.eli +16 -0
  156. package/stdlib/core/data.eli +306 -0
  157. package/stdlib/core/identifier.eli +32 -0
  158. package/stdlib/core/lazy-sequence.eli +63 -0
  159. package/stdlib/core/metadata.eli +20 -0
  160. package/stdlib/core/object.eli +89 -0
  161. package/stdlib/core/order.eli +133 -0
  162. package/stdlib/core/protocol.eli +387 -0
  163. package/stdlib/core/record.eli +16 -0
  164. package/stdlib/core/regex.eli +17 -0
  165. package/stdlib/core/seq.eli +701 -0
  166. package/stdlib/core/set.eli +312 -0
  167. package/stdlib/core/sorted.eli +53 -0
  168. package/stdlib/core/text.eli +103 -0
  169. package/stdlib/core/transducer.eli +59 -0
  170. package/stdlib/core/transient.eli +24 -0
  171. package/stdlib/core/type.eli +19 -0
  172. package/stdlib/core/walk.eli +195 -0
  173. package/stdlib/core/zipper.eli +508 -0
  174. package/stdlib/data-text.eli +1092 -0
  175. package/stdlib/data.eli +42 -0
  176. package/stdlib/deferred.eli +70 -0
  177. package/stdlib/function.eli +120 -0
  178. package/stdlib/hierarchy.eli +245 -0
  179. package/stdlib/identifier.eli +147 -0
  180. package/stdlib/interop/js.eli +616 -0
  181. package/stdlib/json.eli +870 -0
  182. package/stdlib/metadata.eli +56 -0
  183. package/stdlib/multimethod.eli +464 -0
  184. package/stdlib/numeric.eli +193 -0
  185. package/stdlib/object.eli +96 -0
  186. package/stdlib/persistent-list.eli +145 -0
  187. package/stdlib/persistent-map.eli +724 -0
  188. package/stdlib/persistent-queue.eli +32 -0
  189. package/stdlib/persistent-set.eli +236 -0
  190. package/stdlib/persistent-vector.eli +342 -0
  191. package/stdlib/result.eli +141 -0
  192. package/stdlib/sequence.eli +106 -0
  193. package/stdlib/state/atom.eli +265 -0
  194. package/stdlib/text.eli +88 -0
  195. package/stdlib/value.eli +325 -0
@@ -0,0 +1,234 @@
1
+ import { reduce } from "./collection.mjs";
2
+ import {
3
+ EliscriptSymbol,
4
+ Keyword,
5
+ qualifiedIdentifierName,
6
+ } from "./identifier.mjs";
7
+ import { PersistentList } from "./list.mjs";
8
+ import {
9
+ defineProtocol,
10
+ extendProtocolCategory,
11
+ extendProtocolType,
12
+ protocolMethod,
13
+ } from "./protocol.mjs";
14
+ import { into } from "./transducer.mjs";
15
+ import { isTruthy } from "./truth.mjs";
16
+ import { EMPTY_VECTOR, PersistentVector } from "./vector.mjs";
17
+
18
+ export const IComparable = defineProtocol("IComparable", ["compare"]);
19
+ const dispatchCompare = protocolMethod(IComparable, "compare");
20
+
21
+ function requireFunction(value, label) {
22
+ if (typeof value !== "function") {
23
+ throw new TypeError(`${label} must be a function`);
24
+ }
25
+ return value;
26
+ }
27
+
28
+ function comparisonResult(value, label) {
29
+ if (typeof value !== "number" || !Number.isFinite(value)) {
30
+ throw new TypeError(`${label} must return a finite number`);
31
+ }
32
+ return value < 0 ? -1 : value > 0 ? 1 : 0;
33
+ }
34
+
35
+ function typeName(value) {
36
+ if (value === null) return "null";
37
+ if (value === undefined) return "undefined";
38
+ if (value instanceof Keyword) return "keyword";
39
+ if (value instanceof EliscriptSymbol) return "symbol";
40
+ if (value instanceof PersistentVector) return "vector";
41
+ if (value instanceof PersistentList) return "list";
42
+ return typeof value;
43
+ }
44
+
45
+ function requireComparableType(right, predicate, leftName) {
46
+ if (!predicate(right)) {
47
+ throw new TypeError(`cannot compare ${leftName} to ${typeName(right)}`);
48
+ }
49
+ return right;
50
+ }
51
+
52
+ function comparePrimitive(left, right, predicate, name) {
53
+ requireComparableType(right, predicate, name);
54
+ return left < right ? -1 : left > right ? 1 : 0;
55
+ }
56
+
57
+ function compareNumber(left, right) {
58
+ requireComparableType(right, (value) => typeof value === "number", "number");
59
+ if (Number.isNaN(left)) return Number.isNaN(right) ? 0 : 1;
60
+ if (Number.isNaN(right)) return -1;
61
+ return left < right ? -1 : left > right ? 1 : 0;
62
+ }
63
+
64
+ function compareIdentifier(left, right, Constructor, name) {
65
+ requireComparableType(right, (value) => value instanceof Constructor, name);
66
+ return comparePrimitive(
67
+ qualifiedIdentifierName(left),
68
+ qualifiedIdentifierName(right),
69
+ (value) => typeof value === "string",
70
+ "string",
71
+ );
72
+ }
73
+
74
+ function compareSequential(left, right, Constructor, name) {
75
+ requireComparableType(right, (value) => value instanceof Constructor, name);
76
+ const leftIterator = left[Symbol.iterator]();
77
+ const rightIterator = right[Symbol.iterator]();
78
+ while (true) {
79
+ const leftItem = leftIterator.next();
80
+ const rightItem = rightIterator.next();
81
+ if (leftItem.done || rightItem.done) {
82
+ return leftItem.done === rightItem.done ? 0 : leftItem.done ? -1 : 1;
83
+ }
84
+ const result = compareValues(leftItem.value, rightItem.value);
85
+ if (result !== 0) return result;
86
+ }
87
+ }
88
+
89
+ extendProtocolCategory(IComparable, "boolean", {
90
+ compare: (left, right) => comparePrimitive(
91
+ left,
92
+ right,
93
+ (value) => typeof value === "boolean",
94
+ "boolean",
95
+ ),
96
+ });
97
+ extendProtocolCategory(IComparable, "number", { compare: compareNumber });
98
+ extendProtocolCategory(IComparable, "bigint", {
99
+ compare: (left, right) => comparePrimitive(
100
+ left,
101
+ right,
102
+ (value) => typeof value === "bigint",
103
+ "bigint",
104
+ ),
105
+ });
106
+ extendProtocolCategory(IComparable, "string", {
107
+ compare: (left, right) => comparePrimitive(
108
+ left,
109
+ right,
110
+ (value) => typeof value === "string",
111
+ "string",
112
+ ),
113
+ });
114
+ extendProtocolType(IComparable, Keyword, {
115
+ compare: (left, right) => compareIdentifier(left, right, Keyword, "keyword"),
116
+ });
117
+ extendProtocolType(IComparable, EliscriptSymbol, {
118
+ compare: (left, right) =>
119
+ compareIdentifier(left, right, EliscriptSymbol, "symbol"),
120
+ });
121
+ extendProtocolType(IComparable, PersistentVector, {
122
+ compare: (left, right) =>
123
+ compareSequential(left, right, PersistentVector, "vector"),
124
+ });
125
+ extendProtocolType(IComparable, PersistentList, {
126
+ compare: (left, right) =>
127
+ compareSequential(left, right, PersistentList, "list"),
128
+ });
129
+
130
+ export function compareValues(left, right) {
131
+ if (left === right || (Number.isNaN(left) && Number.isNaN(right))) return 0;
132
+ if (left === null) return -1;
133
+ if (right === null) return 1;
134
+ if (left === undefined) return -1;
135
+ if (right === undefined) return 1;
136
+ return comparisonResult(
137
+ dispatchCompare(left, right),
138
+ "IComparable/compare",
139
+ );
140
+ }
141
+
142
+ export function comparator(comparison) {
143
+ requireFunction(comparison, "comparator comparison");
144
+ return (left, right) => {
145
+ const result = comparison(left, right);
146
+ if (typeof result === "number") {
147
+ return comparisonResult(result, "comparator comparison");
148
+ }
149
+ if (isTruthy(result)) return -1;
150
+ return isTruthy(comparison(right, left)) ? 1 : 0;
151
+ };
152
+ }
153
+
154
+ export function reverseComparator(...arguments_) {
155
+ if (arguments_.length > 1) {
156
+ throw new TypeError("reverseComparator expects zero or one comparator");
157
+ }
158
+ const normalized = comparator(
159
+ arguments_.length === 0 ? compareValues : arguments_[0],
160
+ );
161
+ return (left, right) => normalized(right, left);
162
+ }
163
+
164
+ function sortDecorated(values, comparison) {
165
+ values.sort((left, right) =>
166
+ comparison(left.key, right.key) || left.index - right.index);
167
+ return into(EMPTY_VECTOR, values.map(({ value }) => value));
168
+ }
169
+
170
+ function collectDecorated(collection, keyFunction) {
171
+ const values = [];
172
+ reduce(collection, (result, value) => {
173
+ result.push({ index: result.length, key: keyFunction(value), value });
174
+ return result;
175
+ }, values);
176
+ return values;
177
+ }
178
+
179
+ export function sort(...arguments_) {
180
+ if (arguments_.length !== 1 && arguments_.length !== 2) {
181
+ throw new TypeError("sort expects a collection or comparator and collection");
182
+ }
183
+ const comparison = arguments_.length === 1
184
+ ? compareValues
185
+ : arguments_[0];
186
+ const collection = arguments_[arguments_.length - 1];
187
+ return sortDecorated(
188
+ collectDecorated(collection, (value) => value),
189
+ comparator(comparison),
190
+ );
191
+ }
192
+
193
+ export function sortBy(keyFunction, ...arguments_) {
194
+ requireFunction(keyFunction, "sortBy key function");
195
+ if (arguments_.length !== 1 && arguments_.length !== 2) {
196
+ throw new TypeError(
197
+ "sortBy expects a key function, optional comparator, and collection",
198
+ );
199
+ }
200
+ const comparison = arguments_.length === 1
201
+ ? compareValues
202
+ : arguments_[0];
203
+ const collection = arguments_[arguments_.length - 1];
204
+ return sortDecorated(
205
+ collectDecorated(collection, keyFunction),
206
+ comparator(comparison),
207
+ );
208
+ }
209
+
210
+ function extremeKey(label, direction, keyFunction, values) {
211
+ requireFunction(keyFunction, `${label} key function`);
212
+ if (values.length === 0) {
213
+ throw new TypeError(`${label} expects a key function and at least one value`);
214
+ }
215
+ let selected = values[0];
216
+ let selectedKey = keyFunction(selected);
217
+ for (let index = 1; index < values.length; index += 1) {
218
+ const candidate = values[index];
219
+ const candidateKey = keyFunction(candidate);
220
+ if (compareValues(candidateKey, selectedKey) * direction >= 0) {
221
+ selected = candidate;
222
+ selectedKey = candidateKey;
223
+ }
224
+ }
225
+ return selected;
226
+ }
227
+
228
+ export function minKey(keyFunction, ...values) {
229
+ return extremeKey("minKey", -1, keyFunction, values);
230
+ }
231
+
232
+ export function maxKey(keyFunction, ...values) {
233
+ return extremeKey("maxKey", 1, keyFunction, values);
234
+ }
@@ -0,0 +1,43 @@
1
+ export const PERSISTENT_MAP_KIND = Symbol("eliscript.persistent-map.kind");
2
+ export const PERSISTENT_MAP_HAS_VALUE_KEY = Symbol(
3
+ "eliscript.persistent-map.has-value-key",
4
+ );
5
+ export const PERSISTENT_SET_KIND = Symbol("eliscript.persistent-set.kind");
6
+ export const PERSISTENT_SET_HAS_VALUE = Symbol(
7
+ "eliscript.persistent-set.has-value",
8
+ );
9
+
10
+ export function isPersistentMapValue(value) {
11
+ return value?.[PERSISTENT_MAP_KIND] === true &&
12
+ typeof value?.[PERSISTENT_MAP_HAS_VALUE_KEY] === "function";
13
+ }
14
+
15
+ export function isPersistentSetValue(value) {
16
+ return value?.[PERSISTENT_SET_KIND] === true &&
17
+ typeof value?.[PERSISTENT_SET_HAS_VALUE] === "function";
18
+ }
19
+
20
+ export function persistentMapValueEqual(left, right, equal) {
21
+ if (!isPersistentMapValue(right) || right.count !== left.count) {
22
+ return false;
23
+ }
24
+ for (const [key, value] of left) {
25
+ if (!right[PERSISTENT_MAP_HAS_VALUE_KEY](key) ||
26
+ !equal(value, right.get(key))) {
27
+ return false;
28
+ }
29
+ }
30
+ return true;
31
+ }
32
+
33
+ export function persistentSetValueEqual(left, right, equal) {
34
+ if (!isPersistentSetValue(right) || right.count !== left.count) {
35
+ return false;
36
+ }
37
+ for (const value of left) {
38
+ if (!right[PERSISTENT_SET_HAS_VALUE](value, equal)) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ }
@@ -0,0 +1,36 @@
1
+ function protocolHostCategory(value) {
2
+ return value === null ? "null" : typeof value;
3
+ }
4
+
5
+ function observedType(value) {
6
+ const category = protocolHostCategory(value);
7
+ if (category !== "object" && category !== "function") {
8
+ return category;
9
+ }
10
+ try {
11
+ const prototype = Object.getPrototypeOf(value);
12
+ const constructor = prototype?.constructor;
13
+ const name = typeof constructor === "function" && constructor.name.length > 0
14
+ ? constructor.name
15
+ : "anonymous";
16
+ return `${category}:${name}`;
17
+ } catch {
18
+ return category;
19
+ }
20
+ }
21
+
22
+ export class ProtocolDispatchError extends TypeError {
23
+ constructor(protocol, operation, receiver, reason = "missing") {
24
+ const type = observedType(receiver);
25
+ const detail = reason === "missing"
26
+ ? "has no implementation"
27
+ : "has a non-callable direct slot";
28
+ super(`protocol ${protocol.name}/${operation} ${detail} for ${type}`);
29
+ this.name = "ProtocolDispatchError";
30
+ this.code = "ELI-RUNTIME-PROTOCOL";
31
+ this.protocol = protocol.name;
32
+ this.operation = operation;
33
+ this.observedType = type;
34
+ this.reason = reason;
35
+ }
36
+ }
@@ -0,0 +1,326 @@
1
+ // Generated by Eliscript. Do not edit.
2
+ const __eliscript_truthy = (value) => value !== false && value != null;
3
+
4
+ import {ProtocolDispatchError} from "../../runtime/core/protocol-error.mjs";
5
+ const protocol_states = new WeakMap();
6
+ const protocol_missing = Symbol("eliscript.protocol.missing");
7
+ const protocol_host_categories = ["null", "undefined", "boolean", "number", "bigint", "string", "symbol", "function", "object"];
8
+ const protocol_definition_format = "eliscript-protocol-definition";
9
+ const protocol_definition_version = 1;
10
+ const protocol_max_operations = 1024;
11
+ const protocol_symbol = (description) => Symbol(description);
12
+ const protocol_array_QMARK_ = Array.isArray;
13
+ const protocol_map = () => new Map();
14
+ const protocol_null_object = () => Object.create(null);
15
+ const protocol_own_descriptors = Object.getOwnPropertyDescriptors;
16
+ const protocol_own_keys = Reflect.ownKeys;
17
+ const protocol_has_own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
18
+ const protocol_property_present = (value, key) => { if (value === null || value === undefined) return false; return Reflect.has(Object(value), key); };
19
+ const protocol_property_value = (value, key) => Object(value)[key];
20
+ const protocol_host_type = (value) => typeof value;
21
+ const protocol_exact_prototype = (value, missing) => ((typeof value === "object" && value !== null) || typeof value === "function") ? Object.getPrototypeOf(value) : missing;
22
+ const protocol_object_prototype = Object.prototype;
23
+ const protocol_get_prototype = Object.getPrototypeOf;
24
+ const protocol_freeze = Object.freeze;
25
+ const protocol_define_enumerable = (target, key, value) => { Object.defineProperty(target, key, { value, enumerable: true }); return target; };
26
+ const protocol_define_metadata = (target, protocol, operation, slot) => { Object.defineProperties(target, { protocol: { value: protocol }, operation: { value: operation }, slot: { value: slot } }); return target; };
27
+ function protocol_fail(message) {
28
+ return ((__eliscript_value_1) => { throw __eliscript_value_1; })(new globalThis.TypeError(message));
29
+ }
30
+ function protocol_state(protocol) {
31
+ return ((state) => {
32
+ return (__eliscript_truthy((state === undefined)) ? protocol_fail("expected an Eliscript protocol") : state);
33
+ })((protocol_states)["get"](protocol));
34
+ }
35
+ function normalize_name(value, label) {
36
+ return (__eliscript_truthy(((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? __eliscript_value_2 : (((value) ?? []).length === 0)))((!__eliscript_truthy((((__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; } })(value) === "string"))))) ? protocol_fail((String(label) + String(" must be a non-empty string"))) : value);
37
+ }
38
+ function normalize_protocol_operations(operations) {
39
+ (__eliscript_truthy((!__eliscript_truthy(protocol_array_QMARK_(operations)))) ? protocol_fail("protocol operations must be a non-empty dense array") : null);
40
+ return ((length) => {
41
+ (__eliscript_truthy((length === 0)) ? protocol_fail("protocol operations must be a non-empty dense array") : null);
42
+ (__eliscript_truthy((length > protocol_max_operations)) ? protocol_fail((String("protocol operations exceed ") + String(protocol_max_operations))) : null);
43
+ return ((descriptors) => {
44
+ return ((keys) => {
45
+ return ((normalized) => {
46
+ return ((index) => {
47
+ return (() => {
48
+ (__eliscript_truthy(((__eliscript_value_3, __eliscript_value_4) => (__eliscript_value_3 !== __eliscript_value_4))(((keys) ?? []).length, (length + 1))) ? protocol_fail("protocol operations must be a dense array with no extra properties") : null);
49
+ (() => {
50
+ while (__eliscript_truthy((index < length))) {
51
+ ((descriptor) => {
52
+ (__eliscript_truthy(((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? __eliscript_value_5 : ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_value_6 : (!__eliscript_truthy(((descriptor)["enumerable"] ?? false)))))((!__eliscript_truthy(protocol_has_own(descriptor, "value"))))))((descriptor === undefined))) ? protocol_fail("protocol operations must contain enumerable data values") : null);
53
+ return (normalized)["push"](normalize_name((descriptor)["value"], "protocol operation"));
54
+ })(((descriptors)[(String(index))] ?? undefined));
55
+ ((index = (index + 1)));
56
+ }
57
+ return null;
58
+ })();
59
+ return normalized;
60
+ })();
61
+ })(0);
62
+ })([]);
63
+ })(protocol_own_keys(descriptors));
64
+ })(protocol_own_descriptors(operations));
65
+ })(((operations) ?? []).length);
66
+ }
67
+ function protocol_definition_field(descriptors, name) {
68
+ return ((descriptor) => {
69
+ (__eliscript_truthy(((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? __eliscript_value_7 : ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? __eliscript_value_8 : (!__eliscript_truthy(((descriptor)["enumerable"] ?? false)))))((!__eliscript_truthy(protocol_has_own(descriptor, "value"))))))((descriptor === undefined))) ? protocol_fail((String("protocol definition field ") + String(name) + String(" must be an enumerable data property"))) : null);
70
+ return (descriptor)["value"];
71
+ })(((descriptors)[name] ?? undefined));
72
+ }
73
+ function normalize_protocol_definition(definition) {
74
+ (__eliscript_truthy(((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? __eliscript_value_9 : ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? __eliscript_value_10 : protocol_array_QMARK_(definition)))((!__eliscript_truthy((((__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; } })(definition) === "object"))))))((definition === null))) ? protocol_fail("protocol definition must be a plain object") : null);
75
+ ((prototype) => {
76
+ return (__eliscript_truthy(((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? (!__eliscript_truthy((prototype === null))) : __eliscript_value_11))(((__eliscript_value_12, __eliscript_value_13) => (__eliscript_value_12 !== __eliscript_value_13))(prototype, protocol_object_prototype))) ? protocol_fail("protocol definition must be a plain object") : null);
77
+ })(protocol_get_prototype(definition));
78
+ return ((descriptors) => {
79
+ return ((keys) => {
80
+ return (() => {
81
+ (__eliscript_truthy(((__eliscript_value_14, __eliscript_value_15) => (__eliscript_value_14 !== __eliscript_value_15))(((keys) ?? []).length, 4)) ? protocol_fail("protocol definition must contain exactly format, version, name, and operations") : null);
82
+ return ((format, version, name, operations) => {
83
+ (__eliscript_truthy(((__eliscript_value_16, __eliscript_value_17) => (__eliscript_value_16 !== __eliscript_value_17))(format, protocol_definition_format)) ? protocol_fail((String("unsupported protocol definition format ") + String(format))) : null);
84
+ (__eliscript_truthy(((__eliscript_value_18, __eliscript_value_19) => (__eliscript_value_18 !== __eliscript_value_19))(version, protocol_definition_version)) ? protocol_fail((String("unsupported protocol definition version ") + String(version))) : null);
85
+ return ({"name": normalize_name(name, "protocol name"), "operations": normalize_protocol_operations(operations)});
86
+ })(protocol_definition_field(descriptors, "format"), protocol_definition_field(descriptors, "version"), protocol_definition_field(descriptors, "name"), protocol_definition_field(descriptors, "operations"));
87
+ })();
88
+ })(protocol_own_keys(descriptors));
89
+ })(protocol_own_descriptors(definition));
90
+ }
91
+ function operation_record(protocol, operation) {
92
+ return ((state) => {
93
+ return ((record) => {
94
+ return (__eliscript_truthy((record === undefined)) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" has no operation ") + String(operation))) : record);
95
+ })(((state)["operations"])["get"](operation));
96
+ })(protocol_state(protocol));
97
+ }
98
+ function protocol_host_category(value) {
99
+ return (__eliscript_truthy((value === null)) ? "null" : protocol_host_type(value));
100
+ }
101
+ function known_host_category_QMARK_(category) {
102
+ return ((index, found) => {
103
+ (() => {
104
+ while (__eliscript_truthy(((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? (!__eliscript_truthy(found)) : __eliscript_value_20))((index < ((protocol_host_categories) ?? []).length)))) {
105
+ (__eliscript_truthy((category === ((((protocol_host_categories) ?? [])[index]) ?? null))) ? ((found = true)) : null);
106
+ ((index = (index + 1)));
107
+ }
108
+ return null;
109
+ })();
110
+ return found;
111
+ })(0, false);
112
+ }
113
+ function normalize_implementations(protocol, implementations) {
114
+ (__eliscript_truthy(((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? __eliscript_value_21 : (!__eliscript_truthy((((__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; } })(implementations) === "object")))))((implementations === null))) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" implementations must be an object"))) : null);
115
+ return ((descriptors) => {
116
+ return ((keys) => {
117
+ return ((normalized) => {
118
+ return ((index) => {
119
+ return (() => {
120
+ (__eliscript_truthy((((keys) ?? []).length === 0)) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" extension must implement at least one operation"))) : null);
121
+ (() => {
122
+ while (__eliscript_truthy((index < ((keys) ?? []).length))) {
123
+ ((key) => {
124
+ return ((descriptor) => {
125
+ return (() => {
126
+ (__eliscript_truthy((!__eliscript_truthy((((__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; } })(key) === "string")))) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" implementation names must be strings"))) : null);
127
+ operation_record(protocol, key);
128
+ (__eliscript_truthy(((__eliscript_value_22) => (__eliscript_truthy(__eliscript_value_22) ? __eliscript_value_22 : (!__eliscript_truthy((((__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; } })((descriptor)["value"]) === "function")))))((!__eliscript_truthy(protocol_has_own(descriptor, "value"))))) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String("/") + String(key) + String(" implementation must be a function"))) : null);
129
+ return protocol_define_enumerable(normalized, key, (descriptor)["value"]);
130
+ })();
131
+ })((descriptors)[key]);
132
+ })(((((keys) ?? [])[index]) ?? null));
133
+ ((index = (index + 1)));
134
+ }
135
+ return null;
136
+ })();
137
+ return protocol_freeze(normalized);
138
+ })();
139
+ })(0);
140
+ })(protocol_null_object());
141
+ })(protocol_own_keys(descriptors));
142
+ })(protocol_own_descriptors(implementations));
143
+ }
144
+ function merge_implementations(current, incoming) {
145
+ return ((merged, copy) => {
146
+ ((copy = (source) => {
147
+ return (__eliscript_truthy((!__eliscript_truthy((source == null)))) ? ((keys, index) => {
148
+ return (() => {
149
+ while (__eliscript_truthy((index < ((keys) ?? []).length))) {
150
+ ((key) => {
151
+ return protocol_define_enumerable(merged, key, (source)[key]);
152
+ })(((((keys) ?? [])[index]) ?? null));
153
+ ((index = (index + 1)));
154
+ }
155
+ return null;
156
+ })();
157
+ })(Object.keys((source) ?? {}), 0) : null);
158
+ }));
159
+ copy(current);
160
+ copy(incoming);
161
+ return protocol_freeze(merged);
162
+ })(protocol_null_object(), null);
163
+ }
164
+ function direct_method(record, receiver) {
165
+ return (__eliscript_truthy(((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? __eliscript_value_23 : (receiver === undefined)))((receiver === null))) ? protocol_missing : ((slot) => {
166
+ return (__eliscript_truthy((!__eliscript_truthy(protocol_property_present(receiver, slot)))) ? protocol_missing : ((method) => {
167
+ return (__eliscript_truthy((((__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; } })(method) === "function")) ? method : null);
168
+ })(protocol_property_value(receiver, slot)));
169
+ })((record)["slot"]));
170
+ }
171
+ function external_method(state, record, receiver) {
172
+ return ((prototype) => {
173
+ return ((exact_implementations) => {
174
+ return ((exact) => {
175
+ return (__eliscript_truthy((!__eliscript_truthy((exact === undefined)))) ? exact : ((category_implementations) => {
176
+ return ((category) => {
177
+ return (__eliscript_truthy((!__eliscript_truthy((category === undefined)))) ? category : (((state)["defaults"])[(record)["name"]] ?? protocol_missing));
178
+ })((__eliscript_truthy((category_implementations === undefined)) ? undefined : ((category_implementations)[(record)["name"]] ?? undefined)));
179
+ })(((state)["categories"])["get"](protocol_host_category(receiver))));
180
+ })((__eliscript_truthy((exact_implementations === undefined)) ? undefined : ((exact_implementations)[(record)["name"]] ?? undefined)));
181
+ })((__eliscript_truthy((prototype === protocol_missing)) ? undefined : ((state)["types"])["get"](prototype)));
182
+ })(protocol_exact_prototype(receiver, protocol_missing));
183
+ }
184
+ function dispatch(protocol, record, receiver, arguments$) {
185
+ return ((direct) => {
186
+ (__eliscript_truthy((direct === null)) ? ((__eliscript_value_24) => { throw __eliscript_value_24; })(new ProtocolDispatchError(protocol, (record)["name"], receiver, "invalid-direct-slot")) : null);
187
+ return (__eliscript_truthy(((__eliscript_value_25, __eliscript_value_26) => (__eliscript_value_25 !== __eliscript_value_26))(direct, protocol_missing)) ? (direct)["apply"](receiver, arguments$) : ((external) => {
188
+ return (__eliscript_truthy((external === protocol_missing)) ? ((__eliscript_value_27) => { throw __eliscript_value_27; })(new ProtocolDispatchError(protocol, (record)["name"], receiver)) : external(...[receiver, ...((arguments$) ?? [])]));
189
+ })(external_method(protocol_state(protocol), record, receiver)));
190
+ })(direct_method(record, receiver));
191
+ }
192
+ function define_protocol(name, operations) {
193
+ return ((protocol_name, protocol_operations) => {
194
+ return ((records, operation_table, protocol, index) => {
195
+ (() => {
196
+ while (__eliscript_truthy((index < ((protocol_operations) ?? []).length))) {
197
+ ((operation) => {
198
+ (__eliscript_truthy((records)["has"](operation)) ? protocol_fail((String("protocol ") + String(protocol_name) + String(" declares duplicate operation ") + String(operation))) : null);
199
+ return ((slot) => {
200
+ return ((method) => {
201
+ return ((record) => {
202
+ return (() => {
203
+ (records)["set"](operation, record);
204
+ return protocol_define_enumerable(operation_table, operation, method);
205
+ })();
206
+ })(({"name": operation, "slot": slot, "method": method}));
207
+ })((...invocation) => {
208
+ (__eliscript_truthy((((invocation) ?? []).length === 0)) ? protocol_fail((String("protocol ") + String(protocol_name) + String("/") + String(operation) + String(" requires a dispatch value"))) : null);
209
+ return dispatch(protocol, (records)["get"](operation), (invocation)[0], (invocation)["slice"](1));
210
+ });
211
+ })(protocol_symbol((String("eliscript.protocol.") + String(protocol_name) + String("/") + String(operation))));
212
+ })(((((protocol_operations) ?? [])[index]) ?? null));
213
+ ((index = (index + 1)));
214
+ }
215
+ return null;
216
+ })();
217
+ ((protocol = protocol_freeze(({"name": protocol_name, "operations": protocol_freeze(operation_table)}))));
218
+ ((index = 0));
219
+ (() => {
220
+ while (__eliscript_truthy((index < ((protocol_operations) ?? []).length))) {
221
+ ((operation) => {
222
+ return ((record) => {
223
+ return ((method) => {
224
+ return (() => {
225
+ protocol_define_metadata(method, protocol, operation, (record)["slot"]);
226
+ protocol_freeze(method);
227
+ return protocol_freeze(record);
228
+ })();
229
+ })((record)["method"]);
230
+ })((records)["get"](operation));
231
+ })(((((protocol_operations) ?? [])[index]) ?? null));
232
+ ((index = (index + 1)));
233
+ }
234
+ return null;
235
+ })();
236
+ (protocol_states)["set"](protocol, ({"operations": records, "types": protocol_map(), "categories": protocol_map(), "defaults": protocol_freeze(protocol_null_object())}));
237
+ return protocol;
238
+ })(protocol_map(), protocol_null_object(), null, 0);
239
+ })(normalize_name(name, "protocol name"), normalize_protocol_operations(operations));
240
+ }
241
+ function protocol_definition(protocol) {
242
+ protocol_state(protocol);
243
+ return ((operations) => {
244
+ protocol_freeze(operations);
245
+ return protocol_freeze(({"format": protocol_definition_format, "version": protocol_definition_version, "name": (protocol)["name"], "operations": operations}));
246
+ })((Object.keys(((protocol)["operations"]) ?? {}))["slice"]());
247
+ }
248
+ function define_protocol_from_definition(definition) {
249
+ return ((normalized) => {
250
+ return define_protocol((normalized)["name"], (normalized)["operations"]);
251
+ })(normalize_protocol_definition(definition));
252
+ }
253
+ function protocol_method(protocol, operation) {
254
+ return (operation_record(protocol, operation))["method"];
255
+ }
256
+ function protocol_slot(protocol, operation) {
257
+ return (operation_record(protocol, operation))["slot"];
258
+ }
259
+ function extend_protocol_type(protocol, constructor, implementations) {
260
+ return ((state) => {
261
+ (__eliscript_truthy((!__eliscript_truthy((((__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; } })(constructor) === "function")))) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" exact type must be a constructor with a prototype"))) : null);
262
+ return ((prototype) => {
263
+ (__eliscript_truthy(((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? __eliscript_value_28 : (!__eliscript_truthy((((__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; } })(prototype) === "object")))))((prototype === null))) ? protocol_fail((String("protocol ") + String((protocol)["name"]) + String(" exact type must be a constructor with a prototype"))) : null);
264
+ ((normalized) => {
265
+ return ((current) => {
266
+ return ((state)["types"])["set"](prototype, merge_implementations(current, normalized));
267
+ })(((state)["types"])["get"](prototype));
268
+ })(normalize_implementations(protocol, implementations));
269
+ return protocol;
270
+ })(((constructor)["prototype"] ?? null));
271
+ })(protocol_state(protocol));
272
+ }
273
+ function extend_protocol_category(protocol, category, implementations) {
274
+ return ((state) => {
275
+ (__eliscript_truthy((!__eliscript_truthy(known_host_category_QMARK_(category)))) ? protocol_fail((String("unknown protocol host category ") + String(category))) : null);
276
+ ((normalized) => {
277
+ return ((current) => {
278
+ return ((state)["categories"])["set"](category, merge_implementations(current, normalized));
279
+ })(((state)["categories"])["get"](category));
280
+ })(normalize_implementations(protocol, implementations));
281
+ return protocol;
282
+ })(protocol_state(protocol));
283
+ }
284
+ function extend_protocol_default(protocol, implementations) {
285
+ return ((state) => {
286
+ return ((normalized) => {
287
+ return (() => {
288
+ ((state)["defaults"] = merge_implementations((state)["defaults"], normalized));
289
+ return protocol;
290
+ })();
291
+ })(normalize_implementations(protocol, implementations));
292
+ })(protocol_state(protocol));
293
+ }
294
+ function implements_protocol_operation_QMARK_(protocol, operation, value) {
295
+ return ((record) => {
296
+ return ((direct) => {
297
+ return ((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? ((__eliscript_value_30) => (__eliscript_truthy(__eliscript_value_30) ? __eliscript_value_30 : ((__eliscript_value_33, __eliscript_value_34) => (__eliscript_value_33 !== __eliscript_value_34))(external_method(protocol_state(protocol), record, value), protocol_missing)))(((__eliscript_value_31, __eliscript_value_32) => (__eliscript_value_31 !== __eliscript_value_32))(direct, protocol_missing)) : __eliscript_value_29))((!__eliscript_truthy((direct === null))));
298
+ })(direct_method(record, value));
299
+ })(operation_record(protocol, operation));
300
+ }
301
+ function implements_protocol_QMARK_(protocol, value) {
302
+ return ((state) => {
303
+ return ((operations) => {
304
+ return ((index) => {
305
+ return ((implemented) => {
306
+ return (() => {
307
+ (() => {
308
+ while (__eliscript_truthy(((__eliscript_value_35) => (__eliscript_truthy(__eliscript_value_35) ? implemented : __eliscript_value_35))((index < ((operations) ?? []).length)))) {
309
+ ((record) => {
310
+ return ((direct) => {
311
+ return (__eliscript_truthy(((__eliscript_value_36) => (__eliscript_truthy(__eliscript_value_36) ? __eliscript_value_36 : ((__eliscript_value_37) => (__eliscript_truthy(__eliscript_value_37) ? (external_method(state, record, value) === protocol_missing) : __eliscript_value_37))((direct === protocol_missing))))((direct === null))) ? ((implemented = false)) : null);
312
+ })(direct_method(record, value));
313
+ })(((state)["operations"])["get"](((((operations) ?? [])[index]) ?? null)));
314
+ ((index = (index + 1)));
315
+ }
316
+ return null;
317
+ })();
318
+ return implemented;
319
+ })();
320
+ })(true);
321
+ })(0);
322
+ })(Object.keys(((protocol)["operations"]) ?? {}));
323
+ })(protocol_state(protocol));
324
+ }
325
+ export {define_protocol, define_protocol_from_definition, extend_protocol_category, extend_protocol_default, extend_protocol_type, implements_protocol_operation_QMARK_, implements_protocol_QMARK_, protocol_definition, protocol_host_category, protocol_method, protocol_slot};
326
+ //# sourceMappingURL=protocol-impl.mjs.map