parseman 0.61.4 → 0.61.5
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/dist/analysis/diagnostics.js +844 -522
- package/dist/analysis/diagnostics.js.map +3 -3
- package/dist/cli/index.js +846 -522
- package/dist/cli/index.js.map +3 -3
- package/dist/cst/capture-buffer.d.ts +3 -2
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/index.js +846 -520
- package/dist/index.js.map +3 -3
- package/dist/plugin/index.js +844 -518
- package/dist/plugin/index.js.map +3 -3
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/child-slots.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts +1 -1
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/exec.d.ts.map +1 -1
- package/dist/table/fail-clean.d.ts.map +1 -1
- package/dist/table/hold-gap.d.ts.map +1 -1
- package/dist/table/index.js +368 -42
- package/dist/table/index.js.map +3 -3
- package/dist/table/late-frame.d.ts +18 -0
- package/dist/table/late-frame.d.ts.map +1 -0
- package/dist/table/ops.d.ts +17 -0
- package/dist/table/ops.d.ts.map +1 -1
- package/dist/table/select-hot.d.ts.map +1 -1
- package/dist/table/site-labels.d.ts +5 -1
- package/dist/table/site-labels.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/cst/capture-buffer.ts +20 -11
- package/src/table/assemble.ts +124 -4
- package/src/table/child-slots.ts +9 -1
- package/src/table/emit-assembly.ts +101 -14
- package/src/table/encode.ts +69 -6
- package/src/table/exec.ts +7 -1
- package/src/table/fail-clean.ts +8 -1
- package/src/table/hold-gap.ts +5 -1
- package/src/table/late-frame.ts +54 -0
- package/src/table/ops.ts +19 -0
- package/src/table/select-hot.ts +7 -1
- package/src/table/site-labels.ts +38 -14
- package/src/version.ts +1 -1
package/src/table/encode.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
OP_LIT_TRACK, OP_RX_TRACK, OP_NODE_TRACK, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, SCOPE_INHERIT, OP_EXPECT, OP_SEQX, OP_SCAN,
|
|
19
19
|
OP_LIVE, OP_ATTEMPT, OP_LABEL,
|
|
20
20
|
OP_FIELD, OP_DISPATCH, OP_ROUTED, OP_LIT_CI, OP_LIT_CI_TRACK, OP_TOKEN, OP_WITHCTX, OP_GUARD,
|
|
21
|
-
OP_ADJ, OP_GREEDY, OP_REJECT, OP_ARMGATE, OP_RGATE, OP_COV, OP_GAPGATE, OP_RGATE2, OP_STRICT,
|
|
21
|
+
OP_ADJ, OP_GREEDY, OP_REJECT, OP_ARMGATE, OP_RGATE, OP_COV, OP_GAPGATE, OP_RGATE2, OP_STRICT, OP_CONT, OP_SEED,
|
|
22
22
|
OP_LEX_BODY, OP_LEX_PROGRAM,
|
|
23
23
|
} from './ops.ts'
|
|
24
24
|
import { adjacencyExpected } from '../combinators/adjacency.ts'
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
collectLexicalCapabilities, winnerWrapsReference,
|
|
42
42
|
} from '../compiler/token-capability.ts'
|
|
43
43
|
import { directExecutableTokenBody, type ExecutableLexNode } from '../compiler/token-alphabet.ts'
|
|
44
|
+
import { continuationGate } from './late-frame.ts'
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Can `emitConst` print this? Mirrors the guard in `emit.ts` — scalars, arrays
|
|
@@ -159,6 +160,30 @@ function isGap(p: Combinator<unknown>): boolean {
|
|
|
159
160
|
})
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Does this combinator publish exactly one node child and return that same value, on
|
|
165
|
+
* every path? Only then can a late frame (`OP_CONT`) take the corner's publication back
|
|
166
|
+
* and be the child it would have captured. A `transform` returns what its function
|
|
167
|
+
* makes of the child; a `dispatch` returns `[key, arm]` and its selector can publish too;
|
|
168
|
+
* an `expect` publishes nothing when its child fails. A `ref()` not defined yet proves nothing.
|
|
169
|
+
*/
|
|
170
|
+
function publishesOneNode(p: Combinator<unknown>, rr: RefResolver | undefined, seen = new Set<Combinator<unknown>>()): boolean {
|
|
171
|
+
if (seen.has(p)) return true
|
|
172
|
+
seen.add(p)
|
|
173
|
+
const d = p._def
|
|
174
|
+
switch (d.tag) {
|
|
175
|
+
case 'node': return true
|
|
176
|
+
case 'lazy': {
|
|
177
|
+
let target = winnerForRef(p, rr)
|
|
178
|
+
if (target === undefined) { try { target = d.thunk() } catch { return false } }
|
|
179
|
+
return publishesOneNode(target, rr, seen)
|
|
180
|
+
}
|
|
181
|
+
case 'choice': return d.parsers.every(a => publishesOneNode(a, rr, seen))
|
|
182
|
+
case 'grammar': case 'withCtx': case 'label': return publishesOneNode(d.parser, rr, seen)
|
|
183
|
+
default: return false
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
162
187
|
class Encoder {
|
|
163
188
|
code: number[] = []
|
|
164
189
|
k: unknown[] = []
|
|
@@ -1859,7 +1884,8 @@ class Encoder {
|
|
|
1859
1884
|
// without, on match and on failure.
|
|
1860
1885
|
// An AUTHORING error, not a table gap — raise what the other two engines do.
|
|
1861
1886
|
if (d.type === undefined) missingInferredType()
|
|
1862
|
-
const
|
|
1887
|
+
const late = this.opensLate(d)
|
|
1888
|
+
const child = late ? this.lateBody(d.parser._def as Extract<ParserDef, { tag: 'sequence' }>) : this.node(d.parser).ip
|
|
1863
1889
|
// Capture flags, resolved HERE from the reducer's declared arity using the
|
|
1864
1890
|
// same analysis codegen runs (`src/compiler/build-arity.ts`). `hostMode:
|
|
1865
1891
|
// 'cst'` forces them on, exactly as the emitted `cstOut` path does. The
|
|
@@ -1928,7 +1954,15 @@ class Encoder {
|
|
|
1928
1954
|
// `deriveExpected(body)`, which for a body with nullable leading terms
|
|
1929
1955
|
// names tokens the run would have skipped — `['"@"', '"(", '"x"']` where
|
|
1930
1956
|
// running the body reports `['"x"']` alone.
|
|
1931
|
-
|
|
1957
|
+
// `child` is `SEQ 2 seed tail …`, and `seed` is `SEED corner`. A tail with no first
|
|
1958
|
+
// test has nothing to decide on: the node runs as written, over its corner.
|
|
1959
|
+
let run = body
|
|
1960
|
+
if (late) {
|
|
1961
|
+
const corner = this.code[this.code[child + 2]! + 1]!
|
|
1962
|
+
if (continuationGate(this.code, this.code[child + 3]!) === undefined) this.code[child + 2] = corner
|
|
1963
|
+
else run = this.emit(OP_CONT, corner, body, this.code[child + 3]!)
|
|
1964
|
+
}
|
|
1965
|
+
if (matchesEmpty(d.parser, new Set(), this.refResolver())) return run
|
|
1932
1966
|
// A node whose BODY is a bare cross-rule ref (`node('X', g.Y, …)`) caches its
|
|
1933
1967
|
// first set from the ref's base binding. Under a compose OVERRIDE the winner
|
|
1934
1968
|
// for `Y` may be WIDER, so the cached set gates out input the merged rule
|
|
@@ -1940,11 +1974,11 @@ class Encoder {
|
|
|
1940
1974
|
// that set match what entering the body reports (a `keywords()` term, a
|
|
1941
1975
|
// list's item set, an optional lead are only known by running it).
|
|
1942
1976
|
const fs = this.gateFirstSet(d.parser, d.guarded === true, false)
|
|
1943
|
-
if (fs.kind === 'any') return
|
|
1977
|
+
if (fs.kind === 'any') return run
|
|
1944
1978
|
const cls = this.charClass(fs)
|
|
1945
|
-
if (cls < 0) return
|
|
1979
|
+
if (cls < 0) return run
|
|
1946
1980
|
const e = deriveExpected(d.parser)
|
|
1947
|
-
return this.emit(OP_GATE, cls,
|
|
1981
|
+
return this.emit(OP_GATE, cls, run, this.expected(e.length > 0 ? e : [d.parser._tag]))
|
|
1948
1982
|
}
|
|
1949
1983
|
case 'token': {
|
|
1950
1984
|
// A token runs its body with trivia cleared (`token.ts`), so its body is
|
|
@@ -2271,6 +2305,33 @@ class Encoder {
|
|
|
2271
2305
|
}
|
|
2272
2306
|
}
|
|
2273
2307
|
|
|
2308
|
+
/**
|
|
2309
|
+
* `node(sequence(corner, tail), build, { collapse: true })` with a tail that can take
|
|
2310
|
+
* nothing and a corner that is one node: the frame can open after the corner, only if
|
|
2311
|
+
* the tail can start. Any other node keeps its frame from the start, and so does one
|
|
2312
|
+
* with no reducer, whose host can scope the corner's trivia to its type.
|
|
2313
|
+
*/
|
|
2314
|
+
private opensLate(d: Extract<ParserDef, { tag: 'node' }>): boolean {
|
|
2315
|
+
if (this.plan !== undefined || d.collapse !== true || d.build === undefined || d.trailingTrivia === true) return false
|
|
2316
|
+
const seq = d.parser._def
|
|
2317
|
+
return seq.tag === 'sequence' && seq.parsers.length === 2
|
|
2318
|
+
&& matchesEmpty(seq.parsers[1]!, new Set(), this.refResolver())
|
|
2319
|
+
&& publishesOneNode(seq.parsers[0]!, this.refResolver())
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
/** The body of a late frame: the sequence as written, its corner behind `OP_SEED`. */
|
|
2323
|
+
private lateBody(seq: Extract<ParserDef, { tag: 'sequence' }>): number {
|
|
2324
|
+
const seed = this.emit(OP_SEED, this.node(seq.parsers[0]!).ip)
|
|
2325
|
+
const tailIp = this.node(seq.parsers[1]!).ip
|
|
2326
|
+
const head = this.emitHead(seq.valueUnused ? OP_SEQV : OP_SEQ, 5)
|
|
2327
|
+
this.code[head + 1] = 2
|
|
2328
|
+
this.code[head + 2] = seed
|
|
2329
|
+
this.code[head + 3] = tailIp
|
|
2330
|
+
this.code[head + 4] = this.followClass(seq.parsers, 0)
|
|
2331
|
+
this.code[head + 5] = this.followClass(seq.parsers, 1)
|
|
2332
|
+
return head
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2274
2335
|
/**
|
|
2275
2336
|
* Peephole: an `OP_RULE` row is pure indirection — a switch dispatch and a
|
|
2276
2337
|
* call frame to do nothing but jump. Rewrite every child slot that points at
|
|
@@ -2306,6 +2367,8 @@ class Encoder {
|
|
|
2306
2367
|
case OP_REJECT: return [ip + 1]
|
|
2307
2368
|
case OP_REP: case OP_REPV: return this.code[ip + 4]! >= 0 ? [ip + 1, ip + 4] : [ip + 1]
|
|
2308
2369
|
case OP_STRICT: return [ip + 1, ip + 2]
|
|
2370
|
+
case OP_CONT: return [ip + 1, ip + 2, ip + 3]
|
|
2371
|
+
case OP_SEED: return [ip + 1]
|
|
2309
2372
|
default: return []
|
|
2310
2373
|
}
|
|
2311
2374
|
}
|
package/src/table/exec.ts
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
OP_LIT_TRACK, OP_RX_TRACK, OP_NODE_TRACK, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, SCOPE_INHERIT, OP_EXPECT, OP_SEQX, OP_SCAN,
|
|
22
22
|
OP_LIVE,
|
|
23
23
|
OP_FIELD, OP_DISPATCH, OP_ROUTED, OP_LIT_CI, OP_LIT_CI_TRACK, OP_TOKEN, OP_WITHCTX, OP_GUARD, OP_ATTEMPT, OP_LABEL,
|
|
24
|
-
OP_COV, OP_GAPGATE, OP_STRICT,
|
|
24
|
+
OP_COV, OP_GAPGATE, OP_STRICT, OP_CONT, OP_SEED,
|
|
25
25
|
OP_ADJ, OP_GREEDY, OP_REJECT, OP_ARMGATE, OP_RGATE, OP_RGATE2,
|
|
26
26
|
OP_LEX_BODY, OP_LEX_PROGRAM,
|
|
27
27
|
} from './ops.ts'
|
|
@@ -477,6 +477,12 @@ function makeDriver(
|
|
|
477
477
|
case OP_STRICT:
|
|
478
478
|
ip = code[ctx._tolerant || ctx._probe !== undefined ? ip + 2 : ip + 1]!; continue rows
|
|
479
479
|
|
|
480
|
+
// The reference runs a late frame's node as written, and is the leg it is compared with.
|
|
481
|
+
case OP_CONT:
|
|
482
|
+
ip = code[ip + 2]!; continue rows
|
|
483
|
+
case OP_SEED:
|
|
484
|
+
ip = code[ip + 1]!; continue rows
|
|
485
|
+
|
|
480
486
|
case OP_LIVE: {
|
|
481
487
|
// A HAND-WRITTEN COMBINATOR, run through its own `.parse` — mirrors
|
|
482
488
|
// codegen's `emitRuntimeFallback`. Its result IS the interpreter's, so
|
package/src/table/fail-clean.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
OP_ATTEMPT, OP_CHOICE, OP_COV, OP_DISPATCH, OP_EMPTY, OP_EXPECT, OP_FIELD, OP_GATE, OP_GUARD, OP_LABEL,
|
|
25
25
|
OP_LEAF, OP_LIT, OP_LIT_CI, OP_LIT_CI_TRACK, OP_LIT_TRACK, OP_NODE, OP_NODE_TRACK, OP_NOT, OP_OPT, OP_PEEK,
|
|
26
26
|
OP_REP, OP_REPV, OP_ROUTED, OP_RULE, OP_RX, OP_RX_TRACK, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, OP_SEQ,
|
|
27
|
-
OP_SEQV, OP_SEQX, OP_SOURCE_LEAF, OP_TOKEN, OP_WITHCTX, OP_XFORM, OP_GAPGATE,
|
|
27
|
+
OP_SEQV, OP_SEQX, OP_SOURCE_LEAF, OP_TOKEN, OP_WITHCTX, OP_XFORM, OP_GAPGATE, OP_CONT, OP_SEED,
|
|
28
28
|
} from './ops.ts'
|
|
29
29
|
|
|
30
30
|
export type FailClean = (ip: number) => boolean
|
|
@@ -113,6 +113,13 @@ export function failCleanAnalysis(code: ArrayLike<number>): FailClean {
|
|
|
113
113
|
case OP_ROUTED:
|
|
114
114
|
out = code[ip + 1]! < 0 || clean(code[ip + 1]!)
|
|
115
115
|
break
|
|
116
|
+
case OP_SEED:
|
|
117
|
+
out = clean(code[ip + 1]!)
|
|
118
|
+
break
|
|
119
|
+
// The corner may fail; the wrapper fails only through a tail that can.
|
|
120
|
+
case OP_CONT:
|
|
121
|
+
out = clean(code[ip + 1]!) && neverFails(code[ip + 3]!)
|
|
122
|
+
break
|
|
116
123
|
// An arm's failure and the fallback's are committed; only the selector's is
|
|
117
124
|
// not, and without a fallback an unknown key fails after the selector wrote.
|
|
118
125
|
case OP_DISPATCH:
|
package/src/table/hold-gap.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import {
|
|
18
18
|
OP_ADJ, OP_ATTEMPT, OP_CHOICE, OP_COV, OP_EXPECT, OP_FIELD, OP_GATE, OP_LABEL, OP_LEAF, OP_LIT, OP_LIT_CI,
|
|
19
19
|
OP_NODE, OP_NOT, OP_PEEK, OP_REP, OP_REPV, OP_RULE, OP_RX, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, OP_SEQ,
|
|
20
|
-
OP_SEQV, OP_SEQX, OP_SOURCE_LEAF, OP_TOKEN, OP_WITHCTX, OP_XFORM, OP_GAPGATE,
|
|
20
|
+
OP_SEQV, OP_SEQX, OP_SOURCE_LEAF, OP_TOKEN, OP_WITHCTX, OP_XFORM, OP_GAPGATE, OP_CONT, OP_SEED,
|
|
21
21
|
} from './ops.ts'
|
|
22
22
|
import { childSlots } from './child-slots.ts'
|
|
23
23
|
import { leadingTriviaFieldAt } from './field-spec.ts'
|
|
@@ -48,6 +48,10 @@ export function rowNullable(code: ArrayLike<number>, k: readonly unknown[], ip:
|
|
|
48
48
|
out = kids.length === 0 || kids.some(c => rowNullable(code, k, c, memo))
|
|
49
49
|
} else if (op === OP_REP || op === OP_REPV) {
|
|
50
50
|
out = code[ip + 2] === 0 || rowNullable(code, k, code[ip + 1]!, memo)
|
|
51
|
+
} else if (op === OP_SEED) {
|
|
52
|
+
out = rowNullable(code, k, code[ip + 1]!, memo)
|
|
53
|
+
} else if (op === OP_CONT) {
|
|
54
|
+
out = rowNullable(code, k, code[ip + 1]!, memo) && rowNullable(code, k, code[ip + 3]!, memo)
|
|
51
55
|
} else if (WRAPPERS.has(op)) {
|
|
52
56
|
if (childSlots(code, ip, kids) && kids.length === 1) out = rowNullable(code, k, kids[0]!, memo)
|
|
53
57
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHAT THE TAIL OF A LATE FRAME CAN START WITH, read off the row that runs it.
|
|
3
|
+
*
|
|
4
|
+
* `OP_CONT` asks, after the corner, whether the tail could do anything at the next
|
|
5
|
+
* token. The answer is the repeat's or the optional's own first test (`OP_REP` ip+7
|
|
6
|
+
* and its `OP_GAPGATE`, an `OP_OPT` over `OP_GATE`), so it holds exactly where the row
|
|
7
|
+
* would have ended without entering its item. Any other tail has no answer, and with
|
|
8
|
+
* no answer the frame always opens: that site runs as written.
|
|
9
|
+
*/
|
|
10
|
+
import { OP_GAPGATE, OP_GATE, OP_OPT, OP_REP, OP_REPV, OP_RULE, OP_WITHCTX } from './ops.ts'
|
|
11
|
+
import { TRI_NONE } from './site-labels.ts'
|
|
12
|
+
|
|
13
|
+
export type ContinuationGate = {
|
|
14
|
+
/** Class of the first character, past any trivia. */
|
|
15
|
+
readonly cls: number
|
|
16
|
+
/** The regex row of a leading gap, or −1. */
|
|
17
|
+
readonly gapRow: number
|
|
18
|
+
/** Class of the character after the gap. */
|
|
19
|
+
readonly follow: number
|
|
20
|
+
/** Class of an arm that opens without the gap, or −1. */
|
|
21
|
+
readonly other: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function continuationGate(code: ArrayLike<number>, ip: number): ContinuationGate | undefined {
|
|
25
|
+
let at = ip
|
|
26
|
+
for (let n = 0; n < 8; n++) {
|
|
27
|
+
const op = code[at]
|
|
28
|
+
if (op === OP_RULE) at = code[at + 1]!
|
|
29
|
+
else if (op === OP_WITHCTX) at = code[at + 2]!
|
|
30
|
+
else break
|
|
31
|
+
}
|
|
32
|
+
const op = code[at]
|
|
33
|
+
if (op === OP_OPT) {
|
|
34
|
+
const c = code[at + 1]!
|
|
35
|
+
return code[c] === OP_GATE ? { cls: code[c + 1]!, gapRow: -1, follow: -1, other: -1 } : undefined
|
|
36
|
+
}
|
|
37
|
+
if (op !== OP_REP && op !== OP_REPV) return undefined
|
|
38
|
+
// A separated list keeps ip+7 for its recovery sentinel; a mandatory item reports.
|
|
39
|
+
if (code[at + 2] !== 0 || code[at + 4]! >= 0 || code[at + 7]! < 0) return undefined
|
|
40
|
+
const item = code[at + 1]!
|
|
41
|
+
return code[item] === OP_GAPGATE
|
|
42
|
+
? { cls: code[at + 7]!, gapRow: code[item + 2]!, follow: code[item + 3]!, other: code[item + 4]! }
|
|
43
|
+
: { cls: code[at + 7]!, gapRow: -1, follow: -1, other: -1 }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Can this assembly decide at this `OP_CONT`? It needs the tail's test, and the
|
|
48
|
+
* trivia the label names: a scope it cannot name, or one with no scanner, would cost a
|
|
49
|
+
* hit more calls than the frame it saves on a miss.
|
|
50
|
+
*/
|
|
51
|
+
export function canDecide(code: ArrayLike<number>, ip: number, tri: number, triviaScan: readonly unknown[]): boolean {
|
|
52
|
+
if (tri !== TRI_NONE && (tri < 0 || triviaScan[tri] == null)) return false
|
|
53
|
+
return continuationGate(code, code[ip + 3]!) !== undefined
|
|
54
|
+
}
|
package/src/table/ops.ts
CHANGED
|
@@ -509,6 +509,23 @@ export const OP_RGATE2 = 47
|
|
|
509
509
|
* assembly resolves it to one child; it has no body of its own.
|
|
510
510
|
*/
|
|
511
511
|
export const OP_STRICT = 48
|
|
512
|
+
/**
|
|
513
|
+
* `CONT corner wrapper tail` — a `collapse` node that is `sequence(corner, tail)`, with
|
|
514
|
+
* a tail that can take nothing and a corner that is one node. A strict assembly runs
|
|
515
|
+
* `corner` in the PARENT's collector and looks at the next token. Where `tail` cannot
|
|
516
|
+
* start there, the corner is the result: no frame, no children, no builder. Where it
|
|
517
|
+
* can, the corner's publication is taken back and `wrapper`'s frame opens around it and
|
|
518
|
+
* `tail`, in this one function. `tail` is read for the decision (`late-frame.ts`). Where
|
|
519
|
+
* no decision can be made, and under recovery, a probe or the reference driver, this
|
|
520
|
+
* is `wrapper`, the node as written.
|
|
521
|
+
*/
|
|
522
|
+
export const OP_CONT = 49
|
|
523
|
+
/**
|
|
524
|
+
* `SEED corner` — marks the first term of `wrapper`'s body. Run, it is `corner`. It
|
|
525
|
+
* exists so the labels can leave out the edge from a late frame to its corner, which
|
|
526
|
+
* never runs there.
|
|
527
|
+
*/
|
|
528
|
+
export const OP_SEED = 50
|
|
512
529
|
/**
|
|
513
530
|
* `DISPATCH sel d other otherRouted n a1 … an` — `dispatch()`.
|
|
514
531
|
*
|
|
@@ -548,4 +565,6 @@ export const OP_NAMES: Record<number, string> = {
|
|
|
548
565
|
[OP_GAPGATE]: 'GAPGATE',
|
|
549
566
|
[OP_RGATE2]: 'RGATE2',
|
|
550
567
|
[OP_STRICT]: 'STRICT',
|
|
568
|
+
[OP_CONT]: 'CONT',
|
|
569
|
+
[OP_SEED]: 'SEED',
|
|
551
570
|
}
|
package/src/table/select-hot.ts
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* A build given a corpus (`assemblyProfile`) ranks by measured calls instead.
|
|
16
16
|
*/
|
|
17
17
|
import { childSlots } from './child-slots.ts'
|
|
18
|
-
import {
|
|
18
|
+
import { continuationGate } from './late-frame.ts'
|
|
19
|
+
import { OP_CHOICE, OP_CONT, OP_DISPATCH, OP_GAPGATE, OP_REP, OP_REPV } from './ops.ts'
|
|
19
20
|
|
|
20
21
|
const LOOP = 8
|
|
21
22
|
const ROUNDS = 60
|
|
@@ -90,6 +91,11 @@ function staticWeights(code: readonly number[], entries: readonly number[]): Map
|
|
|
90
91
|
kids.length = 0
|
|
91
92
|
childSlots(code, ip, kids)
|
|
92
93
|
const op = code[ip]
|
|
94
|
+
// A late frame is lowered with its wrapper in one function, calling these two.
|
|
95
|
+
if (op === OP_CONT && continuationGate(code, code[ip + 3]!) !== undefined) {
|
|
96
|
+
kids.length = 0
|
|
97
|
+
kids.push(code[ip + 1]!, code[ip + 3]!)
|
|
98
|
+
}
|
|
93
99
|
const scale = op === OP_REP || op === OP_REPV ? LOOP
|
|
94
100
|
: op === OP_CHOICE || op === OP_DISPATCH ? 1 / Math.max(1, kids.length)
|
|
95
101
|
: 1
|
package/src/table/site-labels.ts
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
* label licenses at a leaf is dropping the TEST — never the capture.
|
|
61
61
|
*/
|
|
62
62
|
import {
|
|
63
|
-
OP_ATTEMPT, OP_CHOICE, OP_DISPATCH, OP_EXPECT, OP_FIELD, OP_GATE, OP_LABEL, OP_LEAF, OP_LIT, OP_SOURCE_LEAF,
|
|
63
|
+
OP_CONT, OP_SEED, OP_ATTEMPT, OP_CHOICE, OP_DISPATCH, OP_EXPECT, OP_FIELD, OP_GATE, OP_LABEL, OP_LEAF, OP_LIT, OP_SOURCE_LEAF,
|
|
64
64
|
OP_NODE, OP_NODE_TRACK, OP_NOT, OP_OPT, OP_PEEK, OP_REP, OP_REPV, OP_ROUTED, OP_RULE,
|
|
65
65
|
OP_SCAN, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, SCOPE_INHERIT, OP_SEQ, OP_SEQV, OP_SEQX, OP_TOKEN, OP_XFORM,
|
|
66
66
|
} from './ops.ts'
|
|
@@ -161,7 +161,7 @@ export function passCollapse(code: Int32Array, ip: number, hostCst: boolean): bo
|
|
|
161
161
|
else if (op === OP_RULE) at = code[at + 1]!
|
|
162
162
|
else break
|
|
163
163
|
}
|
|
164
|
-
return code[at] === OP_NODE
|
|
164
|
+
return code[at] === OP_NODE || code[at] === OP_CONT
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
@@ -266,7 +266,11 @@ function transfer(code: Int32Array, ip: number, at: SiteLabel, hostCst: boolean)
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
/** A site's label, or `TOP` for anything the walk did not reach. */
|
|
269
|
-
export type SiteLabels = {
|
|
269
|
+
export type SiteLabels = {
|
|
270
|
+
at: (ip: number) => SiteLabel
|
|
271
|
+
/** The `OP_CONT` sites whose corner runs in the parent's collector in every engine. */
|
|
272
|
+
late: ReadonlySet<number>
|
|
273
|
+
}
|
|
270
274
|
|
|
271
275
|
/**
|
|
272
276
|
* Compute a label for every site reachable from `roots`.
|
|
@@ -284,10 +288,11 @@ export function computeSiteLabels(
|
|
|
284
288
|
code: Int32Array,
|
|
285
289
|
roots: Iterable<number>,
|
|
286
290
|
hostCst: boolean,
|
|
291
|
+
/** Does this assembly run this `OP_CONT` late, in EVERY engine it holds? Absent: none. */
|
|
292
|
+
late?: (ip: number, tri: number) => boolean,
|
|
287
293
|
): SiteLabels {
|
|
288
294
|
const labels = new Map<number, SiteLabel>()
|
|
289
295
|
const work: number[] = []
|
|
290
|
-
|
|
291
296
|
const push = (ip: number, l: SiteLabel): void => {
|
|
292
297
|
const cur = labels.get(ip)
|
|
293
298
|
if (cur === undefined) {
|
|
@@ -300,19 +305,38 @@ export function computeSiteLabels(
|
|
|
300
305
|
labels.set(ip, next)
|
|
301
306
|
work.push(ip)
|
|
302
307
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
// A corner a late frame never runs takes no label from that frame. So every frame is
|
|
309
|
+
// late until a site proves undecidable, when its seed's edge joins the same fixpoint: a
|
|
310
|
+
// frame does not change the trivia in force, so no other site's answer moves.
|
|
311
|
+
const opened = new Set<number>()
|
|
306
312
|
const kids: number[] = []
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
+
const lateIps = new Set<number>()
|
|
314
|
+
for (const r of roots) push(r, TOP)
|
|
315
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
316
|
+
while (work.length > 0) {
|
|
317
|
+
const ip = work.pop()!
|
|
318
|
+
const down = transfer(code, ip, labels.get(ip)!, hostCst)
|
|
319
|
+
kids.length = 0
|
|
320
|
+
if (late === undefined || code[ip] !== OP_SEED || opened.has(ip)) childSlots(code, ip, kids)
|
|
321
|
+
for (const c of kids) push(c, down)
|
|
322
|
+
}
|
|
323
|
+
if (late === undefined || pass === 1) break
|
|
324
|
+
for (const [ip, l] of [...labels]) {
|
|
325
|
+
if (code[ip] !== OP_CONT) continue
|
|
326
|
+
if (late(ip, l.tri)) lateIps.add(ip)
|
|
327
|
+
else {
|
|
328
|
+
const seed = seedOf(code, ip)
|
|
329
|
+
opened.add(seed)
|
|
330
|
+
work.push(seed)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
313
333
|
}
|
|
334
|
+
return { at: (ip: number): SiteLabel => labels.get(ip) ?? TOP, late: lateIps }
|
|
335
|
+
}
|
|
314
336
|
|
|
315
|
-
|
|
337
|
+
/** `CONT corner wrapper tail`, `NODE … body`, `SEQ n seed tail`. */
|
|
338
|
+
function seedOf(code: ArrayLike<number>, cont: number): number {
|
|
339
|
+
return code[code[code[cont + 2]! + 2]! + 2]!
|
|
316
340
|
}
|
|
317
341
|
|
|
318
342
|
/**
|
package/src/version.ts
CHANGED