@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,110 @@
|
|
|
1
|
+
// What runs in reset(): KIELER's GO-init optimisation moves the assignments of tick 1's straight-line start (the GO
|
|
2
|
+
// block) whose right-hand side reads no input into reset(), before the environment's first inputs (sim/goblock.ts).
|
|
3
|
+
//
|
|
4
|
+
// For inputs that is what the simulator does too (basics.md B-7: the environment's tick-1 value wins), so those always
|
|
5
|
+
// move. For everything else the simulator runs the effect in tick 1 at its place (B-34: KIELER's move can reorder
|
|
6
|
+
// it around input reads), so an effect moves only where that makes no difference: nothing earlier in the schedule
|
|
7
|
+
// (that stays in logic) writes or reads what it writes, or writes what it reads; printed text and random() count as
|
|
8
|
+
// variables of their own. Host code moves as in KIELER (the simulator does not run it). Initialisations
|
|
9
|
+
// (`output int x = 0`) and tick-1 prints move, as in KIELER.
|
|
10
|
+
import { walkExpr } from "../sim/model.js";
|
|
11
|
+
const ALL = Symbol('everything');
|
|
12
|
+
const OUTPUT = Symbol('printed text');
|
|
13
|
+
const RANDOM = Symbol('random()');
|
|
14
|
+
function accessesOf(n) {
|
|
15
|
+
const a = { reads: new Set(), writes: new Set(), host: false };
|
|
16
|
+
const visit = (e) => {
|
|
17
|
+
if (e.k === 'ref')
|
|
18
|
+
a.reads.add(e.v);
|
|
19
|
+
else if (e.k === 'random') {
|
|
20
|
+
a.reads.add(RANDOM);
|
|
21
|
+
a.writes.add(RANDOM);
|
|
22
|
+
}
|
|
23
|
+
else if (e.k === 'host') {
|
|
24
|
+
a.host = true;
|
|
25
|
+
a.reads.add(ALL);
|
|
26
|
+
a.writes.add(ALL);
|
|
27
|
+
}
|
|
28
|
+
else if (e.k === 'call') {
|
|
29
|
+
a.reads.add(ALL);
|
|
30
|
+
a.writes.add(ALL);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
if (n.kind === 'cond')
|
|
34
|
+
walkExpr(n.expr, visit);
|
|
35
|
+
if (n.effect)
|
|
36
|
+
effectAccesses(n.effect, a, visit);
|
|
37
|
+
return a;
|
|
38
|
+
}
|
|
39
|
+
function effectAccesses(f, a, visit) {
|
|
40
|
+
switch (f.k) {
|
|
41
|
+
case 'assign':
|
|
42
|
+
for (const i of f.ref.idx)
|
|
43
|
+
walkExpr(i, visit);
|
|
44
|
+
walkExpr(f.expr, visit);
|
|
45
|
+
if (f.op !== '=')
|
|
46
|
+
a.reads.add(f.ref.v);
|
|
47
|
+
a.writes.add(f.ref.v);
|
|
48
|
+
break;
|
|
49
|
+
case 'print':
|
|
50
|
+
f.args.forEach(x => walkExpr(x, visit));
|
|
51
|
+
a.reads.add(OUTPUT);
|
|
52
|
+
a.writes.add(OUTPUT);
|
|
53
|
+
break;
|
|
54
|
+
case 'host':
|
|
55
|
+
a.host = true;
|
|
56
|
+
a.reads.add(ALL);
|
|
57
|
+
a.writes.add(ALL);
|
|
58
|
+
break;
|
|
59
|
+
case 'call':
|
|
60
|
+
case 'randomize':
|
|
61
|
+
a.reads.add(ALL);
|
|
62
|
+
a.writes.add(ALL);
|
|
63
|
+
break;
|
|
64
|
+
default: break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const meets = (a, b) => {
|
|
68
|
+
if ((a.has(ALL) && b.size) || (b.has(ALL) && a.size))
|
|
69
|
+
return true;
|
|
70
|
+
for (const x of a)
|
|
71
|
+
if (b.has(x))
|
|
72
|
+
return true;
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The schedule positions of the effects that run in reset() instead of logic(), in the GO block's order: tick 1's
|
|
77
|
+
* input assignments (exec.ts goInit) and the moved effects that make no difference there.
|
|
78
|
+
*/
|
|
79
|
+
export function resetNodes(exe) {
|
|
80
|
+
const nodes = exe.nodes;
|
|
81
|
+
const moved = exe.compiled.goBlock.moved;
|
|
82
|
+
const position = new Map(nodes.map((x, i) => [x.src, i]));
|
|
83
|
+
const out = [];
|
|
84
|
+
const inReset = new Set();
|
|
85
|
+
const acc = nodes.map(x => accessesOf(x.src));
|
|
86
|
+
// In the GO block's order (exec.ts runs KIELER's reset() in that order).
|
|
87
|
+
for (const n of exe.compiled.goBlock.nodes) {
|
|
88
|
+
const i = position.get(n);
|
|
89
|
+
if (i === undefined || !moved.has(n))
|
|
90
|
+
continue;
|
|
91
|
+
const f = n.effect;
|
|
92
|
+
let safe = !!nodes[i].goInit || (f?.k === 'mark' && f.m.kind === 'ttsReset') || acc[i].host;
|
|
93
|
+
if (!safe && (f?.k === 'assign' || f?.k === 'print') && !acc[i].reads.has(ALL) && ![...acc[i].reads].some(v => typeof v !== 'symbol' && v.input)) {
|
|
94
|
+
const { reads, writes } = acc[i];
|
|
95
|
+
safe = true;
|
|
96
|
+
for (let k = 0; k < i && safe; k++) {
|
|
97
|
+
if (inReset.has(k))
|
|
98
|
+
continue;
|
|
99
|
+
if (meets(acc[k].writes, writes) || meets(acc[k].reads, writes) || meets(acc[k].writes, reads))
|
|
100
|
+
safe = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!safe)
|
|
104
|
+
continue;
|
|
105
|
+
inReset.add(i);
|
|
106
|
+
out.push(i);
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=reset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reset.js","sourceRoot":"","sources":["../../src/cod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,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC;oBAAE,IAAI,GAAG,KAAK,CAAA;YAChH,CAAC;QACL,CAAC;QACD,IAAI,CAAC,IAAI;YAAE,SAAQ;QACnB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACd,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACf,CAAC;IACD,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["// What runs in reset(): KIELER's GO-init optimisation moves the assignments of tick 1's straight-line start (the GO\n// block) whose right-hand side reads no input into reset(), before the environment's first inputs (sim/goblock.ts).\n//\n// For inputs that is what the simulator does too (basics.md B-7: the environment's tick-1 value wins), so those always\n// move. For everything else the simulator runs the effect in tick 1 at its place (B-34: KIELER's move can reorder\n// it around input reads), so an effect moves only where that makes no difference: nothing earlier in the schedule\n// (that stays in logic) writes or reads what it writes, or writes what it reads; printed text and random() count as\n// variables of their own. Host code moves as in KIELER (the simulator does not run it). Initialisations\n// (`output int x = 0`) and tick-1 prints move, as in KIELER.\n\nimport type { ExecutableChart } from '../sim/exec'\nimport { walkExpr, type CEffect, type CExpr, type CVar } from '../sim/model'\nimport type { SNode } from '../sim/scg'\n\nconst ALL = Symbol('everything')\nconst OUTPUT = Symbol('printed text')\nconst RANDOM = Symbol('random()')\ntype Item = CVar | typeof ALL | typeof OUTPUT | typeof RANDOM\ntype Access = Set<Item>\n\ninterface Accesses { reads: Access; writes: Access; host: boolean }\n\nfunction accessesOf(n: SNode): Accesses {\n const a: Accesses = { reads: new Set(), writes: new Set(), host: false }\n const visit = (e: CExpr) => {\n if (e.k === 'ref') a.reads.add(e.v)\n else if (e.k === 'random') { a.reads.add(RANDOM); a.writes.add(RANDOM) }\n else if (e.k === 'host') { a.host = true; a.reads.add(ALL); a.writes.add(ALL) }\n else if (e.k === 'call') { a.reads.add(ALL); a.writes.add(ALL) }\n }\n if (n.kind === 'cond') walkExpr(n.expr, visit)\n if (n.effect) effectAccesses(n.effect, a, visit)\n return a\n}\n\nfunction effectAccesses(f: CEffect, a: Accesses, visit: (e: CExpr) => void) {\n switch (f.k) {\n case 'assign':\n for (const i of f.ref.idx) walkExpr(i, visit)\n walkExpr(f.expr, visit)\n if (f.op !== '=') a.reads.add(f.ref.v)\n a.writes.add(f.ref.v)\n break\n case 'print': f.args.forEach(x => walkExpr(x, visit)); a.reads.add(OUTPUT); a.writes.add(OUTPUT); break\n case 'host': a.host = true; a.reads.add(ALL); a.writes.add(ALL); break\n case 'call': case 'randomize': a.reads.add(ALL); a.writes.add(ALL); break\n default: break\n }\n}\n\nconst meets = (a: Access, b: Access) => {\n if ((a.has(ALL) && b.size) || (b.has(ALL) && a.size)) return true\n for (const x of a) if (b.has(x)) return true\n return false\n}\n\n/**\n * The schedule positions of the effects that run in reset() instead of logic(), in the GO block's order: tick 1's\n * input assignments (exec.ts goInit) and the moved effects that make no difference there.\n */\nexport function resetNodes(exe: ExecutableChart): number[] {\n const nodes = exe.nodes\n const moved = exe.compiled.goBlock.moved\n const position = new Map(nodes.map((x, i) => [x.src, i]))\n const out: number[] = []\n const inReset = new Set<number>()\n const acc = nodes.map(x => accessesOf(x.src))\n // In the GO block's order (exec.ts runs KIELER's reset() in that order).\n for (const n of exe.compiled.goBlock.nodes) {\n const i = position.get(n)\n if (i === undefined || !moved.has(n)) continue\n const f = n.effect\n let safe = !!nodes[i].goInit || (f?.k === 'mark' && f.m.kind === 'ttsReset') || acc[i].host\n if (!safe && (f?.k === 'assign' || f?.k === 'print') && !acc[i].reads.has(ALL) && ![...acc[i].reads].some(v => typeof v !== 'symbol' && v.input)) {\n const { reads, writes } = acc[i]\n safe = true\n for (let k = 0; k < i && safe; k++) {\n if (inReset.has(k)) continue\n if (meets(acc[k].writes, writes) || meets(acc[k].reads, writes) || meets(acc[k].writes, reads)) safe = false\n }\n }\n if (!safe) continue\n inReset.add(i)\n out.push(i)\n }\n return out\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Diagnostic } from "../types.js";
|
|
2
|
+
/** KIELER's `#code.naming`: the names of the generated functions and of the struct. */
|
|
3
|
+
export interface CNaming {
|
|
4
|
+
tick: string;
|
|
5
|
+
reset: string;
|
|
6
|
+
logic: string;
|
|
7
|
+
struct: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GenerateCOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Names of the functions and the struct. `'prefix'` and `'suffix'` add the chart's name as KIELER's
|
|
12
|
+
* `#code.naming "prefix"` / `"suffix"` do (`ABROtick`, `tickABRO`); an object sets any of them. Default: the chart's
|
|
13
|
+
* own `#code.naming` pragma, else KIELER's `tick`, `reset`, `logic` and `TickData`.
|
|
14
|
+
*/
|
|
15
|
+
naming?: 'default' | 'prefix' | 'suffix' | Partial<CNaming>;
|
|
16
|
+
/**
|
|
17
|
+
* Count the fired transitions in `int _taken_transitions[n]`, as KIELER's simulation chain does (Taken Transition
|
|
18
|
+
* Signaling: index order of `Simulation.takenCounts`). Off by default: KIELER's plain C chain has no counters.
|
|
19
|
+
*/
|
|
20
|
+
takenTransitions?: boolean;
|
|
21
|
+
/** Comments naming the source states and transitions (default true). */
|
|
22
|
+
comments?: boolean;
|
|
23
|
+
/** Base name of the two files (default: the chart's name): `<fileName>.h` and `<fileName>.c`. */
|
|
24
|
+
fileName?: string;
|
|
25
|
+
}
|
|
26
|
+
/** A variable of the chart as it lives in the generated struct. */
|
|
27
|
+
export interface CVariable {
|
|
28
|
+
/** The name in the chart (`count`, `seconds`; a member as `home.count`). */
|
|
29
|
+
name: string;
|
|
30
|
+
/** The member of the struct: `d->` + this is the C lvalue (`count`, `_Chart_local_seconds`, `home.count`). */
|
|
31
|
+
member: string;
|
|
32
|
+
/** The C type of one element: `char` (bool), `int`, `double` (float), `char*` (string), or a host type. */
|
|
33
|
+
ctype: string;
|
|
34
|
+
/** The simulator's type: 'bool', 'int', 'float', 'string' or 'host'. */
|
|
35
|
+
type: 'bool' | 'int' | 'float' | 'string' | 'host';
|
|
36
|
+
/** Array sizes (empty for a scalar). */
|
|
37
|
+
dims: number[];
|
|
38
|
+
input: boolean;
|
|
39
|
+
output: boolean;
|
|
40
|
+
/** The key under which KIELER's simulation reports it (its data pool), when it does. */
|
|
41
|
+
pool?: string;
|
|
42
|
+
/** For a member of a class or struct instance in the pool: the instance's pool key. */
|
|
43
|
+
poolObject?: string;
|
|
44
|
+
/** A valued signal's presence (`S`), value (`S_val`) or the value being emitted (`S_curval`). */
|
|
45
|
+
signal?: 'presence' | 'value' | 'curval';
|
|
46
|
+
}
|
|
47
|
+
export interface GeneratedC {
|
|
48
|
+
/** Code was generated (the chart compiles and the generator understood everything in it). */
|
|
49
|
+
ok: boolean;
|
|
50
|
+
/** The generated chart's name. */
|
|
51
|
+
chart: string;
|
|
52
|
+
/** File name -> contents: `<Chart>.h` and `<Chart>.c`. */
|
|
53
|
+
files: Record<string, string>;
|
|
54
|
+
/** The header's and the C file's names (keys of `files`). */
|
|
55
|
+
header: string;
|
|
56
|
+
source: string;
|
|
57
|
+
names: CNaming;
|
|
58
|
+
/** The chart's variables in the struct, in struct order (KIELER's helpers, `_g...`, are not listed). */
|
|
59
|
+
variables: CVariable[];
|
|
60
|
+
/**
|
|
61
|
+
* Instances of classes, structs and charts used as classes: the struct member and its typedef. `pool`: KIELER's
|
|
62
|
+
* data pool reports the instance as an object under this key even when it has no fields (`{}`).
|
|
63
|
+
*/
|
|
64
|
+
instances: {
|
|
65
|
+
name: string;
|
|
66
|
+
member: string;
|
|
67
|
+
ctype: string;
|
|
68
|
+
pool?: string;
|
|
69
|
+
}[];
|
|
70
|
+
/** Why there is no code (errors), or what to know about it (warnings, infos). */
|
|
71
|
+
diagnostics: Diagnostic[];
|
|
72
|
+
/** The chart uses host code (backticks, `extern`, host types, `#hostcode`): the C code carries it as written. */
|
|
73
|
+
hostCode: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The guide's simulator runs the chart too, and the code computes what the simulation shows (tools/cgen checks
|
|
76
|
+
* that). False for host code and recursive methods, which only C can run (checked against KIELER's recordings).
|
|
77
|
+
*/
|
|
78
|
+
simulated: boolean;
|
|
79
|
+
/** `_taken_transitions` has this many counters (takenTransitions option), in Taken Transition Signaling order. */
|
|
80
|
+
takenTransitions?: string[];
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/codegen/types.ts"],"names":[],"mappings":"AAAA,6DAA6D","sourcesContent":["// The C code generator's public types (index.ts: generateC).\n\nimport type { Diagnostic } from '../types'\n\n/** KIELER's `#code.naming`: the names of the generated functions and of the struct. */\nexport interface CNaming {\n tick: string\n reset: string\n logic: string\n struct: string\n}\n\nexport interface GenerateCOptions {\n /**\n * Names of the functions and the struct. `'prefix'` and `'suffix'` add the chart's name as KIELER's\n * `#code.naming \"prefix\"` / `\"suffix\"` do (`ABROtick`, `tickABRO`); an object sets any of them. Default: the chart's\n * own `#code.naming` pragma, else KIELER's `tick`, `reset`, `logic` and `TickData`.\n */\n naming?: 'default' | 'prefix' | 'suffix' | Partial<CNaming>\n /**\n * Count the fired transitions in `int _taken_transitions[n]`, as KIELER's simulation chain does (Taken Transition\n * Signaling: index order of `Simulation.takenCounts`). Off by default: KIELER's plain C chain has no counters.\n */\n takenTransitions?: boolean\n /** Comments naming the source states and transitions (default true). */\n comments?: boolean\n /** Base name of the two files (default: the chart's name): `<fileName>.h` and `<fileName>.c`. */\n fileName?: string\n}\n\n/** A variable of the chart as it lives in the generated struct. */\nexport interface CVariable {\n /** The name in the chart (`count`, `seconds`; a member as `home.count`). */\n name: string\n /** The member of the struct: `d->` + this is the C lvalue (`count`, `_Chart_local_seconds`, `home.count`). */\n member: string\n /** The C type of one element: `char` (bool), `int`, `double` (float), `char*` (string), or a host type. */\n ctype: string\n /** The simulator's type: 'bool', 'int', 'float', 'string' or 'host'. */\n type: 'bool' | 'int' | 'float' | 'string' | 'host'\n /** Array sizes (empty for a scalar). */\n dims: number[]\n input: boolean\n output: boolean\n /** The key under which KIELER's simulation reports it (its data pool), when it does. */\n pool?: string\n /** For a member of a class or struct instance in the pool: the instance's pool key. */\n poolObject?: string\n /** A valued signal's presence (`S`), value (`S_val`) or the value being emitted (`S_curval`). */\n signal?: 'presence' | 'value' | 'curval'\n}\n\nexport interface GeneratedC {\n /** Code was generated (the chart compiles and the generator understood everything in it). */\n ok: boolean\n /** The generated chart's name. */\n chart: string\n /** File name -> contents: `<Chart>.h` and `<Chart>.c`. */\n files: Record<string, string>\n /** The header's and the C file's names (keys of `files`). */\n header: string\n source: string\n names: CNaming\n /** The chart's variables in the struct, in struct order (KIELER's helpers, `_g...`, are not listed). */\n variables: CVariable[]\n /**\n * Instances of classes, structs and charts used as classes: the struct member and its typedef. `pool`: KIELER's\n * data pool reports the instance as an object under this key even when it has no fields (`{}`).\n */\n instances: { name: string; member: string; ctype: string; pool?: string }[]\n /** Why there is no code (errors), or what to know about it (warnings, infos). */\n diagnostics: Diagnostic[]\n /** The chart uses host code (backticks, `extern`, host types, `#hostcode`): the C code carries it as written. */\n hostCode: boolean\n /**\n * The guide's simulator runs the chart too, and the code computes what the simulation shows (tools/cgen checks\n * that). False for host code and recursive methods, which only C can run (checked against KIELER's recordings).\n */\n simulated: boolean\n /** `_taken_transitions` has this many counters (takenTransitions option), in Taken Transition Signaling order. */\n takenTransitions?: string[]\n}\n"]}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Declaration, Effect, Equation, Expression, LocalAction, Program, Region, SclStatement, State, Transition, ValuedObject } from "./types.js";
|
|
2
|
+
/** What the formatter may need to know beyond the element itself. Everything is optional. */
|
|
3
|
+
export interface FormatContext {
|
|
4
|
+
/** The declaration and valued object behind a resolved reference (`Reference.decl`). Used to print a
|
|
5
|
+
* valued object's display label instead of its name, and to drop the value of an emission of a pure
|
|
6
|
+
* signal (as KIELER does). */
|
|
7
|
+
lookup?(valuedObjectId: string): {
|
|
8
|
+
declaration: Declaration;
|
|
9
|
+
valuedObject: ValuedObject;
|
|
10
|
+
} | undefined;
|
|
11
|
+
/** Name substitutions from `#symbols` / `#symbol` pragmas (KIELER's symbol table). */
|
|
12
|
+
symbols?: SymbolTable;
|
|
13
|
+
}
|
|
14
|
+
/** Builds a context for all charts of a program: declaration lookup and the pragma symbol table. */
|
|
15
|
+
export declare function createFormatContext(program: Pick<Program, 'charts' | 'pragmas'>): FormatContext;
|
|
16
|
+
export interface SymbolTable {
|
|
17
|
+
/** Name prefix → replacement. */
|
|
18
|
+
prefixes: Map<string, string>;
|
|
19
|
+
/** Separator → suffix processor (`#symbols "subscript" "_"`). */
|
|
20
|
+
suffixes: Map<string, (s: string) => string>;
|
|
21
|
+
}
|
|
22
|
+
/** KIELER's `applySymbolTable`: strips Xtext's `^` keyword escape and applies pragma symbols. */
|
|
23
|
+
export declare function displayName(name: string, ctx?: FormatContext): string;
|
|
24
|
+
/** Java's `Double.toString` (KIELER stores float literals as doubles): `1.0`, `0.5`, `1.0E7`, `1.0E-4`. */
|
|
25
|
+
export declare function formatFloat(value: number): string;
|
|
26
|
+
/** An expression as KIELER's diagrams show it (`serializeHR`): parentheses only where precedence needs them. */
|
|
27
|
+
export declare function formatExpression(e: Expression, ctx?: FormatContext): string;
|
|
28
|
+
/** KIELER's plain `serialize`: every operator expression except `!`, `~`, `pre` and `val` in parentheses.
|
|
29
|
+
* The diagram uses it for the value of a valued emission. */
|
|
30
|
+
export declare function formatExpressionPlain(e: Expression, ctx?: FormatContext): string;
|
|
31
|
+
export interface ParenthesiseOptions {
|
|
32
|
+
/**
|
|
33
|
+
* KIELER's model keeps a run of the same operator as one node with several operands (`a - b - c` is one `-`
|
|
34
|
+
* with three). 'flat' (default) prints such a node as it is, `a - b - c`; 'left' nests it the way the
|
|
35
|
+
* generated C code evaluates it, `(a - b) - c`.
|
|
36
|
+
*/
|
|
37
|
+
nary?: 'flat' | 'left';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The expression with every operation that is an operand of another one in parentheses, so the grouping KIELER's
|
|
41
|
+
* parser chose is visible: `a + b * c` is `a + (b * c)`, `!a && b` is `(!a) && b`, `a > 0 ? 1 : 2` is
|
|
42
|
+
* `a > (0 ? 1 : 2)`. The whole expression, array indices, arguments and vector members get no extra parentheses,
|
|
43
|
+
* `pre(x)` and `val(S)` none either (they look like calls already). Names print as written (no labels, no
|
|
44
|
+
* symbol tables): pass the result of `parseExpression`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatExpressionParenthesised(e: Expression, options?: ParenthesiseOptions): string;
|
|
47
|
+
/** An effect with its expressions printed by `formatExpressionParenthesised`: `x = a + (b * c)`, `S(a + (b * c))`. */
|
|
48
|
+
export declare function formatEffectParenthesised(effect: Effect, options?: ParenthesiseOptions): string;
|
|
49
|
+
/** An effect as KIELER's diagrams show it: `x = a + 1`, `x++`, `S`, `V((x + 1))`, `print(x)`. */
|
|
50
|
+
export declare function formatEffect(effect: Effect, ctx?: FormatContext): string;
|
|
51
|
+
/**
|
|
52
|
+
* An SCL code block (`do { ... }`) as KIELER prints it (SCLSerializeExtensions): `{` declarations joined by
|
|
53
|
+
* `; `, then the statements joined by spaces, `}`, each statement ending in `;`. Loops print as their body
|
|
54
|
+
* (`for` and `while` become `{...}`), conditionals as `if (c) {...} else {...}`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatScl(declarations: Declaration[], statements: SclStatement[], ctx?: FormatContext): string;
|
|
57
|
+
/** Effects joined with `; `. */
|
|
58
|
+
export declare function formatEffects(effects: Effect[], ctx?: FormatContext): string;
|
|
59
|
+
/** The trigger with its count delay: `3 A`. Empty when there is no trigger. */
|
|
60
|
+
export declare function formatTrigger(t: Pick<Transition, 'trigger' | 'triggerDelay'>, ctx?: FormatContext): string;
|
|
61
|
+
/** `serializeHR(Transition)`: trigger and effects, without priority (`3 A / x = 1; S`). */
|
|
62
|
+
export declare function formatTransition(t: Transition, ctx?: FormatContext): string;
|
|
63
|
+
export interface TransitionLabelOptions extends FormatContext {
|
|
64
|
+
/** Show `label "..."` user labels instead of trigger and effects (KIELER's "User Labels", default on). */
|
|
65
|
+
userLabels?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The lines of a transition label, as KIELER's TransitionLabelSerializer.serializeMultilineLabel builds them:
|
|
69
|
+
* `["1: A && B", "/ O = true;", " x++"]`. The priority is shown only when the source state has more than one
|
|
70
|
+
* outgoing transition; the trigger goes on the first line and each effect on its own line, indented under the
|
|
71
|
+
* first. `outgoing` is the number of outgoing transitions of the source state.
|
|
72
|
+
*/
|
|
73
|
+
export declare function transitionLabelLines(t: Transition, outgoing: number, options?: TransitionLabelOptions): string[];
|
|
74
|
+
/** The transition label on one line (`TransitionLabelSerializer.serializeLabel`): `1: A && B / O = true; x++`.
|
|
75
|
+
* Empty when KIELER shows no label. */
|
|
76
|
+
export declare function transitionLabel(t: Transition, outgoing: number, options?: TransitionLabelOptions): string;
|
|
77
|
+
/** KIELER draws a transition dashed when it is immediate, leaves a connector, or is a termination without
|
|
78
|
+
* trigger that is not explicitly delayed (`SCChartsTransitionExtensions.isImplicitlyImmediate`). */
|
|
79
|
+
export declare function isImplicitlyImmediate(t: Transition, source: Pick<State, 'connector'>): boolean;
|
|
80
|
+
export type TextFormat = 'keyword' | 'text' | 'highlight' | 'schedule';
|
|
81
|
+
/** A run of text in one format. Keyword runs are bold in KIELER's notation. */
|
|
82
|
+
export interface TextSegment {
|
|
83
|
+
text: string;
|
|
84
|
+
format: TextFormat;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Merges label components into runs the way KIELER's `addKeywordLabel` does: consecutive components of the
|
|
88
|
+
* same format are joined with a space (no space before a comma); a run that is followed by a run of another
|
|
89
|
+
* format keeps a trailing space. Empty runs are dropped.
|
|
90
|
+
*/
|
|
91
|
+
export declare function mergeComponents(components: TextSegment[]): TextSegment[];
|
|
92
|
+
/** The text of merged segments on one line. */
|
|
93
|
+
export declare function segmentsText(segments: TextSegment[]): string;
|
|
94
|
+
/** A valued object as declared: `arr[3]`, or its display label. */
|
|
95
|
+
export declare function formatValuedObject(vo: ValuedObject, ctx?: FormatContext): string;
|
|
96
|
+
/** The label components of a declaration (`serializeHighlighted(declaration, hr = true)`), before merging.
|
|
97
|
+
* For a class, struct or enum this is only its first line; see `declarationLines`. */
|
|
98
|
+
export declare function declarationComponents(d: Declaration, ctx?: FormatContext): TextSegment[];
|
|
99
|
+
/** One line of a declaration label, indented by `indent` levels (KIELER indents 10 px per level). */
|
|
100
|
+
export interface DeclarationLine {
|
|
101
|
+
indent: number;
|
|
102
|
+
components: TextSegment[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The lines of a declaration label. Most declarations are one line; a class or struct shows its members
|
|
106
|
+
* indented between `class Name {` and `} instances`, as KIELER's StateSynthesis.addStructDeclarations does.
|
|
107
|
+
*/
|
|
108
|
+
export declare function declarationLines(d: Declaration, ctx?: FormatContext, indent?: number, member?: {
|
|
109
|
+
hostClass: boolean;
|
|
110
|
+
}): DeclarationLine[];
|
|
111
|
+
/** A declaration line as KIELER's diagram shows it, e.g. `[input bool ][A, B]` (first line only). */
|
|
112
|
+
export declare function declarationSegments(d: Declaration, ctx?: FormatContext): TextSegment[];
|
|
113
|
+
/** A declaration on one line: `output int F = 0`. */
|
|
114
|
+
export declare function formatDeclaration(d: Declaration, ctx?: FormatContext): string;
|
|
115
|
+
/** The label components of a local action (`serializeHighlighted(action, hr = true, userLabels)`). Note that
|
|
116
|
+
* KIELER does not show an action's count delay. */
|
|
117
|
+
export declare function actionComponents(a: LocalAction, options?: TransitionLabelOptions): TextSegment[];
|
|
118
|
+
/** An action line: `[during ][A ][/ c--]`. */
|
|
119
|
+
export declare function actionSegments(a: LocalAction, options?: TransitionLabelOptions): TextSegment[];
|
|
120
|
+
/** An action on one line: `immediate during A / c++`. */
|
|
121
|
+
export declare function formatAction(a: LocalAction, options?: TransitionLabelOptions): string;
|
|
122
|
+
/** The name a state shows: its label, or its name (`serializeHR(State)`). */
|
|
123
|
+
export declare function stateDisplayName(s: Pick<State, 'name' | 'label'>, ctx?: FormatContext): string;
|
|
124
|
+
/** The title of a superstate or root state: the name, and for a reference state `@ Other (a, b)`. */
|
|
125
|
+
export declare function stateTitleSegments(s: State, ctx?: FormatContext): TextSegment[];
|
|
126
|
+
/** The label of a region (`serializeHighlighted(region)`): `override`, its label or name, and for a `for`
|
|
127
|
+
* region `| i[0,3]`. Empty for an anonymous region. */
|
|
128
|
+
export declare function regionLabelSegments(r: Region, ctx?: FormatContext): TextSegment[];
|
|
129
|
+
/**
|
|
130
|
+
* The index range of a `for` region as KIELER computes it (For.getForRegionRange): `for i : 0 to 3` gives
|
|
131
|
+
* [0, 3]; `for i : arr` iterates the indices of the array, [0, size - 1] (the size a literal or a constant's
|
|
132
|
+
* initial value), and [0, -1] when the size is unknown.
|
|
133
|
+
*/
|
|
134
|
+
export declare function forRegionRange(loop: NonNullable<Region['forLoop']>, ctx?: FormatContext): [number, number];
|
|
135
|
+
/** A dataflow equation on one line: `O = A && !pre(A)`. */
|
|
136
|
+
export declare function formatEquation(eq: Equation, ctx?: FormatContext): string;
|