hclang 0.42.0 → 0.44.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 +1387 -400
- package/esm/lib/execute/demi-prologue.js +20 -8
- package/esm/lib/execute/hc-eval.js +2 -0
- package/esm/lib/execute/router-prologue.js +153 -0
- package/esm/lib/frames/fourth-hash.js +139 -5
- package/esm/lib/frames/frame-array.js +5 -2
- package/esm/lib/frames/frame-symbol.js +27 -0
- package/esm/lib/frames.js +1 -1
- package/esm/lib/ops/math.js +47 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -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,31 @@ export function demiClass() {
|
|
|
73
73
|
return loaded;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Constructs a Demi with the HC class: `Demi [
|
|
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).
|
|
77
79
|
*
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @param right The right load.
|
|
80
|
+
* @param count The full application Count.
|
|
81
|
+
* @param loads The ordered channel loads.
|
|
81
82
|
* @returns The new instance, or the class's failure.
|
|
82
83
|
*/
|
|
83
|
-
export function
|
|
84
|
+
export function constructDemiLoads(count, loads) {
|
|
84
85
|
const constructor = demiClass();
|
|
85
86
|
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
86
87
|
return constructor;
|
|
87
88
|
}
|
|
88
|
-
const state = new FrameArray([
|
|
89
|
+
const state = new FrameArray([count, new FrameArray([...loads])]);
|
|
89
90
|
return FrameExpr.answeredValue(constructor.call(state)).referent();
|
|
90
91
|
}
|
|
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,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 RotorRouter class that list division answers (007.27c).
|
|
5
|
+
import "./router-prologue.js";
|
|
4
6
|
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
5
7
|
import { evaluateResourceSource } from "./resource-import.js";
|
|
6
8
|
import { sigilizer } from "./sigilizer.js";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RotorRouter class, loaded from HC for list division.
|
|
3
|
+
*
|
|
4
|
+
* Dividing a list, `xs ./ n`, deals its elements into n channels and answers
|
|
5
|
+
* them as a `RotorRouter`, the HC class in `hc/rotor-router.hc`, so that the
|
|
6
|
+
* channels stay channels and a further division reads them breadth-first
|
|
7
|
+
* (occurrence/figure 007.27c). The ops package deals natively but cannot run
|
|
8
|
+
* HC, so this module installs the constructor it calls
|
|
9
|
+
* (`installDivisionCarrier`).
|
|
10
|
+
*
|
|
11
|
+
* As with the Demi class (`demi-prologue.ts`), the class is read from the
|
|
12
|
+
* compiled-in bundle, evaluated once per process on first use, in a namespace
|
|
13
|
+
* of its own with no host bindings and no root, and its outcome is kept,
|
|
14
|
+
* failure included. A division requested while the file is still loading is
|
|
15
|
+
* `$!.router-prologue-reentrant`.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
import { EvaluationScope, Frame, FrameArray, FrameExpr, installRouterRecognizer, } from "../frames.js";
|
|
20
|
+
import { installDivisionCarrier } from "../ops/math.js";
|
|
21
|
+
import { HC_SOURCES } from "../bundle/hc-sources.js";
|
|
22
|
+
import { evaluateSourceText } from "./resource-import.js";
|
|
23
|
+
/** The bundled file that defines the class. */
|
|
24
|
+
export const ROUTER_SOURCE = "hc/rotor-router.hc";
|
|
25
|
+
/** The name the file declares the constructor under. */
|
|
26
|
+
export const ROUTER_CLASS = "RotorRouter";
|
|
27
|
+
/**
|
|
28
|
+
* The builders the class file declares beside its constructor, which make an
|
|
29
|
+
* instance from channels already known to be admissible, without validating
|
|
30
|
+
* or copying them: `binary-router` for two channels, `channel-router` for any
|
|
31
|
+
* other number.
|
|
32
|
+
*/
|
|
33
|
+
export const ROUTER_BUILDERS = ["binary-router", "channel-router"];
|
|
34
|
+
let loaded;
|
|
35
|
+
let builders;
|
|
36
|
+
let loading = false;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates class source in a namespace of its own, answering its
|
|
39
|
+
* `RotorRouter` or the failure. Uncached: `routerClass` keeps the one result.
|
|
40
|
+
*
|
|
41
|
+
* @param source The source text, or undefined when the bundle lacks it.
|
|
42
|
+
* @returns The constructor, or an error.
|
|
43
|
+
*/
|
|
44
|
+
export function loadRouterClass(source) {
|
|
45
|
+
if (source === undefined) {
|
|
46
|
+
return Frame.error(`$!.router-prologue-missing ${ROUTER_SOURCE}`);
|
|
47
|
+
}
|
|
48
|
+
const namespace = new FrameArray([]);
|
|
49
|
+
const result = evaluateSourceText(source, EvaluationScope.root(namespace));
|
|
50
|
+
if (result.isFailedResult() || result.observationError())
|
|
51
|
+
return result;
|
|
52
|
+
const constructor = namespace.getOwn(ROUTER_CLASS);
|
|
53
|
+
if (constructor.is.missing) {
|
|
54
|
+
return Frame.error(`$!.router-prologue-missing ${ROUTER_CLASS}`);
|
|
55
|
+
}
|
|
56
|
+
const [binary, channel] = ROUTER_BUILDERS.map((key) => namespace.getOwn(key));
|
|
57
|
+
if (binary.is.missing || channel.is.missing) {
|
|
58
|
+
return Frame.error(`$!.router-prologue-missing ${ROUTER_BUILDERS}`);
|
|
59
|
+
}
|
|
60
|
+
builders = { binary, channel };
|
|
61
|
+
return constructor;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The `RotorRouter` constructor closure, evaluated from the bundle on first
|
|
65
|
+
* use.
|
|
66
|
+
*
|
|
67
|
+
* @returns The constructor, or the error that loading it answered.
|
|
68
|
+
*/
|
|
69
|
+
export function routerClass() {
|
|
70
|
+
if (loaded)
|
|
71
|
+
return loaded;
|
|
72
|
+
if (loading)
|
|
73
|
+
return Frame.error("$!.router-prologue-reentrant");
|
|
74
|
+
loading = true;
|
|
75
|
+
try {
|
|
76
|
+
loaded = loadRouterClass(HC_SOURCES.get(ROUTER_SOURCE));
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
loading = false;
|
|
80
|
+
}
|
|
81
|
+
return loaded;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Constructs a router with the HC class: `RotorRouter [ch0, …, chk−1]`.
|
|
85
|
+
*
|
|
86
|
+
* @param channels The channel arrays, in order.
|
|
87
|
+
* @returns The new instance, or the class's failure.
|
|
88
|
+
*/
|
|
89
|
+
export function constructRouter(channels) {
|
|
90
|
+
const constructor = routerClass();
|
|
91
|
+
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
92
|
+
return constructor;
|
|
93
|
+
}
|
|
94
|
+
return FrameExpr.answeredValue(constructor.call(channels)).referent();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The channels of an instance of the shipped class with other than two
|
|
98
|
+
* channels, for `.####` (007.27); undefined for anything else.
|
|
99
|
+
*
|
|
100
|
+
* Recognition mirrors the Demi's (007.25e): the source's own stored
|
|
101
|
+
* `channels`, a list of arrays, must rebuild through the constructor into a
|
|
102
|
+
* router `==` to the source, fields and methods included. Nothing of the
|
|
103
|
+
* source runs, so a record that only spells `channels` is not a router.
|
|
104
|
+
*
|
|
105
|
+
* @param source The observed Frame.
|
|
106
|
+
* @returns The stored channel arrays, or undefined.
|
|
107
|
+
*/
|
|
108
|
+
export function channelRouterChannels(source) {
|
|
109
|
+
const host = source.referent();
|
|
110
|
+
if (!host.ownsIdentity())
|
|
111
|
+
return undefined;
|
|
112
|
+
const stored = host.get_here("channels").referent();
|
|
113
|
+
if (!(stored instanceof FrameArray))
|
|
114
|
+
return undefined;
|
|
115
|
+
const channels = stored.elements().map((channel) => channel.referent());
|
|
116
|
+
if (channels.length === 0 || channels.length === 2)
|
|
117
|
+
return undefined;
|
|
118
|
+
if (!channels.every((channel) => channel instanceof FrameArray)) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const candidate = constructRouter(new FrameArray(channels.map((channel) => new FrameArray([...channel.elements()]))));
|
|
122
|
+
if (candidate.isFailedResult() || candidate.observationError()) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
return candidate.typeEquals(host) === Frame.all ? channels : undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The router a list division answers, from the channels it just dealt.
|
|
129
|
+
*
|
|
130
|
+
* Dealt channels are fresh arrays and a round-robin profile by construction,
|
|
131
|
+
* so they go straight to the class's own builder: validating and copying them
|
|
132
|
+
* through the public constructor costs a closure call per channel, which made
|
|
133
|
+
* a router's breadth-first readout (a division by its longest channel's
|
|
134
|
+
* length) dominate its division (PR #482 review). The instance is the one the
|
|
135
|
+
* constructor would build from the same channels.
|
|
136
|
+
*
|
|
137
|
+
* @param channels The dealt channel arrays, at least one.
|
|
138
|
+
* @returns The new router, or the class's failure.
|
|
139
|
+
*/
|
|
140
|
+
export function dealtRouter(channels) {
|
|
141
|
+
const constructor = routerClass();
|
|
142
|
+
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
143
|
+
return constructor;
|
|
144
|
+
}
|
|
145
|
+
if (!builders)
|
|
146
|
+
return Frame.error("$!.router-unavailable /");
|
|
147
|
+
const build = channels.elements().length === 2
|
|
148
|
+
? builders.binary
|
|
149
|
+
: builders.channel;
|
|
150
|
+
return FrameExpr.answeredValue(build.call(channels)).referent();
|
|
151
|
+
}
|
|
152
|
+
installDivisionCarrier(dealtRouter);
|
|
153
|
+
installRouterRecognizer(channelRouterChannels);
|
|
@@ -12,11 +12,136 @@ let construct;
|
|
|
12
12
|
export function installDemiConstructor(constructor) {
|
|
13
13
|
construct = constructor;
|
|
14
14
|
}
|
|
15
|
+
let recognizeRouter;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
17
|
+
* Installs how `.####` recognizes a channel router (007.27).
|
|
18
|
+
*
|
|
19
|
+
* @param recognizer Answers a channel router's channels, or undefined.
|
|
20
|
+
*/
|
|
21
|
+
export function installRouterRecognizer(recognizer) {
|
|
22
|
+
recognizeRouter = recognizer;
|
|
23
|
+
}
|
|
24
|
+
/** A Frame read as an exact nonnegative Count, or undefined. */
|
|
25
|
+
function exactCount(frame) {
|
|
26
|
+
const value = frame.referent();
|
|
27
|
+
return value instanceof FrameCount && typeof value.data === "bigint" &&
|
|
28
|
+
value.data >= 0n
|
|
29
|
+
? value
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The stored loads of a Demi instance: its own `loads` field, a nonempty list
|
|
34
|
+
* whose elements are all exact Counts, or undefined.
|
|
35
|
+
*
|
|
36
|
+
* Only the instance's own field is read (`get_here`), never a declared parent
|
|
37
|
+
* or a method, and the list's elements are read as stored, so nothing runs.
|
|
38
|
+
*/
|
|
39
|
+
function storedLoads(source) {
|
|
40
|
+
const value = source.get_here("loads").referent();
|
|
41
|
+
if (!value.ownsIdentity())
|
|
42
|
+
return undefined;
|
|
43
|
+
const elements = value.elements();
|
|
44
|
+
if (elements.length === 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
const loads = elements.map(exactCount);
|
|
47
|
+
return loads.every((load) => load !== undefined)
|
|
48
|
+
? loads
|
|
49
|
+
: undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The intrinsic Demi path (007.25e). A constructed Demi is the one Frame whose
|
|
53
|
+
* fourth hash the three observers cannot decide: `Demi [0, 0, 0]` reads 0, 0,
|
|
54
|
+
* 0, exactly as `[]` does, yet it is a present state. Rather than let any
|
|
55
|
+
* class declare its own `.####`, the fourth hash recognizes an instance of the
|
|
56
|
+
* shipped class itself, and nothing else.
|
|
57
|
+
*
|
|
58
|
+
* A source is a Demi exactly when it has a stored Count `count` and a stored
|
|
59
|
+
* nonempty list of Counts `loads`, and it is `==` (same value and same type at
|
|
60
|
+
* every node, fields and methods included) to the Demi the shipped constructor
|
|
61
|
+
* builds from them. A binary Demi stores `left` and `right` too, and the
|
|
62
|
+
* comparison covers them. The answer is then that fresh reconstruction, of
|
|
63
|
+
* the source's own arity, never the source
|
|
64
|
+
* and never anything the source computed. No observer, method or closure of
|
|
65
|
+
* the source runs, so a forged `#`, `##`, `###` or `####` cannot steer it, and
|
|
66
|
+
* comparison is the language's own typed equality, not a spelling. Anything
|
|
67
|
+
* else, a foreign aggregate, a forged or edited instance, or a reconstruction
|
|
68
|
+
* that fails, is undefined, and the source takes the derived path like every
|
|
69
|
+
* other Frame.
|
|
70
|
+
*
|
|
71
|
+
* @param source The observed Frame.
|
|
72
|
+
* @returns A fresh Demi equal to the source, or undefined.
|
|
73
|
+
*/
|
|
74
|
+
function intrinsicDemi(source) {
|
|
75
|
+
if (!construct)
|
|
76
|
+
return undefined;
|
|
77
|
+
const host = source.referent();
|
|
78
|
+
if (!host.ownsIdentity())
|
|
79
|
+
return undefined;
|
|
80
|
+
const count = exactCount(host.get_here("count"));
|
|
81
|
+
const loads = storedLoads(host);
|
|
82
|
+
if (!count || !loads)
|
|
83
|
+
return undefined;
|
|
84
|
+
const candidate = construct(new FrameCount(count.data), loads.map((load) => new FrameCount(load.data)));
|
|
85
|
+
if (candidate.isFailedResult() || candidate.observationError()) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return candidate.typeEquals(host) === Frame.all ? candidate : undefined;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The channel-router path (007.27). A router of k channels routes to channel
|
|
92
|
+
* C mod k, which only a Demi of k loads follows; the binary Demi the observers
|
|
93
|
+
* derive follows parity, so for k other than two it would not be the router's
|
|
94
|
+
* shadow. An instance of the shipped `RotorRouter` class with other than two
|
|
95
|
+
* channels therefore answers the channel Demi of its Count and channel loads,
|
|
96
|
+
* `Demi [C, [load0, …]]`, where a load is the summed Size of a channel's
|
|
97
|
+
* children and an empty channel's load is 0. The binary router keeps the
|
|
98
|
+
* derived path, which already answers `Demi(C, L, R)`.
|
|
99
|
+
*
|
|
100
|
+
* Its Count is the children it holds; at Count zero it has no Demi, as the
|
|
101
|
+
* empty binary router and the empty host have none. Each child's Size is read
|
|
102
|
+
* once, and a failed Size is answered as it is.
|
|
103
|
+
*
|
|
104
|
+
* @param source The observed Frame.
|
|
105
|
+
* @returns The router's channel Demi, nil, an error, or undefined when the
|
|
106
|
+
* source is not a channel router.
|
|
107
|
+
*/
|
|
108
|
+
function channelRouterDemi(source) {
|
|
109
|
+
const channels = recognizeRouter?.(source);
|
|
110
|
+
if (!channels)
|
|
111
|
+
return undefined;
|
|
112
|
+
const count = channels.reduce((total, channel) => total + BigInt(channel.elements().length), 0n);
|
|
113
|
+
if (count === 0n)
|
|
114
|
+
return Frame.nil;
|
|
115
|
+
const loads = [];
|
|
116
|
+
for (const channel of channels) {
|
|
117
|
+
if (channel.elements().length === 0) {
|
|
118
|
+
loads.push(new FrameCount(0n));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const size = channel.sizeFor(Frame.kLEAVES);
|
|
122
|
+
if (size.observationError())
|
|
123
|
+
return size;
|
|
124
|
+
const load = exactCount(size);
|
|
125
|
+
if (!load)
|
|
126
|
+
return Frame.error("$!.demi-observations");
|
|
127
|
+
loads.push(new FrameCount(load.data));
|
|
128
|
+
}
|
|
129
|
+
if (!construct)
|
|
130
|
+
return Frame.error("$!.demi-unavailable");
|
|
131
|
+
return construct(new FrameCount(count), loads);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The fourth hash, `.####`. For a constructed Demi it is that Demi's own state
|
|
135
|
+
* (`intrinsicDemi`), Count zero included. For every other Frame it is derived
|
|
136
|
+
* 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 Demi's Count, kept whole
|
|
138
|
+
* rather than reduced to its parity (007.25c). It never folds, executes or
|
|
139
|
+
* caches the source, and reads each observer at most once.
|
|
140
|
+
*
|
|
141
|
+
* A derived source with Count zero is nil: a host with no children has no
|
|
142
|
+
* Demi, so `[].####` and `0.####` are nil while `(Demi [0, 0, 0]).####` is
|
|
143
|
+
* present. No class can declare `.####` for itself; only the three observers
|
|
144
|
+
* are declarable (`FrameArray.OBSERVATION_KEYS`).
|
|
20
145
|
*
|
|
21
146
|
* In order: a failure of the source or of any observer is answered as it is;
|
|
22
147
|
* no Count (nil) or Count zero is nil; nil residual is nil; observations that
|
|
@@ -31,6 +156,12 @@ export function observeDemi(source) {
|
|
|
31
156
|
const failure = source.observationError();
|
|
32
157
|
if (failure)
|
|
33
158
|
return failure;
|
|
159
|
+
const intrinsic = intrinsicDemi(source);
|
|
160
|
+
if (intrinsic)
|
|
161
|
+
return intrinsic;
|
|
162
|
+
const routed = channelRouterDemi(source);
|
|
163
|
+
if (routed)
|
|
164
|
+
return routed;
|
|
34
165
|
const n = source.sizeFor(Frame.kCOUNT);
|
|
35
166
|
if (n.observationError())
|
|
36
167
|
return n;
|
|
@@ -59,6 +190,9 @@ export function observeDemi(source) {
|
|
|
59
190
|
}
|
|
60
191
|
if (!construct)
|
|
61
192
|
return Frame.error("$!.demi-unavailable");
|
|
62
|
-
return construct(new FrameCount(n.data
|
|
193
|
+
return construct(new FrameCount(n.data), [
|
|
194
|
+
new FrameCount(sum / 2n),
|
|
195
|
+
new FrameCount(difference / 2n),
|
|
196
|
+
]);
|
|
63
197
|
}
|
|
64
198
|
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,
|
|
@@ -292,6 +292,15 @@ export class FrameSymbol extends FrameAtom {
|
|
|
292
292
|
if (this.is.address === true && Frame.SIZE_OPERATORS.includes(this.data)) {
|
|
293
293
|
return context.referent().sizeFor(this.data);
|
|
294
294
|
}
|
|
295
|
+
// A dotted arithmetic operator is the operator itself: `xs ./ 3` is
|
|
296
|
+
// `xs / 3` (GRAMMAR "Mathematical Operators"). Resolved as a name, it
|
|
297
|
+
// missed a named aggregate and was found in the scope the name was read
|
|
298
|
+
// in, so `xs .* 2` answered for that scope (007.27).
|
|
299
|
+
if (this.is.address === true &&
|
|
300
|
+
FrameSymbol.DOTTED_OPERATORS.includes(this.data) &&
|
|
301
|
+
!(context instanceof FrameSymbol && context.isPendingDeclaration())) {
|
|
302
|
+
return new FrameOperator(this.data).called_by(context);
|
|
303
|
+
}
|
|
295
304
|
// An address applied by a receiver reads that member, `o .x`. Two
|
|
296
305
|
// receivers take the name itself instead (#429). A pending declaration
|
|
297
306
|
// stores it, so `.k .x` keeps the key and `o k` reads `o.x` later; the
|
|
@@ -420,6 +429,24 @@ Object.defineProperty(FrameSymbol, "symbols", {
|
|
|
420
429
|
writable: true,
|
|
421
430
|
value: {}
|
|
422
431
|
});
|
|
432
|
+
/**
|
|
433
|
+
* The arithmetic operators a dot may prefix and still mean the operator,
|
|
434
|
+
* `.+ .- .* ./ .%% .**`. They dispatch as the bare operator does: the left
|
|
435
|
+
* operand's declared method, then the global operation.
|
|
436
|
+
*/
|
|
437
|
+
Object.defineProperty(FrameSymbol, "DOTTED_OPERATORS", {
|
|
438
|
+
enumerable: true,
|
|
439
|
+
configurable: true,
|
|
440
|
+
writable: true,
|
|
441
|
+
value: [
|
|
442
|
+
"+",
|
|
443
|
+
"-",
|
|
444
|
+
"*",
|
|
445
|
+
"/",
|
|
446
|
+
"%%",
|
|
447
|
+
"**",
|
|
448
|
+
]
|
|
449
|
+
});
|
|
423
450
|
export class FrameOperator extends FrameSymbol {
|
|
424
451
|
constructor(source, meta = NilContext) {
|
|
425
452
|
super(source, meta);
|
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 { installDemiConstructor, observeDemi, } from "./frames/fourth-hash.js";
|
|
30
|
+
export { installDemiConstructor, installRouterRecognizer, observeDemi, } 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/ops/math.js
CHANGED
|
@@ -3,6 +3,8 @@ import { Frame } from "../frames/frame.js";
|
|
|
3
3
|
import { FrameNumeric } from "../frames/frame-numeric.js";
|
|
4
4
|
import { FrameArray } from "../frames/frame-array.js";
|
|
5
5
|
import { FrameCount } from "../frames/frame-count.js";
|
|
6
|
+
import { FrameGroup } from "../frames/frame-group.js";
|
|
7
|
+
import { REPETITION_ELEMENT_LIMIT } from "../frames/frame-numeric.js";
|
|
6
8
|
/** Applies a numeric operation, or answers nil for any other pair. */
|
|
7
9
|
const numeric = (source, block, operation) => {
|
|
8
10
|
return source instanceof FrameNumeric && block instanceof FrameNumeric
|
|
@@ -40,7 +42,51 @@ export const Multiply = (source, block) => {
|
|
|
40
42
|
return FrameArray.starCount(left, block);
|
|
41
43
|
return Frame.error("$!.star-domain *");
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* `/`, also spelled `./`. A numeric pair keeps the exact numeric ladder. An
|
|
47
|
+
* ordered aggregate, an array or a group, divided by a positive Count n is
|
|
48
|
+
* dealt into n channels (007.27): the element at index i goes to channel
|
|
49
|
+
* i mod n, so `[A, B, C, D, E, F, G] / 3` is the n-channel `RotorRouter`
|
|
50
|
+
* whose channels are `[[A, D, G], [B, E], [C, F]]`. Anything else answers nil,
|
|
51
|
+
* as before.
|
|
52
|
+
*/
|
|
53
|
+
export const Divide = (source, block) => {
|
|
54
|
+
const left = source.referent();
|
|
55
|
+
if (left instanceof FrameArray || left instanceof FrameGroup) {
|
|
56
|
+
return failure(left) ?? failure(block) ?? deal(left, block);
|
|
57
|
+
}
|
|
58
|
+
return arithmetic(source, block, (left, right) => left.divide(right));
|
|
59
|
+
};
|
|
60
|
+
let carrier;
|
|
61
|
+
/**
|
|
62
|
+
* Installs what list division answers its channels with.
|
|
63
|
+
*
|
|
64
|
+
* @param construct The constructor, called once per division.
|
|
65
|
+
*/
|
|
66
|
+
export function installDivisionCarrier(construct) {
|
|
67
|
+
carrier = construct;
|
|
68
|
+
}
|
|
69
|
+
const deal = (source, block) => {
|
|
70
|
+
const divisor = block.referent();
|
|
71
|
+
if (!(divisor instanceof FrameCount) || typeof divisor.data !== "bigint") {
|
|
72
|
+
return Frame.error("$!.division-domain /");
|
|
73
|
+
}
|
|
74
|
+
if (divisor.data === 0n)
|
|
75
|
+
return Frame.error("$!.division-by-zero /");
|
|
76
|
+
const elements = source.elements();
|
|
77
|
+
if (divisor.data > REPETITION_ELEMENT_LIMIT &&
|
|
78
|
+
divisor.data > BigInt(elements.length)) {
|
|
79
|
+
return Frame.error(`$!.repetition-size ${REPETITION_ELEMENT_LIMIT}`);
|
|
80
|
+
}
|
|
81
|
+
const n = Number(divisor.data);
|
|
82
|
+
const channels = Array.from({ length: n }, () => []);
|
|
83
|
+
elements.forEach((element, index) => {
|
|
84
|
+
channels[index % n].push(element);
|
|
85
|
+
});
|
|
86
|
+
if (!carrier)
|
|
87
|
+
return Frame.error("$!.router-unavailable /");
|
|
88
|
+
return carrier(new FrameArray(channels.map((channel) => new FrameArray(channel))));
|
|
89
|
+
};
|
|
44
90
|
export const Modulo = (source, block) => arithmetic(source, block, (left, right) => left.modulo(right));
|
|
45
91
|
export const Power = (source, block) => arithmetic(source, block, (left, right) => left.power(right));
|
|
46
92
|
export const Equals = (source, block) => {
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.44.0";
|