hclang 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/lib/execute/eval-pipe.js +45 -4
- package/esm/lib/execute/hc-eval.js +4 -7
- package/esm/lib/execute/lex-pipe.js +70 -2
- package/esm/lib/execute/parse-pipe.js +84 -6
- package/esm/lib/execute/resource-import.js +81 -0
- package/esm/lib/execute/terminals.js +4 -1
- package/esm/lib/frames/evaluation-scope.js +66 -1
- package/esm/lib/frames/frame-handle.js +6 -0
- package/esm/lib/frames/frame-import.js +54 -0
- package/esm/lib/frames/frame-symbol.js +7 -14
- package/esm/lib/frames/meta-frame.js +37 -3
- package/esm/lib/frames.js +1 -0
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
import { EvaluationScope, Frame, NilContext } from "../frames.js";
|
|
1
|
+
import { EvaluationScope, Frame, FrameGroup, NilContext, } from "../frames.js";
|
|
2
|
+
import { LexPipe } from "./lex-pipe.js";
|
|
3
|
+
import { ParsePipe } from "./parse-pipe.js";
|
|
4
|
+
/** Builds the shared Lex/Parse/Eval pipeline for one HC source unit. */
|
|
5
|
+
export function makeSourcePipe(evaluator, options = {}) {
|
|
6
|
+
return new LexPipe(new ParsePipe(evaluator, FrameGroup, options));
|
|
7
|
+
}
|
|
8
|
+
/** Live lexical lookup over every layer in one supplied evaluation scope. */
|
|
9
|
+
class ScopedLexicalContext extends Frame {
|
|
10
|
+
constructor(scope) {
|
|
11
|
+
super();
|
|
12
|
+
Object.defineProperty(this, "scope", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: scope
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get(key) {
|
|
20
|
+
const receiver = this.scope.receiverState?.receiver;
|
|
21
|
+
for (const context of this.scope.lookupFrames()) {
|
|
22
|
+
const value = context.get(key, receiver ?? context);
|
|
23
|
+
if (!value.is.missing)
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
return Frame.missing;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
2
29
|
/** Evaluates parsed groups against one source unit and emits to its output. */
|
|
3
30
|
export class EvalPipe extends Frame {
|
|
31
|
+
static scoped(out, scope) {
|
|
32
|
+
const pipe = new EvalPipe(out, scope.fileScope, scope.hostNamespace);
|
|
33
|
+
pipe.scope = scope;
|
|
34
|
+
pipe.set(Frame.kOUT, new ScopedLexicalContext(scope));
|
|
35
|
+
return pipe;
|
|
36
|
+
}
|
|
4
37
|
constructor(out, fileScope = out, hostNamespace = Frame.nil, meta = NilContext) {
|
|
5
38
|
super(meta);
|
|
6
39
|
Object.defineProperty(this, "out", {
|
|
@@ -21,13 +54,21 @@ export class EvalPipe extends Frame {
|
|
|
21
54
|
writable: true,
|
|
22
55
|
value: hostNamespace
|
|
23
56
|
});
|
|
24
|
-
|
|
25
|
-
|
|
57
|
+
Object.defineProperty(this, "scope", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
// Legacy lexical features follow kOUT to the file scope. Scoped pipes
|
|
64
|
+
// replace it with a live view of every supplied lookup layer.
|
|
26
65
|
this.set(Frame.kOUT, fileScope);
|
|
27
66
|
this.up = out;
|
|
28
67
|
}
|
|
29
68
|
apply(expr, context) {
|
|
30
|
-
const
|
|
69
|
+
const scope = this.scope ??
|
|
70
|
+
EvaluationScope.root(this.fileScope, this.hostNamespace);
|
|
71
|
+
const result = expr.in(scope);
|
|
31
72
|
this.out.collect(result, context);
|
|
32
73
|
return result;
|
|
33
74
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Frame,
|
|
2
|
-
import { EvalPipe } from "./eval-pipe.js";
|
|
3
|
-
import {
|
|
4
|
-
import { ParsePipe } from "./parse-pipe.js";
|
|
1
|
+
import { Frame, FrameInt, FrameString, FrameSymbol, } from "../frames.js";
|
|
2
|
+
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
3
|
+
import { evaluateResourceSource } from "./resource-import.js";
|
|
5
4
|
import { sigilizer } from "./sigilizer.js";
|
|
6
5
|
/**
|
|
7
6
|
* Creates a new context from the given key-value entries.
|
|
@@ -54,9 +53,7 @@ export class HCEval {
|
|
|
54
53
|
* Creates a lexical pipe for evaluating expressions.
|
|
55
54
|
*/
|
|
56
55
|
static make_pipe(out, fileScope = out, hostNamespace = Frame.nil) {
|
|
57
|
-
|
|
58
|
-
const parser = new ParsePipe(evaluator, FrameGroup);
|
|
59
|
-
return new LexPipe(parser);
|
|
56
|
+
return makeSourcePipe(new EvalPipe(out, fileScope, hostNamespace), { importSource: evaluateResourceSource });
|
|
60
57
|
}
|
|
61
58
|
constructor(out, fileScope = out, hostNamespace = Frame.nil) {
|
|
62
59
|
Object.defineProperty(this, "out", {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Frame, FrameString, FrameSymbol, } from "../frames.js";
|
|
1
|
+
import { Frame, FrameInt, FrameOperator, FrameSchema, FrameString, FrameSymbol, } from "../frames.js";
|
|
2
|
+
import { Token } from "./lex.js";
|
|
3
|
+
import { sigilizer } from "./sigilizer.js";
|
|
2
4
|
import { getSyntax } from "./syntax.js";
|
|
3
5
|
function ensure_factory(factory) {
|
|
4
6
|
if (factory instanceof Frame) {
|
|
@@ -17,6 +19,12 @@ export class LexPipe extends Frame {
|
|
|
17
19
|
writable: true,
|
|
18
20
|
value: void 0
|
|
19
21
|
});
|
|
22
|
+
Object.defineProperty(this, "angleLookahead", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
20
28
|
this.level = 0;
|
|
21
29
|
}
|
|
22
30
|
lex_string(input) {
|
|
@@ -26,7 +34,46 @@ export class LexPipe extends Frame {
|
|
|
26
34
|
lex(source) {
|
|
27
35
|
return source.scanInto(this);
|
|
28
36
|
}
|
|
37
|
+
scan(argument) {
|
|
38
|
+
const pending = this.angleLookahead;
|
|
39
|
+
if (pending === undefined)
|
|
40
|
+
return super.scan(argument);
|
|
41
|
+
const symbol = argument.toString();
|
|
42
|
+
if (pending === "<") {
|
|
43
|
+
if (symbol === "-") {
|
|
44
|
+
this.angleLookahead = "<-";
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
this.angleLookahead = undefined;
|
|
48
|
+
const pushed = this.perform({ push: FrameSchema });
|
|
49
|
+
return pushed === this ? super.scan(argument) : pushed;
|
|
50
|
+
}
|
|
51
|
+
this.angleLookahead = undefined;
|
|
52
|
+
if (FrameInt.NUMBER_CHAR.test(symbol)) {
|
|
53
|
+
const pushed = this.perform({ push: FrameSchema });
|
|
54
|
+
if (pushed !== this)
|
|
55
|
+
return pushed;
|
|
56
|
+
const withMinus = sigilizer.scan(this, FrameSymbol.for("-"));
|
|
57
|
+
return sigilizer.scan(withMinus, argument);
|
|
58
|
+
}
|
|
59
|
+
this.emitImportArrow();
|
|
60
|
+
return super.scan(argument);
|
|
61
|
+
}
|
|
29
62
|
finish(_parameter) {
|
|
63
|
+
const pending = this.angleLookahead;
|
|
64
|
+
this.angleLookahead = undefined;
|
|
65
|
+
if (pending === "<") {
|
|
66
|
+
const pushed = this.perform({ push: FrameSchema });
|
|
67
|
+
if (pushed !== this)
|
|
68
|
+
return pushed;
|
|
69
|
+
}
|
|
70
|
+
else if (pending === "<-") {
|
|
71
|
+
this.emitImportArrow();
|
|
72
|
+
}
|
|
73
|
+
const parser = this.get(Frame.kOUT);
|
|
74
|
+
if (parser.strictStructure && this.level !== 0) {
|
|
75
|
+
return this.structureFailure("unclosed", `${this.level}`);
|
|
76
|
+
}
|
|
30
77
|
const next_parser = this.unbind();
|
|
31
78
|
const output = FrameSymbol.end();
|
|
32
79
|
next_parser.call(output);
|
|
@@ -41,6 +88,10 @@ export class LexPipe extends Frame {
|
|
|
41
88
|
}
|
|
42
89
|
perform(action) {
|
|
43
90
|
for (const [key, value] of Object.entries(action)) {
|
|
91
|
+
if (key === "angle") {
|
|
92
|
+
this.angleLookahead = "<";
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
44
95
|
const skip = key === "push";
|
|
45
96
|
let parser = this.unbind(skip);
|
|
46
97
|
switch (key) {
|
|
@@ -53,6 +104,10 @@ export class LexPipe extends Frame {
|
|
|
53
104
|
break;
|
|
54
105
|
}
|
|
55
106
|
case "end": {
|
|
107
|
+
if (this.level !== 0) {
|
|
108
|
+
parser.next(false);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
56
111
|
if (value instanceof Frame) {
|
|
57
112
|
parser.finish(value);
|
|
58
113
|
}
|
|
@@ -74,12 +129,18 @@ export class LexPipe extends Frame {
|
|
|
74
129
|
break;
|
|
75
130
|
}
|
|
76
131
|
case "pop": {
|
|
132
|
+
const factory = ensure_factory(value);
|
|
77
133
|
if (this.level === 0) {
|
|
134
|
+
if (parser.strictStructure) {
|
|
135
|
+
return this.structureFailure("unmatched", factory.name);
|
|
136
|
+
}
|
|
78
137
|
console.error("LexPipe.perform.pop.failed: already at top level");
|
|
79
138
|
break;
|
|
80
139
|
}
|
|
81
|
-
const factory = ensure_factory(value);
|
|
82
140
|
if (!parser.canPop(factory)) {
|
|
141
|
+
if (parser.strictStructure) {
|
|
142
|
+
return this.structureFailure("mismatched", `${factory.name} ${parser.factoryName()}`);
|
|
143
|
+
}
|
|
83
144
|
break;
|
|
84
145
|
}
|
|
85
146
|
parser = parser.pop(factory);
|
|
@@ -91,4 +152,11 @@ export class LexPipe extends Frame {
|
|
|
91
152
|
}
|
|
92
153
|
return this;
|
|
93
154
|
}
|
|
155
|
+
emitImportArrow() {
|
|
156
|
+
const parser = this.get(Frame.kOUT);
|
|
157
|
+
parser.call(new Token(new FrameOperator("<-")));
|
|
158
|
+
}
|
|
159
|
+
structureFailure(kind, detail) {
|
|
160
|
+
return Frame.error(`$!.parse-${kind}-structure ${detail}`);
|
|
161
|
+
}
|
|
94
162
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Frame, FrameArray, FrameBind, FrameExpr, FrameGroup, FrameSchema, } from "../frames.js";
|
|
1
|
+
import { Frame, FrameArray, FrameBind, FrameExpr, FrameGroup, FrameImport, FrameName, FrameOperator, FrameSchema, FrameSymbol, } from "../frames.js";
|
|
2
2
|
import { Terminal } from "./terminals.js";
|
|
3
3
|
export class ParsePipe extends FrameArray {
|
|
4
|
-
constructor(out, factory) {
|
|
4
|
+
constructor(out, factory, options = {}) {
|
|
5
5
|
const meta = {};
|
|
6
6
|
meta[ParsePipe.kOUT] = out;
|
|
7
7
|
meta[Frame.kEND] = Terminal.end();
|
|
@@ -12,6 +12,12 @@ export class ParsePipe extends FrameArray {
|
|
|
12
12
|
writable: true,
|
|
13
13
|
value: void 0
|
|
14
14
|
});
|
|
15
|
+
Object.defineProperty(this, "strictStructure", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
15
21
|
Object.defineProperty(this, "Factory", {
|
|
16
22
|
enumerable: true,
|
|
17
23
|
configurable: true,
|
|
@@ -32,9 +38,17 @@ export class ParsePipe extends FrameArray {
|
|
|
32
38
|
writable: true,
|
|
33
39
|
value: false
|
|
34
40
|
});
|
|
41
|
+
Object.defineProperty(this, "options", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
35
47
|
this.Factory = factory;
|
|
36
48
|
this.collector = [];
|
|
37
49
|
this.nested = out instanceof ParsePipe;
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.strictStructure = options.strictStructure ?? false;
|
|
38
52
|
}
|
|
39
53
|
next(statement = false) {
|
|
40
54
|
if (statement) {
|
|
@@ -52,8 +66,11 @@ export class ParsePipe extends FrameArray {
|
|
|
52
66
|
if (statement) {
|
|
53
67
|
expr.is.statement = true;
|
|
54
68
|
}
|
|
55
|
-
this.collector.push(expr);
|
|
69
|
+
this.collector.push(this.importExpression(expr));
|
|
56
70
|
this.reset();
|
|
71
|
+
if (statement && this.emitsCompletedForms()) {
|
|
72
|
+
this.emitCompletedForm();
|
|
73
|
+
}
|
|
57
74
|
return this;
|
|
58
75
|
}
|
|
59
76
|
bind(_Factory = undefined) {
|
|
@@ -67,8 +84,7 @@ export class ParsePipe extends FrameArray {
|
|
|
67
84
|
return next;
|
|
68
85
|
}
|
|
69
86
|
push(Factory) {
|
|
70
|
-
|
|
71
|
-
return child;
|
|
87
|
+
return new ParsePipe(this, Factory, this.options);
|
|
72
88
|
}
|
|
73
89
|
pop(_Factory) {
|
|
74
90
|
const parent = this.get(ParsePipe.kOUT);
|
|
@@ -77,14 +93,21 @@ export class ParsePipe extends FrameArray {
|
|
|
77
93
|
}
|
|
78
94
|
canPop(Factory) {
|
|
79
95
|
const match = this.Factory.name === Factory.name;
|
|
80
|
-
if (!match) {
|
|
96
|
+
if (!match && !this.strictStructure) {
|
|
81
97
|
console.error(`ParsePipe.canPop.failed: ${Factory.name} cannot pop ${this.Factory.name}`);
|
|
82
98
|
}
|
|
83
99
|
return match;
|
|
84
100
|
}
|
|
101
|
+
factoryName() {
|
|
102
|
+
return this.Factory.name;
|
|
103
|
+
}
|
|
85
104
|
finish(terminal) {
|
|
86
105
|
this.next();
|
|
87
106
|
const out = this.get(Frame.kOUT);
|
|
107
|
+
if (this.emitsCompletedForms() && this.collector.length === 0) {
|
|
108
|
+
out.call(terminal);
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
88
111
|
let value = this.makeFrame();
|
|
89
112
|
if (value instanceof FrameBind && value.isEmpty()) {
|
|
90
113
|
return out;
|
|
@@ -110,4 +133,59 @@ export class ParsePipe extends FrameArray {
|
|
|
110
133
|
this.sequenced = false;
|
|
111
134
|
return group;
|
|
112
135
|
}
|
|
136
|
+
emitsCompletedForms() {
|
|
137
|
+
return !this.nested && (this.options.emitCompletedForms ?? false);
|
|
138
|
+
}
|
|
139
|
+
emitCompletedForm() {
|
|
140
|
+
const out = this.get(Frame.kOUT);
|
|
141
|
+
out.call(this.makeFrame());
|
|
142
|
+
}
|
|
143
|
+
importExpression(expr) {
|
|
144
|
+
if (this.Factory === FrameBind)
|
|
145
|
+
return expr;
|
|
146
|
+
let terms = expr.asArray().map(unwrapImportTerm);
|
|
147
|
+
if (terms.length === 2 &&
|
|
148
|
+
(terms[1] instanceof FrameBind || terms[1] instanceof FrameExpr)) {
|
|
149
|
+
const remainder = terms[1].asArray().map(unwrapImportTerm);
|
|
150
|
+
if (remainder[0] instanceof FrameOperator &&
|
|
151
|
+
remainder[0].operator === "<-") {
|
|
152
|
+
terms = [terms[0], ...remainder];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const arrows = terms.filter((term) => term instanceof FrameOperator && term.operator === "<-");
|
|
156
|
+
if (arrows.length === 0)
|
|
157
|
+
return expr;
|
|
158
|
+
const fail = () => wrapExpression(Frame.error(`$!.resource-import-syntax ${expr.toString()}`), expr);
|
|
159
|
+
if (arrows.length !== 1 || terms.length !== 3 ||
|
|
160
|
+
!(terms[1] instanceof FrameOperator) ||
|
|
161
|
+
terms[1].operator !== "<-" || this.options.importSource === undefined) {
|
|
162
|
+
return fail();
|
|
163
|
+
}
|
|
164
|
+
let target;
|
|
165
|
+
if (terms[0] instanceof FrameName && terms[0].source === "") {
|
|
166
|
+
target = { kind: "local" };
|
|
167
|
+
}
|
|
168
|
+
else if (terms[0] instanceof FrameSymbol &&
|
|
169
|
+
Object.getPrototypeOf(terms[0]) === FrameSymbol.prototype) {
|
|
170
|
+
target = { kind: "named", key: terms[0].spelling() };
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return fail();
|
|
174
|
+
}
|
|
175
|
+
return wrapExpression(new FrameImport(target, terms[2], this.options.importSource), expr);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function unwrapImportTerm(frame) {
|
|
179
|
+
let result = frame;
|
|
180
|
+
while ((result instanceof FrameBind || result instanceof FrameExpr) &&
|
|
181
|
+
result.size() === 1) {
|
|
182
|
+
result = result.asArray()[0];
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
function wrapExpression(value, source) {
|
|
187
|
+
const result = new FrameExpr([value]);
|
|
188
|
+
if (source.is.statement === true)
|
|
189
|
+
result.is.statement = true;
|
|
190
|
+
return result;
|
|
113
191
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Frame, FrameExpr, FrameSymbol, hasCharacterContent, } from "../frames.js";
|
|
2
|
+
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
3
|
+
import { sigilizer } from "./sigilizer.js";
|
|
4
|
+
/** Private output state for one imported source evaluation. */
|
|
5
|
+
class ImportProgress extends Frame {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
Object.defineProperty(this, "lastResult", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: Frame.nil
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "firstFailure", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
collect(value) {
|
|
22
|
+
const answer = FrameExpr.answeredValue(value);
|
|
23
|
+
if (this.firstFailure === undefined) {
|
|
24
|
+
if (answer.isFailedResult()) {
|
|
25
|
+
this.firstFailure = answer;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.lastResult = answer;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const sourceTypeFailure = (value) => Frame.error(`$!.resource-import-source-type ${value.toString()}`);
|
|
35
|
+
/** Evaluate a resource's character elements through the existing HC pipeline. */
|
|
36
|
+
export function evaluateResourceSource(resource, scope) {
|
|
37
|
+
return evaluateResourceSourceWithChain(resource, scope, []);
|
|
38
|
+
}
|
|
39
|
+
function evaluateResourceSourceWithChain(resource, scope, activeImports) {
|
|
40
|
+
const spelling = resource.toString();
|
|
41
|
+
if (activeImports.some((active) => active.hostNamespace === scope.hostNamespace &&
|
|
42
|
+
active.resource === spelling)) {
|
|
43
|
+
return Frame.error(`$!.resource-import-cycle ${spelling}`);
|
|
44
|
+
}
|
|
45
|
+
const nextActiveImports = [
|
|
46
|
+
...activeImports,
|
|
47
|
+
{ hostNamespace: scope.hostNamespace, resource: spelling },
|
|
48
|
+
];
|
|
49
|
+
const progress = new ImportProgress();
|
|
50
|
+
const lexer = makeSourcePipe(EvalPipe.scoped(progress, scope), {
|
|
51
|
+
importSource: (nestedResource, nestedScope) => evaluateResourceSourceWithChain(nestedResource, nestedScope, nextActiveImports),
|
|
52
|
+
emitCompletedForms: true,
|
|
53
|
+
strictStructure: true,
|
|
54
|
+
});
|
|
55
|
+
let receiver = lexer;
|
|
56
|
+
const elements = resource.elements();
|
|
57
|
+
for (const element of elements) {
|
|
58
|
+
if (element.isFailedResult())
|
|
59
|
+
return element;
|
|
60
|
+
if (!hasCharacterContent(element))
|
|
61
|
+
return sourceTypeFailure(element);
|
|
62
|
+
for (const character of element.characterContent().split("")) {
|
|
63
|
+
receiver = sigilizer.scan(receiver, FrameSymbol.for(character));
|
|
64
|
+
if (receiver.isFailedResult())
|
|
65
|
+
return receiver;
|
|
66
|
+
if (progress.firstFailure)
|
|
67
|
+
return progress.firstFailure;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (receiver !== lexer) {
|
|
71
|
+
receiver = sigilizer.finish(receiver, FrameSymbol.end());
|
|
72
|
+
if (receiver.isFailedResult())
|
|
73
|
+
return receiver;
|
|
74
|
+
if (progress.firstFailure)
|
|
75
|
+
return progress.firstFailure;
|
|
76
|
+
}
|
|
77
|
+
const finished = lexer.finish(Frame.nil);
|
|
78
|
+
if (finished.isFailedResult())
|
|
79
|
+
return finished;
|
|
80
|
+
return progress.firstFailure ?? progress.lastResult;
|
|
81
|
+
}
|
|
@@ -48,7 +48,10 @@ function addGroup(Grouper) {
|
|
|
48
48
|
if (mode !== "push" && mode !== "pop") {
|
|
49
49
|
throw new Error(`Invalid structural Sigil mode: ${mode}`);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const action = Grouper === FrameSchema && key === FrameSchema.BEGIN_SCHEMA
|
|
52
|
+
? "angle"
|
|
53
|
+
: mode;
|
|
54
|
+
terminals[key] = new Terminal(perform({ [action]: Grouper }));
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
terminals[Frame.kEND] = Terminal.end();
|
|
@@ -9,9 +9,52 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _EvaluationScope_lookupFrames, _EvaluationScope_lookupMembers;
|
|
12
|
+
var _LiveLookupContext_lookupFrames, _LiveLookupContext_identityHandles, _EvaluationScope_lookupFrames, _EvaluationScope_lookupMembers;
|
|
13
13
|
import { Frame } from "./frame.js";
|
|
14
14
|
import { FrameHandle } from "./frame-handle.js";
|
|
15
|
+
/** Live, read-only lookup through an ordered set of existing frame identities. */
|
|
16
|
+
class LiveLookupContext extends Frame {
|
|
17
|
+
constructor(frames, continuation) {
|
|
18
|
+
super();
|
|
19
|
+
Object.defineProperty(this, "continuation", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: continuation
|
|
24
|
+
});
|
|
25
|
+
_LiveLookupContext_lookupFrames.set(this, void 0);
|
|
26
|
+
_LiveLookupContext_identityHandles.set(this, new WeakMap());
|
|
27
|
+
__classPrivateFieldSet(this, _LiveLookupContext_lookupFrames, frames.map((frame) => frame instanceof FrameHandle ? frame.withoutWriteAuthority() : frame), "f");
|
|
28
|
+
}
|
|
29
|
+
resolve_here(key, _origin = this) {
|
|
30
|
+
for (const context of __classPrivateFieldGet(this, _LiveLookupContext_lookupFrames, "f")) {
|
|
31
|
+
const binding = context.resolve(key, context);
|
|
32
|
+
if (binding)
|
|
33
|
+
return binding;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
lookup_here(key, _origin) {
|
|
38
|
+
for (const context of __classPrivateFieldGet(this, _LiveLookupContext_lookupFrames, "f")) {
|
|
39
|
+
const value = context.get(key, context);
|
|
40
|
+
if (value.is.missing)
|
|
41
|
+
continue;
|
|
42
|
+
if (value instanceof FrameHandle) {
|
|
43
|
+
return value.withoutWriteAuthority();
|
|
44
|
+
}
|
|
45
|
+
if (!value.ownsIdentity())
|
|
46
|
+
return value;
|
|
47
|
+
const existing = __classPrivateFieldGet(this, _LiveLookupContext_identityHandles, "f").get(value);
|
|
48
|
+
if (existing)
|
|
49
|
+
return existing;
|
|
50
|
+
const projected = new FrameHandle(value, false, undefined, this.continuation);
|
|
51
|
+
__classPrivateFieldGet(this, _LiveLookupContext_identityHandles, "f").set(value, projected);
|
|
52
|
+
return projected;
|
|
53
|
+
}
|
|
54
|
+
return Frame.missing;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_LiveLookupContext_lookupFrames = new WeakMap(), _LiveLookupContext_identityHandles = new WeakMap();
|
|
15
58
|
/**
|
|
16
59
|
* Named, immutable state for one evaluation.
|
|
17
60
|
*
|
|
@@ -214,6 +257,28 @@ export class EvaluationScope {
|
|
|
214
257
|
carriedRoots?.hostNamespace ?? Frame.nil,
|
|
215
258
|
});
|
|
216
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Creates a fresh named namespace with live lookup into this scope.
|
|
262
|
+
*
|
|
263
|
+
* Imported declarations stop at the namespace, while lookup retains exact
|
|
264
|
+
* references to the caller's existing layers. Call-only parameter and
|
|
265
|
+
* receiver authority are deliberately not inherited.
|
|
266
|
+
*/
|
|
267
|
+
namedChild(namespace) {
|
|
268
|
+
namespace.up = new LiveLookupContext(__classPrivateFieldGet(this, _EvaluationScope_lookupFrames, "f"), namespace);
|
|
269
|
+
const layers = EvaluationScope.layers([namespace]);
|
|
270
|
+
return new EvaluationScope({
|
|
271
|
+
argument: namespace,
|
|
272
|
+
writeTarget: namespace,
|
|
273
|
+
writeTargetRole: "statement",
|
|
274
|
+
lookupFrames: layers.frames,
|
|
275
|
+
lookupMembers: layers.members,
|
|
276
|
+
enclosing: this,
|
|
277
|
+
lexicalTarget: namespace,
|
|
278
|
+
fileScope: namespace,
|
|
279
|
+
hostNamespace: this.hostNamespace,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
217
282
|
/**
|
|
218
283
|
* Adds syntax or metadata to lookup without changing any named role.
|
|
219
284
|
*
|
|
@@ -75,6 +75,12 @@ export class FrameHandle extends Frame {
|
|
|
75
75
|
isMutable() {
|
|
76
76
|
return this.mutable;
|
|
77
77
|
}
|
|
78
|
+
/** Retains this live reference while withholding its write capability. */
|
|
79
|
+
withoutWriteAuthority() {
|
|
80
|
+
return this.mutable
|
|
81
|
+
? new FrameHandle(this.target, false, this.copyOnWrite, this.readContext, this.searchReadContext)
|
|
82
|
+
: this;
|
|
83
|
+
}
|
|
78
84
|
/** The lexical fallback selected for this particular read. */
|
|
79
85
|
readContextFrame() {
|
|
80
86
|
return this.readContext;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Frame } from "./frame.js";
|
|
2
|
+
import { FrameArray } from "./frame-array.js";
|
|
3
|
+
import { FrameResource } from "./frame-resource.js";
|
|
4
|
+
import { FrameSymbol } from "./frame-symbol.js";
|
|
5
|
+
import { EvaluationScope } from "./evaluation-scope.js";
|
|
6
|
+
/** An import expression whose source evaluator is supplied by the pipeline. */
|
|
7
|
+
export class FrameImport extends Frame {
|
|
8
|
+
constructor(target, resourceExpression, evaluateSource) {
|
|
9
|
+
super();
|
|
10
|
+
Object.defineProperty(this, "target", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: target
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "resourceExpression", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: resourceExpression
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "evaluateSource", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: evaluateSource
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
in(input = []) {
|
|
30
|
+
const scope = EvaluationScope.from(input);
|
|
31
|
+
const resource = this.resourceExpression.in(scope);
|
|
32
|
+
if (resource.isFailedResult())
|
|
33
|
+
return resource;
|
|
34
|
+
if (!(resource instanceof FrameResource)) {
|
|
35
|
+
return Frame.error(`$!.resource-import-source-type ${resource.toString()}`);
|
|
36
|
+
}
|
|
37
|
+
if (this.target.kind === "local") {
|
|
38
|
+
return this.evaluateSource(resource, scope);
|
|
39
|
+
}
|
|
40
|
+
const namespace = new FrameArray([]);
|
|
41
|
+
const child = scope.namedChild(namespace);
|
|
42
|
+
const result = this.evaluateSource(resource, child);
|
|
43
|
+
if (result.isFailedResult())
|
|
44
|
+
return result;
|
|
45
|
+
const binding = FrameSymbol.for(this.target.key)
|
|
46
|
+
.setter(scope.writeTarget)
|
|
47
|
+
.apply(namespace, Frame.nil);
|
|
48
|
+
return binding.isFailedResult() ? binding : result;
|
|
49
|
+
}
|
|
50
|
+
toString() {
|
|
51
|
+
const target = this.target.kind === "local" ? "." : this.target.key;
|
|
52
|
+
return `${target} <- ${this.resourceExpression.toString()}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -160,20 +160,13 @@ export class FrameSymbol extends FrameAtom {
|
|
|
160
160
|
const scope = EvaluationScope.from(input);
|
|
161
161
|
const first = scope.argument;
|
|
162
162
|
for (const context of scope.lookupFrames()) {
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (binding.value.is.error)
|
|
171
|
-
return binding.value;
|
|
172
|
-
const schema = owner.meta[`${binding.key}.<>`];
|
|
173
|
-
return schema ?? Frame.error(`$!.schema-missing .${this.data}`);
|
|
174
|
-
}
|
|
175
|
-
owner = owner.up;
|
|
176
|
-
}
|
|
163
|
+
const binding = context.resolve(this.data, context);
|
|
164
|
+
if (!binding)
|
|
165
|
+
continue;
|
|
166
|
+
if (binding.value.is.error)
|
|
167
|
+
return binding.value;
|
|
168
|
+
const schema = binding.owner.meta[`${binding.key}.<>`];
|
|
169
|
+
return schema ?? Frame.error(`$!.schema-missing .${this.data}`);
|
|
177
170
|
}
|
|
178
171
|
return FrameNote.key(first.id + "." + this.data, first);
|
|
179
172
|
}
|
|
@@ -117,11 +117,29 @@ export class MetaFrame {
|
|
|
117
117
|
return this.authorize(key, Visibility.Protected, key.slice(1), origin);
|
|
118
118
|
}
|
|
119
119
|
const publicValue = this.meta[key];
|
|
120
|
-
if (publicValue != null)
|
|
121
|
-
return { key, value: publicValue };
|
|
120
|
+
if (publicValue != null) {
|
|
121
|
+
return { owner: this, key, value: publicValue };
|
|
122
|
+
}
|
|
122
123
|
return this.authorize(`_${key}`, Visibility.Protected, key, origin) ??
|
|
123
124
|
this.authorize(`__${key}`, Visibility.Private, key, origin);
|
|
124
125
|
}
|
|
126
|
+
/** Resolves a binding through the same guarded graph as ordinary lookup. */
|
|
127
|
+
resolve(key, origin = this) {
|
|
128
|
+
const local = this.resolve_here(key, origin);
|
|
129
|
+
if (local)
|
|
130
|
+
return local;
|
|
131
|
+
const seen = new Set([this]);
|
|
132
|
+
for (const link of this.lookup_links()) {
|
|
133
|
+
const result = MetaFrame.resolveBinding(link, key, origin, seen);
|
|
134
|
+
if (result)
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
const globals = Frame.globals;
|
|
138
|
+
if (globals && !globals.is.missing && !seen.has(globals)) {
|
|
139
|
+
return MetaFrame.resolveBinding(globals, key, origin, seen);
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
125
143
|
/**
|
|
126
144
|
* Get a frame by key through one guarded lookup traversal.
|
|
127
145
|
*
|
|
@@ -190,6 +208,21 @@ export class MetaFrame {
|
|
|
190
208
|
}
|
|
191
209
|
return Frame.missing;
|
|
192
210
|
}
|
|
211
|
+
/** Depth-first binding traversal without global fallback. */
|
|
212
|
+
static resolveBinding(frame, key, origin, seen) {
|
|
213
|
+
if (seen.has(frame))
|
|
214
|
+
return undefined;
|
|
215
|
+
seen.add(frame);
|
|
216
|
+
const local = frame.resolve_here(key, origin);
|
|
217
|
+
if (local)
|
|
218
|
+
return local;
|
|
219
|
+
for (const link of frame.lookup_links()) {
|
|
220
|
+
const result = MetaFrame.resolveBinding(link, key, origin, seen);
|
|
221
|
+
if (result)
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
193
226
|
/**
|
|
194
227
|
* set adds a new key-value pair to the current context.
|
|
195
228
|
*/
|
|
@@ -295,9 +328,10 @@ export class MetaFrame {
|
|
|
295
328
|
? origin === this
|
|
296
329
|
: this.isAncestorOf(origin));
|
|
297
330
|
if (authorized) {
|
|
298
|
-
return { key: physicalKey, value };
|
|
331
|
+
return { owner: this, key: physicalKey, value };
|
|
299
332
|
}
|
|
300
333
|
return {
|
|
334
|
+
owner: this,
|
|
301
335
|
key: physicalKey,
|
|
302
336
|
value: Frame.error(`$!.is-${visibility} .${key}`),
|
|
303
337
|
};
|
package/esm/lib/frames.js
CHANGED
|
@@ -15,6 +15,7 @@ export { FrameBind, FrameExpr } from "./frames/frame-expr.js";
|
|
|
15
15
|
// tests, while `WriteTargetRole` stays private to the scope module.
|
|
16
16
|
export { EvaluationScope, } from "./frames/evaluation-scope.js";
|
|
17
17
|
export { FrameGroup } from "./frames/frame-group.js";
|
|
18
|
+
export { FrameImport, } from "./frames/frame-import.js";
|
|
18
19
|
export { FrameLazy } from "./frames/frame-lazy.js";
|
|
19
20
|
export { isFrameMatcher, } from "./frames/frame-match.js";
|
|
20
21
|
export { FrameList } from "./frames/frame-list.js";
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.20.0";
|