@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,230 @@
|
|
|
1
|
+
// KIELER's For processor (sccharts/processors/For.xtend). Owner: the structure workstream. structure.md S-21 .. S-24.
|
|
2
|
+
//
|
|
3
|
+
// `region R for i : a to b` (int literals; counting down when a > b) and `region R for i : A` (0 to the array's first
|
|
4
|
+
// size - 1) become one copy of the region per counter value, appended after the state's other regions in counter
|
|
5
|
+
// order (S-22); the original goes. In each copy the counter is a constant: KIELER declares `const int i = <value>`
|
|
6
|
+
// in the copy, and its Const processor replaces every use by the value and folds the copy's constant expressions.
|
|
7
|
+
// Copies keep their transitions' Taken Transition Signaling marks, so all copies share the original's counter
|
|
8
|
+
// (S-23); the marks get a `key` per copy for the tracker (structure/track.ts).
|
|
9
|
+
//
|
|
10
|
+
// What KIELER cannot compile (S-24): a for-region inside another for-region, and a declaration of the region whose
|
|
11
|
+
// initial value uses the counter (Region Actions has moved it out of the region, so the copies lose the counter):
|
|
12
|
+
// both crash in KIELER's SCG transformation; assigning the counter fails in Const.
|
|
13
|
+
import { allContainedStates, allScopes, allStates, isRegion, printEffect, } from "../model.js";
|
|
14
|
+
import { foldConstants } from "../fold.js";
|
|
15
|
+
import { copyRegion } from "../structure/copy.js";
|
|
16
|
+
import { rewriteScope, rewriteStatements } from "../structure/rewrite.js";
|
|
17
|
+
export const forRegion = {
|
|
18
|
+
id: 'de.cau.cs.kieler.sccharts.processors.for',
|
|
19
|
+
name: 'For',
|
|
20
|
+
owner: 'structure',
|
|
21
|
+
run(ctx) {
|
|
22
|
+
const regions = allStates(ctx.root).flatMap(s => s.regions.filter(r => r.ext.forCounter !== undefined));
|
|
23
|
+
if (!regions.length)
|
|
24
|
+
return;
|
|
25
|
+
// Nested for-regions and counters used outside their region crash KIELER: reject before copying.
|
|
26
|
+
let crashed = false;
|
|
27
|
+
for (const r of regions) {
|
|
28
|
+
const counter = r.ext.forCounter;
|
|
29
|
+
const nested = regions.some(o => o !== r && inside(r, o));
|
|
30
|
+
const outside = usesOutside(ctx.root, r, counter);
|
|
31
|
+
// A code effect (or method) declared outside the region that uses the counter: its C function reads a
|
|
32
|
+
// counter that does not exist (KIELER's Code Effects come before For and put the method in the state
|
|
33
|
+
// around the region).
|
|
34
|
+
const method = !nested && !outside && methodUses(ctx.root, r, counter);
|
|
35
|
+
if (method) {
|
|
36
|
+
crashed = true;
|
|
37
|
+
ctx.report({
|
|
38
|
+
severity: 'error', code: 'for-counter-method', related: [r.origin, method.decl].filter((x) => !!x),
|
|
39
|
+
span: method.method?.span,
|
|
40
|
+
message: `The counter \`${counter.name}\` is used in a code block or method of the for-region's state, where it does not exist`,
|
|
41
|
+
kieler: `‘TickData’ has no member named ‘${counter.name}’\nCompiler did not return success (exit value != 0)`,
|
|
42
|
+
hint: `KIELER turns a code block on a transition into a method of the state around the region before it copies the for-region, so the method sees no \`${counter.name}\`. Write the effects without braces (\`s += ${counter.name} * 10\`), or pass \`${counter.name}\` to a method as an argument.`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (nested || outside) {
|
|
46
|
+
crashed = true;
|
|
47
|
+
ctx.report({
|
|
48
|
+
severity: 'error', code: 'kieler-crash', related: r.origin ? [r.origin] : undefined,
|
|
49
|
+
message: nested
|
|
50
|
+
? 'KIELER cannot compile a for-region inside another for-region'
|
|
51
|
+
: `KIELER cannot compile this for-region: a declaration of the region uses its counter \`${counter.name}\``,
|
|
52
|
+
kieler: 'java.lang.IllegalArgumentException: Can\'t copy valued object. Valued object is null!',
|
|
53
|
+
hint: nested
|
|
54
|
+
? 'Its compiler crashes while copying the inner for-region. Write the inner copies out by hand, or use one for-region over all combinations (`for k : 0 to 5` with `k / 3` and `k % 3`).'
|
|
55
|
+
: `KIELER moves the region's declarations to the state around it before making the copies, so their initial values cannot see \`${counter.name}\`. Declare the variable in a state inside the region, or assign it on a transition (\`${counter.name}\` itself is a constant in each copy).`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (crashed)
|
|
60
|
+
return;
|
|
61
|
+
const copies = (ctx.shared.forCopies ??= []);
|
|
62
|
+
for (const r of regions) {
|
|
63
|
+
const values = range(r);
|
|
64
|
+
if (r.origin)
|
|
65
|
+
copies.push({ region: r.origin, values, counter: r.ext.forCounter.name, name: r.name });
|
|
66
|
+
expand(ctx, r, values);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/** Is `inner` (a region) inside `outer` (a region)? */
|
|
71
|
+
function inside(outer, inner) {
|
|
72
|
+
for (let s = inner.parent; s; s = up(s))
|
|
73
|
+
if (s === outer)
|
|
74
|
+
return true;
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
function up(s) {
|
|
78
|
+
return isRegion(s) ? s.parent : s.parent;
|
|
79
|
+
}
|
|
80
|
+
/** Is the counter referenced anywhere but inside its region (a declaration Region Actions moved out)? */
|
|
81
|
+
/** A method declared outside the region whose body uses the counter. */
|
|
82
|
+
function methodUses(root, region, counter) {
|
|
83
|
+
const within = new Set([region, ...allContainedStates(region).flatMap(s => [s, ...s.regions])]);
|
|
84
|
+
for (const scope of allScopes(root)) {
|
|
85
|
+
if (within.has(scope))
|
|
86
|
+
continue;
|
|
87
|
+
for (const v of scope.decls) {
|
|
88
|
+
if (!v.method)
|
|
89
|
+
continue;
|
|
90
|
+
let found = false;
|
|
91
|
+
const probe = (r) => { if (r.v === counter)
|
|
92
|
+
found = true; return undefined; };
|
|
93
|
+
rewriteStatements(v.method.body, { read: probe, target: probe });
|
|
94
|
+
if (found)
|
|
95
|
+
return v;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
function usesOutside(root, region, counter) {
|
|
101
|
+
const within = new Set([region, ...allContainedStates(region).flatMap(s => [s, ...s.regions])]);
|
|
102
|
+
let found = false;
|
|
103
|
+
for (const scope of allScopes(root)) {
|
|
104
|
+
if (within.has(scope))
|
|
105
|
+
continue;
|
|
106
|
+
usesIn(scope, counter, () => { found = true; });
|
|
107
|
+
}
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
/** Calls `hit` for every use of `v` in a scope's own declarations, actions and (for states) outgoing transitions. */
|
|
111
|
+
function usesIn(scope, v, hit) {
|
|
112
|
+
const visit = (e) => {
|
|
113
|
+
if (!e)
|
|
114
|
+
return;
|
|
115
|
+
if (e.k === 'ref') {
|
|
116
|
+
if (e.v === v)
|
|
117
|
+
hit();
|
|
118
|
+
e.idx.forEach(visit);
|
|
119
|
+
}
|
|
120
|
+
else if (e.k === 'op')
|
|
121
|
+
e.args.forEach(visit);
|
|
122
|
+
else if (e.k === 'vector')
|
|
123
|
+
e.values.forEach(visit);
|
|
124
|
+
else if (e.k === 'call')
|
|
125
|
+
e.args.forEach(visit);
|
|
126
|
+
};
|
|
127
|
+
for (const d of scope.decls) {
|
|
128
|
+
visit(d.init);
|
|
129
|
+
d.dims.forEach(visit);
|
|
130
|
+
}
|
|
131
|
+
for (const a of scope.actions) {
|
|
132
|
+
visit(a.trigger);
|
|
133
|
+
for (const f of a.effects)
|
|
134
|
+
if (f.k === 'assign') {
|
|
135
|
+
visit(f.ref);
|
|
136
|
+
visit(f.expr);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!isRegion(scope)) {
|
|
140
|
+
for (const t of scope.out) {
|
|
141
|
+
visit(t.trigger);
|
|
142
|
+
for (const f of t.effects)
|
|
143
|
+
if (f.k === 'assign') {
|
|
144
|
+
visit(f.ref);
|
|
145
|
+
visit(f.expr);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** The counter values of a for-region (KIELER's getForRegionRange). */
|
|
151
|
+
function range(r) {
|
|
152
|
+
const from = r.ext.forFrom;
|
|
153
|
+
const to = r.ext.forTo;
|
|
154
|
+
let first = 0;
|
|
155
|
+
let last = -1;
|
|
156
|
+
if (from?.k === 'lit' && typeof from.v === 'number' && to?.k === 'lit' && typeof to.v === 'number') {
|
|
157
|
+
first = from.v;
|
|
158
|
+
last = to.v;
|
|
159
|
+
}
|
|
160
|
+
else if (from?.k === 'ref') {
|
|
161
|
+
const size = from.v.dims[0];
|
|
162
|
+
if (size?.k === 'lit' && typeof size.v === 'number')
|
|
163
|
+
last = size.v - 1;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
// Xtend's first..second counts down when first > second.
|
|
169
|
+
const out = [];
|
|
170
|
+
if (first <= last)
|
|
171
|
+
for (let i = first; i <= last; i++)
|
|
172
|
+
out.push(i);
|
|
173
|
+
else
|
|
174
|
+
for (let i = first; i >= last; i--)
|
|
175
|
+
out.push(i);
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** Marks the log note that says which copy of a for-region a transition fired in (describe.ts). */
|
|
179
|
+
export const FOR_COPY_NOTE = '#for-copy';
|
|
180
|
+
/** The tracker key of a for-region copy: appended to the ids of everything inside it. */
|
|
181
|
+
export function copyKey(region, value) {
|
|
182
|
+
return `|${region}=${value}`;
|
|
183
|
+
}
|
|
184
|
+
function expand(ctx, region, values) {
|
|
185
|
+
const counter = region.ext.forCounter;
|
|
186
|
+
const parent = region.parent;
|
|
187
|
+
for (const value of values) {
|
|
188
|
+
const copy = copyRegion(region);
|
|
189
|
+
delete copy.ext.forCounter;
|
|
190
|
+
delete copy.ext.forFrom;
|
|
191
|
+
delete copy.ext.forTo;
|
|
192
|
+
delete copy.ext.forLoop;
|
|
193
|
+
const literal = (span) => ({ k: 'lit', t: 'int', v: value, span });
|
|
194
|
+
// Const: the counter is replaced by its value; assigning it fails.
|
|
195
|
+
for (const s of allContainedStates(copy)) {
|
|
196
|
+
for (const f of [...s.out.flatMap(t => t.effects), ...[s, ...s.regions].flatMap(x => x.actions).flatMap(a => a.effects)]) {
|
|
197
|
+
if (f.k === 'assign' && f.ref.v === counter) {
|
|
198
|
+
ctx.report({
|
|
199
|
+
severity: 'error', code: 'for-counter-assignment', span: f.o.span, related: f.o.by ? [f.o.by] : undefined,
|
|
200
|
+
message: `The counter \`${counter.name}\` of a for-region cannot be assigned: it is a constant in each copy (here ${value})`,
|
|
201
|
+
kieler: `Cannot replace left hand side of assignment by a value. (Trying to replace ${counter.name} by ${value} in ${printEffect(f)})`,
|
|
202
|
+
hint: `Use a variable of your own for values that change: \`int k = ${counter.name}\` in a state of the region, then assign \`k\`.`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// The copy's own variables (its states' declarations), for tracing each copy's value (traceableVariables).
|
|
208
|
+
for (const s of allContainedStates(copy))
|
|
209
|
+
for (const scope of [s, ...s.regions])
|
|
210
|
+
for (const v of scope.decls)
|
|
211
|
+
v.forCopy = { region: region.origin ?? '', counter: counter.name, value };
|
|
212
|
+
rewriteScope(copy, { read: r => (r.v === counter ? literal(r.span) : undefined) });
|
|
213
|
+
// Const folds the constant expressions of the scope that declares the constant (the copy).
|
|
214
|
+
rewriteScope(copy, { node: e => (e.k === 'op' ? foldConstants(e) : undefined) });
|
|
215
|
+
// The copies share the original's taken counters; the tracker tells them apart.
|
|
216
|
+
const key = copyKey(region.origin ?? '', value);
|
|
217
|
+
for (const s of allContainedStates(copy)) {
|
|
218
|
+
for (const t of s.out) {
|
|
219
|
+
for (const f of t.effects) {
|
|
220
|
+
if (f.k === 'mark' && f.m.kind === 'take')
|
|
221
|
+
f.m = { ...f.m, key: (f.m.key ?? f.m.transition) + key };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
copy.parent = parent;
|
|
226
|
+
parent.regions.push(copy);
|
|
227
|
+
}
|
|
228
|
+
parent.regions.splice(parent.regions.indexOf(region), 1);
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=forRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forRegion.js","sourceRoot":"","sources":["../../../src/sim/passes/forRegion.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,EAAE;AACF,sHAAsH;AACtH,iHAAiH;AACjH,mHAAmH;AACnH,kHAAkH;AAClH,8GAA8G;AAC9G,+EAA+E;AAC/E,EAAE;AACF,mHAAmH;AACnH,kHAAkH;AAClH,mFAAmF;AAInF,OAAO,EACH,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,GAClE,oBAAgB;AACjB,OAAO,EAAE,aAAa,EAAE,mBAAe;AACvC,OAAO,EAAE,UAAU,EAAE,6BAAyB;AAC9C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,gCAA4B;AAEtE,MAAM,CAAC,MAAM,SAAS,GAAS;IAC3B,EAAE,EAAE,0CAA0C;IAC9C,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,WAAW;IAClB,GAAG,CAAC,GAAgB;QAChB,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAA;QACvG,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAM;QAC3B,iGAAiG;QACjG,IAAI,O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AAE,CAAC;gBACpB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;oBACxB,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM;wBAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,GAAG,EAAE,CAAA;gBACvG,CAAC;YACL,CAAC;QACL,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["// KIELER's For processor (sccharts/processors/For.xtend). Owner: the structure workstream. structure.md S-21 .. S-24.\n//\n// `region R for i : a to b` (int literals; counting down when a > b) and `region R for i : A` (0 to the array's first\n// size - 1) become one copy of the region per counter value, appended after the state's other regions in counter\n// order (S-22); the original goes. In each copy the counter is a constant: KIELER declares `const int i = <value>`\n// in the copy, and its Const processor replaces every use by the value and folds the copy's constant expressions.\n// Copies keep their transitions' Taken Transition Signaling marks, so all copies share the original's counter\n// (S-23); the marks get a `key` per copy for the tracker (structure/track.ts).\n//\n// What KIELER cannot compile (S-24): a for-region inside another for-region, and a declaration of the region whose\n// initial value uses the counter (Region Actions has moved it out of the region, so the copies lose the counter):\n// both crash in KIELER's SCG transformation; assigning the counter fails in Const.\n\nimport type { ForCopies } from '../../types'\nimport type { Pass, PassContext } from './context'\nimport {\n allContainedStates, allScopes, allStates, isRegion, printEffect, type CExpr, type CRef, type CRegion, type CState, type CVar, type Scope,\n} from '../model'\nimport { foldConstants } from '../fold'\nimport { copyRegion } from '../structure/copy'\nimport { rewriteScope, rewriteStatements } from '../structure/rewrite'\n\nexport const forRegion: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.for',\n name: 'For',\n owner: 'structure',\n run(ctx: PassContext) {\n const regions = allStates(ctx.root).flatMap(s => s.regions.filter(r => r.ext.forCounter !== undefined))\n if (!regions.length) return\n // Nested for-regions and counters used outside their region crash KIELER: reject before copying.\n let crashed = false\n for (const r of regions) {\n const counter = r.ext.forCounter as CVar\n const nested = regions.some(o => o !== r && inside(r, o))\n const outside = usesOutside(ctx.root, r, counter)\n // A code effect (or method) declared outside the region that uses the counter: its C function reads a\n // counter that does not exist (KIELER's Code Effects come before For and put the method in the state\n // around the region).\n const method = !nested && !outside && methodUses(ctx.root, r, counter)\n if (method) {\n crashed = true\n ctx.report({\n severity: 'error', code: 'for-counter-method', related: [r.origin, method.decl].filter((x): x is string => !!x),\n span: method.method?.span,\n message: `The counter \\`${counter.name}\\` is used in a code block or method of the for-region's state, where it does not exist`,\n kieler: `‘TickData’ has no member named ‘${counter.name}’\\nCompiler did not return success (exit value != 0)`,\n hint: `KIELER turns a code block on a transition into a method of the state around the region before it copies the for-region, so the method sees no \\`${counter.name}\\`. Write the effects without braces (\\`s += ${counter.name} * 10\\`), or pass \\`${counter.name}\\` to a method as an argument.`,\n })\n }\n if (nested || outside) {\n crashed = true\n ctx.report({\n severity: 'error', code: 'kieler-crash', related: r.origin ? [r.origin] : undefined,\n message: nested\n ? 'KIELER cannot compile a for-region inside another for-region'\n : `KIELER cannot compile this for-region: a declaration of the region uses its counter \\`${counter.name}\\``,\n kieler: 'java.lang.IllegalArgumentException: Can\\'t copy valued object. Valued object is null!',\n hint: nested\n ? 'Its compiler crashes while copying the inner for-region. Write the inner copies out by hand, or use one for-region over all combinations (`for k : 0 to 5` with `k / 3` and `k % 3`).'\n : `KIELER moves the region's declarations to the state around it before making the copies, so their initial values cannot see \\`${counter.name}\\`. Declare the variable in a state inside the region, or assign it on a transition (\\`${counter.name}\\` itself is a constant in each copy).`,\n })\n }\n }\n if (crashed) return\n const copies = (ctx.shared.forCopies ??= []) as ForCopies[]\n for (const r of regions) {\n const values = range(r)\n if (r.origin) copies.push({ region: r.origin, values, counter: (r.ext.forCounter as CVar).name, name: r.name })\n expand(ctx, r, values)\n }\n },\n}\n\n/** Is `inner` (a region) inside `outer` (a region)? */\nfunction inside(outer: CRegion, inner: CRegion): boolean {\n for (let s: Scope | undefined = inner.parent; s; s = up(s)) if (s === outer) return true\n return false\n}\n\nfunction up(s: Scope): Scope | undefined {\n return isRegion(s) ? s.parent : s.parent\n}\n\n/** Is the counter referenced anywhere but inside its region (a declaration Region Actions moved out)? */\n/** A method declared outside the region whose body uses the counter. */\nfunction methodUses(root: CState, region: CRegion, counter: CVar): CVar | undefined {\n const within = new Set<Scope>([region, ...allContainedStates(region).flatMap(s => [s, ...s.regions])])\n for (const scope of allScopes(root)) {\n if (within.has(scope)) continue\n for (const v of scope.decls) {\n if (!v.method) continue\n let found = false\n const probe = (r: CRef) => { if (r.v === counter) found = true; return undefined }\n rewriteStatements(v.method.body, { read: probe, target: probe })\n if (found) return v\n }\n }\n return undefined\n}\n\nfunction usesOutside(root: CState, region: CRegion, counter: CVar): boolean {\n const within = new Set<Scope>([region, ...allContainedStates(region).flatMap(s => [s, ...s.regions])])\n let found = false\n for (const scope of allScopes(root)) {\n if (within.has(scope)) continue\n usesIn(scope, counter, () => { found = true })\n }\n return found\n}\n\n/** Calls `hit` for every use of `v` in a scope's own declarations, actions and (for states) outgoing transitions. */\nfunction usesIn(scope: Scope, v: CVar, hit: () => void) {\n const visit = (e: CExpr | undefined) => {\n if (!e) return\n if (e.k === 'ref') { if (e.v === v) hit(); e.idx.forEach(visit) }\n else if (e.k === 'op') e.args.forEach(visit)\n else if (e.k === 'vector') e.values.forEach(visit)\n else if (e.k === 'call') e.args.forEach(visit)\n }\n for (const d of scope.decls) { visit(d.init); d.dims.forEach(visit) }\n for (const a of scope.actions) {\n visit(a.trigger)\n for (const f of a.effects) if (f.k === 'assign') { visit(f.ref); visit(f.expr) }\n }\n if (!isRegion(scope)) {\n for (const t of scope.out) {\n visit(t.trigger)\n for (const f of t.effects) if (f.k === 'assign') { visit(f.ref); visit(f.expr) }\n }\n }\n}\n\n/** The counter values of a for-region (KIELER's getForRegionRange). */\nfunction range(r: CRegion): number[] {\n const from = r.ext.forFrom as CExpr | undefined\n const to = r.ext.forTo as CExpr | undefined\n let first = 0\n let last = -1\n if (from?.k === 'lit' && typeof from.v === 'number' && to?.k === 'lit' && typeof to.v === 'number') {\n first = from.v\n last = to.v\n } else if (from?.k === 'ref') {\n const size = from.v.dims[0]\n if (size?.k === 'lit' && typeof size.v === 'number') last = size.v - 1\n } else {\n return []\n }\n // Xtend's first..second counts down when first > second.\n const out: number[] = []\n if (first <= last) for (let i = first; i <= last; i++) out.push(i)\n else for (let i = first; i >= last; i--) out.push(i)\n return out\n}\n\n/** The counter values a source for-region was copied for (the tracker's view of the copies, structure/track.ts). */\nexport type { ForCopies }\n\n/** Marks the log note that says which copy of a for-region a transition fired in (describe.ts). */\nexport const FOR_COPY_NOTE = '#for-copy'\n\n/** The tracker key of a for-region copy: appended to the ids of everything inside it. */\nexport function copyKey(region: string, value: number): string {\n return `|${region}=${value}`\n}\n\nfunction expand(ctx: PassContext, region: CRegion, values: number[]) {\n const counter = region.ext.forCounter as CVar\n const parent = region.parent\n for (const value of values) {\n const copy = copyRegion(region)\n delete copy.ext.forCounter\n delete copy.ext.forFrom\n delete copy.ext.forTo\n delete copy.ext.forLoop\n const literal = (span?: CRef['span']): CExpr => ({ k: 'lit', t: 'int', v: value, span })\n // Const: the counter is replaced by its value; assigning it fails.\n for (const s of allContainedStates(copy)) {\n for (const f of [...s.out.flatMap(t => t.effects), ...[s, ...s.regions].flatMap(x => x.actions).flatMap(a => a.effects)]) {\n if (f.k === 'assign' && f.ref.v === counter) {\n ctx.report({\n severity: 'error', code: 'for-counter-assignment', span: f.o.span, related: f.o.by ? [f.o.by] : undefined,\n message: `The counter \\`${counter.name}\\` of a for-region cannot be assigned: it is a constant in each copy (here ${value})`,\n kieler: `Cannot replace left hand side of assignment by a value. (Trying to replace ${counter.name} by ${value} in ${printEffect(f)})`,\n hint: `Use a variable of your own for values that change: \\`int k = ${counter.name}\\` in a state of the region, then assign \\`k\\`.`,\n })\n }\n }\n }\n // The copy's own variables (its states' declarations), for tracing each copy's value (traceableVariables).\n for (const s of allContainedStates(copy)) for (const scope of [s, ...s.regions]) for (const v of scope.decls) v.forCopy = { region: region.origin ?? '', counter: counter.name, value }\n rewriteScope(copy, { read: r => (r.v === counter ? literal(r.span) as never : undefined) })\n // Const folds the constant expressions of the scope that declares the constant (the copy).\n rewriteScope(copy, { node: e => (e.k === 'op' ? foldConstants(e) : undefined) })\n // The copies share the original's taken counters; the tracker tells them apart.\n const key = copyKey(region.origin ?? '', value)\n for (const s of allContainedStates(copy)) {\n for (const t of s.out) {\n for (const f of t.effects) {\n if (f.k === 'mark' && f.m.kind === 'take') f.m = { ...f.m, key: (f.m.key ?? f.m.transition) + key }\n }\n }\n }\n copy.parent = parent\n parent.regions.push(copy)\n }\n parent.regions.splice(parent.regions.indexOf(region), 1)\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Pass } from "./context.js";
|
|
2
|
+
import { type CVar } from "../model.js";
|
|
3
|
+
export declare const history: Pass;
|
|
4
|
+
/**
|
|
5
|
+
* KIELER's record of a source region (root.ext.historyRecords, by region id): the variable and the source state
|
|
6
|
+
* each of its values resumes. The tracker reads it, so the source-level configuration resumes exactly what KIELER
|
|
7
|
+
* resumes (a deferred entry, for example, does not update the record: Deferred removes the entry action).
|
|
8
|
+
*/
|
|
9
|
+
export interface HistoryRecord {
|
|
10
|
+
v: CVar;
|
|
11
|
+
states: (string | undefined)[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// KIELER's History processor (sccharts/processors/History.xtend), the first processor of the extended chain: a
|
|
2
|
+
// state M that is the target of a `history` (deep) or `shallow history` transition gets one int `_HM` per region
|
|
3
|
+
// (declared in the root, initially 0); every state of the region gets `entry do _HM = k` (k = 0 for the original
|
|
4
|
+
// initial state, then the others in order), and a new initial state `_HInit` dispatches with
|
|
5
|
+
// `immediate if _HM == k go to S_k`. Non-history transitions into M reset the records, shallow ones also reset the
|
|
6
|
+
// records of the states nested in M (preemption.md P-47..P-52).
|
|
7
|
+
//
|
|
8
|
+
// KIELER only looks at the states of the top-level regions, and recurses only into states that are history
|
|
9
|
+
// targets themselves (the dispatch of a deep history counts as a history transition into each inner state).
|
|
10
|
+
// Every other history transition is silently a normal one (P-51): reproduced, with a kieler-quirk info, and the
|
|
11
|
+
// tracker is told (the take mark's `history`).
|
|
12
|
+
//
|
|
13
|
+
// History is also the first preemption pass, so it runs the static checks for the preemption quirks (quirks.ts)
|
|
14
|
+
// on the chart before anything is rewritten.
|
|
15
|
+
import { takeMarks } from "./contained.js";
|
|
16
|
+
import { preemptionQuirks } from "./quirks.js";
|
|
17
|
+
import { allTransitions, assign, controlflowRegions, controlflowRegionsContainStates, createEntryAction, createImmediateTransitionTo, createInitialState, createVar, initialState, lit, op, ref, } from "../model.js";
|
|
18
|
+
export const history = {
|
|
19
|
+
id: 'de.cau.cs.kieler.sccharts.processors.history',
|
|
20
|
+
name: 'History',
|
|
21
|
+
owner: 'preemption',
|
|
22
|
+
run(ctx) {
|
|
23
|
+
preemptionQuirks(ctx);
|
|
24
|
+
const written = allTransitions(ctx.root).filter(isHistory);
|
|
25
|
+
const effective = new Map();
|
|
26
|
+
for (const t of written)
|
|
27
|
+
effective.set(t, t.history);
|
|
28
|
+
const processed = new Set();
|
|
29
|
+
const root = ctx.root;
|
|
30
|
+
for (const region of controlflowRegions(root)) {
|
|
31
|
+
for (const state of [...region.states])
|
|
32
|
+
transformHistory(state, root, processed);
|
|
33
|
+
}
|
|
34
|
+
for (const t of written) {
|
|
35
|
+
const kind = effective.get(t);
|
|
36
|
+
for (const m of takeMarks(t))
|
|
37
|
+
m.history = processed.has(t) ? kind : 'reset';
|
|
38
|
+
// History into a state without inner states changes nothing.
|
|
39
|
+
if (processed.has(t) || !controlflowRegionsContainStates(t.target))
|
|
40
|
+
continue;
|
|
41
|
+
ctx.report({
|
|
42
|
+
severity: 'info', code: 'kieler-quirk', span: t.span, related: [t.origin, t.target.origin].filter((x) => !!x),
|
|
43
|
+
message: `KIELER ignores this ${kind === 'shallow' ? 'shallow history' : 'history'}: \`${t.target.name}\` restarts from its initial state${controlflowRegions(t.target).length > 1 ? 's' : ''}`,
|
|
44
|
+
hint: `KIELER only handles history on transitions into states of the chart's top-level regions, or inside a state that is itself the target of a history transition. Here \`${t.target.name}\` is nested in a state without one, so this transition behaves like a normal transition. Move the mode switch to the top level, or give the enclosing state a history transition too.`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const isHistory = (t) => t.history === 'shallow' || t.history === 'deep';
|
|
50
|
+
/** History.transformHistory: returns the records of `state` and of the states nested in it. */
|
|
51
|
+
function transformHistory(state, root, processed) {
|
|
52
|
+
const historyTransitions = state.incoming.filter(isHistory);
|
|
53
|
+
const nonHistoryTransitions = state.incoming.filter(t => !isHistory(t));
|
|
54
|
+
if (!historyTransitions.length)
|
|
55
|
+
return [];
|
|
56
|
+
const about = state.origin ?? state.about;
|
|
57
|
+
const regions = controlflowRegions(state);
|
|
58
|
+
const records = new Map();
|
|
59
|
+
for (const r of regions) {
|
|
60
|
+
const v = createVar(root, '_H' + state.name, 'int', 'history');
|
|
61
|
+
v.display = `the history of \`${state.name}\``;
|
|
62
|
+
v.init = lit(0);
|
|
63
|
+
records.set(r, v);
|
|
64
|
+
}
|
|
65
|
+
const tracked = root.ext.historyRecords ?? new Map();
|
|
66
|
+
root.ext.historyRecords = tracked;
|
|
67
|
+
// Entering without history forgets the record.
|
|
68
|
+
for (const t of nonHistoryTransitions) {
|
|
69
|
+
for (const v of records.values())
|
|
70
|
+
t.effects.push(assign(v, lit(0), { hidden: true, by: about }));
|
|
71
|
+
}
|
|
72
|
+
const deep = historyTransitions.some(t => t.history === 'deep');
|
|
73
|
+
for (const r of regions) {
|
|
74
|
+
const v = records.get(r);
|
|
75
|
+
const original = initialState(r);
|
|
76
|
+
if (!original)
|
|
77
|
+
continue;
|
|
78
|
+
original.initial = false;
|
|
79
|
+
const states = [original, ...r.states.filter(s => s !== original)];
|
|
80
|
+
if (r.origin)
|
|
81
|
+
tracked.set(r.origin, { v, states: states.map(s => s.origin) });
|
|
82
|
+
const dispatcher = createInitialState(r, '_HInit');
|
|
83
|
+
dispatcher.about = about;
|
|
84
|
+
states.forEach((s, k) => dispatch(dispatcher, s, v, k, deep, about));
|
|
85
|
+
}
|
|
86
|
+
const nested = new Set();
|
|
87
|
+
for (const r of regions) {
|
|
88
|
+
for (const sub of [...r.states])
|
|
89
|
+
for (const v of transformHistory(sub, root, processed))
|
|
90
|
+
nested.add(v);
|
|
91
|
+
}
|
|
92
|
+
for (const v of nested) {
|
|
93
|
+
for (const t of nonHistoryTransitions)
|
|
94
|
+
t.effects.push(assign(v, lit(0), { hidden: true, by: about }));
|
|
95
|
+
for (const t of historyTransitions.filter(t => t.history !== 'deep'))
|
|
96
|
+
t.effects.push(assign(v, lit(0), { hidden: true, by: about }));
|
|
97
|
+
}
|
|
98
|
+
for (const t of historyTransitions) {
|
|
99
|
+
processed.add(t);
|
|
100
|
+
t.history = 'reset';
|
|
101
|
+
}
|
|
102
|
+
return [...records.values(), ...nested];
|
|
103
|
+
}
|
|
104
|
+
/** History.createDispatchingTransition. */
|
|
105
|
+
function dispatch(dispatcher, target, record, k, deep, about) {
|
|
106
|
+
const t = createImmediateTransitionTo(dispatcher, target);
|
|
107
|
+
t.about = about;
|
|
108
|
+
t.trigger = op('==', ref(record), lit(k));
|
|
109
|
+
const entry = createEntryAction(target);
|
|
110
|
+
entry.about = about;
|
|
111
|
+
entry.effects.push(assign(record, lit(k), { hidden: true, by: about }));
|
|
112
|
+
if (deep)
|
|
113
|
+
t.history = 'deep';
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../../src/sim/passes/history.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,iHAAiH;AACjH,iHAAiH;AACjH,6FAA6F;AAC7F,mHAAmH;AACnH,gEAAgE;AAChE,EAAE;AACF,2GAA2G;AAC3G,4GAA4G;AAC5G,gHAAgH;AAChH,+CAA+C;AAC/C,EAAE;AACF,gHAAgH;AAChH,6CAA6C;AAG7C,OAAO,EAAE,SAAS,EAAE,uBAAmB;AACvC,OAAO,EAAE,gBAAgB,EAAE,oBAAgB;AAC3C,OAAO,EACH,cAAc,EAAE,MAAM,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,kBAAkB,EAC/I,SAAS,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GACxC,oBAAgB;AAEjB,MAAM,CAAC,MAAM,OAAO,GAAS;IACzB,EAAE,EAAE,8CAA8C;IAClD,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,YAAY;IACnB,GAAG,CAAC,GAAgB;QAChB,gBAAgB,CAAC,GAAG,CAAC,CAAA;QACrB,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAC1D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmC,CAAA;QAC5D,KAAK,MAAM,CAAC,IAAI,OAAO;YAAE,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,OAA6B,CAAC,CAAA;QAC1E,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAA;QACxC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACrB,KAAK,MAAM,MAAM,IAAI,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KAAyB;IACnH,MAAM,CAAC,GAAG,2BAA2B,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IACzD,CAAC,CAAC,KAAK,GAAG,KAAK,CAAA;IACf,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAA;IACvC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IACnB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IACvE,IAAI,IAAI;QAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAAA;AAChC,CAAC","sourcesContent":["// KIELER's History processor (sccharts/processors/History.xtend), the first processor of the extended chain: a\n// state M that is the target of a `history` (deep) or `shallow history` transition gets one int `_HM` per region\n// (declared in the root, initially 0); every state of the region gets `entry do _HM = k` (k = 0 for the original\n// initial state, then the others in order), and a new initial state `_HInit` dispatches with\n// `immediate if _HM == k go to S_k`. Non-history transitions into M reset the records, shallow ones also reset the\n// records of the states nested in M (preemption.md P-47..P-52).\n//\n// KIELER only looks at the states of the top-level regions, and recurses only into states that are history\n// targets themselves (the dispatch of a deep history counts as a history transition into each inner state).\n// Every other history transition is silently a normal one (P-51): reproduced, with a kieler-quirk info, and the\n// tracker is told (the take mark's `history`).\n//\n// History is also the first preemption pass, so it runs the static checks for the preemption quirks (quirks.ts)\n// on the chart before anything is rewritten.\n\nimport type { Pass, PassContext } from './context'\nimport { takeMarks } from './contained'\nimport { preemptionQuirks } from './quirks'\nimport {\n allTransitions, assign, controlflowRegions, controlflowRegionsContainStates, createEntryAction, createImmediateTransitionTo, createInitialState,\n createVar, initialState, lit, op, ref, type CRegion, type CState, type CTransition, type CVar,\n} from '../model'\n\nexport const history: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.history',\n name: 'History',\n owner: 'preemption',\n run(ctx: PassContext) {\n preemptionQuirks(ctx)\n const written = allTransitions(ctx.root).filter(isHistory)\n const effective = new Map<CTransition, 'shallow' | 'deep'>()\n for (const t of written) effective.set(t, t.history as 'shallow' | 'deep')\n const processed = new Set<CTransition>()\n const root = ctx.root\n for (const region of controlflowRegions(root)) {\n for (const state of [...region.states]) transformHistory(state, root, processed)\n }\n for (const t of written) {\n const kind = effective.get(t)!\n for (const m of takeMarks(t)) m.history = processed.has(t) ? kind : 'reset'\n // History into a state without inner states changes nothing.\n if (processed.has(t) || !controlflowRegionsContainStates(t.target)) continue\n ctx.report({\n severity: 'info', code: 'kieler-quirk', span: t.span, related: [t.origin, t.target.origin].filter((x): x is string => !!x),\n message: `KIELER ignores this ${kind === 'shallow' ? 'shallow history' : 'history'}: \\`${t.target.name}\\` restarts from its initial state${controlflowRegions(t.target).length > 1 ? 's' : ''}`,\n hint: `KIELER only handles history on transitions into states of the chart's top-level regions, or inside a state that is itself the target of a history transition. Here \\`${t.target.name}\\` is nested in a state without one, so this transition behaves like a normal transition. Move the mode switch to the top level, or give the enclosing state a history transition too.`,\n })\n }\n },\n}\n\nconst isHistory = (t: CTransition) => t.history === 'shallow' || t.history === 'deep'\n\n/** History.transformHistory: returns the records of `state` and of the states nested in it. */\nfunction transformHistory(state: CState, root: CState, processed: Set<CTransition>): CVar[] {\n const historyTransitions = state.incoming.filter(isHistory)\n const nonHistoryTransitions = state.incoming.filter(t => !isHistory(t))\n if (!historyTransitions.length) return []\n const about = state.origin ?? state.about\n\n const regions = controlflowRegions(state)\n const records = new Map<CRegion, CVar>()\n for (const r of regions) {\n const v = createVar(root, '_H' + state.name, 'int', 'history')\n v.display = `the history of \\`${state.name}\\``\n v.init = lit(0)\n records.set(r, v)\n }\n const tracked = (root.ext.historyRecords as Map<string, HistoryRecord> | undefined) ?? new Map<string, HistoryRecord>()\n root.ext.historyRecords = tracked\n // Entering without history forgets the record.\n for (const t of nonHistoryTransitions) {\n for (const v of records.values()) t.effects.push(assign(v, lit(0), { hidden: true, by: about }))\n }\n\n const deep = historyTransitions.some(t => t.history === 'deep')\n for (const r of regions) {\n const v = records.get(r)!\n const original = initialState(r)\n if (!original) continue\n original.initial = false\n const states = [original, ...r.states.filter(s => s !== original)]\n if (r.origin) tracked.set(r.origin, { v, states: states.map(s => s.origin) })\n const dispatcher = createInitialState(r, '_HInit')\n dispatcher.about = about\n states.forEach((s, k) => dispatch(dispatcher, s, v, k, deep, about))\n }\n\n const nested = new Set<CVar>()\n for (const r of regions) {\n for (const sub of [...r.states]) for (const v of transformHistory(sub, root, processed)) nested.add(v)\n }\n for (const v of nested) {\n for (const t of nonHistoryTransitions) t.effects.push(assign(v, lit(0), { hidden: true, by: about }))\n for (const t of historyTransitions.filter(t => t.history !== 'deep')) t.effects.push(assign(v, lit(0), { hidden: true, by: about }))\n }\n\n for (const t of historyTransitions) {\n processed.add(t)\n t.history = 'reset'\n }\n return [...records.values(), ...nested]\n}\n\n/**\n * KIELER's record of a source region (root.ext.historyRecords, by region id): the variable and the source state\n * each of its values resumes. The tracker reads it, so the source-level configuration resumes exactly what KIELER\n * resumes (a deferred entry, for example, does not update the record: Deferred removes the entry action).\n */\nexport interface HistoryRecord {\n v: CVar\n states: (string | undefined)[]\n}\n\n/** History.createDispatchingTransition. */\nfunction dispatch(dispatcher: CState, target: CState, record: CVar, k: number, deep: boolean, about: string | undefined) {\n const t = createImmediateTransitionTo(dispatcher, target)\n t.about = about\n t.trigger = op('==', ref(record), lit(k))\n const entry = createEntryAction(target)\n entry.about = about\n entry.effects.push(assign(record, lit(k), { hidden: true, by: about }))\n if (deep) t.history = 'deep'\n}\n"]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Host code and extern calls. Owner: the structure workstream. structure.md S-45 .. S-47.
|
|
2
|
+
//
|
|
3
|
+
// Not one of KIELER's SCCharts processors: host code (backticks), `extern` functions and `#hostcode` pragmas go
|
|
4
|
+
// straight into KIELER's generated C code, which the browser cannot compile or run. KIELER accepts such charts, so
|
|
5
|
+
// they stay accepted (`ok`), but the simulator reports that it cannot run them ('unsupported', info). Methods are
|
|
6
|
+
// run by the simulator (structure/methods.ts); a chart that calls a recursive one is rejected, as KIELER's dependency
|
|
7
|
+
// analysis never returns from it.
|
|
8
|
+
import { construct, declsOf } from "./detect.js";
|
|
9
|
+
import { allActionSites, effectExprs, walkExpr } from "../model.js";
|
|
10
|
+
function hostUses(root) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const v of declsOf(root)) {
|
|
13
|
+
if (v.extern)
|
|
14
|
+
out.push(construct('extern functions', v.span, v.decl));
|
|
15
|
+
if (v.method)
|
|
16
|
+
for (const s of stmts(v.method.body))
|
|
17
|
+
if (s.k === 'do' && s.f.k === 'host')
|
|
18
|
+
out.push(construct('host code', s.f.o.span, v.decl));
|
|
19
|
+
}
|
|
20
|
+
for (const site of allActionSites(root)) {
|
|
21
|
+
const holder = site.transition ?? site.action;
|
|
22
|
+
const by = holder.origin ?? holder.about;
|
|
23
|
+
const visit = (e) => {
|
|
24
|
+
if (e.k === 'call' && e.extern)
|
|
25
|
+
out.push(construct('extern function calls', e.span, by));
|
|
26
|
+
if (e.k === 'host')
|
|
27
|
+
out.push(construct('host code', e.span, by));
|
|
28
|
+
};
|
|
29
|
+
walkExpr(holder.trigger, visit);
|
|
30
|
+
for (const f of holder.effects) {
|
|
31
|
+
if (f.k === 'host')
|
|
32
|
+
out.push(construct('host code', f.o.span, by));
|
|
33
|
+
for (const e of effectExprs(f))
|
|
34
|
+
walkExpr(e, visit);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function* stmts(list) {
|
|
40
|
+
for (const s of list) {
|
|
41
|
+
yield s;
|
|
42
|
+
if (s.k === 'if') {
|
|
43
|
+
yield* stmts(s.then);
|
|
44
|
+
if (s.else)
|
|
45
|
+
yield* stmts(s.else);
|
|
46
|
+
}
|
|
47
|
+
if (s.k === 'while' || s.k === 'for') {
|
|
48
|
+
yield* stmts(s.body);
|
|
49
|
+
if (s.k === 'for') {
|
|
50
|
+
yield* stmts(s.init);
|
|
51
|
+
yield* stmts(s.update);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Methods that call themselves, directly or through others. */
|
|
57
|
+
function recursive(root) {
|
|
58
|
+
const methods = declsOf(root).filter(v => v.method);
|
|
59
|
+
const calls = (m) => {
|
|
60
|
+
const out = [];
|
|
61
|
+
const visit = (e) => { if (e.k === 'call' && e.target?.v.method)
|
|
62
|
+
out.push(e.target.v); };
|
|
63
|
+
for (const s of stmts(m.body)) {
|
|
64
|
+
if (s.k === 'do')
|
|
65
|
+
for (const e of effectExprs(s.f))
|
|
66
|
+
walkExpr(e, visit);
|
|
67
|
+
else if (s.k === 'if' || s.k === 'while')
|
|
68
|
+
walkExpr(s.cond, visit);
|
|
69
|
+
else if (s.k === 'for')
|
|
70
|
+
walkExpr(s.cond, visit);
|
|
71
|
+
else if (s.k === 'return' || s.k === 'expr')
|
|
72
|
+
walkExpr(s.k === 'return' ? s.expr : s.e, visit);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
};
|
|
76
|
+
return methods.filter(m => {
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const work = calls(m.method);
|
|
79
|
+
while (work.length) {
|
|
80
|
+
const x = work.pop();
|
|
81
|
+
if (x === m)
|
|
82
|
+
return true;
|
|
83
|
+
if (seen.has(x))
|
|
84
|
+
continue;
|
|
85
|
+
seen.add(x);
|
|
86
|
+
if (x.method)
|
|
87
|
+
work.push(...calls(x.method));
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** The methods the chart's triggers and effects call, directly or through other methods. */
|
|
93
|
+
function calledMethods(root) {
|
|
94
|
+
const out = new Set();
|
|
95
|
+
const work = [];
|
|
96
|
+
const visit = (e) => { if (e.k === 'call' && !e.extern && e.target?.v.method && !out.has(e.target.v)) {
|
|
97
|
+
out.add(e.target.v);
|
|
98
|
+
work.push(e.target.v);
|
|
99
|
+
} };
|
|
100
|
+
for (const site of allActionSites(root)) {
|
|
101
|
+
const holder = site.transition ?? site.action;
|
|
102
|
+
walkExpr(holder.trigger, visit);
|
|
103
|
+
for (const f of holder.effects)
|
|
104
|
+
for (const e of effectExprs(f))
|
|
105
|
+
walkExpr(e, visit);
|
|
106
|
+
}
|
|
107
|
+
while (work.length) {
|
|
108
|
+
const m = work.pop().method;
|
|
109
|
+
for (const s of stmts(m.body)) {
|
|
110
|
+
if (s.k === 'do')
|
|
111
|
+
for (const e of effectExprs(s.f))
|
|
112
|
+
walkExpr(e, visit);
|
|
113
|
+
else if (s.k === 'if' || s.k === 'while' || s.k === 'for')
|
|
114
|
+
walkExpr(s.cond, visit);
|
|
115
|
+
else if (s.k === 'return' || s.k === 'expr')
|
|
116
|
+
walkExpr(s.k === 'return' ? s.expr : s.e, visit);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
export const hostCode = {
|
|
122
|
+
id: 'de.cau.cs.kieler.scg.processors.methods',
|
|
123
|
+
name: 'Methods and host code',
|
|
124
|
+
owner: 'structure',
|
|
125
|
+
run(ctx) {
|
|
126
|
+
// KIELER's dependency analysis follows every call into the method it calls, without end for a recursive one
|
|
127
|
+
// (probes kieler/codegen/probe-recursive-*): a chart that calls one is rejected; one never called is harmless.
|
|
128
|
+
const called = calledMethods(ctx.root);
|
|
129
|
+
const loops = recursive(ctx.root).filter(m => called.has(m));
|
|
130
|
+
if (loops.length) {
|
|
131
|
+
ctx.report({
|
|
132
|
+
severity: 'error', code: 'kieler-crash', span: loops[0].span, related: loops.flatMap(v => (v.decl ? [v.decl] : [])),
|
|
133
|
+
message: `KIELER's compiler crashes on this chart: ${loops.map(v => `\`${v.name}\``).join(', ')} ${loops.length > 1 ? 'call' : 'calls'} ${loops.length > 1 ? 'each other or themselves' : 'itself'}`,
|
|
134
|
+
kieler: 'The compiler ran out of stack space during Dependency.',
|
|
135
|
+
hint: 'KIELER\'s dependency analysis follows each call into the method it calls, and for a recursive method it never stops. Write the method with a loop instead (`while` or `for`).',
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// The C code generator compiles such charts on: its C code carries the host code and calls C functions.
|
|
140
|
+
if (ctx.config.hostCode)
|
|
141
|
+
return;
|
|
142
|
+
const uses = hostUses(ctx.root);
|
|
143
|
+
if (uses.length) {
|
|
144
|
+
ctx.report({
|
|
145
|
+
severity: 'info', code: 'unsupported', span: uses[0].span, related: [...new Set(uses.flatMap(u => u.related ?? []))],
|
|
146
|
+
message: `This chart uses ${uses[0].what}, which cannot run in the browser`,
|
|
147
|
+
hint: 'KIELER pastes host code and extern calls into the C program it generates and compiles that with gcc, so whether it accepts the chart depends on that C text; the guide\'s simulator runs in your browser and has no C compiler. Its generated C runs it: download it from the playground\'s C code tab, or build it with SCCharts Lab for VS Code or KIELER.',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=hostCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostCode.js","sourceRoot":"","sources":["../../../src/sim/passes/hostCode.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,EAAE;AACF,gHAAgH;AAChH,mHAAmH;AACnH,kHAAkH;AAClH,sHAAsH;AACtH,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAgB;AAC7C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAgE,oBAAgB;AAG9H,SAAS,QAAQ,CAAC,IAAY;IAC1B,MAAM,GAAG,GAAgB,EAAE,CAAA;IAC3B,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,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;gBACpH,OAAO,EAAE,mBAAmB,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,mCAAmC;gBAC3E,IAAI,EAAE,8VAA8V;aACvW,CAAC,CAAA;QACN,CAAC;IACL,CAAC;CACJ,CAAA","sourcesContent":["// Host code and extern calls. Owner: the structure workstream. structure.md S-45 .. S-47.\n//\n// Not one of KIELER's SCCharts processors: host code (backticks), `extern` functions and `#hostcode` pragmas go\n// straight into KIELER's generated C code, which the browser cannot compile or run. KIELER accepts such charts, so\n// they stay accepted (`ok`), but the simulator reports that it cannot run them ('unsupported', info). Methods are\n// run by the simulator (structure/methods.ts); a chart that calls a recursive one is rejected, as KIELER's dependency\n// analysis never returns from it.\n\nimport type { Pass, PassContext } from './context'\nimport { construct, declsOf } from './detect'\nimport { allActionSites, effectExprs, walkExpr, type CExpr, type CMethod, type CState, type CStmt, type CVar } from '../model'\nimport type { Construct } from './context'\n\nfunction hostUses(root: CState): Construct[] {\n const out: Construct[] = []\n for (const v of declsOf(root)) {\n if (v.extern) out.push(construct('extern functions', v.span, v.decl))\n if (v.method) for (const s of stmts(v.method.body)) if (s.k === 'do' && s.f.k === 'host') out.push(construct('host code', s.f.o.span, v.decl))\n }\n for (const site of allActionSites(root)) {\n const holder = site.transition ?? site.action!\n const by = holder.origin ?? holder.about\n const visit = (e: CExpr) => {\n if (e.k === 'call' && e.extern) out.push(construct('extern function calls', e.span, by))\n if (e.k === 'host') out.push(construct('host code', e.span, by))\n }\n walkExpr(holder.trigger, visit)\n for (const f of holder.effects) {\n if (f.k === 'host') out.push(construct('host code', f.o.span, by))\n for (const e of effectExprs(f)) walkExpr(e, visit)\n }\n }\n return out\n}\n\nfunction* stmts(list: CStmt[]): Generator<CStmt> {\n for (const s of list) {\n yield s\n if (s.k === 'if') { yield* stmts(s.then); if (s.else) yield* stmts(s.else) }\n if (s.k === 'while' || s.k === 'for') { yield* stmts(s.body); if (s.k === 'for') { yield* stmts(s.init); yield* stmts(s.update) } }\n }\n}\n\n/** Methods that call themselves, directly or through others. */\nfunction recursive(root: CState): CVar[] {\n const methods = declsOf(root).filter(v => v.method)\n const calls = (m: CMethod): CVar[] => {\n const out: CVar[] = []\n const visit = (e: CExpr) => { if (e.k === 'call' && e.target?.v.method) out.push(e.target.v) }\n for (const s of stmts(m.body)) {\n if (s.k === 'do') for (const e of effectExprs(s.f)) walkExpr(e, visit)\n else if (s.k === 'if' || s.k === 'while') walkExpr(s.cond, visit)\n else if (s.k === 'for') walkExpr(s.cond, visit)\n else if (s.k === 'return' || s.k === 'expr') walkExpr(s.k === 'return' ? s.expr : s.e, visit)\n }\n return out\n }\n return methods.filter(m => {\n const seen = new Set<CVar>()\n const work = calls(m.method!)\n while (work.length) {\n const x = work.pop()!\n if (x === m) return true\n if (seen.has(x)) continue\n seen.add(x)\n if (x.method) work.push(...calls(x.method))\n }\n return false\n })\n}\n\n/** The methods the chart's triggers and effects call, directly or through other methods. */\nfunction calledMethods(root: CState): Set<CVar> {\n const out = new Set<CVar>()\n const work: CVar[] = []\n const visit = (e: CExpr) => { if (e.k === 'call' && !e.extern && e.target?.v.method && !out.has(e.target.v)) { out.add(e.target.v); work.push(e.target.v) } }\n for (const site of allActionSites(root)) {\n const holder = site.transition ?? site.action!\n walkExpr(holder.trigger, visit)\n for (const f of holder.effects) for (const e of effectExprs(f)) walkExpr(e, visit)\n }\n while (work.length) {\n const m = work.pop()!.method!\n for (const s of stmts(m.body)) {\n if (s.k === 'do') for (const e of effectExprs(s.f)) walkExpr(e, visit)\n else if (s.k === 'if' || s.k === 'while' || s.k === 'for') walkExpr(s.cond, visit)\n else if (s.k === 'return' || s.k === 'expr') walkExpr(s.k === 'return' ? s.expr : s.e, visit)\n }\n }\n return out\n}\n\nexport const hostCode: Pass = {\n id: 'de.cau.cs.kieler.scg.processors.methods',\n name: 'Methods and host code',\n owner: 'structure',\n run(ctx: PassContext) {\n // KIELER's dependency analysis follows every call into the method it calls, without end for a recursive one\n // (probes kieler/codegen/probe-recursive-*): a chart that calls one is rejected; one never called is harmless.\n const called = calledMethods(ctx.root)\n const loops = recursive(ctx.root).filter(m => called.has(m))\n if (loops.length) {\n ctx.report({\n severity: 'error', code: 'kieler-crash', span: loops[0].span, related: loops.flatMap(v => (v.decl ? [v.decl] : [])),\n message: `KIELER's compiler crashes on this chart: ${loops.map(v => `\\`${v.name}\\``).join(', ')} ${loops.length > 1 ? 'call' : 'calls'} ${loops.length > 1 ? 'each other or themselves' : 'itself'}`,\n kieler: 'The compiler ran out of stack space during Dependency.',\n hint: 'KIELER\\'s dependency analysis follows each call into the method it calls, and for a recursive method it never stops. Write the method with a loop instead (`while` or `for`).',\n })\n return\n }\n // The C code generator compiles such charts on: its C code carries the host code and calls C functions.\n if (ctx.config.hostCode) return\n const uses = hostUses(ctx.root)\n if (uses.length) {\n ctx.report({\n severity: 'info', code: 'unsupported', span: uses[0].span, related: [...new Set(uses.flatMap(u => u.related ?? []))],\n message: `This chart uses ${uses[0].what}, which cannot run in the browser`,\n hint: 'KIELER pastes host code and extern calls into the C program it generates and compiles that with gcc, so whether it accepts the chart depends on that C text; the guide\\'s simulator runs in your browser and has no C compiler. Its generated C runs it: download it from the playground\\'s C code tab, or build it with SCCharts Lab for VS Code or KIELER.',\n })\n }\n },\n}\n"]}
|