hclang 0.42.0 → 0.43.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.
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `.####` answers a Demi, and a Demi is an HC class, `Demi` in `hc/demi.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
7
|
* constructor it calls (`installDemiConstructor`).
|
|
8
8
|
*
|
|
9
9
|
* The class is read from the compiled-in bundle, not through a resource root,
|
|
@@ -73,19 +73,19 @@ export function demiClass() {
|
|
|
73
73
|
return loaded;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Constructs a Demi with the HC class: `Demi [
|
|
76
|
+
* Constructs a Demi with the HC class: `Demi [count, left, right]`.
|
|
77
77
|
*
|
|
78
|
-
* @param
|
|
78
|
+
* @param count The full application Count; the Demi derives its phase from it.
|
|
79
79
|
* @param left The left load.
|
|
80
80
|
* @param right The right load.
|
|
81
81
|
* @returns The new instance, or the class's failure.
|
|
82
82
|
*/
|
|
83
|
-
export function constructDemi(
|
|
83
|
+
export function constructDemi(count, left, right) {
|
|
84
84
|
const constructor = demiClass();
|
|
85
85
|
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
86
86
|
return constructor;
|
|
87
87
|
}
|
|
88
|
-
const state = new FrameArray([
|
|
88
|
+
const state = new FrameArray([count, left, right]);
|
|
89
89
|
return FrameExpr.answeredValue(constructor.call(state)).referent();
|
|
90
90
|
}
|
|
91
91
|
installDemiConstructor(constructDemi);
|
|
@@ -12,11 +12,69 @@ let construct;
|
|
|
12
12
|
export function installDemiConstructor(constructor) {
|
|
13
13
|
construct = constructor;
|
|
14
14
|
}
|
|
15
|
+
/** The stored fields a Demi instance is reconstructed from, in order. */
|
|
16
|
+
const DEMI_STATE = ["count", "left", "right"];
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* the
|
|
19
|
-
*
|
|
18
|
+
* A stored field read as an exact nonnegative Count, or undefined.
|
|
19
|
+
*
|
|
20
|
+
* Only the instance's own field is read (`get_here`), never a declared parent
|
|
21
|
+
* or a method, so nothing runs.
|
|
22
|
+
*/
|
|
23
|
+
function storedCount(source, key) {
|
|
24
|
+
const value = source.get_here(key).referent();
|
|
25
|
+
return value instanceof FrameCount && typeof value.data === "bigint" &&
|
|
26
|
+
value.data >= 0n
|
|
27
|
+
? value
|
|
28
|
+
: undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The intrinsic Demi path (007.25e). A constructed Demi is the one Frame whose
|
|
32
|
+
* fourth hash the three observers cannot decide: `Demi [0, 0, 0]` reads 0, 0,
|
|
33
|
+
* 0, exactly as `[]` does, yet it is a present state. Rather than let any
|
|
34
|
+
* class declare its own `.####`, the fourth hash recognizes an instance of the
|
|
35
|
+
* shipped class itself, and nothing else.
|
|
36
|
+
*
|
|
37
|
+
* A source is a Demi exactly when it has stored Counts `count`, `left` and
|
|
38
|
+
* `right`, and it is `==` (same value and same type at every node, fields and
|
|
39
|
+
* methods included) to the Demi the shipped constructor builds from those
|
|
40
|
+
* three Counts. The answer is then that fresh reconstruction, never the source
|
|
41
|
+
* and never anything the source computed. No observer, method or closure of
|
|
42
|
+
* the source runs, so a forged `#`, `##`, `###` or `####` cannot steer it, and
|
|
43
|
+
* comparison is the language's own typed equality, not a spelling. Anything
|
|
44
|
+
* else, a foreign aggregate, a forged or edited instance, or a reconstruction
|
|
45
|
+
* that fails, is undefined, and the source takes the derived path like every
|
|
46
|
+
* other Frame.
|
|
47
|
+
*
|
|
48
|
+
* @param source The observed Frame.
|
|
49
|
+
* @returns A fresh Demi equal to the source, or undefined.
|
|
50
|
+
*/
|
|
51
|
+
function intrinsicDemi(source) {
|
|
52
|
+
if (!construct)
|
|
53
|
+
return undefined;
|
|
54
|
+
const host = source.referent();
|
|
55
|
+
if (!host.ownsIdentity())
|
|
56
|
+
return undefined;
|
|
57
|
+
const [count, left, right] = DEMI_STATE.map((key) => storedCount(host, key));
|
|
58
|
+
if (!count || !left || !right)
|
|
59
|
+
return undefined;
|
|
60
|
+
const candidate = construct(new FrameCount(count.data), new FrameCount(left.data), new FrameCount(right.data));
|
|
61
|
+
if (candidate.isFailedResult() || candidate.observationError()) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return candidate.typeEquals(host) === Frame.all ? candidate : undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The fourth hash, `.####`. For a constructed Demi it is that Demi's own state
|
|
68
|
+
* (`intrinsicDemi`), Count zero included. For every other Frame it is derived
|
|
69
|
+
* only from the existing observers: Count n, Size s and residual r give the
|
|
70
|
+
* loads (s+r)/2 and (s−r)/2, and n itself is the Demi's Count, kept whole
|
|
71
|
+
* rather than reduced to its parity (007.25c). It never folds, executes or
|
|
72
|
+
* caches the source, and reads each observer at most once.
|
|
73
|
+
*
|
|
74
|
+
* A derived source with Count zero is nil: a host with no children has no
|
|
75
|
+
* Demi, so `[].####` and `0.####` are nil while `(Demi [0, 0, 0]).####` is
|
|
76
|
+
* present. No class can declare `.####` for itself; only the three observers
|
|
77
|
+
* are declarable (`FrameArray.OBSERVATION_KEYS`).
|
|
20
78
|
*
|
|
21
79
|
* In order: a failure of the source or of any observer is answered as it is;
|
|
22
80
|
* no Count (nil) or Count zero is nil; nil residual is nil; observations that
|
|
@@ -31,6 +89,9 @@ export function observeDemi(source) {
|
|
|
31
89
|
const failure = source.observationError();
|
|
32
90
|
if (failure)
|
|
33
91
|
return failure;
|
|
92
|
+
const intrinsic = intrinsicDemi(source);
|
|
93
|
+
if (intrinsic)
|
|
94
|
+
return intrinsic;
|
|
34
95
|
const n = source.sizeFor(Frame.kCOUNT);
|
|
35
96
|
if (n.observationError())
|
|
36
97
|
return n;
|
|
@@ -59,6 +120,6 @@ export function observeDemi(source) {
|
|
|
59
120
|
}
|
|
60
121
|
if (!construct)
|
|
61
122
|
return Frame.error("$!.demi-unavailable");
|
|
62
|
-
return construct(new FrameCount(n.data
|
|
123
|
+
return construct(new FrameCount(n.data), new FrameCount(sum / 2n), new FrameCount(difference / 2n));
|
|
63
124
|
}
|
|
64
125
|
Frame.demi = observeDemi;
|
|
@@ -503,8 +503,11 @@ Object.defineProperty(FrameArray, "TEXT_KEY", {
|
|
|
503
503
|
});
|
|
504
504
|
/**
|
|
505
505
|
* The size operators an aggregate may declare its own answer to (011.20):
|
|
506
|
-
* Count, Size and residual. `.####` is not among them, because it is
|
|
507
|
-
*
|
|
506
|
+
* Count, Size and residual. `.####` is not among them, because it is derived
|
|
507
|
+
* from these three, so a class that declares them gets it for free. No
|
|
508
|
+
* class declares `.####`: a method under that name is an ordinary property
|
|
509
|
+
* the fourth hash never runs. The one Demi these cannot derive, a constructed
|
|
510
|
+
* zero-Count Demi, is recognized intrinsically (`fourth-hash.ts`).
|
|
508
511
|
*/
|
|
509
512
|
Object.defineProperty(FrameArray, "OBSERVATION_KEYS", {
|
|
510
513
|
enumerable: true,
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.43.0";
|