@calcit/procs 0.13.1 → 0.13.2
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/.yarn/install-state.gz +0 -0
- package/editing-history/202608061714-struct-enum-data-model-v2.md +39 -0
- package/editing-history/202608061731-release-0.13.2.md +18 -0
- package/history/202608061433-required-record-field-access.md +32 -0
- package/lib/calcit-data.mjs +24 -24
- package/lib/calcit.procs.d.mts +43 -43
- package/lib/calcit.procs.mjs +165 -168
- package/lib/custom-formatter.mjs +23 -38
- package/lib/js-cirru.mjs +25 -25
- package/lib/js-enum-def.d.mts +11 -0
- package/lib/{js-enum.mjs → js-enum-def.mjs} +3 -3
- package/lib/{js-tuple.d.mts → js-enum-value.d.mts} +6 -7
- package/lib/{js-tuple.mjs → js-enum-value.mjs} +8 -15
- package/lib/js-list.mjs +6 -6
- package/lib/js-primes.d.mts +5 -5
- package/lib/js-primes.mjs +16 -16
- package/lib/{js-struct.d.mts → js-struct-def.d.mts} +2 -2
- package/lib/{js-struct.mjs → js-struct-def.mjs} +6 -6
- package/lib/{js-record.d.mts → js-struct-value.d.mts} +16 -15
- package/lib/{js-record.mjs → js-struct-value.mjs} +67 -59
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit-data.mts +24 -24
- package/ts-src/calcit.procs.mts +165 -168
- package/ts-src/custom-formatter.mts +28 -56
- package/ts-src/js-cirru.mts +26 -26
- package/ts-src/{js-enum.mts → js-enum-def.mts} +7 -7
- package/ts-src/{js-tuple.mts → js-enum-value.mts} +12 -19
- package/ts-src/js-list.mts +6 -6
- package/ts-src/js-primes.mts +16 -16
- package/ts-src/{js-struct.mts → js-struct-def.mts} +7 -7
- package/ts-src/{js-record.mts → js-struct-value.mts} +72 -66
- package/lib/js-enum.d.mts +0 -11
package/lib/calcit.procs.mjs
CHANGED
|
@@ -5,21 +5,21 @@ import { parse } from "@cirru/parser.ts";
|
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
6
6
|
import { CalcitSymbol, CalcitTag, CalcitRecur, castTag, newTag, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
|
|
7
7
|
import { CalcitRef, atom } from "./js-ref.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { CalcitStructValue } from "./js-struct-value.mjs";
|
|
9
9
|
import { CalcitImpl } from "./js-impl.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { CalcitStructDef } from "./js-struct-def.mjs";
|
|
11
|
+
import { CalcitEnumDef } from "./js-enum-def.mjs";
|
|
12
12
|
import { CalcitTrait } from "./js-trait.mjs";
|
|
13
13
|
export * from "./calcit-data.mjs";
|
|
14
|
-
export * from "./js-
|
|
14
|
+
export * from "./js-struct-value.mjs";
|
|
15
15
|
export * from "./js-impl.mjs";
|
|
16
|
-
export * from "./js-struct.mjs";
|
|
17
|
-
export * from "./js-enum.mjs";
|
|
16
|
+
export * from "./js-struct-def.mjs";
|
|
17
|
+
export * from "./js-enum-def.mjs";
|
|
18
18
|
export * from "./js-map.mjs";
|
|
19
19
|
export * from "./js-list.mjs";
|
|
20
20
|
export * from "./js-set.mjs";
|
|
21
21
|
export * from "./js-primes.mjs";
|
|
22
|
-
export * from "./js-
|
|
22
|
+
export * from "./js-enum-value.mjs";
|
|
23
23
|
export * from "./js-trait.mjs";
|
|
24
24
|
export * from "./custom-formatter.mjs";
|
|
25
25
|
export * from "./js-cirru.mjs";
|
|
@@ -30,7 +30,7 @@ export { _$n_compare } from "./js-primes.mjs";
|
|
|
30
30
|
import { CalcitList, CalcitSliceList, foldl } from "./js-list.mjs";
|
|
31
31
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
32
32
|
import { CalcitSet } from "./js-set.mjs";
|
|
33
|
-
import {
|
|
33
|
+
import { CalcitEnumValue } from "./js-enum-value.mjs";
|
|
34
34
|
import { to_calcit_data, extract_cirru_edn, extract_cirru_edn_for_typed, CalcitCirruQuote } from "./js-cirru.mjs";
|
|
35
35
|
import { TypedEdnSetView } from "./typed-edn.mjs";
|
|
36
36
|
let inNodeJs = typeof process !== "undefined" && process?.release?.name === "node";
|
|
@@ -56,8 +56,8 @@ export let type_of = (x) => {
|
|
|
56
56
|
if (x instanceof CalcitRef) {
|
|
57
57
|
return newTag("ref");
|
|
58
58
|
}
|
|
59
|
-
if (x instanceof
|
|
60
|
-
return newTag("
|
|
59
|
+
if (x instanceof CalcitEnumValue) {
|
|
60
|
+
return newTag("enum");
|
|
61
61
|
}
|
|
62
62
|
if (x instanceof CalcitSymbol) {
|
|
63
63
|
return newTag("symbol");
|
|
@@ -65,17 +65,17 @@ export let type_of = (x) => {
|
|
|
65
65
|
if (x instanceof CalcitSet) {
|
|
66
66
|
return newTag("set");
|
|
67
67
|
}
|
|
68
|
-
if (x instanceof
|
|
69
|
-
return newTag("
|
|
68
|
+
if (x instanceof CalcitStructValue) {
|
|
69
|
+
return newTag("struct");
|
|
70
70
|
}
|
|
71
71
|
if (x instanceof CalcitImpl) {
|
|
72
72
|
return newTag("impl");
|
|
73
73
|
}
|
|
74
|
-
if (x instanceof
|
|
75
|
-
return newTag("struct");
|
|
74
|
+
if (x instanceof CalcitStructDef) {
|
|
75
|
+
return newTag("struct-def");
|
|
76
76
|
}
|
|
77
|
-
if (x instanceof
|
|
78
|
-
return newTag("enum");
|
|
77
|
+
if (x instanceof CalcitEnumDef) {
|
|
78
|
+
return newTag("enum-def");
|
|
79
79
|
}
|
|
80
80
|
if (x instanceof CalcitTrait) {
|
|
81
81
|
return newTag("trait");
|
|
@@ -185,7 +185,7 @@ export let _$n_assert_traits = function (value, traitDef) {
|
|
|
185
185
|
throw new Error(`&assert-traits cannot resolve impls for: ${toString(value, true)}`);
|
|
186
186
|
}
|
|
187
187
|
const impls = pair[0];
|
|
188
|
-
const reverse = value instanceof
|
|
188
|
+
const reverse = value instanceof CalcitStructValue || value instanceof CalcitEnumValue || value instanceof CalcitStructDef || value instanceof CalcitEnumDef;
|
|
189
189
|
const ordered = reverse ? [...impls].reverse() : impls;
|
|
190
190
|
const selected = ordered.find((impl) => impl != null && impl.origin === traitDef);
|
|
191
191
|
if (selected == null) {
|
|
@@ -222,7 +222,7 @@ export let defstruct = (name, ...entries) => {
|
|
|
222
222
|
}
|
|
223
223
|
const fieldTags = fields.map((entry) => entry.tag);
|
|
224
224
|
const fieldTypes = fields.map((entry) => entry.type);
|
|
225
|
-
return new
|
|
225
|
+
return new CalcitStructDef(structName, fieldTags, fieldTypes, null);
|
|
226
226
|
};
|
|
227
227
|
export let defenum = (name, ...variants) => {
|
|
228
228
|
const enumName = castTag(name);
|
|
@@ -245,8 +245,8 @@ export let defenum = (name, ...variants) => {
|
|
|
245
245
|
}
|
|
246
246
|
const tags = entries.map((entry) => entry.tag);
|
|
247
247
|
const values = entries.map((entry) => entry.payload);
|
|
248
|
-
const prototype = new
|
|
249
|
-
return new
|
|
248
|
+
const prototype = new CalcitStructValue(enumName, tags, values, null);
|
|
249
|
+
return new CalcitEnumDef(prototype);
|
|
250
250
|
};
|
|
251
251
|
export let _$n_impl_$o__$o_new = (name, ...pairs) => {
|
|
252
252
|
if (name === undefined)
|
|
@@ -257,13 +257,13 @@ export let _$n_impl_$o__$o_new = (name, ...pairs) => {
|
|
|
257
257
|
let sourcePairs = pairs;
|
|
258
258
|
if (pairs.length === 1 && pairs[0] instanceof CalcitImpl) {
|
|
259
259
|
const sourceImpl = pairs[0];
|
|
260
|
-
sourcePairs = sourceImpl.fields.map((field, idx) => new
|
|
260
|
+
sourcePairs = sourceImpl.fields.map((field, idx) => new CalcitEnumValue(newTag(field.value), [sourceImpl.values[idx]], null));
|
|
261
261
|
}
|
|
262
262
|
for (let idx = 0; idx < sourcePairs.length; idx++) {
|
|
263
263
|
const pairValue = sourcePairs[idx];
|
|
264
264
|
let fieldTag;
|
|
265
265
|
let value;
|
|
266
|
-
if (pairValue instanceof
|
|
266
|
+
if (pairValue instanceof CalcitEnumValue) {
|
|
267
267
|
if (pairValue.extra.length !== 1) {
|
|
268
268
|
throw new Error(`&impl::new expects (field value) pairs, got: ${toString(pairValue, true)}`);
|
|
269
269
|
}
|
|
@@ -307,10 +307,10 @@ export let _$n_impl_$o__$o_new = (name, ...pairs) => {
|
|
|
307
307
|
}
|
|
308
308
|
return new CalcitImpl(implName, fields, values, origin);
|
|
309
309
|
};
|
|
310
|
-
export let _$
|
|
310
|
+
export let _$n_struct_def_$o_new = (name, ...entries) => {
|
|
311
311
|
return defstruct(name, ...entries);
|
|
312
312
|
};
|
|
313
|
-
export let _$
|
|
313
|
+
export let _$n_enum_def_$o_new = (name, ...variants) => {
|
|
314
314
|
return defenum(name, ...variants);
|
|
315
315
|
};
|
|
316
316
|
export let print = (...xs) => {
|
|
@@ -332,25 +332,25 @@ export function _$n_map_$o_count(x) {
|
|
|
332
332
|
return x.len();
|
|
333
333
|
throw new Error(`expected a map ${x}`);
|
|
334
334
|
}
|
|
335
|
-
export function _$
|
|
336
|
-
if (x instanceof
|
|
335
|
+
export function _$n_struct_$o_count(x) {
|
|
336
|
+
if (x instanceof CalcitStructValue)
|
|
337
337
|
return x.fields.length;
|
|
338
|
-
throw new Error(`expected a
|
|
338
|
+
throw new Error(`expected a struct value ${x}`);
|
|
339
339
|
}
|
|
340
|
-
export function _$
|
|
341
|
-
if (!(x instanceof
|
|
342
|
-
throw new Error(`&
|
|
340
|
+
export function _$n_struct_$o_field_tag(x, idx) {
|
|
341
|
+
if (!(x instanceof CalcitStructValue))
|
|
342
|
+
throw new Error(`&struct:field-tag expected a struct value, got ${x}`);
|
|
343
343
|
const i = idx;
|
|
344
344
|
if (i < 0 || i >= x.fields.length)
|
|
345
|
-
throw new Error(`&
|
|
345
|
+
throw new Error(`&struct:field-tag index ${i} out of bounds (${x.fields.length})`);
|
|
346
346
|
return x.fields[i];
|
|
347
347
|
}
|
|
348
|
-
export function _$
|
|
349
|
-
if (!(x instanceof
|
|
350
|
-
throw new Error(`&
|
|
348
|
+
export function _$n_struct_$o_nth(x, idx) {
|
|
349
|
+
if (!(x instanceof CalcitStructValue))
|
|
350
|
+
throw new Error(`&struct:nth expected a struct value, got ${x}`);
|
|
351
351
|
const i = idx;
|
|
352
352
|
if (i < 0 || i >= x.values.length)
|
|
353
|
-
throw new Error(`&
|
|
353
|
+
throw new Error(`&struct:nth index ${i} out of range for struct with ${x.values.length} fields`);
|
|
354
354
|
return x.values[i];
|
|
355
355
|
}
|
|
356
356
|
export function _$n_set_$o_count(x) {
|
|
@@ -434,10 +434,10 @@ export let _$n_map_$o_contains_$q_ = (xs, x) => {
|
|
|
434
434
|
return xs.contains(x);
|
|
435
435
|
throw new Error("map `contains?` expected a map");
|
|
436
436
|
};
|
|
437
|
-
export let _$
|
|
438
|
-
if (xs instanceof
|
|
437
|
+
export let _$n_struct_$o_contains_$q_ = (xs, x) => {
|
|
438
|
+
if (xs instanceof CalcitStructValue)
|
|
439
439
|
return xs.contains(x);
|
|
440
|
-
throw new Error("
|
|
440
|
+
throw new Error("struct `contains?` expected a struct value");
|
|
441
441
|
};
|
|
442
442
|
export let _$n_str_$o_includes_$q_ = (xs, x) => {
|
|
443
443
|
if (typeof xs === "string") {
|
|
@@ -497,19 +497,19 @@ export let _$n_list_$o_nth = function (xs, k) {
|
|
|
497
497
|
return xs.get(k);
|
|
498
498
|
throw new Error("Does not support `nth` on this type");
|
|
499
499
|
};
|
|
500
|
-
export let _$
|
|
500
|
+
export let _$n_enum_$o_nth = function (xs, k) {
|
|
501
501
|
if (arguments.length !== 2)
|
|
502
502
|
throw new Error("nth takes 2 arguments");
|
|
503
503
|
if (typeof k !== "number")
|
|
504
504
|
throw new Error("Expected number index for a list");
|
|
505
|
-
if (xs instanceof
|
|
505
|
+
if (xs instanceof CalcitEnumValue)
|
|
506
506
|
return xs.get(k);
|
|
507
507
|
throw new Error("Does not support `nth` on this type");
|
|
508
508
|
};
|
|
509
|
-
export let _$
|
|
509
|
+
export let _$n_enum_$o_count = function (xs) {
|
|
510
510
|
if (arguments.length !== 1)
|
|
511
|
-
throw new Error("&
|
|
512
|
-
if (xs instanceof
|
|
511
|
+
throw new Error("&enum:count takes 1 arguments");
|
|
512
|
+
if (xs instanceof CalcitEnumValue)
|
|
513
513
|
return xs.count();
|
|
514
514
|
throw new Error("Does not support `count` on this type");
|
|
515
515
|
};
|
|
@@ -519,63 +519,60 @@ const coerce_impl = (value, procName) => {
|
|
|
519
519
|
}
|
|
520
520
|
throw new Error(`${procName} expects trait impls as impls`);
|
|
521
521
|
};
|
|
522
|
-
export let _$
|
|
522
|
+
export let _$n_enum_$o_impls = function (x) {
|
|
523
523
|
if (arguments.length !== 1)
|
|
524
|
-
throw new Error("&
|
|
524
|
+
throw new Error("&enum:impls takes 1 argument");
|
|
525
525
|
return new CalcitSliceList(x.impls);
|
|
526
526
|
};
|
|
527
|
-
export let _$
|
|
527
|
+
export let _$n_enum_$o_params = function (x) {
|
|
528
528
|
if (arguments.length !== 1)
|
|
529
|
-
throw new Error("&
|
|
529
|
+
throw new Error("&enum:params takes 1 argument");
|
|
530
530
|
return new CalcitSliceList(x.extra);
|
|
531
531
|
};
|
|
532
|
-
export let _$
|
|
532
|
+
export let _$n_enum_$o_with_impls = function (x, y) {
|
|
533
533
|
if (arguments.length !== 2)
|
|
534
|
-
throw new Error("&
|
|
535
|
-
if (!(x instanceof
|
|
536
|
-
throw new Error("&
|
|
537
|
-
const impl = coerce_impl(y, "&
|
|
534
|
+
throw new Error("&enum:with-impls takes 2 arguments");
|
|
535
|
+
if (!(x instanceof CalcitEnumValue))
|
|
536
|
+
throw new Error("&enum:with-impls expects an enum value");
|
|
537
|
+
const impl = coerce_impl(y, "&enum:with-impls");
|
|
538
538
|
let proto = x.enumPrototype;
|
|
539
539
|
if (proto == null) {
|
|
540
|
-
proto = new
|
|
540
|
+
proto = new CalcitEnumDef(new CalcitStructValue(newTag("_"), [], [], new CalcitStructDef(newTag("_"), [], [])));
|
|
541
541
|
}
|
|
542
|
-
return new
|
|
542
|
+
return new CalcitEnumValue(x.tag, x.extra, proto.withImpls(impl));
|
|
543
543
|
};
|
|
544
|
-
export let _$
|
|
544
|
+
export let _$n_enum_$o_impl_traits = function (x, ...traits) {
|
|
545
545
|
if (traits.length < 1)
|
|
546
|
-
throw new Error("&
|
|
547
|
-
if (!(x instanceof
|
|
548
|
-
throw new Error("&
|
|
549
|
-
const impls = traits.map((trait) => coerce_impl(trait, "&
|
|
546
|
+
throw new Error("&enum:impl-traits takes 2+ arguments");
|
|
547
|
+
if (!(x instanceof CalcitEnumValue))
|
|
548
|
+
throw new Error("&enum:impl-traits expects an enum value");
|
|
549
|
+
const impls = traits.map((trait) => coerce_impl(trait, "&enum:impl-traits"));
|
|
550
550
|
let proto = x.enumPrototype;
|
|
551
551
|
if (proto == null) {
|
|
552
552
|
const tagName = x.tag instanceof CalcitTag ? x.tag : newTag("tag");
|
|
553
553
|
const anyTypes = new CalcitSliceList(new Array(x.extra.length).fill(newTag("any")));
|
|
554
|
-
proto = new
|
|
554
|
+
proto = new CalcitEnumDef(new CalcitStructValue(newTag("_"), [tagName], [anyTypes], new CalcitStructDef(newTag("_"), [tagName], [anyTypes])));
|
|
555
555
|
}
|
|
556
|
-
return new
|
|
556
|
+
return new CalcitEnumValue(x.tag, x.extra, proto.withImpls(impls));
|
|
557
557
|
};
|
|
558
|
-
export let _$
|
|
558
|
+
export let _$n_enum_$o_definition = function (x) {
|
|
559
559
|
if (arguments.length !== 1)
|
|
560
|
-
throw new Error("&
|
|
561
|
-
if (!(x instanceof
|
|
562
|
-
throw new Error("&
|
|
560
|
+
throw new Error("&enum:definition takes 1 argument");
|
|
561
|
+
if (!(x instanceof CalcitEnumValue))
|
|
562
|
+
throw new Error("&enum:definition expects an enum value");
|
|
563
563
|
if (x.enumPrototype == null) {
|
|
564
564
|
return null;
|
|
565
565
|
}
|
|
566
|
-
|
|
567
|
-
return x.enumPrototype;
|
|
568
|
-
}
|
|
569
|
-
return new CalcitEnum(x.enumPrototype);
|
|
566
|
+
return x.enumPrototype;
|
|
570
567
|
};
|
|
571
568
|
const unwrap_enum_prototype = (enumPrototype, procName) => {
|
|
572
|
-
if (enumPrototype instanceof
|
|
569
|
+
if (enumPrototype instanceof CalcitEnumDef) {
|
|
573
570
|
return enumPrototype.prototype;
|
|
574
571
|
}
|
|
575
|
-
if (enumPrototype instanceof
|
|
576
|
-
|
|
572
|
+
if (enumPrototype instanceof CalcitStructValue) {
|
|
573
|
+
throw new Error(`${procName} no longer accepts a struct prototype; pass an EnumDef produced by defenum`);
|
|
577
574
|
}
|
|
578
|
-
throw new Error(`${procName} expects
|
|
575
|
+
throw new Error(`${procName} expects an EnumDef as first argument`);
|
|
579
576
|
};
|
|
580
577
|
const assert_enum_tag_args = (procName, enumPrototype, variantTag) => {
|
|
581
578
|
const proto = unwrap_enum_prototype(enumPrototype, procName);
|
|
@@ -584,17 +581,17 @@ const assert_enum_tag_args = (procName, enumPrototype, variantTag) => {
|
|
|
584
581
|
}
|
|
585
582
|
return proto;
|
|
586
583
|
};
|
|
587
|
-
export let _$
|
|
584
|
+
export let _$n_enum_def_$o_has_variant_$q_ = function (enumPrototype, variantTag) {
|
|
588
585
|
if (arguments.length !== 2)
|
|
589
|
-
throw new Error("&
|
|
590
|
-
const proto = assert_enum_tag_args("&
|
|
586
|
+
throw new Error("&enum-def:has-variant? takes 2 arguments");
|
|
587
|
+
const proto = assert_enum_tag_args("&enum-def:has-variant?", enumPrototype, variantTag);
|
|
591
588
|
return proto.contains(variantTag);
|
|
592
589
|
};
|
|
593
|
-
export let _$
|
|
594
|
-
export let _$
|
|
590
|
+
export let _$n_enum_def_$o_has_variant = _$n_enum_def_$o_has_variant_$q_;
|
|
591
|
+
export let _$n_enum_def_$o_variant_arity = function (enumPrototype, variantTag) {
|
|
595
592
|
if (arguments.length !== 2)
|
|
596
|
-
throw new Error("&
|
|
597
|
-
const proto = assert_enum_tag_args("&
|
|
593
|
+
throw new Error("&enum-def:variant-arity takes 2 arguments");
|
|
594
|
+
const proto = assert_enum_tag_args("&enum-def:variant-arity", enumPrototype, variantTag);
|
|
598
595
|
const variant = proto.getOrNil(variantTag);
|
|
599
596
|
if (variant === undefined) {
|
|
600
597
|
throw new Error(`Variant ${variantTag.value} not found in enum ${proto.name.value}`);
|
|
@@ -604,36 +601,36 @@ export let _$n_tuple_$o_enum_variant_arity = function (enumPrototype, variantTag
|
|
|
604
601
|
}
|
|
605
602
|
throw new Error("Expected variant to be a list");
|
|
606
603
|
};
|
|
607
|
-
export let _$
|
|
604
|
+
export let _$n_enum_$o_validate = function (enumValue, tag) {
|
|
608
605
|
if (arguments.length !== 2)
|
|
609
|
-
throw new Error("&
|
|
610
|
-
if (!(
|
|
611
|
-
throw new Error("&
|
|
612
|
-
if (
|
|
606
|
+
throw new Error("&enum:validate takes 2 arguments");
|
|
607
|
+
if (!(enumValue instanceof CalcitEnumValue))
|
|
608
|
+
throw new Error("&enum:validate expects an enum value as first argument");
|
|
609
|
+
if (enumValue.enumPrototype == null) {
|
|
613
610
|
return null;
|
|
614
611
|
}
|
|
615
|
-
const proto = assert_enum_tag_args("&
|
|
612
|
+
const proto = assert_enum_tag_args("&enum:validate", enumValue.enumPrototype, tag);
|
|
616
613
|
const tagValue = tag;
|
|
617
614
|
const variant = proto.getOrNil(tagValue);
|
|
618
615
|
if (variant === undefined) {
|
|
619
|
-
throw new Error(`enum does not have variant ${tagValue.value} for ${
|
|
616
|
+
throw new Error(`enum does not have variant ${tagValue.value} for ${enumValue}`);
|
|
620
617
|
}
|
|
621
618
|
if (variant instanceof CalcitSliceList) {
|
|
622
619
|
const expected = variant.len();
|
|
623
|
-
const actual =
|
|
620
|
+
const actual = enumValue.extra.length;
|
|
624
621
|
if (expected !== actual) {
|
|
625
|
-
throw new Error(`enum variant expects ${expected} payload(s), got ${actual} for ${
|
|
622
|
+
throw new Error(`enum variant expects ${expected} payload(s), got ${actual} for ${enumValue}`);
|
|
626
623
|
}
|
|
627
624
|
return null;
|
|
628
625
|
}
|
|
629
626
|
throw new Error("Expected variant to be a list");
|
|
630
627
|
};
|
|
631
|
-
export let _$
|
|
628
|
+
export let _$n_struct_$o_get = function (xs, k) {
|
|
632
629
|
if (arguments.length !== 2) {
|
|
633
|
-
throw new Error("
|
|
630
|
+
throw new Error("&struct:get takes 2 arguments");
|
|
634
631
|
}
|
|
635
|
-
if (xs instanceof
|
|
636
|
-
return xs.
|
|
632
|
+
if (xs instanceof CalcitStructValue)
|
|
633
|
+
return xs.getRequired(k);
|
|
637
634
|
throw new Error("Does not support `&get` on this type");
|
|
638
635
|
};
|
|
639
636
|
export let _$n_list_$o_assoc = function (xs, k, v) {
|
|
@@ -647,16 +644,16 @@ export let _$n_list_$o_assoc = function (xs, k, v) {
|
|
|
647
644
|
}
|
|
648
645
|
throw new Error("list `assoc` expected a list");
|
|
649
646
|
};
|
|
650
|
-
export let _$
|
|
647
|
+
export let _$n_enum_$o_assoc = function (xs, k, v) {
|
|
651
648
|
if (arguments.length !== 3)
|
|
652
649
|
throw new Error("assoc takes 3 arguments");
|
|
653
|
-
if (xs instanceof
|
|
650
|
+
if (xs instanceof CalcitEnumValue) {
|
|
654
651
|
if (typeof k !== "number") {
|
|
655
652
|
throw new Error("Expected number index for lists");
|
|
656
653
|
}
|
|
657
654
|
return xs.assoc(k, v);
|
|
658
655
|
}
|
|
659
|
-
throw new Error("
|
|
656
|
+
throw new Error("enum `assoc` expected an enum value");
|
|
660
657
|
};
|
|
661
658
|
export let _$n_map_$o_assoc = function (xs, ...args) {
|
|
662
659
|
if (arguments.length < 3)
|
|
@@ -667,50 +664,46 @@ export let _$n_map_$o_assoc = function (xs, ...args) {
|
|
|
667
664
|
return xs.assoc(...args);
|
|
668
665
|
throw new Error("map `assoc` expected a map");
|
|
669
666
|
};
|
|
670
|
-
export let _$
|
|
667
|
+
export let _$n_struct_$o_assoc = function (xs, k, v) {
|
|
671
668
|
if (arguments.length !== 3)
|
|
672
669
|
throw new Error("assoc takes 3 arguments");
|
|
673
|
-
if (xs instanceof
|
|
670
|
+
if (xs instanceof CalcitStructValue)
|
|
674
671
|
return xs.assoc(k, v);
|
|
675
|
-
throw new Error("
|
|
672
|
+
throw new Error("struct `assoc` expected a struct value");
|
|
676
673
|
};
|
|
677
|
-
export let _$
|
|
674
|
+
export let _$n_struct_$o_impls = function (xs) {
|
|
678
675
|
if (arguments.length !== 1)
|
|
679
|
-
throw new Error("&
|
|
680
|
-
if (xs instanceof
|
|
676
|
+
throw new Error("&struct:impls takes 1 argument");
|
|
677
|
+
if (xs instanceof CalcitStructValue)
|
|
681
678
|
return new CalcitSliceList(xs.structRef.impls);
|
|
682
|
-
throw new Error("&
|
|
683
|
-
};
|
|
684
|
-
export let _$n_record_$o_impl_traits = function (xs, ...traits) {
|
|
685
|
-
if (traits.length < 1)
|
|
686
|
-
throw new Error("&record:impl-traits takes 2+ arguments");
|
|
687
|
-
if (!(xs instanceof CalcitRecord))
|
|
688
|
-
throw new Error("&record:impl-traits expected a record");
|
|
689
|
-
const impls = traits.map((trait) => coerce_impl(trait, "&record:impl-traits"));
|
|
690
|
-
const nextStruct = new CalcitStruct(xs.name, xs.fields, xs.structRef.fieldTypes, xs.structRef.impls.concat(impls));
|
|
691
|
-
return new CalcitRecord(xs.name, xs.fields, xs.values, nextStruct);
|
|
679
|
+
throw new Error("&struct:impls expected a struct value");
|
|
692
680
|
};
|
|
693
681
|
export let _$n_struct_$o_impl_traits = function (xs, ...traits) {
|
|
694
682
|
if (traits.length < 1)
|
|
695
683
|
throw new Error("&struct:impl-traits takes 2+ arguments");
|
|
696
|
-
if (!(xs instanceof
|
|
697
|
-
throw new Error("&struct:impl-traits expected a struct");
|
|
698
|
-
const
|
|
684
|
+
if (!(xs instanceof CalcitStructValue))
|
|
685
|
+
throw new Error("&struct:impl-traits expected a struct value");
|
|
686
|
+
const impls = traits.map((trait) => coerce_impl(trait, "&struct:impl-traits"));
|
|
687
|
+
const nextStruct = new CalcitStructDef(xs.name, xs.fields, xs.structRef.fieldTypes, xs.structRef.impls.concat(impls));
|
|
688
|
+
return new CalcitStructValue(xs.name, xs.fields, xs.values, nextStruct);
|
|
689
|
+
};
|
|
690
|
+
export let _$n_struct_def_$o_impl_traits = function (xs, ...traits) {
|
|
691
|
+
if (traits.length < 1)
|
|
692
|
+
throw new Error("&struct-def:impl-traits takes 2+ arguments");
|
|
693
|
+
if (!(xs instanceof CalcitStructDef))
|
|
694
|
+
throw new Error("&struct-def:impl-traits expected a struct definition");
|
|
695
|
+
const addedImpls = traits.map((trait) => coerce_impl(trait, "&struct-def:impl-traits"));
|
|
699
696
|
const baseImpls = xs.impls ?? [];
|
|
700
|
-
return new
|
|
697
|
+
return new CalcitStructDef(xs.name, xs.fields, xs.fieldTypes, baseImpls.concat(addedImpls));
|
|
701
698
|
};
|
|
702
|
-
export let _$
|
|
699
|
+
export let _$n_enum_def_$o_impl_traits = function (xs, ...traits) {
|
|
703
700
|
if (traits.length < 1)
|
|
704
|
-
throw new Error("&enum:impl-traits takes 2+ arguments");
|
|
705
|
-
const addedImpls = traits.map((trait) => coerce_impl(trait, "&enum:impl-traits"));
|
|
706
|
-
if (xs instanceof
|
|
701
|
+
throw new Error("&enum-def:impl-traits takes 2+ arguments");
|
|
702
|
+
const addedImpls = traits.map((trait) => coerce_impl(trait, "&enum-def:impl-traits"));
|
|
703
|
+
if (xs instanceof CalcitEnumDef) {
|
|
707
704
|
return xs.withImpls(addedImpls);
|
|
708
705
|
}
|
|
709
|
-
|
|
710
|
-
const nextStruct = new CalcitStruct(xs.name, xs.fields, xs.structRef.fieldTypes, xs.structRef.impls.concat(addedImpls));
|
|
711
|
-
return new CalcitRecord(xs.name, xs.fields, xs.values, nextStruct);
|
|
712
|
-
}
|
|
713
|
-
throw new Error("&enum:impl-traits expected an enum or enum record");
|
|
706
|
+
throw new Error("&enum-def:impl-traits expected an enum definition");
|
|
714
707
|
};
|
|
715
708
|
export let _$n_impl_$o_origin = function (impl) {
|
|
716
709
|
if (arguments.length !== 1)
|
|
@@ -1089,7 +1082,7 @@ export let _$n_merge = (a, b) => {
|
|
|
1089
1082
|
throw new Error("Expected an argument of map");
|
|
1090
1083
|
}
|
|
1091
1084
|
}
|
|
1092
|
-
if (a instanceof
|
|
1085
|
+
if (a instanceof CalcitStructValue) {
|
|
1093
1086
|
if (b instanceof CalcitMap || b instanceof CalcitSliceMap) {
|
|
1094
1087
|
let values = [];
|
|
1095
1088
|
for (let idx = 0; idx < a.values.length; idx++) {
|
|
@@ -1114,10 +1107,10 @@ export let _$n_merge = (a, b) => {
|
|
|
1114
1107
|
throw new Error(`Cannot find field ${field} among (${a.fields.join(", ")})`);
|
|
1115
1108
|
}
|
|
1116
1109
|
}
|
|
1117
|
-
return new
|
|
1110
|
+
return new CalcitStructValue(a.name, a.fields, values);
|
|
1118
1111
|
}
|
|
1119
1112
|
}
|
|
1120
|
-
throw new Error("Expected map or
|
|
1113
|
+
throw new Error("Expected map or struct value");
|
|
1121
1114
|
};
|
|
1122
1115
|
export let _$n_merge_non_nil = (a, b) => {
|
|
1123
1116
|
if (a == null) {
|
|
@@ -1143,7 +1136,7 @@ export let to_pairs = (xs) => {
|
|
|
1143
1136
|
}
|
|
1144
1137
|
return new CalcitSet(result);
|
|
1145
1138
|
}
|
|
1146
|
-
else if (xs instanceof
|
|
1139
|
+
else if (xs instanceof CalcitStructValue) {
|
|
1147
1140
|
let arr_result = [];
|
|
1148
1141
|
for (let idx = 0; idx < xs.fields.length; idx++) {
|
|
1149
1142
|
arr_result.push(new CalcitSliceList([xs.fields[idx], xs.values[idx]]));
|
|
@@ -1493,11 +1486,17 @@ export let fn_$q_ = (x) => {
|
|
|
1493
1486
|
export let ref_$q_ = (x) => {
|
|
1494
1487
|
return x instanceof CalcitRef;
|
|
1495
1488
|
};
|
|
1496
|
-
export let
|
|
1497
|
-
|
|
1489
|
+
export let struct_$q_ = (x) => {
|
|
1490
|
+
if (x instanceof CalcitStructDef) {
|
|
1491
|
+
throw new Error("`struct?` now checks struct values; use `struct-def?` for a value produced by `defstruct`");
|
|
1492
|
+
}
|
|
1493
|
+
return x instanceof CalcitStructValue;
|
|
1498
1494
|
};
|
|
1499
|
-
export let
|
|
1500
|
-
|
|
1495
|
+
export let enum_$q_ = (x) => {
|
|
1496
|
+
if (x instanceof CalcitEnumDef) {
|
|
1497
|
+
throw new Error("`enum?` now checks enum values; use `enum-def?` for a value produced by `defenum`");
|
|
1498
|
+
}
|
|
1499
|
+
return x instanceof CalcitEnumValue;
|
|
1501
1500
|
};
|
|
1502
1501
|
export let buffer_$q_ = (x) => {
|
|
1503
1502
|
console.warn("TODO, detecting buffer");
|
|
@@ -1559,10 +1558,10 @@ const typed_edn_kind = (value) => {
|
|
|
1559
1558
|
return "map";
|
|
1560
1559
|
if (value instanceof CalcitSet || value instanceof TypedEdnSetView)
|
|
1561
1560
|
return "set";
|
|
1562
|
-
if (value instanceof
|
|
1563
|
-
return "
|
|
1564
|
-
if (value instanceof
|
|
1565
|
-
return
|
|
1561
|
+
if (value instanceof CalcitStructValue)
|
|
1562
|
+
return "struct";
|
|
1563
|
+
if (value instanceof CalcitEnumValue)
|
|
1564
|
+
return "enum";
|
|
1566
1565
|
if (value instanceof CalcitRef)
|
|
1567
1566
|
return "atom";
|
|
1568
1567
|
if (value instanceof CalcitCirruQuote)
|
|
@@ -1575,7 +1574,7 @@ const typed_edn_error = (path, message) => {
|
|
|
1575
1574
|
throw new Error(`parse-cirru-edn-as failed at ${path}: ${message}`);
|
|
1576
1575
|
};
|
|
1577
1576
|
const enum_prototype_name = (value) => {
|
|
1578
|
-
return value instanceof
|
|
1577
|
+
return value instanceof CalcitEnumDef ? value.name() : value.name.value;
|
|
1579
1578
|
};
|
|
1580
1579
|
const decode_typed_edn_node = (graph, nodeId, input, path, depth) => {
|
|
1581
1580
|
if (depth > 1024)
|
|
@@ -1664,18 +1663,18 @@ const decode_typed_edn_node = (graph, nodeId, input, path, depth) => {
|
|
|
1664
1663
|
return typed_edn_error(path, `expected atom, got ${typed_edn_kind(input)}`);
|
|
1665
1664
|
return atom(decode_typed_edn_node(graph, node.inner, input.value, `${path}.value`, depth + 1));
|
|
1666
1665
|
case "struct": {
|
|
1667
|
-
if (!(input instanceof
|
|
1668
|
-
return typed_edn_error(path, `expected
|
|
1666
|
+
if (!(input instanceof CalcitStructValue)) {
|
|
1667
|
+
return typed_edn_error(path, `expected struct :${node.nominal.name.value}, got ${typed_edn_kind(input)}`);
|
|
1669
1668
|
}
|
|
1670
1669
|
if (input.name.value !== node.nominal.name.value) {
|
|
1671
|
-
return typed_edn_error(path, `expected
|
|
1670
|
+
return typed_edn_error(path, `expected struct :${node.nominal.name.value}, got struct :${input.name.value}`);
|
|
1672
1671
|
}
|
|
1673
1672
|
const expectedNames = node.fields.map(([name]) => name);
|
|
1674
1673
|
const actualNames = input.fields.map((field) => field.value);
|
|
1675
1674
|
const missing = expectedNames.filter((name) => !actualNames.includes(name)).sort();
|
|
1676
1675
|
const unknown = actualNames.filter((name) => !expectedNames.includes(name)).sort();
|
|
1677
1676
|
if (missing.length > 0 || unknown.length > 0 || expectedNames.length !== actualNames.length) {
|
|
1678
|
-
return typed_edn_error(path, `
|
|
1677
|
+
return typed_edn_error(path, `struct :${node.nominal.name.value} fields mismatch; missing [${missing.join(", ")}], unknown [${unknown.join(", ")}]`);
|
|
1679
1678
|
}
|
|
1680
1679
|
const decodedFields = new Map();
|
|
1681
1680
|
node.fields.forEach(([name, fieldNode]) => {
|
|
@@ -1685,18 +1684,18 @@ const decode_typed_edn_node = (graph, nodeId, input, path, depth) => {
|
|
|
1685
1684
|
// Native declarations use lexical field order while the JS runtime keeps
|
|
1686
1685
|
// its interned-tag order. Re-align values to the nominal JS declaration.
|
|
1687
1686
|
if (decodedFields.size !== node.nominal.fields.length) {
|
|
1688
|
-
return typed_edn_error(path, `
|
|
1687
|
+
return typed_edn_error(path, `struct :${node.nominal.name.value} decoder fields do not match its nominal declaration`);
|
|
1689
1688
|
}
|
|
1690
1689
|
const values = node.nominal.fields.map((field) => {
|
|
1691
1690
|
if (!decodedFields.has(field.value)) {
|
|
1692
|
-
return typed_edn_error(path, `
|
|
1691
|
+
return typed_edn_error(path, `struct :${node.nominal.name.value} is missing declared field :${field.value}`);
|
|
1693
1692
|
}
|
|
1694
1693
|
return decodedFields.get(field.value);
|
|
1695
1694
|
});
|
|
1696
|
-
return new
|
|
1695
|
+
return new CalcitStructValue(node.nominal.name, node.nominal.fields, values, node.nominal);
|
|
1697
1696
|
}
|
|
1698
1697
|
case "enum": {
|
|
1699
|
-
if (!(input instanceof
|
|
1698
|
+
if (!(input instanceof CalcitEnumValue) || input.enumPrototype == null) {
|
|
1700
1699
|
return typed_edn_error(path, `expected enum :${node.nominal.name()}, got ${typed_edn_kind(input)}`);
|
|
1701
1700
|
}
|
|
1702
1701
|
const actualEnumName = enum_prototype_name(input.enumPrototype);
|
|
@@ -1715,7 +1714,7 @@ const decode_typed_edn_node = (graph, nodeId, input, path, depth) => {
|
|
|
1715
1714
|
return typed_edn_error(path, `enum :${node.nominal.name()} variant :${variant.tag} expects ${variant.payload.length} payload(s), got ${input.extra.length}`);
|
|
1716
1715
|
}
|
|
1717
1716
|
const values = variant.payload.map((payloadNode, idx) => decode_typed_edn_node(graph, payloadNode, input.extra[idx], `${path}.payload[${idx}]`, depth + 1));
|
|
1718
|
-
return new
|
|
1717
|
+
return new CalcitEnumValue(newTag(variant.tag), values, node.nominal);
|
|
1719
1718
|
}
|
|
1720
1719
|
default:
|
|
1721
1720
|
return typed_edn_error(path, `invalid data shape node kind: ${node.kind}`);
|
|
@@ -1811,13 +1810,13 @@ const calcit_to_json = (value) => {
|
|
|
1811
1810
|
}
|
|
1812
1811
|
return result;
|
|
1813
1812
|
}
|
|
1814
|
-
if (value instanceof
|
|
1813
|
+
if (value instanceof CalcitEnumValue) {
|
|
1815
1814
|
return [calcit_to_json(value.tag), ...value.extra.map(calcit_to_json)];
|
|
1816
1815
|
}
|
|
1817
1816
|
if (value instanceof CalcitCirruQuote) {
|
|
1818
1817
|
return cirru_quote_to_json(value.value);
|
|
1819
1818
|
}
|
|
1820
|
-
if (value instanceof
|
|
1819
|
+
if (value instanceof CalcitStructValue) {
|
|
1821
1820
|
const result = {};
|
|
1822
1821
|
for (let idx = 0; idx < value.fields.length; idx++) {
|
|
1823
1822
|
result[value.fields[idx].value] = calcit_to_json(value.values[idx]);
|
|
@@ -1932,7 +1931,7 @@ export let _$n_js_object = (...xs) => {
|
|
|
1932
1931
|
return ret;
|
|
1933
1932
|
};
|
|
1934
1933
|
export let _$o__$o_ = (tagName, ...extra) => {
|
|
1935
|
-
return new
|
|
1934
|
+
return new CalcitEnumValue(tagName, extra, null);
|
|
1936
1935
|
};
|
|
1937
1936
|
export let _PCT__$o__$o_ = (enumPrototype, tag, ...extra) => {
|
|
1938
1937
|
const proto = assert_enum_tag_args("%::", enumPrototype, tag);
|
|
@@ -1951,8 +1950,7 @@ export let _PCT__$o__$o_ = (enumPrototype, tag, ...extra) => {
|
|
|
1951
1950
|
else {
|
|
1952
1951
|
throw new Error(`Expected variant definition to be a list, got ${variantDefinition}`);
|
|
1953
1952
|
}
|
|
1954
|
-
|
|
1955
|
-
return new CalcitTuple(tag, extra, tupleEnumPrototype);
|
|
1953
|
+
return new CalcitEnumValue(tag, extra, enumPrototype);
|
|
1956
1954
|
};
|
|
1957
1955
|
export let _PCT__PCT__$o__$o_ = (impl, enumPrototype, tag, ...extra) => {
|
|
1958
1956
|
// Runtime validation: check if tag exists in enum and arity matches
|
|
@@ -1972,9 +1970,8 @@ export let _PCT__PCT__$o__$o_ = (impl, enumPrototype, tag, ...extra) => {
|
|
|
1972
1970
|
else {
|
|
1973
1971
|
throw new Error(`Expected variant definition to be a list, got ${variantDefinition}`);
|
|
1974
1972
|
}
|
|
1975
|
-
const tupleEnumPrototype = enumPrototype instanceof CalcitEnum ? enumPrototype : proto;
|
|
1976
1973
|
const implValue = coerce_impl(impl, "%:: with impl");
|
|
1977
|
-
return new
|
|
1974
|
+
return new CalcitEnumValue(tag, extra, enumPrototype.withImpls(implValue));
|
|
1978
1975
|
};
|
|
1979
1976
|
let calcit_builtin_impls = {
|
|
1980
1977
|
number: null,
|
|
@@ -1983,8 +1980,8 @@ let calcit_builtin_impls = {
|
|
|
1983
1980
|
list: null,
|
|
1984
1981
|
map: null,
|
|
1985
1982
|
fn: null,
|
|
1986
|
-
|
|
1987
|
-
|
|
1983
|
+
enum: null,
|
|
1984
|
+
struct: null,
|
|
1988
1985
|
scalar: null,
|
|
1989
1986
|
};
|
|
1990
1987
|
// need to register code from outside
|
|
@@ -2024,10 +2021,10 @@ function lookup_impls(obj) {
|
|
|
2024
2021
|
tag = "&core-map-methods";
|
|
2025
2022
|
impls = normalize_builtin_impls(calcit_builtin_impls.map);
|
|
2026
2023
|
}
|
|
2027
|
-
else if (obj instanceof
|
|
2024
|
+
else if (obj instanceof CalcitStructValue) {
|
|
2028
2025
|
tag = obj.name.toString();
|
|
2029
2026
|
let instanceImpls = obj.structRef.impls;
|
|
2030
|
-
let builtinRecordImpls = normalize_builtin_impls(calcit_builtin_impls.
|
|
2027
|
+
let builtinRecordImpls = normalize_builtin_impls(calcit_builtin_impls.struct);
|
|
2031
2028
|
if (builtinRecordImpls && instanceImpls && instanceImpls.length > 0) {
|
|
2032
2029
|
impls = [...builtinRecordImpls, ...instanceImpls];
|
|
2033
2030
|
}
|
|
@@ -2038,10 +2035,10 @@ function lookup_impls(obj) {
|
|
|
2038
2035
|
impls = instanceImpls;
|
|
2039
2036
|
}
|
|
2040
2037
|
}
|
|
2041
|
-
else if (obj instanceof
|
|
2038
|
+
else if (obj instanceof CalcitEnumValue) {
|
|
2042
2039
|
tag = obj.tag.toString();
|
|
2043
2040
|
let instanceImpls = obj.impls;
|
|
2044
|
-
let builtinTupleImpls = normalize_builtin_impls(calcit_builtin_impls.
|
|
2041
|
+
let builtinTupleImpls = normalize_builtin_impls(calcit_builtin_impls.enum);
|
|
2045
2042
|
if (builtinTupleImpls && instanceImpls && instanceImpls.length > 0) {
|
|
2046
2043
|
impls = [...builtinTupleImpls, ...instanceImpls];
|
|
2047
2044
|
}
|
|
@@ -2056,17 +2053,17 @@ function lookup_impls(obj) {
|
|
|
2056
2053
|
tag = "&core-set-methods";
|
|
2057
2054
|
impls = normalize_builtin_impls(calcit_builtin_impls.set);
|
|
2058
2055
|
}
|
|
2059
|
-
else if (obj instanceof
|
|
2056
|
+
else if (obj instanceof CalcitStructDef) {
|
|
2060
2057
|
// Bare type definitions (not yet instantiated) carry their own attached
|
|
2061
2058
|
// impls, so introspection tools like `&methods-of` can answer "what
|
|
2062
2059
|
// methods will instances of this type have" without a concrete instance.
|
|
2063
2060
|
tag = obj.name.toString();
|
|
2064
|
-
const builtinRecordImpls = normalize_builtin_impls(calcit_builtin_impls.
|
|
2061
|
+
const builtinRecordImpls = normalize_builtin_impls(calcit_builtin_impls.struct) ?? [];
|
|
2065
2062
|
impls = [...builtinRecordImpls, ...(obj.impls ?? [])];
|
|
2066
2063
|
}
|
|
2067
|
-
else if (obj instanceof
|
|
2064
|
+
else if (obj instanceof CalcitEnumDef) {
|
|
2068
2065
|
tag = obj.name();
|
|
2069
|
-
const builtinTupleImpls = normalize_builtin_impls(calcit_builtin_impls.
|
|
2066
|
+
const builtinTupleImpls = normalize_builtin_impls(calcit_builtin_impls.enum) ?? [];
|
|
2070
2067
|
impls = [...builtinTupleImpls, ...(obj.impls ?? [])];
|
|
2071
2068
|
}
|
|
2072
2069
|
else if (typeof obj === "number") {
|
|
@@ -2105,7 +2102,7 @@ export function invoke_method(p, obj, ...args) {
|
|
|
2105
2102
|
let tag = pair[1];
|
|
2106
2103
|
// builtin impl lists are ordered by priority in calcit-core.
|
|
2107
2104
|
// user-defined values use impl-traits append, so later impls override earlier ones.
|
|
2108
|
-
let reverse = obj instanceof
|
|
2105
|
+
let reverse = obj instanceof CalcitStructValue || obj instanceof CalcitEnumValue || obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef;
|
|
2109
2106
|
let idx = reverse ? impls.length - 1 : 0;
|
|
2110
2107
|
while (reverse ? idx >= 0 : idx < impls.length) {
|
|
2111
2108
|
let klass = impls[idx];
|
|
@@ -2134,7 +2131,7 @@ export function _$n_methods_of(obj) {
|
|
|
2134
2131
|
throw new Error(`&methods-of cannot resolve impls for: ${toString(obj, true)}`);
|
|
2135
2132
|
}
|
|
2136
2133
|
let impls = pair[0];
|
|
2137
|
-
let reverse = obj instanceof
|
|
2134
|
+
let reverse = obj instanceof CalcitStructValue || obj instanceof CalcitEnumValue || obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef;
|
|
2138
2135
|
let seen = new Set();
|
|
2139
2136
|
let ys = [];
|
|
2140
2137
|
let idx = reverse ? impls.length - 1 : 0;
|
|
@@ -2176,7 +2173,7 @@ export function _$n_inspect_methods(obj, note) {
|
|
|
2176
2173
|
throw new Error(`&inspect-methods cannot resolve impls for: ${toString(obj, true)}`);
|
|
2177
2174
|
}
|
|
2178
2175
|
let impls = pair[0];
|
|
2179
|
-
let reverse = obj instanceof
|
|
2176
|
+
let reverse = obj instanceof CalcitStructValue || obj instanceof CalcitEnumValue || obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef;
|
|
2180
2177
|
console.log("\n&inspect-methods");
|
|
2181
2178
|
console.log(`Note: ${toString(note, true)}`);
|
|
2182
2179
|
console.log(`Value type: ${type_of(obj).toString()}`);
|
|
@@ -2225,7 +2222,7 @@ export function _$n_trait_call(traitDef, method, obj, ...args) {
|
|
|
2225
2222
|
throw new Error(`&trait-call cannot resolve impls for: ${toString(obj, true)}`);
|
|
2226
2223
|
}
|
|
2227
2224
|
const impls = pair[0];
|
|
2228
|
-
const reverse = obj instanceof
|
|
2225
|
+
const reverse = obj instanceof CalcitStructValue || obj instanceof CalcitEnumValue || obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef;
|
|
2229
2226
|
let idx = reverse ? impls.length - 1 : 0;
|
|
2230
2227
|
while (reverse ? idx >= 0 : idx < impls.length) {
|
|
2231
2228
|
const impl = impls[idx];
|