@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
@@ -1,13 +1,13 @@
1
1
  import { isLiteral } from "./js-primes.mjs";
2
2
  import { CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
3
3
  import { CalcitRef } from "./js-ref.mjs";
4
- import { CalcitRecord } from "./js-record.mjs";
5
- import { CalcitStruct } from "./js-struct.mjs";
6
- import { CalcitEnum } from "./js-enum.mjs";
4
+ import { CalcitStructValue } from "./js-struct-value.mjs";
5
+ import { CalcitStructDef } from "./js-struct-def.mjs";
6
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
7
7
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
8
8
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
9
9
  import { CalcitSet } from "./js-set.mjs";
10
- import { CalcitTuple } from "./js-tuple.mjs";
10
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
11
11
  import { CalcitCirruQuote } from "./js-cirru.mjs";
12
12
  let embedObject = (x) => {
13
13
  if (x == null) {
@@ -150,38 +150,23 @@ export let load_console_formatter_$x_ = () => {
150
150
  color: hsl(280, 80, 80, 0.8),
151
151
  }, `${obj.len()}`), preview);
152
152
  }
153
- if (obj instanceof CalcitRecord) {
154
- let name = new CalcitSymbol(obj.name.value);
155
- if (obj.structRef.impls.length > 0) {
156
- let ret = div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, span({}, "%{}"), span({ marginLeft: "6px" }, embedObject(obj.structRef.impls[0])), span({ marginLeft: "6px" }, embedObject(name)), span({ marginLeft: "6px" }, `...`));
157
- return ret;
158
- }
159
- else {
160
- let ret = div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%{} ", embedObject(name), " ...");
161
- return ret;
162
- }
153
+ if (obj instanceof CalcitStructValue) {
154
+ const name = new CalcitSymbol(obj.name.value);
155
+ return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%{} ", embedObject(name), " ...");
163
156
  }
164
- if (obj instanceof CalcitStruct) {
165
- return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%struct ", embedObject(new CalcitSymbol(obj.name.value)), " ...");
157
+ if (obj instanceof CalcitStructDef) {
158
+ return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%struct-def ", embedObject(new CalcitSymbol(obj.name.value)), " ...");
166
159
  }
167
- if (obj instanceof CalcitEnum) {
168
- return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%enum ", embedObject(new CalcitSymbol(obj.prototype.name.value)), " ...");
160
+ if (obj instanceof CalcitEnumDef) {
161
+ return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%enum-def ", embedObject(new CalcitSymbol(obj.prototype.name.value)), " ...");
169
162
  }
170
- if (obj instanceof CalcitTuple) {
171
- if (obj.impls.length > 0) {
172
- let ret = div({ marginRight: "16px" }, div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.impls[0])), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag)));
173
- for (let idx = 0; idx < obj.extra.length; idx++) {
174
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
175
- }
176
- return ret;
177
- }
178
- else {
179
- let ret = div({ marginRight: "16px" }, div({ display: "inline-block", color: hsl(300, 100, 40) }, "::"), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag)));
180
- for (let idx = 0; idx < obj.extra.length; idx++) {
181
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
182
- }
183
- return ret;
163
+ if (obj instanceof CalcitEnumValue) {
164
+ const enumName = obj.enumPrototype == null ? "_" : obj.enumPrototype.name();
165
+ let ret = div({ marginRight: "16px" }, div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"), div({ marginLeft: "6px", display: "inline-block" }, embedObject(new CalcitSymbol(enumName))), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag)));
166
+ for (let idx = 0; idx < obj.extra.length; idx++) {
167
+ ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
184
168
  }
169
+ return ret;
185
170
  }
186
171
  if (obj instanceof CalcitRef) {
187
172
  return div({
@@ -206,11 +191,11 @@ export let load_console_formatter_$x_ = () => {
206
191
  let hasCollection = obj.nestedDataInChildren();
207
192
  return obj.len() > 0 && hasCollection;
208
193
  }
209
- if (obj instanceof CalcitRecord) {
194
+ if (obj instanceof CalcitStructValue) {
210
195
  return obj.fields.length > 0;
211
196
  }
212
- if (obj instanceof CalcitStruct || obj instanceof CalcitEnum) {
213
- return obj instanceof CalcitStruct ? obj.fields.length > 0 : obj.prototype.fields.length > 0;
197
+ if (obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef) {
198
+ return obj instanceof CalcitStructDef ? obj.fields.length > 0 : obj.prototype.fields.length > 0;
214
199
  }
215
200
  return false;
216
201
  },
@@ -260,21 +245,21 @@ export let load_console_formatter_$x_ = () => {
260
245
  }
261
246
  return ret;
262
247
  }
263
- if (obj instanceof CalcitRecord) {
248
+ if (obj instanceof CalcitStructValue) {
264
249
  let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
265
250
  for (let idx = 0; idx < obj.fields.length; idx++) {
266
251
  ret.push(tr({}, td({ paddingLeft: "8px", verticalAlign: "top", whiteSpace: "pre", minWidth: "40px" }, embedObject(obj.fields[idx])), td({ paddingLeft: "8px" }, embedObject(obj.values[idx]))));
267
252
  }
268
253
  return ret;
269
254
  }
270
- if (obj instanceof CalcitStruct) {
255
+ if (obj instanceof CalcitStructDef) {
271
256
  let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
272
257
  for (let idx = 0; idx < obj.fields.length; idx++) {
273
258
  ret.push(tr({}, td({ paddingLeft: "8px", verticalAlign: "top", whiteSpace: "pre", minWidth: "40px" }, embedObject(obj.fields[idx])), td({ paddingLeft: "8px" }, embedObject(obj.fieldTypes[idx]))));
274
259
  }
275
260
  return ret;
276
261
  }
277
- if (obj instanceof CalcitEnum) {
262
+ if (obj instanceof CalcitEnumDef) {
278
263
  let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
279
264
  for (let idx = 0; idx < obj.prototype.fields.length; idx++) {
280
265
  ret.push(tr({}, td({ paddingLeft: "8px", verticalAlign: "top", whiteSpace: "pre", minWidth: "40px" }, embedObject(obj.prototype.fields[idx])), td({ paddingLeft: "8px" }, embedObject(obj.prototype.values[idx]))));
package/lib/js-cirru.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { writeCirruCode, writeCirruOneLiner } from "@cirru/writer.ts";
2
2
  import { isLiteral, _$n_compare } from "./js-primes.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 { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
6
6
  import { CalcitSet } from "./js-set.mjs";
7
7
  import { CalcitTag, CalcitSymbol, CalcitRecur, newTag } from "./calcit-data.mjs";
8
- import { CalcitTuple } from "./js-tuple.mjs";
9
- import { CalcitEnum } from "./js-enum.mjs";
8
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
9
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
10
10
  import { CalcitImpl } from "./js-impl.mjs";
11
11
  import { CalcitRef } from "./js-ref.mjs";
12
12
  import { deepEqual } from "@calcit/ternary-tree/lib/utils.mjs";
@@ -148,14 +148,14 @@ export let to_cirru_edn = (x) => {
148
148
  }
149
149
  return buffer;
150
150
  }
151
- if (x instanceof CalcitRecord) {
151
+ if (x instanceof CalcitStructValue) {
152
152
  let buffer = [];
153
153
  for (let idx = 0; idx < x.fields.length; idx++) {
154
154
  buffer.push([x.fields[idx].toString(), to_cirru_edn(x.values[idx])]);
155
155
  }
156
156
  // placed literals first
157
157
  buffer.sort(recordFieldOrder);
158
- buffer.unshift(x.name.toString());
158
+ buffer.unshift(new CalcitSymbol(x.name.value).toString());
159
159
  buffer.unshift("%{}");
160
160
  return buffer;
161
161
  }
@@ -171,34 +171,34 @@ export let to_cirru_edn = (x) => {
171
171
  }
172
172
  return buffer;
173
173
  }
174
- if (x instanceof CalcitTuple) {
174
+ if (x instanceof CalcitEnumValue) {
175
175
  if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
176
176
  // turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
177
177
  return ["quote", toWriterNode(x.get(1))];
178
178
  }
179
179
  else if (x.enumPrototype != null) {
180
- let enumTag = unwrap_enum_prototype_local(x.enumPrototype).name.toString();
180
+ let enumTag = new CalcitSymbol(unwrap_enum_prototype_local(x.enumPrototype).name.value).toString();
181
181
  if (x.tag instanceof CalcitTag) {
182
- return ["%::", enumTag, x.tag.toString(), ...x.extra.map(to_cirru_edn)];
182
+ return ["%::", enumTag, new CalcitSymbol(x.tag.value).toString(), ...x.extra.map(to_cirru_edn)];
183
183
  }
184
- else if (x.tag instanceof CalcitRecord) {
185
- return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
184
+ else if (x.tag instanceof CalcitStructValue) {
185
+ return ["%::", enumTag, new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
186
186
  }
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
  }
190
190
  else {
191
191
  throw new Error(`Unsupported tag for EDN: ${x.tag}`);
192
192
  }
193
193
  }
194
194
  else if (x.tag instanceof CalcitTag) {
195
- return ["::", x.tag.toString(), ...x.extra.map(to_cirru_edn)];
195
+ return ["::", new CalcitSymbol(x.tag.value).toString(), ...x.extra.map(to_cirru_edn)];
196
196
  }
197
- else if (x.tag instanceof CalcitRecord) {
198
- return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
197
+ else if (x.tag instanceof CalcitStructValue) {
198
+ return ["::", new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
199
199
  }
200
200
  else if (x.tag instanceof CalcitImpl) {
201
- return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
201
+ return ["::", new CalcitSymbol(x.tag.name.value).toString(), ...x.extra.map(to_cirru_edn)];
202
202
  }
203
203
  else {
204
204
  throw new Error(`Unsupported tag for EDN: ${x.tag}`);
@@ -235,29 +235,29 @@ let extractFieldTag = (x) => {
235
235
  let resolveEnumPrototype = (enumName, options) => {
236
236
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
237
237
  let value = options.get(extractFieldTag(enumName));
238
- if (value instanceof CalcitEnum || value instanceof CalcitRecord) {
238
+ if (value instanceof CalcitEnumDef) {
239
239
  return value;
240
240
  }
241
+ if (value instanceof CalcitStructValue) {
242
+ throw new Error(`Enum ${enumName} uses a legacy struct prototype; provide an EnumDef produced by defenum`);
243
+ }
241
244
  if (value != null) {
242
245
  throw new Error(`Expected enum prototype for ${enumName}, got: ${value}`);
243
246
  }
244
247
  }
245
248
  return null;
246
249
  };
247
- // local helper to unwrap an enum prototype value to a CalcitRecord prototype
250
+ // local helper to inspect an EnumDef's variant prototype
248
251
  const unwrap_enum_prototype_local = (enumPrototype) => {
249
- if (enumPrototype instanceof CalcitEnum) {
252
+ if (enumPrototype instanceof CalcitEnumDef) {
250
253
  return enumPrototype.prototype;
251
254
  }
252
- if (enumPrototype instanceof CalcitRecord) {
253
- return enumPrototype;
254
- }
255
- throw new Error(`expected enum prototype`);
255
+ throw new Error(`expected an EnumDef produced by defenum`);
256
256
  };
257
257
  const tag_to_string = (tag) => {
258
258
  if (tag instanceof CalcitTag)
259
259
  return tag.toString();
260
- if (tag instanceof CalcitRecord)
260
+ if (tag instanceof CalcitStructValue)
261
261
  return tag.name.toString();
262
262
  throw new Error(`Unsupported tag for EDN: ${tag}`);
263
263
  };
@@ -330,7 +330,7 @@ const extract_cirru_edn_inner = (x, options, preserveSourceEntries) => {
330
330
  if (x[0] === "%{}") {
331
331
  let name = x[1];
332
332
  if (typeof name != "string") {
333
- throw new Error(`Expected string for record name, got: ${name}`);
333
+ throw new Error(`Expected string for struct name, got: ${name}`);
334
334
  }
335
335
  // put to entries first, sort and then...
336
336
  let entries = [];
@@ -357,7 +357,7 @@ const extract_cirru_edn_inner = (x, options, preserveSourceEntries) => {
357
357
  }
358
358
  }
359
359
  else {
360
- throw new Error(`Expected pairs for record, got: ${pair}`);
360
+ throw new Error(`Expected field pairs for struct, got: ${pair}`);
361
361
  }
362
362
  });
363
363
  entries.sort((a, b) => {
@@ -371,13 +371,13 @@ const extract_cirru_edn_inner = (x, options, preserveSourceEntries) => {
371
371
  }
372
372
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
373
373
  let v = options.get(extractFieldTag(name));
374
- if (v != null && v instanceof CalcitRecord) {
374
+ if (v != null && v instanceof CalcitStructValue) {
375
375
  if (deepEqual(v.fields, fields)) {
376
- return new CalcitRecord(extractFieldTag(name), fields, values, v.structRef);
376
+ return new CalcitStructValue(extractFieldTag(name), fields, values, v.structRef);
377
377
  }
378
378
  }
379
379
  }
380
- return new CalcitRecord(extractFieldTag(name), fields, values);
380
+ return new CalcitStructValue(extractFieldTag(name), fields, values);
381
381
  }
382
382
  let notComment = (x) => {
383
383
  if (x instanceof Array && x[0] === ";") {
@@ -410,9 +410,9 @@ const extract_cirru_edn_inner = (x, options, preserveSourceEntries) => {
410
410
  }
411
411
  if (x[0] === "::") {
412
412
  if (x.length < 2) {
413
- throw new Error(`tuple expects at least 1 value, got: ${x}`);
413
+ throw new Error(`anonymous enum expects at least 1 value, got: ${x}`);
414
414
  }
415
- return new CalcitTuple(extract_cirru_edn_inner(x[1], options, preserveSourceEntries), x
415
+ return new CalcitEnumValue(extract_cirru_edn_inner(x[1], options, preserveSourceEntries), x
416
416
  .slice(2)
417
417
  .filter(notComment)
418
418
  .map((x) => extract_cirru_edn_inner(x, options, preserveSourceEntries)));
@@ -429,7 +429,7 @@ const extract_cirru_edn_inner = (x, options, preserveSourceEntries) => {
429
429
  // unwrap prototype to record then extract name
430
430
  const proto = enumPrototype != null ? unwrap_enum_prototype_local(enumPrototype) : null;
431
431
  const enumTag = proto != null ? proto.name.toString() : enumName;
432
- return new CalcitTuple(extract_cirru_edn_inner(x[2], options, preserveSourceEntries), x
432
+ return new CalcitEnumValue(extract_cirru_edn_inner(x[2], options, preserveSourceEntries), x
433
433
  .slice(3)
434
434
  .filter(notComment)
435
435
  .map((x) => extract_cirru_edn_inner(x, options, preserveSourceEntries)), enumPrototype);
@@ -504,7 +504,7 @@ export let to_calcit_data = (x, noKeyword = false) => {
504
504
  return x;
505
505
  if (x instanceof CalcitSet)
506
506
  return x;
507
- if (x instanceof CalcitRecord)
507
+ if (x instanceof CalcitStructValue)
508
508
  return x;
509
509
  if (x instanceof CalcitRecur)
510
510
  return x;
@@ -514,7 +514,7 @@ export let to_calcit_data = (x, noKeyword = false) => {
514
514
  return x;
515
515
  if (x instanceof CalcitSymbol)
516
516
  return x;
517
- if (x instanceof CalcitTuple)
517
+ if (x instanceof CalcitEnumValue)
518
518
  return x;
519
519
  // detects object
520
520
  if (x === Object(x)) {
@@ -0,0 +1,11 @@
1
+ import { CalcitStructValue } from "./js-struct-value.mjs";
2
+ import { CalcitImpl } from "./js-impl.mjs";
3
+ export declare class CalcitEnumDef {
4
+ prototype: CalcitStructValue;
5
+ cachedHash: number;
6
+ constructor(prototype: CalcitStructValue);
7
+ name(): string;
8
+ get impls(): CalcitImpl[];
9
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitEnumDef;
10
+ toString(): string;
11
+ }
@@ -1,5 +1,5 @@
1
1
  import { CalcitImpl } from "./js-impl.mjs";
2
- export class CalcitEnum {
2
+ export class CalcitEnumDef {
3
3
  constructor(prototype) {
4
4
  this.prototype = prototype;
5
5
  this.cachedHash = null;
@@ -21,9 +21,9 @@ export class CalcitEnum {
21
21
  else {
22
22
  throw new Error("Expected an impl as implementation");
23
23
  }
24
- return new CalcitEnum(this.prototype.withImpls(nextImpls));
24
+ return new CalcitEnumDef(this.prototype.withImpls(nextImpls));
25
25
  }
26
26
  toString() {
27
- return `(%enum '${this.prototype.name.value})`;
27
+ return `(%enum-def '${this.prototype.name.value})`;
28
28
  }
29
29
  }
@@ -1,18 +1,17 @@
1
1
  import { Hash } from "@calcit/ternary-tree";
2
2
  import { CalcitValue } from "./js-primes.mjs";
3
3
  import { CalcitImpl } from "./js-impl.mjs";
4
- import { CalcitRecord } from "./js-record.mjs";
5
- import { CalcitEnum } from "./js-enum.mjs";
6
- export declare class CalcitTuple {
4
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
5
+ export declare class CalcitEnumValue {
7
6
  tag: CalcitValue;
8
7
  extra: CalcitValue[];
9
- enumPrototype: CalcitRecord | CalcitEnum;
8
+ enumPrototype: CalcitEnumDef;
10
9
  cachedHash: Hash;
11
- constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype?: CalcitRecord | CalcitEnum);
10
+ constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype?: CalcitEnumDef);
12
11
  get impls(): CalcitImpl[];
13
12
  get(n: number): CalcitValue;
14
- assoc(n: number, v: CalcitValue): CalcitTuple;
13
+ assoc(n: number, v: CalcitValue): CalcitEnumValue;
15
14
  count(): number;
16
- eq(y: CalcitTuple): boolean;
15
+ eq(y: CalcitEnumValue): boolean;
17
16
  toString(disableJsDataWarning?: boolean): string;
18
17
  }
@@ -1,6 +1,5 @@
1
1
  import { _$n__$e_, toString } from "./calcit-data.mjs";
2
- import { CalcitEnum } from "./js-enum.mjs";
3
- export class CalcitTuple {
2
+ export class CalcitEnumValue {
4
3
  constructor(tagName, extra, enumPrototype = null) {
5
4
  this.tag = tagName;
6
5
  this.extra = extra;
@@ -11,10 +10,7 @@ export class CalcitTuple {
11
10
  if (this.enumPrototype == null) {
12
11
  return [];
13
12
  }
14
- if (this.enumPrototype instanceof CalcitEnum) {
15
- return this.enumPrototype.impls;
16
- }
17
- return this.enumPrototype.structRef.impls;
13
+ return this.enumPrototype.impls;
18
14
  }
19
15
  get(n) {
20
16
  if (n === 0) {
@@ -24,20 +20,20 @@ export class CalcitTuple {
24
20
  return this.extra[n - 1];
25
21
  }
26
22
  else {
27
- throw new Error(`Tuple only have ${this.extra.length + 1} elements`);
23
+ throw new Error(`Enum value only has ${this.extra.length + 1} elements`);
28
24
  }
29
25
  }
30
26
  assoc(n, v) {
31
27
  if (n === 0) {
32
- return new CalcitTuple(v, this.extra, this.enumPrototype);
28
+ return new CalcitEnumValue(v, this.extra, this.enumPrototype);
33
29
  }
34
30
  else if (n - 1 < this.extra.length) {
35
31
  let next_extra = this.extra.slice();
36
32
  next_extra[n - 1] = v;
37
- return new CalcitTuple(this.tag, next_extra, this.enumPrototype);
33
+ return new CalcitEnumValue(this.tag, next_extra, this.enumPrototype);
38
34
  }
39
35
  else {
40
- throw new Error(`Tuple only have ${this.extra.length} elements`);
36
+ throw new Error(`Enum value only has ${this.extra.length} elements`);
41
37
  }
42
38
  }
43
39
  count() {
@@ -67,10 +63,7 @@ export class CalcitTuple {
67
63
  content += toString(args[i], true, disableJsDataWarning);
68
64
  }
69
65
  const hasEnum = this.enumPrototype != null;
70
- const enumName = hasEnum ? (this.enumPrototype instanceof CalcitEnum ? this.enumPrototype.prototype.name.value : this.enumPrototype.name.value) : null;
71
- if (hasEnum) {
72
- return `(%:: ${content} (:enum ${enumName}))`;
73
- }
74
- return `(:: ${content})`;
66
+ const enumName = hasEnum ? this.enumPrototype.name() : null;
67
+ return `(%:: ${hasEnum ? `'${enumName}` : "_"} ${content})`;
75
68
  }
76
69
  }
package/lib/js-list.mjs CHANGED
@@ -3,7 +3,7 @@ import { isLiteral } from "./js-primes.mjs";
3
3
  import { initTernaryTreeList, initTernaryTreeListFromRange, listLen, listGet, assocList, listToItems, dissocList, assocBefore, assocAfter, } from "@calcit/ternary-tree";
4
4
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
5
5
  import { CalcitSet } from "./js-set.mjs";
6
- import { CalcitTuple } from "./js-tuple.mjs";
6
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
7
7
  import { isNestedCalcitData, tipNestedCalcitData, toString } from "./calcit-data.mjs";
8
8
  // two list implementations, should offer same interface
9
9
  export class CalcitList {
@@ -328,7 +328,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
328
328
  for (let idx = 0; idx < size; idx++) {
329
329
  let item = xs.get(idx);
330
330
  let pair = f(state, item);
331
- if (pair instanceof CalcitTuple) {
331
+ if (pair instanceof CalcitEnumValue) {
332
332
  if (typeof pair.tag === "boolean") {
333
333
  if (pair.tag) {
334
334
  return pair.get(1);
@@ -350,7 +350,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
350
350
  for (let idx = 0; idx < values.length; idx++) {
351
351
  let item = values[idx];
352
352
  let pair = f(state, item);
353
- if (pair instanceof CalcitTuple) {
353
+ if (pair instanceof CalcitEnumValue) {
354
354
  if (typeof pair.tag === "boolean") {
355
355
  if (pair.tag) {
356
356
  return pair.get(1);
@@ -373,7 +373,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
373
373
  for (let i = 0; i < size; i++) {
374
374
  let pos = i << 1;
375
375
  let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
376
- if (pair instanceof CalcitTuple) {
376
+ if (pair instanceof CalcitEnumValue) {
377
377
  if (typeof pair.tag === "boolean") {
378
378
  if (pair.tag) {
379
379
  return pair.get(1);
@@ -395,7 +395,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
395
395
  for (let idx = 0; idx < pairs.length; idx++) {
396
396
  let item = pairs[idx];
397
397
  let pair = f(state, new CalcitSliceList(item));
398
- if (pair instanceof CalcitTuple) {
398
+ if (pair instanceof CalcitEnumValue) {
399
399
  if (typeof pair.tag === "boolean") {
400
400
  if (pair.tag) {
401
401
  return pair.get(1);
@@ -426,7 +426,7 @@ export let foldr_shortcut = function (xs, acc, v0, f) {
426
426
  for (let idx = xs.len() - 1; idx >= 0; idx--) {
427
427
  let item = xs.get(idx);
428
428
  let pair = f(state, item);
429
- if (pair instanceof CalcitTuple) {
429
+ if (pair instanceof CalcitEnumValue) {
430
430
  if (typeof pair.tag === "boolean") {
431
431
  if (pair.tag) {
432
432
  return pair.get(1);
@@ -1,15 +1,15 @@
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 } from "./js-cirru.mjs";
12
12
  import { CalcitTrait } from "./js-trait.mjs";
13
- export type CalcitValue = string | number | boolean | CalcitMap | CalcitSliceMap | CalcitList | CalcitSliceList | CalcitSet | CalcitTag | CalcitSymbol | CalcitRef | CalcitTuple | CalcitFn | CalcitRecur | CalcitRecord | CalcitImpl | CalcitTrait | CalcitStruct | CalcitEnum | CalcitCirruQuote | null;
13
+ export type CalcitValue = string | number | boolean | CalcitMap | CalcitSliceMap | CalcitList | CalcitSliceList | CalcitSet | CalcitTag | CalcitSymbol | CalcitRef | CalcitEnumValue | CalcitFn | CalcitRecur | CalcitStructValue | CalcitImpl | CalcitTrait | CalcitStructDef | CalcitEnumDef | CalcitCirruQuote | null;
14
14
  export declare let isLiteral: (x: CalcitValue) => boolean;
15
15
  export declare let _$n_compare: (a: CalcitValue, b: CalcitValue) => number;
package/lib/js-primes.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { CalcitTag, CalcitSymbol, 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 } from "./js-cirru.mjs";
12
12
  export let isLiteral = (x) => {
13
13
  if (x == null)
@@ -33,15 +33,15 @@ var PseudoTypeIndex;
33
33
  PseudoTypeIndex[PseudoTypeIndex["tag"] = 4] = "tag";
34
34
  PseudoTypeIndex[PseudoTypeIndex["string"] = 5] = "string";
35
35
  PseudoTypeIndex[PseudoTypeIndex["ref"] = 6] = "ref";
36
- PseudoTypeIndex[PseudoTypeIndex["tuple"] = 7] = "tuple";
36
+ PseudoTypeIndex[PseudoTypeIndex["enum_value"] = 7] = "enum_value";
37
37
  PseudoTypeIndex[PseudoTypeIndex["recur"] = 8] = "recur";
38
38
  PseudoTypeIndex[PseudoTypeIndex["list"] = 9] = "list";
39
39
  PseudoTypeIndex[PseudoTypeIndex["set"] = 10] = "set";
40
40
  PseudoTypeIndex[PseudoTypeIndex["map"] = 11] = "map";
41
- PseudoTypeIndex[PseudoTypeIndex["record"] = 12] = "record";
41
+ PseudoTypeIndex[PseudoTypeIndex["struct_value"] = 12] = "struct_value";
42
42
  PseudoTypeIndex[PseudoTypeIndex["impl"] = 13] = "impl";
43
- PseudoTypeIndex[PseudoTypeIndex["struct"] = 14] = "struct";
44
- PseudoTypeIndex[PseudoTypeIndex["enum_type"] = 15] = "enum_type";
43
+ PseudoTypeIndex[PseudoTypeIndex["struct_def"] = 14] = "struct_def";
44
+ PseudoTypeIndex[PseudoTypeIndex["enum_def"] = 15] = "enum_def";
45
45
  PseudoTypeIndex[PseudoTypeIndex["fn"] = 16] = "fn";
46
46
  PseudoTypeIndex[PseudoTypeIndex["cirru_quote"] = 17] = "cirru_quote";
47
47
  })(PseudoTypeIndex || (PseudoTypeIndex = {}));
@@ -62,8 +62,8 @@ let typeAsInt = (x) => {
62
62
  return PseudoTypeIndex.string;
63
63
  if (x instanceof CalcitRef)
64
64
  return PseudoTypeIndex.ref;
65
- if (x instanceof CalcitTuple)
66
- return PseudoTypeIndex.tuple;
65
+ if (x instanceof CalcitEnumValue)
66
+ return PseudoTypeIndex.enum_value;
67
67
  if (x instanceof CalcitRecur)
68
68
  return PseudoTypeIndex.recur;
69
69
  if (x instanceof CalcitList || x instanceof CalcitSliceList)
@@ -72,14 +72,14 @@ let typeAsInt = (x) => {
72
72
  return PseudoTypeIndex.set;
73
73
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap)
74
74
  return PseudoTypeIndex.map;
75
- if (x instanceof CalcitRecord)
76
- return PseudoTypeIndex.record;
75
+ if (x instanceof CalcitStructValue)
76
+ return PseudoTypeIndex.struct_value;
77
77
  if (x instanceof CalcitImpl)
78
78
  return PseudoTypeIndex.impl;
79
- if (x instanceof CalcitStruct)
80
- return PseudoTypeIndex.struct;
81
- if (x instanceof CalcitEnum)
82
- return PseudoTypeIndex.enum_type;
79
+ if (x instanceof CalcitStructDef)
80
+ return PseudoTypeIndex.struct_def;
81
+ if (x instanceof CalcitEnumDef)
82
+ return PseudoTypeIndex.enum_def;
83
83
  if (x instanceof CalcitCirruQuote)
84
84
  return PseudoTypeIndex.cirru_quote;
85
85
  // proc, fn, macro, syntax, not distinguished
@@ -1,13 +1,13 @@
1
1
  import { CalcitTag } from "./calcit-data.mjs";
2
2
  import { CalcitValue } from "./js-primes.mjs";
3
3
  import { CalcitImpl } from "./js-impl.mjs";
4
- export declare class CalcitStruct {
4
+ export declare class CalcitStructDef {
5
5
  name: CalcitTag;
6
6
  fields: CalcitTag[];
7
7
  fieldTypes: CalcitValue[];
8
8
  impls: CalcitImpl[];
9
9
  cachedHash: number;
10
10
  constructor(name: CalcitTag, fields: CalcitTag[], fieldTypes: CalcitValue[], impls?: CalcitImpl[]);
11
- withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStruct;
11
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStructDef;
12
12
  toString(disableJsDataWarning?: boolean): string;
13
13
  }
@@ -1,9 +1,9 @@
1
1
  import { toString } from "./calcit-data.mjs";
2
2
  import { CalcitImpl } from "./js-impl.mjs";
3
- export class CalcitStruct {
3
+ export class CalcitStructDef {
4
4
  constructor(name, fields, fieldTypes, impls = []) {
5
5
  if (fields.length !== fieldTypes.length) {
6
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
6
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
7
7
  }
8
8
  this.name = name;
9
9
  this.fields = fields;
@@ -13,18 +13,18 @@ export class CalcitStruct {
13
13
  }
14
14
  withImpls(impls) {
15
15
  if (impls instanceof CalcitImpl) {
16
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, [impls]);
16
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, [impls]);
17
17
  }
18
18
  else if (Array.isArray(impls)) {
19
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, impls);
19
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, impls);
20
20
  }
21
21
  throw new Error("Expected an impl as implementation");
22
22
  }
23
23
  toString(disableJsDataWarning = false) {
24
24
  if (this.fields.length !== this.fieldTypes.length) {
25
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
25
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
26
26
  }
27
- const parts = ["(%struct '", this.name.value];
27
+ const parts = ["(%struct-def '", this.name.value];
28
28
  for (let idx = 0; idx < this.fields.length; idx++) {
29
29
  const field = this.fields[idx];
30
30
  const fieldType = this.fieldTypes[idx];