hclang 0.37.0 → 0.37.3

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/README.md CHANGED
@@ -93,21 +93,21 @@ deno task test
93
93
 
94
94
  The root `deno.json` provides several tasks:
95
95
 
96
- | Task | Description |
97
- | ---------------------- | ------------------------------------------------- |
98
- | `deno task hc` | Launch the HC REPL |
99
- | `deno task setup` | Install pre-commit hooks |
100
- | `deno task test` | Run all tests (setup, format, lint, and tests) |
101
- | `deno task test:setup` | Run all pre-commit hooks on all files |
102
- | `deno task test:cli` | Test CLI package |
103
- | `deno task test:lib` | Test library package |
104
- | `deno task test:maml` | Test MAML package |
105
- | `deno task test:web` | Test web package |
106
- | `deno task test:bs` | Test BitScheme documentation |
107
- | `deno task test:doc` | Test HC documentation examples |
108
- | `deno task build` | Build native, npm, and web artifacts |
109
- | `deno task build:npm` | Generate the Node.js CLI package in `dist/npm` |
110
- | `deno task test:npm` | Pack and smoke-test the CLI package through `npx` |
96
+ | Task | Description |
97
+ | --------------------- | ------------------------------------------------- |
98
+ | `deno task hc` | Launch the HC REPL |
99
+ | `deno task setup` | Install pre-commit hooks |
100
+ | `deno task test` | Check formatting and lint, then run all tests |
101
+ | `deno task fix` | Format sources and apply lint fixes |
102
+ | `deno task test:cli` | Test CLI package |
103
+ | `deno task test:lib` | Test library package |
104
+ | `deno task test:maml` | Test MAML package |
105
+ | `deno task test:web` | Test web package |
106
+ | `deno task test:bs` | Test BitScheme documentation |
107
+ | `deno task test:doc` | Test HC documentation examples |
108
+ | `deno task build` | Build native, npm, and web artifacts |
109
+ | `deno task build:npm` | Generate the Node.js CLI package in `dist/npm` |
110
+ | `deno task test:npm` | Pack and smoke-test the CLI package through `npx` |
111
111
 
112
112
  ### BitScheme
113
113
 
@@ -161,8 +161,7 @@ deno task hc
161
161
  # Other platforms: pip install pre-commit
162
162
  ```
163
163
 
164
- Pre-commit hooks are automatically installed when you run `deno task test` or
165
- manually with `deno task setup`.
164
+ Install pre-commit hooks explicitly with `deno task setup`.
166
165
 
167
166
  4. Run tests:
168
167
 
@@ -170,8 +169,11 @@ deno task hc
170
169
  deno task test
171
170
  ```
172
171
 
173
- This will automatically set up pre-commit hooks, format code, run linters,
174
- and execute the test suite.
172
+ This checks formatting and lint without fixing sources, then runs the test
173
+ suite. Use `deno task fix` to format and apply lint fixes.
174
+
175
+ `deno task bundle:check` checks bundled HC sources without rewriting them;
176
+ after editing `hc/*.hc`, regenerate them with `deno task bundle:embed`.
175
177
 
176
178
  ### Project Structure
177
179
 
package/esm/cli/hc.js CHANGED
@@ -117,6 +117,7 @@ export async function main(hcEval, options) {
117
117
  let evaluated = false;
118
118
  let sourceStarted = false;
119
119
  let lexicalComplete = true;
120
+ let runtimeFailed = false;
120
121
  let test;
121
122
  if (options.verbose) {
122
123
  console.error("options", options);
@@ -128,6 +129,7 @@ export async function main(hcEval, options) {
128
129
  }
129
130
  const finishSource = (evaluator) => {
130
131
  const complete = evaluator.finish();
132
+ runtimeFailed ||= evaluator.hasFailures();
131
133
  if (!complete) {
132
134
  const reason = evaluator.error() ?? "incomplete lexical input";
133
135
  console.error(`HCEval.finish.failed: ${reason}`);
@@ -168,7 +170,7 @@ export async function main(hcEval, options) {
168
170
  if (test && lexicalComplete) {
169
171
  test.finish();
170
172
  }
171
- return lexicalComplete ? test?.exitCode ?? 0 : 1;
173
+ return lexicalComplete ? test?.exitCode ?? (runtimeFailed ? 1 : 0) : 1;
172
174
  }
173
175
  if (globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
174
176
  // One name at a time, through the dictionary. A wholesale read would hand the
@@ -1164,73 +1164,57 @@ export const HC_SOURCES = new Map([
1164
1164
  [
1165
1165
  "#!/usr/bin/env hc",
1166
1166
  "```",
1167
- "Figures are native frames (#454; issue occurrence/figure 010.02)",
1168
- "",
1169
- "A Figure is a finite nested array built from `[]`, read through its elements",
1170
- "only: properties and declared parents are ignored by observations. Star keeps",
1171
- "nonterminal metadata when rebuilding frames. Construction is brackets, form is the value itself, immediate size is `.#`, terminal count",
1172
- "is `.##`, form equality is `=`, and identity is `===`. The empty frame is one",
1173
- "terminal: `[].#` is 0 and `[].##` is 1. The signed residual `.###` is",
1167
+ "Figures as projections of native HC frames (#454; occurrence/figure 010.09)",
1168
+ "",
1169
+ "A figure is a projection of HC frames through which we observe invariants that",
1170
+ "embody mathematical relations. This is a working definition: each investigation",
1171
+ "specifies its projection, transformations and invariants.",
1172
+ "",
1173
+ "Finite nested arrays built from `[]` are the simplest construction family used",
1174
+ "below. They do not define the full domain of native observations. Size, residual",
1175
+ "and immediate identity membership exclude properties and declared parents;",
1176
+ "Star keeps nonterminal metadata when rebuilding frames. Construction is brackets,",
1177
+ "form is the value itself, immediate arity is `.#`, Size is `.##`, form equality",
1178
+ "is `=`, and identity is `===`. The empty frame is one terminal: `[].#` is 0 and",
1179
+ "`[].##` is 1. The signed residual `.###` is",
1174
1180
  "`x₁.## − x₂.## + x₃.## − …` over the immediate elements, a FrameInt that is 0",
1175
1181
  "for `[]` (issue occurrence/figure 010.04).",
1176
1182
  "",
1177
1183
  "There are no Figure constructors, marks, tally observers, count aliases or",
1178
- "comparison wrappers. Use native operations directly. Star `x * y` places y at each terminal of x, preserving nesting.",
1184
+ "comparison wrappers. Use native operations directly. Star `x * y` places y at",
1185
+ "each terminal of x, preserving nesting.",
1179
1186
  "Flat repetition is `x.## [y]`. A tally, when wanted, is an explicit",
1180
1187
  "construction, such as `x & {[[]]}` for one fresh mark per immediate element.",
1181
1188
  "Native `.##` uses each child's native Size, including numeric magnitude and",
1182
1189
  "text length. Native `.###` also accepts mixed arrays and evaluated groups.",
1183
1190
  "Star keeps its narrower array/Count composition domain.",
1184
1191
  "",
1185
- "Only observation operations remain: `withness`, `gap` and `spin`, with `pure` and `need` for domain validation.",
1186
- "The traversals validate at their public boundary; their recursive steps use",
1187
- "native operations directly. Withness returns a native boolean, `<>` or `()`.",
1188
- "```",
1189
- "```",
1190
- "`pure x` retains its name for compatibility but now accepts the native residual",
1191
- "domain: mixed arrays and evaluated groups with finite child Sizes. Properties",
1192
- "and declared parents are ignored. Standalone atoms, schemas and closures have",
1193
- "no residual. It is the native `.###` check: a FrameInt, even 0, is true,",
1194
- "and nil is false. Helper retirement is deferred to occurrence/figure 010.09.",
1195
- "```",
1196
- ".pure {.x _; (x.###) ? {<>} : {()}};",
1197
- "```",
1198
- "`need x` returns a supported frame itself, or a native refusal.",
1199
- "```",
1200
- ".need {.x _; (pure x) ? {x} : {unsupported-figure}};",
1201
- "```",
1202
- "Native Star `x * y` replaces empty-array terminals with y and composes",
1203
- "FrameCount leaves using the same rule as a root count, including zero.",
1204
- "Replacements are shared by identity; ancestors preserve native metadata.",
1205
- "Terminals carrying metadata or statements are refused to avoid losing them.",
1206
- "Use `*` directly; the Figures module provides no composition wrapper.",
1192
+ "Only two derived mathematical abbreviations remain: Gap = |signed residual|",
1193
+ "and Spin = signed residual / positive Count. They define no Figure domain.",
1194
+ "Incidence is native `point ~~~ line`; collective incidence uses ordinary",
1195
+ "iteration. Observer eligibility is `x.###` itself: a FrameInt, including zero,",
1196
+ "is true; an unsupported host answers nil. No `pure`, `need` or `withness`",
1197
+ "helper is exported (issue occurrence/figure 010.09).",
1207
1198
  "",
1208
- "`withness x [f, …]` asks whether every requested frame is an immediate element",
1209
- "of x by native identity. It returns a native boolean. No requested frames is true.",
1210
- "```",
1211
- ".withness {.x _; .host x;",
1212
- " {.fs _;",
1213
- " .absent (fs &| {.f _; (f ~~~ host) ? {[]} : {[f]}});",
1214
- " absent = []}};",
1215
- "```",
1216
- "`gap x` is the absolute value of native `x.###`, the alternating sum of its",
1217
- "immediate elements' `.##` counts, always a nonnegative FrameInt (Owner decision",
1218
- "for #455). The empty frame has Gap 0 as a FrameInt too.",
1199
+ "Gap keeps a FrameInt result. Using `(x.###).##` instead would change the type",
1200
+ "to Count and would even give Size 1 for an unsupported host's nil. Test residual",
1201
+ "availability directly, then bind its value and choose its sign with native HC.",
1219
1202
  "```",
1220
- ".gap {.x _; (pure x) ? {",
1203
+ ".gap {.x _; (x.###) ? {",
1221
1204
  " .signed (x.###);",
1222
- " (signed .< 0) ? {0 - signed} : {signed}} : {need x}};",
1205
+ " (signed .< 0) ? {0 - signed} : {signed}} : {unsupported-figure}};",
1223
1206
  "```",
1224
- "`spin x N` keeps the sign of `x.###` and divides by a positive count N.",
1225
- "Non-count N is a type error; zero is division-by-zero. The host is validated",
1226
- "before the resolution is checked.",
1207
+ "Spin retains a typed positive Count divisor. Bare `x.### / N` would accept",
1208
+ "negative or fractional divisors and silently answer nil for an unsupported",
1209
+ "host. This abbreviation keeps host refusal before divisor validation, Count",
1210
+ "type errors, and division-by-zero even for a zero residual. These two short",
1211
+ "definitions are mathematical conveniences, not constructors or type guards.",
1227
1212
  "```",
1228
1213
  ".spin {.x _; .host x;",
1229
- " (pure host) ? {",
1230
- " {.n <(1).<>> _;",
1231
- " .signed (host.###);",
1214
+ " (host.###) ? {",
1215
+ " {.n <(1).<>> _; .signed (host.###);",
1232
1216
  " (n .< 1) ? {signed / 0} : {signed / n}}} : {",
1233
- " {.n _; need host}}};",
1217
+ " {.n _; unsupported-figure}}};",
1234
1218
  "```",
1235
1219
  "Native construction, counting and comparisons need no module helpers.",
1236
1220
  "```",
@@ -1242,11 +1226,11 @@ export const HC_SOURCES = new Map([
1242
1226
  "; [e.## = [[], []].##, [].## = [[]].##]",
1243
1227
  "# [<>, <>]",
1244
1228
  "```",
1245
- "Native terminal counting needs no enumeration or tally construction.",
1229
+ "Native observations need no domain wrapper, enumeration or tally construction.",
1246
1230
  "```",
1247
- "; [(pure []), (pure [[], [[]]]), (pure [[], 5]), (pure [.k 1; []])]",
1231
+ "; [([].### ? {<>} : {()}), ([[], [[]]].### ? {<>} : {()}), ([[], 5].### ? {<>} : {()}), ([.k 1; []].### ? {<>} : {()})]",
1248
1232
  "# [<>, <>, <>, <>]",
1249
- "; [(need e) = e, (need e) === e]",
1233
+ "; [(e.### ? {e} : {unsupported-figure}) = e, (e.### ? {e} : {unsupported-figure}) === e]",
1250
1234
  "# [<>, <>]",
1251
1235
  "; [[], “a”] * [[]]",
1252
1236
  "# $!.star-domain *",
@@ -1284,15 +1268,26 @@ export const HC_SOURCES = new Map([
1284
1268
  "; [([[[], []]].## [[[]]]) = [[[]], [[]]], ([[[], []]] * [[]]) = [[[[]], [[]]]]]",
1285
1269
  "# [<>, <>]",
1286
1270
  "```",
1287
- "Withness uses identity, and its answer is the native boolean.",
1271
+ "Incidence uses immediate identity. These shared frame objects illustrate Fano",
1272
+ "incidence (see `hc/membership.hc`; occurrence/figure 010.06), without claiming",
1273
+ "that the complete Fano geometry has been derived. Equal form is not incidence.",
1274
+ "Collective incidence keeps the absent requested points and asks if none remain;",
1275
+ "empty requests are true, repeats need one match, and nested-only points fail.",
1288
1276
  "```",
1289
1277
  "; .shared [[]]; .p1 [shared, []]; .p2 [[], shared];",
1290
- "; [(withness p1 [shared]), (withness p2 [shared]), (withness p1 [[[]]])]",
1278
+ "; [shared ~~~ p1, shared ~~~ p2, [[]] ~~~ p1]",
1291
1279
  "# [<>, <>, ()]",
1292
- "; [(withness [] [[[]]]), (withness [shared] [])]",
1280
+ "; [[[]] ~~~ [], ([] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []]",
1293
1281
  "# [(), <>]",
1282
+ "; ([shared, shared] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []",
1283
+ "# <>",
1284
+ "; ([shared, [[]]] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []",
1285
+ "# ()",
1286
+ "; .nested [p1];",
1287
+ "; ([shared] &| {.f _; (f ~~~ nested) ? {[]} : {[f]}}) = []",
1288
+ "# ()",
1294
1289
  "```",
1295
- "Native `.###` folds the immediate elements' terminal counts with alternating",
1290
+ "Native `.###` folds the immediate elements' Sizes with alternating",
1296
1291
  "signs, one sign per element, and answers a FrameInt even when it is 0 or",
1297
1292
  "positive. Mixed arrays and evaluated groups use the same rule.",
1298
1293
  "```",
@@ -1319,7 +1314,14 @@ export const HC_SOURCES = new Map([
1319
1314
  "# [1, 3, 3, 1, 1]",
1320
1315
  "; [[5, “hello”].##, [5, “hello”].###, (5, 3).###, [5, 3, 2, 7].###]",
1321
1316
  "# [10, 0, 2, -3]",
1317
+ "; [([5, “hello”].### ? {<>} : {()}), (5.### ? {<>} : {()})]",
1318
+ "# [<>, ()]",
1319
+ "; { .x <[].<>> _; x.### } [[], [“nested atom”]]",
1320
+ "# -10",
1322
1321
  "```",
1322
+ "Outer array binding accepts nested atoms, and rejects groups despite their valid",
1323
+ "residual. It is neither a recursive array-only constraint nor the residual domain.",
1324
+ "",
1323
1325
  "Gap is `|x.###|` and Spin is `x.### / N`, including shared branches at every",
1324
1326
  "occurrence. Reversing two unequal branches reverses Spin's sign.",
1325
1327
  "```",
@@ -1338,6 +1340,12 @@ export const HC_SOURCES = new Map([
1338
1340
  "# $!.type-error .n <(1).<>> 2.5",
1339
1341
  "; spin [[[], []]] 0",
1340
1342
  "# $!.division-by-zero /",
1343
+ "; [gap [5, “hello”], spin [5, “hello”] 4]",
1344
+ "# [0, 0]",
1345
+ "; spin [] (0 - 2)",
1346
+ "# $!.type-error .n <(1).<>> -2",
1347
+ "; spin [] 0",
1348
+ "# $!.division-by-zero /",
1341
1349
  "",
1342
1350
  "```",
1343
1351
  "Star uses native `*` dispatch; numeric pairs keep arithmetic.",
@@ -2189,8 +2197,11 @@ export const HC_SOURCES = new Map([
2189
2197
  "# $!.unimplemented .x 42",
2190
2198
  "; .mat <tensor<2x3xf32>> [[1,2,3]] # Tensor types",
2191
2199
  "# $!.unimplemented .mat...",
2192
- "; .f <(.x <i32>) -> <i32>> {x + 1} # Function signatures",
2193
- "# $!.unimplemented .f...",
2200
+ "```",
2201
+ "Function-signature notation such as \\`.f <(.x <i32>) -> <i32>> {x + 1}\\`",
2202
+ "remains a proposal and is not executable HC. Its arrow is not accepted by the",
2203
+ "current schema grammar.",
2204
+ "```",
2194
2205
  "",
2195
2206
  ].join("\n"),
2196
2207
  ],
@@ -1,4 +1,4 @@
1
- import { EvaluationScope, Frame, FrameGroup, NilContext, } from "../frames.js";
1
+ import { EvaluationScope, Frame, FrameGroup, FrameNote, NilContext, } from "../frames.js";
2
2
  import { LexPipe } from "./lex-pipe.js";
3
3
  import { ParsePipe } from "./parse-pipe.js";
4
4
  /** Builds the shared Lex/Parse/Eval pipeline for one HC source unit. */
@@ -60,6 +60,13 @@ export class EvalPipe extends Frame {
60
60
  writable: true,
61
61
  value: void 0
62
62
  });
63
+ /** Whether this source unit emitted an unhandled evaluation failure. */
64
+ Object.defineProperty(this, "failed", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: false
69
+ });
63
70
  // Legacy lexical features follow kOUT to the file scope. Scoped pipes
64
71
  // replace it with a live view of every supplied lookup layer.
65
72
  this.set(Frame.kOUT, fileScope);
@@ -69,7 +76,17 @@ export class EvalPipe extends Frame {
69
76
  const scope = this.scope ??
70
77
  EvaluationScope.root(this.fileScope, this.hostNamespace);
71
78
  const result = expr.in(scope);
79
+ this.failed ||= outputFailed(result, new Set());
72
80
  this.out.collect(result, context);
73
81
  return result;
74
82
  }
75
83
  }
84
+ /** Inspect emitted values without evaluating them or following metadata links. */
85
+ function outputFailed(result, seen) {
86
+ if (seen.has(result))
87
+ return false;
88
+ seen.add(result);
89
+ return result.isFailedResult() ||
90
+ (result instanceof FrameNote && result.isDiagnosticFailure()) ||
91
+ result.asArray().some((item) => outputFailed(item, seen));
92
+ }
@@ -54,7 +54,7 @@ export class HCEval {
54
54
  * Creates a lexical pipe for evaluating expressions.
55
55
  */
56
56
  static make_pipe(out, fileScope = out, hostNamespace = Frame.nil) {
57
- return makeSourcePipe(new EvalPipe(out, fileScope, hostNamespace), { importSource: evaluateResourceSource });
57
+ return makeSourcePipe(new EvalPipe(out, fileScope, hostNamespace), { importSource: evaluateResourceSource, strictStructure: true });
58
58
  }
59
59
  constructor(out, fileScope = out, hostNamespace = Frame.nil) {
60
60
  Object.defineProperty(this, "out", {
@@ -75,6 +75,12 @@ export class HCEval {
75
75
  writable: true,
76
76
  value: hostNamespace
77
77
  });
78
+ Object.defineProperty(this, "evaluator", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: void 0
83
+ });
78
84
  Object.defineProperty(this, "pipe", {
79
85
  enumerable: true,
80
86
  configurable: true,
@@ -105,7 +111,11 @@ export class HCEval {
105
111
  writable: true,
106
112
  value: false
107
113
  });
108
- this.pipe = HCEval.make_pipe(out, fileScope, hostNamespace);
114
+ this.evaluator = new EvalPipe(out, fileScope, hostNamespace);
115
+ this.pipe = makeSourcePipe(this.evaluator, {
116
+ importSource: evaluateResourceSource,
117
+ strictStructure: true,
118
+ });
109
119
  this.lex = this.pipe;
110
120
  }
111
121
  /** Reuses this source unit and host while directing results elsewhere. */
@@ -155,7 +165,8 @@ export class HCEval {
155
165
  if (!activeDocument) {
156
166
  this.checkInput(input);
157
167
  }
158
- const result = source.scanInto(this.lex, endOfLine);
168
+ const scanned = source.scanInto(this.lex, false);
169
+ const result = endOfLine ? this.pipe.endLine(scanned) : scanned;
159
170
  this.lex = result.is.lexical === true ? result : this.pipe;
160
171
  if (result.is.error === true) {
161
172
  this.lexicalError = result.toString();
@@ -174,21 +185,30 @@ export class HCEval {
174
185
  complete = result.is.error !== true;
175
186
  this.lexicalError = complete ? null : result.toString();
176
187
  }
177
- else if (this.needsFinish) {
178
- this.pipe.finish(Frame.nil);
179
- this.lexicalError = null;
188
+ else if (this.needsFinish || this.pipe.level !== 0) {
189
+ const result = this.pipe.finish(Frame.nil);
190
+ complete = result.is.error !== true;
191
+ this.lexicalError = complete ? null : result.toString();
180
192
  }
181
193
  else {
182
194
  this.lexicalError = null;
183
195
  }
184
196
  if (!complete) {
185
- this.pipe = HCEval.make_pipe(this.out, this.fileScope, this.hostNamespace);
197
+ this.evaluator = new EvalPipe(this.out, this.fileScope, this.hostNamespace);
198
+ this.pipe = makeSourcePipe(this.evaluator, {
199
+ importSource: evaluateResourceSource,
200
+ strictStructure: true,
201
+ });
186
202
  }
187
203
  this.lex = this.pipe;
188
204
  this.inputBuffer = "";
189
205
  this.needsFinish = false;
190
206
  return complete;
191
207
  }
208
+ /** Runtime failures are separate from lexical completion (testdocs may expect them). */
209
+ hasFailures() {
210
+ return this.evaluator.failed;
211
+ }
192
212
  error() {
193
213
  return this.lexicalError;
194
214
  }
@@ -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,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";
@@ -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";
@@ -117,7 +114,7 @@ export class FrameExpr extends FrameList {
117
114
  return value;
118
115
  // An explicit nil receiver still has a Size. The initial nil accumulator
119
116
  // is not a receiver, so a leading .## remains an address (#411).
120
- if (index > 0 && sum.is.void && value instanceof FrameSymbol &&
117
+ if (index > 0 && sum.is.void && value.isSymbol() &&
121
118
  value.is.address &&
122
119
  [Frame.kLEAVES, Frame.kRESIDUAL].includes(value.spelling())) {
123
120
  return value.called_by(sum);
@@ -129,8 +126,8 @@ export class FrameExpr extends FrameList {
129
126
  }, Frame.nil);
130
127
  }
131
128
  schemaRetrieval(scope) {
132
- if (this.data.length !== 2 || !(this.data[0] instanceof FrameSymbol) ||
133
- !(this.data[1] instanceof FrameName) || this.data[1].source !== "<^>")
129
+ if (this.data.length !== 2 || !this.data[0].isSymbol() ||
130
+ !this.data[1].isName() || this.data[1].source !== "<^>")
134
131
  return undefined;
135
132
  return this.data[0].bindingSchema(resumedScope(this.data[0], scope));
136
133
  }
@@ -139,12 +136,12 @@ export class FrameExpr extends FrameList {
139
136
  return undefined;
140
137
  const name = unwrapSingleton(this.data[0]);
141
138
  const schema = unwrapSingleton(this.data[1]);
142
- if (!(name instanceof FrameName) || !(schema instanceof FrameSchema)) {
139
+ if (!name.isName() || !schema.isSchema()) {
143
140
  return undefined;
144
141
  }
145
142
  const setter = name.in(scope);
146
143
  const value = schema.in(scope);
147
- if (!(setter instanceof FrameSymbol) || !(value instanceof FrameSchema)) {
144
+ if (!setter.isSymbol() || !value.isSchema()) {
148
145
  return Frame.error("$!.unsupported-schema-definition");
149
146
  }
150
147
  return setter.defineSchema(value);
@@ -222,7 +219,7 @@ export function atomsOf(terms, sites = new Map(), resume) {
222
219
  if (terms.length < 2)
223
220
  return undefined;
224
221
  const head = firstAtom(terms[0]);
225
- if (!(head instanceof FrameName) || /^\.*$/.test(head.source)) {
222
+ if (!head.isName() || /^\.*$/.test(head.source)) {
226
223
  return undefined;
227
224
  }
228
225
  heads.add(head);
@@ -247,10 +244,10 @@ export function atomsOf(terms, sites = new Map(), resume) {
247
244
  atoms.push(scoped(term));
248
245
  }
249
246
  }
250
- else if (term instanceof FrameName) {
247
+ else if (term.isName()) {
251
248
  atoms.push(FrameWord.address(term.source, heads.has(term) ? term : undefined));
252
249
  }
253
- else if (term instanceof FrameSymbol) {
250
+ else if (term.isSymbol()) {
254
251
  const spelling = term.spelling();
255
252
  atoms.push(FrameWord.word(spelling, scope.get(spelling), resume));
256
253
  }
@@ -320,10 +317,10 @@ export function sizeAtomsOf(terms) {
320
317
  walkAtom(term.asArray()[0], path);
321
318
  path.delete(term);
322
319
  }
323
- else if (term instanceof FrameName) {
320
+ else if (term.isName()) {
324
321
  atoms.push(FrameWord.address(term.source));
325
322
  }
326
- else if (term instanceof FrameSymbol) {
323
+ else if (term.isSymbol()) {
327
324
  atoms.push(FrameWord.word(term.spelling()));
328
325
  }
329
326
  else {
@@ -449,7 +446,7 @@ export class FrameScoped extends Frame {
449
446
  }
450
447
  /** Sizes as its term does, `.#`, `.##` and `.###`; anything else is applied. */
451
448
  call(argument, parameter = Frame.nil) {
452
- if (argument instanceof FrameSymbol && argument.is.address === true &&
449
+ if (argument.isSymbol() && argument.is.address === true &&
453
450
  Frame.SIZE_OPERATORS.includes(argument.spelling())) {
454
451
  return this.sizeFor(argument.spelling());
455
452
  }
@@ -496,7 +493,7 @@ export function sitesAround(body) {
496
493
  }
497
494
  function unwrapSingleton(frame) {
498
495
  let result = frame;
499
- while (result instanceof FrameList && !(result instanceof FrameSchema) &&
496
+ while (result instanceof FrameList && !result.isSchema() &&
500
497
  result.size() === 1) {
501
498
  result = result.asArray()[0];
502
499
  }
@@ -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();
@@ -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", {
@@ -55,6 +55,9 @@ const recognizeName = (symbol, source = "") => {
55
55
  };
56
56
  };
57
57
  export class FrameName extends FrameAtom {
58
+ isName() {
59
+ return true;
60
+ }
58
61
  constructor(source, meta = NilContext) {
59
62
  super(meta);
60
63
  Object.defineProperty(this, "source", {
@@ -51,6 +51,10 @@ export class FrameNote extends FrameAtom {
51
51
  this.setLabel(data, source);
52
52
  this.id += this.data;
53
53
  }
54
+ /** Diagnostic notes that represent failures, rather than test progress. */
55
+ isDiagnosticFailure() {
56
+ return ["!", "<>", ">", "-"].includes(this.data);
57
+ }
54
58
  in(_contexts = [Frame.nil]) {
55
59
  return this;
56
60
  }
@@ -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 { FrameList } from "./frame-list.js";
6
3
  import { FrameNote } from "./frame-note.js";
@@ -8,6 +5,9 @@ import { compileSchemaMatcher } from "./schema-compiler.js";
8
5
  import { EnumerationSchemaMatcher, } from "./schema-matcher.js";
9
6
  import { NilContext } from "./context.js";
10
7
  export class FrameSchema extends FrameList {
8
+ isSchema() {
9
+ return true;
10
+ }
11
11
  constructor(data, meta = NilContext, matcher = new EnumerationSchemaMatcher()) {
12
12
  super(data, meta);
13
13
  Object.defineProperty(this, "matcher", {