@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
|
@@ -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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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 {
|
|
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
|
|
185
|
-
|
|
186
|
-
|
|
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
|
|
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
|
|
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
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
251
|
+
if (obj instanceof CalcitStructValue) {
|
|
280
252
|
return obj.fields.length > 0;
|
|
281
253
|
}
|
|
282
|
-
if (obj instanceof
|
|
283
|
-
return obj instanceof
|
|
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
|
|
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
|
|
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
|
|
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(
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -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 {
|
|
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 {
|
|
11
|
-
import {
|
|
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,7 +151,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
151
151
|
}
|
|
152
152
|
return buffer;
|
|
153
153
|
}
|
|
154
|
-
if (x instanceof
|
|
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])]);
|
|
@@ -174,7 +174,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
174
174
|
}
|
|
175
175
|
return buffer;
|
|
176
176
|
}
|
|
177
|
-
if (x instanceof
|
|
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;
|
|
@@ -182,7 +182,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
182
182
|
let enumTag = unwrap_enum_prototype_local(x.enumPrototype).name.toString();
|
|
183
183
|
if (x.tag instanceof CalcitTag) {
|
|
184
184
|
return ["%::", enumTag, x.tag.toString(), ...x.extra.map(to_cirru_edn)];
|
|
185
|
-
} else if (x.tag instanceof
|
|
185
|
+
} else if (x.tag instanceof CalcitStructValue) {
|
|
186
186
|
return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
187
187
|
} else if (x.tag instanceof CalcitImpl) {
|
|
188
188
|
return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
@@ -191,7 +191,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
191
191
|
}
|
|
192
192
|
} else if (x.tag instanceof CalcitTag) {
|
|
193
193
|
return ["::", x.tag.toString(), ...x.extra.map(to_cirru_edn)];
|
|
194
|
-
} else if (x.tag instanceof
|
|
194
|
+
} else if (x.tag instanceof CalcitStructValue) {
|
|
195
195
|
return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
196
196
|
} else if (x.tag instanceof CalcitImpl) {
|
|
197
197
|
return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
@@ -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
|
|
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
|
|
244
|
-
const unwrap_enum_prototype_local = (enumPrototype: CalcitValue):
|
|
245
|
-
if (enumPrototype instanceof
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
363
|
+
if (v != null && v instanceof CalcitStructValue) {
|
|
364
364
|
if (deepEqual(v.fields, fields)) {
|
|
365
|
-
return new
|
|
365
|
+
return new CalcitStructValue(extractFieldTag(name), fields, values, v.structRef);
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
-
return new
|
|
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(`
|
|
405
|
+
throw new Error(`anonymous enum expects at least 1 value, got: ${x}`);
|
|
406
406
|
}
|
|
407
|
-
return new
|
|
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
|
|
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
|
|
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
|
|
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 {
|
|
1
|
+
import { CalcitStructValue } from "./js-struct-value.mjs";
|
|
2
2
|
import { CalcitImpl } from "./js-impl.mjs";
|
|
3
3
|
|
|
4
|
-
export class
|
|
5
|
-
prototype:
|
|
4
|
+
export class CalcitEnumDef {
|
|
5
|
+
prototype: CalcitStructValue;
|
|
6
6
|
cachedHash: number;
|
|
7
7
|
|
|
8
|
-
constructor(prototype:
|
|
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[]):
|
|
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
|
|
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 {
|
|
7
|
-
import { CalcitEnum } from "./js-enum.mjs";
|
|
6
|
+
import { CalcitEnumDef } from "./js-enum-def.mjs";
|
|
8
7
|
|
|
9
|
-
export class
|
|
8
|
+
export class CalcitEnumValue {
|
|
10
9
|
tag: CalcitValue;
|
|
11
10
|
extra: CalcitValue[];
|
|
12
|
-
enumPrototype:
|
|
11
|
+
enumPrototype: CalcitEnumDef;
|
|
13
12
|
cachedHash: Hash;
|
|
14
|
-
constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype:
|
|
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
|
-
|
|
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(`
|
|
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
|
|
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
|
|
42
|
+
return new CalcitEnumValue(this.tag, next_extra, this.enumPrototype);
|
|
47
43
|
} else {
|
|
48
|
-
throw new Error(`
|
|
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:
|
|
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 ?
|
|
74
|
+
const enumName = hasEnum ? this.enumPrototype.name() : null;
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
return `(%:: ${content} (:enum ${enumName}))`;
|
|
82
|
-
}
|
|
83
|
-
return `(:: ${content})`;
|
|
76
|
+
return `(%:: ${hasEnum ? `'${enumName}` : "_"} ${content})`;
|
|
84
77
|
}
|
|
85
78
|
}
|
package/ts-src/js-list.mts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
443
|
+
if (pair instanceof CalcitEnumValue) {
|
|
444
444
|
if (typeof pair.tag === "boolean") {
|
|
445
445
|
if (pair.tag) {
|
|
446
446
|
return pair.get(1);
|
package/ts-src/js-primes.mts
CHANGED
|
@@ -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 {
|
|
4
|
+
import { CalcitStructValue } from "./js-struct-value.mjs";
|
|
5
5
|
import { CalcitImpl } from "./js-impl.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
|
26
|
+
| CalcitEnumValue
|
|
27
27
|
| CalcitFn
|
|
28
28
|
| CalcitRecur // should not be exposed to function
|
|
29
|
-
|
|
|
29
|
+
| CalcitStructValue
|
|
30
30
|
| CalcitImpl
|
|
31
31
|
| CalcitTrait
|
|
32
|
-
|
|
|
33
|
-
|
|
|
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
|
-
|
|
55
|
+
enum_value,
|
|
56
56
|
recur,
|
|
57
57
|
list,
|
|
58
58
|
set,
|
|
59
59
|
map,
|
|
60
|
-
|
|
60
|
+
struct_value,
|
|
61
61
|
impl,
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
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
|
|
83
|
+
if (x instanceof CalcitStructValue) return PseudoTypeIndex.struct_value;
|
|
84
84
|
if (x instanceof CalcitImpl) return PseudoTypeIndex.impl;
|
|
85
|
-
if (x instanceof
|
|
86
|
-
if (x instanceof
|
|
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
|
|
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("
|
|
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[]):
|
|
23
|
+
withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStructDef {
|
|
24
24
|
if (impls instanceof CalcitImpl) {
|
|
25
|
-
return new
|
|
25
|
+
return new CalcitStructDef(this.name, this.fields, this.fieldTypes, [impls]);
|
|
26
26
|
} else if (Array.isArray(impls)) {
|
|
27
|
-
return new
|
|
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("
|
|
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];
|