@calcit/procs 0.11.0-a9 → 0.11.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 (34) hide show
  1. package/.gitattributes +1 -0
  2. package/.yarn/install-state.gz +0 -0
  3. package/build.rs +74 -0
  4. package/editing-history/2026-0213-1841-trait-origin-structural-eq.md +91 -0
  5. package/editing-history/2026-0213-1926-docs-tests-followup.md +33 -0
  6. package/editing-history/2026-0214-2050-js-codegen-recursion-tag-migration.md +39 -0
  7. package/editing-history/2026-0214-2358-emit-js-modularization-shift-left.md +63 -0
  8. package/editing-history/2026-0215-1941-macro-diagnostics-refinement.md +39 -0
  9. package/editing-history/2026-0215-diagnostics-consolidated.md +35 -0
  10. package/editing-history/2026-0216-2043-core-api-docs-cleanup.md +40 -0
  11. package/editing-history/2026-0216-2128-docs-smoke-and-trait-errors.md +20 -0
  12. package/lib/calcit-data.mjs +9 -0
  13. package/lib/calcit.procs.mjs +60 -21
  14. package/lib/custom-formatter.mjs +2 -2
  15. package/lib/js-arity-helpers.mjs +9 -0
  16. package/lib/js-cirru.mjs +3 -3
  17. package/lib/js-enum.mjs +11 -5
  18. package/lib/js-impl.mjs +2 -1
  19. package/lib/js-record.mjs +32 -16
  20. package/lib/js-tag-helpers.mjs +15 -0
  21. package/lib/js-tuple.mjs +12 -10
  22. package/lib/package.json +9 -2
  23. package/package.json +9 -2
  24. package/ts-src/calcit-data.mts +9 -0
  25. package/ts-src/calcit.procs.mts +63 -23
  26. package/ts-src/custom-formatter.mts +2 -2
  27. package/ts-src/js-arity-helpers.mts +11 -0
  28. package/ts-src/js-cirru.mts +2 -4
  29. package/ts-src/js-enum.mts +11 -6
  30. package/ts-src/js-impl.mts +4 -1
  31. package/ts-src/js-primes.mts +2 -0
  32. package/ts-src/js-record.mts +32 -17
  33. package/ts-src/js-tag-helpers.mts +17 -0
  34. package/ts-src/js-tuple.mts +14 -11
@@ -1,15 +1,18 @@
1
1
  import { Hash } from "@calcit/ternary-tree";
2
2
  import { CalcitValue } from "./js-primes.mjs";
3
3
  import { CalcitTag, castTag, findInFields, toString } from "./calcit-data.mjs";
4
+ import type { CalcitTrait } from "./js-trait.mjs";
4
5
 
5
6
  export class CalcitImpl {
6
7
  name: CalcitTag;
8
+ origin: CalcitTrait | null;
7
9
  fields: Array<CalcitTag>;
8
10
  values: Array<CalcitValue>;
9
11
  cachedHash: Hash;
10
12
 
11
- constructor(name: CalcitTag, fields: Array<CalcitTag>, values: Array<CalcitValue>) {
13
+ constructor(name: CalcitTag, fields: Array<CalcitTag>, values: Array<CalcitValue>, origin: CalcitTrait | null = null) {
12
14
  this.name = name;
15
+ this.origin = origin;
13
16
  this.fields = fields;
14
17
  this.values = values;
15
18
  this.cachedHash = null;
@@ -9,6 +9,7 @@ import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
9
9
  import { CalcitSet as CalcitSet } from "./js-set.mjs";
10
10
  import { CalcitTuple } from "./js-tuple.mjs";
11
11
  import { CalcitCirruQuote, cirru_deep_equal } from "./js-cirru.mjs";
12
+ import { CalcitTrait } from "./js-trait.mjs";
12
13
 
13
14
  export type CalcitValue =
14
15
  | string
@@ -27,6 +28,7 @@ export type CalcitValue =
27
28
  | CalcitRecur // should not be exposed to function
28
29
  | CalcitRecord
29
30
  | CalcitImpl
31
+ | CalcitTrait
30
32
  | CalcitStruct
31
33
  | CalcitEnum
32
34
  | CalcitCirruQuote
@@ -5,13 +5,15 @@ import { newTag, castTag, toString, CalcitTag, getStringName, findInFields } fro
5
5
 
6
6
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
7
7
 
8
+ import { CalcitStruct } from "./js-struct.mjs";
9
+
8
10
  export class CalcitRecord {
9
11
  name: CalcitTag;
10
12
  fields: Array<CalcitTag>;
11
13
  values: Array<CalcitValue>;
12
- impls: Array<CalcitImpl>;
14
+ structRef: CalcitStruct;
13
15
  cachedHash: Hash;
14
- constructor(name: CalcitTag, fields: Array<CalcitTag>, values?: Array<CalcitValue>, impls?: Array<CalcitImpl>) {
16
+ constructor(name: CalcitTag, fields: Array<CalcitTag>, values?: Array<CalcitValue>, structRef?: CalcitStruct) {
15
17
  this.name = name;
16
18
  let fieldNames = fields.map(castTag);
17
19
  this.fields = fields;
@@ -24,7 +26,7 @@ export class CalcitRecord {
24
26
  this.values = new Array(fieldNames.length);
25
27
  }
26
28
  this.cachedHash = null;
27
- this.impls = impls || [];
29
+ this.structRef = structRef || new CalcitStruct(name, fields, new Array(fields.length).fill(null));
28
30
  }
29
31
  get(k: CalcitValue) {
30
32
  let field = castTag(k);
@@ -54,7 +56,7 @@ export class CalcitRecord {
54
56
  values[idx] = this.values[idx];
55
57
  }
56
58
  }
57
- return new CalcitRecord(this.name, this.fields, values, this.impls);
59
+ return new CalcitRecord(this.name, this.fields, values, this.structRef);
58
60
  }
59
61
  /** return -1 for missing */
60
62
  findIndex(k: CalcitValue) {
@@ -75,12 +77,17 @@ export class CalcitRecord {
75
77
  parts.push(")");
76
78
  return parts.join("");
77
79
  }
78
- withImpls(impl: CalcitValue): CalcitRecord {
80
+ withImpls(impl: CalcitValue | CalcitImpl[]): CalcitRecord {
81
+ let nextImpls: CalcitImpl[];
79
82
  if (impl instanceof CalcitImpl) {
80
- return new CalcitRecord(this.name, this.fields, this.values, [impl]);
83
+ nextImpls = [impl];
84
+ } else if (Array.isArray(impl)) {
85
+ nextImpls = impl;
81
86
  } else {
82
- throw new Error("Expected an impl");
87
+ throw new Error("Expected an impl or array of impls");
83
88
  }
89
+ let nextStruct = new CalcitStruct(this.name, this.fields, this.structRef.fieldTypes, this.structRef.impls.concat(nextImpls));
90
+ return new CalcitRecord(this.name, this.fields, this.values, nextStruct);
84
91
  }
85
92
  }
86
93
 
@@ -107,7 +114,9 @@ export let new_impl_record = (impl: CalcitImpl, name: CalcitValue, ...fields: Ar
107
114
  throw new Error(`Unexpected duplication in record fields: ${x.toString()}`);
108
115
  }
109
116
  });
110
- return new CalcitRecord(castTag(name), fieldNames, undefined, [impl]);
117
+ let nameTag = castTag(name);
118
+ let structRef = new CalcitStruct(nameTag, fieldNames, new Array(fieldNames.length).fill(null), [impl]);
119
+ return new CalcitRecord(nameTag, fieldNames, undefined, structRef);
111
120
  };
112
121
 
113
122
  export let fieldsEqual = (xs: Array<CalcitTag>, ys: Array<CalcitTag>): boolean => {
@@ -126,20 +135,28 @@ export let fieldsEqual = (xs: Array<CalcitTag>, ys: Array<CalcitTag>): boolean =
126
135
  };
127
136
 
128
137
  export let _$n__PCT__$M_ = (proto: CalcitValue, ...xs: Array<CalcitValue>): CalcitValue => {
138
+ let recordProto: CalcitRecord;
129
139
  if (proto instanceof CalcitRecord) {
140
+ recordProto = proto;
141
+ } else if (proto instanceof CalcitStruct) {
142
+ recordProto = new CalcitRecord(proto.name, proto.fields, new Array(proto.fields.length).fill(null), proto);
143
+ } else {
144
+ throw new Error("Expected prototype to be a record");
145
+ }
146
+ {
130
147
  if (xs.length % 2 !== 0) {
131
148
  throw new Error("Expected even number of key/value");
132
149
  }
133
- if (xs.length !== proto.fields.length * 2) {
150
+ if (xs.length !== recordProto.fields.length * 2) {
134
151
  throw new Error("fields size does not match");
135
152
  }
136
153
 
137
- let values = new Array(proto.fields.length);
154
+ let values = new Array(recordProto.fields.length);
138
155
 
139
- for (let i = 0; i < proto.fields.length; i++) {
156
+ for (let i = 0; i < recordProto.fields.length; i++) {
140
157
  let idx = -1;
141
- let k = proto.fields[i];
142
- for (let j = 0; j < proto.fields.length; j++) {
158
+ let k = recordProto.fields[i];
159
+ for (let j = 0; j < recordProto.fields.length; j++) {
143
160
  if (k === castTag(xs[j * 2])) {
144
161
  idx = j;
145
162
  break;
@@ -155,9 +172,7 @@ export let _$n__PCT__$M_ = (proto: CalcitValue, ...xs: Array<CalcitValue>): Calc
155
172
  values[i] = xs[idx * 2 + 1];
156
173
  }
157
174
 
158
- return new CalcitRecord(proto.name, proto.fields, values, proto.impls);
159
- } else {
160
- throw new Error("Expected prototype to be a record");
175
+ return new CalcitRecord(recordProto.name, recordProto.fields, values, recordProto.structRef);
161
176
  }
162
177
  };
163
178
 
@@ -177,7 +192,7 @@ export let _$n_record_$o_with = (proto: CalcitValue, ...xs: Array<CalcitValue>):
177
192
  }
178
193
  values[idx] = v;
179
194
  }
180
- return new CalcitRecord(proto.name, proto.fields, values, proto.impls);
195
+ return new CalcitRecord(proto.name, proto.fields, values, proto.structRef);
181
196
  } else {
182
197
  throw new Error("Expected prototype to be a record");
183
198
  }
@@ -0,0 +1,17 @@
1
+ import { CalcitTag, newTag } from "./calcit-data.mjs";
2
+
3
+ let _tag_cache: Record<string, CalcitTag> = {};
4
+
5
+ export let init_tags = (arr: string[]) => {
6
+ let tags: Record<string, CalcitTag> = {};
7
+ for (let idx = 0; idx < arr.length; idx++) {
8
+ let name = arr[idx];
9
+ let item = _tag_cache[name];
10
+ if (item === undefined) {
11
+ item = newTag(name);
12
+ _tag_cache[name] = item;
13
+ }
14
+ tags[name] = item;
15
+ }
16
+ return tags;
17
+ };
@@ -9,16 +9,25 @@ import { CalcitEnum } from "./js-enum.mjs";
9
9
  export class CalcitTuple {
10
10
  tag: CalcitValue;
11
11
  extra: CalcitValue[];
12
- impls: CalcitImpl[];
13
12
  enumPrototype: CalcitRecord | CalcitEnum;
14
13
  cachedHash: Hash;
15
- constructor(tagName: CalcitValue, extra: CalcitValue[], impls: CalcitImpl[] = [], enumPrototype: CalcitRecord | CalcitEnum = null) {
14
+ constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype: CalcitRecord | CalcitEnum = null) {
16
15
  this.tag = tagName;
17
16
  this.extra = extra;
18
- this.impls = impls;
19
17
  this.enumPrototype = enumPrototype;
20
18
  this.cachedHash = null;
21
19
  }
20
+
21
+ get impls(): CalcitImpl[] {
22
+ if (this.enumPrototype == null) {
23
+ return [];
24
+ }
25
+ if (this.enumPrototype instanceof CalcitEnum) {
26
+ return this.enumPrototype.impls;
27
+ }
28
+ return this.enumPrototype.structRef.impls;
29
+ }
30
+
22
31
  get(n: number) {
23
32
  if (n === 0) {
24
33
  return this.tag;
@@ -30,11 +39,11 @@ export class CalcitTuple {
30
39
  }
31
40
  assoc(n: number, v: CalcitValue) {
32
41
  if (n === 0) {
33
- return new CalcitTuple(v, this.extra, this.impls, this.enumPrototype);
42
+ return new CalcitTuple(v, this.extra, this.enumPrototype);
34
43
  } else if (n - 1 < this.extra.length) {
35
44
  let next_extra = this.extra.slice();
36
45
  next_extra[n - 1] = v;
37
- return new CalcitTuple(this.tag, next_extra, this.impls, this.enumPrototype);
46
+ return new CalcitTuple(this.tag, next_extra, this.enumPrototype);
38
47
  } else {
39
48
  throw new Error(`Tuple only have ${this.extra.length} elements`);
40
49
  }
@@ -68,15 +77,9 @@ export class CalcitTuple {
68
77
  const hasEnum = this.enumPrototype != null;
69
78
  const enumName = hasEnum ? (this.enumPrototype instanceof CalcitEnum ? this.enumPrototype.prototype.name.value : this.enumPrototype.name.value) : null;
70
79
 
71
- if (this.impls.length > 0 && hasEnum) {
72
- return `(%:: ${content} (:impls ${this.impls[0].name.value}) (:enum ${enumName}))`;
73
- }
74
80
  if (hasEnum) {
75
81
  return `(%:: ${content} (:enum ${enumName}))`;
76
82
  }
77
- if (this.impls.length > 0) {
78
- return `(:: ${content} (:impls ${this.impls[0].name.value}))`;
79
- }
80
83
  return `(:: ${content})`;
81
84
  }
82
85
  }