@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,147 @@
|
|
|
1
|
+
// KIELER's Array Assignment processor (sccharts/processors/ArrayAssignment.xtend): `a = {e0, e1, ...}` becomes
|
|
2
|
+
// `a[0] = e0; a[1] = e1; ...`, executed in index order (basics.md B-28), with KIELER's cardinality checks.
|
|
3
|
+
import { allActionSites, copyExpr, copyRef, lit, walkExpr } from "../model.js";
|
|
4
|
+
import { printExpr } from "../model.js";
|
|
5
|
+
export const arrayAssignment = {
|
|
6
|
+
id: 'de.cau.cs.kieler.sccharts.processors.arrayAssignment',
|
|
7
|
+
name: 'Array Assignment',
|
|
8
|
+
owner: 'core',
|
|
9
|
+
run(ctx) {
|
|
10
|
+
for (const site of allActionSites(ctx.root)) {
|
|
11
|
+
const holder = site.transition ?? site.action;
|
|
12
|
+
let again = true;
|
|
13
|
+
while (again) {
|
|
14
|
+
again = false;
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const f of holder.effects) {
|
|
17
|
+
if (f.k !== 'assign' || !f.expr || !containsVector(f.expr)) {
|
|
18
|
+
out.push(f);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const expr = computeVectorValues(f.expr);
|
|
22
|
+
const asm = { ...f, expr };
|
|
23
|
+
validate(asm, ctx);
|
|
24
|
+
const target = lowermost(asm.ref);
|
|
25
|
+
if (target.v.dims.length > 0 && expr.k === 'vector') {
|
|
26
|
+
expr.values.forEach((v, i) => {
|
|
27
|
+
if (v.k === 'vector')
|
|
28
|
+
again = true;
|
|
29
|
+
const r = copyRef(asm.ref);
|
|
30
|
+
const low = lowermost(r);
|
|
31
|
+
low.idx = [...target.idx.map(x => copyExpr(x)), lit(i)];
|
|
32
|
+
out.push({ ...asm, ref: r, expr: v, o: { ...asm.o } });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
out.push(asm);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
holder.effects = out;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
function lowermost(r) {
|
|
45
|
+
let x = r;
|
|
46
|
+
while (x.sub)
|
|
47
|
+
x = x.sub;
|
|
48
|
+
return x;
|
|
49
|
+
}
|
|
50
|
+
function containsVector(e) {
|
|
51
|
+
let found = false;
|
|
52
|
+
walkExpr(e, x => { if (x.k === 'vector')
|
|
53
|
+
found = true; });
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function computeVectorValues(e) {
|
|
57
|
+
if (e.k === 'vector') {
|
|
58
|
+
if (e.range) {
|
|
59
|
+
const [a, b] = [e.values[0], e.values[e.values.length - 1]];
|
|
60
|
+
const start = a?.k === 'lit' ? a.v : 0;
|
|
61
|
+
const end = b?.k === 'lit' ? b.v : -1;
|
|
62
|
+
const values = [];
|
|
63
|
+
for (let i = start; i <= end; i++)
|
|
64
|
+
values.push(lit(i));
|
|
65
|
+
return { k: 'vector', values, span: e.span };
|
|
66
|
+
}
|
|
67
|
+
return { ...e, values: e.values.map(computeVectorValues) };
|
|
68
|
+
}
|
|
69
|
+
if (e.k !== 'op')
|
|
70
|
+
return e;
|
|
71
|
+
const args = e.args.map(computeVectorValues);
|
|
72
|
+
const vectors = args.filter(a => a.k === 'vector');
|
|
73
|
+
if (vectors.length) {
|
|
74
|
+
if (e.op === '+') {
|
|
75
|
+
const values = [];
|
|
76
|
+
for (const a of args) {
|
|
77
|
+
if (a.k === 'vector')
|
|
78
|
+
values.push(...a.values);
|
|
79
|
+
else
|
|
80
|
+
values.push(a);
|
|
81
|
+
}
|
|
82
|
+
return { k: 'vector', values, span: e.span };
|
|
83
|
+
}
|
|
84
|
+
if (e.op === '*') {
|
|
85
|
+
if (vectors.length !== 1 || args.length !== 2)
|
|
86
|
+
return { ...e, args };
|
|
87
|
+
const vector = vectors[0];
|
|
88
|
+
const n = args.find(a => a.k !== 'vector');
|
|
89
|
+
if (n.k === 'lit' && n.t === 'int') {
|
|
90
|
+
const values = [];
|
|
91
|
+
for (let i = 0; i < n.v; i++)
|
|
92
|
+
for (const v of vector.values)
|
|
93
|
+
values.push(copyExpr(v));
|
|
94
|
+
return { k: 'vector', values, span: e.span };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { ...e, args };
|
|
99
|
+
}
|
|
100
|
+
function validate(asm, ctx) {
|
|
101
|
+
const target = lowermost(asm.ref);
|
|
102
|
+
const v = target.v;
|
|
103
|
+
const name = printExpr(target);
|
|
104
|
+
const error = (message) => ctx.report({
|
|
105
|
+
severity: 'error', code: 'cardinality', span: asm.o.span, message, kieler: message,
|
|
106
|
+
hint: 'A vector may be shorter than the array (the rest keeps its value) but not longer, and must have the array\'s shape.',
|
|
107
|
+
related: asm.o.by ? [asm.o.by] : undefined,
|
|
108
|
+
});
|
|
109
|
+
const expr = asm.expr;
|
|
110
|
+
if (v.dims.length && expr.k !== 'vector' && expr.k !== 'ref') {
|
|
111
|
+
if (target.idx.length !== v.dims.length) {
|
|
112
|
+
error(`Cardinalities do not match. ${name} is an array of dimension ${v.dims.length - target.idx.length} but only a single value is given.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (v.dims.length && expr.k === 'vector') {
|
|
116
|
+
const rest = v.dims.slice(target.idx.length);
|
|
117
|
+
if (!rest.length)
|
|
118
|
+
error(`Cardinalities do not match. ${name} is not an array but a vector of size ${expr.values.length} is given.`);
|
|
119
|
+
let depth = 0;
|
|
120
|
+
for (const card of rest) {
|
|
121
|
+
if (card.k === 'lit' && typeof card.v === 'number') {
|
|
122
|
+
let expressions = [expr];
|
|
123
|
+
for (let d = 0; d < depth; d++) {
|
|
124
|
+
const deeper = [];
|
|
125
|
+
for (const e of expressions) {
|
|
126
|
+
if (e.k === 'vector')
|
|
127
|
+
deeper.push(...e.values);
|
|
128
|
+
else if (e.k !== 'ref')
|
|
129
|
+
error(`Cardinalities do not match. ${name} at dimension ${d} is an array of size ${card.v} but only a single value is given.`);
|
|
130
|
+
}
|
|
131
|
+
expressions = deeper;
|
|
132
|
+
}
|
|
133
|
+
for (const e of expressions) {
|
|
134
|
+
if (e.k === 'vector') {
|
|
135
|
+
if (e.values.length > card.v)
|
|
136
|
+
error(`Cardinalities do not match. ${name} at dimension ${depth} is an array of size ${card.v} but a vector of size ${e.values.length} is given.`);
|
|
137
|
+
}
|
|
138
|
+
else if (e.k !== 'ref') {
|
|
139
|
+
error(`Cardinalities do not match. ${name} at dimension ${depth} is an array of size ${card.v} but only a single value is given.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
depth++;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=arrayAssignment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayAssignment.js","sourceRoot":"","sources":["../../../src/sim/passes/arrayAssignment.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,2GAA2G;AAG3G,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAuC,oBAAgB;AAChH,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC,MAAM,CAAC,MAAM,eAAe,GAAS;IACjC,EAAE,EAAE,sDAAsD;IAC1D,IAAI,EAAE,kBAAkB;IACxB,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;YACD,KAAK,EAAE,CAAA;QACX,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["// KIELER's Array Assignment processor (sccharts/processors/ArrayAssignment.xtend): `a = {e0, e1, ...}` becomes\n// `a[0] = e0; a[1] = e1; ...`, executed in index order (basics.md B-28), with KIELER's cardinality checks.\n\nimport type { Pass, PassContext } from './context'\nimport { allActionSites, copyExpr, copyRef, lit, walkExpr, type CEffect, type CExpr, type CRef } from '../model'\nimport { printExpr } from '../model'\n\nexport const arrayAssignment: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.arrayAssignment',\n name: 'Array Assignment',\n owner: 'core',\n run(ctx: PassContext) {\n for (const site of allActionSites(ctx.root)) {\n const holder = site.transition ?? site.action!\n let again = true\n while (again) {\n again = false\n const out: CEffect[] = []\n for (const f of holder.effects) {\n if (f.k !== 'assign' || !f.expr || !containsVector(f.expr)) {\n out.push(f)\n continue\n }\n const expr = computeVectorValues(f.expr)\n const asm = { ...f, expr }\n validate(asm, ctx)\n const target = lowermost(asm.ref)\n if (target.v.dims.length > 0 && expr.k === 'vector') {\n expr.values.forEach((v, i) => {\n if (v.k === 'vector') again = true\n const r = copyRef(asm.ref)\n const low = lowermost(r)\n low.idx = [...target.idx.map(x => copyExpr(x)), lit(i)]\n out.push({ ...asm, ref: r, expr: v, o: { ...asm.o } })\n })\n } else {\n out.push(asm)\n }\n }\n holder.effects = out\n }\n }\n },\n}\n\nfunction lowermost(r: CRef): CRef {\n let x = r\n while (x.sub) x = x.sub\n return x\n}\n\nfunction containsVector(e: CExpr): boolean {\n let found = false\n walkExpr(e, x => { if (x.k === 'vector') found = true })\n return found\n}\n\nfunction computeVectorValues(e: CExpr): CExpr {\n if (e.k === 'vector') {\n if (e.range) {\n const [a, b] = [e.values[0], e.values[e.values.length - 1]]\n const start = a?.k === 'lit' ? (a.v as number) : 0\n const end = b?.k === 'lit' ? (b.v as number) : -1\n const values: CExpr[] = []\n for (let i = start; i <= end; i++) values.push(lit(i))\n return { k: 'vector', values, span: e.span }\n }\n return { ...e, values: e.values.map(computeVectorValues) }\n }\n if (e.k !== 'op') return e\n const args = e.args.map(computeVectorValues)\n const vectors = args.filter(a => a.k === 'vector')\n if (vectors.length) {\n if (e.op === '+') {\n const values: CExpr[] = []\n for (const a of args) {\n if (a.k === 'vector') values.push(...a.values)\n else values.push(a)\n }\n return { k: 'vector', values, span: e.span }\n }\n if (e.op === '*') {\n if (vectors.length !== 1 || args.length !== 2) return { ...e, args }\n const vector = vectors[0] as Extract<CExpr, { k: 'vector' }>\n const n = args.find(a => a.k !== 'vector')!\n if (n.k === 'lit' && n.t === 'int') {\n const values: CExpr[] = []\n for (let i = 0; i < (n.v as number); i++) for (const v of vector.values) values.push(copyExpr(v))\n return { k: 'vector', values, span: e.span }\n }\n }\n }\n return { ...e, args }\n}\n\nfunction validate(asm: Extract<CEffect, { k: 'assign' }>, ctx: PassContext) {\n const target = lowermost(asm.ref)\n const v = target.v\n const name = printExpr(target)\n const error = (message: string) => ctx.report({\n severity: 'error', code: 'cardinality', span: asm.o.span, message, kieler: message,\n hint: 'A vector may be shorter than the array (the rest keeps its value) but not longer, and must have the array\\'s shape.',\n related: asm.o.by ? [asm.o.by] : undefined,\n })\n const expr = asm.expr!\n if (v.dims.length && expr.k !== 'vector' && expr.k !== 'ref') {\n if (target.idx.length !== v.dims.length) {\n error(`Cardinalities do not match. ${name} is an array of dimension ${v.dims.length - target.idx.length} but only a single value is given.`)\n }\n }\n if (v.dims.length && expr.k === 'vector') {\n const rest = v.dims.slice(target.idx.length)\n if (!rest.length) error(`Cardinalities do not match. ${name} is not an array but a vector of size ${expr.values.length} is given.`)\n let depth = 0\n for (const card of rest) {\n if (card.k === 'lit' && typeof card.v === 'number') {\n let expressions: CExpr[] = [expr]\n for (let d = 0; d < depth; d++) {\n const deeper: CExpr[] = []\n for (const e of expressions) {\n if (e.k === 'vector') deeper.push(...e.values)\n else if (e.k !== 'ref') error(`Cardinalities do not match. ${name} at dimension ${d} is an array of size ${card.v} but only a single value is given.`)\n }\n expressions = deeper\n }\n for (const e of expressions) {\n if (e.k === 'vector') {\n if (e.values.length > card.v) error(`Cardinalities do not match. ${name} at dimension ${depth} is an array of size ${card.v} but a vector of size ${e.values.length} is given.`)\n } else if (e.k !== 'ref') {\n error(`Cardinalities do not match. ${name} at dimension ${depth} is an array of size ${card.v} but only a single value is given.`)\n }\n }\n }\n depth++\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// KIELER's SCL Code Effects processor (sccharts/processors/SclCodeEffect.xtend). Owner: the structure workstream.
|
|
2
|
+
// structure.md S-44.
|
|
3
|
+
//
|
|
4
|
+
// A code effect `do { ... }` becomes a void method `_effect<n>` of the state (an action's own state; for a
|
|
5
|
+
// transition, the state containing its source) and a call of it. The simulator does this while lowering (lower.ts,
|
|
6
|
+
// codeEffect), where the block's own declarations are at hand; the method is then inlined into the SCG like any short
|
|
7
|
+
// method (structure/methods.ts). Nothing is left for this pass.
|
|
8
|
+
export const codeEffects = {
|
|
9
|
+
id: 'de.cau.cs.kieler.sccharts.processors.codeEffects',
|
|
10
|
+
name: 'Code Effects',
|
|
11
|
+
owner: 'structure',
|
|
12
|
+
run() { },
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=codeEffects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeEffects.js","sourceRoot":"","sources":["../../../src/sim/passes/codeEffects.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,qBAAqB;AACrB,EAAE;AACF,2GAA2G;AAC3G,mHAAmH;AACnH,sHAAsH;AACtH,gEAAgE;AAIhE,MAAM,CAAC,MAAM,WAAW,GAAS;IAC7B,EAAE,EAAE,kDAAkD;IACtD,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,WAAW;IAClB,GAAG,KAAI,CAAC;CACX,CAAA","sourcesContent":["// KIELER's SCL Code Effects processor (sccharts/processors/SclCodeEffect.xtend). Owner: the structure workstream.\n// structure.md S-44.\n//\n// A code effect `do { ... }` becomes a void method `_effect<n>` of the state (an action's own state; for a\n// transition, the state containing its source) and a call of it. The simulator does this while lowering (lower.ts,\n// codeEffect), where the block's own declarations are at hand; the method is then inlined into the SCG like any short\n// method (structure/methods.ts). Nothing is left for this pass.\n\nimport type { Pass } from './context'\n\nexport const codeEffects: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.codeEffects',\n name: 'Code Effects',\n owner: 'structure',\n run() {},\n}\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// KIELER's Complex Final State processor (sccharts/processors/ComplexFinalState.xtend): final states with
|
|
2
|
+
// outgoing transitions (or during/exit actions, or inner states) stop being final; a `_CFSterm` flag per region
|
|
3
|
+
// records whether the region is in a final state, and the parent's terminations check the flags
|
|
4
|
+
// (basics.md B-19; concurrency.md T-2, T-8).
|
|
5
|
+
import { addTerminationCheck, ANNOTATION_TERMINATION_DELAYED, setRegionTerm } from "./termination.js";
|
|
6
|
+
import { actionsOf, addRegion, allContainedStates, allStates, assign, controlflowRegions, createControlflowRegion, createEntryAction, createFinalState, createImmediateTransitionTo, createInitialState, createVar, finalStates, isImmediatelyReachable, isImplicitlyImmediate, regionsMayTerminate, FALSE, TRUE, readableName, readableRegionName, } from "../model.js";
|
|
7
|
+
export const complexFinalState = {
|
|
8
|
+
id: 'de.cau.cs.kieler.sccharts.processors.complexFinalState',
|
|
9
|
+
name: 'Complex Final State',
|
|
10
|
+
owner: 'core',
|
|
11
|
+
run(ctx) {
|
|
12
|
+
const parents = allStates(ctx.root).filter(s => s.regions.some(r => !r.dataflow && r.states.some(isComplexFinalState)));
|
|
13
|
+
// CREATE_FINAL_REGIONS follows finalRegion.supported, which is false in the netlist chain.
|
|
14
|
+
for (const parent of parents)
|
|
15
|
+
transform(parent, ctx);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export function isComplexFinalState(s) {
|
|
19
|
+
return s.final && (s.out.length > 0 || actionsOf(s, 'during').length > 0 || actionsOf(s, 'exit').length > 0 || allContainedStates(s).length > 0);
|
|
20
|
+
}
|
|
21
|
+
function transform(parent, ctx) {
|
|
22
|
+
const termVars = [];
|
|
23
|
+
let state = parent;
|
|
24
|
+
const about = parent.origin ?? parent.about;
|
|
25
|
+
if (!regionsMayTerminate(state)) {
|
|
26
|
+
if (!ctx.config.finalRegions) {
|
|
27
|
+
for (const r of controlflowRegions(state))
|
|
28
|
+
for (const cfs of finalStates(r).filter(isComplexFinalState))
|
|
29
|
+
cfs.final = false;
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (parent.root) {
|
|
34
|
+
const r = createControlflowRegion(parent, '_CFSMain');
|
|
35
|
+
const i = createInitialState(r, '_CFSI');
|
|
36
|
+
const f = createFinalState(r, '_CFSF');
|
|
37
|
+
i.about = about;
|
|
38
|
+
f.about = about;
|
|
39
|
+
for (const main of parent.regions.filter(x => x !== r))
|
|
40
|
+
addRegion(i, main);
|
|
41
|
+
createImmediateTransitionTo(i, f).preemption = 'termination';
|
|
42
|
+
state = i;
|
|
43
|
+
}
|
|
44
|
+
for (const region of controlflowRegions(state)) {
|
|
45
|
+
const allFinal = region.states.length === region.states.filter(s => s.final).length;
|
|
46
|
+
const finals = region.states.filter(s => s.final && (s.incoming.length > 0 || s.initial));
|
|
47
|
+
const complexFinals = finals.filter(isComplexFinalState);
|
|
48
|
+
if (!allFinal) {
|
|
49
|
+
const term = createVar(state.parent.parent, '_CFSterm', 'bool', 'term');
|
|
50
|
+
term.display = `whether ${readableRegionName(region) ? `region \`${region.name}\` of ` : 'a region of '}${readableName(state) ? `\`${readableName(state)}\`` : 'a superstate'} finished`;
|
|
51
|
+
if (!region.states.filter(s => s.final).some(isImmediatelyReachable))
|
|
52
|
+
term.tags.add(ANNOTATION_TERMINATION_DELAYED);
|
|
53
|
+
const reset = createEntryAction(state);
|
|
54
|
+
reset.about = about;
|
|
55
|
+
reset.effects.push(assign(term, FALSE));
|
|
56
|
+
if (region.states.find(s => s.initial)?.final)
|
|
57
|
+
term.init = TRUE;
|
|
58
|
+
termVars.push(term);
|
|
59
|
+
if (!complexFinals.length)
|
|
60
|
+
setRegionTerm(region, term);
|
|
61
|
+
for (const f of finals) {
|
|
62
|
+
for (const t of f.incoming.filter(t => !t.source.final))
|
|
63
|
+
t.effects.push(assign(term, TRUE));
|
|
64
|
+
for (const t of f.out.filter(t => !t.target.final))
|
|
65
|
+
t.effects.push(assign(term, FALSE));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const cfs of complexFinals)
|
|
69
|
+
cfs.final = false;
|
|
70
|
+
}
|
|
71
|
+
for (const t of state.out.filter(t => t.preemption === 'termination')) {
|
|
72
|
+
t.delay = isImplicitlyImmediate(t) ? 'immediate' : 'undefined';
|
|
73
|
+
t.preemption = 'weak';
|
|
74
|
+
addTerminationCheck(t, termVars);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=complexFinalState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complexFinalState.js","sourceRoot":"","sources":["../../../src/sim/passes/complexFinalState.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,gHAAgH;AAChH,gGAAgG;AAChG,6CAA6C;AAG7C,OAAO,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,aAAa,EAAE,yBAAqB;AAClG,OAAO,EACH,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,uBAAuB,EACxG,iBAAiB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAC5G,sBAAsB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAC/E,YAAY,EAAE,kBAAkB,GACnC,oBAAgB;AAEjB,MAAM,CAAC,MAAM,iBAAiB,GAAS;IACnC,EAAE,EAAE,wDAAwD;IAC5D,IA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;oBAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;gBAC3F,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;YAC3F,CAAC;QACL,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,aAAa;YAAE,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;IACtD,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,aAAa,CAAC,EAAE,CAAC;QACpE,CAAC,CAAC,KAAK,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAA;QAC9D,CAAC,CAAC,UAAU,GAAG,MAAM,CAAA;QACrB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;IACpC,CAAC;AACL,CAAC","sourcesContent":["// KIELER's Complex Final State processor (sccharts/processors/ComplexFinalState.xtend): final states with\n// outgoing transitions (or during/exit actions, or inner states) stop being final; a `_CFSterm` flag per region\n// records whether the region is in a final state, and the parent's terminations check the flags\n// (basics.md B-19; concurrency.md T-2, T-8).\n\nimport type { Pass, PassContext } from './context'\nimport { addTerminationCheck, ANNOTATION_TERMINATION_DELAYED, setRegionTerm } from './termination'\nimport {\n actionsOf, addRegion, allContainedStates, allStates, assign, controlflowRegions, createControlflowRegion,\n createEntryAction, createFinalState, createImmediateTransitionTo, createInitialState, createVar, finalStates,\n isImmediatelyReachable, isImplicitlyImmediate, regionsMayTerminate, FALSE, TRUE, type CState, type CVar,\n readableName, readableRegionName,\n} from '../model'\n\nexport const complexFinalState: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.complexFinalState',\n name: 'Complex Final State',\n owner: 'core',\n run(ctx: PassContext) {\n const parents = allStates(ctx.root).filter(s => s.regions.some(r => !r.dataflow && r.states.some(isComplexFinalState)))\n // CREATE_FINAL_REGIONS follows finalRegion.supported, which is false in the netlist chain.\n for (const parent of parents) transform(parent, ctx)\n },\n}\n\nexport function isComplexFinalState(s: CState): boolean {\n return s.final && (s.out.length > 0 || actionsOf(s, 'during').length > 0 || actionsOf(s, 'exit').length > 0 || allContainedStates(s).length > 0)\n}\n\nfunction transform(parent: CState, ctx: PassContext) {\n const termVars: CVar[] = []\n let state = parent\n const about = parent.origin ?? parent.about\n\n if (!regionsMayTerminate(state)) {\n if (!ctx.config.finalRegions) {\n for (const r of controlflowRegions(state)) for (const cfs of finalStates(r).filter(isComplexFinalState)) cfs.final = false\n }\n return\n }\n\n if (parent.root) {\n const r = createControlflowRegion(parent, '_CFSMain')\n const i = createInitialState(r, '_CFSI')\n const f = createFinalState(r, '_CFSF')\n i.about = about\n f.about = about\n for (const main of parent.regions.filter(x => x !== r)) addRegion(i, main)\n createImmediateTransitionTo(i, f).preemption = 'termination'\n state = i\n }\n\n for (const region of controlflowRegions(state)) {\n const allFinal = region.states.length === region.states.filter(s => s.final).length\n const finals = region.states.filter(s => s.final && (s.incoming.length > 0 || s.initial))\n const complexFinals = finals.filter(isComplexFinalState)\n if (!allFinal) {\n const term = createVar(state.parent!.parent, '_CFSterm', 'bool', 'term')\n term.display = `whether ${readableRegionName(region) ? `region \\`${region.name}\\` of ` : 'a region of '}${readableName(state) ? `\\`${readableName(state)}\\`` : 'a superstate'} finished`\n if (!region.states.filter(s => s.final).some(isImmediatelyReachable)) term.tags.add(ANNOTATION_TERMINATION_DELAYED)\n const reset = createEntryAction(state)\n reset.about = about\n reset.effects.push(assign(term, FALSE))\n if (region.states.find(s => s.initial)?.final) term.init = TRUE\n termVars.push(term)\n if (!complexFinals.length) setRegionTerm(region, term)\n for (const f of finals) {\n for (const t of f.incoming.filter(t => !t.source.final)) t.effects.push(assign(term, TRUE))\n for (const t of f.out.filter(t => !t.target.final)) t.effects.push(assign(term, FALSE))\n }\n }\n for (const cfs of complexFinals) cfs.final = false\n }\n\n for (const t of state.out.filter(t => t.preemption === 'termination')) {\n t.delay = isImplicitlyImmediate(t) ? 'immediate' : 'undefined'\n t.preemption = 'weak'\n addTerminationCheck(t, termVars)\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// KIELER's Connector processor (sccharts/processors/Connector.xtend): a connector state becomes a normal state
|
|
2
|
+
// whose outgoing transitions are all immediate (preemption.md P-57).
|
|
3
|
+
import { allStates } from "../model.js";
|
|
4
|
+
export const connector = {
|
|
5
|
+
id: 'de.cau.cs.kieler.sccharts.processors.connector',
|
|
6
|
+
name: 'Connector',
|
|
7
|
+
owner: 'preemption',
|
|
8
|
+
run(ctx) {
|
|
9
|
+
for (const s of allStates(ctx.root)) {
|
|
10
|
+
if (!s.connector)
|
|
11
|
+
continue;
|
|
12
|
+
s.connector = false;
|
|
13
|
+
for (const t of s.out)
|
|
14
|
+
t.delay = 'immediate';
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../../../src/sim/passes/connector.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,qEAAqE;AAGrE,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC,MAAM,CAAC,MAAM,SAAS,GAAS;IAC3B,EAAE,EAAE,gDAAgD;IACpD,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,YAAY;IACnB,GAAG,CAAC,GAAgB;QAChB,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,CAAC,CAAC,SAAS;gBAAE,SAAQ;YAC1B,CAAC,CAAC,SAAS,GAAG,KAAK,CAAA;YACnB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG;gBAAE,CAAC,CAAC,KAAK,GAAG,WAAW,CAAA;QAChD,CAAC;IACL,CAAC;CACJ,CAAA","sourcesContent":["// KIELER's Connector processor (sccharts/processors/Connector.xtend): a connector state becomes a normal state\n// whose outgoing transitions are all immediate (preemption.md P-57).\n\nimport type { Pass, PassContext } from './context'\nimport { allStates } from '../model'\n\nexport const connector: Pass = {\n id: 'de.cau.cs.kieler.sccharts.processors.connector',\n name: 'Connector',\n owner: 'preemption',\n run(ctx: PassContext) {\n for (const s of allStates(ctx.root)) {\n if (!s.connector) continue\n s.connector = false\n for (const t of s.out) t.delay = 'immediate'\n }\n },\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CAction, CRegion, CState, CTransition, type CExpr, type Mark } from "../model.js";
|
|
2
|
+
import type { PassContext } from "./context.js";
|
|
3
|
+
/**
|
|
4
|
+
* eAllContents order of the transitions inside a state: for every state, the contents of its regions first,
|
|
5
|
+
* then its own outgoing transitions (State's `regions` feature comes before `outgoingTransitions`).
|
|
6
|
+
* `self`: include the state's own outgoing transitions.
|
|
7
|
+
*/
|
|
8
|
+
export declare function containedTransitions(state: CState, self?: boolean): CTransition[];
|
|
9
|
+
/**
|
|
10
|
+
* SCChartsScopeExtensions.getAllContainedActions: every action (local actions and transitions, which are actions
|
|
11
|
+
* too) contained in a state, its own local actions and outgoing transitions included.
|
|
12
|
+
*/
|
|
13
|
+
export declare function containedActions(state: CState): (CAction | CTransition)[];
|
|
14
|
+
/** sccAllControlflowRegions(State): every control-flow region inside a state, at any depth, in pre-order. */
|
|
15
|
+
export declare function allContainedControlflowRegions(state: CState): CRegion[];
|
|
16
|
+
/** SCChartsStateExtensions.getInitialStates: the initial state of each control-flow region of a state. */
|
|
17
|
+
export declare function initialStates(state: CState): CState[];
|
|
18
|
+
/** KExpressionsComplexCreateExtensions.and(first, second): `second` alone if there is no first. */
|
|
19
|
+
export declare function and2(first: CExpr | undefined, second: CExpr): CExpr;
|
|
20
|
+
export declare function not(e: CExpr): CExpr;
|
|
21
|
+
export declare function markDoNotDefer(ctx: PassContext, a: CAction): void;
|
|
22
|
+
export declare function isDoNotDefer(ctx: PassContext, a: CAction): boolean;
|
|
23
|
+
export declare function copyAction(a: CAction, ctx?: PassContext): CAction;
|
|
24
|
+
export declare function copyTransitionFields(from: CTransition, to: CTransition): void;
|
|
25
|
+
/**
|
|
26
|
+
* Deep copy of a state with its regions, inner states, actions and inner transitions; the state's own outgoing
|
|
27
|
+
* transitions are not copied (KIELER's callers clear them), nor are declarations (the caller moves them out first,
|
|
28
|
+
* Deferred.makeVariablesPublic, so the copy's expressions refer to the same variables, as in KIELER). The copy keeps
|
|
29
|
+
* `origin`: it is the same state of the chart as written.
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyState(s: CState, ctx: PassContext): CState;
|
|
32
|
+
/** Adds a bookkeeping mark (no KIELER effect) as the first effect of a generated transition. */
|
|
33
|
+
export declare function addMark(t: CTransition, m: Mark): void;
|
|
34
|
+
/** The Taken Transition Signaling marks of a transition (a source transition has one, moved copies too). */
|
|
35
|
+
export declare function takeMarks(t: CTransition): Extract<Mark, {
|
|
36
|
+
kind: 'take';
|
|
37
|
+
}>[];
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Helpers shared by the preemption passes (History, Suspend, Count Delay, Weak Suspend, Deferred, Final Region):
|
|
2
|
+
// KIELER's iteration orders over the EMF containment tree, its `and`/`not` builders, deep copies of states
|
|
3
|
+
// (EcoreUtil.copy), and the bookkeeping the passes leave for the executor (tracker hooks, KIELER's
|
|
4
|
+
// `DoNotDefer` annotation).
|
|
5
|
+
import { CAction, CRegion, CState, CTransition, controlflowRegions, copyEffect, copyExpr, setSource, setTarget, } from "../model.js";
|
|
6
|
+
/**
|
|
7
|
+
* eAllContents order of the transitions inside a state: for every state, the contents of its regions first,
|
|
8
|
+
* then its own outgoing transitions (State's `regions` feature comes before `outgoingTransitions`).
|
|
9
|
+
* `self`: include the state's own outgoing transitions.
|
|
10
|
+
*/
|
|
11
|
+
export function containedTransitions(state, self = true) {
|
|
12
|
+
const out = [];
|
|
13
|
+
const visit = (s, own) => {
|
|
14
|
+
for (const r of s.regions)
|
|
15
|
+
for (const c of r.states)
|
|
16
|
+
visit(c, true);
|
|
17
|
+
if (own)
|
|
18
|
+
out.push(...s.out);
|
|
19
|
+
};
|
|
20
|
+
visit(state, self);
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SCChartsScopeExtensions.getAllContainedActions: every action (local actions and transitions, which are actions
|
|
25
|
+
* too) contained in a state, its own local actions and outgoing transitions included.
|
|
26
|
+
*/
|
|
27
|
+
export function containedActions(state) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const visitState = (s) => {
|
|
30
|
+
out.push(...s.actions);
|
|
31
|
+
for (const r of s.regions)
|
|
32
|
+
visitRegion(r);
|
|
33
|
+
out.push(...s.out);
|
|
34
|
+
};
|
|
35
|
+
const visitRegion = (r) => {
|
|
36
|
+
out.push(...r.actions);
|
|
37
|
+
for (const c of r.states)
|
|
38
|
+
visitState(c);
|
|
39
|
+
};
|
|
40
|
+
visitState(state);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** sccAllControlflowRegions(State): every control-flow region inside a state, at any depth, in pre-order. */
|
|
44
|
+
export function allContainedControlflowRegions(state) {
|
|
45
|
+
const out = [];
|
|
46
|
+
const visit = (r) => {
|
|
47
|
+
out.push(r);
|
|
48
|
+
for (const s of r.states)
|
|
49
|
+
for (const c of controlflowRegions(s))
|
|
50
|
+
visit(c);
|
|
51
|
+
};
|
|
52
|
+
for (const r of controlflowRegions(state))
|
|
53
|
+
visit(r);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/** SCChartsStateExtensions.getInitialStates: the initial state of each control-flow region of a state. */
|
|
57
|
+
export function initialStates(state) {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const r of controlflowRegions(state)) {
|
|
60
|
+
const i = r.states.find(s => s.initial);
|
|
61
|
+
if (i)
|
|
62
|
+
out.push(i);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/** KExpressionsComplexCreateExtensions.and(first, second): `second` alone if there is no first. */
|
|
67
|
+
export function and2(first, second) {
|
|
68
|
+
if (first === undefined)
|
|
69
|
+
return second;
|
|
70
|
+
return { k: 'op', op: '&&', args: [first, second] };
|
|
71
|
+
}
|
|
72
|
+
export function not(e) {
|
|
73
|
+
return { k: 'op', op: '!', args: [e] };
|
|
74
|
+
}
|
|
75
|
+
// ---------------------------------------------------------------------------------------------------
|
|
76
|
+
// DoNotDefer (Deferred.DO_NOT_DEFER): entry actions that Deferred must keep (the count delay's counter reset)
|
|
77
|
+
// ---------------------------------------------------------------------------------------------------
|
|
78
|
+
function doNotDeferSet(ctx) {
|
|
79
|
+
let set = ctx.shared.doNotDefer;
|
|
80
|
+
if (!set)
|
|
81
|
+
ctx.shared.doNotDefer = set = new WeakSet();
|
|
82
|
+
return set;
|
|
83
|
+
}
|
|
84
|
+
export function markDoNotDefer(ctx, a) {
|
|
85
|
+
doNotDeferSet(ctx).add(a);
|
|
86
|
+
}
|
|
87
|
+
export function isDoNotDefer(ctx, a) {
|
|
88
|
+
return doNotDeferSet(ctx).has(a);
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------------------------------
|
|
91
|
+
// Copies (EcoreUtil.copy of a state: its whole containment tree, references inside the copy point to the copies)
|
|
92
|
+
// ---------------------------------------------------------------------------------------------------
|
|
93
|
+
export function copyAction(a, ctx) {
|
|
94
|
+
const c = new CAction(a.kind);
|
|
95
|
+
c.delay = a.delay;
|
|
96
|
+
c.preemption = a.preemption;
|
|
97
|
+
c.weak = a.weak;
|
|
98
|
+
c.triggerDelay = a.triggerDelay;
|
|
99
|
+
c.trigger = copyExpr(a.trigger);
|
|
100
|
+
c.effects = a.effects.map(copyEffect);
|
|
101
|
+
c.origin = a.origin;
|
|
102
|
+
c.about = a.about;
|
|
103
|
+
c.span = a.span;
|
|
104
|
+
if (ctx && isDoNotDefer(ctx, a))
|
|
105
|
+
markDoNotDefer(ctx, c);
|
|
106
|
+
return c;
|
|
107
|
+
}
|
|
108
|
+
export function copyTransitionFields(from, to) {
|
|
109
|
+
to.delay = from.delay;
|
|
110
|
+
to.preemption = from.preemption;
|
|
111
|
+
to.trigger = copyExpr(from.trigger);
|
|
112
|
+
to.effects = from.effects.map(copyEffect);
|
|
113
|
+
to.triggerDelay = from.triggerDelay;
|
|
114
|
+
to.history = from.history;
|
|
115
|
+
to.deferred = from.deferred;
|
|
116
|
+
to.origin = from.origin;
|
|
117
|
+
to.about = from.about;
|
|
118
|
+
to.checks = from.checks;
|
|
119
|
+
to.span = from.span;
|
|
120
|
+
to.annotations = new Map([...from.annotations].map(([k, v]) => [k, [...v]]));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Deep copy of a state with its regions, inner states, actions and inner transitions; the state's own outgoing
|
|
124
|
+
* transitions are not copied (KIELER's callers clear them), nor are declarations (the caller moves them out first,
|
|
125
|
+
* Deferred.makeVariablesPublic, so the copy's expressions refer to the same variables, as in KIELER). The copy keeps
|
|
126
|
+
* `origin`: it is the same state of the chart as written.
|
|
127
|
+
*/
|
|
128
|
+
export function copyState(s, ctx) {
|
|
129
|
+
const map = new Map();
|
|
130
|
+
const pending = [];
|
|
131
|
+
const copyS = (x, own) => {
|
|
132
|
+
const c = new CState(x.name);
|
|
133
|
+
map.set(x, c);
|
|
134
|
+
c.label = x.label;
|
|
135
|
+
c.initial = x.initial;
|
|
136
|
+
c.final = x.final;
|
|
137
|
+
c.connector = x.connector;
|
|
138
|
+
c.violation = x.violation;
|
|
139
|
+
c.root = x.root;
|
|
140
|
+
// EcoreUtil.copy would copy the declarations too; Deferred, the only caller, has moved them out already.
|
|
141
|
+
c.decls = [];
|
|
142
|
+
c.actions = x.actions.map(a => copyAction(a, ctx));
|
|
143
|
+
c.origin = x.origin;
|
|
144
|
+
c.about = x.about;
|
|
145
|
+
c.annotations = new Map([...x.annotations].map(([k, v]) => [k, [...v]]));
|
|
146
|
+
c.ext = { ...x.ext };
|
|
147
|
+
for (const r of x.regions) {
|
|
148
|
+
const cr = new CRegion();
|
|
149
|
+
cr.name = r.name;
|
|
150
|
+
cr.label = r.label;
|
|
151
|
+
cr.parent = c;
|
|
152
|
+
cr.decls = [];
|
|
153
|
+
cr.actions = r.actions.map(a => copyAction(a, ctx));
|
|
154
|
+
cr.origin = r.origin;
|
|
155
|
+
cr.about = r.about;
|
|
156
|
+
cr.dataflow = r.dataflow;
|
|
157
|
+
cr.final = r.final;
|
|
158
|
+
cr.abort = r.abort;
|
|
159
|
+
cr.override = r.override;
|
|
160
|
+
cr.annotations = new Map([...r.annotations].map(([k, v]) => [k, [...v]]));
|
|
161
|
+
cr.ext = { ...r.ext };
|
|
162
|
+
c.regions.push(cr);
|
|
163
|
+
for (const inner of r.states) {
|
|
164
|
+
const ci = copyS(inner, true);
|
|
165
|
+
ci.parent = cr;
|
|
166
|
+
cr.states.push(ci);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (own)
|
|
170
|
+
for (const t of x.out)
|
|
171
|
+
pending.push([t, c]);
|
|
172
|
+
return c;
|
|
173
|
+
};
|
|
174
|
+
const copy = copyS(s, false);
|
|
175
|
+
for (const [t, source] of pending) {
|
|
176
|
+
const c = new CTransition();
|
|
177
|
+
copyTransitionFields(t, c);
|
|
178
|
+
setTarget(c, map.get(t.target) ?? t.target);
|
|
179
|
+
setSource(c, source);
|
|
180
|
+
}
|
|
181
|
+
return copy;
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------------------------------
|
|
184
|
+
// Tracker hooks: bookkeeping marks for the source-level configuration (tracker.ts)
|
|
185
|
+
// ---------------------------------------------------------------------------------------------------
|
|
186
|
+
/** Adds a bookkeeping mark (no KIELER effect) as the first effect of a generated transition. */
|
|
187
|
+
export function addMark(t, m) {
|
|
188
|
+
t.effects.unshift({ k: 'mark', m, o: { hidden: true } });
|
|
189
|
+
}
|
|
190
|
+
/** The Taken Transition Signaling marks of a transition (a source transition has one, moved copies too). */
|
|
191
|
+
export function takeMarks(t) {
|
|
192
|
+
const out = [];
|
|
193
|
+
for (const f of t.effects)
|
|
194
|
+
if (f.k === 'mark' && f.m.kind === 'take')
|
|
195
|
+
out.push(f.m);
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=contained.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contained.js","sourceRoot":"","sources":["../../../src/sim/passes/contained.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,2GAA2G;AAC3G,mGAAmG;AACnG,4BAA4B;AAE5B,OAAO,EACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GAExG,oBAAgB;AAGjB;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa,EAAE,IAAI,GAAG,IAAI;IAC3D,MAAM,GAAG,GAAkB,EAAE,CAAA;IAC7B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,GAAY,EAAE,EAAE;QACtC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;YAAE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM;gBAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;QACnE,IAAI,GAAG;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC,CAAA;IACD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAClB,OAAO,GAAG,CAAA;AACd,CAAC;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C,CAAC,MAAM,CAAC,CAAA;QAC3C,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,sGAAsG;AACtG,mFAAmF;AACnF,sGAAsG;AAEtG,gGAAgG;AAChG,MAAM,UAAU,OAAO,CAAC,CAAc,EAAE,CAAO;IAC3C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;AAC5D,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,SAAS,CAAC,CAAc;IACpC,MAAM,GAAG,GAAsC,EAAE,CAAA;IACjD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;QAAE,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM;YAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnF,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["// Helpers shared by the preemption passes (History, Suspend, Count Delay, Weak Suspend, Deferred, Final Region):\n// KIELER's iteration orders over the EMF containment tree, its `and`/`not` builders, deep copies of states\n// (EcoreUtil.copy), and the bookkeeping the passes leave for the executor (tracker hooks, KIELER's\n// `DoNotDefer` annotation).\n\nimport {\n CAction, CRegion, CState, CTransition, controlflowRegions, copyEffect, copyExpr, setSource, setTarget,\n type CExpr, type Mark,\n} from '../model'\nimport type { PassContext } from './context'\n\n/**\n * eAllContents order of the transitions inside a state: for every state, the contents of its regions first,\n * then its own outgoing transitions (State's `regions` feature comes before `outgoingTransitions`).\n * `self`: include the state's own outgoing transitions.\n */\nexport function containedTransitions(state: CState, self = true): CTransition[] {\n const out: CTransition[] = []\n const visit = (s: CState, own: boolean) => {\n for (const r of s.regions) for (const c of r.states) visit(c, true)\n if (own) out.push(...s.out)\n }\n visit(state, self)\n return out\n}\n\n/**\n * SCChartsScopeExtensions.getAllContainedActions: every action (local actions and transitions, which are actions\n * too) contained in a state, its own local actions and outgoing transitions included.\n */\nexport function containedActions(state: CState): (CAction | CTransition)[] {\n const out: (CAction | CTransition)[] = []\n const visitState = (s: CState) => {\n out.push(...s.actions)\n for (const r of s.regions) visitRegion(r)\n out.push(...s.out)\n }\n const visitRegion = (r: CRegion) => {\n out.push(...r.actions)\n for (const c of r.states) visitState(c)\n }\n visitState(state)\n return out\n}\n\n/** sccAllControlflowRegions(State): every control-flow region inside a state, at any depth, in pre-order. */\nexport function allContainedControlflowRegions(state: CState): CRegion[] {\n const out: CRegion[] = []\n const visit = (r: CRegion) => {\n out.push(r)\n for (const s of r.states) for (const c of controlflowRegions(s)) visit(c)\n }\n for (const r of controlflowRegions(state)) visit(r)\n return out\n}\n\n/** SCChartsStateExtensions.getInitialStates: the initial state of each control-flow region of a state. */\nexport function initialStates(state: CState): CState[] {\n const out: CState[] = []\n for (const r of controlflowRegions(state)) {\n const i = r.states.find(s => s.initial)\n if (i) out.push(i)\n }\n return out\n}\n\n/** KExpressionsComplexCreateExtensions.and(first, second): `second` alone if there is no first. */\nexport function and2(first: CExpr | undefined, second: CExpr): CExpr {\n if (first === undefined) return second\n return { k: 'op', op: '&&', args: [first, second] }\n}\n\nexport function not(e: CExpr): CExpr {\n return { k: 'op', op: '!', args: [e] }\n}\n\n// ---------------------------------------------------------------------------------------------------\n// DoNotDefer (Deferred.DO_NOT_DEFER): entry actions that Deferred must keep (the count delay's counter reset)\n// ---------------------------------------------------------------------------------------------------\n\nfunction doNotDeferSet(ctx: PassContext): WeakSet<CAction> {\n let set = ctx.shared.doNotDefer as WeakSet<CAction> | undefined\n if (!set) ctx.shared.doNotDefer = set = new WeakSet<CAction>()\n return set\n}\n\nexport function markDoNotDefer(ctx: PassContext, a: CAction) {\n doNotDeferSet(ctx).add(a)\n}\n\nexport function isDoNotDefer(ctx: PassContext, a: CAction): boolean {\n return doNotDeferSet(ctx).has(a)\n}\n\n// ---------------------------------------------------------------------------------------------------\n// Copies (EcoreUtil.copy of a state: its whole containment tree, references inside the copy point to the copies)\n// ---------------------------------------------------------------------------------------------------\n\nexport function copyAction(a: CAction, ctx?: PassContext): CAction {\n const c = new CAction(a.kind)\n c.delay = a.delay\n c.preemption = a.preemption\n c.weak = a.weak\n c.triggerDelay = a.triggerDelay\n c.trigger = copyExpr(a.trigger)\n c.effects = a.effects.map(copyEffect)\n c.origin = a.origin\n c.about = a.about\n c.span = a.span\n if (ctx && isDoNotDefer(ctx, a)) markDoNotDefer(ctx, c)\n return c\n}\n\nexport function copyTransitionFields(from: CTransition, to: CTransition) {\n to.delay = from.delay\n to.preemption = from.preemption\n to.trigger = copyExpr(from.trigger)\n to.effects = from.effects.map(copyEffect)\n to.triggerDelay = from.triggerDelay\n to.history = from.history\n to.deferred = from.deferred\n to.origin = from.origin\n to.about = from.about\n to.checks = from.checks\n to.span = from.span\n to.annotations = new Map([...from.annotations].map(([k, v]) => [k, [...v]]))\n}\n\n/**\n * Deep copy of a state with its regions, inner states, actions and inner transitions; the state's own outgoing\n * transitions are not copied (KIELER's callers clear them), nor are declarations (the caller moves them out first,\n * Deferred.makeVariablesPublic, so the copy's expressions refer to the same variables, as in KIELER). The copy keeps\n * `origin`: it is the same state of the chart as written.\n */\nexport function copyState(s: CState, ctx: PassContext): CState {\n const map = new Map<CState, CState>()\n const pending: [CTransition, CState][] = []\n const copyS = (x: CState, own: boolean): CState => {\n const c = new CState(x.name)\n map.set(x, c)\n c.label = x.label\n c.initial = x.initial\n c.final = x.final\n c.connector = x.connector\n c.violation = x.violation\n c.root = x.root\n // EcoreUtil.copy would copy the declarations too; Deferred, the only caller, has moved them out already.\n c.decls = []\n c.actions = x.actions.map(a => copyAction(a, ctx))\n c.origin = x.origin\n c.about = x.about\n c.annotations = new Map([...x.annotations].map(([k, v]) => [k, [...v]]))\n c.ext = { ...x.ext }\n for (const r of x.regions) {\n const cr = new CRegion()\n cr.name = r.name\n cr.label = r.label\n cr.parent = c\n cr.decls = []\n cr.actions = r.actions.map(a => copyAction(a, ctx))\n cr.origin = r.origin\n cr.about = r.about\n cr.dataflow = r.dataflow\n cr.final = r.final\n cr.abort = r.abort\n cr.override = r.override\n cr.annotations = new Map([...r.annotations].map(([k, v]) => [k, [...v]]))\n cr.ext = { ...r.ext }\n c.regions.push(cr)\n for (const inner of r.states) {\n const ci = copyS(inner, true)\n ci.parent = cr\n cr.states.push(ci)\n }\n }\n if (own) for (const t of x.out) pending.push([t, c])\n return c\n }\n const copy = copyS(s, false)\n for (const [t, source] of pending) {\n const c = new CTransition()\n copyTransitionFields(t, c)\n setTarget(c, map.get(t.target) ?? t.target)\n setSource(c, source)\n }\n return copy\n}\n\n// ---------------------------------------------------------------------------------------------------\n// Tracker hooks: bookkeeping marks for the source-level configuration (tracker.ts)\n// ---------------------------------------------------------------------------------------------------\n\n/** Adds a bookkeeping mark (no KIELER effect) as the first effect of a generated transition. */\nexport function addMark(t: CTransition, m: Mark) {\n t.effects.unshift({ k: 'mark', m, o: { hidden: true } })\n}\n\n/** The Taken Transition Signaling marks of a transition (a source transition has one, moved copies too). */\nexport function takeMarks(t: CTransition): Extract<Mark, { kind: 'take' }>[] {\n const out: Extract<Mark, { kind: 'take' }>[] = []\n for (const f of t.effects) if (f.k === 'mark' && f.m.kind === 'take') out.push(f.m)\n return out\n}\n"]}
|