hclang 0.48.0 → 0.49.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 +501 -374
- package/esm/lib/execute/{demi-prologue.js → denum-prologue.js} +29 -29
- package/esm/lib/execute/hc-eval.js +2 -2
- package/esm/lib/execute/resource-import.js +1 -1
- package/esm/lib/execute/router-prologue.js +2 -2
- package/esm/lib/frames/fourth-hash.js +101 -40
- package/esm/lib/frames/frame-array.js +2 -2
- package/esm/lib/frames/frame-lazy.js +1 -1
- package/esm/lib/frames/frame-name.js +10 -2
- package/esm/lib/frames/frame.js +23 -8
- package/esm/lib/frames.js +1 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The Denum class, loaded from HC for the fourth hash.
|
|
3
3
|
*
|
|
4
|
-
* `.####` answers a
|
|
4
|
+
* `.####` answers a Denum, and a Denum is an HC class, `Denum` in `hc/denum.hc`,
|
|
5
5
|
* not a native one (occurrence/figure 011.20). The frames package derives the
|
|
6
6
|
* Count and loads natively but cannot run HC, so this module installs the
|
|
7
|
-
* constructor it calls (`
|
|
7
|
+
* constructor it calls (`installDenumConstructor`).
|
|
8
8
|
*
|
|
9
9
|
* The class is read from the compiled-in bundle, not through a resource root,
|
|
10
10
|
* so `.####` works in a bare `evaluate`, which has no root and imports nothing.
|
|
11
|
-
* The file is evaluated the first time a
|
|
11
|
+
* The file is evaluated the first time a Denum is constructed, once per
|
|
12
12
|
* process, the way an import evaluates a testdoc: its example lines are
|
|
13
13
|
* dropped and the first failure fails the whole. It runs in a namespace of its
|
|
14
14
|
* own, with no host bindings and no root, so it can read nothing but the
|
|
15
15
|
* global operators, and nothing a program declares can reach it. Its outcome
|
|
16
|
-
* is kept, failure included, so it is never evaluated twice. A
|
|
17
|
-
* while the file is still loading is `$!.
|
|
16
|
+
* is kept, failure included, so it is never evaluated twice. A Denum requested
|
|
17
|
+
* while the file is still loading is `$!.denum-prologue-reentrant`, because
|
|
18
18
|
* the class cannot be defined by itself.
|
|
19
19
|
*
|
|
20
20
|
* What stays native is only what HC cannot say: reading `#`, `##` and `###`
|
|
21
21
|
* in a fixed order with their absence and error rules, and checking that the
|
|
22
|
-
* loads are whole. Everything a
|
|
22
|
+
* loads are whole. Everything a Denum does is in the HC source.
|
|
23
23
|
*
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
|
-
import { EvaluationScope, Frame, FrameArray, FrameExpr,
|
|
26
|
+
import { EvaluationScope, Frame, FrameArray, FrameExpr, installDenumConstructor, } from "../frames.js";
|
|
27
27
|
import { HC_SOURCES } from "../bundle/hc-sources.js";
|
|
28
28
|
import { evaluateSourceText } from "./resource-import.js";
|
|
29
29
|
/** The bundled file that defines the class. */
|
|
30
|
-
export const
|
|
30
|
+
export const DENUM_SOURCE = "hc/denum.hc";
|
|
31
31
|
/** The name the file declares the constructor under. */
|
|
32
|
-
export const
|
|
32
|
+
export const DENUM_CLASS = "Denum";
|
|
33
33
|
let loaded;
|
|
34
34
|
let loading = false;
|
|
35
35
|
/**
|
|
36
36
|
* Evaluates class source in a namespace of its own, with no host bindings and
|
|
37
|
-
* no root, answering its `
|
|
37
|
+
* no root, answering its `Denum` or the failure. Uncached: `denumClass` keeps
|
|
38
38
|
* the one result the process uses.
|
|
39
39
|
*
|
|
40
40
|
* @param source The source text, or undefined when the bundle lacks it.
|
|
41
41
|
* @returns The constructor, or an error.
|
|
42
42
|
*/
|
|
43
|
-
export function
|
|
43
|
+
export function loadDenumClass(source) {
|
|
44
44
|
if (source === undefined) {
|
|
45
|
-
return Frame.error(`$!.
|
|
45
|
+
return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
|
|
46
46
|
}
|
|
47
47
|
const namespace = new FrameArray([]);
|
|
48
48
|
const result = evaluateSourceText(source, EvaluationScope.root(namespace));
|
|
49
49
|
if (result.isFailedResult() || result.observationError())
|
|
50
50
|
return result;
|
|
51
|
-
const constructor = namespace.getOwn(
|
|
51
|
+
const constructor = namespace.getOwn(DENUM_CLASS);
|
|
52
52
|
return constructor.is.missing
|
|
53
|
-
? Frame.error(`$!.
|
|
53
|
+
? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
|
|
54
54
|
: constructor;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* The `
|
|
57
|
+
* The `Denum` constructor closure, evaluated from the bundle on first use.
|
|
58
58
|
*
|
|
59
59
|
* @returns The constructor, or the error that loading it answered.
|
|
60
60
|
*/
|
|
61
|
-
export function
|
|
61
|
+
export function denumClass() {
|
|
62
62
|
if (loaded)
|
|
63
63
|
return loaded;
|
|
64
64
|
if (loading)
|
|
65
|
-
return Frame.error("$!.
|
|
65
|
+
return Frame.error("$!.denum-prologue-reentrant");
|
|
66
66
|
loading = true;
|
|
67
67
|
try {
|
|
68
|
-
loaded =
|
|
68
|
+
loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
|
|
69
69
|
}
|
|
70
70
|
finally {
|
|
71
71
|
loading = false;
|
|
@@ -73,16 +73,16 @@ export function demiClass() {
|
|
|
73
73
|
return loaded;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Constructs a
|
|
77
|
-
* Two loads give the binary
|
|
78
|
-
* right]` builds; any other nonzero number gives the channel
|
|
76
|
+
* Constructs a Denum of any arity with the HC class: `Denum [count, loads]`.
|
|
77
|
+
* Two loads give the binary Denum, the same instance `Denum [count, left,
|
|
78
|
+
* right]` builds; any other nonzero number gives the channel Denum (007.27).
|
|
79
79
|
*
|
|
80
80
|
* @param count The full application Count.
|
|
81
81
|
* @param loads The ordered channel loads.
|
|
82
82
|
* @returns The new instance, or the class's failure.
|
|
83
83
|
*/
|
|
84
|
-
export function
|
|
85
|
-
const constructor =
|
|
84
|
+
export function constructDenumLoads(count, loads) {
|
|
85
|
+
const constructor = denumClass();
|
|
86
86
|
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
87
87
|
return constructor;
|
|
88
88
|
}
|
|
@@ -90,14 +90,14 @@ export function constructDemiLoads(count, loads) {
|
|
|
90
90
|
return FrameExpr.answeredValue(constructor.call(state)).referent();
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* Constructs a binary
|
|
93
|
+
* Constructs a binary Denum with the HC class: `Denum [count, left, right]`.
|
|
94
94
|
*
|
|
95
|
-
* @param count The full application Count; the
|
|
95
|
+
* @param count The full application Count; the Denum derives its phase from it.
|
|
96
96
|
* @param left The left load.
|
|
97
97
|
* @param right The right load.
|
|
98
98
|
* @returns The new instance, or the class's failure.
|
|
99
99
|
*/
|
|
100
|
-
export function
|
|
101
|
-
return
|
|
100
|
+
export function constructDenum(count, left, right) {
|
|
101
|
+
return constructDenumLoads(count, [left, right]);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
installDenumConstructor(constructDenumLoads);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
|
|
2
|
-
// Installs the
|
|
3
|
-
import "./
|
|
2
|
+
// Installs the Denum class that `.####` constructs (011.20).
|
|
3
|
+
import "./denum-prologue.js";
|
|
4
4
|
// Installs the RotorRouter class that list division answers (007.27c).
|
|
5
5
|
import "./router-prologue.js";
|
|
6
6
|
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
@@ -126,7 +126,7 @@ function evaluateResourceSourceWithChain(resource, scope, activeImports) {
|
|
|
126
126
|
* Evaluates HC source text as an import would: example lines dropped, the first
|
|
127
127
|
* failed form failing the whole, and the last answer returned. Declarations
|
|
128
128
|
* land in the scope's write target. Used for source the program carries rather
|
|
129
|
-
* than reads, such as the
|
|
129
|
+
* than reads, such as the Denum class (`denum-prologue.ts`).
|
|
130
130
|
*
|
|
131
131
|
* @param source The source text.
|
|
132
132
|
* @param scope The scope it evaluates in.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* HC, so this module installs the constructor it calls
|
|
9
9
|
* (`installDivisionCarrier`).
|
|
10
10
|
*
|
|
11
|
-
* As with the
|
|
11
|
+
* As with the Denum class (`denum-prologue.ts`), the class is read from the
|
|
12
12
|
* compiled-in bundle, evaluated once per process on first use, in a namespace
|
|
13
13
|
* of its own with no host bindings and no root, and its outcome is kept,
|
|
14
14
|
* failure included. A division requested while the file is still loading is
|
|
@@ -97,7 +97,7 @@ export function constructRouter(channels) {
|
|
|
97
97
|
* The channels of an instance of the shipped class with other than two
|
|
98
98
|
* channels, for `.####` (007.27); undefined for anything else.
|
|
99
99
|
*
|
|
100
|
-
* Recognition mirrors the
|
|
100
|
+
* Recognition mirrors the Denum's (007.25e): the source's own stored
|
|
101
101
|
* `channels`, a list of arrays, must rebuild through the constructor into a
|
|
102
102
|
* router `==` to the source, fields and methods included. Nothing of the
|
|
103
103
|
* source runs, so a record that only spells `channels` is not a router.
|
|
@@ -3,13 +3,13 @@ import { FrameCount } from "./frame-count.js";
|
|
|
3
3
|
import { FrameInt } from "./frame-int.js";
|
|
4
4
|
let construct;
|
|
5
5
|
/**
|
|
6
|
-
* Installs what `.####` answers a present
|
|
7
|
-
* `
|
|
8
|
-
* its constructor from the evaluator (`lib/execute/
|
|
6
|
+
* Installs what `.####` answers a present Denum with. The Denum is an HC class,
|
|
7
|
+
* `Denum` in `hc/denum.hc`, so the frames package, which cannot run HC, takes
|
|
8
|
+
* its constructor from the evaluator (`lib/execute/denum-prologue.ts`).
|
|
9
9
|
*
|
|
10
10
|
* @param constructor The constructor, called once per present observation.
|
|
11
11
|
*/
|
|
12
|
-
export function
|
|
12
|
+
export function installDenumConstructor(constructor) {
|
|
13
13
|
construct = constructor;
|
|
14
14
|
}
|
|
15
15
|
let recognizeRouter;
|
|
@@ -30,7 +30,7 @@ function exactCount(frame) {
|
|
|
30
30
|
: undefined;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* The stored loads of a
|
|
33
|
+
* The stored loads of a Denum instance: its own `loads` field, a nonempty list
|
|
34
34
|
* whose elements are all exact Counts, or undefined.
|
|
35
35
|
*
|
|
36
36
|
* Only the instance's own field is read (`get_here`), never a declared parent
|
|
@@ -49,17 +49,17 @@ function storedLoads(source) {
|
|
|
49
49
|
: undefined;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* The intrinsic
|
|
53
|
-
* fourth hash the three observers cannot decide: `
|
|
52
|
+
* The intrinsic Denum path (007.25e). A constructed Denum is the one Frame whose
|
|
53
|
+
* fourth hash the three observers cannot decide: `Denum [0, 0, 0]` reads 0, 0,
|
|
54
54
|
* 0, exactly as `[]` does, yet it is a present state. Rather than let any
|
|
55
55
|
* class declare its own `.####`, the fourth hash recognizes an instance of the
|
|
56
56
|
* shipped class itself, and nothing else.
|
|
57
57
|
*
|
|
58
|
-
* A source is a
|
|
58
|
+
* A source is a Denum exactly when it has a stored Count `count` and a stored
|
|
59
59
|
* nonempty list of Counts `loads`, and it is `==` (same value and same type at
|
|
60
|
-
* every node, fields and methods included) to the
|
|
61
|
-
* builds from them. A
|
|
62
|
-
*
|
|
60
|
+
* every node, fields and methods included) to the Denum the shipped constructor
|
|
61
|
+
* builds from them. A Denum stores nothing else (007.40), and the comparison
|
|
62
|
+
* covers its methods too. The answer is then that fresh reconstruction, of
|
|
63
63
|
* the source's own arity, never the source
|
|
64
64
|
* and never anything the source computed. No observer, method or closure of
|
|
65
65
|
* the source runs, so a forged `#`, `##`, `###` or `####` cannot steer it, and
|
|
@@ -69,9 +69,17 @@ function storedLoads(source) {
|
|
|
69
69
|
* other Frame.
|
|
70
70
|
*
|
|
71
71
|
* @param source The observed Frame.
|
|
72
|
-
* @returns A fresh
|
|
72
|
+
* @returns A fresh Denum equal to the source, or undefined.
|
|
73
73
|
*/
|
|
74
|
-
function
|
|
74
|
+
function intrinsicDenum(source) {
|
|
75
|
+
return recognizeDenum(source)?.denum;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Recognizes an instance of the shipped Denum class exactly as
|
|
79
|
+
* `intrinsicDenum` documents, answering its reconstruction together with the
|
|
80
|
+
* stored Count and loads it was rebuilt from, or undefined.
|
|
81
|
+
*/
|
|
82
|
+
function recognizeDenum(source) {
|
|
75
83
|
if (!construct)
|
|
76
84
|
return undefined;
|
|
77
85
|
const host = source.referent();
|
|
@@ -85,27 +93,79 @@ function intrinsicDemi(source) {
|
|
|
85
93
|
if (candidate.isFailedResult() || candidate.observationError()) {
|
|
86
94
|
return undefined;
|
|
87
95
|
}
|
|
88
|
-
return candidate.typeEquals(host) === Frame.all
|
|
96
|
+
return candidate.typeEquals(host) === Frame.all
|
|
97
|
+
? {
|
|
98
|
+
denum: candidate,
|
|
99
|
+
count: count.data,
|
|
100
|
+
loads: loads.map((load) => load.data),
|
|
101
|
+
}
|
|
102
|
+
: undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The most loads `.#%` materializes. The Count is exact and unbounded, but the
|
|
106
|
+
* bound Denum holds C loads, so a Count above this is refused with
|
|
107
|
+
* `$!.denum-binding-capacity` rather than allocated, truncated or converted.
|
|
108
|
+
*/
|
|
109
|
+
export const DENUM_BINDING_CAPACITY = 65536n;
|
|
110
|
+
/**
|
|
111
|
+
* Count binding, `d.#%` (occurrence/figure 007.39a, 007.40). For a Denum
|
|
112
|
+
* `d = (C; [a0, …, a(A−1)])` with C > 0 it answers the new Denum
|
|
113
|
+
* `(C; [b0, …, b(C−1)])`, where `bj` is the sum of every `ai` with
|
|
114
|
+
* `i mod C = j`: fewer loads than C are copied and zero-filled, exactly C are
|
|
115
|
+
* kept, and more fold onto the first C by index. The Count, the total Size
|
|
116
|
+
* and nonnegativity are kept, the arity becomes C, and binding is idempotent.
|
|
117
|
+
* It is not a rank and allocates no geometry.
|
|
118
|
+
*
|
|
119
|
+
* Only a genuine Denum is bound, recognized as `.####` recognizes it, so
|
|
120
|
+
* nothing of the receiver runs. In order: a failed receiver is answered as it
|
|
121
|
+
* is; anything that is not a Denum is `$!.denum-binding-receiver`; Count zero
|
|
122
|
+
* is `$!.denum-binding-zero-count`, since there is no channel to bind into;
|
|
123
|
+
* and a Count above `DENUM_BINDING_CAPACITY` is `$!.denum-binding-capacity`.
|
|
124
|
+
* The receiver is never changed.
|
|
125
|
+
*
|
|
126
|
+
* @param source The observed Frame.
|
|
127
|
+
* @returns The bound Denum, or an error.
|
|
128
|
+
*/
|
|
129
|
+
export function bindDenumCount(source) {
|
|
130
|
+
const failure = source.observationError();
|
|
131
|
+
if (failure)
|
|
132
|
+
return failure;
|
|
133
|
+
if (!construct)
|
|
134
|
+
return Frame.error("$!.denum-unavailable");
|
|
135
|
+
const state = recognizeDenum(source);
|
|
136
|
+
if (!state)
|
|
137
|
+
return Frame.error("$!.denum-binding-receiver");
|
|
138
|
+
if (state.count === 0n)
|
|
139
|
+
return Frame.error("$!.denum-binding-zero-count");
|
|
140
|
+
if (state.count > DENUM_BINDING_CAPACITY) {
|
|
141
|
+
return Frame.error("$!.denum-binding-capacity");
|
|
142
|
+
}
|
|
143
|
+
const arity = Number(state.count);
|
|
144
|
+
const bound = new Array(arity).fill(0n);
|
|
145
|
+
state.loads.forEach((load, index) => {
|
|
146
|
+
bound[index % arity] += load;
|
|
147
|
+
});
|
|
148
|
+
return construct(new FrameCount(state.count), bound.map((load) => new FrameCount(load)));
|
|
89
149
|
}
|
|
90
150
|
/**
|
|
91
151
|
* The channel-router path (007.27). A router of k channels routes to channel
|
|
92
|
-
* C mod k, which only a
|
|
152
|
+
* C mod k, which only a Denum of k loads follows; the binary Denum the observers
|
|
93
153
|
* derive follows parity, so for k other than two it would not be the router's
|
|
94
154
|
* shadow. An instance of the shipped `RotorRouter` class with other than two
|
|
95
|
-
* channels therefore answers the channel
|
|
96
|
-
* `
|
|
155
|
+
* channels therefore answers the channel Denum of its Count and channel loads,
|
|
156
|
+
* `Denum [C, [load0, …]]`, where a load is the summed Size of a channel's
|
|
97
157
|
* children and an empty channel's load is 0. The binary router keeps the
|
|
98
|
-
* derived path, which already answers `
|
|
158
|
+
* derived path, which already answers `Denum(C, L, R)`.
|
|
99
159
|
*
|
|
100
|
-
* Its Count is the children it holds; at Count zero it has no
|
|
160
|
+
* Its Count is the children it holds; at Count zero it has no Denum, as the
|
|
101
161
|
* empty binary router and the empty host have none. Each child's Size is read
|
|
102
162
|
* once, and a failed Size is answered as it is.
|
|
103
163
|
*
|
|
104
164
|
* @param source The observed Frame.
|
|
105
|
-
* @returns The router's channel
|
|
165
|
+
* @returns The router's channel Denum, nil, an error, or undefined when the
|
|
106
166
|
* source is not a channel router.
|
|
107
167
|
*/
|
|
108
|
-
function
|
|
168
|
+
function channelRouterDenum(source) {
|
|
109
169
|
const channels = recognizeRouter?.(source);
|
|
110
170
|
if (!channels)
|
|
111
171
|
return undefined;
|
|
@@ -123,52 +183,52 @@ function channelRouterDemi(source) {
|
|
|
123
183
|
return size;
|
|
124
184
|
const load = exactCount(size);
|
|
125
185
|
if (!load)
|
|
126
|
-
return Frame.error("$!.
|
|
186
|
+
return Frame.error("$!.denum-observations");
|
|
127
187
|
loads.push(new FrameCount(load.data));
|
|
128
188
|
}
|
|
129
189
|
if (!construct)
|
|
130
|
-
return Frame.error("$!.
|
|
190
|
+
return Frame.error("$!.denum-unavailable");
|
|
131
191
|
return construct(new FrameCount(count), loads);
|
|
132
192
|
}
|
|
133
193
|
/**
|
|
134
|
-
* The fourth hash, `.####`. For a constructed
|
|
135
|
-
* (`
|
|
194
|
+
* The fourth hash, `.####`. For a constructed Denum it is that Denum's own state
|
|
195
|
+
* (`intrinsicDenum`), Count zero included. For every other Frame it is derived
|
|
136
196
|
* only from the existing observers: Count n, Size s and residual r give the
|
|
137
|
-
* loads (s+r)/2 and (s−r)/2, and n itself is the
|
|
197
|
+
* loads (s+r)/2 and (s−r)/2, and n itself is the Denum's Count, kept whole
|
|
138
198
|
* rather than reduced to its parity (007.25c). It never folds, executes or
|
|
139
199
|
* caches the source, and reads each observer at most once.
|
|
140
200
|
*
|
|
141
201
|
* A derived source with Count zero is nil: a host with no children has no
|
|
142
|
-
*
|
|
202
|
+
* Denum, so `[].####` and `0.####` are nil while `(Denum [0, 0, 0]).####` is
|
|
143
203
|
* present. No class can declare `.####` for itself; only the three observers
|
|
144
204
|
* are declarable (`FrameArray.OBSERVATION_KEYS`).
|
|
145
205
|
*
|
|
146
206
|
* In order: a failure of the source or of any observer is answered as it is;
|
|
147
207
|
* no Count (nil) or Count zero is nil; nil residual is nil; observations that
|
|
148
|
-
* are not exact Counts and an integer are `$!.
|
|
149
|
-
* that are negative or not whole are `$!.
|
|
150
|
-
*
|
|
208
|
+
* are not exact Counts and an integer are `$!.denum-observations`; and loads
|
|
209
|
+
* that are negative or not whole are `$!.denum-coherence`. Only then is the
|
|
210
|
+
* Denum constructed (011.18b–m).
|
|
151
211
|
*
|
|
152
212
|
* @param source The observed Frame.
|
|
153
|
-
* @returns A
|
|
213
|
+
* @returns A Denum, nil, or an error.
|
|
154
214
|
*/
|
|
155
|
-
export function
|
|
215
|
+
export function observeDenum(source) {
|
|
156
216
|
const failure = source.observationError();
|
|
157
217
|
if (failure)
|
|
158
218
|
return failure;
|
|
159
|
-
const intrinsic =
|
|
219
|
+
const intrinsic = intrinsicDenum(source);
|
|
160
220
|
if (intrinsic)
|
|
161
221
|
return intrinsic;
|
|
162
|
-
const routed =
|
|
222
|
+
const routed = channelRouterDenum(source);
|
|
163
223
|
if (routed)
|
|
164
224
|
return routed;
|
|
165
225
|
const n = source.sizeFor(Frame.kCOUNT);
|
|
166
226
|
if (n.observationError())
|
|
167
227
|
return n;
|
|
168
228
|
if (n === Frame.nil)
|
|
169
|
-
return Frame.nil; // no Count, no
|
|
229
|
+
return Frame.nil; // no Count, no Denum (011.18k)
|
|
170
230
|
if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
|
|
171
|
-
return Frame.error("$!.
|
|
231
|
+
return Frame.error("$!.denum-count");
|
|
172
232
|
}
|
|
173
233
|
if (n.data === 0n)
|
|
174
234
|
return Frame.nil;
|
|
@@ -182,17 +242,18 @@ export function observeDemi(source) {
|
|
|
182
242
|
return Frame.nil;
|
|
183
243
|
if (!(s instanceof FrameCount) || !(r instanceof FrameInt) ||
|
|
184
244
|
typeof s.data !== "bigint" || typeof r.data !== "bigint" || s.data < 0n)
|
|
185
|
-
return Frame.error("$!.
|
|
245
|
+
return Frame.error("$!.denum-observations");
|
|
186
246
|
const sum = s.data + r.data;
|
|
187
247
|
const difference = s.data - r.data;
|
|
188
248
|
if (sum < 0n || difference < 0n || sum % 2n !== 0n || difference % 2n !== 0n) {
|
|
189
|
-
return Frame.error("$!.
|
|
249
|
+
return Frame.error("$!.denum-coherence");
|
|
190
250
|
}
|
|
191
251
|
if (!construct)
|
|
192
|
-
return Frame.error("$!.
|
|
252
|
+
return Frame.error("$!.denum-unavailable");
|
|
193
253
|
return construct(new FrameCount(n.data), [
|
|
194
254
|
new FrameCount(sum / 2n),
|
|
195
255
|
new FrameCount(difference / 2n),
|
|
196
256
|
]);
|
|
197
257
|
}
|
|
198
|
-
Frame.
|
|
258
|
+
Frame.denum = observeDenum;
|
|
259
|
+
Frame.bindCount = bindDenumCount;
|
|
@@ -537,8 +537,8 @@ Object.defineProperty(FrameArray, "TEXT_KEY", {
|
|
|
537
537
|
* Count, Size and residual. `.####` is not among them, because it is derived
|
|
538
538
|
* from these three, so a class that declares them gets it for free. No
|
|
539
539
|
* class declares `.####`: a method under that name is an ordinary property
|
|
540
|
-
* the fourth hash never runs. The one
|
|
541
|
-
* zero-Count
|
|
540
|
+
* the fourth hash never runs. The one Denum these cannot derive, a constructed
|
|
541
|
+
* zero-Count Denum, is recognized intrinsically (`fourth-hash.ts`).
|
|
542
542
|
*/
|
|
543
543
|
Object.defineProperty(FrameArray, "OBSERVATION_KEYS", {
|
|
544
544
|
enumerable: true,
|
|
@@ -153,7 +153,7 @@ export class FrameLazy extends FrameExpr {
|
|
|
153
153
|
/**
|
|
154
154
|
* `.#` counts the body's represented words (#429). `.##` sums their native
|
|
155
155
|
* Sizes without execution or evaluation-site registration; an empty body
|
|
156
|
-
* retains Size 1. Residual alternates complete stored-word Sizes;
|
|
156
|
+
* retains Size 1. Residual alternates complete stored-word Sizes; Denum
|
|
157
157
|
* derives from those observations (011.18c). The operator reaches a closure
|
|
158
158
|
* as its argument and is answered before its body runs.
|
|
159
159
|
*/
|
|
@@ -27,8 +27,16 @@ const recognizeName = (symbol, source = "") => {
|
|
|
27
27
|
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
28
28
|
}
|
|
29
29
|
// `#` begins a comment except where it spells a size operator, `.#`, `.##`
|
|
30
|
-
//
|
|
31
|
-
// `.foo#bar` still ends at its first hash.
|
|
30
|
+
// `.###`, `.####` or the Count binding `.#%` (011.18, 007.40). A fifth hash
|
|
31
|
+
// starts a comment; `.foo#bar` still ends at its first hash.
|
|
32
|
+
// `.#%%` cannot be split back into `.#` and `%%` once `%` is consumed, so it
|
|
33
|
+
// is refused rather than read as `.#%` before a `%`: write `.# %%`.
|
|
34
|
+
if (source === Frame.kBIND && char === "%") {
|
|
35
|
+
return {
|
|
36
|
+
disposition: ScanDisposition.Error,
|
|
37
|
+
message: "`.#%%` is ambiguous: write `.# %%` or `.#% %`",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
32
40
|
if (Frame.SIZE_OPERATORS.includes(source + char)) {
|
|
33
41
|
return { disposition: ScanDisposition.Consume };
|
|
34
42
|
}
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -718,10 +718,10 @@ export class Frame extends MetaFrame {
|
|
|
718
718
|
return this.is.error || this.is.cyclicReference ? this : undefined;
|
|
719
719
|
}
|
|
720
720
|
/**
|
|
721
|
-
* Native Count, Size, residual and derived
|
|
721
|
+
* Native Count, Size, residual and derived Denum. Missing Count falls back to
|
|
722
722
|
* Size, and missing residual to Count parity; kinds with their own rules
|
|
723
|
-
* (lists, schemas,
|
|
724
|
-
* Nil has no Count, so no residual or
|
|
723
|
+
* (lists, schemas, Denum, all) supply them explicitly (011.18k, 011.18m).
|
|
724
|
+
* Nil has no Count, so no residual or Denum.
|
|
725
725
|
*/
|
|
726
726
|
sizeFor(key) {
|
|
727
727
|
if (!Frame.SIZE_OPERATORS.includes(key))
|
|
@@ -749,8 +749,10 @@ export class Frame extends MetaFrame {
|
|
|
749
749
|
const data = n.data;
|
|
750
750
|
return typeof data === "bigint" ? Frame.signed(data % 2n) : Frame.nil;
|
|
751
751
|
}
|
|
752
|
-
case Frame.
|
|
753
|
-
return Frame.
|
|
752
|
+
case Frame.kDENUM:
|
|
753
|
+
return Frame.denum(this);
|
|
754
|
+
case Frame.kBIND:
|
|
755
|
+
return Frame.bindCount(this);
|
|
754
756
|
default:
|
|
755
757
|
return Frame.nil;
|
|
756
758
|
}
|
|
@@ -1133,13 +1135,25 @@ Object.defineProperty(Frame, "kRESIDUAL", {
|
|
|
1133
1135
|
writable: true,
|
|
1134
1136
|
value: "###"
|
|
1135
1137
|
});
|
|
1136
|
-
/** Derived nullable
|
|
1137
|
-
Object.defineProperty(Frame, "
|
|
1138
|
+
/** Derived nullable Denum, an instance of the HC class in `hc/denum.hc` (011.20). */
|
|
1139
|
+
Object.defineProperty(Frame, "kDENUM", {
|
|
1138
1140
|
enumerable: true,
|
|
1139
1141
|
configurable: true,
|
|
1140
1142
|
writable: true,
|
|
1141
1143
|
value: "####"
|
|
1142
1144
|
});
|
|
1145
|
+
/**
|
|
1146
|
+
* kBIND is `.#%`, Count binding (occurrence/figure 007.39a, 007.40): a
|
|
1147
|
+
* Denum `(C; [a0, …])` with C > 0 answers the new Denum of C loads whose
|
|
1148
|
+
* load j sums every source load at an index congruent to j mod C. Only a
|
|
1149
|
+
* genuine Denum is bound; any other receiver is refused (`fourth-hash.ts`).
|
|
1150
|
+
*/
|
|
1151
|
+
Object.defineProperty(Frame, "kBIND", {
|
|
1152
|
+
enumerable: true,
|
|
1153
|
+
configurable: true,
|
|
1154
|
+
writable: true,
|
|
1155
|
+
value: "#%"
|
|
1156
|
+
});
|
|
1143
1157
|
/**
|
|
1144
1158
|
* The size operators, the only names spelled with `#` (#411). Each answers
|
|
1145
1159
|
* for its receiver through `sizeFor`, never through name lookup.
|
|
@@ -1152,7 +1166,8 @@ Object.defineProperty(Frame, "SIZE_OPERATORS", {
|
|
|
1152
1166
|
Frame.kCOUNT,
|
|
1153
1167
|
Frame.kLEAVES,
|
|
1154
1168
|
Frame.kRESIDUAL,
|
|
1155
|
-
Frame.
|
|
1169
|
+
Frame.kDENUM,
|
|
1170
|
+
Frame.kBIND,
|
|
1156
1171
|
]
|
|
1157
1172
|
});
|
|
1158
1173
|
/**
|
package/esm/lib/frames.js
CHANGED
|
@@ -27,7 +27,7 @@ export { FrameObservation } from "./frames/frame-observation.js";
|
|
|
27
27
|
export { FrameNumeric, NUMERIC_RANK, } from "./frames/frame-numeric.js";
|
|
28
28
|
export { FrameInt } from "./frames/frame-int.js";
|
|
29
29
|
export { FrameCount } from "./frames/frame-count.js";
|
|
30
|
-
export {
|
|
30
|
+
export { installDenumConstructor, installRouterRecognizer, observeDenum, } from "./frames/fourth-hash.js";
|
|
31
31
|
export { FrameDecimal } from "./frames/frame-decimal.js";
|
|
32
32
|
export { FrameSequence } from "./frames/frame-sequence.js";
|
|
33
33
|
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.49.0";
|