hclang 0.37.1 → 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
@@ -2197,8 +2197,11 @@ export const HC_SOURCES = new Map([
2197
2197
  "# $!.unimplemented .x 42",
2198
2198
  "; .mat <tensor<2x3xf32>> [[1,2,3]] # Tensor types",
2199
2199
  "# $!.unimplemented .mat...",
2200
- "; .f <(.x <i32>) -> <i32>> {x + 1} # Function signatures",
2201
- "# $!.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
+ "```",
2202
2205
  "",
2203
2206
  ].join("\n"),
2204
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", {
@@ -65,6 +65,9 @@ export class FrameLiteral extends FrameAtom {
65
65
  }
66
66
  }
67
67
  export class FrameSymbol extends FrameAtom {
68
+ isSymbol() {
69
+ return true;
70
+ }
68
71
  static for(symbol) {
69
72
  const exists = FrameSymbol.symbols[symbol];
70
73
  return exists || (FrameSymbol.symbols[symbol] = new FrameSymbol(symbol));
@@ -1,5 +1,389 @@
1
- import { MetaFrame } from "./meta-frame.js";
2
1
  import { NilContext } from "./context.js";
2
+ import { renderNested } from "./stringify.js";
3
+ /** Visibility levels for logical frame bindings. */
4
+ export var Visibility;
5
+ (function (Visibility) {
6
+ Visibility["Public"] = "public";
7
+ Visibility["Protected"] = "protected";
8
+ Visibility["Private"] = "private";
9
+ })(Visibility || (Visibility = {}));
10
+ /**
11
+ * MetaFrame is the parent class of Frame, providing methods for managing metadata.
12
+ */
13
+ export class MetaFrame {
14
+ /**
15
+ * Checks if the given string is numeric
16
+ * (to distinguish array indices from metadata keys)
17
+ *
18
+ * @param {string} value - The string to check.
19
+ * @returns {boolean} `true` if the string is all numeric, `false` otherwise.
20
+ */
21
+ static isInteger(value) {
22
+ return /^\p{N}+$/u.test(value);
23
+ }
24
+ /**
25
+ * Checks if the given character is alphabetic.
26
+ *
27
+ * @param {string} char - The character to check.
28
+ * @returns {boolean} `true` if the character is alphabetic, `false` otherwise.
29
+ */
30
+ static isAlphabetic(char) {
31
+ return /\p{L}/u.test(char);
32
+ }
33
+ /**
34
+ * meta is a map of key-value pairs for the Frame.
35
+ * _isNil is a flag indicating if the Frame is nil.
36
+ */
37
+ constructor(meta = NilContext, _isNil = false) {
38
+ Object.defineProperty(this, "meta", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: meta
43
+ });
44
+ /**
45
+ * up is the lexical parent carried by structurally nested frames and
46
+ * per-read plumbing copies. Symbol lookup never rewrites it on a shared
47
+ * value; identity-bearing values carry reader context in a FrameHandle.
48
+ */
49
+ Object.defineProperty(this, "up", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: {}
54
+ }); // forward-declare Frame
55
+ /**
56
+ * parent is the declared parent: the explicit `.^` inheritance link.
57
+ * It is written only by setParent, so the declared chain is acyclic by
58
+ * construction, and it is the only chain visibility authorizes against.
59
+ */
60
+ Object.defineProperty(this, "parent", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: {}
65
+ }); // forward-declare Frame
66
+ /** Typed receiver capability installed only on an invocation frame. */
67
+ Object.defineProperty(this, "receiverState", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ /**
74
+ * declares marks a frame that accepts declarations, so a name binds to the
75
+ * innermost marked target instead of inferring one from context classes.
76
+ */
77
+ Object.defineProperty(this, "declares", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: false
82
+ });
83
+ /**
84
+ * id is a unique identifier for each Frame.
85
+ */
86
+ Object.defineProperty(this, "id", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ const name = this.constructor.name;
93
+ const id = name + "." + MetaFrame.id_count++;
94
+ this.id = "$:" + id;
95
+ }
96
+ /**
97
+ * get_here retrieves a Frame by key from the current context.
98
+ */
99
+ get_here(key, _origin = this) {
100
+ const exact = this.resolve_here(key, _origin);
101
+ if (exact != null) {
102
+ return exact.value;
103
+ }
104
+ return this.match_here(key);
105
+ }
106
+ /** Lets a projection perform another frame's local lookup without its links. */
107
+ lookup_here_on(frame, key, origin) {
108
+ return frame.lookup_here(key, origin);
109
+ }
110
+ /**
111
+ * Lets a forwarding link search another frame's non-global lookup graph.
112
+ *
113
+ * `Frame.globals` stays the one final tier of the outer `get`, which
114
+ * curries an operator with that lookup's own origin; a forwarded `get`
115
+ * would reach the globals early, from the wrong frame.
116
+ */
117
+ lookup_graph_on(frame, key, origin) {
118
+ return MetaFrame.lookup(frame, key, origin, new Set());
119
+ }
120
+ /**
121
+ * Lets a forwarding link resolve a binding through another frame's
122
+ * non-global graph.
123
+ *
124
+ * The binding counterpart of `lookup_graph_on`, with the same tiers, so a
125
+ * forwarded value and its binding metadata come from the same declaration
126
+ * owner. `Frame.globals` stays the one final tier of the outer `resolve`.
127
+ */
128
+ resolve_graph_on(frame, key, origin) {
129
+ return MetaFrame.resolveBinding(frame, key, origin, new Set());
130
+ }
131
+ /** Resolves a logical name to the declaration key visible from origin. */
132
+ resolve_here(key, origin = this) {
133
+ if (key.startsWith("__")) {
134
+ return this.authorize(key, Visibility.Private, key.slice(2), origin);
135
+ }
136
+ if (key.startsWith("_")) {
137
+ return this.authorize(key, Visibility.Protected, key.slice(1), origin);
138
+ }
139
+ const publicValue = this.meta[key];
140
+ if (publicValue != null) {
141
+ return { owner: this, key, value: publicValue };
142
+ }
143
+ return this.authorize(`_${key}`, Visibility.Protected, key, origin) ??
144
+ this.authorize(`__${key}`, Visibility.Private, key, origin);
145
+ }
146
+ /** Resolves a binding through the same guarded graph as ordinary lookup. */
147
+ resolve(key, origin = this) {
148
+ const local = this.resolve_here(key, origin);
149
+ if (local)
150
+ return local;
151
+ const seen = new Set([this]);
152
+ for (const link of this.lookup_links()) {
153
+ const result = MetaFrame.resolveBinding(link, key, origin, seen);
154
+ if (result)
155
+ return result;
156
+ }
157
+ const globals = Frame.globals;
158
+ if (globals && !globals.is.missing && !seen.has(globals)) {
159
+ return MetaFrame.resolveBinding(globals, key, origin, seen);
160
+ }
161
+ return undefined;
162
+ }
163
+ /**
164
+ * Get a frame by key through one guarded lookup traversal.
165
+ *
166
+ * Subclasses customize only local lookup, links, and successful-result
167
+ * transformation. The traversal itself stays here so a virtual override
168
+ * cannot accidentally discard cycle state. Declared parents precede lexical
169
+ * scope, and globals are consulted once after the complete scope graph.
170
+ */
171
+ get(key, origin = this) {
172
+ const local = this.lookup_here(key, origin);
173
+ if (!local.is.missing) {
174
+ return this.lookup_result(local, key);
175
+ }
176
+ // Allocate traversal state only after an immediate local miss.
177
+ const seen = new Set([this]);
178
+ for (const link of this.lookup_links()) {
179
+ const result = MetaFrame.lookup(link, key, origin, seen);
180
+ if (!result.is.missing) {
181
+ return this.lookup_result(result, key);
182
+ }
183
+ }
184
+ // Globals are the final lookup tier, even when the lexical graph cycles.
185
+ const globals = Frame.globals;
186
+ if (globals && !globals.is.missing && !seen.has(globals)) {
187
+ const result = MetaFrame.lookup(globals, key, origin, seen);
188
+ if (!result.is.missing) {
189
+ return this.lookup_result(result, key);
190
+ }
191
+ }
192
+ return Frame.missing;
193
+ }
194
+ /** Local behavior used by the guarded lookup driver. */
195
+ lookup_here(key, origin) {
196
+ return this.get_here(key, origin);
197
+ }
198
+ /** Non-global links in lookup precedence order. */
199
+ lookup_links() {
200
+ const links = [];
201
+ if (this.parent && !this.parent.is.missing) {
202
+ links.push(this.parent);
203
+ }
204
+ if (this.up && !this.up.is.missing && this.up !== Frame.globals) {
205
+ links.push(this.up);
206
+ }
207
+ return links;
208
+ }
209
+ /** Allows wrappers to transform a value found anywhere below them. */
210
+ lookup_result(result, _key) {
211
+ return result;
212
+ }
213
+ /** Depth-first declared-before-lexical traversal without global fallback. */
214
+ static lookup(frame, key, origin, seen) {
215
+ if (seen.has(frame)) {
216
+ return Frame.missing;
217
+ }
218
+ seen.add(frame);
219
+ const local = frame.lookup_here(key, origin);
220
+ if (!local.is.missing) {
221
+ return frame.lookup_result(local, key);
222
+ }
223
+ for (const link of frame.lookup_links()) {
224
+ const result = MetaFrame.lookup(link, key, origin, seen);
225
+ if (!result.is.missing) {
226
+ return frame.lookup_result(result, key);
227
+ }
228
+ }
229
+ return Frame.missing;
230
+ }
231
+ /** Depth-first binding traversal without global fallback. */
232
+ static resolveBinding(frame, key, origin, seen) {
233
+ if (seen.has(frame))
234
+ return undefined;
235
+ seen.add(frame);
236
+ const local = frame.resolve_here(key, origin);
237
+ if (local)
238
+ return local;
239
+ for (const link of frame.lookup_links()) {
240
+ const result = MetaFrame.resolveBinding(link, key, origin, seen);
241
+ if (result)
242
+ return result;
243
+ }
244
+ return undefined;
245
+ }
246
+ /**
247
+ * set adds a new key-value pair to the current context.
248
+ */
249
+ set(key, value) {
250
+ if (this.meta === NilContext) {
251
+ this.meta = {};
252
+ }
253
+ this.meta[key] = value;
254
+ return this;
255
+ }
256
+ /** Whether this frame carries an explicitly declared parent. */
257
+ hasDeclaredParent() {
258
+ return this.parent != null && !this.parent.is.missing;
259
+ }
260
+ /**
261
+ * setParent is the only path that may attach a declared parent, so a cyclic
262
+ * declared chain cannot be built by a caller that forgot to check. It returns
263
+ * an error frame when the link is refused and undefined when it is accepted.
264
+ */
265
+ setParent(parent) {
266
+ if (this.wouldCreateParentCycle(parent)) {
267
+ return Frame.error("$!.cyclic-parent .^");
268
+ }
269
+ this.parent = parent;
270
+ return undefined;
271
+ }
272
+ /** Whether assigning parent would attach this frame to a cyclic chain. */
273
+ wouldCreateParentCycle(parent) {
274
+ const seen = new Set([this]);
275
+ let current = parent;
276
+ while (current && !current.is.missing) {
277
+ if (seen.has(current))
278
+ return true;
279
+ seen.add(current);
280
+ current = current.parent;
281
+ }
282
+ return false;
283
+ }
284
+ /**
285
+ * meta_copy creates a shallow copy of the current context.
286
+ */
287
+ meta_copy() {
288
+ return { ...this.meta };
289
+ }
290
+ /**
291
+ * meta_keys returns an array of keys in the current context.
292
+ */
293
+ meta_keys() {
294
+ return Object.keys(this.meta);
295
+ }
296
+ /**
297
+ * meta_length returns the number of keys in the current context.
298
+ */
299
+ meta_length() {
300
+ return this.meta_keys().length;
301
+ }
302
+ /**
303
+ * meta_pairs returns an array of key-value pairs in the current context.
304
+ */
305
+ meta_pairs() {
306
+ return Object.entries(this.meta);
307
+ }
308
+ /**
309
+ * meta_string returns a string representation of the current context.
310
+ *
311
+ * Nested values render through the cycle guard, so metadata that reaches this
312
+ * frame again yields an id rather than overflowing the host stack.
313
+ */
314
+ meta_string() {
315
+ return this.meta_pairs().map(([key, value]) => {
316
+ if (key === Frame.kOUT) {
317
+ return `.${key} ${value.id};`;
318
+ }
319
+ return `.${key} ${renderNested(value, () => value.toString())};`;
320
+ }).join(" ");
321
+ }
322
+ /**
323
+ * match_here checks if a target string matches any key in the current context.
324
+ */
325
+ match_here(target) {
326
+ let result = Frame.missing;
327
+ this.meta_pairs().forEach(([key, value]) => {
328
+ const isPattern = key.match(/\/(.*)\//);
329
+ if (isPattern) {
330
+ const pattern = new RegExp(isPattern[1]);
331
+ if (pattern.test(target)) {
332
+ result = value;
333
+ if ("source" in result) {
334
+ const sourced = result;
335
+ sourced.source = target;
336
+ }
337
+ }
338
+ }
339
+ });
340
+ return result;
341
+ }
342
+ authorize(physicalKey, visibility, key, origin) {
343
+ const value = this.meta[physicalKey];
344
+ if (value == null)
345
+ return undefined;
346
+ const authorized = visibility === Visibility.Public ||
347
+ (visibility === Visibility.Private
348
+ ? origin === this
349
+ : this.isAncestorOf(origin));
350
+ if (authorized) {
351
+ return { owner: this, key: physicalKey, value };
352
+ }
353
+ return {
354
+ owner: this,
355
+ key: physicalKey,
356
+ value: Frame.error(`$!.is-${visibility} .${key}`),
357
+ };
358
+ }
359
+ /**
360
+ * isAncestorOf walks the declared parent chain only. Lexical nesting and
361
+ * syntactic containment confer no protected access: an inner aggregate or an
362
+ * unrelated peer's method is not a descendant.
363
+ */
364
+ isAncestorOf(origin) {
365
+ const seen = new Set();
366
+ let current = origin;
367
+ while (current && !seen.has(current)) {
368
+ if (current === this)
369
+ return true;
370
+ seen.add(current);
371
+ if (!current.hasDeclaredParent())
372
+ return false;
373
+ current = current.parent;
374
+ }
375
+ return false;
376
+ }
377
+ }
378
+ /**
379
+ * id_count is a static counter, incremented to generate unique IDs.
380
+ */
381
+ Object.defineProperty(MetaFrame, "id_count", {
382
+ enumerable: true,
383
+ configurable: true,
384
+ writable: true,
385
+ value: 0
386
+ });
3
387
  /**
4
388
  * inspectFlags returns a string representation of the Flags.
5
389
  *
@@ -243,11 +627,20 @@ export class Frame extends MetaFrame {
243
627
  atSite(_site) {
244
628
  return this;
245
629
  }
246
- /**
247
- * Whether evaluating this atom resolves a binding where it is evaluated, as
248
- * an alias does, rather than being a value or a name a walk already holds
249
- * as a word. A walk holds such an atom with its closure's scope (spec a17).
250
- */
630
+ /** Concrete syntax/value families, without eager imports of subclasses. */
631
+ isName() {
632
+ return false;
633
+ }
634
+ isSymbol() {
635
+ return false;
636
+ }
637
+ isSchema() {
638
+ return false;
639
+ }
640
+ isClosure() {
641
+ return false;
642
+ }
643
+ /** Whether evaluating this atom resolves a binding in its evaluation scope. */
251
644
  resolvesInScope() {
252
645
  return false;
253
646
  }
@@ -1,387 +1,6 @@
1
- import { Frame } from "./frame.js";
2
- import { NilContext } from "./context.js";
3
- import { renderNested } from "./stringify.js";
4
- /** Visibility levels for logical frame bindings. */
5
- export var Visibility;
6
- (function (Visibility) {
7
- Visibility["Public"] = "public";
8
- Visibility["Protected"] = "protected";
9
- Visibility["Private"] = "private";
10
- })(Visibility || (Visibility = {}));
11
1
  /**
12
- * MetaFrame is the parent class of Frame, providing methods for managing metadata.
2
+ * The metadata base and Frame share one declaration module: metadata lookup
3
+ * needs Frame's sentinels, while Frame extends MetaFrame. Keep this public
4
+ * entry point without an inheritance cycle between the two modules.
13
5
  */
14
- export class MetaFrame {
15
- /**
16
- * Checks if the given string is numeric
17
- * (to distinguish array indices from metadata keys)
18
- *
19
- * @param {string} value - The string to check.
20
- * @returns {boolean} `true` if the string is all numeric, `false` otherwise.
21
- */
22
- static isInteger(value) {
23
- return /^\p{N}+$/u.test(value);
24
- }
25
- /**
26
- * Checks if the given character is alphabetic.
27
- *
28
- * @param {string} char - The character to check.
29
- * @returns {boolean} `true` if the character is alphabetic, `false` otherwise.
30
- */
31
- static isAlphabetic(char) {
32
- return /\p{L}/u.test(char);
33
- }
34
- /**
35
- * meta is a map of key-value pairs for the Frame.
36
- * _isNil is a flag indicating if the Frame is nil.
37
- */
38
- constructor(meta = NilContext, _isNil = false) {
39
- Object.defineProperty(this, "meta", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: meta
44
- });
45
- /**
46
- * up is the lexical parent carried by structurally nested frames and
47
- * per-read plumbing copies. Symbol lookup never rewrites it on a shared
48
- * value; identity-bearing values carry reader context in a FrameHandle.
49
- */
50
- Object.defineProperty(this, "up", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: {}
55
- }); // forward-declare Frame
56
- /**
57
- * parent is the declared parent: the explicit `.^` inheritance link.
58
- * It is written only by setParent, so the declared chain is acyclic by
59
- * construction, and it is the only chain visibility authorizes against.
60
- */
61
- Object.defineProperty(this, "parent", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: {}
66
- }); // forward-declare Frame
67
- /** Typed receiver capability installed only on an invocation frame. */
68
- Object.defineProperty(this, "receiverState", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
74
- /**
75
- * declares marks a frame that accepts declarations, so a name binds to the
76
- * innermost marked target instead of inferring one from context classes.
77
- */
78
- Object.defineProperty(this, "declares", {
79
- enumerable: true,
80
- configurable: true,
81
- writable: true,
82
- value: false
83
- });
84
- /**
85
- * id is a unique identifier for each Frame.
86
- */
87
- Object.defineProperty(this, "id", {
88
- enumerable: true,
89
- configurable: true,
90
- writable: true,
91
- value: void 0
92
- });
93
- const name = this.constructor.name;
94
- const id = name + "." + MetaFrame.id_count++;
95
- this.id = "$:" + id;
96
- }
97
- /**
98
- * get_here retrieves a Frame by key from the current context.
99
- */
100
- get_here(key, _origin = this) {
101
- const exact = this.resolve_here(key, _origin);
102
- if (exact != null) {
103
- return exact.value;
104
- }
105
- return this.match_here(key);
106
- }
107
- /** Lets a projection perform another frame's local lookup without its links. */
108
- lookup_here_on(frame, key, origin) {
109
- return frame.lookup_here(key, origin);
110
- }
111
- /**
112
- * Lets a forwarding link search another frame's non-global lookup graph.
113
- *
114
- * `Frame.globals` stays the one final tier of the outer `get`, which
115
- * curries an operator with that lookup's own origin; a forwarded `get`
116
- * would reach the globals early, from the wrong frame.
117
- */
118
- lookup_graph_on(frame, key, origin) {
119
- return MetaFrame.lookup(frame, key, origin, new Set());
120
- }
121
- /**
122
- * Lets a forwarding link resolve a binding through another frame's
123
- * non-global graph.
124
- *
125
- * The binding counterpart of `lookup_graph_on`, with the same tiers, so a
126
- * forwarded value and its binding metadata come from the same declaration
127
- * owner. `Frame.globals` stays the one final tier of the outer `resolve`.
128
- */
129
- resolve_graph_on(frame, key, origin) {
130
- return MetaFrame.resolveBinding(frame, key, origin, new Set());
131
- }
132
- /** Resolves a logical name to the declaration key visible from origin. */
133
- resolve_here(key, origin = this) {
134
- if (key.startsWith("__")) {
135
- return this.authorize(key, Visibility.Private, key.slice(2), origin);
136
- }
137
- if (key.startsWith("_")) {
138
- return this.authorize(key, Visibility.Protected, key.slice(1), origin);
139
- }
140
- const publicValue = this.meta[key];
141
- if (publicValue != null) {
142
- return { owner: this, key, value: publicValue };
143
- }
144
- return this.authorize(`_${key}`, Visibility.Protected, key, origin) ??
145
- this.authorize(`__${key}`, Visibility.Private, key, origin);
146
- }
147
- /** Resolves a binding through the same guarded graph as ordinary lookup. */
148
- resolve(key, origin = this) {
149
- const local = this.resolve_here(key, origin);
150
- if (local)
151
- return local;
152
- const seen = new Set([this]);
153
- for (const link of this.lookup_links()) {
154
- const result = MetaFrame.resolveBinding(link, key, origin, seen);
155
- if (result)
156
- return result;
157
- }
158
- const globals = Frame.globals;
159
- if (globals && !globals.is.missing && !seen.has(globals)) {
160
- return MetaFrame.resolveBinding(globals, key, origin, seen);
161
- }
162
- return undefined;
163
- }
164
- /**
165
- * Get a frame by key through one guarded lookup traversal.
166
- *
167
- * Subclasses customize only local lookup, links, and successful-result
168
- * transformation. The traversal itself stays here so a virtual override
169
- * cannot accidentally discard cycle state. Declared parents precede lexical
170
- * scope, and globals are consulted once after the complete scope graph.
171
- */
172
- get(key, origin = this) {
173
- const local = this.lookup_here(key, origin);
174
- if (!local.is.missing) {
175
- return this.lookup_result(local, key);
176
- }
177
- // Allocate traversal state only after an immediate local miss.
178
- const seen = new Set([this]);
179
- for (const link of this.lookup_links()) {
180
- const result = MetaFrame.lookup(link, key, origin, seen);
181
- if (!result.is.missing) {
182
- return this.lookup_result(result, key);
183
- }
184
- }
185
- // Globals are the final lookup tier, even when the lexical graph cycles.
186
- const globals = Frame.globals;
187
- if (globals && !globals.is.missing && !seen.has(globals)) {
188
- const result = MetaFrame.lookup(globals, key, origin, seen);
189
- if (!result.is.missing) {
190
- return this.lookup_result(result, key);
191
- }
192
- }
193
- return Frame.missing;
194
- }
195
- /** Local behavior used by the guarded lookup driver. */
196
- lookup_here(key, origin) {
197
- return this.get_here(key, origin);
198
- }
199
- /** Non-global links in lookup precedence order. */
200
- lookup_links() {
201
- const links = [];
202
- if (this.parent && !this.parent.is.missing) {
203
- links.push(this.parent);
204
- }
205
- if (this.up && !this.up.is.missing && this.up !== Frame.globals) {
206
- links.push(this.up);
207
- }
208
- return links;
209
- }
210
- /** Allows wrappers to transform a value found anywhere below them. */
211
- lookup_result(result, _key) {
212
- return result;
213
- }
214
- /** Depth-first declared-before-lexical traversal without global fallback. */
215
- static lookup(frame, key, origin, seen) {
216
- if (seen.has(frame)) {
217
- return Frame.missing;
218
- }
219
- seen.add(frame);
220
- const local = frame.lookup_here(key, origin);
221
- if (!local.is.missing) {
222
- return frame.lookup_result(local, key);
223
- }
224
- for (const link of frame.lookup_links()) {
225
- const result = MetaFrame.lookup(link, key, origin, seen);
226
- if (!result.is.missing) {
227
- return frame.lookup_result(result, key);
228
- }
229
- }
230
- return Frame.missing;
231
- }
232
- /** Depth-first binding traversal without global fallback. */
233
- static resolveBinding(frame, key, origin, seen) {
234
- if (seen.has(frame))
235
- return undefined;
236
- seen.add(frame);
237
- const local = frame.resolve_here(key, origin);
238
- if (local)
239
- return local;
240
- for (const link of frame.lookup_links()) {
241
- const result = MetaFrame.resolveBinding(link, key, origin, seen);
242
- if (result)
243
- return result;
244
- }
245
- return undefined;
246
- }
247
- /**
248
- * set adds a new key-value pair to the current context.
249
- */
250
- set(key, value) {
251
- if (this.meta === NilContext) {
252
- this.meta = {};
253
- }
254
- this.meta[key] = value;
255
- return this;
256
- }
257
- /** Whether this frame carries an explicitly declared parent. */
258
- hasDeclaredParent() {
259
- return this.parent != null && !this.parent.is.missing;
260
- }
261
- /**
262
- * setParent is the only path that may attach a declared parent, so a cyclic
263
- * declared chain cannot be built by a caller that forgot to check. It returns
264
- * an error frame when the link is refused and undefined when it is accepted.
265
- */
266
- setParent(parent) {
267
- if (this.wouldCreateParentCycle(parent)) {
268
- return Frame.error("$!.cyclic-parent .^");
269
- }
270
- this.parent = parent;
271
- return undefined;
272
- }
273
- /** Whether assigning parent would attach this frame to a cyclic chain. */
274
- wouldCreateParentCycle(parent) {
275
- const seen = new Set([this]);
276
- let current = parent;
277
- while (current && !current.is.missing) {
278
- if (seen.has(current))
279
- return true;
280
- seen.add(current);
281
- current = current.parent;
282
- }
283
- return false;
284
- }
285
- /**
286
- * meta_copy creates a shallow copy of the current context.
287
- */
288
- meta_copy() {
289
- return { ...this.meta };
290
- }
291
- /**
292
- * meta_keys returns an array of keys in the current context.
293
- */
294
- meta_keys() {
295
- return Object.keys(this.meta);
296
- }
297
- /**
298
- * meta_length returns the number of keys in the current context.
299
- */
300
- meta_length() {
301
- return this.meta_keys().length;
302
- }
303
- /**
304
- * meta_pairs returns an array of key-value pairs in the current context.
305
- */
306
- meta_pairs() {
307
- return Object.entries(this.meta);
308
- }
309
- /**
310
- * meta_string returns a string representation of the current context.
311
- *
312
- * Nested values render through the cycle guard, so metadata that reaches this
313
- * frame again yields an id rather than overflowing the host stack.
314
- */
315
- meta_string() {
316
- return this.meta_pairs().map(([key, value]) => {
317
- if (key === Frame.kOUT) {
318
- return `.${key} ${value.id};`;
319
- }
320
- return `.${key} ${renderNested(value, () => value.toString())};`;
321
- }).join(" ");
322
- }
323
- /**
324
- * match_here checks if a target string matches any key in the current context.
325
- */
326
- match_here(target) {
327
- let result = Frame.missing;
328
- this.meta_pairs().forEach(([key, value]) => {
329
- const isPattern = key.match(/\/(.*)\//);
330
- if (isPattern) {
331
- const pattern = new RegExp(isPattern[1]);
332
- if (pattern.test(target)) {
333
- result = value;
334
- if ("source" in result) {
335
- const sourced = result;
336
- sourced.source = target;
337
- }
338
- }
339
- }
340
- });
341
- return result;
342
- }
343
- authorize(physicalKey, visibility, key, origin) {
344
- const value = this.meta[physicalKey];
345
- if (value == null)
346
- return undefined;
347
- const authorized = visibility === Visibility.Public ||
348
- (visibility === Visibility.Private
349
- ? origin === this
350
- : this.isAncestorOf(origin));
351
- if (authorized) {
352
- return { owner: this, key: physicalKey, value };
353
- }
354
- return {
355
- owner: this,
356
- key: physicalKey,
357
- value: Frame.error(`$!.is-${visibility} .${key}`),
358
- };
359
- }
360
- /**
361
- * isAncestorOf walks the declared parent chain only. Lexical nesting and
362
- * syntactic containment confer no protected access: an inner aggregate or an
363
- * unrelated peer's method is not a descendant.
364
- */
365
- isAncestorOf(origin) {
366
- const seen = new Set();
367
- let current = origin;
368
- while (current && !seen.has(current)) {
369
- if (current === this)
370
- return true;
371
- seen.add(current);
372
- if (!current.hasDeclaredParent())
373
- return false;
374
- current = current.parent;
375
- }
376
- return false;
377
- }
378
- }
379
- /**
380
- * id_count is a static counter, incremented to generate unique IDs.
381
- */
382
- Object.defineProperty(MetaFrame, "id_count", {
383
- enumerable: true,
384
- configurable: true,
385
- writable: true,
386
- value: 0
387
- });
6
+ export { MetaFrame, Visibility, } from "./frame.js";
@@ -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 { isFrameMatcher, matchFailure, matchSuccess, } from "./frame-match.js";
@@ -1,5 +1,3 @@
1
- // Enter the aggregate cycle at FrameLazy, as schema matchers do.
2
- import "../frames/frame-lazy.js";
3
1
  import { Frame } from "../frames/frame.js";
4
2
  import { FrameList } from "../frames/frame-list.js";
5
3
  import { isFrameMatcher } from "../frames/frame-match.js";
@@ -1 +1 @@
1
- export const VERSION = "0.37.1";
1
+ export const VERSION = "0.37.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.37.1",
3
+ "version": "0.37.3",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",