hclang 0.47.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 -1227
- package/esm/lib/execute/denum-prologue.js +53 -67
- package/esm/lib/execute/hc-eval.js +1 -3
- 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 +3 -3
- package/esm/lib/frames/frame-expr.js +3 -3
- package/esm/lib/frames/frame-lazy.js +2 -2
- package/esm/lib/frames/frame-list.js +1 -1
- package/esm/lib/frames/frame-name.js +10 -10
- package/esm/lib/frames/frame-symbol.js +1 -1
- package/esm/lib/frames/frame.js +27 -38
- package/esm/lib/frames.js +1 -3
- package/esm/lib/ops.js +0 -3
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
- package/esm/lib/execute/demi-prologue.js +0 -103
- package/esm/lib/frames/denum-hash.js +0 -180
- package/esm/lib/frames/denum.js +0 -601
- package/esm/lib/ops/denum.js +0 -238
package/esm/lib/frames/frame.js
CHANGED
|
@@ -452,17 +452,6 @@ export function inspectFlags(flags) {
|
|
|
452
452
|
* manipulating and interacting with frames.
|
|
453
453
|
*/
|
|
454
454
|
export class Frame extends MetaFrame {
|
|
455
|
-
/**
|
|
456
|
-
* Whether `key` names an observer a Frame answers for itself: one of the four
|
|
457
|
-
* fixed hashes `#`, `##`, `###`, `####`, or a ranked hash `#n`.
|
|
458
|
-
*/
|
|
459
|
-
static isSizeOperator(key) {
|
|
460
|
-
return Frame.SIZE_OPERATORS.includes(key) || Frame.RANKED_HASH.test(key);
|
|
461
|
-
}
|
|
462
|
-
/** The rung n of a ranked hash `#n`, or undefined for any other key. */
|
|
463
|
-
static hashRank(key) {
|
|
464
|
-
return Frame.RANKED_HASH.test(key) ? Number(key.slice(1)) : undefined;
|
|
465
|
-
}
|
|
466
455
|
/** Creates a runtime error value without coupling MetaFrame to FrameNote. */
|
|
467
456
|
static error(source) {
|
|
468
457
|
const error = new (class extends Frame {
|
|
@@ -729,13 +718,13 @@ export class Frame extends MetaFrame {
|
|
|
729
718
|
return this.is.error || this.is.cyclicReference ? this : undefined;
|
|
730
719
|
}
|
|
731
720
|
/**
|
|
732
|
-
* Native Count, Size, residual and derived
|
|
721
|
+
* Native Count, Size, residual and derived Denum. Missing Count falls back to
|
|
733
722
|
* Size, and missing residual to Count parity; kinds with their own rules
|
|
734
|
-
* (lists, schemas,
|
|
735
|
-
* 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.
|
|
736
725
|
*/
|
|
737
726
|
sizeFor(key) {
|
|
738
|
-
if (!Frame.
|
|
727
|
+
if (!Frame.SIZE_OPERATORS.includes(key))
|
|
739
728
|
return Frame.nil;
|
|
740
729
|
const failure = this.observationError();
|
|
741
730
|
if (failure)
|
|
@@ -760,12 +749,12 @@ export class Frame extends MetaFrame {
|
|
|
760
749
|
const data = n.data;
|
|
761
750
|
return typeof data === "bigint" ? Frame.signed(data % 2n) : Frame.nil;
|
|
762
751
|
}
|
|
763
|
-
case Frame.
|
|
764
|
-
return Frame.
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
752
|
+
case Frame.kDENUM:
|
|
753
|
+
return Frame.denum(this);
|
|
754
|
+
case Frame.kBIND:
|
|
755
|
+
return Frame.bindCount(this);
|
|
756
|
+
default:
|
|
757
|
+
return Frame.nil;
|
|
769
758
|
}
|
|
770
759
|
}
|
|
771
760
|
/** Nonnegative represented quantity; path tracks recursive containment only. */
|
|
@@ -1083,7 +1072,7 @@ export class Frame extends MetaFrame {
|
|
|
1083
1072
|
return undefined;
|
|
1084
1073
|
}
|
|
1085
1074
|
const key = argument.spelling();
|
|
1086
|
-
return Frame.
|
|
1075
|
+
return Frame.SIZE_OPERATORS.includes(key) ? key : undefined;
|
|
1087
1076
|
}
|
|
1088
1077
|
/**
|
|
1089
1078
|
* Negation is decided by the symbol's name, never by how it prints.
|
|
@@ -1146,13 +1135,25 @@ Object.defineProperty(Frame, "kRESIDUAL", {
|
|
|
1146
1135
|
writable: true,
|
|
1147
1136
|
value: "###"
|
|
1148
1137
|
});
|
|
1149
|
-
/** Derived nullable
|
|
1150
|
-
Object.defineProperty(Frame, "
|
|
1138
|
+
/** Derived nullable Denum, an instance of the HC class in `hc/denum.hc` (011.20). */
|
|
1139
|
+
Object.defineProperty(Frame, "kDENUM", {
|
|
1151
1140
|
enumerable: true,
|
|
1152
1141
|
configurable: true,
|
|
1153
1142
|
writable: true,
|
|
1154
1143
|
value: "####"
|
|
1155
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
|
+
});
|
|
1156
1157
|
/**
|
|
1157
1158
|
* The size operators, the only names spelled with `#` (#411). Each answers
|
|
1158
1159
|
* for its receiver through `sizeFor`, never through name lookup.
|
|
@@ -1165,22 +1166,10 @@ Object.defineProperty(Frame, "SIZE_OPERATORS", {
|
|
|
1165
1166
|
Frame.kCOUNT,
|
|
1166
1167
|
Frame.kLEAVES,
|
|
1167
1168
|
Frame.kRESIDUAL,
|
|
1168
|
-
Frame.
|
|
1169
|
+
Frame.kDENUM,
|
|
1170
|
+
Frame.kBIND,
|
|
1169
1171
|
]
|
|
1170
1172
|
});
|
|
1171
|
-
/**
|
|
1172
|
-
* The ranked hash `.#n` (occurrence/figure 007.32): `#` and decimal digits,
|
|
1173
|
-
* as `.#2`, in canonical decimal (no leading zero, so each rung has one
|
|
1174
|
-
* spelling). Its n is the Cayley–Dickson rung and not a hash count, so it is
|
|
1175
|
-
* not one of {@link SIZE_OPERATORS}, whose spellings are the four fixed
|
|
1176
|
-
* hashes. Bare `.#` stays the Count.
|
|
1177
|
-
*/
|
|
1178
|
-
Object.defineProperty(Frame, "RANKED_HASH", {
|
|
1179
|
-
enumerable: true,
|
|
1180
|
-
configurable: true,
|
|
1181
|
-
writable: true,
|
|
1182
|
-
value: /^#(0|[1-9][0-9]*)$/
|
|
1183
|
-
});
|
|
1184
1173
|
/**
|
|
1185
1174
|
* BEGIN_EXPR is the symbol for the beginning of an expression.
|
|
1186
1175
|
*/
|
package/esm/lib/frames.js
CHANGED
|
@@ -27,9 +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 {
|
|
31
|
-
export { installDenumConstructors, observeDenum, } from "./frames/denum-hash.js";
|
|
32
|
-
export * as denum from "./frames/denum.js";
|
|
30
|
+
export { installDenumConstructor, installRouterRecognizer, observeDenum, } from "./frames/fourth-hash.js";
|
|
33
31
|
export { FrameDecimal } from "./frames/frame-decimal.js";
|
|
34
32
|
export { FrameSequence } from "./frames/frame-sequence.js";
|
|
35
33
|
export { FrameTypedNumber } from "./frames/frame-typed-number.js";
|
package/esm/lib/ops.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IfElse, IfThen } from "./ops/conditionals.js";
|
|
2
|
-
import { DenumEngine } from "./ops/denum.js";
|
|
3
2
|
import { FrameOps } from "./ops/frame-ops.js";
|
|
4
3
|
import { MapElements, MapMembers, ReduceElements, ReduceMembers, SpliceElements, } from "./ops/iterators.js";
|
|
5
4
|
import { Add, Divide, Equals, GreaterThan, GreaterThanOrEqual, Identical, LessThan, LessThanOrEqual, Modulo, Multiply, Power, Subtract, TypeEquals, } from "./ops/math.js";
|
|
@@ -35,6 +34,4 @@ export const Ops = new FrameOps({
|
|
|
35
34
|
"^": BindType,
|
|
36
35
|
"^^": BindReturn,
|
|
37
36
|
"->": Arrow,
|
|
38
|
-
// The one native seam under `hc/denum.hc`: pure Cayley–Dickson arithmetic.
|
|
39
|
-
"denum-engine": DenumEngine,
|
|
40
37
|
});
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.49.0";
|
package/package.json
CHANGED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Demi class, loaded from HC for the fourth hash.
|
|
3
|
-
*
|
|
4
|
-
* `.####` answers a Demi, and a Demi is an HC class, `Demi` in `hc/demi.hc`,
|
|
5
|
-
* not a native one (occurrence/figure 011.20). The frames package derives the
|
|
6
|
-
* Count and loads natively but cannot run HC, so this module installs the
|
|
7
|
-
* constructor it calls (`installDemiConstructor`).
|
|
8
|
-
*
|
|
9
|
-
* The class is read from the compiled-in bundle, not through a resource root,
|
|
10
|
-
* so `.####` works in a bare `evaluate`, which has no root and imports nothing.
|
|
11
|
-
* The file is evaluated the first time a Demi is constructed, once per
|
|
12
|
-
* process, the way an import evaluates a testdoc: its example lines are
|
|
13
|
-
* dropped and the first failure fails the whole. It runs in a namespace of its
|
|
14
|
-
* own, with no host bindings and no root, so it can read nothing but the
|
|
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 Demi requested
|
|
17
|
-
* while the file is still loading is `$!.demi-prologue-reentrant`, because
|
|
18
|
-
* the class cannot be defined by itself.
|
|
19
|
-
*
|
|
20
|
-
* What stays native is only what HC cannot say: reading `#`, `##` and `###`
|
|
21
|
-
* in a fixed order with their absence and error rules, and checking that the
|
|
22
|
-
* loads are whole. Everything a Demi does is in the HC source.
|
|
23
|
-
*
|
|
24
|
-
* @module
|
|
25
|
-
*/
|
|
26
|
-
import { EvaluationScope, Frame, FrameArray, FrameExpr, installDemiConstructor, } from "../frames.js";
|
|
27
|
-
import { HC_SOURCES } from "../bundle/hc-sources.js";
|
|
28
|
-
import { evaluateSourceText } from "./resource-import.js";
|
|
29
|
-
/** The bundled file that defines the class. */
|
|
30
|
-
export const DEMI_SOURCE = "hc/demi.hc";
|
|
31
|
-
/** The name the file declares the constructor under. */
|
|
32
|
-
export const DEMI_CLASS = "Demi";
|
|
33
|
-
let loaded;
|
|
34
|
-
let loading = false;
|
|
35
|
-
/**
|
|
36
|
-
* Evaluates class source in a namespace of its own, with no host bindings and
|
|
37
|
-
* no root, answering its `Demi` or the failure. Uncached: `demiClass` keeps
|
|
38
|
-
* the one result the process uses.
|
|
39
|
-
*
|
|
40
|
-
* @param source The source text, or undefined when the bundle lacks it.
|
|
41
|
-
* @returns The constructor, or an error.
|
|
42
|
-
*/
|
|
43
|
-
export function loadDemiClass(source) {
|
|
44
|
-
if (source === undefined) {
|
|
45
|
-
return Frame.error(`$!.demi-prologue-missing ${DEMI_SOURCE}`);
|
|
46
|
-
}
|
|
47
|
-
const namespace = new FrameArray([]);
|
|
48
|
-
const result = evaluateSourceText(source, EvaluationScope.root(namespace));
|
|
49
|
-
if (result.isFailedResult() || result.observationError())
|
|
50
|
-
return result;
|
|
51
|
-
const constructor = namespace.getOwn(DEMI_CLASS);
|
|
52
|
-
return constructor.is.missing
|
|
53
|
-
? Frame.error(`$!.demi-prologue-missing ${DEMI_CLASS}`)
|
|
54
|
-
: constructor;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The `Demi` constructor closure, evaluated from the bundle on first use.
|
|
58
|
-
*
|
|
59
|
-
* @returns The constructor, or the error that loading it answered.
|
|
60
|
-
*/
|
|
61
|
-
export function demiClass() {
|
|
62
|
-
if (loaded)
|
|
63
|
-
return loaded;
|
|
64
|
-
if (loading)
|
|
65
|
-
return Frame.error("$!.demi-prologue-reentrant");
|
|
66
|
-
loading = true;
|
|
67
|
-
try {
|
|
68
|
-
loaded = loadDemiClass(HC_SOURCES.get(DEMI_SOURCE));
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
loading = false;
|
|
72
|
-
}
|
|
73
|
-
return loaded;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Constructs a Demi of any arity with the HC class: `Demi [count, loads]`.
|
|
77
|
-
* Two loads give the binary Demi, the same instance `Demi [count, left,
|
|
78
|
-
* right]` builds; any other nonzero number gives the channel Demi (007.27).
|
|
79
|
-
*
|
|
80
|
-
* @param count The full application Count.
|
|
81
|
-
* @param loads The ordered channel loads.
|
|
82
|
-
* @returns The new instance, or the class's failure.
|
|
83
|
-
*/
|
|
84
|
-
export function constructDemiLoads(count, loads) {
|
|
85
|
-
const constructor = demiClass();
|
|
86
|
-
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
87
|
-
return constructor;
|
|
88
|
-
}
|
|
89
|
-
const state = new FrameArray([count, new FrameArray([...loads])]);
|
|
90
|
-
return FrameExpr.answeredValue(constructor.call(state)).referent();
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Constructs a binary Demi with the HC class: `Demi [count, left, right]`.
|
|
94
|
-
*
|
|
95
|
-
* @param count The full application Count; the Demi derives its phase from it.
|
|
96
|
-
* @param left The left load.
|
|
97
|
-
* @param right The right load.
|
|
98
|
-
* @returns The new instance, or the class's failure.
|
|
99
|
-
*/
|
|
100
|
-
export function constructDemi(count, left, right) {
|
|
101
|
-
return constructDemiLoads(count, [left, right]);
|
|
102
|
-
}
|
|
103
|
-
installDemiConstructor(constructDemiLoads);
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { Frame } from "./frame.js";
|
|
2
|
-
import { FrameCount } from "./frame-count.js";
|
|
3
|
-
import { FrameInt } from "./frame-int.js";
|
|
4
|
-
import { DenumError, fromHost, MAX_RANK, promoteDenum, } from "./denum.js";
|
|
5
|
-
let constructors;
|
|
6
|
-
/**
|
|
7
|
-
* Installs what `.#n` answers with and recognizes. The classes are HC, so the
|
|
8
|
-
* frames package, which cannot run HC, takes them from the evaluator
|
|
9
|
-
* (`lib/execute/denum-prologue.ts`), as `.####` takes its Demi. They are
|
|
10
|
-
* installed as a pair: the Denum constructor builds every answer, and the view
|
|
11
|
-
* derivation is used only to recognize a view source, which is refused.
|
|
12
|
-
*
|
|
13
|
-
* @param installed Both, called once per present observation.
|
|
14
|
-
*/
|
|
15
|
-
export function installDenumConstructors(installed) {
|
|
16
|
-
constructors = installed;
|
|
17
|
-
}
|
|
18
|
-
/** A Frame read as an exact nonnegative Count, or undefined. */
|
|
19
|
-
function exactCount(frame) {
|
|
20
|
-
const value = frame.referent();
|
|
21
|
-
return value instanceof FrameCount && typeof value.data === "bigint" &&
|
|
22
|
-
value.data >= 0n
|
|
23
|
-
? value.data
|
|
24
|
-
: undefined;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* The stored state of a Denum instance: its own `count` and `loads` fields
|
|
28
|
-
* (there is no stored rank). Only the instance's own fields are read (`get_here`), never a
|
|
29
|
-
* declared parent or a method, and the loads are read as stored, so nothing
|
|
30
|
-
* runs. Undefined when any field is absent or not an exact Count of the right
|
|
31
|
-
* shape.
|
|
32
|
-
*/
|
|
33
|
-
function storedState(host) {
|
|
34
|
-
const count = exactCount(host.get_here("count"));
|
|
35
|
-
const list = host.get_here("loads").referent();
|
|
36
|
-
if (count === undefined)
|
|
37
|
-
return undefined;
|
|
38
|
-
if (!list.ownsIdentity())
|
|
39
|
-
return undefined;
|
|
40
|
-
const loads = list.elements().map(exactCount);
|
|
41
|
-
if (loads.length === 0 || loads.some((load) => load === undefined)) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
return { count, loads: loads };
|
|
45
|
-
}
|
|
46
|
-
/** True when `construct(state)` builds exactly `host` (same value and type). */
|
|
47
|
-
function rebuilds(construct, state, host) {
|
|
48
|
-
let candidate;
|
|
49
|
-
try {
|
|
50
|
-
candidate = construct(state);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (error instanceof DenumError)
|
|
54
|
-
return false;
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
if (candidate.isFailedResult() || candidate.observationError())
|
|
58
|
-
return false;
|
|
59
|
-
return candidate.typeEquals(host) === Frame.all;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The intrinsic path, as `.####` has for a Demi. A source is a Denum (or a CD
|
|
63
|
-
* view) exactly when its stored `count` and `loads` are a valid state and it is
|
|
64
|
-
* `==` (same value and same type at every node, fields and methods included) to
|
|
65
|
-
* the instance the shipped `Denum` constructor (or its `.cd ()` view) builds
|
|
66
|
-
* from them. The answer is then built from that reconstruction, never from the
|
|
67
|
-
* source: no observer, method or closure of the source runs, so a forged `#`,
|
|
68
|
-
* `##` or `###` cannot steer it. A zero Count is therefore present, unlike a
|
|
69
|
-
* host with no children. The arity decides nothing: a Denum with `2ⁿ` loads is
|
|
70
|
-
* not a view, and a view is not rebuilt by the Denum constructor.
|
|
71
|
-
*
|
|
72
|
-
* @returns Which construction rebuilds the source, and its state; or undefined.
|
|
73
|
-
*/
|
|
74
|
-
function intrinsicDenum(source) {
|
|
75
|
-
if (!constructors)
|
|
76
|
-
return undefined;
|
|
77
|
-
const host = source.referent();
|
|
78
|
-
if (!host.ownsIdentity())
|
|
79
|
-
return undefined;
|
|
80
|
-
const state = storedState(host);
|
|
81
|
-
if (!state)
|
|
82
|
-
return undefined;
|
|
83
|
-
if (rebuilds(constructors.denum, state, host)) {
|
|
84
|
-
return { kind: "denum", state };
|
|
85
|
-
}
|
|
86
|
-
if (rebuilds(constructors.view, state, host))
|
|
87
|
-
return { kind: "view", state };
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* The ranked hash, `.#n` (occurrence/figure 007.32, 007.32b, 007.35b, 007.36):
|
|
92
|
-
* a generic Denum of rung n, n from 0 to 5. It never answers a CD view, and
|
|
93
|
-
* there is no `#n=`; the algebraic value is `d.coordinates ()` of a view
|
|
94
|
-
* derived by `d.cd ()`.
|
|
95
|
-
*
|
|
96
|
-
* Three different cases answer it, and they are not the same:
|
|
97
|
-
*
|
|
98
|
-
* - **Construction from a host.** A host answers its Count C, Size s and
|
|
99
|
-
* residual r only, so the Denum is built from those three observers with
|
|
100
|
-
* the derivation of `.####` (`observeDemi`), at rank n (`fromHost`). A host
|
|
101
|
-
* with no Count, or Count zero, has no Denum and answers nil, as it has no
|
|
102
|
-
* Demi; rank 0 reads no residual. Failures are answered as they are, and
|
|
103
|
-
* unusable observations are `$!.denum-count`, `$!.denum-observations` and
|
|
104
|
-
* `$!.denum-coherence`.
|
|
105
|
-
* - **Promotion of a Denum.** An instance of the shipped `Denum` class with a
|
|
106
|
-
* shipped binary arity (1, 2, 4, 8, 16, 32) answers its own state under the
|
|
107
|
-
* load-preserving embedding at rung n, keeping Count and every load, and
|
|
108
|
-
* below its own derived rank `$!.denum-demotion`. The embedding is
|
|
109
|
-
* structural: it does not invoke the CD interpretation, and the answer is a
|
|
110
|
-
* Denum. A Denum of Count zero is present. Any other arity is
|
|
111
|
-
* `$!.denum-unsupported-arity`: nothing is truncated, padded or read as
|
|
112
|
-
* `2^rank`.
|
|
113
|
-
* - **Refusal of a CD view.** A view derived by `d.cd ()` is never a source:
|
|
114
|
-
* the answer is `$!.denum-view-source`, and it is not measured as a host from
|
|
115
|
-
* its Count and Size either. Ask the Denum it views, `v.denum ()`.
|
|
116
|
-
*
|
|
117
|
-
* A multi-channel `RotorRouter` is not special-cased here as it is under
|
|
118
|
-
* `.####` (`channelRouterDemi`): `.#n` reads only Count, Size and residual, so
|
|
119
|
-
* `x.#1` equals `x.####` for ordinary and binary hosts, and for a router of
|
|
120
|
-
* more than two channels is the binary projection while `.####` keeps its
|
|
121
|
-
* channel Demi (pinned in `hc/denum.hc`).
|
|
122
|
-
*
|
|
123
|
-
* Nothing folds, executes or caches the source, and each observer is read at
|
|
124
|
-
* most once. A rank above 5 is `$!.denum-rank`.
|
|
125
|
-
*
|
|
126
|
-
* @param source The observed Frame.
|
|
127
|
-
* @param rank The rung n of `.#n`.
|
|
128
|
-
* @returns A Denum, nil, or an error.
|
|
129
|
-
*/
|
|
130
|
-
export function observeDenum(source, rank) {
|
|
131
|
-
const failure = source.observationError();
|
|
132
|
-
if (failure)
|
|
133
|
-
return failure;
|
|
134
|
-
if (!Number.isInteger(rank) || rank < 0 || rank > MAX_RANK) {
|
|
135
|
-
return Frame.error("$!.denum-rank");
|
|
136
|
-
}
|
|
137
|
-
if (!constructors)
|
|
138
|
-
return Frame.error("$!.denum-unavailable");
|
|
139
|
-
const construct = constructors.denum;
|
|
140
|
-
try {
|
|
141
|
-
const intrinsic = intrinsicDenum(source);
|
|
142
|
-
if (intrinsic?.kind === "view")
|
|
143
|
-
return Frame.error("$!.denum-view-source");
|
|
144
|
-
if (intrinsic)
|
|
145
|
-
return construct(promoteDenum(intrinsic.state, rank));
|
|
146
|
-
const n = source.sizeFor(Frame.kCOUNT);
|
|
147
|
-
if (n.observationError())
|
|
148
|
-
return n;
|
|
149
|
-
if (n === Frame.nil)
|
|
150
|
-
return Frame.nil; // no Count, no Denum
|
|
151
|
-
if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
|
|
152
|
-
return Frame.error("$!.denum-count");
|
|
153
|
-
}
|
|
154
|
-
if (n.data === 0n)
|
|
155
|
-
return Frame.nil;
|
|
156
|
-
const s = source.sizeFor(Frame.kLEAVES);
|
|
157
|
-
if (s.observationError())
|
|
158
|
-
return s;
|
|
159
|
-
if (!(s instanceof FrameCount) || typeof s.data !== "bigint") {
|
|
160
|
-
return Frame.error("$!.denum-observations");
|
|
161
|
-
}
|
|
162
|
-
if (rank === 0)
|
|
163
|
-
return construct(fromHost(0, n.data, s.data, 0n));
|
|
164
|
-
const r = source.sizeFor(Frame.kRESIDUAL);
|
|
165
|
-
if (r.observationError())
|
|
166
|
-
return r;
|
|
167
|
-
if (r === Frame.nil)
|
|
168
|
-
return Frame.nil;
|
|
169
|
-
if (!(r instanceof FrameInt) || typeof r.data !== "bigint") {
|
|
170
|
-
return Frame.error("$!.denum-observations");
|
|
171
|
-
}
|
|
172
|
-
return construct(fromHost(rank, n.data, s.data, r.data));
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
if (error instanceof DenumError)
|
|
176
|
-
return Frame.error(error.kind);
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
Frame.denum = observeDenum;
|