hclang 0.43.0 → 0.44.1

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.
@@ -55,12 +55,7 @@ export class FrameExpr extends FrameList {
55
55
  }
56
56
  let result = Frame.nil;
57
57
  for (const run of commaRuns(body)) {
58
- const [item] = run;
59
- result = run.length > 1
60
- ? FrameExpr.commaGroup(run, scope)
61
- : item instanceof FrameExpr
62
- ? item.evaluate(scope)
63
- : item.in(scope);
58
+ result = FrameExpr.evaluateRun(run, scope);
64
59
  // A sequence stops at the first failing statement, because later
65
60
  // statements were written to run after the earlier ones succeeded.
66
61
  if (result.isFailedResult())
@@ -68,6 +63,42 @@ export class FrameExpr extends FrameList {
68
63
  }
69
64
  return result;
70
65
  }
66
+ /**
67
+ * `evaluateBody`, one statement at a time.
68
+ *
69
+ * The generator yields after each statement of a sequenced body and returns
70
+ * the body's value, with the same stops and the same scope as
71
+ * `evaluateBody`, so a body stepped to completion answers what a called one
72
+ * answers. A body that is not a sequence, or has one term, is one step. The
73
+ * statement is the finest boundary the language defines between two
74
+ * effects of one body, so it is the unit an event dispatcher may interleave
75
+ * at (`event-dispatch.ts`); nothing inside a statement is a boundary.
76
+ */
77
+ static *stepBody(body, input, sequence = false) {
78
+ const scope = EvaluationScope.from(input);
79
+ if (body.length === 1 || !sequence) {
80
+ const result = FrameExpr.evaluateBody(body, scope, sequence);
81
+ yield result;
82
+ return result;
83
+ }
84
+ let result = Frame.nil;
85
+ for (const run of commaRuns(body)) {
86
+ result = FrameExpr.evaluateRun(run, scope);
87
+ yield result;
88
+ if (result.isFailedResult())
89
+ return result;
90
+ }
91
+ return result;
92
+ }
93
+ /** One statement of a sequenced body: a comma group, or a single term. */
94
+ static evaluateRun(run, scope) {
95
+ const [item] = run;
96
+ return run.length > 1
97
+ ? FrameExpr.commaGroup(run, scope)
98
+ : item instanceof FrameExpr
99
+ ? item.evaluate(scope)
100
+ : item.in(scope);
101
+ }
71
102
  call(argument, parameter = Frame.nil) {
72
103
  return this.in(EvaluationScope.call(argument, parameter));
73
104
  }
@@ -132,6 +132,18 @@ export class FrameLazy extends FrameExpr {
132
132
  in(input = []) {
133
133
  return this.bind(input);
134
134
  }
135
+ /** The scope this bound copy captured; a template no read bound has none. */
136
+ capturedScope() {
137
+ return capturedScopes.get(this) ?? this.legacyCapture();
138
+ }
139
+ /**
140
+ * The scope a call of this closure would evaluate its body in, built as
141
+ * `call` builds it, without running the body. A static walk of the body
142
+ * resolves names against this scope's lookup frames (`access-footprint.ts`).
143
+ */
144
+ scopeForCall(argument, parameter = Frame.nil, receiverState) {
145
+ return EvaluationScope.call(argument, parameter, this, this.capturedScope(), receiverState);
146
+ }
135
147
  /** Returns state only when this literal was evaluated in that invocation. */
136
148
  receiverStateForCallback(receiverState) {
137
149
  return inlineCallbackReceiverStates.get(this) === receiverState
@@ -170,6 +182,29 @@ export class FrameLazy extends FrameExpr {
170
182
  }
171
183
  /** Evaluates this closure with optional bound receiver capability. */
172
184
  call(argument, parameter = Frame.nil, receiverState) {
185
+ const scope = this.prelude(argument, parameter, receiverState);
186
+ if (scope instanceof Frame)
187
+ return scope;
188
+ const result = FrameExpr.evaluateBody(this.data, scope, this.is.sequence === true);
189
+ return this.checkReturn(result);
190
+ }
191
+ /**
192
+ * `call`, one statement at a time (`FrameExpr.stepBody`). The generator
193
+ * yields after each statement and returns what `call` would have answered.
194
+ * A call that never reaches the body, a size operator, an empty body, or a
195
+ * refused argument, is one step.
196
+ */
197
+ *steps(argument, parameter = Frame.nil, receiverState) {
198
+ const scope = this.prelude(argument, parameter, receiverState);
199
+ if (scope instanceof Frame) {
200
+ yield scope;
201
+ return scope;
202
+ }
203
+ const result = yield* FrameExpr.stepBody(this.data, scope, this.is.sequence === true);
204
+ return this.checkReturn(result);
205
+ }
206
+ /** Everything `call` does before the body: an answer, or the body's scope. */
207
+ prelude(argument, parameter, receiverState) {
173
208
  if (argument instanceof FrameSymbol && argument.is.address === true &&
174
209
  argument.spelling() === "<>")
175
210
  return FrameType.of(this);
@@ -185,10 +220,7 @@ export class FrameLazy extends FrameExpr {
185
220
  const prepared = this.prepareArgument(argument);
186
221
  if (prepared.is.error)
187
222
  return prepared;
188
- const enclosing = capturedScopes.get(this) ?? this.legacyCapture();
189
- const scope = EvaluationScope.call(prepared, parameter, this, enclosing, receiverState);
190
- const result = FrameExpr.evaluateBody(this.data, scope, this.is.sequence === true);
191
- return this.checkReturn(result);
223
+ return this.scopeForCall(prepared, parameter, receiverState);
192
224
  }
193
225
  legacyCapture() {
194
226
  return this.up && !this.up.is.missing
@@ -236,7 +236,7 @@ export class FrameList extends Frame {
236
236
  for (const term of repeated)
237
237
  terms.push(term);
238
238
  }
239
- result.data = terms;
239
+ result.adoptData(terms);
240
240
  return result.finishRepetition();
241
241
  }
242
242
  /**
@@ -283,9 +283,16 @@ export class FrameList extends Frame {
283
283
  }
284
284
  copy() {
285
285
  const clone = super.copy();
286
- clone.data = this.itemsFor(clone, (item) => item);
286
+ clone.adoptData(this.itemsFor(clone, (item) => item));
287
287
  return clone;
288
288
  }
289
+ /**
290
+ * Replaces the whole data plane. The one assignment point, so an aggregate
291
+ * can observe the elements it stops and starts holding (`FrameArray`).
292
+ */
293
+ adoptData(data) {
294
+ this.data = data;
295
+ }
289
296
  /**
290
297
  * This frame's items as a copy holds them.
291
298
  *
@@ -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);
@@ -1,6 +1,7 @@
1
1
  import { NilContext } from "./context.js";
2
2
  import { renderNested } from "./stringify.js";
3
3
  import { hasEffectSubscribers, notifyEffect } from "./effect-registry.js";
4
+ import { guardAccess, noteCopiedHoldings, noteCreated, noteHolding, noteRead, noteWrite, PARENT_KEY, } from "./reference-tracking.js";
4
5
  /** Visibility levels for logical frame bindings. */
5
6
  export var Visibility;
6
7
  (function (Visibility) {
@@ -101,15 +102,22 @@ export class MetaFrame {
101
102
  const name = this.constructor.name;
102
103
  const id = name + "." + MetaFrame.id_count++;
103
104
  this.id = "$:" + id;
105
+ noteCreated(this);
104
106
  }
105
107
  /**
106
108
  * get_here retrieves a Frame by key from the current context.
107
109
  */
108
110
  get_here(key, _origin = this) {
111
+ // A keyed lookup is a read of this frame's state, a miss included: the
112
+ // miss is this frame's answer that the key is absent, and it decides
113
+ // whether the lookup falls through or matches a pattern. Guarded before
114
+ // anything is resolved, so a refusal sees and changes nothing
115
+ // (reference-tracking.ts).
116
+ guardAccess(this, "read");
117
+ noteRead(this);
109
118
  const exact = this.resolve_here(key, _origin);
110
- if (exact != null) {
119
+ if (exact != null)
111
120
  return exact.value;
112
- }
113
121
  return this.match_here(key);
114
122
  }
115
123
  /** Lets a projection perform another frame's local lookup without its links. */
@@ -268,9 +276,16 @@ export class MetaFrame {
268
276
  this.meta = {};
269
277
  }
270
278
  const previous = this.meta[key];
279
+ // Refused before the write lands, so a refusal changes nothing.
280
+ if (previous !== value)
281
+ guardAccess(this, "write");
271
282
  this.meta[key] = value;
272
- if (previous !== value && hasEffectSubscribers(this)) {
273
- notifyEffect(this);
283
+ noteHolding(this, key, value, previous);
284
+ if (previous !== value) {
285
+ noteWrite(this);
286
+ if (hasEffectSubscribers(this)) {
287
+ notifyEffect(this);
288
+ }
274
289
  }
275
290
  return this;
276
291
  }
@@ -287,7 +302,13 @@ export class MetaFrame {
287
302
  if (this.wouldCreateParentCycle(parent)) {
288
303
  return Frame.error("$!.cyclic-parent .^");
289
304
  }
305
+ guardAccess(this, "write");
306
+ const previous = this.parent;
290
307
  this.parent = parent;
308
+ // The parent edge is a holding too (reference-tracking.ts): it is how a
309
+ // name reaches the parent, though it conveys no authority of its own.
310
+ noteHolding(this, PARENT_KEY, parent, previous && !previous.is.missing ? previous : undefined);
311
+ noteWrite(this);
291
312
  return undefined;
292
313
  }
293
314
  /** Whether assigning parent would attach this frame to a cyclic chain. */
@@ -342,6 +363,10 @@ export class MetaFrame {
342
363
  }
343
364
  /**
344
365
  * match_here checks if a target string matches any key in the current context.
366
+ *
367
+ * A match rewrites the bound value's `source` to the target, which changes
368
+ * what every later reader of that binding sees, so it is a write of this
369
+ * frame: guarded before the value is touched, and noted after.
345
370
  */
346
371
  match_here(target) {
347
372
  let result = Frame.missing;
@@ -352,8 +377,10 @@ export class MetaFrame {
352
377
  if (pattern.test(target)) {
353
378
  result = value;
354
379
  if ("source" in result) {
380
+ guardAccess(this, "write");
355
381
  const sourced = result;
356
382
  sourced.source = target;
383
+ noteWrite(this);
357
384
  }
358
385
  }
359
386
  }
@@ -994,6 +1021,12 @@ export class Frame extends MetaFrame {
994
1021
  clone.meta = this.meta_copy();
995
1022
  clone.is = { ...this.is };
996
1023
  clone.id = `$:${this.className()}.${MetaFrame.id_count++}`;
1024
+ // `Object.create` bypasses the constructor, so the clone registers its
1025
+ // construction and its duplicated holdings here (reference-tracking.ts).
1026
+ noteCreated(clone);
1027
+ if (clone.meta !== NilContext) {
1028
+ noteCopiedHoldings(clone);
1029
+ }
997
1030
  return clone;
998
1031
  }
999
1032
  /**
@@ -1015,14 +1048,20 @@ export class Frame extends MetaFrame {
1015
1048
  let replaced = false;
1016
1049
  for (const [key, value] of this.meta_pairs()) {
1017
1050
  if (value === member) {
1051
+ if (!replaced)
1052
+ guardAccess(this, "write");
1018
1053
  this.meta[key] = replacement;
1054
+ noteHolding(this, key, replacement, member);
1019
1055
  replaced = true;
1020
1056
  }
1021
1057
  }
1022
1058
  // An element-plane commit is a mutation too; a copy-on-write install lands
1023
1059
  // on a fresh copy that carries no subscribers, so it never fires here.
1024
- if (replaced && hasEffectSubscribers(this)) {
1025
- notifyEffect(this);
1060
+ if (replaced) {
1061
+ noteWrite(this);
1062
+ if (hasEffectSubscribers(this)) {
1063
+ notifyEffect(this);
1064
+ }
1026
1065
  }
1027
1066
  return replaced;
1028
1067
  }
@@ -0,0 +1,275 @@
1
+ import { touchesIdentity } from "./effect-marker.js";
2
+ /** The key a declared parent is held under. */
3
+ export const PARENT_KEY = "^";
4
+ const isIndexKey = (key) => /^\d+$/.test(key);
5
+ const kindOf = (key) => key === PARENT_KEY ? "parent" : isIndexKey(key) ? "element" : "member";
6
+ /** Whether a key, by its spelling alone, hands out mutation authority. */
7
+ export const keyGrantsMutation = (key) => key !== PARENT_KEY && (isIndexKey(key) || touchesIdentity(key));
8
+ /** Identity → the bindings that hold it. Keyed weakly by the identity. */
9
+ const holdings = new WeakMap();
10
+ /** Identity → the number of mutations committed on it. */
11
+ const versions = new WeakMap();
12
+ /**
13
+ * What one event actually touched while its record was active.
14
+ *
15
+ * `reads` maps each frame read to the version it was first observed at;
16
+ * `writes` maps each frame written to the version its last commit produced.
17
+ * `created` holds the frames constructed while the record was active, so a
18
+ * consumer can tell an event's own fresh state (a functional-update copy, a
19
+ * call frame) from shared state it reached.
20
+ */
21
+ export class AccessRecord {
22
+ constructor() {
23
+ Object.defineProperty(this, "reads", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: new Map()
28
+ });
29
+ Object.defineProperty(this, "writes", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: new Map()
34
+ });
35
+ Object.defineProperty(this, "created", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: new WeakSet()
40
+ });
41
+ /**
42
+ * The certificate this record's accesses are confined to, if any. While a
43
+ * guard is installed, an access to a shared frame the guard does not allow
44
+ * is refused before it happens (`guardAccess`), so the record can never
45
+ * show an access outside what its guard admits.
46
+ */
47
+ Object.defineProperty(this, "guard", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ }
54
+ /** The frames this record saw written that it did not itself create. */
55
+ sharedWrites() {
56
+ return [...this.writes.keys()].filter((frame) => !this.created.has(frame));
57
+ }
58
+ /** The frames this record saw read that it did not itself create. */
59
+ sharedReads() {
60
+ return [...this.reads.keys()].filter((frame) => !this.created.has(frame));
61
+ }
62
+ }
63
+ /** The records currently receiving access notes, innermost last. */
64
+ const active = [];
65
+ /**
66
+ * An access a guard refused. It is thrown from the commit or read point
67
+ * *before* the access happens, so the state is as it was. It carries the
68
+ * record whose guard refused, so that only the dispatcher that installed that
69
+ * guard handles it: when dispatches nest, an inner dispatcher rethrows a
70
+ * refusal that belongs to an outer event, and the outer event ends there.
71
+ */
72
+ export class UncertifiedAccess extends Error {
73
+ constructor(frame, access, record) {
74
+ super(`$!.uncertified-${access} ${frame.className()}`);
75
+ Object.defineProperty(this, "frame", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: frame
80
+ });
81
+ Object.defineProperty(this, "access", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: access
86
+ });
87
+ Object.defineProperty(this, "record", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: record
92
+ });
93
+ this.name = "UncertifiedAccess";
94
+ }
95
+ }
96
+ /**
97
+ * Refuses `access` to `frame` if any active record's guard does not allow
98
+ * it, naming the outermost such record. Called at every commit point before
99
+ * the mutation lands and at every keyed or indexed lookup (hit or miss)
100
+ * before the value is handed out, so a refusal leaves the state untouched and
101
+ * the value unseen. Costs one length check when no record is active and one
102
+ * `WeakSet` lookup per guarded record otherwise.
103
+ */
104
+ export function guardAccess(frame, access) {
105
+ if (active.length === 0)
106
+ return;
107
+ for (const record of active) {
108
+ if (!record.guard || record.created.has(frame))
109
+ continue;
110
+ if (!record.guard(frame, access)) {
111
+ throw new UncertifiedAccess(frame, access, record);
112
+ }
113
+ }
114
+ }
115
+ /** Runs `work` with `record` receiving every access note it causes. */
116
+ export function withAccessRecord(record, work) {
117
+ active.push(record);
118
+ try {
119
+ return work();
120
+ }
121
+ finally {
122
+ active.pop();
123
+ }
124
+ }
125
+ /** Whether any record is active, so hot paths can skip their note early. */
126
+ export const isTracking = () => active.length > 0;
127
+ /** The number of mutations committed on `frame`; 0 for a never-written one. */
128
+ export function versionOf(frame) {
129
+ return versions.get(frame) ?? 0;
130
+ }
131
+ /**
132
+ * Notes a committed mutation of `frame`: its version advances, and every
133
+ * active record learns the version this write produced.
134
+ */
135
+ export function noteWrite(frame) {
136
+ const next = versionOf(frame) + 1;
137
+ versions.set(frame, next);
138
+ for (const record of active)
139
+ record.writes.set(frame, next);
140
+ }
141
+ /** Notes a read of `frame`, dated by the version current at the first read. */
142
+ export function noteRead(frame) {
143
+ if (active.length === 0)
144
+ return;
145
+ for (const record of active) {
146
+ if (!record.reads.has(frame))
147
+ record.reads.set(frame, versionOf(frame));
148
+ }
149
+ }
150
+ /** Notes that `frame` was constructed, for every active record. */
151
+ export function noteCreated(frame) {
152
+ if (active.length === 0)
153
+ return;
154
+ for (const record of active)
155
+ record.created.add(frame);
156
+ }
157
+ /**
158
+ * Notes that `holder` bound `value` under `key`, replacing `previous`. The
159
+ * key is a member name, an element index, or `PARENT_KEY`.
160
+ *
161
+ * Only an identity-owning value is indexed: an atom or a closure has no
162
+ * identity a handle could claim authority over. Rebinding a key releases the
163
+ * previous identity's holding first, so the index reflects the live bindings.
164
+ */
165
+ export function noteHolding(holder, key, value, previous) {
166
+ const identity = identityOf(value);
167
+ const released = previous === undefined ? undefined : identityOf(previous);
168
+ if (released && released !== identity)
169
+ dropHolding(released, holder, key);
170
+ if (identity)
171
+ addHolding(identity, holder, key);
172
+ }
173
+ /**
174
+ * The identity a stored value holds, if it holds one: the value itself when
175
+ * it owns identity, or the identity behind a handle, which is how an element
176
+ * plane stores a name's value (`[x_]` holds a handle on `x_`).
177
+ */
178
+ function identityOf(value) {
179
+ const target = value.referent();
180
+ return target.ownsIdentity() ? target : undefined;
181
+ }
182
+ /** Notes that `holder` no longer holds `previous` under `key`. */
183
+ export function noteReleased(holder, key, previous) {
184
+ const released = identityOf(previous);
185
+ if (released)
186
+ dropHolding(released, holder, key);
187
+ }
188
+ /**
189
+ * Notes that `holder` now holds `elements` in its element plane, element i
190
+ * under the index key `i`, releasing whatever it held under those indexes
191
+ * before. This is the commit point for every assignment of an aggregate's
192
+ * element plane as a whole; an append goes through `noteHolding` with its
193
+ * index.
194
+ */
195
+ export function noteElements(holder, elements, previous = []) {
196
+ for (let index = 0; index < previous.length; index++) {
197
+ const released = identityOf(previous[index]);
198
+ if (released)
199
+ dropHolding(released, holder, String(index));
200
+ }
201
+ for (let index = 0; index < elements.length; index++) {
202
+ const identity = identityOf(elements[index]);
203
+ if (identity)
204
+ addHolding(identity, holder, String(index));
205
+ }
206
+ }
207
+ /**
208
+ * Indexes the identity-owning bindings `clone` holds: its members, its
209
+ * declared parent, and, when given, its elements. A copy duplicates its
210
+ * source's bindings without committing them through `set`, so the index would
211
+ * otherwise miss every holder that is a copy, functional-update copies
212
+ * included.
213
+ */
214
+ export function noteCopiedHoldings(clone, elements = []) {
215
+ for (const [key, value] of clone.meta_pairs()) {
216
+ const identity = identityOf(value);
217
+ if (identity)
218
+ addHolding(identity, clone, key);
219
+ }
220
+ if (clone.hasDeclaredParent()) {
221
+ const parent = identityOf(clone.parent);
222
+ if (parent)
223
+ addHolding(parent, clone, PARENT_KEY);
224
+ }
225
+ noteElements(clone, elements);
226
+ }
227
+ /**
228
+ * The live bindings that hold `identity`, each graded by its key's marker.
229
+ *
230
+ * The answer is the ART inverse index: where the reference relation goes from
231
+ * holder to value, this goes from value to holders. It reports possession,
232
+ * which is distinct from active use: an event holding `x` mutably is not
233
+ * thereby writing it (see `AccessRecord`).
234
+ */
235
+ export function holdersOf(identity) {
236
+ const records = holdings.get(identity);
237
+ if (!records)
238
+ return [];
239
+ const result = [];
240
+ for (const record of records) {
241
+ result.push({
242
+ holder: record.holder,
243
+ key: record.key,
244
+ kind: kindOf(record.key),
245
+ mutable: keyGrantsMutation(record.key),
246
+ });
247
+ }
248
+ return result;
249
+ }
250
+ /** The holdings of `identity` whose key claims mutation authority. */
251
+ export function mutableHoldersOf(identity) {
252
+ return holdersOf(identity).filter((holding) => holding.mutable);
253
+ }
254
+ function addHolding(identity, holder, key) {
255
+ let records = holdings.get(identity);
256
+ if (!records) {
257
+ records = new Set();
258
+ holdings.set(identity, records);
259
+ }
260
+ for (const record of records) {
261
+ if (record.key === key && record.holder === holder)
262
+ return;
263
+ }
264
+ records.add({ holder, key });
265
+ }
266
+ function dropHolding(identity, holder, key) {
267
+ const records = holdings.get(identity);
268
+ if (!records)
269
+ return;
270
+ for (const record of records) {
271
+ if (record.holder === holder && record.key === key) {
272
+ records.delete(record);
273
+ }
274
+ }
275
+ }
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";
@@ -51,5 +51,11 @@ export { MetaFrame, Visibility } from "./frames/meta-frame.js";
51
51
  export { ScanDisposition, } from "./scan.js";
52
52
  export { contextEqual, contextString, NilContext, } from "./frames/context.js";
53
53
  export { hasEffectSubscribers, installEffectInvoker, isEffectObserver, notifyEffect, registerEffect, } from "./frames/effect-registry.js";
54
+ export { AccessRecord, guardAccess, holdersOf, isTracking, keyGrantsMutation, mutableHoldersOf, PARENT_KEY, UncertifiedAccess, versionOf, withAccessRecord, } from "./frames/reference-tracking.js";
55
+ export { footprintsConflict, isOpaque, isState, potentialFootprint, } from "./frames/access-footprint.js";
56
+ export { accessesOutside, dispatch, stepsOf, versionRead, versionWritten, } from "./frames/event-dispatch.js";
57
+ export { DISPATCH_KEY, dispatchNamespace } from "./frames/dispatch-host.js";
58
+ export { BoundMethod } from "./frames/bound-method.js";
59
+ export { FrameHandle } from "./frames/frame-handle.js";
54
60
  export { checkPartitions, partitionPlan, } from "./frames/partition-check.js";
55
61
  Frame.globals = Ops;
@@ -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
- export const Divide = (source, block) => arithmetic(source, block, (left, right) => left.divide(right));
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) => {
@@ -1 +1 @@
1
- export const VERSION = "0.43.0";
1
+ export const VERSION = "0.44.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",