@calcit/procs 0.6.10 → 0.6.11
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/.vscode/launch.json +101 -0
- package/.vscode/settings.json +3 -0
- package/lib/calcit-data.mjs +10 -4
- package/lib/calcit.procs.mjs +73 -61
- package/lib/custom-formatter.mjs +2 -1
- package/lib/js-cirru.mjs +9 -6
- package/lib/js-list.mjs +6 -2
- package/lib/js-map.mjs +6 -2
- package/lib/js-record.mjs +13 -9
- package/package.json +2 -2
- package/ts-src/calcit-data.mts +10 -4
- package/ts-src/calcit.procs.mts +63 -50
- package/ts-src/custom-formatter.mts +2 -1
- package/ts-src/js-cirru.mts +9 -6
- package/ts-src/js-list.mts +6 -2
- package/ts-src/js-map.mts +6 -2
- package/ts-src/js-record.mts +13 -9
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "lldb",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Debug unit tests in library 'calcit'",
|
|
11
|
+
"cargo": {
|
|
12
|
+
"args": [
|
|
13
|
+
"test",
|
|
14
|
+
"--no-run",
|
|
15
|
+
"--lib",
|
|
16
|
+
"--package=calcit"
|
|
17
|
+
],
|
|
18
|
+
"filter": {
|
|
19
|
+
"name": "calcit",
|
|
20
|
+
"kind": "lib"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"args": [],
|
|
24
|
+
"cwd": "${workspaceFolder}"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "lldb",
|
|
28
|
+
"request": "launch",
|
|
29
|
+
"name": "Debug executable 'cr'",
|
|
30
|
+
"cargo": {
|
|
31
|
+
"args": [
|
|
32
|
+
"build",
|
|
33
|
+
"--bin=cr",
|
|
34
|
+
"--package=calcit"
|
|
35
|
+
],
|
|
36
|
+
"filter": {
|
|
37
|
+
"name": "cr",
|
|
38
|
+
"kind": "bin"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"args": [],
|
|
42
|
+
"cwd": "${workspaceFolder}"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"type": "lldb",
|
|
46
|
+
"request": "launch",
|
|
47
|
+
"name": "Debug unit tests in executable 'cr'",
|
|
48
|
+
"cargo": {
|
|
49
|
+
"args": [
|
|
50
|
+
"test",
|
|
51
|
+
"--no-run",
|
|
52
|
+
"--bin=cr",
|
|
53
|
+
"--package=calcit"
|
|
54
|
+
],
|
|
55
|
+
"filter": {
|
|
56
|
+
"name": "cr",
|
|
57
|
+
"kind": "bin"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"args": [],
|
|
61
|
+
"cwd": "${workspaceFolder}"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "lldb",
|
|
65
|
+
"request": "launch",
|
|
66
|
+
"name": "Debug executable 'bundle_calcit'",
|
|
67
|
+
"cargo": {
|
|
68
|
+
"args": [
|
|
69
|
+
"build",
|
|
70
|
+
"--bin=bundle_calcit",
|
|
71
|
+
"--package=calcit"
|
|
72
|
+
],
|
|
73
|
+
"filter": {
|
|
74
|
+
"name": "bundle_calcit",
|
|
75
|
+
"kind": "bin"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"args": [],
|
|
79
|
+
"cwd": "${workspaceFolder}"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"type": "lldb",
|
|
83
|
+
"request": "launch",
|
|
84
|
+
"name": "Debug unit tests in executable 'bundle_calcit'",
|
|
85
|
+
"cargo": {
|
|
86
|
+
"args": [
|
|
87
|
+
"test",
|
|
88
|
+
"--no-run",
|
|
89
|
+
"--bin=bundle_calcit",
|
|
90
|
+
"--package=calcit"
|
|
91
|
+
],
|
|
92
|
+
"filter": {
|
|
93
|
+
"name": "bundle_calcit",
|
|
94
|
+
"kind": "bin"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"args": [],
|
|
98
|
+
"cwd": "${workspaceFolder}"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
package/lib/calcit-data.mjs
CHANGED
|
@@ -255,7 +255,8 @@ export let hashFunction = (x) => {
|
|
|
255
255
|
let base = defaultHash_map;
|
|
256
256
|
let pairs = x.pairs();
|
|
257
257
|
pairs.sort((a, b) => _$n_compare(a[0], b[0]));
|
|
258
|
-
for (let
|
|
258
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
259
|
+
let [k, v] = pairs[idx];
|
|
259
260
|
base = mergeValueHash(base, hashFunction(k));
|
|
260
261
|
base = mergeValueHash(base, hashFunction(v));
|
|
261
262
|
}
|
|
@@ -266,7 +267,8 @@ export let hashFunction = (x) => {
|
|
|
266
267
|
let base = defaultHash_map;
|
|
267
268
|
let pairs = x.pairs();
|
|
268
269
|
pairs.sort((a, b) => _$n_compare(a[0], b[0]));
|
|
269
|
-
for (let
|
|
270
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
271
|
+
let [k, v] = pairs[idx];
|
|
270
272
|
base = mergeValueHash(base, hashFunction(k));
|
|
271
273
|
base = mergeValueHash(base, hashFunction(v));
|
|
272
274
|
}
|
|
@@ -407,7 +409,9 @@ export let to_js_data = (x, addColon = false) => {
|
|
|
407
409
|
}
|
|
408
410
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
409
411
|
let result = {};
|
|
410
|
-
|
|
412
|
+
let pairs = x.pairs();
|
|
413
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
414
|
+
let [k, v] = pairs[idx];
|
|
411
415
|
var key = to_js_data(k, addColon);
|
|
412
416
|
result[key] = to_js_data(v, addColon);
|
|
413
417
|
}
|
|
@@ -511,7 +515,9 @@ export let _$n__$e_ = (x, y) => {
|
|
|
511
515
|
if (x.len() !== y.len()) {
|
|
512
516
|
return false;
|
|
513
517
|
}
|
|
514
|
-
|
|
518
|
+
let pairs = x.pairs();
|
|
519
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
520
|
+
let [k, v] = pairs[idx];
|
|
515
521
|
if (!y.contains(k)) {
|
|
516
522
|
return false;
|
|
517
523
|
}
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
// CALCIT VERSION
|
|
3
|
-
export const calcit_version = "0.6.
|
|
3
|
+
export const calcit_version = "0.6.11";
|
|
4
4
|
import { parse } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
6
6
|
import "./js-primes.mjs";
|
|
@@ -201,7 +201,9 @@ export let _$n_list_$o_includes_$q_ = (xs, x) => {
|
|
|
201
201
|
};
|
|
202
202
|
export let _$n_map_$o_includes_$q_ = (xs, x) => {
|
|
203
203
|
if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
|
|
204
|
-
|
|
204
|
+
let pairs = xs.pairs();
|
|
205
|
+
for (let idx = 0; idx < pairs.length; idx = idx + 1) {
|
|
206
|
+
let v = pairs[idx][1];
|
|
205
207
|
if (_$n__$e_(v, x)) {
|
|
206
208
|
return true;
|
|
207
209
|
}
|
|
@@ -566,7 +568,8 @@ export let _$n_list_$o_slice = (xs, from, to) => {
|
|
|
566
568
|
};
|
|
567
569
|
export let _$n_list_$o_concat = (...lists) => {
|
|
568
570
|
let result = new CalcitSliceList([]);
|
|
569
|
-
for (let
|
|
571
|
+
for (let idx = 0; idx < lists.length; idx++) {
|
|
572
|
+
let item = lists[idx];
|
|
570
573
|
if (item == null) {
|
|
571
574
|
continue;
|
|
572
575
|
}
|
|
@@ -653,10 +656,12 @@ export let _$n_merge = (a, b) => {
|
|
|
653
656
|
if (a instanceof CalcitRecord) {
|
|
654
657
|
if (b instanceof CalcitMap || b instanceof CalcitSliceMap) {
|
|
655
658
|
let values = [];
|
|
656
|
-
for (let
|
|
657
|
-
values.push(
|
|
659
|
+
for (let idx = 0; idx < a.values.length; idx++) {
|
|
660
|
+
values.push(a.values[idx]);
|
|
658
661
|
}
|
|
659
|
-
|
|
662
|
+
let pairs = b.pairs();
|
|
663
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
664
|
+
let [k, v] = pairs[idx];
|
|
660
665
|
let field;
|
|
661
666
|
if (k instanceof CalcitKeyword) {
|
|
662
667
|
field = k;
|
|
@@ -664,9 +669,9 @@ export let _$n_merge = (a, b) => {
|
|
|
664
669
|
else {
|
|
665
670
|
field = kwd(getStringName(k));
|
|
666
671
|
}
|
|
667
|
-
let
|
|
668
|
-
if (
|
|
669
|
-
values[
|
|
672
|
+
let position = a.findIndex(field);
|
|
673
|
+
if (position >= 0) {
|
|
674
|
+
values[position] = v;
|
|
670
675
|
}
|
|
671
676
|
else {
|
|
672
677
|
throw new Error(`Cannot find field ${field} among (${a.fields.join(", ")})`);
|
|
@@ -695,8 +700,9 @@ export let _$n_merge_non_nil = (a, b) => {
|
|
|
695
700
|
export let to_pairs = (xs) => {
|
|
696
701
|
if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
|
|
697
702
|
let result = [];
|
|
698
|
-
|
|
699
|
-
|
|
703
|
+
let pairs = xs.pairs();
|
|
704
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
705
|
+
result.push(new CalcitSliceList(pairs[idx]));
|
|
700
706
|
}
|
|
701
707
|
return new CalcitSet(result);
|
|
702
708
|
}
|
|
@@ -1166,65 +1172,71 @@ let calcit_builtin_classes = {
|
|
|
1166
1172
|
export let register_calcit_builtin_classes = (options) => {
|
|
1167
1173
|
Object.assign(calcit_builtin_classes, options);
|
|
1168
1174
|
};
|
|
1169
|
-
|
|
1175
|
+
/** method used as closure */
|
|
1176
|
+
export function invoke_method_closure(p) {
|
|
1170
1177
|
return (obj, ...args) => {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
}
|
|
1184
|
-
else if (typeof obj === "number") {
|
|
1185
|
-
klass = calcit_builtin_classes.number;
|
|
1186
|
-
}
|
|
1187
|
-
else if (typeof obj === "string") {
|
|
1188
|
-
klass = calcit_builtin_classes.string;
|
|
1189
|
-
}
|
|
1190
|
-
else if (typeof obj === "function") {
|
|
1191
|
-
klass = calcit_builtin_classes.fn;
|
|
1192
|
-
}
|
|
1193
|
-
else if (obj instanceof CalcitSet) {
|
|
1194
|
-
klass = calcit_builtin_classes.set;
|
|
1195
|
-
}
|
|
1196
|
-
else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
1197
|
-
klass = calcit_builtin_classes.list;
|
|
1198
|
-
}
|
|
1199
|
-
else if (obj instanceof CalcitRecord) {
|
|
1200
|
-
klass = calcit_builtin_classes.record;
|
|
1201
|
-
}
|
|
1202
|
-
else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
1203
|
-
klass = calcit_builtin_classes.map;
|
|
1178
|
+
return invoke_method(p, obj, ...args);
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
export function invoke_method(p, obj, ...args) {
|
|
1182
|
+
let klass;
|
|
1183
|
+
let value = obj;
|
|
1184
|
+
if (obj == null) {
|
|
1185
|
+
klass = calcit_builtin_classes.nil;
|
|
1186
|
+
}
|
|
1187
|
+
else if (obj instanceof CalcitTuple) {
|
|
1188
|
+
if (obj.fst instanceof CalcitRecord) {
|
|
1189
|
+
klass = obj.fst;
|
|
1204
1190
|
}
|
|
1205
1191
|
else {
|
|
1206
|
-
|
|
1207
|
-
throw new Error(`Missing method \`${p}\` on object`);
|
|
1208
|
-
}
|
|
1209
|
-
return obj[p](...args); // trying to call native JavaScript method
|
|
1210
|
-
}
|
|
1211
|
-
if (klass == null)
|
|
1212
|
-
throw new Error("Cannot find class for this object for invoking");
|
|
1213
|
-
if (!klass.contains(p))
|
|
1214
|
-
throw new Error(`Missing method '${p}' for object: ${obj}`);
|
|
1215
|
-
let method = klass.get(p);
|
|
1216
|
-
if (typeof method === "function") {
|
|
1217
|
-
return method(value, ...args);
|
|
1192
|
+
throw new Error("Method invoking expected a record as class");
|
|
1218
1193
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1194
|
+
}
|
|
1195
|
+
else if (typeof obj === "number") {
|
|
1196
|
+
klass = calcit_builtin_classes.number;
|
|
1197
|
+
}
|
|
1198
|
+
else if (typeof obj === "string") {
|
|
1199
|
+
klass = calcit_builtin_classes.string;
|
|
1200
|
+
}
|
|
1201
|
+
else if (typeof obj === "function") {
|
|
1202
|
+
klass = calcit_builtin_classes.fn;
|
|
1203
|
+
}
|
|
1204
|
+
else if (obj instanceof CalcitSet) {
|
|
1205
|
+
klass = calcit_builtin_classes.set;
|
|
1206
|
+
}
|
|
1207
|
+
else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
1208
|
+
klass = calcit_builtin_classes.list;
|
|
1209
|
+
}
|
|
1210
|
+
else if (obj instanceof CalcitRecord) {
|
|
1211
|
+
klass = calcit_builtin_classes.record;
|
|
1212
|
+
}
|
|
1213
|
+
else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
1214
|
+
klass = calcit_builtin_classes.map;
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
if (obj[p] == null) {
|
|
1218
|
+
throw new Error(`Missing method \`${p}\` on object`);
|
|
1221
1219
|
}
|
|
1222
|
-
|
|
1220
|
+
return obj[p](...args); // trying to call native JavaScript method
|
|
1221
|
+
}
|
|
1222
|
+
if (klass == null)
|
|
1223
|
+
throw new Error("Cannot find class for this object for invoking");
|
|
1224
|
+
if (!klass.contains(p))
|
|
1225
|
+
throw new Error(`Missing method '${p}' for object: ${obj}`);
|
|
1226
|
+
let method = klass.get(p);
|
|
1227
|
+
if (typeof method === "function") {
|
|
1228
|
+
return method(value, ...args);
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
throw new Error("Method for invoking is not a function");
|
|
1232
|
+
}
|
|
1223
1233
|
}
|
|
1224
1234
|
export let _$n_map_$o_to_list = (m) => {
|
|
1225
1235
|
if (m instanceof CalcitMap || m instanceof CalcitSliceMap) {
|
|
1226
1236
|
let ys = [];
|
|
1227
|
-
|
|
1237
|
+
let pairs = m.pairs();
|
|
1238
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
1239
|
+
let pair = pairs[idx];
|
|
1228
1240
|
ys.push(new CalcitSliceList(pair));
|
|
1229
1241
|
}
|
|
1230
1242
|
return new CalcitSliceList(ys);
|
package/lib/custom-formatter.mjs
CHANGED
|
@@ -118,7 +118,8 @@ export let load_console_formatter_$x_ = () => {
|
|
|
118
118
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
119
119
|
let ret = ["div", { style: "color: hsl(280, 80%, 60%)" }];
|
|
120
120
|
let pairs = obj.pairs();
|
|
121
|
-
for (let
|
|
121
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
122
|
+
let [k, v] = pairs[idx];
|
|
122
123
|
ret.push([
|
|
123
124
|
"div",
|
|
124
125
|
{ style: "margin-left: 8px; display: flex;" },
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -30,7 +30,8 @@ export let format_cirru = (data, useInline) => {
|
|
|
30
30
|
if (!Array.isArray(chunk)) {
|
|
31
31
|
throw new Error("Expected data of list");
|
|
32
32
|
}
|
|
33
|
-
for (let
|
|
33
|
+
for (let idx = 0; idx < chunk.length; idx++) {
|
|
34
|
+
let item = chunk[idx];
|
|
34
35
|
if (!Array.isArray(item)) {
|
|
35
36
|
throw new Error("Expected data in a list of lists");
|
|
36
37
|
}
|
|
@@ -66,11 +67,12 @@ export let to_cirru_edn = (x) => {
|
|
|
66
67
|
}
|
|
67
68
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
68
69
|
let buffer = ["{}"];
|
|
69
|
-
let
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let pairs_buffer = [];
|
|
71
|
+
let pairs = x.pairs();
|
|
72
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
73
|
+
pairs_buffer.push(pairs[idx]);
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
pairs_buffer.sort((a, b) => {
|
|
74
76
|
let a0_literal = is_literal(a[0]);
|
|
75
77
|
let a1_literal = is_literal(a[1]);
|
|
76
78
|
let b0_literal = is_literal(b[0]);
|
|
@@ -96,7 +98,8 @@ export let to_cirru_edn = (x) => {
|
|
|
96
98
|
return _$n_compare(a[0], b[0]);
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
|
-
for (let
|
|
101
|
+
for (let idx = 0; idx < pairs_buffer.length; idx++) {
|
|
102
|
+
let [k, v] = pairs_buffer[idx];
|
|
100
103
|
buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
|
|
101
104
|
}
|
|
102
105
|
return buffer;
|
package/lib/js-list.mjs
CHANGED
|
@@ -323,7 +323,9 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
323
323
|
}
|
|
324
324
|
if (xs instanceof CalcitSet) {
|
|
325
325
|
let state = acc;
|
|
326
|
-
|
|
326
|
+
let values = xs.values();
|
|
327
|
+
for (let idx = 0; idx < values.length; idx++) {
|
|
328
|
+
let item = values[idx];
|
|
327
329
|
let pair = f(state, item);
|
|
328
330
|
if (pair instanceof CalcitTuple) {
|
|
329
331
|
if (typeof pair.fst === "boolean") {
|
|
@@ -366,7 +368,9 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
366
368
|
}
|
|
367
369
|
if (xs instanceof CalcitMap) {
|
|
368
370
|
let state = acc;
|
|
369
|
-
|
|
371
|
+
let pairs = xs.pairs();
|
|
372
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
373
|
+
let item = pairs[idx];
|
|
370
374
|
let pair = f(state, new CalcitSliceList(item));
|
|
371
375
|
if (pair instanceof CalcitTuple) {
|
|
372
376
|
if (typeof pair.fst === "boolean") {
|
package/lib/js-map.mjs
CHANGED
|
@@ -48,7 +48,9 @@ export class CalcitMap {
|
|
|
48
48
|
}
|
|
49
49
|
toString(shorter = false, disableJsDataWarning = false) {
|
|
50
50
|
let itemsCode = "";
|
|
51
|
-
|
|
51
|
+
let pairs = this.pairs();
|
|
52
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
53
|
+
let [k, v] = pairs[idx];
|
|
52
54
|
if (shorter) {
|
|
53
55
|
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
54
56
|
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
@@ -235,7 +237,9 @@ export class CalcitSliceMap {
|
|
|
235
237
|
}
|
|
236
238
|
toString(shorter = false, disableJsDataWarning = false) {
|
|
237
239
|
let itemsCode = "";
|
|
238
|
-
|
|
240
|
+
let pairs = this.pairs();
|
|
241
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
242
|
+
let [k, v] = pairs[idx];
|
|
239
243
|
if (shorter) {
|
|
240
244
|
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
241
245
|
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
package/lib/js-record.mjs
CHANGED
|
@@ -136,7 +136,8 @@ export let _$n_record_$o_from_map = (proto, data) => {
|
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
let values = [];
|
|
139
|
-
for (let
|
|
139
|
+
for (let i = 0; i < proto.fields.length; i++) {
|
|
140
|
+
let field = proto.fields[i];
|
|
140
141
|
let idx = findInFields(data.fields, field);
|
|
141
142
|
if (idx < 0) {
|
|
142
143
|
throw new Error(`Cannot find field ${field} among ${data.fields}`);
|
|
@@ -147,22 +148,25 @@ export let _$n_record_$o_from_map = (proto, data) => {
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
else if (data instanceof CalcitMap || data instanceof CalcitSliceMap) {
|
|
150
|
-
let
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
let pairs_buffer = [];
|
|
152
|
+
let pairs = data.pairs();
|
|
153
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
154
|
+
let [k, v] = pairs[i];
|
|
155
|
+
pairs_buffer.push([castKwd(k), v]);
|
|
153
156
|
}
|
|
154
157
|
// mutable sort
|
|
155
|
-
|
|
158
|
+
pairs_buffer.sort((pair1, pair2) => pair1[0].cmp(pair2[0]));
|
|
156
159
|
let values = [];
|
|
157
|
-
outerLoop: for (let
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
outerLoop: for (let i = 0; i < proto.fields.length; i++) {
|
|
161
|
+
let field = proto.fields[i];
|
|
162
|
+
for (let idx = 0; idx < pairs_buffer.length; idx++) {
|
|
163
|
+
let pair = pairs_buffer[idx];
|
|
160
164
|
if (pair[0] === field) {
|
|
161
165
|
values.push(pair[1]);
|
|
162
166
|
continue outerLoop; // dirty code for performance
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
|
-
throw new Error(`Cannot find field ${field} among ${
|
|
169
|
+
throw new Error(`Cannot find field ${field} among ${pairs_buffer}`);
|
|
166
170
|
}
|
|
167
171
|
return new CalcitRecord(proto.name, proto.fields, values);
|
|
168
172
|
}
|
package/package.json
CHANGED
package/ts-src/calcit-data.mts
CHANGED
|
@@ -286,7 +286,8 @@ export let hashFunction = (x: CalcitValue): Hash => {
|
|
|
286
286
|
let base = defaultHash_map;
|
|
287
287
|
let pairs = x.pairs();
|
|
288
288
|
pairs.sort((a, b) => _$n_compare(a[0], b[0]));
|
|
289
|
-
for (let
|
|
289
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
290
|
+
let [k, v] = pairs[idx];
|
|
290
291
|
base = mergeValueHash(base, hashFunction(k));
|
|
291
292
|
base = mergeValueHash(base, hashFunction(v));
|
|
292
293
|
}
|
|
@@ -298,7 +299,8 @@ export let hashFunction = (x: CalcitValue): Hash => {
|
|
|
298
299
|
|
|
299
300
|
let pairs = x.pairs();
|
|
300
301
|
pairs.sort((a, b) => _$n_compare(a[0], b[0]));
|
|
301
|
-
for (let
|
|
302
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
303
|
+
let [k, v] = pairs[idx];
|
|
302
304
|
base = mergeValueHash(base, hashFunction(k));
|
|
303
305
|
base = mergeValueHash(base, hashFunction(v));
|
|
304
306
|
}
|
|
@@ -441,7 +443,9 @@ export let to_js_data = (x: CalcitValue, addColon: boolean = false): any => {
|
|
|
441
443
|
}
|
|
442
444
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
443
445
|
let result: Record<string, CalcitValue> = {};
|
|
444
|
-
|
|
446
|
+
let pairs = x.pairs();
|
|
447
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
448
|
+
let [k, v] = pairs[idx];
|
|
445
449
|
var key = to_js_data(k, addColon);
|
|
446
450
|
result[key] = to_js_data(v, addColon);
|
|
447
451
|
}
|
|
@@ -552,7 +556,9 @@ export let _$n__$e_ = (x: CalcitValue, y: CalcitValue): boolean => {
|
|
|
552
556
|
if (x.len() !== y.len()) {
|
|
553
557
|
return false;
|
|
554
558
|
}
|
|
555
|
-
|
|
559
|
+
let pairs = x.pairs();
|
|
560
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
561
|
+
let [k, v] = pairs[idx];
|
|
556
562
|
if (!y.contains(k)) {
|
|
557
563
|
return false;
|
|
558
564
|
}
|
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// CALCIT VERSION
|
|
2
|
-
export const calcit_version = "0.6.
|
|
2
|
+
export const calcit_version = "0.6.11";
|
|
3
3
|
|
|
4
4
|
import { parse, ICirruNode } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
@@ -243,7 +243,9 @@ export let _$n_list_$o_includes_$q_ = (xs: CalcitValue, x: CalcitValue): boolean
|
|
|
243
243
|
|
|
244
244
|
export let _$n_map_$o_includes_$q_ = (xs: CalcitValue, x: CalcitValue): boolean => {
|
|
245
245
|
if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
|
|
246
|
-
|
|
246
|
+
let pairs = xs.pairs();
|
|
247
|
+
for (let idx = 0; idx < pairs.length; idx = idx + 1) {
|
|
248
|
+
let v = pairs[idx][1];
|
|
247
249
|
if (_$n__$e_(v, x)) {
|
|
248
250
|
return true;
|
|
249
251
|
}
|
|
@@ -637,7 +639,8 @@ export let _$n_list_$o_slice = (xs: CalcitList, from: number, to: number): Calci
|
|
|
637
639
|
|
|
638
640
|
export let _$n_list_$o_concat = (...lists: (CalcitList | CalcitSliceList)[]): CalcitList | CalcitSliceList => {
|
|
639
641
|
let result: CalcitSliceList | CalcitList = new CalcitSliceList([]);
|
|
640
|
-
for (let
|
|
642
|
+
for (let idx = 0; idx < lists.length; idx++) {
|
|
643
|
+
let item = lists[idx];
|
|
641
644
|
if (item == null) {
|
|
642
645
|
continue;
|
|
643
646
|
}
|
|
@@ -726,19 +729,21 @@ export let _$n_merge = (a: CalcitValue, b: CalcitMap | CalcitSliceMap): CalcitVa
|
|
|
726
729
|
if (a instanceof CalcitRecord) {
|
|
727
730
|
if (b instanceof CalcitMap || b instanceof CalcitSliceMap) {
|
|
728
731
|
let values = [];
|
|
729
|
-
for (let
|
|
730
|
-
values.push(
|
|
732
|
+
for (let idx = 0; idx < a.values.length; idx++) {
|
|
733
|
+
values.push(a.values[idx]);
|
|
731
734
|
}
|
|
732
|
-
|
|
735
|
+
let pairs = b.pairs();
|
|
736
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
737
|
+
let [k, v] = pairs[idx];
|
|
733
738
|
let field: CalcitKeyword;
|
|
734
739
|
if (k instanceof CalcitKeyword) {
|
|
735
740
|
field = k;
|
|
736
741
|
} else {
|
|
737
742
|
field = kwd(getStringName(k));
|
|
738
743
|
}
|
|
739
|
-
let
|
|
740
|
-
if (
|
|
741
|
-
values[
|
|
744
|
+
let position = a.findIndex(field);
|
|
745
|
+
if (position >= 0) {
|
|
746
|
+
values[position] = v;
|
|
742
747
|
} else {
|
|
743
748
|
throw new Error(`Cannot find field ${field} among (${a.fields.join(", ")})`);
|
|
744
749
|
}
|
|
@@ -769,8 +774,9 @@ export let _$n_merge_non_nil = (a: CalcitMap | CalcitSliceMap, b: CalcitMap | Ca
|
|
|
769
774
|
export let to_pairs = (xs: CalcitValue): CalcitValue | CalcitSliceList => {
|
|
770
775
|
if (xs instanceof CalcitMap || xs instanceof CalcitSliceMap) {
|
|
771
776
|
let result: Array<CalcitSliceList> = [];
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
let pairs = xs.pairs();
|
|
778
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
779
|
+
result.push(new CalcitSliceList(pairs[idx]));
|
|
774
780
|
}
|
|
775
781
|
return new CalcitSet(result);
|
|
776
782
|
} else if (xs instanceof CalcitRecord) {
|
|
@@ -1267,55 +1273,62 @@ export let register_calcit_builtin_classes = (options: typeof calcit_builtin_cla
|
|
|
1267
1273
|
Object.assign(calcit_builtin_classes, options);
|
|
1268
1274
|
};
|
|
1269
1275
|
|
|
1270
|
-
|
|
1276
|
+
/** method used as closure */
|
|
1277
|
+
export function invoke_method_closure(p: string) {
|
|
1271
1278
|
return (obj: CalcitValue, ...args: CalcitValue[]) => {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
klass =
|
|
1284
|
-
} else if (typeof obj === "string") {
|
|
1285
|
-
klass = calcit_builtin_classes.string;
|
|
1286
|
-
} else if (typeof obj === "function") {
|
|
1287
|
-
klass = calcit_builtin_classes.fn;
|
|
1288
|
-
} else if (obj instanceof CalcitSet) {
|
|
1289
|
-
klass = calcit_builtin_classes.set;
|
|
1290
|
-
} else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
1291
|
-
klass = calcit_builtin_classes.list;
|
|
1292
|
-
} else if (obj instanceof CalcitRecord) {
|
|
1293
|
-
klass = calcit_builtin_classes.record;
|
|
1294
|
-
} else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
1295
|
-
klass = calcit_builtin_classes.map;
|
|
1279
|
+
return invoke_method(p, obj, ...args);
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[]) {
|
|
1284
|
+
let klass: CalcitRecord;
|
|
1285
|
+
let value = obj;
|
|
1286
|
+
if (obj == null) {
|
|
1287
|
+
klass = calcit_builtin_classes.nil;
|
|
1288
|
+
} else if (obj instanceof CalcitTuple) {
|
|
1289
|
+
if (obj.fst instanceof CalcitRecord) {
|
|
1290
|
+
klass = obj.fst;
|
|
1296
1291
|
} else {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1292
|
+
throw new Error("Method invoking expected a record as class");
|
|
1293
|
+
}
|
|
1294
|
+
} else if (typeof obj === "number") {
|
|
1295
|
+
klass = calcit_builtin_classes.number;
|
|
1296
|
+
} else if (typeof obj === "string") {
|
|
1297
|
+
klass = calcit_builtin_classes.string;
|
|
1298
|
+
} else if (typeof obj === "function") {
|
|
1299
|
+
klass = calcit_builtin_classes.fn;
|
|
1300
|
+
} else if (obj instanceof CalcitSet) {
|
|
1301
|
+
klass = calcit_builtin_classes.set;
|
|
1302
|
+
} else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
1303
|
+
klass = calcit_builtin_classes.list;
|
|
1304
|
+
} else if (obj instanceof CalcitRecord) {
|
|
1305
|
+
klass = calcit_builtin_classes.record;
|
|
1306
|
+
} else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
1307
|
+
klass = calcit_builtin_classes.map;
|
|
1308
|
+
} else {
|
|
1309
|
+
if ((obj as any)[p] == null) {
|
|
1310
|
+
throw new Error(`Missing method \`${p}\` on object`);
|
|
1301
1311
|
}
|
|
1302
|
-
|
|
1312
|
+
return (obj as any)[p](...args); // trying to call native JavaScript method
|
|
1313
|
+
}
|
|
1314
|
+
if (klass == null) throw new Error("Cannot find class for this object for invoking");
|
|
1303
1315
|
|
|
1304
|
-
|
|
1316
|
+
if (!klass.contains(p)) throw new Error(`Missing method '${p}' for object: ${obj}`);
|
|
1305
1317
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
};
|
|
1318
|
+
let method = klass.get(p);
|
|
1319
|
+
if (typeof method === "function") {
|
|
1320
|
+
return method(value, ...args);
|
|
1321
|
+
} else {
|
|
1322
|
+
throw new Error("Method for invoking is not a function");
|
|
1323
|
+
}
|
|
1313
1324
|
}
|
|
1314
1325
|
|
|
1315
1326
|
export let _$n_map_$o_to_list = (m: CalcitValue): CalcitSliceList => {
|
|
1316
1327
|
if (m instanceof CalcitMap || m instanceof CalcitSliceMap) {
|
|
1317
1328
|
let ys = [];
|
|
1318
|
-
|
|
1329
|
+
let pairs = m.pairs();
|
|
1330
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
1331
|
+
let pair = pairs[idx];
|
|
1319
1332
|
ys.push(new CalcitSliceList(pair));
|
|
1320
1333
|
}
|
|
1321
1334
|
return new CalcitSliceList(ys);
|
|
@@ -133,7 +133,8 @@ export let load_console_formatter_$x_ = () => {
|
|
|
133
133
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
134
134
|
let ret: any[] = ["div", { style: "color: hsl(280, 80%, 60%)" }];
|
|
135
135
|
let pairs = obj.pairs();
|
|
136
|
-
for (let
|
|
136
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
137
|
+
let [k, v] = pairs[idx];
|
|
137
138
|
ret.push([
|
|
138
139
|
"div",
|
|
139
140
|
{ style: "margin-left: 8px; display: flex;" },
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -36,7 +36,8 @@ export let format_cirru = (data: CalcitCirruQuote | CalcitList, useInline: boole
|
|
|
36
36
|
if (!Array.isArray(chunk)) {
|
|
37
37
|
throw new Error("Expected data of list");
|
|
38
38
|
}
|
|
39
|
-
for (let
|
|
39
|
+
for (let idx = 0; idx < chunk.length; idx++) {
|
|
40
|
+
let item = chunk[idx];
|
|
40
41
|
if (!Array.isArray(item)) {
|
|
41
42
|
throw new Error("Expected data in a list of lists");
|
|
42
43
|
}
|
|
@@ -73,11 +74,12 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
73
74
|
}
|
|
74
75
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
75
76
|
let buffer: CirruEdnFormat = ["{}"];
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
let pairs_buffer: [CalcitValue, CalcitValue][] = [];
|
|
78
|
+
let pairs = x.pairs();
|
|
79
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
80
|
+
pairs_buffer.push(pairs[idx]);
|
|
79
81
|
}
|
|
80
|
-
|
|
82
|
+
pairs_buffer.sort((a, b) => {
|
|
81
83
|
let a0_literal = is_literal(a[0]);
|
|
82
84
|
let a1_literal = is_literal(a[1]);
|
|
83
85
|
let b0_literal = is_literal(b[0]);
|
|
@@ -98,7 +100,8 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
98
100
|
return _$n_compare(a[0], b[0]);
|
|
99
101
|
}
|
|
100
102
|
});
|
|
101
|
-
for (let
|
|
103
|
+
for (let idx = 0; idx < pairs_buffer.length; idx++) {
|
|
104
|
+
let [k, v] = pairs_buffer[idx];
|
|
102
105
|
buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
|
|
103
106
|
}
|
|
104
107
|
return buffer;
|
package/ts-src/js-list.mts
CHANGED
|
@@ -340,7 +340,9 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
340
340
|
}
|
|
341
341
|
if (xs instanceof CalcitSet) {
|
|
342
342
|
let state = acc;
|
|
343
|
-
|
|
343
|
+
let values = xs.values();
|
|
344
|
+
for (let idx = 0; idx < values.length; idx++) {
|
|
345
|
+
let item = values[idx];
|
|
344
346
|
let pair = f(state, item);
|
|
345
347
|
if (pair instanceof CalcitTuple) {
|
|
346
348
|
if (typeof pair.fst === "boolean") {
|
|
@@ -379,7 +381,9 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
379
381
|
}
|
|
380
382
|
if (xs instanceof CalcitMap) {
|
|
381
383
|
let state = acc;
|
|
382
|
-
|
|
384
|
+
let pairs = xs.pairs();
|
|
385
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
386
|
+
let item = pairs[idx];
|
|
383
387
|
let pair = f(state, new CalcitSliceList(item));
|
|
384
388
|
if (pair instanceof CalcitTuple) {
|
|
385
389
|
if (typeof pair.fst === "boolean") {
|
package/ts-src/js-map.mts
CHANGED
|
@@ -68,7 +68,9 @@ export class CalcitMap {
|
|
|
68
68
|
}
|
|
69
69
|
toString(shorter = false, disableJsDataWarning = false) {
|
|
70
70
|
let itemsCode = "";
|
|
71
|
-
|
|
71
|
+
let pairs = this.pairs();
|
|
72
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
73
|
+
let [k, v] = pairs[idx];
|
|
72
74
|
if (shorter) {
|
|
73
75
|
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
74
76
|
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
@@ -254,7 +256,9 @@ export class CalcitSliceMap {
|
|
|
254
256
|
}
|
|
255
257
|
toString(shorter = false, disableJsDataWarning = false) {
|
|
256
258
|
let itemsCode = "";
|
|
257
|
-
|
|
259
|
+
let pairs = this.pairs();
|
|
260
|
+
for (let idx = 0; idx < pairs.length; idx++) {
|
|
261
|
+
let [k, v] = pairs[idx];
|
|
258
262
|
if (shorter) {
|
|
259
263
|
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
260
264
|
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
package/ts-src/js-record.mts
CHANGED
|
@@ -143,7 +143,8 @@ export let _$n_record_$o_from_map = (proto: CalcitValue, data: CalcitValue): Cal
|
|
|
143
143
|
return new CalcitRecord(proto.name, proto.fields, data.values);
|
|
144
144
|
} else {
|
|
145
145
|
let values: Array<CalcitValue> = [];
|
|
146
|
-
for (let
|
|
146
|
+
for (let i = 0; i < proto.fields.length; i++) {
|
|
147
|
+
let field = proto.fields[i];
|
|
147
148
|
let idx = findInFields(data.fields, field);
|
|
148
149
|
if (idx < 0) {
|
|
149
150
|
throw new Error(`Cannot find field ${field} among ${data.fields}`);
|
|
@@ -153,23 +154,26 @@ export let _$n_record_$o_from_map = (proto: CalcitValue, data: CalcitValue): Cal
|
|
|
153
154
|
return new CalcitRecord(proto.name, proto.fields, values);
|
|
154
155
|
}
|
|
155
156
|
} else if (data instanceof CalcitMap || data instanceof CalcitSliceMap) {
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
let pairs_buffer: Array<[CalcitKeyword, CalcitValue]> = [];
|
|
158
|
+
let pairs = data.pairs();
|
|
159
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
160
|
+
let [k, v] = pairs[i];
|
|
161
|
+
pairs_buffer.push([castKwd(k), v]);
|
|
159
162
|
}
|
|
160
163
|
// mutable sort
|
|
161
|
-
|
|
164
|
+
pairs_buffer.sort((pair1, pair2) => pair1[0].cmp(pair2[0]));
|
|
162
165
|
|
|
163
166
|
let values: Array<CalcitValue> = [];
|
|
164
|
-
outerLoop: for (let
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
outerLoop: for (let i = 0; i < proto.fields.length; i++) {
|
|
168
|
+
let field = proto.fields[i];
|
|
169
|
+
for (let idx = 0; idx < pairs_buffer.length; idx++) {
|
|
170
|
+
let pair = pairs_buffer[idx];
|
|
167
171
|
if (pair[0] === field) {
|
|
168
172
|
values.push(pair[1]);
|
|
169
173
|
continue outerLoop; // dirty code for performance
|
|
170
174
|
}
|
|
171
175
|
}
|
|
172
|
-
throw new Error(`Cannot find field ${field} among ${
|
|
176
|
+
throw new Error(`Cannot find field ${field} among ${pairs_buffer}`);
|
|
173
177
|
}
|
|
174
178
|
return new CalcitRecord(proto.name, proto.fields, values);
|
|
175
179
|
} else {
|