@calcit/procs 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarn/install-state.gz +0 -0
- package/editing-history/202608061714-struct-enum-data-model-v2.md +39 -0
- package/editing-history/202608061731-release-0.13.2.md +18 -0
- package/history/202608061433-required-record-field-access.md +32 -0
- package/lib/calcit-data.mjs +24 -24
- package/lib/calcit.procs.d.mts +43 -43
- package/lib/calcit.procs.mjs +165 -168
- package/lib/custom-formatter.mjs +23 -38
- package/lib/js-cirru.mjs +25 -25
- package/lib/js-enum-def.d.mts +11 -0
- package/lib/{js-enum.mjs → js-enum-def.mjs} +3 -3
- package/lib/{js-tuple.d.mts → js-enum-value.d.mts} +6 -7
- package/lib/{js-tuple.mjs → js-enum-value.mjs} +8 -15
- package/lib/js-list.mjs +6 -6
- package/lib/js-primes.d.mts +5 -5
- package/lib/js-primes.mjs +16 -16
- package/lib/{js-struct.d.mts → js-struct-def.d.mts} +2 -2
- package/lib/{js-struct.mjs → js-struct-def.mjs} +6 -6
- package/lib/{js-record.d.mts → js-struct-value.d.mts} +16 -15
- package/lib/{js-record.mjs → js-struct-value.mjs} +67 -59
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit-data.mts +24 -24
- package/ts-src/calcit.procs.mts +165 -168
- package/ts-src/custom-formatter.mts +28 -56
- package/ts-src/js-cirru.mts +26 -26
- package/ts-src/{js-enum.mts → js-enum-def.mts} +7 -7
- package/ts-src/{js-tuple.mts → js-enum-value.mts} +12 -19
- package/ts-src/js-list.mts +6 -6
- package/ts-src/js-primes.mts +16 -16
- package/ts-src/{js-struct.mts → js-struct-def.mts} +7 -7
- package/ts-src/{js-record.mts → js-struct-value.mts} +72 -66
- package/lib/js-enum.d.mts +0 -11
package/lib/custom-formatter.mjs
CHANGED
|
@@ -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 {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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 {
|
|
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
|
|
154
|
-
|
|
155
|
-
|
|
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
|
|
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
|
|
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
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
194
|
+
if (obj instanceof CalcitStructValue) {
|
|
210
195
|
return obj.fields.length > 0;
|
|
211
196
|
}
|
|
212
|
-
if (obj instanceof
|
|
213
|
-
return obj instanceof
|
|
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
|
|
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
|
|
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
|
|
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 {
|
|
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 {
|
|
9
|
-
import {
|
|
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,7 +148,7 @@ export let to_cirru_edn = (x) => {
|
|
|
148
148
|
}
|
|
149
149
|
return buffer;
|
|
150
150
|
}
|
|
151
|
-
if (x instanceof
|
|
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])]);
|
|
@@ -171,7 +171,7 @@ export let to_cirru_edn = (x) => {
|
|
|
171
171
|
}
|
|
172
172
|
return buffer;
|
|
173
173
|
}
|
|
174
|
-
if (x instanceof
|
|
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))];
|
|
@@ -181,7 +181,7 @@ export let to_cirru_edn = (x) => {
|
|
|
181
181
|
if (x.tag instanceof CalcitTag) {
|
|
182
182
|
return ["%::", enumTag, x.tag.toString(), ...x.extra.map(to_cirru_edn)];
|
|
183
183
|
}
|
|
184
|
-
else if (x.tag instanceof
|
|
184
|
+
else if (x.tag instanceof CalcitStructValue) {
|
|
185
185
|
return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
186
186
|
}
|
|
187
187
|
else if (x.tag instanceof CalcitImpl) {
|
|
@@ -194,7 +194,7 @@ export let to_cirru_edn = (x) => {
|
|
|
194
194
|
else if (x.tag instanceof CalcitTag) {
|
|
195
195
|
return ["::", x.tag.toString(), ...x.extra.map(to_cirru_edn)];
|
|
196
196
|
}
|
|
197
|
-
else if (x.tag instanceof
|
|
197
|
+
else if (x.tag instanceof CalcitStructValue) {
|
|
198
198
|
return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
|
|
199
199
|
}
|
|
200
200
|
else if (x.tag instanceof CalcitImpl) {
|
|
@@ -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
|
|
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
|
|
250
|
+
// local helper to inspect an EnumDef's variant prototype
|
|
248
251
|
const unwrap_enum_prototype_local = (enumPrototype) => {
|
|
249
|
-
if (enumPrototype instanceof
|
|
252
|
+
if (enumPrototype instanceof CalcitEnumDef) {
|
|
250
253
|
return enumPrototype.prototype;
|
|
251
254
|
}
|
|
252
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
374
|
+
if (v != null && v instanceof CalcitStructValue) {
|
|
375
375
|
if (deepEqual(v.fields, fields)) {
|
|
376
|
-
return new
|
|
376
|
+
return new CalcitStructValue(extractFieldTag(name), fields, values, v.structRef);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
return new
|
|
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(`
|
|
413
|
+
throw new Error(`anonymous enum expects at least 1 value, got: ${x}`);
|
|
414
414
|
}
|
|
415
|
-
return new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 {
|
|
5
|
-
|
|
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:
|
|
8
|
+
enumPrototype: CalcitEnumDef;
|
|
10
9
|
cachedHash: Hash;
|
|
11
|
-
constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype?:
|
|
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):
|
|
13
|
+
assoc(n: number, v: CalcitValue): CalcitEnumValue;
|
|
15
14
|
count(): number;
|
|
16
|
-
eq(y:
|
|
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
|
-
|
|
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
|
-
|
|
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(`
|
|
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
|
|
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
|
|
33
|
+
return new CalcitEnumValue(this.tag, next_extra, this.enumPrototype);
|
|
38
34
|
}
|
|
39
35
|
else {
|
|
40
|
-
throw new Error(`
|
|
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 ?
|
|
71
|
-
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
429
|
+
if (pair instanceof CalcitEnumValue) {
|
|
430
430
|
if (typeof pair.tag === "boolean") {
|
|
431
431
|
if (pair.tag) {
|
|
432
432
|
return pair.get(1);
|
package/lib/js-primes.d.mts
CHANGED
|
@@ -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 {
|
|
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 } 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 |
|
|
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 {
|
|
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 } 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["
|
|
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["
|
|
41
|
+
PseudoTypeIndex[PseudoTypeIndex["struct_value"] = 12] = "struct_value";
|
|
42
42
|
PseudoTypeIndex[PseudoTypeIndex["impl"] = 13] = "impl";
|
|
43
|
-
PseudoTypeIndex[PseudoTypeIndex["
|
|
44
|
-
PseudoTypeIndex[PseudoTypeIndex["
|
|
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
|
|
66
|
-
return PseudoTypeIndex.
|
|
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
|
|
76
|
-
return PseudoTypeIndex.
|
|
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
|
|
80
|
-
return PseudoTypeIndex.
|
|
81
|
-
if (x instanceof
|
|
82
|
-
return PseudoTypeIndex.
|
|
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
|
|
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[]):
|
|
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
|
|
3
|
+
export class CalcitStructDef {
|
|
4
4
|
constructor(name, fields, fieldTypes, impls = []) {
|
|
5
5
|
if (fields.length !== fieldTypes.length) {
|
|
6
|
-
throw new Error("
|
|
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
|
|
16
|
+
return new CalcitStructDef(this.name, this.fields, this.fieldTypes, [impls]);
|
|
17
17
|
}
|
|
18
18
|
else if (Array.isArray(impls)) {
|
|
19
|
-
return new
|
|
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("
|
|
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];
|
|
@@ -2,35 +2,36 @@ import { Hash } from "@calcit/ternary-tree";
|
|
|
2
2
|
import { CalcitValue } from "./js-primes.mjs";
|
|
3
3
|
import { CalcitImpl } from "./js-impl.mjs";
|
|
4
4
|
import { CalcitTag } from "./calcit-data.mjs";
|
|
5
|
-
import {
|
|
6
|
-
export declare class
|
|
5
|
+
import { CalcitStructDef } from "./js-struct-def.mjs";
|
|
6
|
+
export declare class CalcitStructValue {
|
|
7
7
|
name: CalcitTag;
|
|
8
8
|
fields: Array<CalcitTag>;
|
|
9
9
|
values: Array<CalcitValue>;
|
|
10
|
-
structRef:
|
|
10
|
+
structRef: CalcitStructDef;
|
|
11
11
|
cachedHash: Hash;
|
|
12
|
-
constructor(name: CalcitTag, fields: Array<CalcitTag>, values?: Array<CalcitValue>, structRef?:
|
|
12
|
+
constructor(name: CalcitTag, fields: Array<CalcitTag>, values?: Array<CalcitValue>, structRef?: CalcitStructDef);
|
|
13
13
|
get(k: CalcitValue): CalcitValue;
|
|
14
|
+
getRequired(k: CalcitValue): CalcitValue;
|
|
14
15
|
getOrNil(k: CalcitValue): CalcitValue;
|
|
15
|
-
assoc(k: CalcitValue, v: CalcitValue):
|
|
16
|
+
assoc(k: CalcitValue, v: CalcitValue): CalcitStructValue;
|
|
16
17
|
/** return -1 for missing */
|
|
17
18
|
findIndex(k: CalcitValue): number;
|
|
18
19
|
contains(k: CalcitValue): boolean;
|
|
19
20
|
toString(disableJsDataWarning?: boolean): string;
|
|
20
|
-
withImpls(impl: CalcitValue | CalcitImpl[]):
|
|
21
|
+
withImpls(impl: CalcitValue | CalcitImpl[]): CalcitStructValue;
|
|
21
22
|
}
|
|
22
|
-
export declare let
|
|
23
|
-
export declare let
|
|
23
|
+
export declare let new_struct_value: (name: CalcitValue, ...fields: Array<CalcitValue>) => CalcitValue;
|
|
24
|
+
export declare let new_impl_struct_value: (impl: CalcitImpl, name: CalcitValue, ...fields: Array<CalcitValue>) => CalcitValue;
|
|
24
25
|
/** Loose record: `?{} :field1 val1 :field2 val2` – record without a declared struct.
|
|
25
26
|
* Fields are sorted by tag index. The record name is "?" (sentinel). */
|
|
26
27
|
export declare let _$q__$M_: (...xs: Array<CalcitValue>) => CalcitValue;
|
|
27
28
|
export declare let fieldsEqual: (xs: Array<CalcitTag>, ys: Array<CalcitTag>) => boolean;
|
|
28
29
|
export declare let _$n__PCT__$M_: (proto: CalcitValue, ...xs: Array<CalcitValue>) => CalcitValue;
|
|
29
30
|
export declare let _$n__PCT__$M__$q_: (proto: CalcitValue, ...xs: Array<CalcitValue>) => CalcitValue;
|
|
30
|
-
export declare let _$
|
|
31
|
-
export declare let _$
|
|
32
|
-
export declare let _$
|
|
33
|
-
export declare let _$
|
|
34
|
-
export declare let _$
|
|
35
|
-
export declare let _$
|
|
36
|
-
export declare function _$
|
|
31
|
+
export declare let _$n_struct_$o_with: (proto: CalcitValue, ...xs: Array<CalcitValue>) => CalcitValue;
|
|
32
|
+
export declare let _$n_struct_$o_get_name: (x: CalcitValue) => CalcitTag;
|
|
33
|
+
export declare let _$n_struct_$o_definition: (x: CalcitValue) => CalcitValue;
|
|
34
|
+
export declare let _$n_struct_$o_from_map: (proto: CalcitValue, data: CalcitValue) => CalcitValue;
|
|
35
|
+
export declare let _$n_struct_$o_to_map: (x: CalcitValue) => CalcitValue;
|
|
36
|
+
export declare let _$n_struct_$o_matches_$q_: (x: CalcitValue, y: CalcitValue) => boolean;
|
|
37
|
+
export declare function _$n_struct_$o_extend_as(obj: CalcitValue, new_name: CalcitValue, new_key: CalcitValue, new_value: CalcitValue): CalcitStructValue;
|