hclang 0.37.1 → 0.38.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.
@@ -1,4 +1,6 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
+ // Installs the Demi class that `.####` constructs (011.20).
3
+ import "./demi-prologue.js";
2
4
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
3
5
  import { evaluateResourceSource } from "./resource-import.js";
4
6
  import { sigilizer } from "./sigilizer.js";
@@ -54,7 +56,7 @@ export class HCEval {
54
56
  * Creates a lexical pipe for evaluating expressions.
55
57
  */
56
58
  static make_pipe(out, fileScope = out, hostNamespace = Frame.nil) {
57
- return makeSourcePipe(new EvalPipe(out, fileScope, hostNamespace), { importSource: evaluateResourceSource });
59
+ return makeSourcePipe(new EvalPipe(out, fileScope, hostNamespace), { importSource: evaluateResourceSource, strictStructure: true });
58
60
  }
59
61
  constructor(out, fileScope = out, hostNamespace = Frame.nil) {
60
62
  Object.defineProperty(this, "out", {
@@ -75,6 +77,12 @@ export class HCEval {
75
77
  writable: true,
76
78
  value: hostNamespace
77
79
  });
80
+ Object.defineProperty(this, "evaluator", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
78
86
  Object.defineProperty(this, "pipe", {
79
87
  enumerable: true,
80
88
  configurable: true,
@@ -105,7 +113,11 @@ export class HCEval {
105
113
  writable: true,
106
114
  value: false
107
115
  });
108
- this.pipe = HCEval.make_pipe(out, fileScope, hostNamespace);
116
+ this.evaluator = new EvalPipe(out, fileScope, hostNamespace);
117
+ this.pipe = makeSourcePipe(this.evaluator, {
118
+ importSource: evaluateResourceSource,
119
+ strictStructure: true,
120
+ });
109
121
  this.lex = this.pipe;
110
122
  }
111
123
  /** Reuses this source unit and host while directing results elsewhere. */
@@ -155,7 +167,8 @@ export class HCEval {
155
167
  if (!activeDocument) {
156
168
  this.checkInput(input);
157
169
  }
158
- const result = source.scanInto(this.lex, endOfLine);
170
+ const scanned = source.scanInto(this.lex, false);
171
+ const result = endOfLine ? this.pipe.endLine(scanned) : scanned;
159
172
  this.lex = result.is.lexical === true ? result : this.pipe;
160
173
  if (result.is.error === true) {
161
174
  this.lexicalError = result.toString();
@@ -174,21 +187,30 @@ export class HCEval {
174
187
  complete = result.is.error !== true;
175
188
  this.lexicalError = complete ? null : result.toString();
176
189
  }
177
- else if (this.needsFinish) {
178
- this.pipe.finish(Frame.nil);
179
- this.lexicalError = null;
190
+ else if (this.needsFinish || this.pipe.level !== 0) {
191
+ const result = this.pipe.finish(Frame.nil);
192
+ complete = result.is.error !== true;
193
+ this.lexicalError = complete ? null : result.toString();
180
194
  }
181
195
  else {
182
196
  this.lexicalError = null;
183
197
  }
184
198
  if (!complete) {
185
- this.pipe = HCEval.make_pipe(this.out, this.fileScope, this.hostNamespace);
199
+ this.evaluator = new EvalPipe(this.out, this.fileScope, this.hostNamespace);
200
+ this.pipe = makeSourcePipe(this.evaluator, {
201
+ importSource: evaluateResourceSource,
202
+ strictStructure: true,
203
+ });
186
204
  }
187
205
  this.lex = this.pipe;
188
206
  this.inputBuffer = "";
189
207
  this.needsFinish = false;
190
208
  return complete;
191
209
  }
210
+ /** Runtime failures are separate from lexical completion (testdocs may expect them). */
211
+ hasFailures() {
212
+ return this.evaluator.failed;
213
+ }
192
214
  error() {
193
215
  return this.lexicalError;
194
216
  }
@@ -1,6 +1,6 @@
1
1
  import { Frame, FrameInt, FrameOperator, FrameSchema, FrameString, FrameSymbol, } from "../frames.js";
2
2
  import { Token } from "./lex.js";
3
- import { sigilizer } from "./sigilizer.js";
3
+ import { lexicalError, sigilizer } from "./sigilizer.js";
4
4
  import { getSyntax } from "./syntax.js";
5
5
  function ensure_factory(factory) {
6
6
  if (factory instanceof Frame) {
@@ -19,6 +19,12 @@ export class LexPipe extends Frame {
19
19
  writable: true,
20
20
  value: void 0
21
21
  });
22
+ Object.defineProperty(this, "logicalEnd", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: false
27
+ });
22
28
  Object.defineProperty(this, "angleLookahead", {
23
29
  enumerable: true,
24
30
  configurable: true,
@@ -59,6 +65,16 @@ export class LexPipe extends Frame {
59
65
  this.emitImportArrow();
60
66
  return super.scan(argument);
61
67
  }
68
+ /** Flush a logical source line while leaving open structures for later lines. */
69
+ endLine(receiver) {
70
+ this.logicalEnd = true;
71
+ try {
72
+ return sigilizer.scan(receiver, FrameSymbol.end());
73
+ }
74
+ finally {
75
+ this.logicalEnd = false;
76
+ }
77
+ }
62
78
  finish(_parameter) {
63
79
  const pending = this.angleLookahead;
64
80
  this.angleLookahead = undefined;
@@ -71,7 +87,7 @@ export class LexPipe extends Frame {
71
87
  this.emitImportArrow();
72
88
  }
73
89
  const parser = this.get(Frame.kOUT);
74
- if (parser.strictStructure && this.level !== 0) {
90
+ if (parser.strictStructure && !this.logicalEnd && this.level !== 0) {
75
91
  return this.structureFailure("unclosed", `${this.level}`);
76
92
  }
77
93
  // A line that ends inside an open structure ends a term, as a newline
@@ -164,6 +180,6 @@ export class LexPipe extends Frame {
164
180
  parser.call(new Token(new FrameOperator("<-")));
165
181
  }
166
182
  structureFailure(kind, detail) {
167
- return Frame.error(`$!.parse-${kind}-structure ${detail}`);
183
+ return lexicalError(`$!.parse-${kind}-structure ${detail}`);
168
184
  }
169
185
  }
@@ -1,4 +1,4 @@
1
- import { Frame, FrameExpr, FrameGroup, FrameLazy, FrameResource, FrameSymbol, hasCharacterContent, } from "../frames.js";
1
+ import { Frame, FrameExpr, FrameGroup, FrameLazy, FrameResource, FrameString, FrameSymbol, hasCharacterContent, } from "../frames.js";
2
2
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
3
3
  import { LexPipe } from "./lex-pipe.js";
4
4
  import { ParsePipe } from "./parse-pipe.js";
@@ -120,6 +120,22 @@ function evaluateResourceSourceWithChain(resource, scope, activeImports) {
120
120
  ...activeImports,
121
121
  { hostNamespace: scope.hostNamespace, resource: spelling },
122
122
  ];
123
+ return evaluateElements(resource.elements(), scope, nextActiveImports);
124
+ }
125
+ /**
126
+ * Evaluates HC source text as an import would: example lines dropped, the first
127
+ * failed form failing the whole, and the last answer returned. Declarations
128
+ * land in the scope's write target. Used for source the program carries rather
129
+ * than reads, such as the Demi class (`demi-prologue.ts`).
130
+ *
131
+ * @param source The source text.
132
+ * @param scope The scope it evaluates in.
133
+ * @returns The last answer, or the first failure.
134
+ */
135
+ export function evaluateSourceText(source, scope) {
136
+ return evaluateElements([new FrameString(source)], scope, []);
137
+ }
138
+ function evaluateElements(elements, scope, nextActiveImports) {
123
139
  const progress = new ImportProgress();
124
140
  const lexer = makeSourcePipe(EvalPipe.scoped(progress, scope), {
125
141
  importSource: (nestedResource, nestedScope) => evaluateResourceSourceWithChain(nestedResource, nestedScope, nextActiveImports),
@@ -134,7 +150,6 @@ function evaluateResourceSourceWithChain(resource, scope, activeImports) {
134
150
  return progress.firstFailure;
135
151
  };
136
152
  const examples = new ExampleFilter();
137
- const elements = resource.elements();
138
153
  for (const element of elements) {
139
154
  if (element.isFailedResult())
140
155
  return element;
@@ -103,7 +103,10 @@ export class BoundMethod extends Frame {
103
103
  // the lookup order, and a shared body's captured scope is whichever instance
104
104
  // was built last, so a method would read another instance's fields.
105
105
  const result = this.method.call(argument, Frame.nil, state);
106
- if (result.isFailedResult())
106
+ // A mutating method answers its receiver, unless it answered an error. A
107
+ // diagnostic note such as `$!.name-missing` is one too, though it is not
108
+ // flagged, so it is answered rather than replaced by the receiver (011.20).
109
+ if (result.isFailedResult() || result.referent().isError())
107
110
  return result;
108
111
  return this.isMutating() ? state.receiver : result;
109
112
  }
@@ -0,0 +1,64 @@
1
+ import { Frame } from "./frame.js";
2
+ import { FrameCount } from "./frame-count.js";
3
+ import { FrameInt } from "./frame-int.js";
4
+ let construct;
5
+ /**
6
+ * Installs what `.####` answers a present Demi with. The Demi is an HC class,
7
+ * `Demi` in `hc/demi.hc`, so the frames package, which cannot run HC, takes
8
+ * its constructor from the evaluator (`lib/execute/demi-prologue.ts`).
9
+ *
10
+ * @param constructor The constructor, called once per present observation.
11
+ */
12
+ export function installDemiConstructor(constructor) {
13
+ construct = constructor;
14
+ }
15
+ /**
16
+ * The fourth hash, `.####`, derived only from the existing observers: Count n,
17
+ * Size s and residual r give the loads (s+r)/2 and (s−r)/2, and n's parity
18
+ * the phase. It never folds, executes or caches the source, and reads each
19
+ * observer at most once.
20
+ *
21
+ * In order: a failure of the source or of any observer is answered as it is;
22
+ * no Count (nil) or Count zero is nil; nil residual is nil; observations that
23
+ * are not exact Counts and an integer are `$!.demi-observations`; and loads
24
+ * that are negative or not whole are `$!.demi-coherence`. Only then is the
25
+ * Demi constructed (011.18b–m).
26
+ *
27
+ * @param source The observed Frame.
28
+ * @returns A Demi, nil, or an error.
29
+ */
30
+ export function observeDemi(source) {
31
+ const failure = source.observationError();
32
+ if (failure)
33
+ return failure;
34
+ const n = source.sizeFor(Frame.kCOUNT);
35
+ if (n.observationError())
36
+ return n;
37
+ if (n === Frame.nil)
38
+ return Frame.nil; // no Count, no Demi (011.18k)
39
+ if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
40
+ return Frame.error("$!.demi-count");
41
+ }
42
+ if (n.data === 0n)
43
+ return Frame.nil;
44
+ const s = source.sizeFor(Frame.kLEAVES);
45
+ if (s.observationError())
46
+ return s;
47
+ const r = source.sizeFor(Frame.kRESIDUAL);
48
+ if (r.observationError())
49
+ return r;
50
+ if (r === Frame.nil)
51
+ return Frame.nil;
52
+ if (!(s instanceof FrameCount) || !(r instanceof FrameInt) ||
53
+ typeof s.data !== "bigint" || typeof r.data !== "bigint" || s.data < 0n)
54
+ return Frame.error("$!.demi-observations");
55
+ const sum = s.data + r.data;
56
+ const difference = s.data - r.data;
57
+ if (sum < 0n || difference < 0n || sum % 2n !== 0n || difference % 2n !== 0n) {
58
+ return Frame.error("$!.demi-coherence");
59
+ }
60
+ if (!construct)
61
+ return Frame.error("$!.demi-unavailable");
62
+ return construct(new FrameCount(n.data % 2n === 0n ? 2n : 1n), new FrameCount(sum / 2n), new FrameCount(difference / 2n));
63
+ }
64
+ Frame.demi = observeDemi;
@@ -1,6 +1,3 @@
1
- // Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
2
- // FrameExpr exist before any subclass, whichever module is imported first.
3
- import "./frame-lazy.js";
4
1
  import { Frame } from "./frame.js";
5
2
  import { BoundMethod } from "./bound-method.js";
6
3
  import { methodEffect } from "./effect-marker.js";
@@ -138,8 +135,8 @@ export class FrameArray extends FrameList {
138
135
  return true;
139
136
  }
140
137
  /**
141
- * An evaluated array exposes ordered data for residual; properties and
142
- * declared parents are excluded.
138
+ * An array exposes its ordered stored contents for residual; properties
139
+ * and declared parents are excluded. Source forms are not executed.
143
140
  */
144
141
  supportsResidual() {
145
142
  return true;
@@ -268,6 +265,86 @@ export class FrameArray extends FrameList {
268
265
  return this;
269
266
  return new BoundMethod(method, this, false, methodEffect(FrameArray.TEXT_KEY)).call(Frame.nil);
270
267
  }
268
+ /**
269
+ * An aggregate observes its elements, so a class that keeps its state in
270
+ * fields observes as its empty element list: Count 0, Size 1, residual 0.
271
+ * One that declares a method named `#`, `##` or `###`, on itself or a
272
+ * declared parent, answers that method's result instead, the way one that
273
+ * declares `apply` decides its own application (011.20). Nothing declares
274
+ * one by default, so every other aggregate observes exactly as before.
275
+ *
276
+ * The answer must be the kind the operator answers: a Count for `#` and
277
+ * `##`, an exact integer for `###`. Anything else is
278
+ * `$!.declared-observation`, an error the method answered is answered as it
279
+ * is, and a method that observes its own receiver the same way, directly
280
+ * or through other declared observations, is `$!.cyclic-observation`.
281
+ * Nesting deeper than `OBSERVATION_DEPTH_LIMIT`, as a method that observes
282
+ * a fresh instance of its own class does, is `$!.observation-depth`.
283
+ *
284
+ * The method runs immutably, so it cannot write its receiver. It is still
285
+ * code the class wrote: it runs on every observation, with no caching, and
286
+ * may act on anything else it can reach, a mutable handle in scope
287
+ * included. Observation is pure only for classes that keep it pure.
288
+ *
289
+ * @param key A size operator.
290
+ * @returns The declared answer, or undefined when none is declared.
291
+ */
292
+ declaredObservation(key) {
293
+ if (!FrameArray.OBSERVATION_KEYS.includes(key))
294
+ return undefined;
295
+ const method = this.declaredMethod(key);
296
+ if (!method)
297
+ return undefined;
298
+ const active = FrameArray.observing.get(this) ?? new Set();
299
+ if (active.has(key))
300
+ return Frame.error(`$!.cyclic-observation .${key}`);
301
+ if (FrameArray.observationDepth >= FrameArray.OBSERVATION_DEPTH_LIMIT) {
302
+ return Frame.error(`$!.observation-depth .${key}`);
303
+ }
304
+ active.add(key);
305
+ FrameArray.observing.set(this, active);
306
+ FrameArray.observationDepth++;
307
+ let answer;
308
+ try {
309
+ answer = new BoundMethod(method, this, false, methodEffect(key)).call(Frame.nil).referent();
310
+ }
311
+ finally {
312
+ FrameArray.observationDepth--;
313
+ active.delete(key);
314
+ if (active.size === 0)
315
+ FrameArray.observing.delete(this);
316
+ }
317
+ const failure = answer.observationError();
318
+ if (failure)
319
+ return failure;
320
+ const data = answer.data;
321
+ const valid = key === Frame.kRESIDUAL
322
+ ? answer.className() === "FrameInt" || answer instanceof FrameCount
323
+ : answer instanceof FrameCount;
324
+ return valid && typeof data === "bigint"
325
+ ? answer
326
+ : Frame.error(`$!.declared-observation .${key}`);
327
+ }
328
+ /** A declared Count, Size or residual first; the list's own rule otherwise. */
329
+ sizeFor(key) {
330
+ const failure = this.observationError();
331
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
332
+ return failure;
333
+ return this.declaredObservation(key) ?? super.sizeFor(key);
334
+ }
335
+ /**
336
+ * A declared Size is also what this aggregate contributes inside another,
337
+ * so `[d, d].##` adds the declared Sizes rather than one terminal for each.
338
+ */
339
+ nativeSize(path) {
340
+ const failure = this.observationError();
341
+ if (failure)
342
+ return failure;
343
+ const declared = this.declaredObservation(Frame.kLEAVES);
344
+ if (declared === undefined)
345
+ return super.nativeSize(path);
346
+ return declared instanceof FrameCount ? declared.data : declared;
347
+ }
271
348
  /**
272
349
  * A method declared under `key` on this aggregate or its declared parents.
273
350
  *
@@ -385,3 +462,43 @@ Object.defineProperty(FrameArray, "TEXT_KEY", {
385
462
  writable: true,
386
463
  value: "toText"
387
464
  });
465
+ /**
466
+ * The size operators an aggregate may declare its own answer to (011.20):
467
+ * Count, Size and residual. `.####` is not among them, because it is always
468
+ * derived from these three, so a class that declares them gets it for free.
469
+ */
470
+ Object.defineProperty(FrameArray, "OBSERVATION_KEYS", {
471
+ enumerable: true,
472
+ configurable: true,
473
+ writable: true,
474
+ value: [
475
+ Frame.kCOUNT,
476
+ Frame.kLEAVES,
477
+ Frame.kRESIDUAL,
478
+ ]
479
+ });
480
+ /** Declared observations in progress, so one that reads itself fails. */
481
+ Object.defineProperty(FrameArray, "observing", {
482
+ enumerable: true,
483
+ configurable: true,
484
+ writable: true,
485
+ value: new Map()
486
+ });
487
+ /**
488
+ * How deeply declared observations may nest. A cycle through the same
489
+ * receivers is caught exactly; one that builds a fresh receiver each step
490
+ * is not, so nesting is bounded too, far above any real class's need.
491
+ */
492
+ Object.defineProperty(FrameArray, "OBSERVATION_DEPTH_LIMIT", {
493
+ enumerable: true,
494
+ configurable: true,
495
+ writable: true,
496
+ value: 32
497
+ });
498
+ /** Declared observations now running, across every receiver. */
499
+ Object.defineProperty(FrameArray, "observationDepth", {
500
+ enumerable: true,
501
+ configurable: true,
502
+ writable: true,
503
+ value: 0
504
+ });
@@ -4,6 +4,16 @@ export class FrameAtom extends Frame {
4
4
  constructor(meta = NilContext) {
5
5
  super(meta);
6
6
  }
7
+ /**
8
+ * A void atom, such as a comment, keeps an explicit Count zero; only nil
9
+ * itself has no Count (011.18k).
10
+ */
11
+ sizeFor(key) {
12
+ if (key === Frame.kCOUNT && this.is.void) {
13
+ return this.observationError() ?? Frame.count(0n);
14
+ }
15
+ return super.sizeFor(key);
16
+ }
7
17
  string_prefix() {
8
18
  return "";
9
19
  }
@@ -32,13 +32,18 @@ export class FrameCount extends FrameInt {
32
32
  }
33
33
  }
34
34
  /**
35
- * A count is its own size, so `.#` and `.##` both answer it (#411). A count
36
- * is not a Figure, so `.###` answers nil, as for any atom (010.04). The
37
- * spelling is the literal `Frame.kRESIDUAL`, since this module imports
38
- * `Frame` as a type only.
35
+ * A count is its own immediate count and Size (#411). Its residual, Count
36
+ * parity n mod 2, comes from the base Frame rule (011.18k, 011.18m).
37
+ * Unknown keys must not inherit the old accidental Count fallback.
39
38
  */
40
39
  sizeFor(key) {
41
- return key === "###" ? super.sizeFor(key) : this;
40
+ switch (key) {
41
+ case Frame.kCOUNT:
42
+ case Frame.kLEAVES:
43
+ return this;
44
+ default:
45
+ return super.sizeFor(key);
46
+ }
42
47
  }
43
48
  promoteOne() {
44
49
  return new FrameInt(this.data);
@@ -1,8 +1,5 @@
1
1
  import { Frame } from "./frame.js";
2
2
  import { FrameList } from "./frame-list.js";
3
- import { FrameName } from "./frame-name.js";
4
- import { FrameSchema } from "./frame-schema.js";
5
- import { FrameSymbol } from "./frame-symbol.js";
6
3
  import { FrameWord } from "./frame-word.js";
7
4
  import { EvaluationScope } from "./evaluation-scope.js";
8
5
  import { renderNested } from "./stringify.js";
@@ -115,11 +112,14 @@ export class FrameExpr extends FrameList {
115
112
  const value = item.in(resumedScope(item, scope));
116
113
  if (value.is.error === true)
117
114
  return value;
115
+ if (index === 0 && value.isSymbol() && value.is.address &&
116
+ Frame.SIZE_OPERATORS.includes(value.spelling()))
117
+ return value;
118
118
  // An explicit nil receiver still has a Size. The initial nil accumulator
119
119
  // is not a receiver, so a leading .## remains an address (#411).
120
- if (index > 0 && sum.is.void && value instanceof FrameSymbol &&
120
+ if (index > 0 && sum.is.void && value.isSymbol() &&
121
121
  value.is.address &&
122
- [Frame.kLEAVES, Frame.kRESIDUAL].includes(value.spelling())) {
122
+ Frame.SIZE_OPERATORS.includes(value.spelling())) {
123
123
  return value.called_by(sum);
124
124
  }
125
125
  if (index > 0 && value.is.operator === true) {
@@ -129,8 +129,8 @@ export class FrameExpr extends FrameList {
129
129
  }, Frame.nil);
130
130
  }
131
131
  schemaRetrieval(scope) {
132
- if (this.data.length !== 2 || !(this.data[0] instanceof FrameSymbol) ||
133
- !(this.data[1] instanceof FrameName) || this.data[1].source !== "<^>")
132
+ if (this.data.length !== 2 || !this.data[0].isSymbol() ||
133
+ !this.data[1].isName() || this.data[1].source !== "<^>")
134
134
  return undefined;
135
135
  return this.data[0].bindingSchema(resumedScope(this.data[0], scope));
136
136
  }
@@ -139,12 +139,12 @@ export class FrameExpr extends FrameList {
139
139
  return undefined;
140
140
  const name = unwrapSingleton(this.data[0]);
141
141
  const schema = unwrapSingleton(this.data[1]);
142
- if (!(name instanceof FrameName) || !(schema instanceof FrameSchema)) {
142
+ if (!name.isName() || !schema.isSchema()) {
143
143
  return undefined;
144
144
  }
145
145
  const setter = name.in(scope);
146
146
  const value = schema.in(scope);
147
- if (!(setter instanceof FrameSymbol) || !(value instanceof FrameSchema)) {
147
+ if (!setter.isSymbol() || !value.isSchema()) {
148
148
  return Frame.error("$!.unsupported-schema-definition");
149
149
  }
150
150
  return setter.defineSchema(value);
@@ -222,7 +222,7 @@ export function atomsOf(terms, sites = new Map(), resume) {
222
222
  if (terms.length < 2)
223
223
  return undefined;
224
224
  const head = firstAtom(terms[0]);
225
- if (!(head instanceof FrameName) || /^\.*$/.test(head.source)) {
225
+ if (!head.isName() || /^\.*$/.test(head.source)) {
226
226
  return undefined;
227
227
  }
228
228
  heads.add(head);
@@ -247,10 +247,10 @@ export function atomsOf(terms, sites = new Map(), resume) {
247
247
  atoms.push(scoped(term));
248
248
  }
249
249
  }
250
- else if (term instanceof FrameName) {
250
+ else if (term.isName()) {
251
251
  atoms.push(FrameWord.address(term.source, heads.has(term) ? term : undefined));
252
252
  }
253
- else if (term instanceof FrameSymbol) {
253
+ else if (term.isSymbol()) {
254
254
  const spelling = term.spelling();
255
255
  atoms.push(FrameWord.word(spelling, scope.get(spelling), resume));
256
256
  }
@@ -320,10 +320,10 @@ export function sizeAtomsOf(terms) {
320
320
  walkAtom(term.asArray()[0], path);
321
321
  path.delete(term);
322
322
  }
323
- else if (term instanceof FrameName) {
323
+ else if (term.isName()) {
324
324
  atoms.push(FrameWord.address(term.source));
325
325
  }
326
- else if (term instanceof FrameSymbol) {
326
+ else if (term.isSymbol()) {
327
327
  atoms.push(FrameWord.word(term.spelling()));
328
328
  }
329
329
  else {
@@ -449,7 +449,7 @@ export class FrameScoped extends Frame {
449
449
  }
450
450
  /** Sizes as its term does, `.#`, `.##` and `.###`; anything else is applied. */
451
451
  call(argument, parameter = Frame.nil) {
452
- if (argument instanceof FrameSymbol && argument.is.address === true &&
452
+ if (argument.isSymbol() && argument.is.address === true &&
453
453
  Frame.SIZE_OPERATORS.includes(argument.spelling())) {
454
454
  return this.sizeFor(argument.spelling());
455
455
  }
@@ -496,7 +496,7 @@ export function sitesAround(body) {
496
496
  }
497
497
  function unwrapSingleton(frame) {
498
498
  let result = frame;
499
- while (result instanceof FrameList && !(result instanceof FrameSchema) &&
499
+ while (result instanceof FrameList && !result.isSchema() &&
500
500
  result.size() === 1) {
501
501
  result = result.asArray()[0];
502
502
  }
@@ -1,6 +1,3 @@
1
- // Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
2
- // FrameExpr exist before any subclass, whichever module is imported first.
3
- import "./frame-lazy.js";
4
1
  import { FrameExpr } from "./frame-expr.js";
5
2
  import { Frame } from "./frame.js";
6
3
  import { FrameList } from "./frame-list.js";
@@ -1,5 +1,4 @@
1
1
  import { Frame } from "./frame.js";
2
- import { FrameLazy } from "./frame-lazy.js";
3
2
  import { BoundMethod } from "./bound-method.js";
4
3
  import { methodEffect } from "./effect-marker.js";
5
4
  /**
@@ -154,7 +153,7 @@ export class FrameHandle extends Frame {
154
153
  return links;
155
154
  }
156
155
  lookup_result(value, key) {
157
- if (value instanceof FrameLazy) {
156
+ if (value.isClosure()) {
158
157
  const effect = methodEffect(key);
159
158
  if (effect.mutating && this.mutable)
160
159
  this.copyOnWriteTarget();
@@ -216,3 +216,4 @@ Object.defineProperty(FrameInt, "NUMBER_CHAR", {
216
216
  writable: true,
217
217
  value: /\d/
218
218
  });
219
+ Frame.signed = (value) => new FrameInt(value);
@@ -12,6 +12,9 @@ import { renderSourceTerm } from "./frame-list.js";
12
12
  const capturedScopes = new WeakMap();
13
13
  const inlineCallbackReceiverStates = new WeakMap();
14
14
  export class FrameLazy extends FrameExpr {
15
+ isClosure() {
16
+ return true;
17
+ }
15
18
  constructor(data, meta = NilContext) {
16
19
  super(data, meta);
17
20
  Object.defineProperty(this, "signature", {
@@ -95,9 +98,9 @@ export class FrameLazy extends FrameExpr {
95
98
  /**
96
99
  * `.#` counts the body's represented words (#429). `.##` sums their native
97
100
  * Sizes without execution or evaluation-site registration; an empty body
98
- * retains Size 1. A closure's words are executable syntax, so it has no
99
- * ordered data plane for `.###` and answers nil (010.08). The operator
100
- * reaches a closure as its argument and is answered before its body runs.
101
+ * retains Size 1. Residual alternates complete stored-word Sizes; Demi
102
+ * derives from those observations (011.18c). The operator reaches a closure
103
+ * as its argument and is answered before its body runs.
101
104
  */
102
105
  sizeOperator(argument) {
103
106
  if (argument instanceof FrameSymbol && argument.is.address === true &&
@@ -144,13 +144,22 @@ export class FrameList extends Frame {
144
144
  }
145
145
  /** Immediate count is unchanged; Size and residual share native child sizes. */
146
146
  sizeFor(key) {
147
+ const failure = this.observationError();
148
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
149
+ return failure;
147
150
  if (key === Frame.kCOUNT) {
148
- return new FrameCount(BigInt(this.countedElements().length));
151
+ const elements = this.sizeElements();
152
+ return elements instanceof Frame
153
+ ? elements
154
+ : new FrameCount(BigInt(elements.length));
149
155
  }
150
156
  return key === Frame.kRESIDUAL ? this.residual() : super.sizeFor(key);
151
157
  }
152
158
  /** Empty aggregates retain one terminal; shared descendants count per occurrence. */
153
159
  nativeSize(path) {
160
+ const failure = this.observationError();
161
+ if (failure)
162
+ return failure;
154
163
  if (path.has(this))
155
164
  return Frame.error("$!.cyclic-aggregate .##");
156
165
  path.add(this);
@@ -173,21 +182,24 @@ export class FrameList extends Frame {
173
182
  path.delete(this);
174
183
  }
175
184
  }
176
- /** Only concrete ordered data hosts opt in, never executable/matcher syntax. */
185
+ /** Lists observe stored contents; schemas retain their separate semantics. */
177
186
  supportsResidual() {
178
- return false;
187
+ return true;
179
188
  }
180
189
  /** Alternate over immediate positions, using each child's complete Size. */
181
190
  residual() {
182
- if (!this.supportsResidual() || this.is.source === true)
191
+ if (!this.supportsResidual())
183
192
  return Frame.nil;
193
+ const elements = this.sizeElements();
194
+ if (elements instanceof Frame)
195
+ return elements;
184
196
  const path = new Set([this]);
185
197
  let signed = 0n;
186
198
  let positive = true;
187
- for (const element of this.countedElements()) {
199
+ for (const element of elements) {
188
200
  const size = element.referent().nativeSize(path);
189
201
  if (typeof size !== "bigint")
190
- return Frame.nil;
202
+ return size;
191
203
  signed += positive ? size : -size;
192
204
  positive = !positive;
193
205
  }