hclang 0.20.3 → 0.21.0
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/esm/lib/bundle/hc-sources.js +98 -15
- package/esm/lib/execute/hc-eval.js +4 -3
- package/esm/lib/execute/syntax.js +1 -1
- package/esm/lib/frames/frame-blob.js +2 -2
- package/esm/lib/frames/frame-count.js +67 -0
- package/esm/lib/frames/frame-decimal.js +2 -2
- package/esm/lib/frames/frame-int.js +25 -34
- package/esm/lib/frames/frame-number.js +2 -2
- package/esm/lib/frames/frame-numeric.js +30 -13
- package/esm/lib/frames/frame-rational.js +3 -2
- package/esm/lib/frames/frame-resource.js +3 -3
- package/esm/lib/frames.js +2 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -1745,7 +1745,7 @@ export const HC_SOURCES = new Map([
|
|
|
1745
1745
|
"; 3.%%2",
|
|
1746
1746
|
"# 1",
|
|
1747
1747
|
"; 3.0 %% 2",
|
|
1748
|
-
"# $!.numeric-domain %% FrameDecimal
|
|
1748
|
+
"# $!.numeric-domain %% FrameDecimal FrameCount",
|
|
1749
1749
|
"```",
|
|
1750
1750
|
"Zero and unsupported domains return stable errors",
|
|
1751
1751
|
"```",
|
|
@@ -1754,9 +1754,9 @@ export const HC_SOURCES = new Map([
|
|
|
1754
1754
|
"; 1 %% (1 - 1)",
|
|
1755
1755
|
"# $!.modulo-by-zero %%",
|
|
1756
1756
|
"; 1.408.555 + 1",
|
|
1757
|
-
"# $!.numeric-domain + FrameSequence
|
|
1757
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1758
1758
|
"; 1.408.555.< 2",
|
|
1759
|
-
"# $!.numeric-domain < FrameSequence
|
|
1759
|
+
"# $!.numeric-domain < FrameSequence FrameCount",
|
|
1760
1760
|
"; 1.408.555 = 1",
|
|
1761
1761
|
"# ()",
|
|
1762
1762
|
"; -1.408.555",
|
|
@@ -1771,7 +1771,90 @@ export const HC_SOURCES = new Map([
|
|
|
1771
1771
|
"; 65537“x”",
|
|
1772
1772
|
"# $!.repetition-limit 65536",
|
|
1773
1773
|
"; 2 ** 1000000",
|
|
1774
|
-
"# $!.numeric-range **
|
|
1774
|
+
"# $!.numeric-range ** FrameCount",
|
|
1775
|
+
"```",
|
|
1776
|
+
"Counts (#407). Every nonnegative integer literal is a `FrameCount`, the root of",
|
|
1777
|
+
"the ladder, and prints as the same integer does. A sequence's refusal names the",
|
|
1778
|
+
"class of its other operand, which is how these examples observe the rung",
|
|
1779
|
+
"```",
|
|
1780
|
+
"; 1.408.555 + 0",
|
|
1781
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1782
|
+
"; 1.408.555 + 1234567890",
|
|
1783
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1784
|
+
"; 1.408.555 + -1",
|
|
1785
|
+
"# $!.numeric-domain + FrameSequence FrameInt",
|
|
1786
|
+
"```",
|
|
1787
|
+
"Counts are closed under `+`, `*`, `%%`, and a nonnegative integral `**`",
|
|
1788
|
+
"```",
|
|
1789
|
+
"; 1.408.555 + (2 + 3)",
|
|
1790
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1791
|
+
"; 1.408.555 + (2 3)",
|
|
1792
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1793
|
+
"; 1.408.555 + (7 %% 3)",
|
|
1794
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1795
|
+
"; 1.408.555 + (2 ** 3)",
|
|
1796
|
+
"# $!.numeric-domain + FrameSequence FrameCount",
|
|
1797
|
+
"```",
|
|
1798
|
+
"Negation and subtraction answer `FrameInt` whatever the sign of the result, and",
|
|
1799
|
+
"division answers a ratio, which collapses to `FrameInt` when it is whole",
|
|
1800
|
+
"```",
|
|
1801
|
+
"; 5 - 3",
|
|
1802
|
+
"# 2",
|
|
1803
|
+
"; 1.408.555 + (5 - 3)",
|
|
1804
|
+
"# $!.numeric-domain + FrameSequence FrameInt",
|
|
1805
|
+
"; 1.408.555 + -0",
|
|
1806
|
+
"# $!.numeric-domain + FrameSequence FrameInt",
|
|
1807
|
+
"; 1.408.555 + (6 / 3)",
|
|
1808
|
+
"# $!.numeric-domain + FrameSequence FrameInt",
|
|
1809
|
+
"; 7 / 2",
|
|
1810
|
+
"# 7/2",
|
|
1811
|
+
"```",
|
|
1812
|
+
"Mixed operands follow the ladder",
|
|
1813
|
+
"```",
|
|
1814
|
+
"; 1.408.555 + (2 + (0 - 3))",
|
|
1815
|
+
"# $!.numeric-domain + FrameSequence FrameInt",
|
|
1816
|
+
"; 1.408.555 + (2 * 1.5)",
|
|
1817
|
+
"# $!.numeric-domain + FrameSequence FrameDecimal",
|
|
1818
|
+
"; 7 %% (0 - 3)",
|
|
1819
|
+
"# -2",
|
|
1820
|
+
"```",
|
|
1821
|
+
"Comparison and `=` compare values across rungs, so a count and a FrameInt of the",
|
|
1822
|
+
"same value are `=`. `==`, `===` and `~~` compare exact types, so the two are",
|
|
1823
|
+
"not `==`, just as `2` and `2.0` are not",
|
|
1824
|
+
"```",
|
|
1825
|
+
"; 2 = (5 - 3)",
|
|
1826
|
+
"# <>",
|
|
1827
|
+
"; (5 - 3) = 2",
|
|
1828
|
+
"# <>",
|
|
1829
|
+
"; 2 == (5 - 3)",
|
|
1830
|
+
"# ()",
|
|
1831
|
+
"; (5 - 3) == 2",
|
|
1832
|
+
"# ()",
|
|
1833
|
+
"; 2 === (5 - 3)",
|
|
1834
|
+
"# ()",
|
|
1835
|
+
"; 2 == 2.0",
|
|
1836
|
+
"# ()",
|
|
1837
|
+
"; ~~2 (5 - 3)",
|
|
1838
|
+
"# $!.type-error ~~2 2",
|
|
1839
|
+
"; ~~(5 - 3) 2",
|
|
1840
|
+
"# $!.type-error ~~2 2",
|
|
1841
|
+
"; (0 - 1).< 0",
|
|
1842
|
+
"# <>",
|
|
1843
|
+
"; 2.<= (5 - 3)",
|
|
1844
|
+
"# <>",
|
|
1845
|
+
"; 2.< 2.5",
|
|
1846
|
+
"# <>",
|
|
1847
|
+
"```",
|
|
1848
|
+
"Within one rung, `==` and `~~` hold as they always have",
|
|
1849
|
+
"```",
|
|
1850
|
+
"; 2 == (1 + 1)",
|
|
1851
|
+
"# <>",
|
|
1852
|
+
"; (5 - 3) == (4 - 2)",
|
|
1853
|
+
"# <>",
|
|
1854
|
+
"; ~~2 3",
|
|
1855
|
+
"# 3",
|
|
1856
|
+
"; ~~(0 - 1) (0 - 5)",
|
|
1857
|
+
"# -5",
|
|
1775
1858
|
"",
|
|
1776
1859
|
].join("\n"),
|
|
1777
1860
|
],
|
|
@@ -2240,11 +2323,11 @@ export const HC_SOURCES = new Map([
|
|
|
2240
2323
|
"; %2026-08-21T00:00:00Z% + %2026-08-21T00:00:00Z%",
|
|
2241
2324
|
"# $!.numeric-domain + FrameDateTime FrameDateTime",
|
|
2242
2325
|
"; %2026-08-21% * 2",
|
|
2243
|
-
"# $!.numeric-domain * FrameDateTime
|
|
2326
|
+
"# $!.numeric-domain * FrameDateTime FrameCount",
|
|
2244
2327
|
"; %PT1H% + 1",
|
|
2245
|
-
"# $!.numeric-domain + FrameDuration
|
|
2328
|
+
"# $!.numeric-domain + FrameDuration FrameCount",
|
|
2246
2329
|
"; 1 + %PT1H%",
|
|
2247
|
-
"# $!.numeric-domain +
|
|
2330
|
+
"# $!.numeric-domain + FrameCount FrameDuration",
|
|
2248
2331
|
"```",
|
|
2249
2332
|
"Division follows the same table: an interval over a scalar is an interval, and an",
|
|
2250
2333
|
"interval over an interval is the plain number relating them",
|
|
@@ -2262,7 +2345,7 @@ export const HC_SOURCES = new Map([
|
|
|
2262
2345
|
"; %PT1H% * 1.5",
|
|
2263
2346
|
"# %PT1H30M%",
|
|
2264
2347
|
"; %PT1S% / 3",
|
|
2265
|
-
"# $!.time-inexact / FrameDuration
|
|
2348
|
+
"# $!.time-inexact / FrameDuration FrameCount",
|
|
2266
2349
|
"; (%PT1S% * 1000000000) / 1000000000",
|
|
2267
2350
|
"# %PT1S%",
|
|
2268
2351
|
"```",
|
|
@@ -2404,17 +2487,17 @@ export const HC_SOURCES = new Map([
|
|
|
2404
2487
|
"; 9.8.m.s-1 + 1.0.m.s-1",
|
|
2405
2488
|
"# $!.numeric-domain + FrameTypedNumber FrameTypedNumber",
|
|
2406
2489
|
"; 9.8.m + 1",
|
|
2407
|
-
"# $!.numeric-domain + FrameTypedNumber
|
|
2490
|
+
"# $!.numeric-domain + FrameTypedNumber FrameCount",
|
|
2408
2491
|
"; 1 + 9.8.m",
|
|
2409
|
-
"# $!.numeric-domain +
|
|
2492
|
+
"# $!.numeric-domain + FrameCount FrameTypedNumber",
|
|
2410
2493
|
"; 9.8.m 2",
|
|
2411
|
-
"# $!.numeric-domain * FrameTypedNumber
|
|
2494
|
+
"# $!.numeric-domain * FrameTypedNumber FrameCount",
|
|
2412
2495
|
"; 9.8.m / 2",
|
|
2413
|
-
"# $!.numeric-domain / FrameTypedNumber
|
|
2496
|
+
"# $!.numeric-domain / FrameTypedNumber FrameCount",
|
|
2414
2497
|
"; 9.8.m %% 2",
|
|
2415
|
-
"# $!.numeric-domain %% FrameTypedNumber
|
|
2498
|
+
"# $!.numeric-domain %% FrameTypedNumber FrameCount",
|
|
2416
2499
|
"; 9.8.m ** 2",
|
|
2417
|
-
"# $!.numeric-domain ** FrameTypedNumber
|
|
2500
|
+
"# $!.numeric-domain ** FrameTypedNumber FrameCount",
|
|
2418
2501
|
"; 9.8.m.< 10.2.m",
|
|
2419
2502
|
"# $!.numeric-domain < FrameTypedNumber FrameTypedNumber",
|
|
2420
2503
|
"; 9.8.m“Hi”",
|
|
@@ -2427,7 +2510,7 @@ export const HC_SOURCES = new Map([
|
|
|
2427
2510
|
"; 9.8.5",
|
|
2428
2511
|
"# 9.8.5",
|
|
2429
2512
|
"; 100.kg",
|
|
2430
|
-
"# $!.name-missing “$:
|
|
2513
|
+
"# $!.name-missing “$:FrameCount...",
|
|
2431
2514
|
"; (1 / 3).m",
|
|
2432
2515
|
"# $!.name-missing “$:FrameRational...",
|
|
2433
2516
|
"; (1 / 2.0).m",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Frame,
|
|
1
|
+
import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
|
|
2
2
|
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
3
3
|
import { evaluateResourceSource } from "./resource-import.js";
|
|
4
4
|
import { sigilizer } from "./sigilizer.js";
|
|
@@ -12,7 +12,8 @@ import { sigilizer } from "./sigilizer.js";
|
|
|
12
12
|
* This method iterates over the entries and determines the type of each value
|
|
13
13
|
* based on its first character:
|
|
14
14
|
* - If alphabetic, the value is wrapped in a `FrameString`.
|
|
15
|
-
* - If numeric, the value is wrapped in a `
|
|
15
|
+
* - If numeric, the value is wrapped in a `FrameCount`, as the same digits
|
|
16
|
+
* written in source would be.
|
|
16
17
|
* - If neither, an error is logged and the key is set to `Frame.nil`.
|
|
17
18
|
*
|
|
18
19
|
* If the context contains a `DEBUG_ENV` key, the context is logged to the console
|
|
@@ -32,7 +33,7 @@ export function make_context(entries) {
|
|
|
32
33
|
const context = {};
|
|
33
34
|
Object.entries(entries).forEach(([key, value]) => {
|
|
34
35
|
if (/^\p{Nd}+$/u.test(value)) {
|
|
35
|
-
context[key] =
|
|
36
|
+
context[key] = FrameCount.for(value);
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
context[key] = new FrameString(value);
|
|
@@ -27,7 +27,7 @@ export const syntaxFacets = [
|
|
|
27
27
|
frame.FrameDoc.SYNTAX,
|
|
28
28
|
frame.FrameName.SYNTAX,
|
|
29
29
|
frame.FrameScopeAnchor.SYNTAX,
|
|
30
|
-
frame.
|
|
30
|
+
frame.FrameCount.SYNTAX,
|
|
31
31
|
frame.FrameOperator.SYNTAX,
|
|
32
32
|
frame.FrameString.SYNTAX,
|
|
33
33
|
frame.FrameStringEnd.SYNTAX,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FrameCount } from "./frame-count.js";
|
|
2
2
|
import { FrameAtom } from "./frame-atom.js";
|
|
3
3
|
import { NilContext } from "./context.js";
|
|
4
4
|
import { completeAtEnd, includeOrReserve } from "./atom-syntax.js";
|
|
@@ -174,7 +174,7 @@ Object.defineProperty(FrameBlob, "SYNTAX", {
|
|
|
174
174
|
fromSource: (source) => {
|
|
175
175
|
const lexeme = `${FrameBlob.BLOB_START}${source}`;
|
|
176
176
|
return /^\d+$/.test(lexeme)
|
|
177
|
-
?
|
|
177
|
+
? FrameCount.for(lexeme)
|
|
178
178
|
: new FrameBlob(lexeme);
|
|
179
179
|
},
|
|
180
180
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { completeAtEnd, includeOrReserve } from "./atom-syntax.js";
|
|
2
|
+
import { NilContext } from "./context.js";
|
|
3
|
+
import { FrameInt } from "./frame-int.js";
|
|
4
|
+
import { NUMERIC_RANK, } from "./frame-numeric.js";
|
|
5
|
+
/**
|
|
6
|
+
* Exact nonnegative integer, the root of the numeric ladder, and owner of
|
|
7
|
+
* decimal-digit source syntax: every digit literal is a count, `0` and
|
|
8
|
+
* `1234567890` alike.
|
|
9
|
+
*
|
|
10
|
+
* A count is a FrameInt that cannot be negative, so whatever accepts an integer
|
|
11
|
+
* accepts a count, and it prints exactly as the same integer does. It is closed
|
|
12
|
+
* under `+`, `*`, `%%`, and a nonnegative integral `**`, which therefore answer
|
|
13
|
+
* counts. The operations that can leave the domain answer the rung that holds
|
|
14
|
+
* their result whatever its sign: unary minus and `-` answer a FrameInt, and
|
|
15
|
+
* `/` answers a ratio, which collapses to a FrameInt when it is whole.
|
|
16
|
+
*/
|
|
17
|
+
export class FrameCount extends FrameInt {
|
|
18
|
+
static for(source) {
|
|
19
|
+
return new FrameCount(source);
|
|
20
|
+
}
|
|
21
|
+
constructor(source, meta = NilContext, spelling) {
|
|
22
|
+
super(source, meta, spelling);
|
|
23
|
+
Object.defineProperty(this, "rank", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: NUMERIC_RANK.count
|
|
28
|
+
});
|
|
29
|
+
if (this.data < 0n || this.spelling.startsWith("-")) {
|
|
30
|
+
throw new RangeError(`count must not be negative: ${this.spelling}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
promoteOne() {
|
|
34
|
+
return new FrameInt(this.data);
|
|
35
|
+
}
|
|
36
|
+
sameRung(value) {
|
|
37
|
+
return new FrameCount(value);
|
|
38
|
+
}
|
|
39
|
+
unaryPlus() {
|
|
40
|
+
return this.spelling.startsWith("+")
|
|
41
|
+
? this
|
|
42
|
+
: new FrameCount(this.data, NilContext, `+${this.spelling}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(FrameCount, "SIGIL_STARTS", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: [
|
|
50
|
+
{ key: FrameCount.NUMBER_BEGIN.toString(), mode: "atom" },
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(FrameCount, "SYNTAX", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: {
|
|
58
|
+
NAME: "FrameCount",
|
|
59
|
+
SIGIL_STARTS: FrameCount.SIGIL_STARTS,
|
|
60
|
+
recognize: (symbol, source = "") => {
|
|
61
|
+
const char = symbol.toString();
|
|
62
|
+
return includeOrReserve(char, FrameCount.NUMBER_CHAR.test(char), source);
|
|
63
|
+
},
|
|
64
|
+
finish: completeAtEnd,
|
|
65
|
+
fromSource: (source) => FrameCount.for(source),
|
|
66
|
+
}
|
|
67
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NilContext } from "./context.js";
|
|
2
2
|
import { Frame } from "./frame.js";
|
|
3
|
-
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, projectBigIntRatio, } from "./frame-numeric.js";
|
|
3
|
+
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, NUMERIC_RANK, projectBigIntRatio, } from "./frame-numeric.js";
|
|
4
4
|
import { FrameNumber } from "./frame-number.js";
|
|
5
5
|
import { FrameRational } from "./frame-rational.js";
|
|
6
6
|
import { FrameSequence } from "./frame-sequence.js";
|
|
@@ -32,7 +32,7 @@ export class FrameDecimal extends FrameNumeric {
|
|
|
32
32
|
enumerable: true,
|
|
33
33
|
configurable: true,
|
|
34
34
|
writable: true,
|
|
35
|
-
value:
|
|
35
|
+
value: NUMERIC_RANK.decimal
|
|
36
36
|
});
|
|
37
37
|
Object.defineProperty(this, "numerator", {
|
|
38
38
|
enumerable: true,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { completeAtEnd, includeOrReserve } from "./atom-syntax.js";
|
|
2
1
|
import { NilContext } from "./context.js";
|
|
3
2
|
import { FrameDecimal } from "./frame-decimal.js";
|
|
4
3
|
import { Frame } from "./frame.js";
|
|
5
|
-
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, REPETITION_LIMIT, REPETITION_TEXT_LIMIT, } from "./frame-numeric.js";
|
|
4
|
+
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, NUMERIC_RANK, REPETITION_LIMIT, REPETITION_TEXT_LIMIT, } from "./frame-numeric.js";
|
|
6
5
|
import { hasCharacterContent } from "./frame-text.js";
|
|
7
6
|
import { FrameNumber } from "./frame-number.js";
|
|
8
7
|
const INTEGER_SOURCE = /^[+-]?[\p{Nd}]+$/u;
|
|
@@ -22,7 +21,13 @@ function normalizeDecimalDigits(source) {
|
|
|
22
21
|
return ((codePoint - blockStart) % 10).toString();
|
|
23
22
|
}).join("");
|
|
24
23
|
}
|
|
25
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Exact bigint-backed signed integer.
|
|
26
|
+
*
|
|
27
|
+
* No literal produces one: the digits a source spells are a `FrameCount`, which
|
|
28
|
+
* owns that syntax. A FrameInt is what an operation answers once its result may
|
|
29
|
+
* be negative, such as unary minus or subtraction.
|
|
30
|
+
*/
|
|
26
31
|
export class FrameInt extends FrameNumeric {
|
|
27
32
|
static for(source) {
|
|
28
33
|
return new FrameInt(source);
|
|
@@ -33,7 +38,7 @@ export class FrameInt extends FrameNumeric {
|
|
|
33
38
|
enumerable: true,
|
|
34
39
|
configurable: true,
|
|
35
40
|
writable: true,
|
|
36
|
-
value:
|
|
41
|
+
value: NUMERIC_RANK.int
|
|
37
42
|
});
|
|
38
43
|
Object.defineProperty(this, "data", {
|
|
39
44
|
enumerable: true,
|
|
@@ -119,22 +124,31 @@ export class FrameInt extends FrameNumeric {
|
|
|
119
124
|
const spelling = this.spelling.startsWith("-") ? unsigned : `-${unsigned}`;
|
|
120
125
|
return new FrameInt(-this.data, NilContext, spelling);
|
|
121
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* The integer `value` on this frame's own rung, for the operations every
|
|
129
|
+
* integer rung is closed under: `+`, `*`, `%%`, and a nonnegative integral
|
|
130
|
+
* `**`. A count is not closed under `-`, which is why subtraction builds a
|
|
131
|
+
* FrameInt rather than asking here.
|
|
132
|
+
*/
|
|
133
|
+
sameRung(value) {
|
|
134
|
+
return new FrameInt(value);
|
|
135
|
+
}
|
|
122
136
|
addSame(right) {
|
|
123
|
-
return
|
|
137
|
+
return this.sameRung(this.data + right.data);
|
|
124
138
|
}
|
|
125
139
|
subtractSame(right) {
|
|
126
140
|
return new FrameInt(this.data - right.data);
|
|
127
141
|
}
|
|
128
142
|
multiplySame(right) {
|
|
129
|
-
return
|
|
143
|
+
return this.sameRung(this.data * right.data);
|
|
130
144
|
}
|
|
131
145
|
divideSame(_right) {
|
|
132
|
-
return Frame.error(
|
|
146
|
+
return Frame.error(`$!.numeric-internal / ${this.className()}`);
|
|
133
147
|
}
|
|
134
148
|
moduloSame(right) {
|
|
135
149
|
const divisor = right.data;
|
|
136
150
|
const remainder = this.data % divisor;
|
|
137
|
-
return
|
|
151
|
+
return this.sameRung(remainder !== 0n && (remainder < 0n) !== (divisor < 0n)
|
|
138
152
|
? remainder + divisor
|
|
139
153
|
: remainder);
|
|
140
154
|
}
|
|
@@ -144,12 +158,12 @@ export class FrameInt extends FrameNumeric {
|
|
|
144
158
|
}
|
|
145
159
|
powerIntegral(exponent) {
|
|
146
160
|
if (exponent < 0n) {
|
|
147
|
-
return Frame.error(
|
|
161
|
+
return Frame.error(`$!.numeric-internal ** ${this.className()}`);
|
|
148
162
|
}
|
|
149
163
|
if (!exactPowerWithinLimit([this.data], exponent)) {
|
|
150
|
-
return Frame.error(
|
|
164
|
+
return Frame.error(`$!.numeric-range ** ${this.className()}`);
|
|
151
165
|
}
|
|
152
|
-
return
|
|
166
|
+
return this.sameRung(exactBigIntPower(this.data, exponent));
|
|
153
167
|
}
|
|
154
168
|
compareSame(right) {
|
|
155
169
|
const value = right.data;
|
|
@@ -183,26 +197,3 @@ Object.defineProperty(FrameInt, "NUMBER_CHAR", {
|
|
|
183
197
|
writable: true,
|
|
184
198
|
value: /\d/
|
|
185
199
|
});
|
|
186
|
-
Object.defineProperty(FrameInt, "SIGIL_STARTS", {
|
|
187
|
-
enumerable: true,
|
|
188
|
-
configurable: true,
|
|
189
|
-
writable: true,
|
|
190
|
-
value: [
|
|
191
|
-
{ key: FrameInt.NUMBER_BEGIN.toString(), mode: "atom" },
|
|
192
|
-
]
|
|
193
|
-
});
|
|
194
|
-
Object.defineProperty(FrameInt, "SYNTAX", {
|
|
195
|
-
enumerable: true,
|
|
196
|
-
configurable: true,
|
|
197
|
-
writable: true,
|
|
198
|
-
value: {
|
|
199
|
-
NAME: "FrameInt",
|
|
200
|
-
SIGIL_STARTS: FrameInt.SIGIL_STARTS,
|
|
201
|
-
recognize: (symbol, source = "") => {
|
|
202
|
-
const char = symbol.toString();
|
|
203
|
-
return includeOrReserve(char, FrameInt.NUMBER_CHAR.test(char), source);
|
|
204
|
-
},
|
|
205
|
-
finish: completeAtEnd,
|
|
206
|
-
fromSource: (source) => FrameInt.for(source),
|
|
207
|
-
}
|
|
208
|
-
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NilContext } from "./context.js";
|
|
2
|
-
import { FrameNumeric } from "./frame-numeric.js";
|
|
2
|
+
import { FrameNumeric, NUMERIC_RANK, } from "./frame-numeric.js";
|
|
3
3
|
/** Inexact host-number rung, reached only by projection or inexact arithmetic. */
|
|
4
4
|
export class FrameNumber extends FrameNumeric {
|
|
5
5
|
static for(value) {
|
|
@@ -16,7 +16,7 @@ export class FrameNumber extends FrameNumeric {
|
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true,
|
|
19
|
-
value:
|
|
19
|
+
value: NUMERIC_RANK.number
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(this, "data", {
|
|
22
22
|
enumerable: true,
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { FrameAtom } from "./frame-atom.js";
|
|
2
2
|
import { Frame } from "./frame.js";
|
|
3
|
+
/**
|
|
4
|
+
* The promotion ladder, root first: a rung's rank is its position here. The
|
|
5
|
+
* dispatch below names rungs only through this table, so a rung inserted below
|
|
6
|
+
* the root, such as a future `FrameBit`, renumbers this table and nothing else.
|
|
7
|
+
*/
|
|
8
|
+
export const NUMERIC_RANK = {
|
|
9
|
+
count: 0,
|
|
10
|
+
int: 1,
|
|
11
|
+
decimal: 2,
|
|
12
|
+
rational: 3,
|
|
13
|
+
number: 4,
|
|
14
|
+
};
|
|
3
15
|
/** The largest count accepted by integer repetition. */
|
|
4
16
|
export const REPETITION_LIMIT = 65536n;
|
|
5
17
|
/** The largest UTF-16 text result accepted by integer repetition. */
|
|
@@ -82,13 +94,15 @@ export class FrameNumeric extends FrameAtom {
|
|
|
82
94
|
}
|
|
83
95
|
if (right.isZero())
|
|
84
96
|
return Frame.error("$!.division-by-zero /");
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
const { decimal, number, rational } = NUMERIC_RANK;
|
|
98
|
+
// Never below the rational rung: an exact quotient is a ratio, and one
|
|
99
|
+
// whose denominator reduces to 1 collapses to FrameInt, never to a count.
|
|
100
|
+
const target = this.rank === number || right.rank === decimal || right.rank === number
|
|
101
|
+
? number
|
|
102
|
+
: rational;
|
|
103
|
+
if (target === number && this.rank !== number && right.rank !== number) {
|
|
104
|
+
const projectedLeft = this.promoteTo(number);
|
|
105
|
+
const projectedRight = right.promoteTo(number);
|
|
92
106
|
const leftValue = Number(projectedLeft.valueOf());
|
|
93
107
|
const rightValue = Number(projectedRight.valueOf());
|
|
94
108
|
if (Number.isFinite(leftValue) && Number.isFinite(rightValue) &&
|
|
@@ -105,13 +119,16 @@ export class FrameNumeric extends FrameAtom {
|
|
|
105
119
|
}
|
|
106
120
|
return this.promoteTo(target).divideSame(right.promoteTo(target));
|
|
107
121
|
}
|
|
122
|
+
/** Integer rungs only, joined like `+`, so two counts answer a count. */
|
|
108
123
|
modulo(right) {
|
|
109
|
-
if (this.rank
|
|
124
|
+
if (this.rank == null || right.rank == null ||
|
|
125
|
+
this.rank > NUMERIC_RANK.int || right.rank > NUMERIC_RANK.int) {
|
|
110
126
|
return this.operationError("%%", right);
|
|
111
127
|
}
|
|
112
128
|
if (right.isZero())
|
|
113
129
|
return Frame.error("$!.modulo-by-zero %%");
|
|
114
|
-
|
|
130
|
+
const target = Math.max(this.rank, right.rank);
|
|
131
|
+
return this.promoteTo(target).moduloSame(right.promoteTo(target));
|
|
115
132
|
}
|
|
116
133
|
power(right) {
|
|
117
134
|
if (this.rank == null || right.rank == null) {
|
|
@@ -119,15 +136,15 @@ export class FrameNumeric extends FrameAtom {
|
|
|
119
136
|
}
|
|
120
137
|
const exponent = right.integralValue();
|
|
121
138
|
if (exponent == null) {
|
|
122
|
-
const leftNumber = this.promoteTo(
|
|
123
|
-
const rightNumber = right.promoteTo(
|
|
139
|
+
const leftNumber = this.promoteTo(NUMERIC_RANK.number);
|
|
140
|
+
const rightNumber = right.promoteTo(NUMERIC_RANK.number);
|
|
124
141
|
return leftNumber.powerSame(rightNumber);
|
|
125
142
|
}
|
|
126
143
|
if (exponent < 0n && this.isZero()) {
|
|
127
144
|
return Frame.error("$!.division-by-zero **");
|
|
128
145
|
}
|
|
129
|
-
if (exponent < 0n && this.rank !==
|
|
130
|
-
return this.promoteTo(
|
|
146
|
+
if (exponent < 0n && this.rank !== NUMERIC_RANK.number) {
|
|
147
|
+
return this.promoteTo(NUMERIC_RANK.rational).powerIntegral(exponent);
|
|
131
148
|
}
|
|
132
149
|
return this.powerIntegral(exponent);
|
|
133
150
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NilContext } from "./context.js";
|
|
2
2
|
import { FrameInt } from "./frame-int.js";
|
|
3
3
|
import { Frame } from "./frame.js";
|
|
4
|
-
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, projectBigIntRatio, } from "./frame-numeric.js";
|
|
4
|
+
import { exactBigIntPower, exactPowerWithinLimit, FrameNumeric, NUMERIC_RANK, projectBigIntRatio, } from "./frame-numeric.js";
|
|
5
5
|
import { FrameNumber } from "./frame-number.js";
|
|
6
6
|
function greatestCommonDivisor(left, right) {
|
|
7
7
|
let a = left < 0n ? -left : left;
|
|
@@ -13,6 +13,7 @@ function greatestCommonDivisor(left, right) {
|
|
|
13
13
|
}
|
|
14
14
|
/** Reduced exact ratio with a positive denominator. */
|
|
15
15
|
export class FrameRational extends FrameNumeric {
|
|
16
|
+
/** A whole result collapses to FrameInt, never to a count, whatever its sign. */
|
|
16
17
|
static create(numerator, denominator) {
|
|
17
18
|
if (denominator === 0n)
|
|
18
19
|
return Frame.error("$!.division-by-zero /");
|
|
@@ -27,7 +28,7 @@ export class FrameRational extends FrameNumeric {
|
|
|
27
28
|
enumerable: true,
|
|
28
29
|
configurable: true,
|
|
29
30
|
writable: true,
|
|
30
|
-
value:
|
|
31
|
+
value: NUMERIC_RANK.rational
|
|
31
32
|
});
|
|
32
33
|
Object.defineProperty(this, "numerator", {
|
|
33
34
|
enumerable: true,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* @module
|
|
23
23
|
*/
|
|
24
24
|
import { Frame } from "./frame.js";
|
|
25
|
-
import {
|
|
25
|
+
import { FrameCount } from "./frame-count.js";
|
|
26
26
|
import { FrameString } from "./frame-string.js";
|
|
27
27
|
import { FrameURI } from "./frame-uri.js";
|
|
28
28
|
import { hasCharacterContent } from "./frame-text.js";
|
|
@@ -107,12 +107,12 @@ export class FrameResource extends FrameURI {
|
|
|
107
107
|
if (placement.kind === "scheme") {
|
|
108
108
|
const written = placement.handler.write(placement.parts, content);
|
|
109
109
|
return written.ok
|
|
110
|
-
?
|
|
110
|
+
? FrameCount.for(written.count.toString())
|
|
111
111
|
: this.storeRefusal(written.reason);
|
|
112
112
|
}
|
|
113
113
|
const written = this.store.write(placement.path, content);
|
|
114
114
|
return written.ok
|
|
115
|
-
?
|
|
115
|
+
? FrameCount.for(written.content.length.toString())
|
|
116
116
|
: this.storeRefusal(written.reason);
|
|
117
117
|
}
|
|
118
118
|
/**
|
package/esm/lib/frames.js
CHANGED
|
@@ -22,8 +22,9 @@ export { FrameList } from "./frames/frame-list.js";
|
|
|
22
22
|
export { FrameName } from "./frames/frame-name.js";
|
|
23
23
|
export { FrameNote } from "./frames/frame-note.js";
|
|
24
24
|
export { FrameScopeAnchor, } from "./frames/frame-scope-anchor.js";
|
|
25
|
-
export { FrameNumeric } from "./frames/frame-numeric.js";
|
|
25
|
+
export { FrameNumeric, NUMERIC_RANK, } from "./frames/frame-numeric.js";
|
|
26
26
|
export { FrameInt } from "./frames/frame-int.js";
|
|
27
|
+
export { FrameCount } from "./frames/frame-count.js";
|
|
27
28
|
export { FrameDecimal } from "./frames/frame-decimal.js";
|
|
28
29
|
export { FrameSequence } from "./frames/frame-sequence.js";
|
|
29
30
|
export { FrameTypedNumber } from "./frames/frame-typed-number.js";
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.21.0";
|