@calcit/procs 0.6.29 → 0.7.0-a1
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/lib/calcit-data.mjs +28 -25
- package/lib/calcit.procs.mjs +41 -41
- package/lib/custom-formatter.mjs +6 -4
- package/lib/js-cirru.mjs +17 -17
- package/lib/js-list.mjs +20 -20
- package/lib/js-primes.mjs +6 -6
- package/lib/js-record.mjs +12 -12
- package/lib/js-tuple.mjs +20 -19
- package/package.json +1 -1
- package/ts-src/calcit-data.mts +31 -28
- package/ts-src/calcit.procs.mts +48 -48
- package/ts-src/custom-formatter.mts +6 -4
- package/ts-src/js-cirru.mts +19 -19
- package/ts-src/js-list.mts +20 -20
- package/ts-src/js-primes.mts +7 -7
- package/ts-src/js-record.mts +19 -19
- package/ts-src/js-tuple.mts +21 -19
package/lib/calcit-data.mjs
CHANGED
|
@@ -10,12 +10,12 @@ import { CalcitTuple } from "./js-tuple.mjs";
|
|
|
10
10
|
import { CalcitCirruQuote, cirru_deep_equal } from "./js-cirru.mjs";
|
|
11
11
|
// we have to inject cache in a dirty way in some cases
|
|
12
12
|
const calcit_dirty_hash_key = "_calcit_cached_hash";
|
|
13
|
-
let
|
|
14
|
-
export class
|
|
13
|
+
let tagIdx = 0;
|
|
14
|
+
export class CalcitTag {
|
|
15
15
|
constructor(x) {
|
|
16
16
|
this.value = x;
|
|
17
|
-
this.idx =
|
|
18
|
-
|
|
17
|
+
this.idx = tagIdx;
|
|
18
|
+
tagIdx++;
|
|
19
19
|
this.cachedHash = null;
|
|
20
20
|
}
|
|
21
21
|
toString() {
|
|
@@ -96,7 +96,7 @@ export let getStringName = (x) => {
|
|
|
96
96
|
if (typeof x === "string") {
|
|
97
97
|
return x;
|
|
98
98
|
}
|
|
99
|
-
if (x instanceof
|
|
99
|
+
if (x instanceof CalcitTag) {
|
|
100
100
|
return x.value;
|
|
101
101
|
}
|
|
102
102
|
if (x instanceof CalcitSymbol) {
|
|
@@ -127,35 +127,35 @@ export function findInFields(xs, y) {
|
|
|
127
127
|
return upper;
|
|
128
128
|
return -1;
|
|
129
129
|
}
|
|
130
|
-
var
|
|
131
|
-
export let
|
|
132
|
-
let item =
|
|
130
|
+
var tagRegistery = {};
|
|
131
|
+
export let tag = (content) => {
|
|
132
|
+
let item = tagRegistery[content];
|
|
133
133
|
if (item != null) {
|
|
134
134
|
return item;
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
|
-
let v = new
|
|
138
|
-
|
|
137
|
+
let v = new CalcitTag(content);
|
|
138
|
+
tagRegistery[content] = v;
|
|
139
139
|
return v;
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
export let
|
|
143
|
-
if (x instanceof
|
|
142
|
+
export let castTag = (x) => {
|
|
143
|
+
if (x instanceof CalcitTag) {
|
|
144
144
|
return x;
|
|
145
145
|
}
|
|
146
146
|
if (typeof x === "string") {
|
|
147
|
-
return
|
|
147
|
+
return tag(x);
|
|
148
148
|
}
|
|
149
149
|
if (x instanceof CalcitSymbol) {
|
|
150
|
-
return
|
|
150
|
+
return tag(x.value);
|
|
151
151
|
}
|
|
152
|
-
throw new Error(`Cannot cast this to
|
|
152
|
+
throw new Error(`Cannot cast this to tag: ${x}`);
|
|
153
153
|
};
|
|
154
154
|
export var refsRegistry = new Map();
|
|
155
155
|
let defaultHash_nil = valueHash("nil:");
|
|
156
156
|
let defaultHash_number = valueHash("number:");
|
|
157
157
|
let defaultHash_string = valueHash("string:");
|
|
158
|
-
let
|
|
158
|
+
let defaultHash_tag = valueHash("tag:");
|
|
159
159
|
let defaultHash_true = valueHash("bool:true");
|
|
160
160
|
let defaultHash_false = valueHash("bool:false");
|
|
161
161
|
let defaultHash_symbol = valueHash("symbol:");
|
|
@@ -187,8 +187,8 @@ export let hashFunction = (x) => {
|
|
|
187
187
|
if (x[calcit_dirty_hash_key] != null) {
|
|
188
188
|
return x[calcit_dirty_hash_key];
|
|
189
189
|
}
|
|
190
|
-
if (x instanceof
|
|
191
|
-
let h = mergeValueHash(
|
|
190
|
+
if (x instanceof CalcitTag) {
|
|
191
|
+
let h = mergeValueHash(defaultHash_tag, x.idx);
|
|
192
192
|
x.cachedHash = h;
|
|
193
193
|
return h;
|
|
194
194
|
}
|
|
@@ -216,8 +216,11 @@ export let hashFunction = (x) => {
|
|
|
216
216
|
}
|
|
217
217
|
if (x instanceof CalcitTuple) {
|
|
218
218
|
let base = defaultHash_tuple;
|
|
219
|
-
base = mergeValueHash(base, hashFunction(x.
|
|
220
|
-
|
|
219
|
+
base = mergeValueHash(base, hashFunction(x.tag));
|
|
220
|
+
for (let idx = 0; idx < x.extra.length; idx++) {
|
|
221
|
+
let item = x.extra[idx];
|
|
222
|
+
base = mergeValueHash(base, hashFunction(item));
|
|
223
|
+
}
|
|
221
224
|
x.cachedHash = base;
|
|
222
225
|
return base;
|
|
223
226
|
}
|
|
@@ -342,7 +345,7 @@ export let toString = (x, escaped, disableJsDataWarning = false) => {
|
|
|
342
345
|
if (x instanceof CalcitSymbol) {
|
|
343
346
|
return x.toString();
|
|
344
347
|
}
|
|
345
|
-
if (x instanceof
|
|
348
|
+
if (x instanceof CalcitTag) {
|
|
346
349
|
return x.toString();
|
|
347
350
|
}
|
|
348
351
|
if (x instanceof CalcitList || x instanceof CalcitSliceList) {
|
|
@@ -387,7 +390,7 @@ export let to_js_data = (x, addColon = false) => {
|
|
|
387
390
|
if (typeof x === "function") {
|
|
388
391
|
return x;
|
|
389
392
|
}
|
|
390
|
-
if (x instanceof
|
|
393
|
+
if (x instanceof CalcitTag) {
|
|
391
394
|
if (addColon) {
|
|
392
395
|
return `:${x.value}`;
|
|
393
396
|
}
|
|
@@ -474,8 +477,8 @@ export let _$n__$e_ = (x, y) => {
|
|
|
474
477
|
// comparing functions by reference
|
|
475
478
|
return x === y;
|
|
476
479
|
}
|
|
477
|
-
if (x instanceof
|
|
478
|
-
if (y instanceof
|
|
480
|
+
if (x instanceof CalcitTag) {
|
|
481
|
+
if (y instanceof CalcitTag) {
|
|
479
482
|
return x === y;
|
|
480
483
|
}
|
|
481
484
|
return false;
|
|
@@ -536,7 +539,7 @@ export let _$n__$e_ = (x, y) => {
|
|
|
536
539
|
}
|
|
537
540
|
if (x instanceof CalcitTuple) {
|
|
538
541
|
if (y instanceof CalcitTuple) {
|
|
539
|
-
return _$n__$e_(x.
|
|
542
|
+
return _$n__$e_(x.tag, y.tag) && _$n__$e_(x.get(1), y.get(1));
|
|
540
543
|
}
|
|
541
544
|
return false;
|
|
542
545
|
}
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
// CALCIT VERSION
|
|
3
|
-
export const calcit_version = "0.
|
|
3
|
+
export const calcit_version = "0.7.0-a1";
|
|
4
4
|
import { parse } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
6
|
-
import { CalcitSymbol,
|
|
6
|
+
import { CalcitSymbol, CalcitTag, CalcitRef, CalcitRecur, tag, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
|
|
7
7
|
import { CalcitRecord } from "./js-record.mjs";
|
|
8
8
|
export * from "./calcit-data.mjs";
|
|
9
9
|
export * from "./js-record.mjs";
|
|
@@ -23,53 +23,53 @@ import { to_calcit_data, extract_cirru_edn, CalcitCirruQuote } from "./js-cirru.
|
|
|
23
23
|
let inNodeJs = typeof process !== "undefined" && ((_a = process === null || process === void 0 ? void 0 : process.release) === null || _a === void 0 ? void 0 : _a.name) === "node";
|
|
24
24
|
export let type_of = (x) => {
|
|
25
25
|
if (typeof x === "string") {
|
|
26
|
-
return
|
|
26
|
+
return tag("string");
|
|
27
27
|
}
|
|
28
28
|
if (typeof x === "number") {
|
|
29
|
-
return
|
|
29
|
+
return tag("number");
|
|
30
30
|
}
|
|
31
|
-
if (x instanceof
|
|
32
|
-
return
|
|
31
|
+
if (x instanceof CalcitTag) {
|
|
32
|
+
return tag("tag");
|
|
33
33
|
}
|
|
34
34
|
if (x instanceof CalcitList || x instanceof CalcitSliceList) {
|
|
35
|
-
return
|
|
35
|
+
return tag("list");
|
|
36
36
|
}
|
|
37
37
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
38
|
-
return
|
|
38
|
+
return tag("map");
|
|
39
39
|
}
|
|
40
40
|
if (x == null) {
|
|
41
|
-
return
|
|
41
|
+
return tag("nil");
|
|
42
42
|
}
|
|
43
43
|
if (x instanceof CalcitRef) {
|
|
44
|
-
return
|
|
44
|
+
return tag("ref");
|
|
45
45
|
}
|
|
46
46
|
if (x instanceof CalcitTuple) {
|
|
47
|
-
return
|
|
47
|
+
return tag("tuple");
|
|
48
48
|
}
|
|
49
49
|
if (x instanceof CalcitSymbol) {
|
|
50
|
-
return
|
|
50
|
+
return tag("symbol");
|
|
51
51
|
}
|
|
52
52
|
if (x instanceof CalcitSet) {
|
|
53
|
-
return
|
|
53
|
+
return tag("set");
|
|
54
54
|
}
|
|
55
55
|
if (x instanceof CalcitRecord) {
|
|
56
|
-
return
|
|
56
|
+
return tag("record");
|
|
57
57
|
}
|
|
58
58
|
if (x instanceof CalcitCirruQuote) {
|
|
59
|
-
return
|
|
59
|
+
return tag("cirru-quote");
|
|
60
60
|
}
|
|
61
61
|
if (x === true || x === false) {
|
|
62
|
-
return
|
|
62
|
+
return tag("bool");
|
|
63
63
|
}
|
|
64
64
|
if (typeof x === "function") {
|
|
65
65
|
if (x.isMacro) {
|
|
66
66
|
// this is faked...
|
|
67
|
-
return
|
|
67
|
+
return tag("macro");
|
|
68
68
|
}
|
|
69
|
-
return
|
|
69
|
+
return tag("fn");
|
|
70
70
|
}
|
|
71
71
|
if (typeof x === "object") {
|
|
72
|
-
return
|
|
72
|
+
return tag("js-object");
|
|
73
73
|
}
|
|
74
74
|
throw new Error(`Unknown data ${x}`);
|
|
75
75
|
};
|
|
@@ -354,8 +354,8 @@ export let add_watch = (a, k, f) => {
|
|
|
354
354
|
if (!(a instanceof CalcitRef)) {
|
|
355
355
|
throw new Error("Expected ref for add-watch!");
|
|
356
356
|
}
|
|
357
|
-
if (!(k instanceof
|
|
358
|
-
throw new Error("Expected watcher key in
|
|
357
|
+
if (!(k instanceof CalcitTag)) {
|
|
358
|
+
throw new Error("Expected watcher key in tag");
|
|
359
359
|
}
|
|
360
360
|
if (!(typeof f === "function")) {
|
|
361
361
|
throw new Error("Expected watcher function");
|
|
@@ -492,7 +492,7 @@ export let recur = (...xs) => {
|
|
|
492
492
|
return new CalcitRecur(xs);
|
|
493
493
|
};
|
|
494
494
|
export let _$n_get_calcit_backend = () => {
|
|
495
|
-
return
|
|
495
|
+
return tag("js");
|
|
496
496
|
};
|
|
497
497
|
export let not = (x) => {
|
|
498
498
|
return !x;
|
|
@@ -670,11 +670,11 @@ export let _$n_merge = (a, b) => {
|
|
|
670
670
|
for (let idx = 0; idx < pairs.length; idx++) {
|
|
671
671
|
let [k, v] = pairs[idx];
|
|
672
672
|
let field;
|
|
673
|
-
if (k instanceof
|
|
673
|
+
if (k instanceof CalcitTag) {
|
|
674
674
|
field = k;
|
|
675
675
|
}
|
|
676
676
|
else {
|
|
677
|
-
field =
|
|
677
|
+
field = tag(getStringName(k));
|
|
678
678
|
}
|
|
679
679
|
let position = a.findIndex(field);
|
|
680
680
|
if (position >= 0) {
|
|
@@ -892,18 +892,18 @@ export let get_env = (name, v0) => {
|
|
|
892
892
|
}
|
|
893
893
|
return v !== null && v !== void 0 ? v : v0;
|
|
894
894
|
};
|
|
895
|
-
export let
|
|
895
|
+
export let turn_tag = (x) => {
|
|
896
896
|
if (typeof x === "string") {
|
|
897
|
-
return
|
|
897
|
+
return tag(x);
|
|
898
898
|
}
|
|
899
|
-
if (x instanceof
|
|
899
|
+
if (x instanceof CalcitTag) {
|
|
900
900
|
return x;
|
|
901
901
|
}
|
|
902
902
|
if (x instanceof CalcitSymbol) {
|
|
903
|
-
return
|
|
903
|
+
return tag(x.value);
|
|
904
904
|
}
|
|
905
905
|
console.error(x);
|
|
906
|
-
throw new Error("Unexpected data for
|
|
906
|
+
throw new Error("Unexpected data for tag");
|
|
907
907
|
};
|
|
908
908
|
export let turn_symbol = (x) => {
|
|
909
909
|
if (typeof x === "string") {
|
|
@@ -912,7 +912,7 @@ export let turn_symbol = (x) => {
|
|
|
912
912
|
if (x instanceof CalcitSymbol) {
|
|
913
913
|
return x;
|
|
914
914
|
}
|
|
915
|
-
if (x instanceof
|
|
915
|
+
if (x instanceof CalcitTag) {
|
|
916
916
|
return new CalcitSymbol(x.value);
|
|
917
917
|
}
|
|
918
918
|
console.error(x);
|
|
@@ -949,7 +949,7 @@ export let turn_string = (x) => {
|
|
|
949
949
|
if (typeof x === "string") {
|
|
950
950
|
return x;
|
|
951
951
|
}
|
|
952
|
-
if (x instanceof
|
|
952
|
+
if (x instanceof CalcitTag) {
|
|
953
953
|
return x.value;
|
|
954
954
|
}
|
|
955
955
|
if (x instanceof CalcitSymbol) {
|
|
@@ -971,10 +971,10 @@ export let starts_with_$q_ = (xs, y) => {
|
|
|
971
971
|
if (typeof xs === "string" && typeof y === "string") {
|
|
972
972
|
return xs.startsWith(y);
|
|
973
973
|
}
|
|
974
|
-
if (xs instanceof
|
|
974
|
+
if (xs instanceof CalcitTag && y instanceof CalcitTag) {
|
|
975
975
|
return xs.value.startsWith(y.value);
|
|
976
976
|
}
|
|
977
|
-
throw new Error("expected strings or
|
|
977
|
+
throw new Error("expected strings or tags");
|
|
978
978
|
};
|
|
979
979
|
export let ends_with_$q_ = (xs, y) => {
|
|
980
980
|
return xs.endsWith(y);
|
|
@@ -1025,8 +1025,8 @@ export let bool_$q_ = (x) => {
|
|
|
1025
1025
|
export let nil_$q_ = (x) => {
|
|
1026
1026
|
return x == null;
|
|
1027
1027
|
};
|
|
1028
|
-
export let
|
|
1029
|
-
return x instanceof
|
|
1028
|
+
export let tag_$q_ = (x) => {
|
|
1029
|
+
return x instanceof CalcitTag;
|
|
1030
1030
|
};
|
|
1031
1031
|
export let map_$q_ = (x) => {
|
|
1032
1032
|
return x instanceof CalcitSliceMap || x instanceof CalcitMap;
|
|
@@ -1152,7 +1152,7 @@ export let _$n_js_object = (...xs) => {
|
|
|
1152
1152
|
if (typeof k === "string") {
|
|
1153
1153
|
ret[k] = v;
|
|
1154
1154
|
}
|
|
1155
|
-
else if (k instanceof
|
|
1155
|
+
else if (k instanceof CalcitTag) {
|
|
1156
1156
|
ret[turn_string(k)] = v;
|
|
1157
1157
|
}
|
|
1158
1158
|
else {
|
|
@@ -1161,8 +1161,8 @@ export let _$n_js_object = (...xs) => {
|
|
|
1161
1161
|
}
|
|
1162
1162
|
return ret;
|
|
1163
1163
|
};
|
|
1164
|
-
export let _$o__$o_ = (
|
|
1165
|
-
return new CalcitTuple(
|
|
1164
|
+
export let _$o__$o_ = (tag, ...extra) => {
|
|
1165
|
+
return new CalcitTuple(tag, extra);
|
|
1166
1166
|
};
|
|
1167
1167
|
// mutable place for core to register
|
|
1168
1168
|
let calcit_builtin_classes = {
|
|
@@ -1192,8 +1192,8 @@ export function invoke_method(p, obj, ...args) {
|
|
|
1192
1192
|
klass = calcit_builtin_classes.nil;
|
|
1193
1193
|
}
|
|
1194
1194
|
else if (obj instanceof CalcitTuple) {
|
|
1195
|
-
if (obj.
|
|
1196
|
-
klass = obj.
|
|
1195
|
+
if (obj.tag instanceof CalcitRecord) {
|
|
1196
|
+
klass = obj.tag;
|
|
1197
1197
|
}
|
|
1198
1198
|
else {
|
|
1199
1199
|
throw new Error("Method invoking expected a record as class");
|
|
@@ -1322,7 +1322,7 @@ export let _$n_str_$o_pad_right = (s, size, pattern) => {
|
|
|
1322
1322
|
return s.padEnd(size, pattern);
|
|
1323
1323
|
};
|
|
1324
1324
|
export let _$n_get_os = () => {
|
|
1325
|
-
return
|
|
1325
|
+
return tag("js-engine");
|
|
1326
1326
|
};
|
|
1327
1327
|
export let _$n_buffer = (...xs) => {
|
|
1328
1328
|
let buf = new Uint8Array(xs.length);
|
package/lib/custom-formatter.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CalcitRef, CalcitSymbol,
|
|
1
|
+
import { CalcitRef, CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
|
|
2
2
|
import { CalcitRecord } from "./js-record.mjs";
|
|
3
3
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
4
4
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
@@ -21,7 +21,7 @@ export let load_console_formatter_$x_ = () => {
|
|
|
21
21
|
window["devtoolsFormatters"] = [
|
|
22
22
|
{
|
|
23
23
|
header: (obj, config) => {
|
|
24
|
-
if (obj instanceof
|
|
24
|
+
if (obj instanceof CalcitTag) {
|
|
25
25
|
return ["div", { style: "color: hsl(240, 80%, 60%)" }, obj.toString()];
|
|
26
26
|
}
|
|
27
27
|
if (obj instanceof CalcitSymbol) {
|
|
@@ -56,8 +56,10 @@ export let load_console_formatter_$x_ = () => {
|
|
|
56
56
|
if (obj instanceof CalcitTuple) {
|
|
57
57
|
let ret = ["div", {}];
|
|
58
58
|
ret.push(["div", { style: "display: inline-block; color: hsl(300, 100%, 40%); " }, "::"]);
|
|
59
|
-
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.
|
|
60
|
-
|
|
59
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.tag)]);
|
|
60
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
61
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.extra[idx])]);
|
|
62
|
+
}
|
|
61
63
|
return ret;
|
|
62
64
|
}
|
|
63
65
|
if (obj instanceof CalcitRef) {
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
|
4
4
|
import { CalcitRecord } from "./js-record.mjs";
|
|
5
5
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
6
6
|
import { CalcitSet } from "./js-set.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { CalcitTag, CalcitSymbol, CalcitRecur, CalcitRef, tag } from "./calcit-data.mjs";
|
|
8
8
|
import { CalcitTuple } from "./js-tuple.mjs";
|
|
9
9
|
export class CalcitCirruQuote {
|
|
10
10
|
constructor(value) {
|
|
@@ -51,7 +51,7 @@ export let to_cirru_edn = (x) => {
|
|
|
51
51
|
if (typeof x === "boolean") {
|
|
52
52
|
return x.toString();
|
|
53
53
|
}
|
|
54
|
-
if (x instanceof
|
|
54
|
+
if (x instanceof CalcitTag) {
|
|
55
55
|
return x.toString();
|
|
56
56
|
}
|
|
57
57
|
if (x instanceof CalcitSymbol) {
|
|
@@ -123,27 +123,27 @@ export let to_cirru_edn = (x) => {
|
|
|
123
123
|
return buffer;
|
|
124
124
|
}
|
|
125
125
|
if (x instanceof CalcitTuple) {
|
|
126
|
-
if (x.
|
|
126
|
+
if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
|
|
127
127
|
// turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
|
|
128
|
-
return ["quote", toWriterNode(x.
|
|
128
|
+
return ["quote", toWriterNode(x.get(1))];
|
|
129
129
|
}
|
|
130
|
-
else if (x.
|
|
131
|
-
return ["::", x.
|
|
130
|
+
else if (x.tag instanceof CalcitRecord) {
|
|
131
|
+
return ["::", x.tag.name.toString(), to_cirru_edn(x.get(1))];
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
throw new Error(`Unsupported tag for EDN: ${x.
|
|
134
|
+
throw new Error(`Unsupported tag for EDN: ${x.tag}`);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
console.error(x);
|
|
138
138
|
throw new Error("Unexpected data to to-cirru-edn");
|
|
139
139
|
};
|
|
140
140
|
/** makes sure we got string */
|
|
141
|
-
let
|
|
141
|
+
let extractFieldTag = (x) => {
|
|
142
142
|
if (x[0] === ":") {
|
|
143
|
-
return
|
|
143
|
+
return tag(x.slice(1));
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
|
-
return
|
|
146
|
+
return tag(x);
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
export let extract_cirru_edn = (x) => {
|
|
@@ -164,7 +164,7 @@ export let extract_cirru_edn = (x) => {
|
|
|
164
164
|
return x.slice(1);
|
|
165
165
|
}
|
|
166
166
|
if (x[0] === ":") {
|
|
167
|
-
return
|
|
167
|
+
return tag(x.slice(1));
|
|
168
168
|
}
|
|
169
169
|
if (x[0] === "'") {
|
|
170
170
|
return new CalcitSymbol(x.slice(1));
|
|
@@ -208,7 +208,7 @@ export let extract_cirru_edn = (x) => {
|
|
|
208
208
|
}
|
|
209
209
|
if (pair instanceof Array && pair.length === 2) {
|
|
210
210
|
if (typeof pair[0] === "string") {
|
|
211
|
-
entries.push([
|
|
211
|
+
entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1])]);
|
|
212
212
|
}
|
|
213
213
|
else {
|
|
214
214
|
throw new Error("Expected string as field");
|
|
@@ -227,7 +227,7 @@ export let extract_cirru_edn = (x) => {
|
|
|
227
227
|
fields.push(entries[idx][0]);
|
|
228
228
|
values.push(entries[idx][1]);
|
|
229
229
|
}
|
|
230
|
-
return new CalcitRecord(
|
|
230
|
+
return new CalcitRecord(extractFieldTag(name), fields, values);
|
|
231
231
|
}
|
|
232
232
|
if (x[0] === "[]") {
|
|
233
233
|
return new CalcitSliceList(x.slice(1).map(extract_cirru_edn));
|
|
@@ -248,7 +248,7 @@ export let extract_cirru_edn = (x) => {
|
|
|
248
248
|
if (x.length < 3) {
|
|
249
249
|
throw new Error("tuple expects at least 2 values");
|
|
250
250
|
}
|
|
251
|
-
return new CalcitTuple(extract_cirru_edn(x[1]),
|
|
251
|
+
return new CalcitTuple(extract_cirru_edn(x[1]), x.slice(2).map(extract_cirru_edn));
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
console.error(x);
|
|
@@ -270,7 +270,7 @@ export let format_cirru_edn = (data, useInline = true) => {
|
|
|
270
270
|
if (data instanceof CalcitSymbol) {
|
|
271
271
|
return "\ndo " + to_cirru_edn(data) + "\n";
|
|
272
272
|
}
|
|
273
|
-
if (data instanceof
|
|
273
|
+
if (data instanceof CalcitTag) {
|
|
274
274
|
return "\ndo " + to_cirru_edn(data) + "\n";
|
|
275
275
|
}
|
|
276
276
|
return writeCirruCode([to_cirru_edn(data)], { useInline: useInline });
|
|
@@ -282,7 +282,7 @@ export let to_calcit_data = (x, noKeyword = false) => {
|
|
|
282
282
|
return x;
|
|
283
283
|
if (typeof x === "string") {
|
|
284
284
|
if (!noKeyword && x[0] === ":" && x.slice(1).match(/^[\w\d_\?\!\-]+$/)) {
|
|
285
|
-
return
|
|
285
|
+
return tag(x.slice(1));
|
|
286
286
|
}
|
|
287
287
|
return x;
|
|
288
288
|
}
|
|
@@ -316,7 +316,7 @@ export let to_calcit_data = (x, noKeyword = false) => {
|
|
|
316
316
|
return x;
|
|
317
317
|
if (x instanceof CalcitRef)
|
|
318
318
|
return x;
|
|
319
|
-
if (x instanceof
|
|
319
|
+
if (x instanceof CalcitTag)
|
|
320
320
|
return x;
|
|
321
321
|
if (x instanceof CalcitSymbol)
|
|
322
322
|
return x;
|
package/lib/js-list.mjs
CHANGED
|
@@ -305,12 +305,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
305
305
|
let item = xs.get(idx);
|
|
306
306
|
let pair = f(state, item);
|
|
307
307
|
if (pair instanceof CalcitTuple) {
|
|
308
|
-
if (typeof pair.
|
|
309
|
-
if (pair.
|
|
310
|
-
return pair.
|
|
308
|
+
if (typeof pair.tag === "boolean") {
|
|
309
|
+
if (pair.tag) {
|
|
310
|
+
return pair.get(1);
|
|
311
311
|
}
|
|
312
312
|
else {
|
|
313
|
-
state = pair.
|
|
313
|
+
state = pair.get(1);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -327,12 +327,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
327
327
|
let item = values[idx];
|
|
328
328
|
let pair = f(state, item);
|
|
329
329
|
if (pair instanceof CalcitTuple) {
|
|
330
|
-
if (typeof pair.
|
|
331
|
-
if (pair.
|
|
332
|
-
return pair.
|
|
330
|
+
if (typeof pair.tag === "boolean") {
|
|
331
|
+
if (pair.tag) {
|
|
332
|
+
return pair.get(1);
|
|
333
333
|
}
|
|
334
334
|
else {
|
|
335
|
-
state = pair.
|
|
335
|
+
state = pair.get(1);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -350,12 +350,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
350
350
|
let pos = i << 1;
|
|
351
351
|
let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
|
|
352
352
|
if (pair instanceof CalcitTuple) {
|
|
353
|
-
if (typeof pair.
|
|
354
|
-
if (pair.
|
|
355
|
-
return pair.
|
|
353
|
+
if (typeof pair.tag === "boolean") {
|
|
354
|
+
if (pair.tag) {
|
|
355
|
+
return pair.get(1);
|
|
356
356
|
}
|
|
357
357
|
else {
|
|
358
|
-
state = pair.
|
|
358
|
+
state = pair.get(1);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
}
|
|
@@ -372,12 +372,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
372
372
|
let item = pairs[idx];
|
|
373
373
|
let pair = f(state, new CalcitSliceList(item));
|
|
374
374
|
if (pair instanceof CalcitTuple) {
|
|
375
|
-
if (typeof pair.
|
|
376
|
-
if (pair.
|
|
377
|
-
return pair.
|
|
375
|
+
if (typeof pair.tag === "boolean") {
|
|
376
|
+
if (pair.tag) {
|
|
377
|
+
return pair.get(1);
|
|
378
378
|
}
|
|
379
379
|
else {
|
|
380
|
-
state = pair.
|
|
380
|
+
state = pair.get(1);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
}
|
|
@@ -403,12 +403,12 @@ export let foldr_shortcut = function (xs, acc, v0, f) {
|
|
|
403
403
|
let item = xs.get(idx);
|
|
404
404
|
let pair = f(state, item);
|
|
405
405
|
if (pair instanceof CalcitTuple) {
|
|
406
|
-
if (typeof pair.
|
|
407
|
-
if (pair.
|
|
408
|
-
return pair.
|
|
406
|
+
if (typeof pair.tag === "boolean") {
|
|
407
|
+
if (pair.tag) {
|
|
408
|
+
return pair.get(1);
|
|
409
409
|
}
|
|
410
410
|
else {
|
|
411
|
-
state = pair.
|
|
411
|
+
state = pair.get(1);
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
}
|
package/lib/js-primes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CalcitTag, CalcitSymbol, CalcitRef, CalcitRecur } from "./calcit-data.mjs";
|
|
2
2
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
3
3
|
import { CalcitRecord } from "./js-record.mjs";
|
|
4
4
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -14,7 +14,7 @@ export let is_literal = (x) => {
|
|
|
14
14
|
return true;
|
|
15
15
|
if (typeof x == "number")
|
|
16
16
|
return true;
|
|
17
|
-
if (x instanceof
|
|
17
|
+
if (x instanceof CalcitTag)
|
|
18
18
|
return true;
|
|
19
19
|
if (x instanceof CalcitSymbol)
|
|
20
20
|
return true;
|
|
@@ -26,7 +26,7 @@ var PseudoTypeIndex;
|
|
|
26
26
|
PseudoTypeIndex[PseudoTypeIndex["bool"] = 1] = "bool";
|
|
27
27
|
PseudoTypeIndex[PseudoTypeIndex["number"] = 2] = "number";
|
|
28
28
|
PseudoTypeIndex[PseudoTypeIndex["symbol"] = 3] = "symbol";
|
|
29
|
-
PseudoTypeIndex[PseudoTypeIndex["
|
|
29
|
+
PseudoTypeIndex[PseudoTypeIndex["tag"] = 4] = "tag";
|
|
30
30
|
PseudoTypeIndex[PseudoTypeIndex["string"] = 5] = "string";
|
|
31
31
|
PseudoTypeIndex[PseudoTypeIndex["ref"] = 6] = "ref";
|
|
32
32
|
PseudoTypeIndex[PseudoTypeIndex["tuple"] = 7] = "tuple";
|
|
@@ -49,8 +49,8 @@ let typeAsInt = (x) => {
|
|
|
49
49
|
return PseudoTypeIndex.number;
|
|
50
50
|
if (x instanceof CalcitSymbol)
|
|
51
51
|
return PseudoTypeIndex.symbol;
|
|
52
|
-
if (x instanceof
|
|
53
|
-
return PseudoTypeIndex.
|
|
52
|
+
if (x instanceof CalcitTag)
|
|
53
|
+
return PseudoTypeIndex.tag;
|
|
54
54
|
if (t === "string")
|
|
55
55
|
return PseudoTypeIndex.string;
|
|
56
56
|
if (x instanceof CalcitRef)
|
|
@@ -98,7 +98,7 @@ export let _$n_compare = (a, b) => {
|
|
|
98
98
|
return rawCompare(a, b);
|
|
99
99
|
case PseudoTypeIndex.number:
|
|
100
100
|
return rawCompare(a, b);
|
|
101
|
-
case PseudoTypeIndex.
|
|
101
|
+
case PseudoTypeIndex.tag:
|
|
102
102
|
return rawCompare(a.value, b.value);
|
|
103
103
|
case PseudoTypeIndex.symbol:
|
|
104
104
|
return rawCompare(a, b);
|