hclang 0.44.1 → 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.
- package/esm/lib/bundle/hc-sources.js +395 -0
- package/esm/lib/execute/denum-prologue.js +88 -0
- package/esm/lib/execute/hc-eval.js +2 -0
- package/esm/lib/frames/denum-hash.js +166 -0
- package/esm/lib/frames/denum.js +357 -0
- package/esm/lib/frames/frame-array.js +1 -1
- package/esm/lib/frames/frame-expr.js +3 -3
- package/esm/lib/frames/frame-lazy.js +1 -1
- package/esm/lib/frames/frame-list.js +1 -1
- package/esm/lib/frames/frame-name.js +8 -0
- package/esm/lib/frames/frame-symbol.js +1 -1
- package/esm/lib/frames/frame.js +30 -4
- package/esm/lib/frames.js +2 -0
- package/esm/lib/ops/denum.js +120 -0
- package/esm/lib/ops.js +3 -0
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
|
|
2
|
+
import { Frame } from "../frames/frame.js";
|
|
3
|
+
import { FrameArray } from "../frames/frame-array.js";
|
|
4
|
+
import { FrameCount } from "../frames/frame-count.js";
|
|
5
|
+
import { FrameString } from "../frames/frame-string.js";
|
|
6
|
+
import { add, arity, conjugate, denum, DenumError, multiply, observe, opposite, promote, residual, schemaName, signatureName, subtract, } from "../frames/denum.js";
|
|
7
|
+
/**
|
|
8
|
+
* The operations `denum-engine` performs, selected by the first element of its
|
|
9
|
+
* argument. The argument is `[op, rank, count, loads, rank, count, loads]`: the
|
|
10
|
+
* left Denum state, then the right one for the binary operations.
|
|
11
|
+
*/
|
|
12
|
+
export const DENUM_OPERATIONS = {
|
|
13
|
+
/** Validate a state and answer it as built. */
|
|
14
|
+
build: 0,
|
|
15
|
+
add: 1,
|
|
16
|
+
subtract: 2,
|
|
17
|
+
multiply: 3,
|
|
18
|
+
opposite: 4,
|
|
19
|
+
conjugate: 5,
|
|
20
|
+
/** Promote the left state to the rank of the right state's first slot. */
|
|
21
|
+
promote: 6,
|
|
22
|
+
/** The signed integer coordinate of each direction, an observation. */
|
|
23
|
+
observe: 7,
|
|
24
|
+
/** The native signature names of the left state's channels, as text. */
|
|
25
|
+
names: 8,
|
|
26
|
+
/** The schema name `CD[n]` of the left state's rank, as text. */
|
|
27
|
+
schema: 9,
|
|
28
|
+
/** Positive minus negative load total: the declared residual, an integer. */
|
|
29
|
+
residual: 10,
|
|
30
|
+
};
|
|
31
|
+
const counts = (frame) => {
|
|
32
|
+
const value = frame.referent();
|
|
33
|
+
return value instanceof FrameCount && typeof value.data === "bigint"
|
|
34
|
+
? value.data
|
|
35
|
+
: undefined;
|
|
36
|
+
};
|
|
37
|
+
/** The state a triple of Frames holds, or the contract failure. */
|
|
38
|
+
function readState(rank, count, loads) {
|
|
39
|
+
const r = rank === undefined ? undefined : counts(rank);
|
|
40
|
+
const c = count === undefined ? undefined : counts(count);
|
|
41
|
+
// Base Frame.elements() answers [this] for any non-aggregate, so a bare Count
|
|
42
|
+
// would read as a one-element list: require an aggregate, as the hash reader
|
|
43
|
+
// `storedState` does.
|
|
44
|
+
const list = loads?.referent();
|
|
45
|
+
const elements = list?.ownsIdentity() ? list.elements() : undefined;
|
|
46
|
+
const l = elements?.map(counts);
|
|
47
|
+
if (r === undefined || c === undefined || !l || l.some((x) => x === undefined)) {
|
|
48
|
+
throw new DenumError("$!!.invalid-denum");
|
|
49
|
+
}
|
|
50
|
+
if (r > 5n)
|
|
51
|
+
throw new DenumError("$!!.invalid-denum", `rank ${r}`);
|
|
52
|
+
return denum(Number(r), c, l);
|
|
53
|
+
}
|
|
54
|
+
const stateFrame = (state) => new FrameArray([
|
|
55
|
+
Frame.count(BigInt(state.rank)),
|
|
56
|
+
Frame.count(state.count),
|
|
57
|
+
new FrameArray(state.loads.map((load) => Frame.count(load))),
|
|
58
|
+
]);
|
|
59
|
+
/**
|
|
60
|
+
* `denum-engine`, the one native seam under the HC class in `hc/denum.hc`.
|
|
61
|
+
*
|
|
62
|
+
* It is pure arithmetic over the typed reference in `lib/frames/denum.ts`: it
|
|
63
|
+
* reads Counts and answers fresh data, touches no scope and holds no state,
|
|
64
|
+
* and it refuses anything malformed with a named error rather than guessing.
|
|
65
|
+
* The Denum itself is an HC class; this is only how that class reaches the
|
|
66
|
+
* Cayley–Dickson recurrence without a hand-written table in HC.
|
|
67
|
+
*/
|
|
68
|
+
export const DenumEngine = (_source, block) => {
|
|
69
|
+
const failure = block.referent().observationError();
|
|
70
|
+
if (failure)
|
|
71
|
+
return failure;
|
|
72
|
+
const args = block.referent().elements();
|
|
73
|
+
const op = args[0] === undefined ? undefined : counts(args[0]);
|
|
74
|
+
if (op === undefined)
|
|
75
|
+
return Frame.error("$!!.invalid-denum");
|
|
76
|
+
try {
|
|
77
|
+
const left = readState(args[1], args[2], args[3]);
|
|
78
|
+
switch (Number(op)) {
|
|
79
|
+
case DENUM_OPERATIONS.build:
|
|
80
|
+
return stateFrame(left);
|
|
81
|
+
case DENUM_OPERATIONS.opposite:
|
|
82
|
+
return stateFrame(opposite(left));
|
|
83
|
+
case DENUM_OPERATIONS.conjugate:
|
|
84
|
+
return stateFrame(conjugate(left));
|
|
85
|
+
case DENUM_OPERATIONS.observe:
|
|
86
|
+
return new FrameArray(observe(left).map((c) => Frame.signed(c)));
|
|
87
|
+
case DENUM_OPERATIONS.names:
|
|
88
|
+
return new FrameArray(Array.from({ length: arity(left.rank) }, (_, channel) => new FrameString(signatureName(left.rank, channel))));
|
|
89
|
+
case DENUM_OPERATIONS.residual:
|
|
90
|
+
return Frame.signed(residual(left));
|
|
91
|
+
case DENUM_OPERATIONS.schema:
|
|
92
|
+
return new FrameString(schemaName(left.rank));
|
|
93
|
+
case DENUM_OPERATIONS.promote: {
|
|
94
|
+
const target = args[4] === undefined ? undefined : counts(args[4]);
|
|
95
|
+
if (target === undefined || target > 5n) {
|
|
96
|
+
return Frame.error("$!.denum-rank");
|
|
97
|
+
}
|
|
98
|
+
return stateFrame(promote(left, Number(target)));
|
|
99
|
+
}
|
|
100
|
+
case DENUM_OPERATIONS.add:
|
|
101
|
+
case DENUM_OPERATIONS.subtract:
|
|
102
|
+
case DENUM_OPERATIONS.multiply: {
|
|
103
|
+
const right = readState(args[4], args[5], args[6]);
|
|
104
|
+
const operate = Number(op) === DENUM_OPERATIONS.add
|
|
105
|
+
? add
|
|
106
|
+
: Number(op) === DENUM_OPERATIONS.subtract
|
|
107
|
+
? subtract
|
|
108
|
+
: multiply;
|
|
109
|
+
return stateFrame(operate(left, right));
|
|
110
|
+
}
|
|
111
|
+
default:
|
|
112
|
+
return Frame.error("$!!.invalid-denum");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof DenumError)
|
|
117
|
+
return Frame.error(error.kind);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
};
|
package/esm/lib/ops.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IfElse, IfThen } from "./ops/conditionals.js";
|
|
2
|
+
import { DenumEngine } from "./ops/denum.js";
|
|
2
3
|
import { FrameOps } from "./ops/frame-ops.js";
|
|
3
4
|
import { MapElements, MapMembers, ReduceElements, ReduceMembers, SpliceElements, } from "./ops/iterators.js";
|
|
4
5
|
import { Add, Divide, Equals, GreaterThan, GreaterThanOrEqual, Identical, LessThan, LessThanOrEqual, Modulo, Multiply, Power, Subtract, TypeEquals, } from "./ops/math.js";
|
|
@@ -34,4 +35,6 @@ export const Ops = new FrameOps({
|
|
|
34
35
|
"^": BindType,
|
|
35
36
|
"^^": BindReturn,
|
|
36
37
|
"->": Arrow,
|
|
38
|
+
// The one native seam under `hc/denum.hc`: pure Cayley–Dickson arithmetic.
|
|
39
|
+
"denum-engine": DenumEngine,
|
|
37
40
|
});
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.45.0";
|