@calcit/procs 0.8.2 → 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.
@@ -402,6 +402,14 @@ export let to_js_data = (x, addColon = false) => {
402
402
  }
403
403
  return Symbol(x.value);
404
404
  }
405
+ if (x instanceof CalcitTuple) {
406
+ var result = [to_js_data(x.tag)];
407
+ for (let i = 0; i < x.extra.length; i++) {
408
+ let item = x.extra[i];
409
+ result.push(to_js_data(item));
410
+ }
411
+ return result;
412
+ }
405
413
  if (x instanceof CalcitList || x instanceof CalcitSliceList) {
406
414
  var result = [];
407
415
  for (let item of x.items()) {
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.8.2";
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 deref = (x) => {
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
- export function invoke_method(p, obj, ...args) {
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
- let method = klass.get(p);
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(value, ...args);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^20.6.2",
@@ -12,7 +12,7 @@
12
12
  "cp-mac": "cargo build --release && rm -rfv builds/* && node scripts/cp-version.js && scp builds/* rsync-user@calcit-lang.org:/web-assets/repo/calcit-lang/binaries/macos/",
13
13
  "eval": "cargo run --bin cr -- -e",
14
14
  "try-rs": "cargo run --bin cr -- calcit/test.cirru -1",
15
- "try-js-brk": "cargo run --bin cr -- calcit/test.cirru --emit-js -1 && node js-out/main.mjs",
15
+ "try-js-brk": "cargo run --bin cr -- calcit/test.cirru --emit-js -1 && node --inspect-brk js-out/main.mjs",
16
16
  "try-js": "cargo run --bin cr -- calcit/test.cirru --emit-js -1 && node js-out/main.mjs"
17
17
  },
18
18
  "repository": {
@@ -437,6 +437,14 @@ export let to_js_data = (x: CalcitValue, addColon: boolean = false): any => {
437
437
  }
438
438
  return Symbol(x.value);
439
439
  }
440
+ if (x instanceof CalcitTuple) {
441
+ var result: any[] = [to_js_data(x.tag)];
442
+ for (let i = 0; i < x.extra.length; i++) {
443
+ let item = x.extra[i];
444
+ result.push(to_js_data(item));
445
+ }
446
+ return result;
447
+ }
440
448
  if (x instanceof CalcitList || x instanceof CalcitSliceList) {
441
449
  var result: any[] = [];
442
450
  for (let item of x.items()) {
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.8.2";
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 deref = (x: CalcitRef): CalcitValue => {
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
- export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[]) {
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
- if ((obj as any)[p] == null) {
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
- if (klass == null) throw new Error("Cannot find class for this object for invoking");
1353
+ return [klass, tag];
1354
+ }
1358
1355
 
1359
- if (!klass.contains(p)) {
1360
- throw new Error(`Missing method '.${p}' for '${tag}' object '${obj}'.\navailable fields are: ${klass.fields.map((fd: CalcitTag) => fd.value).join(" ")}`);
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(value, ...args);
1363
+ return method(obj, ...args);
1366
1364
  } else {
1367
1365
  throw new Error("Method for invoking is not a function");
1368
1366
  }
@@ -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);