@calcit/procs 0.5.31 → 0.5.34

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.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.5.31";
3
+ export const calcit_version = "0.5.34";
4
4
  import "@calcit/ternary-tree";
5
5
  import { parse } from "@cirru/parser.ts";
6
6
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -1273,6 +1273,22 @@ export let _$n_str_$o_pad_right = (s, size, pattern) => {
1273
1273
  export let _$n_get_os = () => {
1274
1274
  return kwd("js-engine");
1275
1275
  };
1276
+ export let _$n_buffer = (...xs) => {
1277
+ let buf = new Uint8Array(xs.length);
1278
+ for (let idx = 0; idx < xs.length; idx++) {
1279
+ let x = xs[idx];
1280
+ if (typeof x === "number") {
1281
+ buf[idx] = x;
1282
+ }
1283
+ else if (typeof x === "string") {
1284
+ buf[idx] = parseInt(x, 16);
1285
+ }
1286
+ else {
1287
+ throw new Error("invalid value for buffer");
1288
+ }
1289
+ }
1290
+ return buf;
1291
+ };
1276
1292
  // special procs have to be defined manually
1277
1293
  export let reduce = foldl;
1278
1294
  let unavailableProc = (...xs) => {
package/lib/js-cirru.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "@calcit/ternary-tree";
2
2
  import { writeCirruCode } from "@cirru/writer.ts";
3
- import { _$n_compare } from "./js-primes.mjs";
3
+ import { is_literal, _$n_compare } from "./js-primes.mjs";
4
4
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
5
5
  import { CalcitRecord } from "./js-record.mjs";
6
6
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
@@ -50,7 +50,30 @@ export let to_cirru_edn = (x) => {
50
50
  pairs.push(pair);
51
51
  }
52
52
  pairs.sort((a, b) => {
53
- return _$n_compare(a[0], b[0]);
53
+ let a0_literal = is_literal(a[0]);
54
+ let a1_literal = is_literal(a[1]);
55
+ let b0_literal = is_literal(b[0]);
56
+ let b1_literal = is_literal(b[1]);
57
+ if (a0_literal && b0_literal) {
58
+ if (a1_literal && !b1_literal) {
59
+ return -1;
60
+ }
61
+ else if (!a1_literal && b1_literal) {
62
+ return 1;
63
+ }
64
+ else {
65
+ return _$n_compare(a[0], b[0]);
66
+ }
67
+ }
68
+ else if (a0_literal && !b0_literal) {
69
+ return -1;
70
+ }
71
+ else if (!a0_literal && b0_literal) {
72
+ return 1;
73
+ }
74
+ else {
75
+ return _$n_compare(a[0], b[0]);
76
+ }
54
77
  });
55
78
  for (let [k, v] of pairs) {
56
79
  buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
package/lib/js-primes.mjs CHANGED
@@ -4,6 +4,21 @@ import { CalcitRecord } from "./js-record.mjs";
4
4
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
5
5
  import { CalcitSet as CalcitSet } from "./js-set.mjs";
6
6
  import { CalcitTuple } from "./js-tuple.mjs";
7
+ export let is_literal = (x) => {
8
+ if (x == null)
9
+ return true;
10
+ if (typeof x == "string")
11
+ return true;
12
+ if (typeof x == "boolean")
13
+ return true;
14
+ if (typeof x == "number")
15
+ return true;
16
+ if (x instanceof CalcitKeyword)
17
+ return true;
18
+ if (x instanceof CalcitSymbol)
19
+ return true;
20
+ return false;
21
+ };
7
22
  var PseudoTypeIndex;
8
23
  (function (PseudoTypeIndex) {
9
24
  PseudoTypeIndex[PseudoTypeIndex["nil"] = 0] = "nil";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.5.31",
3
+ "version": "0.5.34",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^17.0.23",
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.5.31";
2
+ export const calcit_version = "0.5.34";
3
3
 
4
4
  import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
5
5
  import { parse, ICirruNode } from "@cirru/parser.ts";
@@ -1365,6 +1365,23 @@ export let _$n_get_os = (): CalcitKeyword => {
1365
1365
  return kwd("js-engine");
1366
1366
  };
1367
1367
 
1368
+ export let _$n_buffer = (...xs: CalcitValue[]): Uint8Array => {
1369
+ let buf = new Uint8Array(xs.length);
1370
+
1371
+ for (let idx = 0; idx < xs.length; idx++) {
1372
+ let x = xs[idx];
1373
+ if (typeof x === "number") {
1374
+ buf[idx] = x;
1375
+ } else if (typeof x === "string") {
1376
+ buf[idx] = parseInt(x, 16);
1377
+ } else {
1378
+ throw new Error("invalid value for buffer");
1379
+ }
1380
+ }
1381
+
1382
+ return buf;
1383
+ };
1384
+
1368
1385
  // special procs have to be defined manually
1369
1386
  export let reduce = foldl;
1370
1387
 
@@ -1,7 +1,7 @@
1
1
  import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
2
2
  import { CirruWriterNode, writeCirruCode } from "@cirru/writer.ts";
3
3
 
4
- import { CalcitValue, _$n_compare } from "./js-primes.mjs";
4
+ import { CalcitValue, is_literal, _$n_compare } from "./js-primes.mjs";
5
5
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
6
6
  import { CalcitRecord } from "./js-record.mjs";
7
7
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
@@ -55,7 +55,25 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
55
55
  pairs.push(pair);
56
56
  }
57
57
  pairs.sort((a, b) => {
58
- return _$n_compare(a[0], b[0]);
58
+ let a0_literal = is_literal(a[0]);
59
+ let a1_literal = is_literal(a[1]);
60
+ let b0_literal = is_literal(b[0]);
61
+ let b1_literal = is_literal(b[1]);
62
+ if (a0_literal && b0_literal) {
63
+ if (a1_literal && !b1_literal) {
64
+ return -1;
65
+ } else if (!a1_literal && b1_literal) {
66
+ return 1;
67
+ } else {
68
+ return _$n_compare(a[0], b[0]);
69
+ }
70
+ } else if (a0_literal && !b0_literal) {
71
+ return -1;
72
+ } else if (!a0_literal && b0_literal) {
73
+ return 1;
74
+ } else {
75
+ return _$n_compare(a[0], b[0]);
76
+ }
59
77
  });
60
78
  for (let [k, v] of pairs) {
61
79
  buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
@@ -23,6 +23,16 @@ export type CalcitValue =
23
23
  | CalcitRecord
24
24
  | null;
25
25
 
26
+ export let is_literal = (x: CalcitValue): boolean => {
27
+ if (x == null) return true;
28
+ if (typeof x == "string") return true;
29
+ if (typeof x == "boolean") return true;
30
+ if (typeof x == "number") return true;
31
+ if (x instanceof CalcitKeyword) return true;
32
+ if (x instanceof CalcitSymbol) return true;
33
+ return false;
34
+ };
35
+
26
36
  enum PseudoTypeIndex {
27
37
  nil,
28
38
  bool,