@calcit/procs 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/calcit.procs.mjs +12 -14
- package/lib/js-record.mjs +10 -0
- package/package.json +1 -1
- package/ts-src/calcit.procs.mts +12 -14
- package/ts-src/js-record.mts +9 -0
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
// CALCIT VERSION
|
|
3
|
-
export const calcit_version = "0.8.
|
|
3
|
+
export const calcit_version = "0.8.4";
|
|
4
4
|
import { parse } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
6
6
|
import { CalcitSymbol, CalcitTag, CalcitRef, CalcitRecur, newTag, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
|
|
@@ -129,7 +129,7 @@ export let atom = (x) => {
|
|
|
129
129
|
export let peekDefatom = (path) => {
|
|
130
130
|
return refsRegistry.get(path);
|
|
131
131
|
};
|
|
132
|
-
export let
|
|
132
|
+
export let _$n_atom_$o_deref = (x) => {
|
|
133
133
|
return x.value;
|
|
134
134
|
};
|
|
135
135
|
export let _$n__ADD_ = (x, y) => {
|
|
@@ -1208,10 +1208,9 @@ export function invoke_method_closure(p) {
|
|
|
1208
1208
|
return invoke_method(p, obj, ...args);
|
|
1209
1209
|
};
|
|
1210
1210
|
}
|
|
1211
|
-
|
|
1211
|
+
function lookup_class(obj) {
|
|
1212
1212
|
let klass;
|
|
1213
1213
|
let tag;
|
|
1214
|
-
let value = obj;
|
|
1215
1214
|
if (obj == null) {
|
|
1216
1215
|
tag = "&core-nil-class";
|
|
1217
1216
|
klass = calcit_builtin_classes.nil;
|
|
@@ -1259,19 +1258,18 @@ export function invoke_method(p, obj, ...args) {
|
|
|
1259
1258
|
klass = calcit_builtin_classes.map;
|
|
1260
1259
|
}
|
|
1261
1260
|
else {
|
|
1262
|
-
if (obj[p] == null) {
|
|
1263
|
-
throw new Error(`Missing method \`${p}\` on object`);
|
|
1264
|
-
}
|
|
1265
|
-
return obj[p](...args); // trying to call native JavaScript method
|
|
1266
|
-
}
|
|
1267
|
-
if (klass == null)
|
|
1268
1261
|
throw new Error("Cannot find class for this object for invoking");
|
|
1269
|
-
if (!klass.contains(p)) {
|
|
1270
|
-
throw new Error(`Missing method '.${p}' for '${tag}' object '${obj}'.\navailable fields are: ${klass.fields.map((fd) => fd.value).join(" ")}`);
|
|
1271
1262
|
}
|
|
1272
|
-
|
|
1263
|
+
return [klass, tag];
|
|
1264
|
+
}
|
|
1265
|
+
export function invoke_method(p, obj, ...args) {
|
|
1266
|
+
let [klass, tag] = lookup_class(obj);
|
|
1267
|
+
let method = klass.getOrNil(p);
|
|
1268
|
+
if (method == null) {
|
|
1269
|
+
throw new Error(`No method '.${p}' for '${tag}' object '${obj}'.\navailable fields are: ${klass.fields.map((fd) => fd.value).join(" ")}`);
|
|
1270
|
+
}
|
|
1273
1271
|
if (typeof method === "function") {
|
|
1274
|
-
return method(
|
|
1272
|
+
return method(obj, ...args);
|
|
1275
1273
|
}
|
|
1276
1274
|
else {
|
|
1277
1275
|
throw new Error("Method for invoking is not a function");
|
package/lib/js-record.mjs
CHANGED
|
@@ -27,6 +27,16 @@ export class CalcitRecord {
|
|
|
27
27
|
throw new Error(`Cannot find :${field} among (${this.fields.join(",")})`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
getOrNil(k) {
|
|
31
|
+
let field = castTag(k);
|
|
32
|
+
let idx = findInFields(this.fields, field);
|
|
33
|
+
if (idx >= 0) {
|
|
34
|
+
return this.values[idx];
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
30
40
|
assoc(k, v) {
|
|
31
41
|
let values = new Array(this.fields.length);
|
|
32
42
|
let k_id = castTag(k);
|
package/package.json
CHANGED
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// CALCIT VERSION
|
|
2
|
-
export const calcit_version = "0.8.
|
|
2
|
+
export const calcit_version = "0.8.4";
|
|
3
3
|
|
|
4
4
|
import { parse, ICirruNode } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
@@ -158,7 +158,7 @@ export let peekDefatom = (path: string): CalcitRef => {
|
|
|
158
158
|
return refsRegistry.get(path);
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
export let
|
|
161
|
+
export let _$n_atom_$o_deref = (x: CalcitRef): CalcitValue => {
|
|
162
162
|
return x.value;
|
|
163
163
|
};
|
|
164
164
|
|
|
@@ -1309,10 +1309,9 @@ export function invoke_method_closure(p: string) {
|
|
|
1309
1309
|
};
|
|
1310
1310
|
}
|
|
1311
1311
|
|
|
1312
|
-
|
|
1312
|
+
function lookup_class(obj: CalcitValue): [CalcitRecord, string] {
|
|
1313
1313
|
let klass: CalcitRecord;
|
|
1314
1314
|
let tag: string;
|
|
1315
|
-
let value = obj;
|
|
1316
1315
|
if (obj == null) {
|
|
1317
1316
|
tag = "&core-nil-class";
|
|
1318
1317
|
klass = calcit_builtin_classes.nil;
|
|
@@ -1349,20 +1348,19 @@ export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[
|
|
|
1349
1348
|
tag = "&core-map-class";
|
|
1350
1349
|
klass = calcit_builtin_classes.map;
|
|
1351
1350
|
} else {
|
|
1352
|
-
|
|
1353
|
-
throw new Error(`Missing method \`${p}\` on object`);
|
|
1354
|
-
}
|
|
1355
|
-
return (obj as any)[p](...args); // trying to call native JavaScript method
|
|
1351
|
+
throw new Error("Cannot find class for this object for invoking");
|
|
1356
1352
|
}
|
|
1357
|
-
|
|
1353
|
+
return [klass, tag];
|
|
1354
|
+
}
|
|
1358
1355
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1356
|
+
export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[]) {
|
|
1357
|
+
let [klass, tag] = lookup_class(obj);
|
|
1358
|
+
let method = klass.getOrNil(p);
|
|
1359
|
+
if (method == null) {
|
|
1360
|
+
throw new Error(`No method '.${p}' for '${tag}' object '${obj}'.\navailable fields are: ${klass.fields.map((fd: CalcitTag) => fd.value).join(" ")}`);
|
|
1361
1361
|
}
|
|
1362
|
-
|
|
1363
|
-
let method = klass.get(p);
|
|
1364
1362
|
if (typeof method === "function") {
|
|
1365
|
-
return method(
|
|
1363
|
+
return method(obj, ...args);
|
|
1366
1364
|
} else {
|
|
1367
1365
|
throw new Error("Method for invoking is not a function");
|
|
1368
1366
|
}
|
package/ts-src/js-record.mts
CHANGED
|
@@ -34,6 +34,15 @@ export class CalcitRecord {
|
|
|
34
34
|
throw new Error(`Cannot find :${field} among (${this.fields.join(",")})`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
getOrNil(k: CalcitValue) {
|
|
38
|
+
let field = castTag(k);
|
|
39
|
+
let idx = findInFields(this.fields, field);
|
|
40
|
+
if (idx >= 0) {
|
|
41
|
+
return this.values[idx];
|
|
42
|
+
} else {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
assoc(k: CalcitValue, v: CalcitValue): CalcitRecord {
|
|
38
47
|
let values: Array<CalcitValue> = new Array(this.fields.length);
|
|
39
48
|
let k_id = castTag(k);
|