hclang 0.20.1 → 0.20.2
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/lex-pipe.js +7 -0
- package/esm/lib/frames/bound-method.js +5 -5
- package/esm/lib/frames/evaluation-scope.js +24 -7
- package/esm/lib/frames/frame-alias.js +20 -19
- package/esm/lib/frames/frame-array.js +73 -35
- package/esm/lib/frames/frame-handle.js +51 -24
- package/esm/lib/frames/frame-string.js +12 -6
- package/esm/lib/frames/frame-symbol.js +8 -5
- package/esm/lib/frames/frame.js +49 -5
- package/esm/lib/frames/resource-store.js +34 -9
- package/esm/lib/modules/standard-modules.js +7 -13
- package/esm/lib/modules/standard-sources.js +321 -271
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -74,6 +74,13 @@ export class LexPipe extends Frame {
|
|
|
74
74
|
if (parser.strictStructure && this.level !== 0) {
|
|
75
75
|
return this.structureFailure("unclosed", `${this.level}`);
|
|
76
76
|
}
|
|
77
|
+
// A line that ends inside an open structure ends a term, as a newline
|
|
78
|
+
// character does there, so a line-fed source and a character-fed one
|
|
79
|
+
// parse a multi-line aggregate alike rather than closing it row by row.
|
|
80
|
+
if (this.level !== 0) {
|
|
81
|
+
this.unbind().next(false);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
77
84
|
const next_parser = this.unbind();
|
|
78
85
|
const output = FrameSymbol.end();
|
|
79
86
|
next_parser.call(output);
|
|
@@ -112,12 +112,12 @@ export class BoundMethod extends Frame {
|
|
|
112
112
|
}
|
|
113
113
|
return receiverState(this.receiverTarget, true, this.copyOnWrite, this.lexicalContext, true);
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// Only the receiver is copied now. A member is copied when a write is
|
|
116
|
+
// about to land on it, so whatever the call never writes keeps its
|
|
117
|
+
// identity (#401).
|
|
118
|
+
const target = this.receiverTarget.instanceCopy();
|
|
117
119
|
const copyOnWrite = this.copyOnWrite ?? new WeakSet();
|
|
118
|
-
|
|
119
|
-
copyOnWrite.add(aggregate);
|
|
120
|
-
}
|
|
120
|
+
copyOnWrite.add(target);
|
|
121
121
|
return receiverState(target, true, copyOnWrite, this.lexicalContext, true);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -9,7 +9,7 @@ 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 _LiveLookupContext_lookupFrames, _LiveLookupContext_identityHandles, _EvaluationScope_lookupFrames, _EvaluationScope_lookupMembers;
|
|
12
|
+
var _LiveLookupContext_lookupFrames, _LiveLookupContext_identityHandles, _EvaluationScope_lookupFrames, _EvaluationScope_lookupMembers, _EvaluationScope_argumentLayer;
|
|
13
13
|
import { Frame } from "./frame.js";
|
|
14
14
|
import { FrameHandle } from "./frame-handle.js";
|
|
15
15
|
/** Live, read-only lookup through an ordered set of existing frame identities. */
|
|
@@ -130,6 +130,7 @@ export class EvaluationScope {
|
|
|
130
130
|
});
|
|
131
131
|
_EvaluationScope_lookupFrames.set(this, void 0);
|
|
132
132
|
_EvaluationScope_lookupMembers.set(this, void 0);
|
|
133
|
+
_EvaluationScope_argumentLayer.set(this, void 0);
|
|
133
134
|
this.argument = options.argument;
|
|
134
135
|
this.parameter = options.parameter;
|
|
135
136
|
this.receiverState = options.receiverState;
|
|
@@ -142,6 +143,7 @@ export class EvaluationScope {
|
|
|
142
143
|
this.hostNamespace = options.hostNamespace;
|
|
143
144
|
__classPrivateFieldSet(this, _EvaluationScope_lookupFrames, options.lookupFrames, "f");
|
|
144
145
|
__classPrivateFieldSet(this, _EvaluationScope_lookupMembers, options.lookupMembers, "f");
|
|
146
|
+
__classPrivateFieldSet(this, _EvaluationScope_argumentLayer, options.argumentLayer, "f");
|
|
145
147
|
}
|
|
146
148
|
/** Creates the scope at the evaluator boundary. */
|
|
147
149
|
static root(fileScope, hostNamespace = Frame.nil) {
|
|
@@ -226,14 +228,18 @@ export class EvaluationScope {
|
|
|
226
228
|
const lookupFrames = [local, argument];
|
|
227
229
|
if (!parameter.is.void)
|
|
228
230
|
lookupFrames.push(parameter);
|
|
229
|
-
|
|
231
|
+
// A block nested in a method runs with the receiver state its method
|
|
232
|
+
// forwarded, and the enclosing method scope already holds the receiver
|
|
233
|
+
// layers behind the method's own locals. Pushing them again here would put
|
|
234
|
+
// the scope the receiver was read from ahead of those locals, so a caller
|
|
235
|
+
// that binds a local's name would capture it (#382 H11).
|
|
236
|
+
const forwarded = receiverState !== undefined &&
|
|
237
|
+
receiverState === enclosing?.receiverState;
|
|
238
|
+
if (receiverState && !forwarded) {
|
|
230
239
|
const receiverLookup = receiverState.lexicalContext
|
|
231
|
-
? new FrameHandle(receiverState.receiver, receiverState.mutable, receiverState.copyOnWrite, receiverState.lexicalContext
|
|
240
|
+
? new FrameHandle(receiverState.receiver, receiverState.mutable, receiverState.copyOnWrite, receiverState.lexicalContext)
|
|
232
241
|
: receiverState.receiver;
|
|
233
242
|
lookupFrames.push(receiverLookup);
|
|
234
|
-
if (receiverState.lexicalContext) {
|
|
235
|
-
lookupFrames.push(receiverState.lexicalContext);
|
|
236
|
-
}
|
|
237
243
|
}
|
|
238
244
|
if (closure)
|
|
239
245
|
lookupFrames.push(closure);
|
|
@@ -253,6 +259,7 @@ export class EvaluationScope {
|
|
|
253
259
|
writeTargetRole: targetRole,
|
|
254
260
|
lookupFrames: layers.frames,
|
|
255
261
|
lookupMembers: layers.members,
|
|
262
|
+
argumentLayer: argument,
|
|
256
263
|
enclosing,
|
|
257
264
|
closure,
|
|
258
265
|
lexicalTarget: target,
|
|
@@ -301,6 +308,7 @@ export class EvaluationScope {
|
|
|
301
308
|
writeTargetRole: this.writeTargetRole,
|
|
302
309
|
lookupFrames: layers.frames,
|
|
303
310
|
lookupMembers: layers.members,
|
|
311
|
+
argumentLayer: __classPrivateFieldGet(this, _EvaluationScope_argumentLayer, "f"),
|
|
304
312
|
enclosing: this.enclosing,
|
|
305
313
|
closure: this.closure,
|
|
306
314
|
lexicalTarget: this.lexicalTarget,
|
|
@@ -319,6 +327,7 @@ export class EvaluationScope {
|
|
|
319
327
|
writeTargetRole: role,
|
|
320
328
|
lookupFrames: layers.frames,
|
|
321
329
|
lookupMembers: layers.members,
|
|
330
|
+
argumentLayer: __classPrivateFieldGet(this, _EvaluationScope_argumentLayer, "f"),
|
|
322
331
|
enclosing: this.enclosing,
|
|
323
332
|
closure: this.closure,
|
|
324
333
|
lexicalTarget: target,
|
|
@@ -341,6 +350,14 @@ export class EvaluationScope {
|
|
|
341
350
|
lookupFrames() {
|
|
342
351
|
return __classPrivateFieldGet(this, _EvaluationScope_lookupFrames, "f");
|
|
343
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Whether `layer` is this call's explicit argument, which lookup reads for
|
|
355
|
+
* its own and inherited properties only (spec 7, layer 2), never through the
|
|
356
|
+
* scope that built it.
|
|
357
|
+
*/
|
|
358
|
+
isArgumentLayer(layer) {
|
|
359
|
+
return layer === __classPrivateFieldGet(this, _EvaluationScope_argumentLayer, "f");
|
|
360
|
+
}
|
|
344
361
|
/** Resolves `_`, `__`, ... through enclosing call scopes. */
|
|
345
362
|
argumentAt(level) {
|
|
346
363
|
if (level <= 1)
|
|
@@ -456,4 +473,4 @@ export class EvaluationScope {
|
|
|
456
473
|
return { target: fallback, role: "statement" };
|
|
457
474
|
}
|
|
458
475
|
}
|
|
459
|
-
_EvaluationScope_lookupFrames = new WeakMap(), _EvaluationScope_lookupMembers = new WeakMap();
|
|
476
|
+
_EvaluationScope_lookupFrames = new WeakMap(), _EvaluationScope_lookupMembers = new WeakMap(), _EvaluationScope_argumentLayer = new WeakMap();
|
|
@@ -28,8 +28,9 @@ export class FrameAlias extends FrameAtom {
|
|
|
28
28
|
scope.lookupFrames().find((context) => context instanceof FrameLazy) ??
|
|
29
29
|
scope.argument;
|
|
30
30
|
// Receiver and declared-parent hits are writes to object state, so they
|
|
31
|
-
// require the method capability. A miss searches the
|
|
32
|
-
//
|
|
31
|
+
// require the method capability. A miss searches the method's own scope and
|
|
32
|
+
// the scope it was written in, never the scope its receiver was read from
|
|
33
|
+
// (#400) and never caller-owned argument or parameter values.
|
|
33
34
|
const receiverFound = receiver
|
|
34
35
|
? this.find(receiver, key, origin, new Set(), false)
|
|
35
36
|
: undefined;
|
|
@@ -43,13 +44,19 @@ export class FrameAlias extends FrameAtom {
|
|
|
43
44
|
return this.setterFor(receiverFound, key, receiverState?.copyOnWrite);
|
|
44
45
|
}
|
|
45
46
|
if (receiver) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
for (const context of scope.lookupFrames()) {
|
|
49
|
+
if (context === scope.argument || context === scope.parameter ||
|
|
50
|
+
context.referent() === receiver)
|
|
51
|
+
continue;
|
|
52
|
+
const lexicalFound = this.find(context, key, origin, seen);
|
|
53
|
+
if (lexicalFound instanceof Frame)
|
|
54
|
+
return lexicalFound;
|
|
55
|
+
if (lexicalFound) {
|
|
56
|
+
return this.setterFor(lexicalFound, key, receiverState?.copyOnWrite);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return FrameNote.key(key, this);
|
|
53
60
|
}
|
|
54
61
|
for (const context of scope.lookupFrames()) {
|
|
55
62
|
const found = this.find(context, key, origin);
|
|
@@ -73,17 +80,11 @@ export class FrameAlias extends FrameAtom {
|
|
|
73
80
|
return undefined;
|
|
74
81
|
}
|
|
75
82
|
seen.add(context);
|
|
76
|
-
// A
|
|
77
|
-
// the
|
|
78
|
-
//
|
|
79
|
-
// invocation.
|
|
83
|
+
// A handle created by a read reaches its target and declared parents only:
|
|
84
|
+
// neither the target's historical `up`, which belongs to neither this
|
|
85
|
+
// receiver nor this invocation, nor the scope of the read (#400).
|
|
80
86
|
if (context instanceof FrameHandle && context.readContextFrame()) {
|
|
81
|
-
|
|
82
|
-
if (targetFound)
|
|
83
|
-
return targetFound;
|
|
84
|
-
return followLexical
|
|
85
|
-
? this.find(context.readContextFrame(), key, origin, seen)
|
|
86
|
-
: undefined;
|
|
87
|
+
return this.find(context.unwrap(), key, origin, seen, false, true);
|
|
87
88
|
}
|
|
88
89
|
const binding = context.resolve_here(key, origin);
|
|
89
90
|
if (binding?.value.is.error) {
|
|
@@ -107,25 +107,26 @@ export class FrameArray extends FrameList {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* own field, and the id is always fresh.
|
|
110
|
+
* An instance copy is a fresh aggregate whose members are shared, so a
|
|
111
|
+
* member keeps its identity until a write is about to land on it. Copy on
|
|
112
|
+
* write copies that member then, into the copy that holds it
|
|
113
|
+
* (`FrameHandle.copyOnWriteTarget`, #401), so writing through the copy is
|
|
114
|
+
* still invisible through the original at any depth. A declared parent rides
|
|
115
|
+
* along in its own field, and the id is always fresh.
|
|
116
116
|
*/
|
|
117
|
-
instanceCopy(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
instanceCopy() {
|
|
118
|
+
return this.copy();
|
|
119
|
+
}
|
|
120
|
+
/** Elements are members too, so a held element can be replaced in place. */
|
|
121
|
+
replaceMember(member, replacement) {
|
|
122
|
+
let replaced = super.replaceMember(member, replacement);
|
|
123
|
+
this.data = this.data.map((item) => {
|
|
124
|
+
if (item !== member)
|
|
125
|
+
return item;
|
|
126
|
+
replaced = true;
|
|
127
|
+
return replacement;
|
|
128
|
+
});
|
|
129
|
+
return replaced;
|
|
129
130
|
}
|
|
130
131
|
lookup_here(key, origin) {
|
|
131
132
|
if (/^\d+$/.test(key)) {
|
|
@@ -152,19 +153,45 @@ export class FrameArray extends FrameList {
|
|
|
152
153
|
*/
|
|
153
154
|
applicationMethod() {
|
|
154
155
|
for (const key of FrameArray.APPLICATION_KEYS) {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
while (local.is.missing && next && !seen.has(next)) {
|
|
159
|
-
seen.add(next);
|
|
160
|
-
local = next.get_here(key);
|
|
161
|
-
next = next.hasDeclaredParent() ? next.parent : undefined;
|
|
162
|
-
}
|
|
163
|
-
if (local.className() === "FrameLazy")
|
|
164
|
-
return { key, method: local };
|
|
156
|
+
const method = this.declaredMethod(key);
|
|
157
|
+
if (method)
|
|
158
|
+
return { key, method };
|
|
165
159
|
}
|
|
166
160
|
return undefined;
|
|
167
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* What this aggregate contributes when text receives it (#398).
|
|
164
|
+
*
|
|
165
|
+
* Text contributes an aggregate's spelling, which reads back as the same
|
|
166
|
+
* value but spells every declaration, methods included. An aggregate that
|
|
167
|
+
* declares `toText`, on itself or a declared parent, contributes that
|
|
168
|
+
* method's answer instead, the way one that declares `apply` decides its own
|
|
169
|
+
* application. The printer never calls it, so a printed value still reads
|
|
170
|
+
* back.
|
|
171
|
+
*/
|
|
172
|
+
toText() {
|
|
173
|
+
const method = this.declaredMethod(FrameArray.TEXT_KEY);
|
|
174
|
+
if (!method)
|
|
175
|
+
return this;
|
|
176
|
+
return new BoundMethod(method, this, false, methodEffect(FrameArray.TEXT_KEY)).call(Frame.nil);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A method declared under `key` on this aggregate or its declared parents.
|
|
180
|
+
*
|
|
181
|
+
* Never the scope around it, so a plain array keeps its default behavior
|
|
182
|
+
* wherever it is written.
|
|
183
|
+
*/
|
|
184
|
+
declaredMethod(key) {
|
|
185
|
+
const seen = new Set([this]);
|
|
186
|
+
let local = this.get_here(key);
|
|
187
|
+
let next = this.hasDeclaredParent() ? this.parent : undefined;
|
|
188
|
+
while (local.is.missing && next && !seen.has(next)) {
|
|
189
|
+
seen.add(next);
|
|
190
|
+
local = next.get_here(key);
|
|
191
|
+
next = next.hasDeclaredParent() ? next.parent : undefined;
|
|
192
|
+
}
|
|
193
|
+
return local.className() === "FrameLazy" ? local : undefined;
|
|
194
|
+
}
|
|
168
195
|
/**
|
|
169
196
|
* Runs a declared application with the receiver it binds to.
|
|
170
197
|
*
|
|
@@ -201,16 +228,20 @@ export class FrameArray extends FrameList {
|
|
|
201
228
|
}
|
|
202
229
|
return this;
|
|
203
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* The element at `index`, counting from the end when negative.
|
|
233
|
+
*
|
|
234
|
+
* An index addresses the element plane, the one `&` iterates, so declaring a
|
|
235
|
+
* property never shifts an element's index: `[.k 1; 4, 5] .0` is `4`.
|
|
236
|
+
*/
|
|
204
237
|
at(index) {
|
|
205
|
-
|
|
206
|
-
|
|
238
|
+
const elements = this.elements();
|
|
239
|
+
const n = elements.length;
|
|
240
|
+
if (index >= n || -index > n) {
|
|
241
|
+
const source = "[0.." + n + "]." + index;
|
|
207
242
|
return FrameNote.index(source);
|
|
208
243
|
}
|
|
209
|
-
|
|
210
|
-
return this.data[index];
|
|
211
|
-
}
|
|
212
|
-
const n = this.data.length;
|
|
213
|
-
return this.data[n + index];
|
|
244
|
+
return elements[index >= 0 ? index : n + index];
|
|
214
245
|
}
|
|
215
246
|
length() {
|
|
216
247
|
return this.data.length;
|
|
@@ -254,3 +285,10 @@ Object.defineProperty(FrameArray, "APPLICATION_KEYS", {
|
|
|
254
285
|
writable: true,
|
|
255
286
|
value: ["apply_", "apply"]
|
|
256
287
|
});
|
|
288
|
+
/** The key an aggregate declares its readable text under (#398). */
|
|
289
|
+
Object.defineProperty(FrameArray, "TEXT_KEY", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
configurable: true,
|
|
292
|
+
writable: true,
|
|
293
|
+
value: "toText"
|
|
294
|
+
});
|
|
@@ -12,17 +12,18 @@ import { methodEffect } from "./effect-marker.js";
|
|
|
12
12
|
* views, and application all delegate to the target. A handle is invisible to
|
|
13
13
|
* comparison, and assignment unwraps it, so a mutation lands on the same
|
|
14
14
|
* frame it would have without the wrapper.
|
|
15
|
-
* - **
|
|
16
|
-
* read
|
|
17
|
-
*
|
|
18
|
-
* the
|
|
19
|
-
* handles without a read context retain their original target
|
|
15
|
+
* - **Target lookup.** A handle created by symbol lookup records the scope it
|
|
16
|
+
* was read in, for that read's evaluation roots only. Lookup stays live on
|
|
17
|
+
* the target and its declared parents and never falls back to that scope, so
|
|
18
|
+
* the path a value was reached by supplies no names (#400). Legacy
|
|
19
|
+
* programmatic handles without a read context retain their original target
|
|
20
|
+
* traversal.
|
|
20
21
|
*
|
|
21
22
|
* Discovering a method here yields a `BoundMethod`; the effect rules for that
|
|
22
23
|
* pairing belong to it, not to the handle.
|
|
23
24
|
*/
|
|
24
25
|
export class FrameHandle extends Frame {
|
|
25
|
-
constructor(target, mutable, copyOnWrite, readContext
|
|
26
|
+
constructor(target, mutable, copyOnWrite, readContext) {
|
|
26
27
|
super();
|
|
27
28
|
Object.defineProperty(this, "target", {
|
|
28
29
|
enumerable: true,
|
|
@@ -48,11 +49,12 @@ export class FrameHandle extends Frame {
|
|
|
48
49
|
writable: true,
|
|
49
50
|
value: readContext
|
|
50
51
|
});
|
|
51
|
-
|
|
52
|
+
/** What this handle was read from during a functional update (#401). */
|
|
53
|
+
Object.defineProperty(this, "holder", {
|
|
52
54
|
enumerable: true,
|
|
53
55
|
configurable: true,
|
|
54
56
|
writable: true,
|
|
55
|
-
value:
|
|
57
|
+
value: void 0
|
|
56
58
|
});
|
|
57
59
|
// Preserve the historical programmatic link. Contextual lookup overrides
|
|
58
60
|
// traversal below, so a shared target never needs to acquire this context.
|
|
@@ -61,6 +63,41 @@ export class FrameHandle extends Frame {
|
|
|
61
63
|
unwrap() {
|
|
62
64
|
return this.target;
|
|
63
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Records what this handle was read from, so a write through it during a
|
|
68
|
+
* functional update can copy the path down to its target.
|
|
69
|
+
*/
|
|
70
|
+
heldBy(holder) {
|
|
71
|
+
this.holder = holder;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The target a write through this handle may land on during a functional
|
|
76
|
+
* update, copied into the copy-on-write graph first (#401).
|
|
77
|
+
*
|
|
78
|
+
* A functional update copies only its receiver. When a write is about to
|
|
79
|
+
* reach a member the call has not copied yet, that member is copied now and
|
|
80
|
+
* installed in the copy that holds it, copying that holder first if it too
|
|
81
|
+
* is still shared, and this handle follows the copy. A target reached
|
|
82
|
+
* through a shared declared parent has no copied holder, so it answers
|
|
83
|
+
* nothing and the write meets `$!.copy-on-write-boundary`.
|
|
84
|
+
*/
|
|
85
|
+
copyOnWriteTarget() {
|
|
86
|
+
const graph = this.copyOnWrite;
|
|
87
|
+
if (!graph || graph.has(this.target))
|
|
88
|
+
return this.target;
|
|
89
|
+
const holder = this.holder instanceof FrameHandle
|
|
90
|
+
? this.holder.copyOnWriteTarget()
|
|
91
|
+
: this.holder;
|
|
92
|
+
if (!holder || !graph.has(holder))
|
|
93
|
+
return undefined;
|
|
94
|
+
const copy = this.target.instanceCopy();
|
|
95
|
+
if (!holder.replaceMember(this.target, copy))
|
|
96
|
+
return undefined;
|
|
97
|
+
graph.add(copy);
|
|
98
|
+
this.target = copy;
|
|
99
|
+
return copy;
|
|
100
|
+
}
|
|
64
101
|
/** A handle is transparent to equality: it compares as its target. */
|
|
65
102
|
referent() {
|
|
66
103
|
return this.target.referent();
|
|
@@ -78,25 +115,16 @@ export class FrameHandle extends Frame {
|
|
|
78
115
|
/** Retains this live reference while withholding its write capability. */
|
|
79
116
|
withoutWriteAuthority() {
|
|
80
117
|
return this.mutable
|
|
81
|
-
? new FrameHandle(this.target, false, this.copyOnWrite, this.readContext
|
|
118
|
+
? new FrameHandle(this.target, false, this.copyOnWrite, this.readContext)
|
|
82
119
|
: this;
|
|
83
120
|
}
|
|
84
|
-
/** The
|
|
121
|
+
/** The scope this read happened in, which supplies roots but never names. */
|
|
85
122
|
readContextFrame() {
|
|
86
123
|
return this.readContext;
|
|
87
124
|
}
|
|
88
125
|
evaluationRoots() {
|
|
89
126
|
return this.readContext?.evaluationRoots();
|
|
90
127
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Context to persist on a value returned through this handle.
|
|
93
|
-
*
|
|
94
|
-
* A receiver-only handle restricts one lookup operation; that restriction
|
|
95
|
-
* must not truncate the caller-specific continuation of a returned value.
|
|
96
|
-
*/
|
|
97
|
-
resultContext() {
|
|
98
|
-
return this.searchReadContext ? this : new FrameHandle(this.target, this.mutable, this.copyOnWrite, this.readContext);
|
|
99
|
-
}
|
|
100
128
|
/** Copy provenance carried across dotted aggregate traversal. */
|
|
101
129
|
copyOnWriteScope() {
|
|
102
130
|
return this.copyOnWrite;
|
|
@@ -113,15 +141,14 @@ export class FrameHandle extends Frame {
|
|
|
113
141
|
const links = [];
|
|
114
142
|
if (this.target.hasDeclaredParent())
|
|
115
143
|
links.push(this.target.parent);
|
|
116
|
-
if (this.searchReadContext && this.readContext !== this.target &&
|
|
117
|
-
!links.includes(this.readContext)) {
|
|
118
|
-
links.push(this.readContext);
|
|
119
|
-
}
|
|
120
144
|
return links;
|
|
121
145
|
}
|
|
122
146
|
lookup_result(value, key) {
|
|
123
147
|
if (value instanceof FrameLazy) {
|
|
124
|
-
|
|
148
|
+
const effect = methodEffect(key);
|
|
149
|
+
if (effect.mutating && this.mutable)
|
|
150
|
+
this.copyOnWriteTarget();
|
|
151
|
+
return new BoundMethod(value, this.target, this.mutable, effect, this.copyOnWrite, this.readContext);
|
|
125
152
|
}
|
|
126
153
|
return value;
|
|
127
154
|
}
|
|
@@ -11,15 +11,21 @@ const reducer = (current, char) => {
|
|
|
11
11
|
return result;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Joins one text value with a juxtaposed argument,
|
|
14
|
+
* Joins one text value with a juxtaposed argument, yielding a string.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* The argument contributes what its `toText` answers, which is itself unless
|
|
17
|
+
* an aggregate declared one (#398). Character content contributes its
|
|
18
|
+
* characters; anything else contributes its spelling, so `“a” #c# ` keeps the
|
|
19
|
+
* comment delimiters it was written with. A refusal from a declared `toText`
|
|
20
|
+
* stays a refusal rather than being spelled into the text.
|
|
18
21
|
*/
|
|
19
22
|
export const concatenateText = (receiver, argument) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const text = argument.referent().toText();
|
|
24
|
+
if (text !== argument.referent() && text.isFailedResult())
|
|
25
|
+
return text;
|
|
26
|
+
const value = hasCharacterContent(text)
|
|
27
|
+
? text.characterContent()
|
|
28
|
+
: text.toString();
|
|
23
29
|
return new FrameString(receiver.characterContent() + value);
|
|
24
30
|
};
|
|
25
31
|
/**
|
|
@@ -97,7 +97,9 @@ export class FrameSymbol extends FrameAtom {
|
|
|
97
97
|
(context instanceof FrameHandle && !explicitOrigin.is.missing
|
|
98
98
|
? explicitOrigin
|
|
99
99
|
: context);
|
|
100
|
-
const value =
|
|
100
|
+
const value = scope.isArgumentLayer(context)
|
|
101
|
+
? context.getOwn(this.data, origin)
|
|
102
|
+
: context.get(this.data, origin);
|
|
101
103
|
if (!value.is.missing) {
|
|
102
104
|
if (value.is.error)
|
|
103
105
|
return value;
|
|
@@ -107,7 +109,7 @@ export class FrameSymbol extends FrameAtom {
|
|
|
107
109
|
// re-parented for the benefit of one reader.
|
|
108
110
|
const isCanonicalBoolean = value === Frame.nil || value === Frame.all;
|
|
109
111
|
const continuation = context instanceof FrameHandle
|
|
110
|
-
? context
|
|
112
|
+
? context
|
|
111
113
|
: context.projectionContext();
|
|
112
114
|
const resolved = value instanceof FrameLazy
|
|
113
115
|
? value.bind(scope.captureScope())
|
|
@@ -135,9 +137,10 @@ export class FrameSymbol extends FrameAtom {
|
|
|
135
137
|
const copyOnWrite = context instanceof FrameHandle
|
|
136
138
|
? context.copyOnWriteScope() ?? receiverState?.copyOnWrite
|
|
137
139
|
: receiverState?.copyOnWrite;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
if (!(resolved instanceof FrameArray))
|
|
141
|
+
return resolved;
|
|
142
|
+
const handle = new FrameHandle(resolved, touchesIdentity(this.data), copyOnWrite, continuation);
|
|
143
|
+
return copyOnWrite ? handle.heldBy(context) : handle;
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
return FrameNote.key(first.id + "." + this.data, first);
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -210,6 +210,28 @@ export class Frame extends MetaFrame {
|
|
|
210
210
|
referent() {
|
|
211
211
|
return this;
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Get a frame by key from this frame's own properties and its declared
|
|
215
|
+
* parents only, never its lexical scope.
|
|
216
|
+
*
|
|
217
|
+
* This is how a call reads its explicit argument (spec 7, layer 2). The
|
|
218
|
+
* argument's lexical scope is wherever that value was built, which the
|
|
219
|
+
* closure did not choose, so following it would let any scope that built an
|
|
220
|
+
* argument bind the closure's names. A handle reads its target, and still
|
|
221
|
+
* binds a method it finds to that target.
|
|
222
|
+
*/
|
|
223
|
+
getOwn(key, origin = this) {
|
|
224
|
+
const seen = new Set();
|
|
225
|
+
let frame = this.referent();
|
|
226
|
+
while (frame && !seen.has(frame)) {
|
|
227
|
+
seen.add(frame);
|
|
228
|
+
const local = frame.lookup_here(key, origin);
|
|
229
|
+
if (!local.is.missing)
|
|
230
|
+
return this.lookup_result(local, key);
|
|
231
|
+
frame = frame.hasDeclaredParent() ? frame.parent : undefined;
|
|
232
|
+
}
|
|
233
|
+
return Frame.missing;
|
|
234
|
+
}
|
|
213
235
|
/** Whether a write can land on this frame, so that identity is observable. */
|
|
214
236
|
ownsIdentity() {
|
|
215
237
|
return false;
|
|
@@ -335,6 +357,16 @@ export class Frame extends MetaFrame {
|
|
|
335
357
|
applicationMethod() {
|
|
336
358
|
return undefined;
|
|
337
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* What this frame contributes when text receives it (#398).
|
|
362
|
+
*
|
|
363
|
+
* A frame contributes itself, so text takes its characters or its spelling.
|
|
364
|
+
* An aggregate may declare `toText` to answer something more readable; see
|
|
365
|
+
* `FrameArray.toText`.
|
|
366
|
+
*/
|
|
367
|
+
toText() {
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
338
370
|
/**
|
|
339
371
|
* The values this frame streams when it is iterated.
|
|
340
372
|
*
|
|
@@ -421,14 +453,26 @@ export class Frame extends MetaFrame {
|
|
|
421
453
|
* shields an immutable receiver from a mutating method. Atoms are immutable
|
|
422
454
|
* and closures are shared bodies, so for them sharing is unobservable and the
|
|
423
455
|
* default is to share. Aggregates own identity, so `FrameArray` overrides this
|
|
424
|
-
* to hand back a fresh
|
|
425
|
-
*
|
|
426
|
-
* The map memoizes aggregates already copied in this operation, so a nested
|
|
427
|
-
* aggregate reached twice stays one aggregate and a cyclic chain terminates.
|
|
456
|
+
* to hand back a fresh aggregate whose members are still shared (#401).
|
|
428
457
|
*/
|
|
429
|
-
instanceCopy(
|
|
458
|
+
instanceCopy() {
|
|
430
459
|
return this;
|
|
431
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Replaces a member that is exactly `member` with `replacement`, answering
|
|
463
|
+
* whether one was found. Copy-on-write uses it to install a copy of a member
|
|
464
|
+
* into the copy that holds it, so only declared slots are searched here.
|
|
465
|
+
*/
|
|
466
|
+
replaceMember(member, replacement) {
|
|
467
|
+
let replaced = false;
|
|
468
|
+
for (const [key, value] of this.meta_pairs()) {
|
|
469
|
+
if (value === member) {
|
|
470
|
+
this.meta[key] = replacement;
|
|
471
|
+
replaced = true;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return replaced;
|
|
475
|
+
}
|
|
432
476
|
/**
|
|
433
477
|
* Negation is decided by the symbol's name, never by how it prints.
|
|
434
478
|
*
|