@calcit/procs 0.26.0 → 0.28.0-alpha.1

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/README.md CHANGED
@@ -60,6 +60,8 @@ Installed binaries:
60
60
  - `calcit`, the runtime and JS compiler
61
61
  - `caps`, for downloading dependencies declared in `deps.cirru`
62
62
 
63
+ 从首次包含该资产的版本起,Ubuntu 22.04 x86_64 的低资源机器可下载 Release 中的 `calcit-ubuntu22.04-x86_64-no-wasm`,无需在本机编译;安装与功能边界见 [无 WASM 构建](docs/installation/no-wasm-build.md)。源码构建可用 `cargo build --release --no-default-features --bin calcit` 关闭 WASM/WASI 代码生成依赖,native 运行与 JS 编译仍可使用。
64
+
63
65
  When developing Calcit core from source, install its runtime locally and install caps from its own release:
64
66
 
65
67
  ```bash
@@ -346,6 +346,7 @@ declare let calcit_builtin_impls: {
346
346
  enum: CalcitImplEntry;
347
347
  struct: CalcitImplEntry;
348
348
  scalar: CalcitImplEntry;
349
+ textScalar: CalcitImplEntry;
349
350
  ref: CalcitImplEntry;
350
351
  };
351
352
  export declare let register_calcit_builtin_impls: (options: typeof calcit_builtin_impls) => void;
@@ -466,7 +466,7 @@ export let _$n_list_$o_contains_$q_ = (xs, x) => {
466
466
  throw new Error("Expected number index for detecting");
467
467
  }
468
468
  let size = xs.len();
469
- if (x >= 0 && x < size) {
469
+ if (Number.isInteger(x) && x >= 0 && x < size) {
470
470
  return true;
471
471
  }
472
472
  return false;
@@ -1375,6 +1375,10 @@ export let _$n_str_$o_find_index = (x, y) => {
1375
1375
  return scalar;
1376
1376
  };
1377
1377
  export let _$n_parse_float = (x) => {
1378
+ if (/^[+-]?nan$/i.test(x))
1379
+ return NaN;
1380
+ if (/^[+-]?(?:inf|infinity)$/i.test(x))
1381
+ return x.startsWith("-") ? -Infinity : Infinity;
1378
1382
  if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(x)) {
1379
1383
  return null;
1380
1384
  }
@@ -1419,15 +1423,20 @@ export let _$n_number_$o_display_by = (x, n) => {
1419
1423
  }
1420
1424
  };
1421
1425
  export let get_char_code = (c) => {
1422
- if (typeof c !== "string" || c.length !== 1) {
1426
+ if (typeof c !== "string") {
1423
1427
  throw new Error("Expected a character");
1424
1428
  }
1425
- return c.charCodeAt(0);
1429
+ const code = c.codePointAt(0);
1430
+ if (code === undefined || code >= 0xd800 && code <= 0xdfff || String.fromCodePoint(code) !== c) {
1431
+ throw new Error("Expected a single Unicode scalar character");
1432
+ }
1433
+ return code;
1426
1434
  };
1427
1435
  export let char_from_code = (n) => {
1428
- if (typeof n !== "number")
1429
- throw new Error("Expected an integer");
1430
- return String.fromCharCode(n);
1436
+ if (!Number.isInteger(n) || n < 0 || n > 0x10ffff || n >= 0xd800 && n <= 0xdfff) {
1437
+ throw new Error("Expected a Unicode scalar value");
1438
+ }
1439
+ return String.fromCodePoint(n);
1431
1440
  };
1432
1441
  export let _$n_set_$o_to_list = (x) => {
1433
1442
  return new CalcitSliceList(x.values());
@@ -1573,6 +1582,37 @@ export let quit_$x_ = (code) => {
1573
1582
  throw new Error(`quit!(${code})`);
1574
1583
  }
1575
1584
  };
1585
+ let format_calcit_number = (x) => {
1586
+ // Match native f64 Display, which expands finite exponents into decimal notation.
1587
+ if (Object.is(x, -0)) {
1588
+ return "-0";
1589
+ }
1590
+ if (x === Infinity) {
1591
+ return "inf";
1592
+ }
1593
+ if (x === -Infinity) {
1594
+ return "-inf";
1595
+ }
1596
+ const text = x.toString();
1597
+ const exponentIndex = text.indexOf("e");
1598
+ if (exponentIndex < 0) {
1599
+ return text;
1600
+ }
1601
+ const mantissa = text.slice(0, exponentIndex);
1602
+ const exponent = Number(text.slice(exponentIndex + 1));
1603
+ const sign = mantissa.startsWith("-") ? "-" : "";
1604
+ const unsigned = sign ? mantissa.slice(1) : mantissa;
1605
+ const decimalPoint = unsigned.indexOf(".");
1606
+ const decimalIndex = (decimalPoint < 0 ? unsigned.length : decimalPoint) + exponent;
1607
+ const digits = unsigned.replace(".", "");
1608
+ if (decimalIndex <= 0) {
1609
+ return `${sign}0.${"0".repeat(-decimalIndex)}${digits}`;
1610
+ }
1611
+ if (decimalIndex >= digits.length) {
1612
+ return `${sign}${digits}${"0".repeat(decimalIndex - digits.length)}`;
1613
+ }
1614
+ return `${sign}${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
1615
+ };
1576
1616
  export let turn_string = (x) => {
1577
1617
  if (x === null) {
1578
1618
  return "";
@@ -1587,7 +1627,7 @@ export let turn_string = (x) => {
1587
1627
  return x.value;
1588
1628
  }
1589
1629
  if (typeof x === "number") {
1590
- return x.toString();
1630
+ return format_calcit_number(x);
1591
1631
  }
1592
1632
  if (typeof x === "boolean") {
1593
1633
  return x.toString();
@@ -2279,7 +2319,13 @@ export let format_to_lisp = (x) => {
2279
2319
  return chunk;
2280
2320
  }
2281
2321
  else if (typeof x === "string") {
2282
- return JSON.stringify("|" + x);
2322
+ // Mirror cirru_edn::is_simple_char for each code point, including CJK blocks.
2323
+ const simpleAscii = /^[0-9A-Za-z?$.,'-]$/u;
2324
+ const simpleCjk = /^[\u2e80-\u2fdf\u3000-\u30ff\u3130-\u318f\u31c0-\u31ff\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\ua960-\ua97f\uac00-\ud7af\uf900-\ufaff\ufe30-\ufe4f\uff00-\uffef\u{1b000}-\u{1b2ff}\u{20000}-\u{323af}]$/u;
2325
+ if (![...x].every((char) => simpleAscii.test(char) || simpleCjk.test(char))) {
2326
+ return JSON.stringify("|" + x);
2327
+ }
2328
+ return toString(x, true);
2283
2329
  }
2284
2330
  else {
2285
2331
  return x.toString();
@@ -2403,6 +2449,7 @@ let calcit_builtin_impls = {
2403
2449
  enum: null,
2404
2450
  struct: null,
2405
2451
  scalar: null,
2452
+ textScalar: null,
2406
2453
  ref: null,
2407
2454
  };
2408
2455
  // need to register code from outside
@@ -2503,11 +2550,14 @@ function lookup_impls(obj) {
2503
2550
  tag = "&core-ref-methods";
2504
2551
  impls = normalize_builtin_impls(calcit_builtin_impls.ref);
2505
2552
  }
2506
- else if (obj == null ||
2553
+ else if (obj === null ||
2507
2554
  typeof obj === "boolean" ||
2508
2555
  obj instanceof CalcitTag ||
2509
- obj instanceof CalcitSymbol ||
2510
- obj instanceof CalcitCirruQuote) {
2556
+ obj instanceof CalcitSymbol) {
2557
+ tag = "&core-text-scalar-impls";
2558
+ impls = normalize_builtin_impls(calcit_builtin_impls.textScalar);
2559
+ }
2560
+ else if (obj === undefined || obj instanceof CalcitCirruQuote) {
2511
2561
  tag = "&core-scalar-impls";
2512
2562
  impls = normalize_builtin_impls(calcit_builtin_impls.scalar);
2513
2563
  }
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.26.0",
3
+ "version": "0.28.0-alpha.1",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "files": [
6
6
  "lib/",
@@ -21,7 +21,7 @@
21
21
  "test-rs": "cargo test -q",
22
22
  "test-fail": "cargo test -q --bin calcit type_fail_",
23
23
  "test-snippets": "cargo test -q snippets::tests",
24
- "check-js-runtime": "node scripts/check-js-runtime-identity.mjs && cargo build --bin calcit && node scripts/check-string-unicode.mjs && node scripts/check-numeric-predicate.mjs && node scripts/check-nil-predicate.mjs && node scripts/check-helper-inference.mjs",
24
+ "check-js-runtime": "node scripts/check-js-runtime-identity.mjs && cargo build --bin calcit && node scripts/check-string-unicode.mjs && node scripts/check-numeric-predicate.mjs && node scripts/check-predicate-method-names.mjs && node scripts/check-map-add-trait-boundary.mjs && node scripts/check-typed-string-conversions.mjs && node scripts/check-identity-conversion-fix.mjs && node scripts/check-nil-predicate.mjs && node scripts/check-monotonic-clock-js.mjs && node scripts/check-helper-inference.mjs",
25
25
  "check-js-ffi-source": "cargo build --bin calcit && node scripts/check-js-ffi-source.mjs",
26
26
  "check-literal-paths": "cargo run --bin calcit -- calcit/bench-literal-paths.cirru && cargo run --bin calcit -- --emit-path target/literal-path-js calcit/bench-literal-paths.cirru js && node scripts/bench-literal-paths.mjs",
27
27
  "check-typed-method-rem": "cargo run --bin calcit -- calcit/fibo.cirru && cargo run --bin calcit -- --emit-path target/typed-method-rem-js calcit/fibo.cirru js && node scripts/bench-typed-method-rem.mjs",
@@ -31,7 +31,7 @@
31
31
  "bench-typed-method-rem": "cargo build --release --bin calcit && yarn compile && target/release/calcit calcit/fibo.cirru && node scripts/bench-typed-method-rem-native.mjs && target/release/calcit --emit-path target/typed-method-rem-js calcit/fibo.cirru js && node scripts/bench-typed-method-rem.mjs",
32
32
  "bench-struct-index": "yarn compile && node scripts/bench-struct-index.mjs",
33
33
  "check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",
34
- "check-all": "yarn compile && yarn check-js-runtime && yarn check-js-ffi-source && yarn check-strict-default && yarn check-agent-interface && yarn try-core-tests && yarn check-core-dynamic-classification && yarn try-rs && yarn try-js && yarn try-ir && yarn try-wasm && yarn check-literal-paths && yarn check-typed-method-rem",
34
+ "check-all": "yarn compile && yarn check-js-runtime && node scripts/check-file-read-names.mjs && node scripts/check-enum-impl-cycle.mjs && yarn check-js-ffi-source && yarn check-strict-default && yarn check-agent-interface && node --test scripts/core-api-contract.test.mjs && node scripts/core-api-contract.mjs && yarn try-core-tests && yarn check-core-dynamic-classification && yarn try-rs && yarn try-js && node scripts/check-struct-field-js.mjs && yarn try-ir && yarn try-wasm && yarn check-literal-paths && yarn check-typed-method-rem",
35
35
  "check-strict-default": "cargo build --bin calcit && node scripts/check-strict-default.mjs",
36
36
  "check-agent-interface": "cargo build --bin calcit && node scripts/check-agent-interface.mjs",
37
37
  "try-all": "yarn check-all",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.26.0",
3
+ "version": "0.28.0-alpha.1",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "files": [
6
6
  "lib/",
@@ -21,7 +21,7 @@
21
21
  "test-rs": "cargo test -q",
22
22
  "test-fail": "cargo test -q --bin calcit type_fail_",
23
23
  "test-snippets": "cargo test -q snippets::tests",
24
- "check-js-runtime": "node scripts/check-js-runtime-identity.mjs && cargo build --bin calcit && node scripts/check-string-unicode.mjs && node scripts/check-numeric-predicate.mjs && node scripts/check-nil-predicate.mjs && node scripts/check-helper-inference.mjs",
24
+ "check-js-runtime": "node scripts/check-js-runtime-identity.mjs && cargo build --bin calcit && node scripts/check-string-unicode.mjs && node scripts/check-numeric-predicate.mjs && node scripts/check-predicate-method-names.mjs && node scripts/check-map-add-trait-boundary.mjs && node scripts/check-typed-string-conversions.mjs && node scripts/check-identity-conversion-fix.mjs && node scripts/check-nil-predicate.mjs && node scripts/check-monotonic-clock-js.mjs && node scripts/check-helper-inference.mjs",
25
25
  "check-js-ffi-source": "cargo build --bin calcit && node scripts/check-js-ffi-source.mjs",
26
26
  "check-literal-paths": "cargo run --bin calcit -- calcit/bench-literal-paths.cirru && cargo run --bin calcit -- --emit-path target/literal-path-js calcit/bench-literal-paths.cirru js && node scripts/bench-literal-paths.mjs",
27
27
  "check-typed-method-rem": "cargo run --bin calcit -- calcit/fibo.cirru && cargo run --bin calcit -- --emit-path target/typed-method-rem-js calcit/fibo.cirru js && node scripts/bench-typed-method-rem.mjs",
@@ -31,7 +31,7 @@
31
31
  "bench-typed-method-rem": "cargo build --release --bin calcit && yarn compile && target/release/calcit calcit/fibo.cirru && node scripts/bench-typed-method-rem-native.mjs && target/release/calcit --emit-path target/typed-method-rem-js calcit/fibo.cirru js && node scripts/bench-typed-method-rem.mjs",
32
32
  "bench-struct-index": "yarn compile && node scripts/bench-struct-index.mjs",
33
33
  "check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",
34
- "check-all": "yarn compile && yarn check-js-runtime && yarn check-js-ffi-source && yarn check-strict-default && yarn check-agent-interface && yarn try-core-tests && yarn check-core-dynamic-classification && yarn try-rs && yarn try-js && yarn try-ir && yarn try-wasm && yarn check-literal-paths && yarn check-typed-method-rem",
34
+ "check-all": "yarn compile && yarn check-js-runtime && node scripts/check-file-read-names.mjs && node scripts/check-enum-impl-cycle.mjs && yarn check-js-ffi-source && yarn check-strict-default && yarn check-agent-interface && node --test scripts/core-api-contract.test.mjs && node scripts/core-api-contract.mjs && yarn try-core-tests && yarn check-core-dynamic-classification && yarn try-rs && yarn try-js && node scripts/check-struct-field-js.mjs && yarn try-ir && yarn try-wasm && yarn check-literal-paths && yarn check-typed-method-rem",
35
35
  "check-strict-default": "cargo build --bin calcit && node scripts/check-strict-default.mjs",
36
36
  "check-agent-interface": "cargo build --bin calcit && node scripts/check-agent-interface.mjs",
37
37
  "try-all": "yarn check-all",