@sccharts-lab/engine 0.0.0-stage → 0.1.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/LICENSE +277 -0
- package/README.md +125 -2
- package/dist/codegen/expr.d.ts +36 -0
- package/dist/codegen/expr.js +252 -0
- package/dist/codegen/expr.js.map +1 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.js +238 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/layout.d.ts +57 -0
- package/dist/codegen/layout.js +306 -0
- package/dist/codegen/layout.js.map +1 -0
- package/dist/codegen/logic.d.ts +31 -0
- package/dist/codegen/logic.js +258 -0
- package/dist/codegen/logic.js.map +1 -0
- package/dist/codegen/methods.d.ts +17 -0
- package/dist/codegen/methods.js +242 -0
- package/dist/codegen/methods.js.map +1 -0
- package/dist/codegen/reset.d.ts +6 -0
- package/dist/codegen/reset.js +110 -0
- package/dist/codegen/reset.js.map +1 -0
- package/dist/codegen/types.d.ts +81 -0
- package/dist/codegen/types.js +3 -0
- package/dist/codegen/types.js.map +1 -0
- package/dist/format.d.ts +136 -0
- package/dist/format.js +872 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +507 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/parser/ids.d.ts +4 -0
- package/dist/parser/ids.js +172 -0
- package/dist/parser/ids.js.map +1 -0
- package/dist/parser/imports.d.ts +2 -0
- package/dist/parser/imports.js +28 -0
- package/dist/parser/imports.js.map +1 -0
- package/dist/parser/interface.d.ts +10 -0
- package/dist/parser/interface.js +93 -0
- package/dist/parser/interface.js.map +1 -0
- package/dist/parser/kielerWording.d.ts +2 -0
- package/dist/parser/kielerWording.js +196 -0
- package/dist/parser/kielerWording.js.map +1 -0
- package/dist/parser/lexer.d.ts +25 -0
- package/dist/parser/lexer.js +334 -0
- package/dist/parser/lexer.js.map +1 -0
- package/dist/parser/parser.d.ts +29 -0
- package/dist/parser/parser.js +3249 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/resolve.d.ts +46 -0
- package/dist/parser/resolve.js +919 -0
- package/dist/parser/resolve.js.map +1 -0
- package/dist/parser/source.d.ts +15 -0
- package/dist/parser/source.js +42 -0
- package/dist/parser/source.js.map +1 -0
- package/dist/parser/validate.d.ts +5 -0
- package/dist/parser/validate.js +1430 -0
- package/dist/parser/validate.js.map +1 -0
- package/dist/sim/abortRegions.d.ts +9 -0
- package/dist/sim/abortRegions.js +192 -0
- package/dist/sim/abortRegions.js.map +1 -0
- package/dist/sim/analysis.d.ts +113 -0
- package/dist/sim/analysis.js +1104 -0
- package/dist/sim/analysis.js.map +1 -0
- package/dist/sim/codegen.d.ts +30 -0
- package/dist/sim/codegen.js +730 -0
- package/dist/sim/codegen.js.map +1 -0
- package/dist/sim/compile.d.ts +43 -0
- package/dist/sim/compile.js +1062 -0
- package/dist/sim/compile.js.map +1 -0
- package/dist/sim/deps.d.ts +73 -0
- package/dist/sim/deps.js +481 -0
- package/dist/sim/deps.js.map +1 -0
- package/dist/sim/describe.d.ts +22 -0
- package/dist/sim/describe.js +272 -0
- package/dist/sim/describe.js.map +1 -0
- package/dist/sim/describePreemption.d.ts +22 -0
- package/dist/sim/describePreemption.js +90 -0
- package/dist/sim/describePreemption.js.map +1 -0
- package/dist/sim/describeStructure.d.ts +75 -0
- package/dist/sim/describeStructure.js +293 -0
- package/dist/sim/describeStructure.js.map +1 -0
- package/dist/sim/eval.d.ts +99 -0
- package/dist/sim/eval.js +644 -0
- package/dist/sim/eval.js.map +1 -0
- package/dist/sim/exec.d.ts +212 -0
- package/dist/sim/exec.js +874 -0
- package/dist/sim/exec.js.map +1 -0
- package/dist/sim/fold.d.ts +2 -0
- package/dist/sim/fold.js +40 -0
- package/dist/sim/fold.js.map +1 -0
- package/dist/sim/goblock.d.ts +16 -0
- package/dist/sim/goblock.js +171 -0
- package/dist/sim/goblock.js.map +1 -0
- package/dist/sim/guardIndices.d.ts +13 -0
- package/dist/sim/guardIndices.js +137 -0
- package/dist/sim/guardIndices.js.map +1 -0
- package/dist/sim/index.d.ts +43 -0
- package/dist/sim/index.js +138 -0
- package/dist/sim/index.js.map +1 -0
- package/dist/sim/lower.d.ts +33 -0
- package/dist/sim/lower.js +716 -0
- package/dist/sim/lower.js.map +1 -0
- package/dist/sim/memory.d.ts +47 -0
- package/dist/sim/memory.js +328 -0
- package/dist/sim/memory.js.map +1 -0
- package/dist/sim/model.d.ts +487 -0
- package/dist/sim/model.js +772 -0
- package/dist/sim/model.js.map +1 -0
- package/dist/sim/passes/abort.d.ts +2 -0
- package/dist/sim/passes/abort.js +269 -0
- package/dist/sim/passes/abort.js.map +1 -0
- package/dist/sim/passes/abortRegion.d.ts +10 -0
- package/dist/sim/passes/abortRegion.js +62 -0
- package/dist/sim/passes/abortRegion.js.map +1 -0
- package/dist/sim/passes/arrayAssignment.d.ts +2 -0
- package/dist/sim/passes/arrayAssignment.js +147 -0
- package/dist/sim/passes/arrayAssignment.js.map +1 -0
- package/dist/sim/passes/codeEffects.d.ts +2 -0
- package/dist/sim/passes/codeEffects.js +14 -0
- package/dist/sim/passes/codeEffects.js.map +1 -0
- package/dist/sim/passes/complexFinalState.d.ts +4 -0
- package/dist/sim/passes/complexFinalState.js +77 -0
- package/dist/sim/passes/complexFinalState.js.map +1 -0
- package/dist/sim/passes/connector.d.ts +2 -0
- package/dist/sim/passes/connector.js +18 -0
- package/dist/sim/passes/connector.js.map +1 -0
- package/dist/sim/passes/contained.d.ts +37 -0
- package/dist/sim/passes/contained.js +198 -0
- package/dist/sim/passes/contained.js.map +1 -0
- package/dist/sim/passes/context.d.ts +39 -0
- package/dist/sim/passes/context.js +3 -0
- package/dist/sim/passes/context.js.map +1 -0
- package/dist/sim/passes/countDelay.d.ts +2 -0
- package/dist/sim/passes/countDelay.js +51 -0
- package/dist/sim/passes/countDelay.js.map +1 -0
- package/dist/sim/passes/dataflow.d.ts +11 -0
- package/dist/sim/passes/dataflow.js +319 -0
- package/dist/sim/passes/dataflow.js.map +1 -0
- package/dist/sim/passes/deferred.d.ts +2 -0
- package/dist/sim/passes/deferred.js +345 -0
- package/dist/sim/passes/deferred.js.map +1 -0
- package/dist/sim/passes/detect.d.ts +10 -0
- package/dist/sim/passes/detect.js +33 -0
- package/dist/sim/passes/detect.js.map +1 -0
- package/dist/sim/passes/during.d.ts +2 -0
- package/dist/sim/passes/during.js +67 -0
- package/dist/sim/passes/during.js.map +1 -0
- package/dist/sim/passes/entry.d.ts +5 -0
- package/dist/sim/passes/entry.js +93 -0
- package/dist/sim/passes/entry.js.map +1 -0
- package/dist/sim/passes/enum.d.ts +2 -0
- package/dist/sim/passes/enum.js +22 -0
- package/dist/sim/passes/enum.js.map +1 -0
- package/dist/sim/passes/exit.d.ts +4 -0
- package/dist/sim/passes/exit.js +120 -0
- package/dist/sim/passes/exit.js.map +1 -0
- package/dist/sim/passes/finalRegion.d.ts +2 -0
- package/dist/sim/passes/finalRegion.js +21 -0
- package/dist/sim/passes/finalRegion.js.map +1 -0
- package/dist/sim/passes/followedBy.d.ts +2 -0
- package/dist/sim/passes/followedBy.js +78 -0
- package/dist/sim/passes/followedBy.js.map +1 -0
- package/dist/sim/passes/forRegion.d.ts +9 -0
- package/dist/sim/passes/forRegion.js +230 -0
- package/dist/sim/passes/forRegion.js.map +1 -0
- package/dist/sim/passes/history.d.ts +12 -0
- package/dist/sim/passes/history.js +115 -0
- package/dist/sim/passes/history.js.map +1 -0
- package/dist/sim/passes/hostCode.d.ts +2 -0
- package/dist/sim/passes/hostCode.js +152 -0
- package/dist/sim/passes/hostCode.js.map +1 -0
- package/dist/sim/passes/index.d.ts +4 -0
- package/dist/sim/passes/index.js +84 -0
- package/dist/sim/passes/index.js.map +1 -0
- package/dist/sim/passes/inheritance.d.ts +8 -0
- package/dist/sim/passes/inheritance.js +233 -0
- package/dist/sim/passes/inheritance.js.map +1 -0
- package/dist/sim/passes/initOperator.d.ts +2 -0
- package/dist/sim/passes/initOperator.js +68 -0
- package/dist/sim/passes/initOperator.js.map +1 -0
- package/dist/sim/passes/initialization.d.ts +2 -0
- package/dist/sim/passes/initialization.js +69 -0
- package/dist/sim/passes/initialization.js.map +1 -0
- package/dist/sim/passes/ode.d.ts +2 -0
- package/dist/sim/passes/ode.js +14 -0
- package/dist/sim/passes/ode.js.map +1 -0
- package/dist/sim/passes/period.d.ts +2 -0
- package/dist/sim/passes/period.js +106 -0
- package/dist/sim/passes/period.js.map +1 -0
- package/dist/sim/passes/prTransitions.d.ts +2 -0
- package/dist/sim/passes/prTransitions.js +12 -0
- package/dist/sim/passes/prTransitions.js.map +1 -0
- package/dist/sim/passes/pre.d.ts +4 -0
- package/dist/sim/passes/pre.js +326 -0
- package/dist/sim/passes/pre.js.map +1 -0
- package/dist/sim/passes/quirks.d.ts +2 -0
- package/dist/sim/passes/quirks.js +169 -0
- package/dist/sim/passes/quirks.js.map +1 -0
- package/dist/sim/passes/reference.d.ts +60 -0
- package/dist/sim/passes/reference.js +386 -0
- package/dist/sim/passes/reference.js.map +1 -0
- package/dist/sim/passes/regionActions.d.ts +2 -0
- package/dist/sim/passes/regionActions.js +56 -0
- package/dist/sim/passes/regionActions.js.map +1 -0
- package/dist/sim/passes/sequentialFollowedBy.d.ts +2 -0
- package/dist/sim/passes/sequentialFollowedBy.js +72 -0
- package/dist/sim/passes/sequentialFollowedBy.js.map +1 -0
- package/dist/sim/passes/signal.d.ts +2 -0
- package/dist/sim/passes/signal.js +230 -0
- package/dist/sim/passes/signal.js.map +1 -0
- package/dist/sim/passes/static.d.ts +5 -0
- package/dist/sim/passes/static.js +67 -0
- package/dist/sim/passes/static.js.map +1 -0
- package/dist/sim/passes/suspend.d.ts +10 -0
- package/dist/sim/passes/suspend.js +71 -0
- package/dist/sim/passes/suspend.js.map +1 -0
- package/dist/sim/passes/termination.d.ts +9 -0
- package/dist/sim/passes/termination.js +69 -0
- package/dist/sim/passes/termination.js.map +1 -0
- package/dist/sim/passes/timedAutomata.d.ts +10 -0
- package/dist/sim/passes/timedAutomata.js +437 -0
- package/dist/sim/passes/timedAutomata.js.map +1 -0
- package/dist/sim/passes/unpackClasses.d.ts +2 -0
- package/dist/sim/passes/unpackClasses.js +54 -0
- package/dist/sim/passes/unpackClasses.js.map +1 -0
- package/dist/sim/passes/userSchedule.d.ts +2 -0
- package/dist/sim/passes/userSchedule.js +43 -0
- package/dist/sim/passes/userSchedule.js.map +1 -0
- package/dist/sim/passes/weakSuspend.d.ts +2 -0
- package/dist/sim/passes/weakSuspend.js +145 -0
- package/dist/sim/passes/weakSuspend.js.map +1 -0
- package/dist/sim/preemptionLog.d.ts +41 -0
- package/dist/sim/preemptionLog.js +133 -0
- package/dist/sim/preemptionLog.js.map +1 -0
- package/dist/sim/random.d.ts +12 -0
- package/dist/sim/random.js +40 -0
- package/dist/sim/random.js.map +1 -0
- package/dist/sim/reasons.d.ts +29 -0
- package/dist/sim/reasons.js +168 -0
- package/dist/sim/reasons.js.map +1 -0
- package/dist/sim/scg.d.ts +124 -0
- package/dist/sim/scg.js +723 -0
- package/dist/sim/scg.js.map +1 -0
- package/dist/sim/sfr.d.ts +4 -0
- package/dist/sim/sfr.js +264 -0
- package/dist/sim/sfr.js.map +1 -0
- package/dist/sim/stringConditions.d.ts +3 -0
- package/dist/sim/stringConditions.js +42 -0
- package/dist/sim/stringConditions.js.map +1 -0
- package/dist/sim/structure/copy.d.ts +4 -0
- package/dist/sim/structure/copy.js +140 -0
- package/dist/sim/structure/copy.js.map +1 -0
- package/dist/sim/structure/delays.d.ts +30 -0
- package/dist/sim/structure/delays.js +127 -0
- package/dist/sim/structure/delays.js.map +1 -0
- package/dist/sim/structure/instance.d.ts +15 -0
- package/dist/sim/structure/instance.js +69 -0
- package/dist/sim/structure/instance.js.map +1 -0
- package/dist/sim/structure/methods.d.ts +19 -0
- package/dist/sim/structure/methods.js +550 -0
- package/dist/sim/structure/methods.js.map +1 -0
- package/dist/sim/structure/rewrite.d.ts +20 -0
- package/dist/sim/structure/rewrite.js +113 -0
- package/dist/sim/structure/rewrite.js.map +1 -0
- package/dist/sim/structure/track.d.ts +22 -0
- package/dist/sim/structure/track.js +123 -0
- package/dist/sim/structure/track.js.map +1 -0
- package/dist/sim/tracker.d.ts +77 -0
- package/dist/sim/tracker.js +265 -0
- package/dist/sim/tracker.js.map +1 -0
- package/dist/sim/values.d.ts +31 -0
- package/dist/sim/values.js +103 -0
- package/dist/sim/values.js.map +1 -0
- package/dist/types.d.ts +670 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// KIELER's User Schedule processor (sccharts/processors/UserSchedule.xtend). Owner: the structure workstream.
|
|
2
|
+
//
|
|
3
|
+
// The Dataflow processor gives the regions of a run of sequential equations one schedule object with increasing
|
|
4
|
+
// priorities (structure.md S-27). UserSchedule copies a region's schedule onto every effect inside it (its states'
|
|
5
|
+
// transitions and actions, recursively); the dependency analysis (deps.ts) then orders the accesses of one schedule
|
|
6
|
+
// object by priority instead of initialise-update-read. (KIELER also puts it on triggers; the regions the simulator
|
|
7
|
+
// schedules have none.) Schedules written by the user (`schedule` declarations) are not supported yet.
|
|
8
|
+
import { declsOf } from "./detect.js";
|
|
9
|
+
import { allContainedStates, allRegions } from "../model.js";
|
|
10
|
+
export const userSchedule = {
|
|
11
|
+
id: 'de.cau.cs.kieler.sccharts.processors.userSchedule',
|
|
12
|
+
name: 'User Schedule',
|
|
13
|
+
owner: 'structure',
|
|
14
|
+
run(ctx) {
|
|
15
|
+
const written = declsOf(ctx.root).filter(v => v.declKind === 'schedule');
|
|
16
|
+
if (written.length) {
|
|
17
|
+
ctx.report({
|
|
18
|
+
severity: 'info', code: 'unsupported', span: written[0].span, related: written.flatMap(v => (v.decl ? [v.decl] : [])),
|
|
19
|
+
message: 'The guide\'s simulator cannot run user-defined schedules yet',
|
|
20
|
+
hint: 'This needs KIELER\'s User Schedule transformation for written schedule declarations, which the simulator does not implement yet. The official KIELER tools can run this chart.',
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const region of allRegions(ctx.root)) {
|
|
25
|
+
const schedule = region.ext.schedule;
|
|
26
|
+
if (!schedule)
|
|
27
|
+
continue;
|
|
28
|
+
const add = (f) => {
|
|
29
|
+
f.o = { ...f.o, schedule: [...(f.o.schedule ?? []), { group: schedule.group, priority: schedule.priority }] };
|
|
30
|
+
};
|
|
31
|
+
for (const s of allContainedStates(region)) {
|
|
32
|
+
for (const t of s.out)
|
|
33
|
+
t.effects.forEach(add);
|
|
34
|
+
for (const scope of [s, ...s.regions])
|
|
35
|
+
for (const a of scope.actions)
|
|
36
|
+
a.effects.forEach(add);
|
|
37
|
+
}
|
|
38
|
+
for (const a of region.actions)
|
|
39
|
+
a.effects.forEach(add);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=userSchedule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userSchedule.js","sourceRoot":"","sources":["../../../src/sim/passes/userSchedule.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,EAAE;AACF,gHAAgH;AAChH,mHAAmH;AACnH,oHAAoH;AACpH,oHAAoH;AACpH,uGAAuG;AAGvG,OAAO,EAAE,OAAO,EAAE,oBAAgB;AAClC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAgB,oBAAgB;AAGvE,MAAM,CAAC,MAAM,YAAY,GAAS;IAC9B,EAAE,EAAE,mDAAmD;IACvD,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,WAAW;IAClB,GAAG,CAAC,GAAgB;QAChB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,UAAU,C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AM,CAAC,IAAI,KAAK,CAAC,OAAO;wBAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAChG,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO;gBAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC1D,CAAC;IACL,CAAC;CACJ,CAAA","sourcesContent":["// KIELER's User Schedule processor (sccharts/processors/UserSchedule.xtend). Owner: the structure workstream.\n//\n// The Dataflow processor gives the regions of a run of sequential equations one schedule object with increasing\n// priorities (structure.md S-27). UserSchedule copies a region's schedule onto every effect inside it (its states'\n// transitions and actions, recursively); the dependency analysis (deps.ts) then orders the accesses of one schedule\n// object by priority instead of initialise-update-read. (KIELER also puts it on triggers; the regions the simulator\n// schedules have none.) Schedules written by the user (`schedule` declarations) are not supported yet.\n\nimport type { Pass, PassContext } from './context'\nimport { declsOf } from './detect'\nimport { allContainedStates, allRegions, type CEffect } from '../model'\nimport type { Schedule } from './dataflow'\n\nexport const userSchedule: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.userSchedule',\n name: 'User Schedule',\n owner: 'structure',\n run(ctx: PassContext) {\n const written = declsOf(ctx.root).filter(v => v.declKind === 'schedule')\n if (written.length) {\n ctx.report({\n severity: 'info', code: 'unsupported', span: written[0].span, related: written.flatMap(v => (v.decl ? [v.decl] : [])),\n message: 'The guide\\'s simulator cannot run user-defined schedules yet',\n hint: 'This needs KIELER\\'s User Schedule transformation for written schedule declarations, which the simulator does not implement yet. The official KIELER tools can run this chart.',\n })\n return\n }\n for (const region of allRegions(ctx.root)) {\n const schedule = region.ext.schedule as Schedule | undefined\n if (!schedule) continue\n const add = (f: CEffect) => {\n f.o = { ...f.o, schedule: [...(f.o.schedule ?? []), { group: schedule.group, priority: schedule.priority }] }\n }\n for (const s of allContainedStates(region)) {\n for (const t of s.out) t.effects.forEach(add)\n for (const scope of [s, ...s.regions]) for (const a of scope.actions) a.effects.forEach(add)\n }\n for (const a of region.actions) a.effects.forEach(add)\n }\n },\n}\n"]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// KIELER's Weak Suspend processor (sccharts/processors/WeakSuspend.xtend): in a tick in which `weak suspend if c`
|
|
2
|
+
// of state S holds, S's inside reacts normally, but every region inside S (at any depth) is put back into the
|
|
3
|
+
// state it was in at the end of the last tick without weak suspension, quietly (preemption.md P-46).
|
|
4
|
+
//
|
|
5
|
+
// S gets a flag `_wsFlag` (initially false; `[immediate] during do _wsFlag = c` per weak suspend). Every region
|
|
6
|
+
// inside S gets a bookmark `_<parent>` (initially 0), set by an entry action of each of its states when the flag
|
|
7
|
+
// is off; a state `_WS`, reached from every state by a lowest-priority `immediate if _wsFlag`, from which
|
|
8
|
+
// `immediate if _<parent> == k` goes back to the bookmarked state as a shallow deferred transition (rewritten
|
|
9
|
+
// by Deferred, next); and a new initial state `_Init` that goes straight to `_WS` when the region was weakly
|
|
10
|
+
// suspended in this tick already (`_lastWishDone`), else to the original initial state. Exit actions of the
|
|
11
|
+
// inner states move onto extra states on their outgoing transitions, so the way back to `_WS` skips them. A state
|
|
12
|
+
// that can terminate gets a region `_wsAuxTermination` that is final only while not weakly suspended.
|
|
13
|
+
//
|
|
14
|
+
// The way back to a bookmark carries a `resume` mark, so the tracker (source-level configuration) rewinds too. A
|
|
15
|
+
// weak suspend without trigger is rejected (official KIELER fails in its SCG transformation, P-45).
|
|
16
|
+
import { addMark, allContainedControlflowRegions, and2, copyAction, not } from "./contained.js";
|
|
17
|
+
import { registerSuspend } from "./suspend.js";
|
|
18
|
+
import { actionsOf, allStates, assign, copyExpr, createAction, createControlflowRegion, createEntryAction, createFinalState, createImmediateTransitionTo, createInitialState, createState, createTransitionTo, createVar, isImmediate, lit, op, ref, regionsMayTerminate, removeAction, setLowestPriority, setTarget, FALSE, TRUE, } from "../model.js";
|
|
19
|
+
export const weakSuspend = {
|
|
20
|
+
id: 'de.cau.cs.kieler.sccharts.processors.weakSuspend',
|
|
21
|
+
name: 'Weak Suspend',
|
|
22
|
+
owner: 'preemption',
|
|
23
|
+
run(ctx) {
|
|
24
|
+
for (const state of allStates(ctx.root))
|
|
25
|
+
transformWeakSuspend(state, ctx);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
function transformWeakSuspend(state, ctx) {
|
|
29
|
+
const weakSuspends = state.actions.filter(a => a.kind === 'suspend' && a.weak);
|
|
30
|
+
if (!weakSuspends.length)
|
|
31
|
+
return;
|
|
32
|
+
const about = state.origin ?? state.about;
|
|
33
|
+
const o = { hidden: true, by: about };
|
|
34
|
+
const flag = createVar(state, '_wsFlag', 'bool', 'wsFlag');
|
|
35
|
+
flag.display = `\`${state.name}\` is weakly suspended`;
|
|
36
|
+
flag.init = FALSE;
|
|
37
|
+
registerSuspend(ctx, state, flag, true);
|
|
38
|
+
for (const ws of weakSuspends) {
|
|
39
|
+
const during = createAction(state, 'during');
|
|
40
|
+
during.delay = isImmediate(ws) ? 'immediate' : 'undefined';
|
|
41
|
+
during.about = ws.origin ?? about;
|
|
42
|
+
if (ws.trigger === undefined) {
|
|
43
|
+
ctx.report({
|
|
44
|
+
severity: 'error', code: 'suspend-without-trigger', span: ws.span, related: ws.origin ? [ws.origin] : about ? [about] : undefined,
|
|
45
|
+
message: `This weak suspend has no condition, so it is not clear when \`${state.name}\` should be suspended`,
|
|
46
|
+
hint: 'Write the condition after if, for example `weak suspend if Hold`. KIELER cannot compile a weak suspend without one.',
|
|
47
|
+
kieler: 'This weak suspend has no trigger. KIELER cannot compile a weak suspend without an if condition.',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
during.effects.push(assign(flag, copyExpr(ws.trigger), { hidden: true, by: ws.origin ?? about }));
|
|
52
|
+
}
|
|
53
|
+
removeAction(state, ws);
|
|
54
|
+
}
|
|
55
|
+
for (const region of allContainedControlflowRegions(state)) {
|
|
56
|
+
const subStates = [...region.states];
|
|
57
|
+
const wsState = createState(region, '_WS');
|
|
58
|
+
wsState.about = about;
|
|
59
|
+
const bookmark = createVar(state, '_' + region.parent.name, 'int', 'bookmark');
|
|
60
|
+
bookmark.display = `the state \`${region.parent.name}\` returns to`;
|
|
61
|
+
bookmark.init = lit(0);
|
|
62
|
+
const lastWishDone = createVar(state, '_lastWishDone', 'bool', 'lastWish');
|
|
63
|
+
// Reset in every tick.
|
|
64
|
+
const reset = createAction(state, 'during');
|
|
65
|
+
reset.delay = 'immediate';
|
|
66
|
+
reset.about = about;
|
|
67
|
+
reset.effects.push(assign(lastWishDone, FALSE, o));
|
|
68
|
+
// _WS sets it.
|
|
69
|
+
const wsEntry = createEntryAction(wsState);
|
|
70
|
+
wsEntry.about = about;
|
|
71
|
+
wsEntry.effects.push(assign(lastWishDone, TRUE, o, '|='));
|
|
72
|
+
// Auxiliary initial state for re-entry.
|
|
73
|
+
const initState = createState(region, '_Init');
|
|
74
|
+
initState.about = about;
|
|
75
|
+
initState.initial = true;
|
|
76
|
+
const initWS = createImmediateTransitionTo(initState, wsState);
|
|
77
|
+
initWS.about = about;
|
|
78
|
+
initWS.trigger = and2(ref(flag), ref(lastWishDone));
|
|
79
|
+
let counter = 0;
|
|
80
|
+
for (const sub of subStates) {
|
|
81
|
+
const exits = actionsOf(sub, 'exit');
|
|
82
|
+
if (exits.length) {
|
|
83
|
+
// Exit actions become states on the outgoing transitions, so that going to _WS skips them.
|
|
84
|
+
for (const t of [...sub.out]) {
|
|
85
|
+
const exitState = createState(sub.parent, '__exit');
|
|
86
|
+
exitState.about = sub.origin ?? sub.about;
|
|
87
|
+
for (const a of exits)
|
|
88
|
+
exitState.actions.push(copyAction(a, ctx));
|
|
89
|
+
const exitTransition = createTransitionTo(exitState, t.target);
|
|
90
|
+
exitTransition.about = t.origin ?? t.about;
|
|
91
|
+
exitTransition.history = t.history;
|
|
92
|
+
exitTransition.deferred = t.deferred;
|
|
93
|
+
exitTransition.delay = 'immediate';
|
|
94
|
+
exitTransition.preemption = t.preemption;
|
|
95
|
+
exitTransition.effects.push(...t.effects);
|
|
96
|
+
t.effects = [];
|
|
97
|
+
t.history = 'reset';
|
|
98
|
+
t.deferred = undefined;
|
|
99
|
+
setTarget(t, exitState);
|
|
100
|
+
}
|
|
101
|
+
for (const a of exits)
|
|
102
|
+
removeAction(sub, a);
|
|
103
|
+
}
|
|
104
|
+
const reEnter = createImmediateTransitionTo(wsState, sub);
|
|
105
|
+
reEnter.about = about;
|
|
106
|
+
reEnter.trigger = op('==', ref(bookmark), lit(counter));
|
|
107
|
+
reEnter.deferred = 'shallow';
|
|
108
|
+
if (sub.origin && about)
|
|
109
|
+
addMark(reEnter, { kind: 'resume', state: sub.origin, suspended: about });
|
|
110
|
+
const entry = createEntryAction(sub);
|
|
111
|
+
entry.about = about;
|
|
112
|
+
entry.effects.push(assign(bookmark, lit(counter), o));
|
|
113
|
+
entry.trigger = not(ref(flag));
|
|
114
|
+
counter++;
|
|
115
|
+
// Only if not a final state, or a final state directly inside the weakly suspended state.
|
|
116
|
+
if (!sub.final || sub.parent.parent === state) {
|
|
117
|
+
const toWS = createImmediateTransitionTo(sub, wsState);
|
|
118
|
+
toWS.about = about;
|
|
119
|
+
toWS.trigger = ref(flag);
|
|
120
|
+
setLowestPriority(toWS);
|
|
121
|
+
}
|
|
122
|
+
if (sub.initial) {
|
|
123
|
+
sub.initial = false;
|
|
124
|
+
createImmediateTransitionTo(initState, sub).about = about;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// A state that can terminate only terminates in a tick without weak suspension.
|
|
129
|
+
const needAuxTermRegion = (state.out.some(t => t.preemption === 'termination') || state.root) && regionsMayTerminate(state);
|
|
130
|
+
if (needAuxTermRegion) {
|
|
131
|
+
const aux = createControlflowRegion(state, '_wsAuxTermination');
|
|
132
|
+
aux.about = about;
|
|
133
|
+
const noTerm = createInitialState(aux, '_wsNoTerm');
|
|
134
|
+
const term = createFinalState(aux, '_wsTerm');
|
|
135
|
+
noTerm.about = about;
|
|
136
|
+
term.about = about;
|
|
137
|
+
const t1 = createImmediateTransitionTo(noTerm, term);
|
|
138
|
+
t1.trigger = not(ref(flag));
|
|
139
|
+
t1.about = about;
|
|
140
|
+
const t2 = createTransitionTo(term, noTerm);
|
|
141
|
+
t2.trigger = ref(flag);
|
|
142
|
+
t2.about = about;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=weakSuspend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weakSuspend.js","sourceRoot":"","sources":["../../../src/sim/passes/weakSuspend.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,8GAA8G;AAC9G,qGAAqG;AACrG,EAAE;AACF,gHAAgH;AAChH,iHAAiH;AACjH,0GAA0G;AAC1G,8GAA8G;AAC9G,6GAA6G;AAC7G,4GAA4G;AAC5G,kHAAkH;AAClH,sGAAsG;AACtG,EAAE;AACF,iHAAiH;AACjH,oGAAoG;AAGpG,OAAO,EAAE,OAAO,EAAE,8BAA8B,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,uBAAmB;AAC5F,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EACH,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,gBAAgB,EAClH,2BAA2B,EAAE,kBAAkB,EAAE,WAAW,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,EACjH,GAAG,EAAE,mBAAmB,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,GACpF,oBAAgB;AAEjB,MAAM,CAAC,MAAM,WAAW,GAAS;IAC7B,EAAE,EAAE,kDAAkD;IACtD,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,YAAY;IACnB,GAAG,CAAC,GAAgB;QAChB,KAAK,MAAM,KAAK,IAAI,SAAS,CA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C,KAAK,CAAC,CAAA;IAC3H,IAAI,iBAAiB,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,uBAAuB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAA;QAC/D,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;QACjB,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;QACnD,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QAC7C,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,MAAM,EAAE,GAAG,2BAA2B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACpD,EAAE,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3B,EAAE,CAAC,KAAK,GAAG,KAAK,CAAA;QAChB,MAAM,EAAE,GAAG,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC3C,EAAE,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;QACtB,EAAE,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;AACL,CAAC","sourcesContent":["// KIELER's Weak Suspend processor (sccharts/processors/WeakSuspend.xtend): in a tick in which `weak suspend if c`\n// of state S holds, S's inside reacts normally, but every region inside S (at any depth) is put back into the\n// state it was in at the end of the last tick without weak suspension, quietly (preemption.md P-46).\n//\n// S gets a flag `_wsFlag` (initially false; `[immediate] during do _wsFlag = c` per weak suspend). Every region\n// inside S gets a bookmark `_<parent>` (initially 0), set by an entry action of each of its states when the flag\n// is off; a state `_WS`, reached from every state by a lowest-priority `immediate if _wsFlag`, from which\n// `immediate if _<parent> == k` goes back to the bookmarked state as a shallow deferred transition (rewritten\n// by Deferred, next); and a new initial state `_Init` that goes straight to `_WS` when the region was weakly\n// suspended in this tick already (`_lastWishDone`), else to the original initial state. Exit actions of the\n// inner states move onto extra states on their outgoing transitions, so the way back to `_WS` skips them. A state\n// that can terminate gets a region `_wsAuxTermination` that is final only while not weakly suspended.\n//\n// The way back to a bookmark carries a `resume` mark, so the tracker (source-level configuration) rewinds too. A\n// weak suspend without trigger is rejected (official KIELER fails in its SCG transformation, P-45).\n\nimport type { Pass, PassContext } from './context'\nimport { addMark, allContainedControlflowRegions, and2, copyAction, not } from './contained'\nimport { registerSuspend } from './suspend'\nimport {\n actionsOf, allStates, assign, copyExpr, createAction, createControlflowRegion, createEntryAction, createFinalState,\n createImmediateTransitionTo, createInitialState, createState, createTransitionTo, createVar, isImmediate, lit, op,\n ref, regionsMayTerminate, removeAction, setLowestPriority, setTarget, FALSE, TRUE, type CState,\n} from '../model'\n\nexport const weakSuspend: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.weakSuspend',\n name: 'Weak Suspend',\n owner: 'preemption',\n run(ctx: PassContext) {\n for (const state of allStates(ctx.root)) transformWeakSuspend(state, ctx)\n },\n}\n\nfunction transformWeakSuspend(state: CState, ctx: PassContext) {\n const weakSuspends = state.actions.filter(a => a.kind === 'suspend' && a.weak)\n if (!weakSuspends.length) return\n const about = state.origin ?? state.about\n const o = { hidden: true, by: about }\n\n const flag = createVar(state, '_wsFlag', 'bool', 'wsFlag')\n flag.display = `\\`${state.name}\\` is weakly suspended`\n flag.init = FALSE\n registerSuspend(ctx, state, flag, true)\n\n for (const ws of weakSuspends) {\n const during = createAction(state, 'during')\n during.delay = isImmediate(ws) ? 'immediate' : 'undefined'\n during.about = ws.origin ?? about\n if (ws.trigger === undefined) {\n ctx.report({\n severity: 'error', code: 'suspend-without-trigger', span: ws.span, related: ws.origin ? [ws.origin] : about ? [about] : undefined,\n message: `This weak suspend has no condition, so it is not clear when \\`${state.name}\\` should be suspended`,\n hint: 'Write the condition after if, for example `weak suspend if Hold`. KIELER cannot compile a weak suspend without one.',\n kieler: 'This weak suspend has no trigger. KIELER cannot compile a weak suspend without an if condition.',\n })\n } else {\n during.effects.push(assign(flag, copyExpr(ws.trigger), { hidden: true, by: ws.origin ?? about }))\n }\n removeAction(state, ws)\n }\n\n for (const region of allContainedControlflowRegions(state)) {\n const subStates = [...region.states]\n const wsState = createState(region, '_WS')\n wsState.about = about\n const bookmark = createVar(state, '_' + region.parent.name, 'int', 'bookmark')\n bookmark.display = `the state \\`${region.parent.name}\\` returns to`\n bookmark.init = lit(0)\n\n const lastWishDone = createVar(state, '_lastWishDone', 'bool', 'lastWish')\n // Reset in every tick.\n const reset = createAction(state, 'during')\n reset.delay = 'immediate'\n reset.about = about\n reset.effects.push(assign(lastWishDone, FALSE, o))\n // _WS sets it.\n const wsEntry = createEntryAction(wsState)\n wsEntry.about = about\n wsEntry.effects.push(assign(lastWishDone, TRUE, o, '|='))\n\n // Auxiliary initial state for re-entry.\n const initState = createState(region, '_Init')\n initState.about = about\n initState.initial = true\n const initWS = createImmediateTransitionTo(initState, wsState)\n initWS.about = about\n initWS.trigger = and2(ref(flag), ref(lastWishDone))\n\n let counter = 0\n for (const sub of subStates) {\n const exits = actionsOf(sub, 'exit')\n if (exits.length) {\n // Exit actions become states on the outgoing transitions, so that going to _WS skips them.\n for (const t of [...sub.out]) {\n const exitState = createState(sub.parent!, '__exit')\n exitState.about = sub.origin ?? sub.about\n for (const a of exits) exitState.actions.push(copyAction(a, ctx))\n const exitTransition = createTransitionTo(exitState, t.target)\n exitTransition.about = t.origin ?? t.about\n exitTransition.history = t.history\n exitTransition.deferred = t.deferred\n exitTransition.delay = 'immediate'\n exitTransition.preemption = t.preemption\n exitTransition.effects.push(...t.effects)\n t.effects = []\n t.history = 'reset'\n t.deferred = undefined\n setTarget(t, exitState)\n }\n for (const a of exits) removeAction(sub, a)\n }\n const reEnter = createImmediateTransitionTo(wsState, sub)\n reEnter.about = about\n reEnter.trigger = op('==', ref(bookmark), lit(counter))\n reEnter.deferred = 'shallow'\n if (sub.origin && about) addMark(reEnter, { kind: 'resume', state: sub.origin, suspended: about })\n\n const entry = createEntryAction(sub)\n entry.about = about\n entry.effects.push(assign(bookmark, lit(counter), o))\n entry.trigger = not(ref(flag))\n counter++\n\n // Only if not a final state, or a final state directly inside the weakly suspended state.\n if (!sub.final || sub.parent!.parent === state) {\n const toWS = createImmediateTransitionTo(sub, wsState)\n toWS.about = about\n toWS.trigger = ref(flag)\n setLowestPriority(toWS)\n }\n if (sub.initial) {\n sub.initial = false\n createImmediateTransitionTo(initState, sub).about = about\n }\n }\n }\n\n // A state that can terminate only terminates in a tick without weak suspension.\n const needAuxTermRegion = (state.out.some(t => t.preemption === 'termination') || state.root) && regionsMayTerminate(state)\n if (needAuxTermRegion) {\n const aux = createControlflowRegion(state, '_wsAuxTermination')\n aux.about = about\n const noTerm = createInitialState(aux, '_wsNoTerm')\n const term = createFinalState(aux, '_wsTerm')\n noTerm.about = about\n term.about = about\n const t1 = createImmediateTransitionTo(noTerm, term)\n t1.trigger = not(ref(flag))\n t1.about = about\n const t2 = createTransitionTo(term, noTerm)\n t2.trigger = ref(flag)\n t2.about = about\n }\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { State, TraceEvent, TraceSeen, Transition } from "../types.js";
|
|
2
|
+
import type { CVar, Mark } from "./model.js";
|
|
3
|
+
import type { SuspendInfo } from "./passes/suspend.js";
|
|
4
|
+
import type { HistoryRecord } from "./passes/history.js";
|
|
5
|
+
import type { TakeOptions, Tracker } from "./tracker.js";
|
|
6
|
+
type TakeMark = Extract<Mark, {
|
|
7
|
+
kind: 'take';
|
|
8
|
+
}>;
|
|
9
|
+
export type HookMark = Extract<Mark, {
|
|
10
|
+
kind: 'enterRegions' | 'resume';
|
|
11
|
+
}>;
|
|
12
|
+
/** What the tracker needs from a take mark (undefined: a plain take). */
|
|
13
|
+
export declare function takeOptions(m: TakeMark): TakeOptions | undefined;
|
|
14
|
+
export declare function isHook(m: Mark): m is HookMark;
|
|
15
|
+
/** Source states by id, for the sentences. */
|
|
16
|
+
export declare class StateNames {
|
|
17
|
+
private readonly states;
|
|
18
|
+
private readonly parents;
|
|
19
|
+
private readonly transitions;
|
|
20
|
+
constructor(root: State);
|
|
21
|
+
name(id: string): string;
|
|
22
|
+
state(id: string): State | undefined;
|
|
23
|
+
parent(id: string): State | undefined;
|
|
24
|
+
transition(id: string): Transition | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** A note in plain text and in Markdown: `build` gets how to write a name (as it is, or as code). */
|
|
27
|
+
export declare function note(related: string[], build: (c: (name: string) => string) => string): Extract<TraceEvent, {
|
|
28
|
+
kind: 'note';
|
|
29
|
+
}>;
|
|
30
|
+
/** Notes after a take with refined options: the history KIELER applied, a deferred entry. */
|
|
31
|
+
export declare function takeNotes(transition: string, options: TakeOptions, entered: string[], names: StateNames, tracker?: Tracker): TraceEvent[];
|
|
32
|
+
/** Reads KIELER's history records (passes/history.ts) for the tracker: the state a region's record resumes. */
|
|
33
|
+
export declare function historyRecordReader(records: Map<string, HistoryRecord> | undefined, value: (v: CVar) => number): TakeOptions['record'];
|
|
34
|
+
/** Applies a tracker hook and returns its events. */
|
|
35
|
+
export declare function hookEvents(m: HookMark, tracker: Tracker, names: StateNames, record?: TakeOptions['record']): TraceEvent[];
|
|
36
|
+
/**
|
|
37
|
+
* The (weakly) suspended states of the tick, from their flags after the tick (`value(flag)`: its value; `seen(flag)`:
|
|
38
|
+
* what the suspend triggers read when the flag was computed).
|
|
39
|
+
*/
|
|
40
|
+
export declare function suspendEvents(suspends: SuspendInfo[] | undefined, active: Set<string>, value: (v: CVar) => boolean, names: StateNames, seen?: (v: CVar) => TraceSeen[] | undefined): TraceEvent[];
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// The preemption passes' part of a tick's log (exec.ts calls these): how a take moves the source-level
|
|
2
|
+
// configuration when KIELER applies history differently from what is written (P-51) or enters a state one tick
|
|
3
|
+
// late (deferred, P-54), weak suspend's way back (P-46), and which states were (weakly) suspended in the tick.
|
|
4
|
+
// Every event is in source terms; notes are plain-English sentences that describeTick passes on.
|
|
5
|
+
import { seenText } from "./reasons.js";
|
|
6
|
+
/** What the tracker needs from a take mark (undefined: a plain take). */
|
|
7
|
+
export function takeOptions(m) {
|
|
8
|
+
if (m.history === undefined && !m.deferEntry)
|
|
9
|
+
return undefined;
|
|
10
|
+
return { history: m.history, deferEntry: m.deferEntry };
|
|
11
|
+
}
|
|
12
|
+
export function isHook(m) {
|
|
13
|
+
return m.kind === 'enterRegions' || m.kind === 'resume';
|
|
14
|
+
}
|
|
15
|
+
/** Source states by id, for the sentences. */
|
|
16
|
+
export class StateNames {
|
|
17
|
+
states = new Map();
|
|
18
|
+
parents = new Map();
|
|
19
|
+
transitions = new Map();
|
|
20
|
+
constructor(root) {
|
|
21
|
+
const visit = (s) => {
|
|
22
|
+
this.states.set(s.id, s);
|
|
23
|
+
for (const t of s.transitions)
|
|
24
|
+
this.transitions.set(t.id, t);
|
|
25
|
+
for (const r of s.regions)
|
|
26
|
+
for (const c of r.states) {
|
|
27
|
+
this.parents.set(c.id, s);
|
|
28
|
+
visit(c);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
visit(root);
|
|
32
|
+
}
|
|
33
|
+
name(id) {
|
|
34
|
+
const s = this.states.get(id);
|
|
35
|
+
return s ? s.label ?? s.name : id;
|
|
36
|
+
}
|
|
37
|
+
state(id) {
|
|
38
|
+
return this.states.get(id);
|
|
39
|
+
}
|
|
40
|
+
parent(id) {
|
|
41
|
+
return this.parents.get(id);
|
|
42
|
+
}
|
|
43
|
+
transition(id) {
|
|
44
|
+
return this.transitions.get(id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const list = (names) => names.length <= 1 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
|
|
48
|
+
/** A note in plain text and in Markdown: `build` gets how to write a name (as it is, or as code). */
|
|
49
|
+
export function note(related, build) {
|
|
50
|
+
return { kind: 'note', related, text: build(n => n), markdown: build(n => '`' + n.replace(/`/g, "'") + '`') };
|
|
51
|
+
}
|
|
52
|
+
/** Notes after a take with refined options: the history KIELER applied, a deferred entry. */
|
|
53
|
+
export function takeNotes(transition, options, entered, names, tracker) {
|
|
54
|
+
const out = [];
|
|
55
|
+
const tr = names.transition(transition);
|
|
56
|
+
const target = tr?.target;
|
|
57
|
+
const written = tr?.history;
|
|
58
|
+
if (!target)
|
|
59
|
+
return out;
|
|
60
|
+
const name = names.name(target);
|
|
61
|
+
if (options.deferEntry) {
|
|
62
|
+
out.push(note([transition, target], c => `${c(name)} is entered quietly (deferred): nothing of ${c(name)} runs in this tick, not even its entry actions, and its inner states start in the next tick.`));
|
|
63
|
+
}
|
|
64
|
+
if (written === 'shallow' || written === 'deep') {
|
|
65
|
+
if (options.history === 'reset' && names.state(target)?.regions.some(r => r.states.length > 0)) {
|
|
66
|
+
out.push(note([transition, target], c => `KIELER ignores this ${written === 'shallow' ? 'shallow history' : 'history'}: ${c(name)} is nested in a state that is not itself the target of a history transition, so it restarts from its initial state${entered.length > 2 ? 's' : ''}.`));
|
|
67
|
+
}
|
|
68
|
+
else if (!options.deferEntry) {
|
|
69
|
+
const inner = entered.filter(id => id !== target);
|
|
70
|
+
// KIELER records a state when it is entered; a deferred entry does not record it (Deferred drops the entry action).
|
|
71
|
+
const unrecorded = inner.filter(id => {
|
|
72
|
+
const region = tracker?.regionOf(id);
|
|
73
|
+
const last = region ? tracker?.lastActive(region) : undefined;
|
|
74
|
+
return last !== undefined && last !== id;
|
|
75
|
+
});
|
|
76
|
+
if (inner.length)
|
|
77
|
+
out.push(note([transition, target, ...inner], c => `${c(name)} resumes with its ${written === 'shallow' ? 'shallow history: its own regions continue' : 'history: it continues'} in ${list(inner.map(id => c(names.name(id))))}, ${unrecorded.length
|
|
78
|
+
? `the last state${inner.length > 1 ? 's' : ''} KIELER recorded: a state entered by a deferred transition is not recorded, because KIELER removes the entry actions of such a state, including the one that records it`
|
|
79
|
+
: `the state${inner.length > 1 ? 's' : ''} it was in when it was left`}.`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
/** Reads KIELER's history records (passes/history.ts) for the tracker: the state a region's record resumes. */
|
|
85
|
+
export function historyRecordReader(records, value) {
|
|
86
|
+
if (!records?.size)
|
|
87
|
+
return undefined;
|
|
88
|
+
return regionId => {
|
|
89
|
+
const r = records.get(regionId);
|
|
90
|
+
return r ? r.states[value(r.v)] : undefined;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Applies a tracker hook and returns its events. */
|
|
94
|
+
export function hookEvents(m, tracker, names, record) {
|
|
95
|
+
const out = [];
|
|
96
|
+
if (m.kind === 'enterRegions') {
|
|
97
|
+
const entered = tracker.enterRegionsOf(m.state, record);
|
|
98
|
+
for (const id of entered)
|
|
99
|
+
out.push({ kind: 'enter', state: id });
|
|
100
|
+
if (entered.length)
|
|
101
|
+
out.push(note([m.state, ...entered], c => `One tick after its deferred entry, ${c(names.name(m.state))} starts: ${list(entered.map(id => c(names.name(id))))} ${entered.length > 1 ? 'are' : 'is'} entered now.`));
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
const exited = tracker.resume(m.state);
|
|
105
|
+
if (!exited)
|
|
106
|
+
return out;
|
|
107
|
+
for (const id of exited)
|
|
108
|
+
out.push({ kind: 'exit', state: id });
|
|
109
|
+
const left = exited.filter(id => names.parent(id)?.id === names.parent(m.state)?.id);
|
|
110
|
+
out.push(note([m.state, m.suspended, ...left], c => `${c(names.name(m.suspended))} is weakly suspended, so ${left.length ? `what happened in its region is undone: ${list(left.map(id => c(names.name(id))))} ${left.length > 1 ? 'are' : 'is'} forgotten and ` : ''}control goes back to ${c(names.name(m.state))}, quietly (no entry actions).`));
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The (weakly) suspended states of the tick, from their flags after the tick (`value(flag)`: its value; `seen(flag)`:
|
|
115
|
+
* what the suspend triggers read when the flag was computed).
|
|
116
|
+
*/
|
|
117
|
+
export function suspendEvents(suspends, active, value, names, seen) {
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const s of suspends ?? []) {
|
|
120
|
+
if (!active.has(s.state))
|
|
121
|
+
continue;
|
|
122
|
+
const flag = value(s.flag);
|
|
123
|
+
if (!s.weak && !flag) {
|
|
124
|
+
const read = seen?.(s.flag);
|
|
125
|
+
out.push(read?.length ? { kind: 'suspend', state: s.state, reason: seenText(read), seen: read } : { kind: 'suspend', state: s.state });
|
|
126
|
+
}
|
|
127
|
+
else if (s.weak && flag) {
|
|
128
|
+
out.push(note([s.state], c => `${c(names.name(s.state))} is weakly suspended in this tick: its inside reacts, but at the end of the tick every region inside it goes back to the state it was in after the last tick without weak suspension.`));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=preemptionLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preemptionLog.js","sourceRoot":"","sources":["../../src/sim/preemptionLog.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,+GAA+G;AAC/G,+GAA+G;AAC/G,iGAAiG;AAOjG,OAAO,EAAE,QAAQ,EAAE,qBAAiB;AAKpC,yEAAyE;AACzE,MAAM,UAAU,WAAW,CAAC,CAAW;IACnC,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,UAAU;QAAE,OAAO,SAAS,CAAA;IAC9D,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,CAAO;IAC1B,OAAO,CAAC,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC3D,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,UAAU;IACF,MAAM,GAAG,IAAI,GAAG,EA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AE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QAC1I,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uLAAuL,CAAC,CAAC,CAAA;QACpP,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["// The preemption passes' part of a tick's log (exec.ts calls these): how a take moves the source-level\n// configuration when KIELER applies history differently from what is written (P-51) or enters a state one tick\n// late (deferred, P-54), weak suspend's way back (P-46), and which states were (weakly) suspended in the tick.\n// Every event is in source terms; notes are plain-English sentences that describeTick passes on.\n\nimport type { State, TraceEvent, TraceSeen, Transition } from '../types'\nimport type { CVar, Mark } from './model'\nimport type { SuspendInfo } from './passes/suspend'\nimport type { HistoryRecord } from './passes/history'\nimport type { TakeOptions, Tracker } from './tracker'\nimport { seenText } from './reasons'\n\ntype TakeMark = Extract<Mark, { kind: 'take' }>\nexport type HookMark = Extract<Mark, { kind: 'enterRegions' | 'resume' }>\n\n/** What the tracker needs from a take mark (undefined: a plain take). */\nexport function takeOptions(m: TakeMark): TakeOptions | undefined {\n if (m.history === undefined && !m.deferEntry) return undefined\n return { history: m.history, deferEntry: m.deferEntry }\n}\n\nexport function isHook(m: Mark): m is HookMark {\n return m.kind === 'enterRegions' || m.kind === 'resume'\n}\n\n/** Source states by id, for the sentences. */\nexport class StateNames {\n private readonly states = new Map<string, State>()\n private readonly parents = new Map<string, State>()\n private readonly transitions = new Map<string, Transition>()\n constructor(root: State) {\n const visit = (s: State) => {\n this.states.set(s.id, s)\n for (const t of s.transitions) this.transitions.set(t.id, t)\n for (const r of s.regions) for (const c of r.states) {\n this.parents.set(c.id, s)\n visit(c)\n }\n }\n visit(root)\n }\n name(id: string): string {\n const s = this.states.get(id)\n return s ? s.label ?? s.name : id\n }\n state(id: string): State | undefined {\n return this.states.get(id)\n }\n parent(id: string): State | undefined {\n return this.parents.get(id)\n }\n transition(id: string): Transition | undefined {\n return this.transitions.get(id)\n }\n}\n\nconst list = (names: string[]) => names.length <= 1 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`\n\n/** A note in plain text and in Markdown: `build` gets how to write a name (as it is, or as code). */\nexport function note(related: string[], build: (c: (name: string) => string) => string): Extract<TraceEvent, { kind: 'note' }> {\n return { kind: 'note', related, text: build(n => n), markdown: build(n => '`' + n.replace(/`/g, \"'\") + '`') }\n}\n\n/** Notes after a take with refined options: the history KIELER applied, a deferred entry. */\nexport function takeNotes(transition: string, options: TakeOptions, entered: string[], names: StateNames, tracker?: Tracker): TraceEvent[] {\n const out: TraceEvent[] = []\n const tr = names.transition(transition)\n const target = tr?.target\n const written = tr?.history\n if (!target) return out\n const name = names.name(target)\n if (options.deferEntry) {\n out.push(note([transition, target], c => `${c(name)} is entered quietly (deferred): nothing of ${c(name)} runs in this tick, not even its entry actions, and its inner states start in the next tick.`))\n }\n if (written === 'shallow' || written === 'deep') {\n if (options.history === 'reset' && names.state(target)?.regions.some(r => r.states.length > 0)) {\n out.push(note([transition, target], c => `KIELER ignores this ${written === 'shallow' ? 'shallow history' : 'history'}: ${c(name)} is nested in a state that is not itself the target of a history transition, so it restarts from its initial state${entered.length > 2 ? 's' : ''}.`))\n } else if (!options.deferEntry) {\n const inner = entered.filter(id => id !== target)\n // KIELER records a state when it is entered; a deferred entry does not record it (Deferred drops the entry action).\n const unrecorded = inner.filter(id => {\n const region = tracker?.regionOf(id)\n const last = region ? tracker?.lastActive(region) : undefined\n return last !== undefined && last !== id\n })\n if (inner.length) out.push(note([transition, target, ...inner], c => `${c(name)} resumes with its ${written === 'shallow' ? 'shallow history: its own regions continue' : 'history: it continues'} in ${list(inner.map(id => c(names.name(id))))}, ${unrecorded.length\n ? `the last state${inner.length > 1 ? 's' : ''} KIELER recorded: a state entered by a deferred transition is not recorded, because KIELER removes the entry actions of such a state, including the one that records it`\n : `the state${inner.length > 1 ? 's' : ''} it was in when it was left`}.`))\n }\n }\n return out\n}\n\n/** Reads KIELER's history records (passes/history.ts) for the tracker: the state a region's record resumes. */\nexport function historyRecordReader(records: Map<string, HistoryRecord> | undefined, value: (v: CVar) => number): TakeOptions['record'] {\n if (!records?.size) return undefined\n return regionId => {\n const r = records.get(regionId)\n return r ? r.states[value(r.v)] : undefined\n }\n}\n\n/** Applies a tracker hook and returns its events. */\nexport function hookEvents(m: HookMark, tracker: Tracker, names: StateNames, record?: TakeOptions['record']): TraceEvent[] {\n const out: TraceEvent[] = []\n if (m.kind === 'enterRegions') {\n const entered = tracker.enterRegionsOf(m.state, record)\n for (const id of entered) out.push({ kind: 'enter', state: id })\n if (entered.length) out.push(note([m.state, ...entered], c => `One tick after its deferred entry, ${c(names.name(m.state))} starts: ${list(entered.map(id => c(names.name(id))))} ${entered.length > 1 ? 'are' : 'is'} entered now.`))\n return out\n }\n const exited = tracker.resume(m.state)\n if (!exited) return out\n for (const id of exited) out.push({ kind: 'exit', state: id })\n const left = exited.filter(id => names.parent(id)?.id === names.parent(m.state)?.id)\n out.push(note([m.state, m.suspended, ...left], c => `${c(names.name(m.suspended))} is weakly suspended, so ${left.length ? `what happened in its region is undone: ${list(left.map(id => c(names.name(id))))} ${left.length > 1 ? 'are' : 'is'} forgotten and ` : ''}control goes back to ${c(names.name(m.state))}, quietly (no entry actions).`))\n return out\n}\n\n/**\n * The (weakly) suspended states of the tick, from their flags after the tick (`value(flag)`: its value; `seen(flag)`:\n * what the suspend triggers read when the flag was computed).\n */\nexport function suspendEvents(suspends: SuspendInfo[] | undefined, active: Set<string>, value: (v: CVar) => boolean, names: StateNames, seen?: (v: CVar) => TraceSeen[] | undefined): TraceEvent[] {\n const out: TraceEvent[] = []\n for (const s of suspends ?? []) {\n if (!active.has(s.state)) continue\n const flag = value(s.flag)\n if (!s.weak && !flag) {\n const read = seen?.(s.flag)\n out.push(read?.length ? { kind: 'suspend', state: s.state, reason: seenText(read), seen: read } : { kind: 'suspend', state: s.state })\n } else if (s.weak && flag) {\n out.push(note([s.state], c => `${c(names.name(s.state))} is weakly suspended in this tick: its inside reacts, but at the end of the tick every region inside it goes back to the state it was in after the last tick without weak suspension.`))\n }\n }\n return out\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RandState {
|
|
2
|
+
/** The last 34 values of the additive feedback generator, as a ring buffer. */
|
|
3
|
+
ring: number[];
|
|
4
|
+
/** Index of the next value to compute (i in r[i]). */
|
|
5
|
+
i: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function newRandState(): RandState;
|
|
8
|
+
/** The next rand() result (0 .. 2147483647). */
|
|
9
|
+
export declare function rand(state: RandState): number;
|
|
10
|
+
/** KIELER's random(): ((float) rand() / RAND_MAX), computed in single precision. */
|
|
11
|
+
export declare function random(state: RandState): number;
|
|
12
|
+
export declare function cloneRandState(state: RandState): RandState;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// glibc's rand() with its default state (TYPE_3, seed 1), which KIELER's C simulation uses unseeded
|
|
2
|
+
// (basics.md B-29): the sequence starts 1804289383, 846930886, 1681692777, ...
|
|
3
|
+
export function newRandState() {
|
|
4
|
+
const r = new Array(34);
|
|
5
|
+
r[0] = 1;
|
|
6
|
+
for (let i = 1; i < 31; i++) {
|
|
7
|
+
// 16807 * r[i-1] % 2147483647 with Schrage's method semantics (glibc computes it exactly in 64 bits).
|
|
8
|
+
let v = (16807 * r[i - 1]) % 2147483647;
|
|
9
|
+
if (v < 0)
|
|
10
|
+
v += 2147483647;
|
|
11
|
+
r[i] = v;
|
|
12
|
+
}
|
|
13
|
+
for (let i = 31; i < 34; i++)
|
|
14
|
+
r[i] = r[i - 31];
|
|
15
|
+
const state = { ring: r.map(v => v >>> 0), i: 34 };
|
|
16
|
+
// glibc discards the first 310 outputs (r[34] .. r[343]).
|
|
17
|
+
for (let k = 34; k < 344; k++)
|
|
18
|
+
step(state);
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
function step(state) {
|
|
22
|
+
const { ring } = state;
|
|
23
|
+
const i = state.i;
|
|
24
|
+
const v = (ring[(i - 31) % 34] + ring[(i - 3) % 34]) >>> 0;
|
|
25
|
+
ring[i % 34] = v;
|
|
26
|
+
state.i = i + 1;
|
|
27
|
+
return v;
|
|
28
|
+
}
|
|
29
|
+
/** The next rand() result (0 .. 2147483647). */
|
|
30
|
+
export function rand(state) {
|
|
31
|
+
return step(state) >>> 1;
|
|
32
|
+
}
|
|
33
|
+
/** KIELER's random(): ((float) rand() / RAND_MAX), computed in single precision. */
|
|
34
|
+
export function random(state) {
|
|
35
|
+
return Math.fround(Math.fround(rand(state)) / Math.fround(2147483647));
|
|
36
|
+
}
|
|
37
|
+
export function cloneRandState(state) {
|
|
38
|
+
return { ring: state.ring.slice(), i: state.i };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../src/sim/random.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,+EAA+E;AAS/E,MAAM,UAAU,YAAY;IACxB,MAAM,CAAC,GAAa,IAAI,KAAK,CAAC,EAAE,CAAC,CAAA;IACjC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACR,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1B,sGAAsG;QACtG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CA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CAAC,KAAgB;IACnC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAA;AACnD,CAAC","sourcesContent":["// glibc's rand() with its default state (TYPE_3, seed 1), which KIELER's C simulation uses unseeded\n// (basics.md B-29): the sequence starts 1804289383, 846930886, 1681692777, ...\n\nexport interface RandState {\n /** The last 34 values of the additive feedback generator, as a ring buffer. */\n ring: number[]\n /** Index of the next value to compute (i in r[i]). */\n i: number\n}\n\nexport function newRandState(): RandState {\n const r: number[] = new Array(34)\n r[0] = 1\n for (let i = 1; i < 31; i++) {\n // 16807 * r[i-1] % 2147483647 with Schrage's method semantics (glibc computes it exactly in 64 bits).\n let v = (16807 * r[i - 1]) % 2147483647\n if (v < 0) v += 2147483647\n r[i] = v\n }\n for (let i = 31; i < 34; i++) r[i] = r[i - 31]\n const state: RandState = { ring: r.map(v => v >>> 0), i: 34 }\n // glibc discards the first 310 outputs (r[34] .. r[343]).\n for (let k = 34; k < 344; k++) step(state)\n return state\n}\n\nfunction step(state: RandState): number {\n const { ring } = state\n const i = state.i\n const v = (ring[(i - 31) % 34] + ring[(i - 3) % 34]) >>> 0\n ring[i % 34] = v\n state.i = i + 1\n return v\n}\n\n/** The next rand() result (0 .. 2147483647). */\nexport function rand(state: RandState): number {\n return step(state) >>> 1\n}\n\n/** KIELER's random(): ((float) rand() / RAND_MAX), computed in single precision. */\nexport function random(state: RandState): number {\n return Math.fround(Math.fround(rand(state)) / Math.fround(2147483647))\n}\n\nexport function cloneRandState(state: RandState): RandState {\n return { ring: state.ring.slice(), i: state.i }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Expression, LocalAction, State, TraceSeen, Transition, Value } from "../types.js";
|
|
2
|
+
import type { ModelIndex } from "../parser/resolve.js";
|
|
3
|
+
import type { Fn, Runtime } from "./eval.js";
|
|
4
|
+
import { type CExpr, type CRef } from "./model.js";
|
|
5
|
+
export interface Probe {
|
|
6
|
+
name: string;
|
|
7
|
+
signal: boolean;
|
|
8
|
+
fn: Fn;
|
|
9
|
+
/** Converts the run-time value for the log. */
|
|
10
|
+
value: (v: ReturnType<Fn>) => Value;
|
|
11
|
+
}
|
|
12
|
+
interface SourceElements {
|
|
13
|
+
transitions: Map<string, Transition>;
|
|
14
|
+
actions: Map<string, LocalAction>;
|
|
15
|
+
}
|
|
16
|
+
/** Every source transition and action of the programs the chart was compiled from, by id. */
|
|
17
|
+
export declare function sourceElements(chart: State, index: ModelIndex | undefined): SourceElements;
|
|
18
|
+
/** The source element an executor id stands for: an instance's `<prefix>/<id>` is the referenced chart's `<id>`. */
|
|
19
|
+
export declare function lookupSource<T>(map: Map<string, T>, id: string): T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Probes for a core condition that implements (part of) a source trigger. `compileRef` compiles a core reference
|
|
22
|
+
* into a reader; references of the source trigger the condition does not read are left out.
|
|
23
|
+
*/
|
|
24
|
+
export declare function triggerProbes(core: CExpr | undefined, trigger: Expression | undefined, compileRef: (r: CRef) => Probe['fn'] | undefined, valueOf: (r: CRef) => Probe['value']): Probe[];
|
|
25
|
+
/** Reads the probes now (a probe that cannot be evaluated, e.g. an index out of range, is left out). */
|
|
26
|
+
export declare function readProbes(probes: Probe[], rt: Runtime): TraceSeen[];
|
|
27
|
+
/** "n was 0 and S was present". */
|
|
28
|
+
export declare function seenText(seen: TraceSeen[]): string;
|
|
29
|
+
export {};
|