@calcit/procs 0.13.1 → 0.13.4

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 (67) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/RFCs/08-08-cross-backend-host-ffi-contracts-rfc.md +584 -0
  3. package/RFCs/README.md +2 -1
  4. package/build.rs +24 -23
  5. package/editing-history/202608061714-struct-enum-data-model-v2.md +39 -0
  6. package/editing-history/202608061731-release-0.13.2.md +18 -0
  7. package/editing-history/20260807-1030-doc-struct-enum-rename-followup.md +9 -0
  8. package/editing-history/20260807-1130-rename-record-tuple-doc-files.md +6 -0
  9. package/editing-history/20260807-1200-rename-record-tuple-test-and-rust.md +41 -0
  10. package/editing-history/202608071809-preserve-targeted-schema-edits.md +11 -0
  11. package/editing-history/202608071848-static-method-generic-validation.md +5 -0
  12. package/editing-history/20260808-0913-continue-struct-naming-cleanup.md +21 -0
  13. package/editing-history/20260808-0917-struct-enum-terminology-cleanup.md +17 -0
  14. package/editing-history/20260808-0926-deprecated-record-api-analysis.md +16 -0
  15. package/editing-history/20260808-0939-pr-review-ci-remediation.md +10 -0
  16. package/editing-history/20260808-0959-canonical-edn-fixture-expectations.md +10 -0
  17. package/editing-history/20260808-1004-align-js-canonical-edn-format.md +10 -0
  18. package/editing-history/20260808-1008-deprecated-analysis-review-fixes.md +10 -0
  19. package/editing-history/20260808-1012-document-deprecated-api-cleanup.md +7 -0
  20. package/editing-history/20260808-1020-release-0.13.3.md +7 -0
  21. package/editing-history/20260808-1117-option-result-method-api.md +7 -0
  22. package/editing-history/20260808-1126-format-cirru-snapshots.md +6 -0
  23. package/editing-history/20260808-1300-record-tuple-naming-cleanup.md +62 -0
  24. package/editing-history/20260808-1418-cross-backend-host-ffi-contract-rfc.md +7 -0
  25. package/editing-history/20260808-1439-host-ffi-type-foundation.md +7 -0
  26. package/editing-history/20260808-1523-ffi-schema-redesign-and-cirru-edn-check.md +7 -0
  27. package/editing-history/20260808-1532-external-object-trait-refinement.md +6 -0
  28. package/editing-history/20260808-1632-host-ffi.md +6 -0
  29. package/editing-history/20260808-1734-pr-review-ffi-followups.md +7 -0
  30. package/editing-history/20260808-1745-es-module-typed-adapters.md +6 -0
  31. package/editing-history/20260808-1817-release-0.13.4.md +4 -0
  32. package/editing-history/202608080132-pr-309-review-fixes.md +5 -0
  33. package/editing-history/202608080202-js-example-checks.md +5 -0
  34. package/editing-history/202608080206-quote-shell-special-example.md +4 -0
  35. package/editing-history/202608080854-edn-0.8-integration.md +6 -0
  36. package/history/202608061433-required-record-field-access.md +32 -0
  37. package/history/202608062004-wasm-ffi-declarations.md +7 -0
  38. package/history/202608071500-wasm-ffi-review-fixes.md +6 -0
  39. package/lib/calcit-data.mjs +24 -24
  40. package/lib/calcit.procs.d.mts +43 -43
  41. package/lib/calcit.procs.mjs +165 -168
  42. package/lib/custom-formatter.mjs +23 -38
  43. package/lib/js-cirru.mjs +33 -33
  44. package/lib/js-enum-def.d.mts +11 -0
  45. package/lib/{js-enum.mjs → js-enum-def.mjs} +3 -3
  46. package/lib/{js-tuple.d.mts → js-enum-value.d.mts} +6 -7
  47. package/lib/{js-tuple.mjs → js-enum-value.mjs} +8 -15
  48. package/lib/js-list.mjs +6 -6
  49. package/lib/js-primes.d.mts +5 -5
  50. package/lib/js-primes.mjs +16 -16
  51. package/lib/{js-struct.d.mts → js-struct-def.d.mts} +2 -2
  52. package/lib/{js-struct.mjs → js-struct-def.mjs} +6 -6
  53. package/lib/{js-record.d.mts → js-struct-value.d.mts} +16 -15
  54. package/lib/{js-record.mjs → js-struct-value.mjs} +67 -59
  55. package/lib/package.json +1 -1
  56. package/package.json +1 -1
  57. package/ts-src/calcit-data.mts +24 -24
  58. package/ts-src/calcit.procs.mts +165 -168
  59. package/ts-src/custom-formatter.mts +28 -56
  60. package/ts-src/js-cirru.mts +34 -34
  61. package/ts-src/{js-enum.mts → js-enum-def.mts} +7 -7
  62. package/ts-src/{js-tuple.mts → js-enum-value.mts} +12 -19
  63. package/ts-src/js-list.mts +6 -6
  64. package/ts-src/js-primes.mts +16 -16
  65. package/ts-src/{js-struct.mts → js-struct-def.mts} +7 -7
  66. package/ts-src/{js-record.mts → js-struct-value.mts} +72 -66
  67. package/lib/js-enum.d.mts +0 -11
@@ -2,13 +2,13 @@ import { CalcitValue, isLiteral } from "./js-primes.mjs";
2
2
  import { CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
3
3
  import { CalcitRef } from "./js-ref.mjs";
4
4
 
5
- import { CalcitRecord } from "./js-record.mjs";
6
- import { CalcitStruct } from "./js-struct.mjs";
7
- import { CalcitEnum } from "./js-enum.mjs";
5
+ import { CalcitStructValue } from "./js-struct-value.mjs";
6
+ import { CalcitStructDef } from "./js-struct-def.mjs";
7
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
8
8
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
9
9
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
10
10
  import { CalcitSet } from "./js-set.mjs";
11
- import { CalcitTuple } from "./js-tuple.mjs";
11
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
12
12
  import { CalcitCirruQuote } from "./js-cirru.mjs";
13
13
 
14
14
  declare global {
@@ -181,66 +181,38 @@ export let load_console_formatter_$x_ = () => {
181
181
  preview
182
182
  );
183
183
  }
184
- if (obj instanceof CalcitRecord) {
185
- let name = new CalcitSymbol(obj.name.value);
186
- if (obj.structRef.impls.length > 0) {
187
- let ret: any[] = div(
188
- { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
189
- span({}, "%{}"),
190
- span({ marginLeft: "6px" }, embedObject(obj.structRef.impls[0])),
191
- span({ marginLeft: "6px" }, embedObject(name)),
192
- span({ marginLeft: "6px" }, `...`)
193
- );
194
- return ret;
195
- } else {
196
- let ret: any[] = div(
197
- { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
198
- "%{} ",
199
- embedObject(name),
200
- " ..."
201
- );
202
- return ret;
203
- }
184
+ if (obj instanceof CalcitStructValue) {
185
+ const name = new CalcitSymbol(obj.name.value);
186
+ return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%{} ", embedObject(name), " ...");
204
187
  }
205
- if (obj instanceof CalcitStruct) {
188
+ if (obj instanceof CalcitStructDef) {
206
189
  return div(
207
190
  { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
208
- "%struct ",
191
+ "%struct-def ",
209
192
  embedObject(new CalcitSymbol(obj.name.value)),
210
193
  " ..."
211
194
  );
212
195
  }
213
- if (obj instanceof CalcitEnum) {
196
+ if (obj instanceof CalcitEnumDef) {
214
197
  return div(
215
198
  { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
216
- "%enum ",
199
+ "%enum-def ",
217
200
  embedObject(new CalcitSymbol(obj.prototype.name.value)),
218
201
  " ..."
219
202
  );
220
203
  }
221
- if (obj instanceof CalcitTuple) {
222
- if (obj.impls.length > 0) {
223
- let ret: any[] = div(
224
- { marginRight: "16px" },
225
- div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"),
226
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.impls[0])),
227
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
228
- );
229
- for (let idx = 0; idx < obj.extra.length; idx++) {
230
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
231
- }
232
- return ret;
233
- } else {
234
- let ret: any[] = div(
235
- { marginRight: "16px" },
236
- div({ display: "inline-block", color: hsl(300, 100, 40) }, "::"),
237
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
238
- );
239
- for (let idx = 0; idx < obj.extra.length; idx++) {
240
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
241
- }
242
- return ret;
204
+ if (obj instanceof CalcitEnumValue) {
205
+ const enumName = obj.enumPrototype == null ? "_" : obj.enumPrototype.name();
206
+ let ret: any[] = div(
207
+ { marginRight: "16px" },
208
+ div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"),
209
+ div({ marginLeft: "6px", display: "inline-block" }, embedObject(new CalcitSymbol(enumName))),
210
+ div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
211
+ );
212
+ for (let idx = 0; idx < obj.extra.length; idx++) {
213
+ ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
243
214
  }
215
+ return ret;
244
216
  }
245
217
  if (obj instanceof CalcitRef) {
246
218
  return div(
@@ -276,11 +248,11 @@ export let load_console_formatter_$x_ = () => {
276
248
  let hasCollection = obj.nestedDataInChildren();
277
249
  return obj.len() > 0 && hasCollection;
278
250
  }
279
- if (obj instanceof CalcitRecord) {
251
+ if (obj instanceof CalcitStructValue) {
280
252
  return obj.fields.length > 0;
281
253
  }
282
- if (obj instanceof CalcitStruct || obj instanceof CalcitEnum) {
283
- return obj instanceof CalcitStruct ? obj.fields.length > 0 : obj.prototype.fields.length > 0;
254
+ if (obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef) {
255
+ return obj instanceof CalcitStructDef ? obj.fields.length > 0 : obj.prototype.fields.length > 0;
284
256
  }
285
257
  return false;
286
258
  },
@@ -344,7 +316,7 @@ export let load_console_formatter_$x_ = () => {
344
316
  }
345
317
  return ret;
346
318
  }
347
- if (obj instanceof CalcitRecord) {
319
+ if (obj instanceof CalcitStructValue) {
348
320
  let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
349
321
  for (let idx = 0; idx < obj.fields.length; idx++) {
350
322
  ret.push(
@@ -357,7 +329,7 @@ export let load_console_formatter_$x_ = () => {
357
329
  }
358
330
  return ret;
359
331
  }
360
- if (obj instanceof CalcitStruct) {
332
+ if (obj instanceof CalcitStructDef) {
361
333
  let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
362
334
  for (let idx = 0; idx < obj.fields.length; idx++) {
363
335
  ret.push(
@@ -370,7 +342,7 @@ export let load_console_formatter_$x_ = () => {
370
342
  }
371
343
  return ret;
372
344
  }
373
- if (obj instanceof CalcitEnum) {
345
+ if (obj instanceof CalcitEnumDef) {
374
346
  let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
375
347
  for (let idx = 0; idx < obj.prototype.fields.length; idx++) {
376
348
  ret.push(
@@ -3,12 +3,12 @@ import { CirruWriterNode, writeCirruCode, writeCirruOneLiner } from "@cirru/writ
3
3
 
4
4
  import { CalcitValue, isLiteral, _$n_compare } from "./js-primes.mjs";
5
5
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
6
- import { CalcitRecord } from "./js-record.mjs";
6
+ import { CalcitStructValue } from "./js-struct-value.mjs";
7
7
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
8
8
  import { CalcitSet } from "./js-set.mjs";
9
9
  import { CalcitTag, CalcitSymbol, CalcitRecur, newTag } from "./calcit-data.mjs";
10
- import { CalcitTuple } from "./js-tuple.mjs";
11
- import { CalcitEnum } from "./js-enum.mjs";
10
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
11
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
12
12
  import { CalcitImpl } from "./js-impl.mjs";
13
13
  import { CalcitRef } from "./js-ref.mjs";
14
14
  import { deepEqual } from "@calcit/ternary-tree/lib/utils.mjs";
@@ -151,14 +151,14 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
151
151
  }
152
152
  return buffer;
153
153
  }
154
- if (x instanceof CalcitRecord) {
154
+ if (x instanceof CalcitStructValue) {
155
155
  let buffer: [string, CirruEdnFormat][] = [];
156
156
  for (let idx = 0; idx < x.fields.length; idx++) {
157
157
  buffer.push([x.fields[idx].toString(), to_cirru_edn(x.values[idx])]);
158
158
  }
159
159
  // placed literals first
160
160
  buffer.sort(recordFieldOrder);
161
- (buffer as any[]).unshift(x.name.toString());
161
+ (buffer as any[]).unshift(new CalcitSymbol(x.name.value).toString());
162
162
  (buffer as any[]).unshift("%{}");
163
163
  return buffer;
164
164
  }
@@ -174,27 +174,27 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
174
174
  }
175
175
  return buffer;
176
176
  }
177
- if (x instanceof CalcitTuple) {
177
+ if (x instanceof CalcitEnumValue) {
178
178
  if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
179
179
  // turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
180
180
  return ["quote", toWriterNode(x.get(1) as any)] as CirruEdnFormat;
181
181
  } else if (x.enumPrototype != null) {
182
- let enumTag = unwrap_enum_prototype_local(x.enumPrototype).name.toString();
182
+ let enumTag = new CalcitSymbol(unwrap_enum_prototype_local(x.enumPrototype).name.value).toString();
183
183
  if (x.tag instanceof CalcitTag) {
184
- return ["%::", enumTag, x.tag.toString(), ...x.extra.map(to_cirru_edn)];
185
- } else if (x.tag instanceof CalcitRecord) {
186
- return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
184
+ return ["%::", enumTag, new CalcitSymbol(x.tag.value).toString(), ...x.extra.map(to_cirru_edn)];
185
+ } else if (x.tag instanceof CalcitStructValue) {
186
+ return ["%::", enumTag, new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
187
187
  } else if (x.tag instanceof CalcitImpl) {
188
- return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
188
+ return ["%::", enumTag, new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
189
189
  } else {
190
190
  throw new Error(`Unsupported tag for EDN: ${x.tag}`);
191
191
  }
192
192
  } else if (x.tag instanceof CalcitTag) {
193
- return ["::", x.tag.toString(), ...x.extra.map(to_cirru_edn)];
194
- } else if (x.tag instanceof CalcitRecord) {
195
- return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
193
+ return ["::", new CalcitSymbol(x.tag.value).toString(), ...x.extra.map(to_cirru_edn)];
194
+ } else if (x.tag instanceof CalcitStructValue) {
195
+ return ["::", new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
196
196
  } else if (x.tag instanceof CalcitImpl) {
197
- return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
197
+ return ["::", new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
198
198
  } else {
199
199
  throw new Error(`Unsupported tag for EDN: ${x.tag}`);
200
200
  }
@@ -230,9 +230,12 @@ let extractFieldTag = (x: string) => {
230
230
  let resolveEnumPrototype = (enumName: string, options: CalcitValue) => {
231
231
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
232
232
  let value = options.get(extractFieldTag(enumName));
233
- if (value instanceof CalcitEnum || value instanceof CalcitRecord) {
233
+ if (value instanceof CalcitEnumDef) {
234
234
  return value;
235
235
  }
236
+ if (value instanceof CalcitStructValue) {
237
+ throw new Error(`Enum ${enumName} uses a legacy struct prototype; provide an EnumDef produced by defenum`);
238
+ }
236
239
  if (value != null) {
237
240
  throw new Error(`Expected enum prototype for ${enumName}, got: ${value}`);
238
241
  }
@@ -240,20 +243,17 @@ let resolveEnumPrototype = (enumName: string, options: CalcitValue) => {
240
243
  return null;
241
244
  };
242
245
 
243
- // local helper to unwrap an enum prototype value to a CalcitRecord prototype
244
- const unwrap_enum_prototype_local = (enumPrototype: CalcitValue): CalcitRecord => {
245
- if (enumPrototype instanceof CalcitEnum) {
246
+ // local helper to inspect an EnumDef's variant prototype
247
+ const unwrap_enum_prototype_local = (enumPrototype: CalcitValue): CalcitStructValue => {
248
+ if (enumPrototype instanceof CalcitEnumDef) {
246
249
  return enumPrototype.prototype;
247
250
  }
248
- if (enumPrototype instanceof CalcitRecord) {
249
- return enumPrototype;
250
- }
251
- throw new Error(`expected enum prototype`);
251
+ throw new Error(`expected an EnumDef produced by defenum`);
252
252
  };
253
253
 
254
254
  const tag_to_string = (tag: CalcitValue): string => {
255
255
  if (tag instanceof CalcitTag) return tag.toString();
256
- if (tag instanceof CalcitRecord) return tag.name.toString();
256
+ if (tag instanceof CalcitStructValue) return tag.name.toString();
257
257
  throw new Error(`Unsupported tag for EDN: ${tag}`);
258
258
  };
259
259
 
@@ -321,7 +321,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
321
321
  if (x[0] === "%{}") {
322
322
  let name = x[1];
323
323
  if (typeof name != "string") {
324
- throw new Error(`Expected string for record name, got: ${name}`);
324
+ throw new Error(`Expected string for struct name, got: ${name}`);
325
325
  }
326
326
  // put to entries first, sort and then...
327
327
  let entries: Array<[CalcitTag, CalcitValue]> = [];
@@ -344,7 +344,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
344
344
  throw new Error(`Expected pair of size 2, got: ${pair}`);
345
345
  }
346
346
  } else {
347
- throw new Error(`Expected pairs for record, got: ${pair}`);
347
+ throw new Error(`Expected field pairs for struct, got: ${pair}`);
348
348
  }
349
349
  });
350
350
  entries.sort((a, b) => {
@@ -360,14 +360,14 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
360
360
 
361
361
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
362
362
  let v = options.get(extractFieldTag(name));
363
- if (v != null && v instanceof CalcitRecord) {
363
+ if (v != null && v instanceof CalcitStructValue) {
364
364
  if (deepEqual(v.fields, fields)) {
365
- return new CalcitRecord(extractFieldTag(name), fields, values, v.structRef);
365
+ return new CalcitStructValue(extractFieldTag(name), fields, values, v.structRef);
366
366
  }
367
367
  }
368
368
  }
369
369
 
370
- return new CalcitRecord(extractFieldTag(name), fields, values);
370
+ return new CalcitStructValue(extractFieldTag(name), fields, values);
371
371
  }
372
372
  let notComment = (x: any) => {
373
373
  if (x instanceof Array && x[0] === ";") {
@@ -402,9 +402,9 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
402
402
  }
403
403
  if (x[0] === "::") {
404
404
  if (x.length < 2) {
405
- throw new Error(`tuple expects at least 1 value, got: ${x}`);
405
+ throw new Error(`anonymous enum expects at least 1 value, got: ${x}`);
406
406
  }
407
- return new CalcitTuple(
407
+ return new CalcitEnumValue(
408
408
  extract_cirru_edn_inner(x[1], options, preserveSourceEntries),
409
409
  x
410
410
  .slice(2)
@@ -424,7 +424,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
424
424
  // unwrap prototype to record then extract name
425
425
  const proto = enumPrototype != null ? unwrap_enum_prototype_local(enumPrototype) : null;
426
426
  const enumTag = proto != null ? proto.name.toString() : enumName;
427
- return new CalcitTuple(
427
+ return new CalcitEnumValue(
428
428
  extract_cirru_edn_inner(x[2], options, preserveSourceEntries),
429
429
  x
430
430
  .slice(3)
@@ -505,12 +505,12 @@ export let to_calcit_data = (x: any, noKeyword: boolean = false): CalcitValue =>
505
505
  if (x instanceof CalcitList || x instanceof CalcitSliceList) return x;
506
506
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return x;
507
507
  if (x instanceof CalcitSet) return x;
508
- if (x instanceof CalcitRecord) return x;
508
+ if (x instanceof CalcitStructValue) return x;
509
509
  if (x instanceof CalcitRecur) return x;
510
510
  if (x instanceof CalcitRef) return x;
511
511
  if (x instanceof CalcitTag) return x;
512
512
  if (x instanceof CalcitSymbol) return x;
513
- if (x instanceof CalcitTuple) return x;
513
+ if (x instanceof CalcitEnumValue) return x;
514
514
 
515
515
  // detects object
516
516
  if (x === Object(x)) {
@@ -1,11 +1,11 @@
1
- import { CalcitRecord } from "./js-record.mjs";
1
+ import { CalcitStructValue } from "./js-struct-value.mjs";
2
2
  import { CalcitImpl } from "./js-impl.mjs";
3
3
 
4
- export class CalcitEnum {
5
- prototype: CalcitRecord;
4
+ export class CalcitEnumDef {
5
+ prototype: CalcitStructValue;
6
6
  cachedHash: number;
7
7
 
8
- constructor(prototype: CalcitRecord) {
8
+ constructor(prototype: CalcitStructValue) {
9
9
  this.prototype = prototype;
10
10
  this.cachedHash = null;
11
11
  }
@@ -18,7 +18,7 @@ export class CalcitEnum {
18
18
  return this.prototype.structRef.impls;
19
19
  }
20
20
 
21
- withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitEnum {
21
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitEnumDef {
22
22
  let nextImpls: CalcitImpl[];
23
23
  if (impls instanceof CalcitImpl) {
24
24
  nextImpls = [impls];
@@ -27,10 +27,10 @@ export class CalcitEnum {
27
27
  } else {
28
28
  throw new Error("Expected an impl as implementation");
29
29
  }
30
- return new CalcitEnum(this.prototype.withImpls(nextImpls));
30
+ return new CalcitEnumDef(this.prototype.withImpls(nextImpls));
31
31
  }
32
32
 
33
33
  toString(): string {
34
- return `(%enum '${this.prototype.name.value})`;
34
+ return `(%enum-def '${this.prototype.name.value})`;
35
35
  }
36
36
  }
@@ -3,15 +3,14 @@ import { Hash } from "@calcit/ternary-tree";
3
3
  import { CalcitValue } from "./js-primes.mjs";
4
4
  import { _$n__$e_, newTag, toString } from "./calcit-data.mjs";
5
5
  import { CalcitImpl } from "./js-impl.mjs";
6
- import { CalcitRecord } from "./js-record.mjs";
7
- import { CalcitEnum } from "./js-enum.mjs";
6
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
8
7
 
9
- export class CalcitTuple {
8
+ export class CalcitEnumValue {
10
9
  tag: CalcitValue;
11
10
  extra: CalcitValue[];
12
- enumPrototype: CalcitRecord | CalcitEnum;
11
+ enumPrototype: CalcitEnumDef;
13
12
  cachedHash: Hash;
14
- constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype: CalcitRecord | CalcitEnum = null) {
13
+ constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype: CalcitEnumDef = null) {
15
14
  this.tag = tagName;
16
15
  this.extra = extra;
17
16
  this.enumPrototype = enumPrototype;
@@ -22,10 +21,7 @@ export class CalcitTuple {
22
21
  if (this.enumPrototype == null) {
23
22
  return [];
24
23
  }
25
- if (this.enumPrototype instanceof CalcitEnum) {
26
- return this.enumPrototype.impls;
27
- }
28
- return this.enumPrototype.structRef.impls;
24
+ return this.enumPrototype.impls;
29
25
  }
30
26
 
31
27
  get(n: number) {
@@ -34,24 +30,24 @@ export class CalcitTuple {
34
30
  } else if (n - 1 < this.extra.length) {
35
31
  return this.extra[n - 1];
36
32
  } else {
37
- throw new Error(`Tuple only have ${this.extra.length + 1} elements`);
33
+ throw new Error(`Enum value only has ${this.extra.length + 1} elements`);
38
34
  }
39
35
  }
40
36
  assoc(n: number, v: CalcitValue) {
41
37
  if (n === 0) {
42
- return new CalcitTuple(v, this.extra, this.enumPrototype);
38
+ return new CalcitEnumValue(v, this.extra, this.enumPrototype);
43
39
  } else if (n - 1 < this.extra.length) {
44
40
  let next_extra = this.extra.slice();
45
41
  next_extra[n - 1] = v;
46
- return new CalcitTuple(this.tag, next_extra, this.enumPrototype);
42
+ return new CalcitEnumValue(this.tag, next_extra, this.enumPrototype);
47
43
  } else {
48
- throw new Error(`Tuple only have ${this.extra.length} elements`);
44
+ throw new Error(`Enum value only has ${this.extra.length} elements`);
49
45
  }
50
46
  }
51
47
  count() {
52
48
  return 1 + this.extra.length;
53
49
  }
54
- eq(y: CalcitTuple): boolean {
50
+ eq(y: CalcitEnumValue): boolean {
55
51
  if (!_$n__$e_(this.tag, y.tag)) {
56
52
  return false;
57
53
  }
@@ -75,11 +71,8 @@ export class CalcitTuple {
75
71
  content += toString(args[i], true, disableJsDataWarning);
76
72
  }
77
73
  const hasEnum = this.enumPrototype != null;
78
- const enumName = hasEnum ? (this.enumPrototype instanceof CalcitEnum ? this.enumPrototype.prototype.name.value : this.enumPrototype.name.value) : null;
74
+ const enumName = hasEnum ? this.enumPrototype.name() : null;
79
75
 
80
- if (hasEnum) {
81
- return `(%:: ${content} (:enum ${enumName}))`;
82
- }
83
- return `(:: ${content})`;
76
+ return `(%:: ${hasEnum ? `'${enumName}` : "_"} ${content})`;
84
77
  }
85
78
  }
@@ -18,7 +18,7 @@ import {
18
18
 
19
19
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
20
20
  import { CalcitSet } from "./js-set.mjs";
21
- import { CalcitTuple } from "./js-tuple.mjs";
21
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
22
22
 
23
23
  import { isNestedCalcitData, tipNestedCalcitData, toString, CalcitFn } from "./calcit-data.mjs";
24
24
 
@@ -349,7 +349,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
349
349
  for (let idx = 0; idx < size; idx++) {
350
350
  let item = xs.get(idx);
351
351
  let pair = f(state, item);
352
- if (pair instanceof CalcitTuple) {
352
+ if (pair instanceof CalcitEnumValue) {
353
353
  if (typeof pair.tag === "boolean") {
354
354
  if (pair.tag) {
355
355
  return pair.get(1);
@@ -369,7 +369,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
369
369
  for (let idx = 0; idx < values.length; idx++) {
370
370
  let item = values[idx];
371
371
  let pair = f(state, item);
372
- if (pair instanceof CalcitTuple) {
372
+ if (pair instanceof CalcitEnumValue) {
373
373
  if (typeof pair.tag === "boolean") {
374
374
  if (pair.tag) {
375
375
  return pair.get(1);
@@ -390,7 +390,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
390
390
  for (let i = 0; i < size; i++) {
391
391
  let pos = i << 1;
392
392
  let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
393
- if (pair instanceof CalcitTuple) {
393
+ if (pair instanceof CalcitEnumValue) {
394
394
  if (typeof pair.tag === "boolean") {
395
395
  if (pair.tag) {
396
396
  return pair.get(1);
@@ -410,7 +410,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
410
410
  for (let idx = 0; idx < pairs.length; idx++) {
411
411
  let item = pairs[idx];
412
412
  let pair = f(state, new CalcitSliceList(item));
413
- if (pair instanceof CalcitTuple) {
413
+ if (pair instanceof CalcitEnumValue) {
414
414
  if (typeof pair.tag === "boolean") {
415
415
  if (pair.tag) {
416
416
  return pair.get(1);
@@ -440,7 +440,7 @@ export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
440
440
  for (let idx = xs.len() - 1; idx >= 0; idx--) {
441
441
  let item = xs.get(idx);
442
442
  let pair = f(state, item);
443
- if (pair instanceof CalcitTuple) {
443
+ if (pair instanceof CalcitEnumValue) {
444
444
  if (typeof pair.tag === "boolean") {
445
445
  if (pair.tag) {
446
446
  return pair.get(1);
@@ -1,13 +1,13 @@
1
1
  import { CalcitTag, CalcitSymbol, CalcitFn, CalcitRecur } from "./calcit-data.mjs";
2
2
  import { CalcitRef } from "./js-ref.mjs";
3
3
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
4
- import { CalcitRecord } from "./js-record.mjs";
4
+ import { CalcitStructValue } from "./js-struct-value.mjs";
5
5
  import { CalcitImpl } from "./js-impl.mjs";
6
- import { CalcitStruct } from "./js-struct.mjs";
7
- import { CalcitEnum } from "./js-enum.mjs";
6
+ import { CalcitStructDef } from "./js-struct-def.mjs";
7
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
8
8
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
9
9
  import { CalcitSet as CalcitSet } from "./js-set.mjs";
10
- import { CalcitTuple } from "./js-tuple.mjs";
10
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
11
11
  import { CalcitCirruQuote, cirru_deep_equal } from "./js-cirru.mjs";
12
12
  import { CalcitTrait } from "./js-trait.mjs";
13
13
 
@@ -23,14 +23,14 @@ export type CalcitValue =
23
23
  | CalcitTag
24
24
  | CalcitSymbol
25
25
  | CalcitRef
26
- | CalcitTuple
26
+ | CalcitEnumValue
27
27
  | CalcitFn
28
28
  | CalcitRecur // should not be exposed to function
29
- | CalcitRecord
29
+ | CalcitStructValue
30
30
  | CalcitImpl
31
31
  | CalcitTrait
32
- | CalcitStruct
33
- | CalcitEnum
32
+ | CalcitStructDef
33
+ | CalcitEnumDef
34
34
  | CalcitCirruQuote
35
35
  | null;
36
36
 
@@ -52,15 +52,15 @@ enum PseudoTypeIndex {
52
52
  tag,
53
53
  string,
54
54
  ref,
55
- tuple,
55
+ enum_value,
56
56
  recur,
57
57
  list,
58
58
  set,
59
59
  map,
60
- record,
60
+ struct_value,
61
61
  impl,
62
- struct,
63
- enum_type,
62
+ struct_def,
63
+ enum_def,
64
64
  fn,
65
65
  cirru_quote,
66
66
  }
@@ -75,15 +75,15 @@ let typeAsInt = (x: CalcitValue): number => {
75
75
  if (x instanceof CalcitTag) return PseudoTypeIndex.tag;
76
76
  if (t === "string") return PseudoTypeIndex.string;
77
77
  if (x instanceof CalcitRef) return PseudoTypeIndex.ref;
78
- if (x instanceof CalcitTuple) return PseudoTypeIndex.tuple;
78
+ if (x instanceof CalcitEnumValue) return PseudoTypeIndex.enum_value;
79
79
  if (x instanceof CalcitRecur) return PseudoTypeIndex.recur;
80
80
  if (x instanceof CalcitList || x instanceof CalcitSliceList) return PseudoTypeIndex.list;
81
81
  if (x instanceof CalcitSet) return PseudoTypeIndex.set;
82
82
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return PseudoTypeIndex.map;
83
- if (x instanceof CalcitRecord) return PseudoTypeIndex.record;
83
+ if (x instanceof CalcitStructValue) return PseudoTypeIndex.struct_value;
84
84
  if (x instanceof CalcitImpl) return PseudoTypeIndex.impl;
85
- if (x instanceof CalcitStruct) return PseudoTypeIndex.struct;
86
- if (x instanceof CalcitEnum) return PseudoTypeIndex.enum_type;
85
+ if (x instanceof CalcitStructDef) return PseudoTypeIndex.struct_def;
86
+ if (x instanceof CalcitEnumDef) return PseudoTypeIndex.enum_def;
87
87
  if (x instanceof CalcitCirruQuote) return PseudoTypeIndex.cirru_quote;
88
88
  // proc, fn, macro, syntax, not distinguished
89
89
  if (t === "function") return PseudoTypeIndex.fn;
@@ -2,7 +2,7 @@ import { CalcitTag, toString } from "./calcit-data.mjs";
2
2
  import { CalcitValue } from "./js-primes.mjs";
3
3
  import { CalcitImpl } from "./js-impl.mjs";
4
4
 
5
- export class CalcitStruct {
5
+ export class CalcitStructDef {
6
6
  name: CalcitTag;
7
7
  fields: CalcitTag[];
8
8
  fieldTypes: CalcitValue[];
@@ -11,7 +11,7 @@ export class CalcitStruct {
11
11
 
12
12
  constructor(name: CalcitTag, fields: CalcitTag[], fieldTypes: CalcitValue[], impls: CalcitImpl[] = []) {
13
13
  if (fields.length !== fieldTypes.length) {
14
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
14
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
15
15
  }
16
16
  this.name = name;
17
17
  this.fields = fields;
@@ -20,20 +20,20 @@ export class CalcitStruct {
20
20
  this.cachedHash = null;
21
21
  }
22
22
 
23
- withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStruct {
23
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStructDef {
24
24
  if (impls instanceof CalcitImpl) {
25
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, [impls]);
25
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, [impls]);
26
26
  } else if (Array.isArray(impls)) {
27
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, impls);
27
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, impls);
28
28
  }
29
29
  throw new Error("Expected an impl as implementation");
30
30
  }
31
31
 
32
32
  toString(disableJsDataWarning: boolean = false): string {
33
33
  if (this.fields.length !== this.fieldTypes.length) {
34
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
34
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
35
35
  }
36
- const parts: string[] = ["(%struct '", this.name.value];
36
+ const parts: string[] = ["(%struct-def '", this.name.value];
37
37
  for (let idx = 0; idx < this.fields.length; idx++) {
38
38
  const field = this.fields[idx];
39
39
  const fieldType = this.fieldTypes[idx];