hclang 0.44.0 → 0.45.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.
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The Denum class, loaded from HC for the ranked hash.
3
+ *
4
+ * `x.#n` answers a Denum, and a Denum is an HC class, `Denum` in
5
+ * `hc/denum.hc` (occurrence/figure 007.32). The frames package derives the
6
+ * state natively but cannot run HC, so this module installs the constructor it
7
+ * calls (`installDenumConstructor`), exactly as `demi-prologue.ts` does for
8
+ * `.####`.
9
+ *
10
+ * The class is read from the compiled-in bundle, not through a resource root,
11
+ * so `.#n` works in a bare `evaluate`, which has no root and imports nothing.
12
+ * The file is evaluated the first time a Denum is constructed, once per
13
+ * process: its example lines are dropped and the first failure fails the whole.
14
+ * It runs in a namespace of its own, with no host bindings and no root, so it
15
+ * can read nothing but the global operators, among them the pure
16
+ * `denum-engine`, and nothing a program declares can reach it. Its outcome is
17
+ * kept, failure included, so it is never evaluated twice. A Denum requested
18
+ * while the file is still loading is `$!.denum-prologue-reentrant`.
19
+ *
20
+ * @module
21
+ */
22
+ import { EvaluationScope, Frame, FrameArray, FrameCount, FrameExpr, installDenumConstructor, } from "../frames.js";
23
+ import { HC_SOURCES } from "../bundle/hc-sources.js";
24
+ import { evaluateSourceText } from "./resource-import.js";
25
+ /** The bundled file that defines the class. */
26
+ export const DENUM_SOURCE = "hc/denum.hc";
27
+ /** The name the file declares the constructor under. */
28
+ export const DENUM_CLASS = "Denum";
29
+ let loaded;
30
+ let loading = false;
31
+ /**
32
+ * Evaluates class source in a namespace of its own, answering its `Denum` or
33
+ * the failure. Uncached: `denumClass` keeps the one result the process uses.
34
+ *
35
+ * @param source The source text, or undefined when the bundle lacks it.
36
+ * @returns The constructor, or an error.
37
+ */
38
+ export function loadDenumClass(source) {
39
+ if (source === undefined) {
40
+ return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
41
+ }
42
+ const namespace = new FrameArray([]);
43
+ const result = evaluateSourceText(source, EvaluationScope.root(namespace));
44
+ if (result.isFailedResult() || result.observationError())
45
+ return result;
46
+ const constructor = namespace.getOwn(DENUM_CLASS);
47
+ return constructor.is.missing
48
+ ? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
49
+ : constructor;
50
+ }
51
+ /**
52
+ * The `Denum` constructor closure, evaluated from the bundle on first use.
53
+ *
54
+ * @returns The constructor, or the error that loading it answered.
55
+ */
56
+ export function denumClass() {
57
+ if (loaded)
58
+ return loaded;
59
+ if (loading)
60
+ return Frame.error("$!.denum-prologue-reentrant");
61
+ loading = true;
62
+ try {
63
+ loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
64
+ }
65
+ finally {
66
+ loading = false;
67
+ }
68
+ return loaded;
69
+ }
70
+ /**
71
+ * Constructs a Denum with the HC class: `Denum [rank, count, loads]`.
72
+ *
73
+ * @param state The rank, Count and loads, already admissible.
74
+ * @returns The new instance, or the class's failure.
75
+ */
76
+ export function constructDenum(state) {
77
+ const constructor = denumClass();
78
+ if (constructor.isFailedResult() || constructor.observationError()) {
79
+ return constructor;
80
+ }
81
+ const argument = new FrameArray([
82
+ new FrameCount(BigInt(state.rank)),
83
+ new FrameCount(state.count),
84
+ new FrameArray(state.loads.map((load) => new FrameCount(load))),
85
+ ]);
86
+ return FrameExpr.answeredValue(constructor.call(argument)).referent();
87
+ }
88
+ installDenumConstructor(constructDenum);
@@ -1,6 +1,8 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
2
  // Installs the Demi class that `.####` constructs (011.20).
3
3
  import "./demi-prologue.js";
4
+ // Installs the Denum class that the ranked hash `.#n` constructs (007.32).
5
+ import "./denum-prologue.js";
4
6
  // Installs the RotorRouter class that list division answers (007.27c).
5
7
  import "./router-prologue.js";
6
8
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";