@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,106 @@
|
|
|
1
|
+
// KIELER's Period processor (sccharts/processors/Period.xtend). Owner: the structure workstream. structure.md S-42.
|
|
2
|
+
//
|
|
3
|
+
// `period v` on a state S: a clock `c` and a flag `tick` (initially false; true for `immediate period`) are declared
|
|
4
|
+
// in S, every action and transition of every state in S, S's own included (S-42a), gets the guard `tick && ...`,
|
|
5
|
+
// and S gets a region `Period` with two delayed self-loops on `_s`: `if c >= v do c -= v; tick = true` (soft reset,
|
|
6
|
+
// KIELER's default) or `do c = 0; tick = true` (`@HardReset`), and otherwise `do tick = false`. The clock is then
|
|
7
|
+
// an ordinary clock for the Timed Automata processor, which advances it by deltaT.
|
|
8
|
+
import { allStates, CVar, createControlflowRegion, createInitialState, createTransitionTo, isRegion, ref, } from "../model.js";
|
|
9
|
+
import { up } from "../structure/rewrite.js";
|
|
10
|
+
export const period = {
|
|
11
|
+
id: 'de.cau.cs.kieler.sccharts.processors.period',
|
|
12
|
+
name: 'Period',
|
|
13
|
+
owner: 'structure',
|
|
14
|
+
run(ctx) {
|
|
15
|
+
for (const state of allStates(ctx.root).filter(s => s.actions.some(a => a.kind === 'period')))
|
|
16
|
+
transform(state, ctx);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
/** Names used around the state (uniqueName when the generated names clash, as KIELER does). */
|
|
20
|
+
function clashes(state) {
|
|
21
|
+
for (let s = state; s; s = up(s)) {
|
|
22
|
+
if (!isRegion(s) && s !== state && s.actions.some(a => a.kind === 'period'))
|
|
23
|
+
return true;
|
|
24
|
+
if (s.decls.some(v => v.name === 'c' || v.name === 'tick'))
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function unique(state, base, clash) {
|
|
30
|
+
if (!clash)
|
|
31
|
+
return base;
|
|
32
|
+
const taken = new Set();
|
|
33
|
+
for (let s = state; s; s = up(s))
|
|
34
|
+
for (const v of s.decls)
|
|
35
|
+
taken.add(v.name);
|
|
36
|
+
let i = 1;
|
|
37
|
+
while (taken.has(`${base}_${i}`))
|
|
38
|
+
i++;
|
|
39
|
+
return `${base}_${i}`;
|
|
40
|
+
}
|
|
41
|
+
function transform(state, ctx) {
|
|
42
|
+
const periods = state.actions.filter(a => a.kind === 'period');
|
|
43
|
+
// S-42a: the guard also lands on the state's own transitions.
|
|
44
|
+
const strong = state.out.filter(t => t.preemption === 'strong');
|
|
45
|
+
if (strong.length) {
|
|
46
|
+
ctx.report({
|
|
47
|
+
severity: 'info', code: 'kieler-quirk', related: [state.origin ?? state.about, ...strong.map(t => t.origin)].filter((x) => !!x),
|
|
48
|
+
message: `\`${state.name}\` has a period, so KIELER also guards its own outgoing transitions with the period's tick: they can only fire in a tick after the period elapsed`,
|
|
49
|
+
hint: `KIELER adds the period's condition to every transition of every state inside, \`${state.name}\`'s own included. Put the period into an inner state and leave \`${state.name}\` with a normal transition instead.`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
state.actions = state.actions.filter(a => a.kind !== 'period');
|
|
53
|
+
const clash = clashes(state);
|
|
54
|
+
const several = periods.length > 1;
|
|
55
|
+
const about = (p) => p.origin ?? p.about;
|
|
56
|
+
const clocks = periods.map((p, i) => {
|
|
57
|
+
const v = new CVar(unique(state, several ? `c${i}` : 'c', clash), 'clock');
|
|
58
|
+
v.scope = state;
|
|
59
|
+
v.display = `the period's clock`;
|
|
60
|
+
v.decl = about(p);
|
|
61
|
+
return v;
|
|
62
|
+
});
|
|
63
|
+
state.decls.push(...clocks);
|
|
64
|
+
const ticks = periods.map((p, i) => {
|
|
65
|
+
const v = new CVar(unique(state, several ? `tick${i}` : 'tick', clash), 'bool');
|
|
66
|
+
v.scope = state;
|
|
67
|
+
v.display = `whether \`${state.name}\`'s period has elapsed`;
|
|
68
|
+
v.role = 'tick';
|
|
69
|
+
v.init = { k: 'lit', t: 'bool', v: p.delay === 'immediate' };
|
|
70
|
+
v.decl = about(p);
|
|
71
|
+
return v;
|
|
72
|
+
});
|
|
73
|
+
state.decls.push(...ticks);
|
|
74
|
+
// Guard every action and transition of every state inside, the state itself included.
|
|
75
|
+
for (const tick of ticks) {
|
|
76
|
+
const guard = (trigger) => (trigger ? { k: 'op', op: '&&', args: [ref(tick), trigger] } : ref(tick));
|
|
77
|
+
for (const s of allStates(state)) {
|
|
78
|
+
for (const a of s.actions)
|
|
79
|
+
a.trigger = guard(a.trigger);
|
|
80
|
+
for (const t of s.out)
|
|
81
|
+
t.trigger = guard(t.trigger);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
periods.forEach((p, i) => {
|
|
85
|
+
const clock = clocks[i];
|
|
86
|
+
const tick = ticks[i];
|
|
87
|
+
const hard = p.annotations.some(a => a.toLowerCase() === 'hardreset');
|
|
88
|
+
const threshold = p.trigger ?? { k: 'lit', t: 'int', v: 0 };
|
|
89
|
+
const region = createControlflowRegion(state, i > 0 ? `Period${i}` : 'Period');
|
|
90
|
+
region.about = about(p);
|
|
91
|
+
const s = createInitialState(region, '_s');
|
|
92
|
+
s.about = about(p);
|
|
93
|
+
const o = { by: about(p), hidden: true };
|
|
94
|
+
const elapsed = createTransitionTo(s, s);
|
|
95
|
+
elapsed.about = about(p);
|
|
96
|
+
elapsed.trigger = { k: 'op', op: '>=', args: [ref(clock), threshold] };
|
|
97
|
+
elapsed.effects.push(hard
|
|
98
|
+
? { k: 'assign', ref: ref(clock), op: '=', expr: { k: 'lit', t: 'int', v: 0 }, o }
|
|
99
|
+
: { k: 'assign', ref: ref(clock), op: '-=', expr: threshold, o });
|
|
100
|
+
elapsed.effects.push({ k: 'assign', ref: ref(tick), op: '=', expr: { k: 'lit', t: 'bool', v: true }, o });
|
|
101
|
+
const idle = createTransitionTo(s, s);
|
|
102
|
+
idle.about = about(p);
|
|
103
|
+
idle.effects.push({ k: 'assign', ref: ref(tick), op: '=', expr: { k: 'lit', t: 'bool', v: false }, o });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=period.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.js","sourceRoot":"","sources":["../../../src/sim/passes/period.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,EAAE;AACF,qHAAqH;AACrH,iHAAiH;AACjH,oHAAoH;AACpH,kHAAkH;AAClH,mFAAmF;AAGnF,OAAO,EACH,SAAS,EAAE,IAAI,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,GAElG,oBAAgB;AACjB,OAAO,EAAE,EAAE,EAAE,gCAA4B;AAEzC,MAAM,CAAC,MAAM,MAAM,GAAS;IACxB,EAAE,EAAE,6CAA6C;IACjD,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,WAAW;IAClB,GAAG,CAAC,GAAgB;QAChB,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;YAAE,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACxH,CAAC;CACJ,CAAA;AAED,+FAA+F;AAC/F,SAAS,OAAO,CAAC,KAA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AAI,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;IAC3G,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["// KIELER's Period processor (sccharts/processors/Period.xtend). Owner: the structure workstream. structure.md S-42.\n//\n// `period v` on a state S: a clock `c` and a flag `tick` (initially false; true for `immediate period`) are declared\n// in S, every action and transition of every state in S, S's own included (S-42a), gets the guard `tick && ...`,\n// and S gets a region `Period` with two delayed self-loops on `_s`: `if c >= v do c -= v; tick = true` (soft reset,\n// KIELER's default) or `do c = 0; tick = true` (`@HardReset`), and otherwise `do tick = false`. The clock is then\n// an ordinary clock for the Timed Automata processor, which advances it by deltaT.\n\nimport type { Pass, PassContext } from './context'\nimport {\n allStates, CVar, createControlflowRegion, createInitialState, createTransitionTo, isRegion, ref, type CAction,\n type CExpr, type CState, type Scope,\n} from '../model'\nimport { up } from '../structure/rewrite'\n\nexport const period: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.period',\n name: 'Period',\n owner: 'structure',\n run(ctx: PassContext) {\n for (const state of allStates(ctx.root).filter(s => s.actions.some(a => a.kind === 'period'))) transform(state, ctx)\n },\n}\n\n/** Names used around the state (uniqueName when the generated names clash, as KIELER does). */\nfunction clashes(state: CState): boolean {\n for (let s: Scope | undefined = state; s; s = up(s)) {\n if (!isRegion(s) && s !== state && s.actions.some(a => a.kind === 'period')) return true\n if (s.decls.some(v => v.name === 'c' || v.name === 'tick')) return true\n }\n return false\n}\n\nfunction unique(state: CState, base: string, clash: boolean): string {\n if (!clash) return base\n const taken = new Set<string>()\n for (let s: Scope | undefined = state; s; s = up(s)) for (const v of s.decls) taken.add(v.name)\n let i = 1\n while (taken.has(`${base}_${i}`)) i++\n return `${base}_${i}`\n}\n\nfunction transform(state: CState, ctx: PassContext) {\n const periods = state.actions.filter(a => a.kind === 'period')\n // S-42a: the guard also lands on the state's own transitions.\n const strong = state.out.filter(t => t.preemption === 'strong')\n if (strong.length) {\n ctx.report({\n severity: 'info', code: 'kieler-quirk', related: [state.origin ?? state.about, ...strong.map(t => t.origin)].filter((x): x is string => !!x),\n message: `\\`${state.name}\\` has a period, so KIELER also guards its own outgoing transitions with the period's tick: they can only fire in a tick after the period elapsed`,\n hint: `KIELER adds the period's condition to every transition of every state inside, \\`${state.name}\\`'s own included. Put the period into an inner state and leave \\`${state.name}\\` with a normal transition instead.`,\n })\n }\n state.actions = state.actions.filter(a => a.kind !== 'period')\n const clash = clashes(state)\n const several = periods.length > 1\n const about = (p: CAction) => p.origin ?? p.about\n const clocks = periods.map((p, i) => {\n const v = new CVar(unique(state, several ? `c${i}` : 'c', clash), 'clock')\n v.scope = state\n v.display = `the period's clock`\n v.decl = about(p)\n return v\n })\n state.decls.push(...clocks)\n const ticks = periods.map((p, i) => {\n const v = new CVar(unique(state, several ? `tick${i}` : 'tick', clash), 'bool')\n v.scope = state\n v.display = `whether \\`${state.name}\\`'s period has elapsed`\n v.role = 'tick'\n v.init = { k: 'lit', t: 'bool', v: p.delay === 'immediate' }\n v.decl = about(p)\n return v\n })\n state.decls.push(...ticks)\n // Guard every action and transition of every state inside, the state itself included.\n for (const tick of ticks) {\n const guard = (trigger: CExpr | undefined): CExpr => (trigger ? { k: 'op', op: '&&', args: [ref(tick), trigger] } : ref(tick))\n for (const s of allStates(state)) {\n for (const a of s.actions) a.trigger = guard(a.trigger)\n for (const t of s.out) t.trigger = guard(t.trigger)\n }\n }\n periods.forEach((p, i) => {\n const clock = clocks[i]\n const tick = ticks[i]\n const hard = p.annotations.some(a => a.toLowerCase() === 'hardreset')\n const threshold = p.trigger ?? { k: 'lit', t: 'int', v: 0 }\n const region = createControlflowRegion(state, i > 0 ? `Period${i}` : 'Period')\n region.about = about(p)\n const s = createInitialState(region, '_s')\n s.about = about(p)\n const o = { by: about(p), hidden: true }\n const elapsed = createTransitionTo(s, s)\n elapsed.about = about(p)\n elapsed.trigger = { k: 'op', op: '>=', args: [ref(clock), threshold] }\n elapsed.effects.push(hard\n ? { k: 'assign', ref: ref(clock), op: '=', expr: { k: 'lit', t: 'int', v: 0 }, o }\n : { k: 'assign', ref: ref(clock), op: '-=', expr: threshold, o })\n elapsed.effects.push({ k: 'assign', ref: ref(tick), op: '=', expr: { k: 'lit', t: 'bool', v: true }, o })\n const idle = createTransitionTo(s, s)\n idle.about = about(p)\n idle.effects.push({ k: 'assign', ref: ref(tick), op: '=', expr: { k: 'lit', t: 'bool', v: false }, o })\n })\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// KIELER's Probabilistic Transitions processor (de.cau.cs.kieler.sccharts.processors.prTransitions). Owner: the structure workstream.
|
|
2
|
+
// Removes: Probabilistic transitions `Pr=0.5` (structure.md).
|
|
3
|
+
//
|
|
4
|
+
// Not implemented yet: charts that use it are rejected with an "unsupported" diagnostic. To implement it, add a
|
|
5
|
+
// `run(ctx)` that rewrites ctx.root into constructs the later passes understand (see ../README.md).
|
|
6
|
+
export const prTransitions = {
|
|
7
|
+
id: 'de.cau.cs.kieler.sccharts.processors.prTransitions',
|
|
8
|
+
name: 'Probabilistic Transitions',
|
|
9
|
+
owner: 'structure',
|
|
10
|
+
uses: () => [],
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=prTransitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prTransitions.js","sourceRoot":"","sources":["../../../src/sim/passes/prTransitions.ts"],"names":[],"mappings":"AAAA,sIAAsI;AACtI,8DAA8D;AAC9D,EAAE;AACF,gHAAgH;AAChH,oGAAoG;AAIpG,MAAM,CAAC,MAAM,aAAa,GAAS;IAC/B,EAAE,EAAE,oDAAoD;IACxD,IAAI,EAAE,2BAA2B;IACjC,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE;CACjB,CAAA","sourcesContent":["// KIELER's Probabilistic Transitions processor (de.cau.cs.kieler.sccharts.processors.prTransitions). Owner: the structure workstream.\n// Removes: Probabilistic transitions `Pr=0.5` (structure.md).\n//\n// Not implemented yet: charts that use it are rejected with an \"unsupported\" diagnostic. To implement it, add a\n// `run(ctx)` that rewrites ctx.root into constructs the later passes understand (see ../README.md).\n\nimport type { Pass } from './context'\n\nexport const prTransitions: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.prTransitions',\n name: 'Probabilistic Transitions',\n owner: 'structure',\n uses: () => [],\n}\n"]}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// KIELER's Pre processor (sccharts/processors/Pre.xtend): every variable used under `pre` gets a register
|
|
2
|
+
// `_reg_x` (initialised to the type's default on entry of the declaring state) and `_pre_x`, updated by an
|
|
3
|
+
// immediate during action of the declaring state: `_pre_x = _reg_x; _reg_x = x` (concurrency.md PRE-1..PRE-4).
|
|
4
|
+
//
|
|
5
|
+
// KIELER replaces a `pre(...)` only where its direct container is an assignment, an operator expression, a
|
|
6
|
+
// transition trigger or an array index; anywhere else ("Pre expressions are only supported in assignments,
|
|
7
|
+
// triggers and other pre expressions") it fails: as an argument of print or a call, as an element of a vector,
|
|
8
|
+
// as a declaration's initial value. SCCharts Lab rejects those with a located error, and compiles a `pre(...)`
|
|
9
|
+
// that is the whole trigger of a state action with a divergence warning (official KIELER fails on it).
|
|
10
|
+
import { allActionSites, allScopes, createImmediateDuringAction, CAction, CRegion, CVar, lit, mapExpr, owningState, printExpr, ref, sameExpr, walkExpr, } from "../model.js";
|
|
11
|
+
const KIELER_PLACEMENT = 'Pre expressions are only supported in assignments, triggers and other pre expressions';
|
|
12
|
+
const UNSUPPORTED = 'The official KIELER compiler cannot compile this either: it only accepts `pre(...)` in an assignment, a transition trigger, an array index or inside a larger expression.';
|
|
13
|
+
const isPre = (e) => e?.k === 'op' && e.op === 'pre';
|
|
14
|
+
function preText(e) {
|
|
15
|
+
const a = e.args[0];
|
|
16
|
+
if (a?.k === 'ref')
|
|
17
|
+
return `pre(${a.v.display ?? a.v.name})`;
|
|
18
|
+
if (isPre(a))
|
|
19
|
+
return `pre(${preText(a)})`;
|
|
20
|
+
return 'pre(...)';
|
|
21
|
+
}
|
|
22
|
+
/** KIELER's placement rules for pre (see above): errors for the places it fails on, the divergence warning. */
|
|
23
|
+
function checkPlacements(ctx) {
|
|
24
|
+
const misplaced = (e, message, hint) => {
|
|
25
|
+
ctx.report({ severity: 'error', code: 'pre-placement', span: e.span, message: message(preText(e)), hint: `${UNSUPPORTED} ${hint(preText(e))}`, kieler: KIELER_PLACEMENT });
|
|
26
|
+
};
|
|
27
|
+
// Vectors and call arguments anywhere in an expression.
|
|
28
|
+
const visitExpr = (e) => {
|
|
29
|
+
if (!e)
|
|
30
|
+
return;
|
|
31
|
+
walkExpr(e, x => {
|
|
32
|
+
if (x.k === 'vector')
|
|
33
|
+
for (const v of x.values)
|
|
34
|
+
if (isPre(v))
|
|
35
|
+
misplaced(v, t => `\`${t}\` cannot be used here`, t => `Assign the previous value to a variable first, e.g. \`prev = ${t}\`, and use that variable here.`);
|
|
36
|
+
if (x.k === 'call')
|
|
37
|
+
for (const a of x.args)
|
|
38
|
+
if (isPre(a))
|
|
39
|
+
misplaced(a, t => `\`${t}\` cannot be passed directly as an argument of ${x.name}(...)`, t => `Store the previous value in a variable first, e.g. \`prev = ${t}\`, and pass that variable instead.`);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
for (const site of allActionSites(ctx.root)) {
|
|
43
|
+
const holder = site.transition ?? site.action;
|
|
44
|
+
if (site.action && isPre(holder.trigger)) {
|
|
45
|
+
const text = preText(holder.trigger);
|
|
46
|
+
const operand = holder.trigger.args[0];
|
|
47
|
+
const bool = operand?.k === 'ref' && (operand.v.type === 'bool' || operand.v.type === 'pure' || operand.v.signal);
|
|
48
|
+
const kind = site.action instanceof CAction ? `${site.action.kind === 'entry' ? 'an entry' : site.action.kind === 'exit' ? 'an exit' : site.action.kind === 'during' ? 'a during' : `a ${site.action.kind}`} action` : 'a state action';
|
|
49
|
+
ctx.report({
|
|
50
|
+
severity: 'warning', code: 'kieler-divergence', span: holder.trigger.span,
|
|
51
|
+
message: `The official KIELER compiler fails on \`${text}\` used directly as the trigger of ${kind}`,
|
|
52
|
+
hint: `SCCharts Lab and this guide compile it, but KIELER stops in its Pre transformation. Write \`if ${text}${bool ? ' == true' : ' != 0'}\` instead: it means the same, and KIELER compiles \`pre(...)\` inside a comparison.`,
|
|
53
|
+
kieler: KIELER_PLACEMENT,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
visitExpr(holder.trigger);
|
|
57
|
+
for (const f of holder.effects) {
|
|
58
|
+
if (f.k === 'print') {
|
|
59
|
+
for (const a of f.args)
|
|
60
|
+
if (isPre(a))
|
|
61
|
+
misplaced(a, t => `\`${t}\` cannot be passed directly as an argument of print(...)`, t => `Store the previous value in a variable first, e.g. \`prev = ${t}\`, and pass that variable instead.`);
|
|
62
|
+
f.args.forEach(visitExpr);
|
|
63
|
+
}
|
|
64
|
+
else if (f.k === 'call') {
|
|
65
|
+
visitExpr(f.call);
|
|
66
|
+
}
|
|
67
|
+
else if (f.k === 'assign') {
|
|
68
|
+
visitExpr(f.expr);
|
|
69
|
+
f.ref.idx.forEach(visitExpr);
|
|
70
|
+
}
|
|
71
|
+
else if (f.k === 'emit') {
|
|
72
|
+
visitExpr(f.value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const scope of allScopes(ctx.root)) {
|
|
77
|
+
for (const v of scope.decls) {
|
|
78
|
+
if (isPre(v.init)) {
|
|
79
|
+
const name = v.display ?? v.name;
|
|
80
|
+
misplaced(v.init, t => `\`${t}\` cannot be used in the declaration of \`${name}\``, () => `Give \`${name}\` a plain initial value and assign the previous value to it in an action instead.`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
visitExpr(v.init);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Every `pre(...)` below the root in KIELER's eAllContents order (pre-order over the containment tree; Pre.xtend
|
|
90
|
+
* collects them so): a scope's declarations (initial value, then cardinalities), its actions (effects before the
|
|
91
|
+
* trigger: Action's `effects` feature comes first), then a state's regions and its outgoing transitions (effects,
|
|
92
|
+
* then trigger), a region's states. An outer `pre` comes before the ones inside it.
|
|
93
|
+
*/
|
|
94
|
+
function presInKielerOrder(root) {
|
|
95
|
+
const out = [];
|
|
96
|
+
const expr = (e) => walkExpr(e, x => { if (isPre(x))
|
|
97
|
+
out.push(x); });
|
|
98
|
+
const effect = (f) => {
|
|
99
|
+
switch (f.k) {
|
|
100
|
+
case 'assign':
|
|
101
|
+
expr(f.ref);
|
|
102
|
+
expr(f.expr);
|
|
103
|
+
break;
|
|
104
|
+
case 'emit':
|
|
105
|
+
expr(f.ref);
|
|
106
|
+
expr(f.value);
|
|
107
|
+
break;
|
|
108
|
+
case 'print':
|
|
109
|
+
f.args.forEach(expr);
|
|
110
|
+
break;
|
|
111
|
+
case 'call':
|
|
112
|
+
expr(f.call);
|
|
113
|
+
break;
|
|
114
|
+
default: break;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const action = (a) => { a.effects.forEach(effect); expr(a.trigger); };
|
|
118
|
+
const scope = (s) => {
|
|
119
|
+
for (const v of s.decls) {
|
|
120
|
+
expr(v.init);
|
|
121
|
+
v.dims.forEach(expr);
|
|
122
|
+
}
|
|
123
|
+
s.actions.forEach(action);
|
|
124
|
+
if (s instanceof CRegion) {
|
|
125
|
+
s.states.forEach(scope);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
s.regions.forEach(scope);
|
|
129
|
+
s.out.forEach(action);
|
|
130
|
+
};
|
|
131
|
+
scope(root);
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/** A clock as the reader wrote it (`c`, `!c`). */
|
|
135
|
+
function clockText(c) {
|
|
136
|
+
if (!c)
|
|
137
|
+
return '';
|
|
138
|
+
if (c.k === 'ref' && !c.idx.length && !c.sub)
|
|
139
|
+
return c.v.display ?? c.v.name;
|
|
140
|
+
return printExpr(c).replace(/^\((.*)\)$/, '$1');
|
|
141
|
+
}
|
|
142
|
+
export const pre = {
|
|
143
|
+
id: 'de.cau.cs.kieler.sccharts.processors.pre',
|
|
144
|
+
name: 'Pre',
|
|
145
|
+
owner: 'core',
|
|
146
|
+
run(ctx) {
|
|
147
|
+
checkPlacements(ctx);
|
|
148
|
+
// KIELER pushes every pre onto a stack in eAllContents order and pops them: the last pre of a variable in the
|
|
149
|
+
// chart is handled first and creates its memory (`_reg_x`, `_pre_x` and the during action that updates them,
|
|
150
|
+
// with that pre's clock as the action's trigger); every other pre of the same variable is replaced by the
|
|
151
|
+
// same `_pre_x`, its own clock dropped. So `pre(x)` next to `pre(x, c)` share one memory, clocked or not as
|
|
152
|
+
// the last one says (probes kieler/rare/probe-pre-clock-*). Inner pres are popped first: pre(pre(x)) creates
|
|
153
|
+
// _pre_x, then _pre__pre_x. The memories are created in that order too (their during actions' order).
|
|
154
|
+
const transformed = new Map();
|
|
155
|
+
const deciding = new Map();
|
|
156
|
+
const others = new Map();
|
|
157
|
+
const madeFor = new Map();
|
|
158
|
+
const order = presInKielerOrder(ctx.root);
|
|
159
|
+
for (let i = order.length - 1; i >= 0; i--) {
|
|
160
|
+
const p = order[i];
|
|
161
|
+
const operand = p.args[0];
|
|
162
|
+
const v = operand?.k === 'ref' ? operand.v : isPre(operand) ? madeFor.get(operand) : undefined;
|
|
163
|
+
if (!v || !v.scope)
|
|
164
|
+
continue;
|
|
165
|
+
let preVar = transformed.get(v);
|
|
166
|
+
if (!preVar) {
|
|
167
|
+
preVar = createPre(v, p.args[1]);
|
|
168
|
+
transformed.set(v, preVar);
|
|
169
|
+
deciding.set(v, p);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
others.set(v, [...(others.get(v) ?? []), p]);
|
|
173
|
+
}
|
|
174
|
+
madeFor.set(p, preVar);
|
|
175
|
+
}
|
|
176
|
+
for (const [v, first] of deciding)
|
|
177
|
+
reportSharedClock(ctx, v, first, others.get(v) ?? []);
|
|
178
|
+
let changed = true;
|
|
179
|
+
const replace = (e) => {
|
|
180
|
+
if (e.k !== 'op' || e.op !== 'pre')
|
|
181
|
+
return undefined;
|
|
182
|
+
const operand = e.args[0];
|
|
183
|
+
if (operand?.k !== 'ref')
|
|
184
|
+
return undefined;
|
|
185
|
+
if (containsPre(operand))
|
|
186
|
+
return undefined;
|
|
187
|
+
const v = operand.v;
|
|
188
|
+
if (!v.scope)
|
|
189
|
+
return undefined;
|
|
190
|
+
changed = true;
|
|
191
|
+
let preVar = transformed.get(v);
|
|
192
|
+
if (!preVar) {
|
|
193
|
+
preVar = createPre(v, e.args[1]);
|
|
194
|
+
transformed.set(v, preVar);
|
|
195
|
+
}
|
|
196
|
+
return { ...ref(preVar), idx: operand.idx, span: e.span };
|
|
197
|
+
};
|
|
198
|
+
while (changed) {
|
|
199
|
+
changed = false;
|
|
200
|
+
for (const site of allActionSites(ctx.root)) {
|
|
201
|
+
const holder = site.transition ?? site.action;
|
|
202
|
+
if (holder.trigger)
|
|
203
|
+
holder.trigger = mapExpr(holder.trigger, replace);
|
|
204
|
+
holder.effects = holder.effects.map(f => mapEffect(f, replace));
|
|
205
|
+
}
|
|
206
|
+
// Inside a declaration's initial value (KIELER replaces it there too; the Initialization processor
|
|
207
|
+
// later turns it into an entry assignment).
|
|
208
|
+
for (const scope of allScopes(ctx.root)) {
|
|
209
|
+
for (const v of scope.decls)
|
|
210
|
+
if (v.init && !isPre(v.init))
|
|
211
|
+
v.init = mapExpr(v.init, replace);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* `pre(x)` next to `pre(x, c)` (or two different clocks): KIELER keeps one memory for x, and the last pre of x in the
|
|
218
|
+
* chart decides whether and how it is clocked (above). A kieler-quirk info at each pre whose clock KIELER drops or adds.
|
|
219
|
+
*/
|
|
220
|
+
function reportSharedClock(ctx, v, decider, rest) {
|
|
221
|
+
const clock = decider.args[1];
|
|
222
|
+
const changed = rest.filter(p => !sameExpr(p.args[1], clock));
|
|
223
|
+
if (!changed.length)
|
|
224
|
+
return;
|
|
225
|
+
const name = v.display ?? v.name;
|
|
226
|
+
const written = (p) => (p.args[1] ? `pre(${name}, ${clockText(p.args[1])})` : `pre(${name})`);
|
|
227
|
+
const theirs = written(decider);
|
|
228
|
+
const where = decider.span ? ` (line ${decider.span.line})` : '';
|
|
229
|
+
const copy = `${name}Copy`;
|
|
230
|
+
for (const p of changed) {
|
|
231
|
+
const mine = written(p);
|
|
232
|
+
const own = clockText(p.args[1]);
|
|
233
|
+
const clocked = clock ? clockText(clock) : own;
|
|
234
|
+
// Written after it, but earlier in KIELER's order: the trigger of the transition whose effects hold `mine`.
|
|
235
|
+
const trigger = !!p.span && !!decider.span && p.span.start > decider.span.start;
|
|
236
|
+
ctx.report({
|
|
237
|
+
severity: 'info', code: 'kieler-quirk', span: p.span,
|
|
238
|
+
message: `In KIELER \`${mine}\` behaves as \`${theirs}\`: KIELER keeps one memory for the previous value of \`${name}\`, made for the last \`pre\` of \`${name}\` in the chart, \`${theirs}\`${where}${trigger ? ' (a transition\'s trigger counts as coming after its effects)' : ''}`,
|
|
239
|
+
hint: (clock
|
|
240
|
+
? `So \`${mine}\` changes only in ticks in which \`${clocked}\` holds, and the guide's simulation does the same.`
|
|
241
|
+
: `So \`${mine}\` is the value \`${name}\` had in the previous tick, whether \`${own}\` held or not, and the guide's simulation does the same.`)
|
|
242
|
+
+ ` To have both, give the clocked one a variable of its own: copy \`${name}\` in every tick (\`immediate during do ${copy} = ${name}\`) and write \`pre(${copy}, ${clocked})\`.`,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function containsPre(r) {
|
|
247
|
+
let found = false;
|
|
248
|
+
walkExpr(r, e => { if (e.k === 'op' && e.op === 'pre')
|
|
249
|
+
found = true; });
|
|
250
|
+
return found;
|
|
251
|
+
}
|
|
252
|
+
function neutral(v) {
|
|
253
|
+
const scalar = () => {
|
|
254
|
+
switch (v.type) {
|
|
255
|
+
case 'bool': return lit(false);
|
|
256
|
+
case 'int': return lit(0);
|
|
257
|
+
case 'float': return { k: 'lit', t: 'float', v: 0 };
|
|
258
|
+
case 'string': return { k: 'null' };
|
|
259
|
+
default: return undefined;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
let value = scalar();
|
|
263
|
+
if (!value)
|
|
264
|
+
return undefined;
|
|
265
|
+
for (let i = v.dims.length - 1; i >= 0; i--) {
|
|
266
|
+
const d = v.dims[i];
|
|
267
|
+
const n = d.k === 'lit' && typeof d.v === 'number' ? d.v : 0;
|
|
268
|
+
const element = value;
|
|
269
|
+
value = { k: 'vector', values: Array.from({ length: n }, () => ({ ...element })) };
|
|
270
|
+
}
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
function createPre(v, clock) {
|
|
274
|
+
const state = owningState(v.scope);
|
|
275
|
+
const make = (prefix, role) => {
|
|
276
|
+
const x = new CVar(prefix + v.name, v.type);
|
|
277
|
+
x.dims = v.dims.map(d => ({ ...d }));
|
|
278
|
+
x.combine = v.combine;
|
|
279
|
+
x.generated = true;
|
|
280
|
+
x.role = role;
|
|
281
|
+
x.of = v;
|
|
282
|
+
x.display = v.display ?? v.name;
|
|
283
|
+
x.decl = v.decl;
|
|
284
|
+
x.scope = state;
|
|
285
|
+
state.decls.push(x);
|
|
286
|
+
return x;
|
|
287
|
+
};
|
|
288
|
+
const reg = make('_reg_', 'reg');
|
|
289
|
+
reg.init = neutral(v);
|
|
290
|
+
const preVar = make('_pre_', 'pre');
|
|
291
|
+
const during = createImmediateDuringAction(state);
|
|
292
|
+
during.about = v.decl;
|
|
293
|
+
if (clock)
|
|
294
|
+
during.trigger = clock;
|
|
295
|
+
const o = { hidden: true, by: v.decl };
|
|
296
|
+
if (!v.dims.length) {
|
|
297
|
+
during.effects.unshift({ k: 'assign', ref: ref(reg), op: '=', expr: ref(v), o });
|
|
298
|
+
during.effects.unshift({ k: 'assign', ref: ref(preVar), op: '=', expr: ref(reg), o });
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
for (const index of indices(v)) {
|
|
302
|
+
during.effects.push({ k: 'assign', ref: ref(reg, index.map(i => lit(i))), op: '=', expr: ref(v, index.map(i => lit(i))), o });
|
|
303
|
+
during.effects.unshift({ k: 'assign', ref: ref(preVar, index.map(i => lit(i))), op: '=', expr: ref(reg, index.map(i => lit(i))), o });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return preVar;
|
|
307
|
+
}
|
|
308
|
+
function indices(v) {
|
|
309
|
+
let out = [[]];
|
|
310
|
+
for (const d of v.dims) {
|
|
311
|
+
const n = d.k === 'lit' && typeof d.v === 'number' ? d.v : 0;
|
|
312
|
+
out = out.flatMap(prefix => Array.from({ length: n }, (_, i) => [...prefix, i]));
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
function mapEffect(f, fn) {
|
|
317
|
+
switch (f.k) {
|
|
318
|
+
case 'assign': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(i => mapExpr(i, fn)) }, expr: f.expr ? mapExpr(f.expr, fn) : undefined };
|
|
319
|
+
case 'emit': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(i => mapExpr(i, fn)) }, value: f.value ? mapExpr(f.value, fn) : undefined };
|
|
320
|
+
case 'print': return { ...f, args: f.args.map(a => mapExpr(a, fn)) };
|
|
321
|
+
case 'call': return { ...f, call: mapExpr(f.call, fn) };
|
|
322
|
+
default: return f;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
export { ref };
|
|
326
|
+
//# sourceMappingURL=pre.js.map
|
|
@@ -0,0 +1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I,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAkB,EAAE,CAAA;QACxE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;IACrB,CAAC;AACL,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,CAAA","sourcesContent":["// KIELER's Pre processor (sccharts/processors/Pre.xtend): every variable used under `pre` gets a register\n// `_reg_x` (initialised to the type's default on entry of the declaring state) and `_pre_x`, updated by an\n// immediate during action of the declaring state: `_pre_x = _reg_x; _reg_x = x` (concurrency.md PRE-1..PRE-4).\n//\n// KIELER replaces a `pre(...)` only where its direct container is an assignment, an operator expression, a\n// transition trigger or an array index; anywhere else (\"Pre expressions are only supported in assignments,\n// triggers and other pre expressions\") it fails: as an argument of print or a call, as an element of a vector,\n// as a declaration's initial value. SCCharts Lab rejects those with a located error, and compiles a `pre(...)`\n// that is the whole trigger of a state action with a divergence warning (official KIELER fails on it).\n\nimport type { Pass, PassContext } from './context'\nimport {\n allActionSites, allScopes, createImmediateDuringAction, CAction, CRegion, CVar, lit, mapExpr, owningState, printExpr, ref,\n sameExpr, walkExpr, type CEffect, type CExpr, type CRef, type CState,\n} from '../model'\n\nconst KIELER_PLACEMENT = 'Pre expressions are only supported in assignments, triggers and other pre expressions'\nconst UNSUPPORTED = 'The official KIELER compiler cannot compile this either: it only accepts `pre(...)` in an assignment, a transition trigger, an array index or inside a larger expression.'\n\nconst isPre = (e: CExpr | undefined): e is Extract<CExpr, { k: 'op' }> => e?.k === 'op' && e.op === 'pre'\n\nfunction preText(e: Extract<CExpr, { k: 'op' }>): string {\n const a = e.args[0]\n if (a?.k === 'ref') return `pre(${a.v.display ?? a.v.name})`\n if (isPre(a)) return `pre(${preText(a)})`\n return 'pre(...)'\n}\n\n/** KIELER's placement rules for pre (see above): errors for the places it fails on, the divergence warning. */\nfunction checkPlacements(ctx: PassContext) {\n const misplaced = (e: CExpr, message: (text: string) => string, hint: (text: string) => string) => {\n ctx.report({ severity: 'error', code: 'pre-placement', span: e.span, message: message(preText(e as never)), hint: `${UNSUPPORTED} ${hint(preText(e as never))}`, kieler: KIELER_PLACEMENT })\n }\n // Vectors and call arguments anywhere in an expression.\n const visitExpr = (e: CExpr | undefined) => {\n if (!e) return\n walkExpr(e, x => {\n if (x.k === 'vector') for (const v of x.values) if (isPre(v)) misplaced(v, t => `\\`${t}\\` cannot be used here`, t => `Assign the previous value to a variable first, e.g. \\`prev = ${t}\\`, and use that variable here.`)\n if (x.k === 'call') for (const a of x.args) if (isPre(a)) misplaced(a, t => `\\`${t}\\` cannot be passed directly as an argument of ${x.name}(...)`, t => `Store the previous value in a variable first, e.g. \\`prev = ${t}\\`, and pass that variable instead.`)\n })\n }\n for (const site of allActionSites(ctx.root)) {\n const holder = site.transition ?? site.action!\n if (site.action && isPre(holder.trigger)) {\n const text = preText(holder.trigger)\n const operand = holder.trigger.args[0]\n const bool = operand?.k === 'ref' && (operand.v.type === 'bool' || operand.v.type === 'pure' || operand.v.signal)\n const kind = site.action instanceof CAction ? `${site.action.kind === 'entry' ? 'an entry' : site.action.kind === 'exit' ? 'an exit' : site.action.kind === 'during' ? 'a during' : `a ${site.action.kind}`} action` : 'a state action'\n ctx.report({\n severity: 'warning', code: 'kieler-divergence', span: holder.trigger.span,\n message: `The official KIELER compiler fails on \\`${text}\\` used directly as the trigger of ${kind}`,\n hint: `SCCharts Lab and this guide compile it, but KIELER stops in its Pre transformation. Write \\`if ${text}${bool ? ' == true' : ' != 0'}\\` instead: it means the same, and KIELER compiles \\`pre(...)\\` inside a comparison.`,\n kieler: KIELER_PLACEMENT,\n })\n }\n visitExpr(holder.trigger)\n for (const f of holder.effects) {\n if (f.k === 'print') {\n for (const a of f.args) if (isPre(a)) misplaced(a, t => `\\`${t}\\` cannot be passed directly as an argument of print(...)`, t => `Store the previous value in a variable first, e.g. \\`prev = ${t}\\`, and pass that variable instead.`)\n f.args.forEach(visitExpr)\n } else if (f.k === 'call') {\n visitExpr(f.call)\n } else if (f.k === 'assign') {\n visitExpr(f.expr)\n f.ref.idx.forEach(visitExpr)\n } else if (f.k === 'emit') {\n visitExpr(f.value)\n }\n }\n }\n for (const scope of allScopes(ctx.root)) {\n for (const v of scope.decls) {\n if (isPre(v.init)) {\n const name = v.display ?? v.name\n misplaced(v.init, t => `\\`${t}\\` cannot be used in the declaration of \\`${name}\\``, () => `Give \\`${name}\\` a plain initial value and assign the previous value to it in an action instead.`)\n } else {\n visitExpr(v.init)\n }\n }\n }\n}\n\ntype PreExpr = Extract<CExpr, { k: 'op' }>\n\n/**\n * Every `pre(...)` below the root in KIELER's eAllContents order (pre-order over the containment tree; Pre.xtend\n * collects them so): a scope's declarations (initial value, then cardinalities), its actions (effects before the\n * trigger: Action's `effects` feature comes first), then a state's regions and its outgoing transitions (effects,\n * then trigger), a region's states. An outer `pre` comes before the ones inside it.\n */\nfunction presInKielerOrder(root: CState): PreExpr[] {\n const out: PreExpr[] = []\n const expr = (e: CExpr | undefined) => walkExpr(e, x => { if (isPre(x)) out.push(x) })\n const effect = (f: CEffect) => {\n switch (f.k) {\n case 'assign': expr(f.ref); expr(f.expr); break\n case 'emit': expr(f.ref); expr(f.value); break\n case 'print': f.args.forEach(expr); break\n case 'call': expr(f.call); break\n default: break\n }\n }\n const action = (a: { effects: CEffect[]; trigger?: CExpr }) => { a.effects.forEach(effect); expr(a.trigger) }\n const scope = (s: CState | CRegion) => {\n for (const v of s.decls) { expr(v.init); v.dims.forEach(expr) }\n s.actions.forEach(action)\n if (s instanceof CRegion) { s.states.forEach(scope); return }\n s.regions.forEach(scope)\n s.out.forEach(action)\n }\n scope(root)\n return out\n}\n\n/** A clock as the reader wrote it (`c`, `!c`). */\nfunction clockText(c: CExpr | undefined): string {\n if (!c) return ''\n if (c.k === 'ref' && !c.idx.length && !c.sub) return c.v.display ?? c.v.name\n return printExpr(c).replace(/^\\((.*)\\)$/, '$1')\n}\n\nexport const pre: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.pre',\n name: 'Pre',\n owner: 'core',\n run(ctx: PassContext) {\n checkPlacements(ctx)\n // KIELER pushes every pre onto a stack in eAllContents order and pops them: the last pre of a variable in the\n // chart is handled first and creates its memory (`_reg_x`, `_pre_x` and the during action that updates them,\n // with that pre's clock as the action's trigger); every other pre of the same variable is replaced by the\n // same `_pre_x`, its own clock dropped. So `pre(x)` next to `pre(x, c)` share one memory, clocked or not as\n // the last one says (probes kieler/rare/probe-pre-clock-*). Inner pres are popped first: pre(pre(x)) creates\n // _pre_x, then _pre__pre_x. The memories are created in that order too (their during actions' order).\n const transformed = new Map<CVar, CVar>()\n const deciding = new Map<CVar, PreExpr>()\n const others = new Map<CVar, PreExpr[]>()\n const madeFor = new Map<PreExpr, CVar>()\n const order = presInKielerOrder(ctx.root)\n for (let i = order.length - 1; i >= 0; i--) {\n const p = order[i]\n const operand = p.args[0]\n const v = operand?.k === 'ref' ? operand.v : isPre(operand) ? madeFor.get(operand) : undefined\n if (!v || !v.scope) continue\n let preVar = transformed.get(v)\n if (!preVar) {\n preVar = createPre(v, p.args[1])\n transformed.set(v, preVar)\n deciding.set(v, p)\n } else {\n others.set(v, [...(others.get(v) ?? []), p])\n }\n madeFor.set(p, preVar)\n }\n for (const [v, first] of deciding) reportSharedClock(ctx, v, first, others.get(v) ?? [])\n let changed = true\n const replace = (e: CExpr): CExpr | undefined => {\n if (e.k !== 'op' || e.op !== 'pre') return undefined\n const operand = e.args[0]\n if (operand?.k !== 'ref') return undefined\n if (containsPre(operand)) return undefined\n const v = operand.v\n if (!v.scope) return undefined\n changed = true\n let preVar = transformed.get(v)\n if (!preVar) {\n preVar = createPre(v, e.args[1])\n transformed.set(v, preVar)\n }\n return { ...ref(preVar), idx: operand.idx, span: e.span }\n }\n while (changed) {\n changed = false\n for (const site of allActionSites(ctx.root)) {\n const holder = site.transition ?? site.action!\n if (holder.trigger) holder.trigger = mapExpr(holder.trigger, replace)\n holder.effects = holder.effects.map(f => mapEffect(f, replace))\n }\n // Inside a declaration's initial value (KIELER replaces it there too; the Initialization processor\n // later turns it into an entry assignment).\n for (const scope of allScopes(ctx.root)) {\n for (const v of scope.decls) if (v.init && !isPre(v.init)) v.init = mapExpr(v.init, replace)\n }\n }\n },\n}\n\n/**\n * `pre(x)` next to `pre(x, c)` (or two different clocks): KIELER keeps one memory for x, and the last pre of x in the\n * chart decides whether and how it is clocked (above). A kieler-quirk info at each pre whose clock KIELER drops or adds.\n */\nfunction reportSharedClock(ctx: PassContext, v: CVar, decider: PreExpr, rest: PreExpr[]) {\n const clock = decider.args[1]\n const changed = rest.filter(p => !sameExpr(p.args[1], clock))\n if (!changed.length) return\n const name = v.display ?? v.name\n const written = (p: PreExpr) => (p.args[1] ? `pre(${name}, ${clockText(p.args[1])})` : `pre(${name})`)\n const theirs = written(decider)\n const where = decider.span ? ` (line ${decider.span.line})` : ''\n const copy = `${name}Copy`\n for (const p of changed) {\n const mine = written(p)\n const own = clockText(p.args[1])\n const clocked = clock ? clockText(clock) : own\n // Written after it, but earlier in KIELER's order: the trigger of the transition whose effects hold `mine`.\n const trigger = !!p.span && !!decider.span && p.span.start > decider.span.start\n ctx.report({\n severity: 'info', code: 'kieler-quirk', span: p.span,\n message: `In KIELER \\`${mine}\\` behaves as \\`${theirs}\\`: KIELER keeps one memory for the previous value of \\`${name}\\`, made for the last \\`pre\\` of \\`${name}\\` in the chart, \\`${theirs}\\`${where}${trigger ? ' (a transition\\'s trigger counts as coming after its effects)' : ''}`,\n hint: (clock\n ? `So \\`${mine}\\` changes only in ticks in which \\`${clocked}\\` holds, and the guide's simulation does the same.`\n : `So \\`${mine}\\` is the value \\`${name}\\` had in the previous tick, whether \\`${own}\\` held or not, and the guide's simulation does the same.`)\n + ` To have both, give the clocked one a variable of its own: copy \\`${name}\\` in every tick (\\`immediate during do ${copy} = ${name}\\`) and write \\`pre(${copy}, ${clocked})\\`.`,\n })\n }\n}\n\nfunction containsPre(r: CRef): boolean {\n let found = false\n walkExpr(r, e => { if (e.k === 'op' && e.op === 'pre') found = true })\n return found\n}\n\nfunction neutral(v: CVar): CExpr | undefined {\n const scalar = (): CExpr | undefined => {\n switch (v.type) {\n case 'bool': return lit(false)\n case 'int': return lit(0)\n case 'float': return { k: 'lit', t: 'float', v: 0 }\n case 'string': return { k: 'null' }\n default: return undefined\n }\n }\n let value = scalar()\n if (!value) return undefined\n for (let i = v.dims.length - 1; i >= 0; i--) {\n const d = v.dims[i]\n const n = d.k === 'lit' && typeof d.v === 'number' ? d.v : 0\n const element: CExpr = value\n value = { k: 'vector', values: Array.from({ length: n }, () => ({ ...element })) }\n }\n return value\n}\n\nfunction createPre(v: CVar, clock: CExpr | undefined): CVar {\n const state = owningState(v.scope!)\n const make = (prefix: string, role: string) => {\n const x = new CVar(prefix + v.name, v.type)\n x.dims = v.dims.map(d => ({ ...d }))\n x.combine = v.combine\n x.generated = true\n x.role = role\n x.of = v\n x.display = v.display ?? v.name\n x.decl = v.decl\n x.scope = state\n state.decls.push(x)\n return x\n }\n const reg = make('_reg_', 'reg')\n reg.init = neutral(v)\n const preVar = make('_pre_', 'pre')\n const during = createImmediateDuringAction(state)\n during.about = v.decl\n if (clock) during.trigger = clock\n const o = { hidden: true, by: v.decl }\n if (!v.dims.length) {\n during.effects.unshift({ k: 'assign', ref: ref(reg), op: '=', expr: ref(v), o })\n during.effects.unshift({ k: 'assign', ref: ref(preVar), op: '=', expr: ref(reg), o })\n } else {\n for (const index of indices(v)) {\n during.effects.push({ k: 'assign', ref: ref(reg, index.map(i => lit(i))), op: '=', expr: ref(v, index.map(i => lit(i))), o })\n during.effects.unshift({ k: 'assign', ref: ref(preVar, index.map(i => lit(i))), op: '=', expr: ref(reg, index.map(i => lit(i))), o })\n }\n }\n return preVar\n}\n\nfunction indices(v: CVar): number[][] {\n let out: number[][] = [[]]\n for (const d of v.dims) {\n const n = d.k === 'lit' && typeof d.v === 'number' ? d.v : 0\n out = out.flatMap(prefix => Array.from({ length: n }, (_, i) => [...prefix, i]))\n }\n return out\n}\n\nfunction mapEffect(f: CEffect, fn: (e: CExpr) => CExpr | undefined): CEffect {\n switch (f.k) {\n case 'assign': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(i => mapExpr(i, fn)) }, expr: f.expr ? mapExpr(f.expr, fn) : undefined }\n case 'emit': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(i => mapExpr(i, fn)) }, value: f.value ? mapExpr(f.value, fn) : undefined }\n case 'print': return { ...f, args: f.args.map(a => mapExpr(a, fn)) }\n case 'call': return { ...f, call: mapExpr(f.call, fn) as typeof f.call }\n default: return f\n }\n}\n\nexport { ref }\n"]}
|