@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,293 @@
|
|
|
1
|
+
// describeTick's view of references and for-regions (structure.md): a referenced chart's states and transitions are
|
|
2
|
+
// reported as `<reference state>/<id in the referenced chart>` (dataflow and `ref` instances:
|
|
3
|
+
// `<declaration>/<id>`), and a transition of a for-region copy is followed in the log by a note naming the copy.
|
|
4
|
+
import { formatExpression, stateDisplayName } from "../format.js";
|
|
5
|
+
import { REFERENCE_SEPARATOR } from "./structure/instance.js";
|
|
6
|
+
import { FOR_COPY_NOTE } from "./passes/forRegion.js";
|
|
7
|
+
export const PLAIN = { md: false, code: s => s };
|
|
8
|
+
export const MARKDOWN = { md: true, code: s => '`' + s.replace(/`/g, "'") + '`' };
|
|
9
|
+
/** Splits an instance element's id at its innermost reference: the instance prefix and the id in the referenced chart. */
|
|
10
|
+
function split(id) {
|
|
11
|
+
const i = id.lastIndexOf(REFERENCE_SEPARATOR);
|
|
12
|
+
return i < 0 ? undefined : { prefix: id.slice(0, i), inner: id.slice(i + 1) };
|
|
13
|
+
}
|
|
14
|
+
/** The name of a reference state or `ref` declaration an instance prefix stands for. */
|
|
15
|
+
function instanceName(prefix, idx) {
|
|
16
|
+
const d = prefix.lastIndexOf('$');
|
|
17
|
+
if (d >= 0 && !prefix.slice(d).includes('.'))
|
|
18
|
+
return prefix.slice(d + 1);
|
|
19
|
+
const s = resolveState(prefix, idx);
|
|
20
|
+
return s ? stateDisplayName(s) : prefix;
|
|
21
|
+
}
|
|
22
|
+
/** The source state an id stands for, also inside instances. */
|
|
23
|
+
export function resolveState(id, idx) {
|
|
24
|
+
const s = idx.states.get(id);
|
|
25
|
+
if (s)
|
|
26
|
+
return s;
|
|
27
|
+
const parts = split(id);
|
|
28
|
+
return parts ? idx.states.get(parts.inner) : undefined;
|
|
29
|
+
}
|
|
30
|
+
/** The formals of a chart (its inputs and outputs, in order) bound by a reference's arguments (KIELER's pointer). */
|
|
31
|
+
function bindingsOf(call, chart) {
|
|
32
|
+
const out = new Map();
|
|
33
|
+
if (!call || !chart)
|
|
34
|
+
return out;
|
|
35
|
+
const formals = chart.declarations.filter(d => d.declKind === 'variable' && (d.input || d.output)).flatMap(d => d.valuedObjects.map(v => v.name));
|
|
36
|
+
let ptr = 0;
|
|
37
|
+
for (const p of call.parameters) {
|
|
38
|
+
if (p.binding !== undefined) {
|
|
39
|
+
const i = formals.indexOf(p.binding);
|
|
40
|
+
if (i < 0)
|
|
41
|
+
continue;
|
|
42
|
+
ptr = i;
|
|
43
|
+
}
|
|
44
|
+
if (ptr >= formals.length)
|
|
45
|
+
continue;
|
|
46
|
+
const actual = formatExpression(p.expression);
|
|
47
|
+
if (actual !== formals[ptr])
|
|
48
|
+
out.set(formals[ptr], actual);
|
|
49
|
+
ptr++;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The references an instance element's id is inside of, innermost first. */
|
|
54
|
+
function withinOf(id, idx) {
|
|
55
|
+
const parts = split(id);
|
|
56
|
+
if (!parts)
|
|
57
|
+
return undefined;
|
|
58
|
+
const chart = parts.inner.split(/[.:!$-]/)[0];
|
|
59
|
+
// Inherited regions (passes/inheritance.ts) are prefixed with the inheriting state, `super` copies with `<it>/super`.
|
|
60
|
+
if (parts.prefix.endsWith(`${REFERENCE_SEPARATOR}super`) || idx.states.get(parts.prefix)?.isRoot)
|
|
61
|
+
return { instances: [], inherited: chart };
|
|
62
|
+
const instances = [];
|
|
63
|
+
let prefix = parts.prefix;
|
|
64
|
+
let inner = chart;
|
|
65
|
+
while (prefix !== undefined) {
|
|
66
|
+
const state = resolveState(prefix, idx);
|
|
67
|
+
instances.push({ name: instanceName(prefix, idx), chart: inner, bindings: bindingsOf(state?.reference, idx.charts?.get(inner)) });
|
|
68
|
+
const up = split(prefix);
|
|
69
|
+
if (!up)
|
|
70
|
+
break;
|
|
71
|
+
inner = up.inner.split(/[.:!$-]/)[0];
|
|
72
|
+
prefix = up.prefix;
|
|
73
|
+
}
|
|
74
|
+
return { instances };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* "Inside `Left` (a copy of `PushSwitch`, with `press` bound to `left`)", innermost reference first; `read` are the
|
|
78
|
+
* names the sentence mentions (bindings of other formals are left out).
|
|
79
|
+
*/
|
|
80
|
+
export function withinPhrase(w, f, read = []) {
|
|
81
|
+
if (w.inherited)
|
|
82
|
+
return `In the part inherited from ${f.code(w.inherited)}`;
|
|
83
|
+
return w.instances.map((x, i) => {
|
|
84
|
+
const bound = read.filter(n => x.bindings.has(n)).map(n => `${f.code(n)} bound to ${f.code(x.bindings.get(n))}`);
|
|
85
|
+
return `${i === 0 ? 'Inside' : 'inside'} ${f.code(x.name)} (a copy of ${f.code(x.chart)}${i === 0 && bound.length ? `, with ${list(bound)}` : ''})`;
|
|
86
|
+
}).join(' ');
|
|
87
|
+
}
|
|
88
|
+
/** The source transition an id stands for, and where it is when it belongs to a referenced chart's copy. */
|
|
89
|
+
export function resolveTransition(id, idx) {
|
|
90
|
+
const t = idx.transitions.get(id);
|
|
91
|
+
if (t)
|
|
92
|
+
return { t };
|
|
93
|
+
const parts = split(id);
|
|
94
|
+
if (!parts)
|
|
95
|
+
return undefined;
|
|
96
|
+
const inner = idx.transitions.get(parts.inner);
|
|
97
|
+
if (!inner)
|
|
98
|
+
return undefined;
|
|
99
|
+
return { t: inner, within: withinOf(id, idx) };
|
|
100
|
+
}
|
|
101
|
+
/** "`Off` (inside `Left`)": a state, and the copy it is in when it is in one. */
|
|
102
|
+
export function stateInCopy(id, idx, f) {
|
|
103
|
+
const s = resolveState(id, idx);
|
|
104
|
+
if (!s)
|
|
105
|
+
return undefined;
|
|
106
|
+
const w = withinOf(id, idx);
|
|
107
|
+
const name = f.code(stateDisplayName(s));
|
|
108
|
+
if (!w?.instances.length)
|
|
109
|
+
return name;
|
|
110
|
+
return `${name} (inside ${w.instances.map(x => f.code(x.name)).join(' inside ')})`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A readable name for any element id of a tick (states, transitions, regions, actions), also inside the copies of
|
|
114
|
+
* referenced charts and for-region copies: `{ name: 'Off → On', within: 'inside Left (a copy of PushSwitch)' }`.
|
|
115
|
+
* For "Explain this tick" and anything else that shows log events. Undefined for ids it does not know.
|
|
116
|
+
*/
|
|
117
|
+
export function elementName(id, idx, f = PLAIN) {
|
|
118
|
+
const where = withinOf(id, idx);
|
|
119
|
+
const within = where ? withinPhrase(where, f).replace(/^Inside/, 'inside').replace(/^In the part/, 'in the part') : undefined;
|
|
120
|
+
const t = resolveTransition(id, idx);
|
|
121
|
+
if (t) {
|
|
122
|
+
const src = resolveState(t.t.source, idx);
|
|
123
|
+
const dst = t.t.target ? resolveState(t.t.target, idx) : undefined;
|
|
124
|
+
const name = `${f.code(src ? stateDisplayName(src) : t.t.source)} → ${f.code(dst ? stateDisplayName(dst) : t.t.targetName ?? '?')}`;
|
|
125
|
+
return within ? { name, within } : { name };
|
|
126
|
+
}
|
|
127
|
+
const inner = split(id)?.inner ?? id;
|
|
128
|
+
const s = idx.states.get(id) ?? idx.states.get(inner);
|
|
129
|
+
if (s) {
|
|
130
|
+
// A copy's root is the referenced chart itself: "PushSwitch inside Left".
|
|
131
|
+
if (s.isRoot && where?.instances.length)
|
|
132
|
+
return { name: f.code(s.name), within: `inside ${where.instances.map(x => f.code(x.name)).join(' inside ')}` };
|
|
133
|
+
const name = f.code(stateDisplayName(s));
|
|
134
|
+
return within ? { name, within } : { name };
|
|
135
|
+
}
|
|
136
|
+
const r = idx.regions?.get(id) ?? idx.regions?.get(inner);
|
|
137
|
+
if (r) {
|
|
138
|
+
const name = r.name ? `region ${f.code(r.name)} of ${f.code(stateDisplayName(r.parent))}` : `a region of ${f.code(stateDisplayName(r.parent))}`;
|
|
139
|
+
return within ? { name, within } : { name };
|
|
140
|
+
}
|
|
141
|
+
const a = idx.actions?.get(id) ?? idx.actions?.get(inner);
|
|
142
|
+
if (a) {
|
|
143
|
+
const name = `the ${a.kind} action of ${f.code(stateDisplayName(a.owner))}`;
|
|
144
|
+
return within ? { name, within } : { name };
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
/** For each taken transition (in `result.taken` order), the for-region copy it fired in, as a phrase. */
|
|
149
|
+
export function copyPhrases(result, f = PLAIN) {
|
|
150
|
+
const out = [];
|
|
151
|
+
const log = result.log;
|
|
152
|
+
for (let i = 0; i < log.length; i++) {
|
|
153
|
+
if (log[i].kind !== 'take')
|
|
154
|
+
continue;
|
|
155
|
+
const notes = [];
|
|
156
|
+
for (let j = i + 1; j < log.length; j++) {
|
|
157
|
+
const e = log[j];
|
|
158
|
+
if (e.kind === 'note' && e.related?.[0] === FOR_COPY_NOTE)
|
|
159
|
+
notes.push(f.md ? e.markdown ?? e.text : e.text);
|
|
160
|
+
else if (e.kind !== 'exit' && e.kind !== 'enter')
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
out.push(notes.length ? notes.join(' ') : undefined);
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
/** The log without the copy notes (they are folded into the transitions' sentences). */
|
|
168
|
+
export function withoutCopyNotes(result) {
|
|
169
|
+
return { ...result, log: result.log.filter((e) => !(e.kind === 'note' && e.related?.[0] === FOR_COPY_NOTE)) };
|
|
170
|
+
}
|
|
171
|
+
/** "`Off` (inside `Left`)" for the instances active in tick 1, as phrases for "The chart starts in ...". */
|
|
172
|
+
export function instanceLeaves(result, idx, f = PLAIN) {
|
|
173
|
+
const out = [];
|
|
174
|
+
for (const id of result.active) {
|
|
175
|
+
const parts = split(id);
|
|
176
|
+
if (!parts)
|
|
177
|
+
continue;
|
|
178
|
+
const s = idx.states.get(parts.inner);
|
|
179
|
+
// (A reference state inside a copy is no leaf: its own copy's states are listed.)
|
|
180
|
+
if (!s || s.isRoot || s.reference || s.regions.some(r => r.states.some(c => result.active.includes(`${parts.prefix}${REFERENCE_SEPARATOR}${c.id}`))))
|
|
181
|
+
continue;
|
|
182
|
+
out.push(stateInCopy(id, idx, f) ?? f.code(stateDisplayName(s)));
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
const dataflowCache = new WeakMap();
|
|
187
|
+
/** Ids of the dataflow regions of every chart of the program. */
|
|
188
|
+
function dataflowRegions(program) {
|
|
189
|
+
const cached = dataflowCache.get(program);
|
|
190
|
+
if (cached)
|
|
191
|
+
return cached;
|
|
192
|
+
const out = new Set();
|
|
193
|
+
const visit = (s) => {
|
|
194
|
+
for (const r of s.regions) {
|
|
195
|
+
if (r.regionType === 'dataflow')
|
|
196
|
+
out.add(r.id);
|
|
197
|
+
r.states.forEach(visit);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
program.charts.forEach(visit);
|
|
201
|
+
dataflowCache.set(program, out);
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
function show(v) {
|
|
205
|
+
if (Array.isArray(v))
|
|
206
|
+
return `{${v.map(show).join(', ')}}`;
|
|
207
|
+
if (typeof v === 'string')
|
|
208
|
+
return JSON.stringify(v);
|
|
209
|
+
return String(v);
|
|
210
|
+
}
|
|
211
|
+
function list(items) {
|
|
212
|
+
return items.length <= 1 ? items.join('') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;
|
|
213
|
+
}
|
|
214
|
+
/** The period actions of the program by id, with their state (for "the period of S"). */
|
|
215
|
+
const periodCache = new WeakMap();
|
|
216
|
+
function periods(program) {
|
|
217
|
+
const cached = periodCache.get(program);
|
|
218
|
+
if (cached)
|
|
219
|
+
return cached;
|
|
220
|
+
const out = new Map();
|
|
221
|
+
const visit = (s) => {
|
|
222
|
+
for (const a of s.actions) {
|
|
223
|
+
if (a.kind !== 'period')
|
|
224
|
+
continue;
|
|
225
|
+
const t = a.trigger;
|
|
226
|
+
out.set(a.id, { state: s, value: t && (t.kind === 'int' || t.kind === 'float') ? t.value : undefined });
|
|
227
|
+
}
|
|
228
|
+
for (const r of s.regions)
|
|
229
|
+
r.states.forEach(visit);
|
|
230
|
+
};
|
|
231
|
+
program.charts.forEach(visit);
|
|
232
|
+
periodCache.set(program, out);
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Sentences about clocks, periods and dataflow regions: "Time passed: the clock t advanced to 300 (deltaT = 100).",
|
|
237
|
+
* "The dataflow equations computed O = true." `before` come before the transitions (time passes first), `after`
|
|
238
|
+
* after them; `quiet` are the variables these sentences cover (left out of "x is now ...").
|
|
239
|
+
*/
|
|
240
|
+
export function structureSentences(result, program, f = PLAIN) {
|
|
241
|
+
const before = [];
|
|
242
|
+
const after = [];
|
|
243
|
+
const quiet = new Set();
|
|
244
|
+
const clocks = [];
|
|
245
|
+
let simulated;
|
|
246
|
+
const regions = dataflowRegions(program);
|
|
247
|
+
const periodActions = periods(program);
|
|
248
|
+
const computed = new Map();
|
|
249
|
+
const dt = result.inputs.deltaT;
|
|
250
|
+
for (const e of result.log) {
|
|
251
|
+
if (e.kind !== 'write' || e.how !== 'update')
|
|
252
|
+
continue;
|
|
253
|
+
const period = periodActions.get(e.by);
|
|
254
|
+
if (period) {
|
|
255
|
+
// The period's clock advances (passes/period.ts); the period elapses when it reaches the period.
|
|
256
|
+
const name = f.code(stateDisplayName(period.state));
|
|
257
|
+
const v = typeof e.value === 'number' ? e.value : undefined;
|
|
258
|
+
if (period.value !== undefined && v !== undefined) {
|
|
259
|
+
before.push(v >= period.value
|
|
260
|
+
? `The period of ${name} elapsed (${f.code(show(v))} of ${f.code(show(period.value))} time units), so ${name}'s inside reacts in this tick.`
|
|
261
|
+
: `The period of ${name} has not elapsed yet (${f.code(show(v))} of ${f.code(show(period.value))} time units): ${name}'s inside waits.`);
|
|
262
|
+
}
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
// A clock's increment is written by its own declaration (`t += deltaT`, passes/timedAutomata.ts).
|
|
266
|
+
if (e.by.endsWith(`$${e.variable}`)) {
|
|
267
|
+
if (e.variable === 'deltaT')
|
|
268
|
+
simulated = e.value;
|
|
269
|
+
else if (!clocks.includes(`${e.variable}:${e.value}`))
|
|
270
|
+
clocks.push(`${e.variable}:${e.value}`);
|
|
271
|
+
quiet.add(e.variable);
|
|
272
|
+
}
|
|
273
|
+
if (regions.has(e.by))
|
|
274
|
+
computed.set(e.variable, e.value);
|
|
275
|
+
}
|
|
276
|
+
if (simulated !== undefined)
|
|
277
|
+
before.unshift(`${f.code('@SimulateSleep')}: ${f.code('deltaT')} is the ${f.code('sleepT')} the chart asked for in the previous tick, ${f.code(show(simulated))}.`);
|
|
278
|
+
if (clocks.length) {
|
|
279
|
+
const parts = clocks.map(c => { const i = c.lastIndexOf(':'); return `${f.code(c.slice(0, i))} advanced to ${f.code(c.slice(i + 1))}`; });
|
|
280
|
+
before.push(`Time passed: ${clocks.length === 1 ? 'the clock' : 'the clocks'} ${list(parts)}${dt !== undefined && dt !== null ? ` (${f.code(`deltaT = ${show(dt)}`)})` : ''}.`);
|
|
281
|
+
}
|
|
282
|
+
if (computed.size) {
|
|
283
|
+
after.push(`The dataflow equations computed ${list([...computed].map(([k, v]) => f.code(`${k} = ${show(v)}`)))}.`);
|
|
284
|
+
for (const k of computed.keys())
|
|
285
|
+
quiet.add(k);
|
|
286
|
+
}
|
|
287
|
+
if ('sleepT' in result.values) {
|
|
288
|
+
quiet.add('sleepT');
|
|
289
|
+
after.push(`${f.code(`sleepT = ${show(result.values.sleepT)}`)}: how long the environment may wait before the next tick.`);
|
|
290
|
+
}
|
|
291
|
+
return { before, after, quiet, dataflow: regions.size > 0 };
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=describeStructure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describeStructure.js","sourceRoot":"","sources":["../../src/sim/describeStructure.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,8FAA8F;AAC9F,iHAAiH;AAGjH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,qBAAiB;AAC9D,OAAO,EAAE,mBAAmB,EAAE,gCAA4B;AAC1D,OAAO,EAAE,aAAa,EAAE,8BAA0B;AAalD,MAAM,CAAC,MAAM,KAAK,GAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAA;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAA;AAEtF,0HAA0H;AAC1H,SAAS,KAAK,CAAC,EAAU;IACrB,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAA;IAC7C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAA;AACjF,CAAC;AAED,wFAAwF;AACxF,SAAS,YAAY,CAAC,MAAc,EAAE,GAAU;IAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,C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AC,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnL,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,mCAAmC,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAClH,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE;YAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACjD,CAAC;IACD,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAC5B,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACnB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,2DAA2D,CAAC,CAAA;IAC9H,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAA;AAC/D,CAAC","sourcesContent":["// describeTick's view of references and for-regions (structure.md): a referenced chart's states and transitions are\n// reported as `<reference state>/<id in the referenced chart>` (dataflow and `ref` instances:\n// `<declaration>/<id>`), and a transition of a for-region copy is followed in the log by a note naming the copy.\n\nimport type { Program, ScopeCall, State, TickResult, TraceEvent, Transition } from '../types'\nimport { formatExpression, stateDisplayName } from '../format'\nimport { REFERENCE_SEPARATOR } from './structure/instance'\nimport { FOR_COPY_NOTE } from './passes/forRegion'\n\ninterface Index {\n states: Map<string, State>\n transitions: Map<string, Transition>\n}\n\n/** How describeTick writes names: as they are, or (Markdown) as code. */\nexport interface Fmt {\n md: boolean\n code(s: string): string\n}\n\nexport const PLAIN: Fmt = { md: false, code: s => s }\nexport const MARKDOWN: Fmt = { md: true, code: s => '`' + s.replace(/`/g, \"'\") + '`' }\n\n/** Splits an instance element's id at its innermost reference: the instance prefix and the id in the referenced chart. */\nfunction split(id: string): { prefix: string; inner: string } | undefined {\n const i = id.lastIndexOf(REFERENCE_SEPARATOR)\n return i < 0 ? undefined : { prefix: id.slice(0, i), inner: id.slice(i + 1) }\n}\n\n/** The name of a reference state or `ref` declaration an instance prefix stands for. */\nfunction instanceName(prefix: string, idx: Index): string {\n const d = prefix.lastIndexOf('$')\n if (d >= 0 && !prefix.slice(d).includes('.')) return prefix.slice(d + 1)\n const s = resolveState(prefix, idx)\n return s ? stateDisplayName(s) : prefix\n}\n\n/** The source state an id stands for, also inside instances. */\nexport function resolveState(id: string, idx: Index): State | undefined {\n const s = idx.states.get(id)\n if (s) return s\n const parts = split(id)\n return parts ? idx.states.get(parts.inner) : undefined\n}\n\n/** One reference an element is inside of: the reference state's (or `ref` declaration's) name and the chart. */\nexport interface InstanceInfo {\n name: string\n chart: string\n /** The referenced chart's inputs and outputs bound to another name: formal -> the actual as written. */\n bindings: Map<string, string>\n}\n\n/** Where an element of an instance is: the references it is inside of (innermost first), or a base chart. */\nexport interface Within {\n instances: InstanceInfo[]\n /** Inherited from this chart (passes/inheritance.ts prefixes the inheriting state). */\n inherited?: string\n}\n\n/** The formals of a chart (its inputs and outputs, in order) bound by a reference's arguments (KIELER's pointer). */\nfunction bindingsOf(call: ScopeCall | undefined, chart: State | undefined): Map<string, string> {\n const out = new Map<string, string>()\n if (!call || !chart) return out\n const formals = chart.declarations.filter(d => d.declKind === 'variable' && (d.input || d.output)).flatMap(d => d.valuedObjects.map(v => v.name))\n let ptr = 0\n for (const p of call.parameters) {\n if (p.binding !== undefined) {\n const i = formals.indexOf(p.binding)\n if (i < 0) continue\n ptr = i\n }\n if (ptr >= formals.length) continue\n const actual = formatExpression(p.expression)\n if (actual !== formals[ptr]) out.set(formals[ptr], actual)\n ptr++\n }\n return out\n}\n\n/** The references an instance element's id is inside of, innermost first. */\nfunction withinOf(id: string, idx: Index & { charts?: Map<string, State> }): Within | undefined {\n const parts = split(id)\n if (!parts) return undefined\n const chart = parts.inner.split(/[.:!$-]/)[0]\n // Inherited regions (passes/inheritance.ts) are prefixed with the inheriting state, `super` copies with `<it>/super`.\n if (parts.prefix.endsWith(`${REFERENCE_SEPARATOR}super`) || idx.states.get(parts.prefix)?.isRoot) return { instances: [], inherited: chart }\n const instances: InstanceInfo[] = []\n let prefix: string | undefined = parts.prefix\n let inner = chart\n while (prefix !== undefined) {\n const state = resolveState(prefix, idx)\n instances.push({ name: instanceName(prefix, idx), chart: inner, bindings: bindingsOf(state?.reference, idx.charts?.get(inner)) })\n const up = split(prefix)\n if (!up) break\n inner = up.inner.split(/[.:!$-]/)[0]\n prefix = up.prefix\n }\n return { instances }\n}\n\n/**\n * \"Inside `Left` (a copy of `PushSwitch`, with `press` bound to `left`)\", innermost reference first; `read` are the\n * names the sentence mentions (bindings of other formals are left out).\n */\nexport function withinPhrase(w: Within, f: Fmt, read: string[] = []): string {\n if (w.inherited) return `In the part inherited from ${f.code(w.inherited)}`\n return w.instances.map((x, i) => {\n const bound = read.filter(n => x.bindings.has(n)).map(n => `${f.code(n)} bound to ${f.code(x.bindings.get(n)!)}`)\n return `${i === 0 ? 'Inside' : 'inside'} ${f.code(x.name)} (a copy of ${f.code(x.chart)}${i === 0 && bound.length ? `, with ${list(bound)}` : ''})`\n }).join(' ')\n}\n\n/** The source transition an id stands for, and where it is when it belongs to a referenced chart's copy. */\nexport function resolveTransition(id: string, idx: Index): { t: Transition; within?: Within } | undefined {\n const t = idx.transitions.get(id)\n if (t) return { t }\n const parts = split(id)\n if (!parts) return undefined\n const inner = idx.transitions.get(parts.inner)\n if (!inner) return undefined\n return { t: inner, within: withinOf(id, idx) }\n}\n\n/** \"`Off` (inside `Left`)\": a state, and the copy it is in when it is in one. */\nexport function stateInCopy(id: string, idx: Index, f: Fmt): string | undefined {\n const s = resolveState(id, idx)\n if (!s) return undefined\n const w = withinOf(id, idx)\n const name = f.code(stateDisplayName(s))\n if (!w?.instances.length) return name\n return `${name} (inside ${w.instances.map(x => f.code(x.name)).join(' inside ')})`\n}\n\n/**\n * A readable name for any element id of a tick (states, transitions, regions, actions), also inside the copies of\n * referenced charts and for-region copies: `{ name: 'Off → On', within: 'inside Left (a copy of PushSwitch)' }`.\n * For \"Explain this tick\" and anything else that shows log events. Undefined for ids it does not know.\n */\nexport function elementName(id: string, idx: Index & { regions?: Map<string, { name?: string; parent: State }>; actions?: Map<string, { kind: string; owner: State }> }, f: Fmt = PLAIN): { name: string; within?: string } | undefined {\n const where = withinOf(id, idx)\n const within = where ? withinPhrase(where, f).replace(/^Inside/, 'inside').replace(/^In the part/, 'in the part') : undefined\n const t = resolveTransition(id, idx)\n if (t) {\n const src = resolveState(t.t.source, idx)\n const dst = t.t.target ? resolveState(t.t.target, idx) : undefined\n const name = `${f.code(src ? stateDisplayName(src) : t.t.source)} → ${f.code(dst ? stateDisplayName(dst) : t.t.targetName ?? '?')}`\n return within ? { name, within } : { name }\n }\n const inner = split(id)?.inner ?? id\n const s = idx.states.get(id) ?? idx.states.get(inner)\n if (s) {\n // A copy's root is the referenced chart itself: \"PushSwitch inside Left\".\n if (s.isRoot && where?.instances.length) return { name: f.code(s.name), within: `inside ${where.instances.map(x => f.code(x.name)).join(' inside ')}` }\n const name = f.code(stateDisplayName(s))\n return within ? { name, within } : { name }\n }\n const r = idx.regions?.get(id) ?? idx.regions?.get(inner)\n if (r) {\n const name = r.name ? `region ${f.code(r.name)} of ${f.code(stateDisplayName(r.parent))}` : `a region of ${f.code(stateDisplayName(r.parent))}`\n return within ? { name, within } : { name }\n }\n const a = idx.actions?.get(id) ?? idx.actions?.get(inner)\n if (a) {\n const name = `the ${a.kind} action of ${f.code(stateDisplayName(a.owner))}`\n return within ? { name, within } : { name }\n }\n return undefined\n}\n\n/** For each taken transition (in `result.taken` order), the for-region copy it fired in, as a phrase. */\nexport function copyPhrases(result: TickResult, f: Fmt = PLAIN): (string | undefined)[] {\n const out: (string | undefined)[] = []\n const log = result.log\n for (let i = 0; i < log.length; i++) {\n if (log[i].kind !== 'take') continue\n const notes: string[] = []\n for (let j = i + 1; j < log.length; j++) {\n const e = log[j]\n if (e.kind === 'note' && e.related?.[0] === FOR_COPY_NOTE) notes.push(f.md ? e.markdown ?? e.text : e.text)\n else if (e.kind !== 'exit' && e.kind !== 'enter') break\n }\n out.push(notes.length ? notes.join(' ') : undefined)\n }\n return out\n}\n\n/** The log without the copy notes (they are folded into the transitions' sentences). */\nexport function withoutCopyNotes(result: TickResult): TickResult {\n return { ...result, log: result.log.filter((e: TraceEvent) => !(e.kind === 'note' && e.related?.[0] === FOR_COPY_NOTE)) }\n}\n\n/** \"`Off` (inside `Left`)\" for the instances active in tick 1, as phrases for \"The chart starts in ...\". */\nexport function instanceLeaves(result: TickResult, idx: Index, f: Fmt = PLAIN): string[] {\n const out: string[] = []\n for (const id of result.active) {\n const parts = split(id)\n if (!parts) continue\n const s = idx.states.get(parts.inner)\n // (A reference state inside a copy is no leaf: its own copy's states are listed.)\n if (!s || s.isRoot || s.reference || s.regions.some(r => r.states.some(c => result.active.includes(`${parts.prefix}${REFERENCE_SEPARATOR}${c.id}`)))) continue\n out.push(stateInCopy(id, idx, f) ?? f.code(stateDisplayName(s)))\n }\n return out\n}\n\nexport type { Program }\n\nconst dataflowCache = new WeakMap<Program, Set<string>>()\n\n/** Ids of the dataflow regions of every chart of the program. */\nfunction dataflowRegions(program: Program): Set<string> {\n const cached = dataflowCache.get(program)\n if (cached) return cached\n const out = new Set<string>()\n const visit = (s: State) => {\n for (const r of s.regions) {\n if (r.regionType === 'dataflow') out.add(r.id)\n r.states.forEach(visit)\n }\n }\n program.charts.forEach(visit)\n dataflowCache.set(program, out)\n return out\n}\n\nfunction show(v: unknown): string {\n if (Array.isArray(v)) return `{${v.map(show).join(', ')}}`\n if (typeof v === 'string') return JSON.stringify(v)\n return String(v)\n}\n\nfunction list(items: string[]): string {\n return items.length <= 1 ? items.join('') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`\n}\n\n/** The period actions of the program by id, with their state (for \"the period of S\"). */\nconst periodCache = new WeakMap<Program, Map<string, { state: State; value?: number }>>()\n\nfunction periods(program: Program): Map<string, { state: State; value?: number }> {\n const cached = periodCache.get(program)\n if (cached) return cached\n const out = new Map<string, { state: State; value?: number }>()\n const visit = (s: State) => {\n for (const a of s.actions) {\n if (a.kind !== 'period') continue\n const t = a.trigger\n out.set(a.id, { state: s, value: t && (t.kind === 'int' || t.kind === 'float') ? t.value : undefined })\n }\n for (const r of s.regions) r.states.forEach(visit)\n }\n program.charts.forEach(visit)\n periodCache.set(program, out)\n return out\n}\n\n/**\n * Sentences about clocks, periods and dataflow regions: \"Time passed: the clock t advanced to 300 (deltaT = 100).\",\n * \"The dataflow equations computed O = true.\" `before` come before the transitions (time passes first), `after`\n * after them; `quiet` are the variables these sentences cover (left out of \"x is now ...\").\n */\nexport function structureSentences(result: TickResult, program: Program, f: Fmt = PLAIN): { before: string[]; after: string[]; quiet: Set<string>; dataflow: boolean } {\n const before: string[] = []\n const after: string[] = []\n const quiet = new Set<string>()\n const clocks: string[] = []\n let simulated: unknown\n const regions = dataflowRegions(program)\n const periodActions = periods(program)\n const computed = new Map<string, unknown>()\n const dt = result.inputs.deltaT\n for (const e of result.log) {\n if (e.kind !== 'write' || e.how !== 'update') continue\n const period = periodActions.get(e.by)\n if (period) {\n // The period's clock advances (passes/period.ts); the period elapses when it reaches the period.\n const name = f.code(stateDisplayName(period.state))\n const v = typeof e.value === 'number' ? e.value : undefined\n if (period.value !== undefined && v !== undefined) {\n before.push(v >= period.value\n ? `The period of ${name} elapsed (${f.code(show(v))} of ${f.code(show(period.value))} time units), so ${name}'s inside reacts in this tick.`\n : `The period of ${name} has not elapsed yet (${f.code(show(v))} of ${f.code(show(period.value))} time units): ${name}'s inside waits.`)\n }\n continue\n }\n // A clock's increment is written by its own declaration (`t += deltaT`, passes/timedAutomata.ts).\n if (e.by.endsWith(`$${e.variable}`)) {\n if (e.variable === 'deltaT') simulated = e.value\n else if (!clocks.includes(`${e.variable}:${e.value}`)) clocks.push(`${e.variable}:${e.value}`)\n quiet.add(e.variable)\n }\n if (regions.has(e.by)) computed.set(e.variable, e.value)\n }\n if (simulated !== undefined) before.unshift(`${f.code('@SimulateSleep')}: ${f.code('deltaT')} is the ${f.code('sleepT')} the chart asked for in the previous tick, ${f.code(show(simulated))}.`)\n if (clocks.length) {\n const parts = clocks.map(c => { const i = c.lastIndexOf(':'); return `${f.code(c.slice(0, i))} advanced to ${f.code(c.slice(i + 1))}` })\n before.push(`Time passed: ${clocks.length === 1 ? 'the clock' : 'the clocks'} ${list(parts)}${dt !== undefined && dt !== null ? ` (${f.code(`deltaT = ${show(dt)}`)})` : ''}.`)\n }\n if (computed.size) {\n after.push(`The dataflow equations computed ${list([...computed].map(([k, v]) => f.code(`${k} = ${show(v)}`)))}.`)\n for (const k of computed.keys()) quiet.add(k)\n }\n if ('sleepT' in result.values) {\n quiet.add('sleepT')\n after.push(`${f.code(`sleepT = ${show(result.values.sleepT)}`)}: how long the environment may wait before the next tick.`)\n }\n return { before, after, quiet, dataflow: regions.size > 0 }\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Span } from "../types.js";
|
|
2
|
+
import type { CEffect, CExpr, CRef, CVar } from "./model.js";
|
|
3
|
+
import type { Memory } from "./memory.js";
|
|
4
|
+
import { type RandState } from "./random.js";
|
|
5
|
+
import { type CString, type CType, type RValue } from "./values.js";
|
|
6
|
+
/** A failure while running a tick (division by zero, index out of range, ...). */
|
|
7
|
+
export declare class SimError extends Error {
|
|
8
|
+
readonly span?: Span | undefined;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly hint?: string | undefined;
|
|
11
|
+
constructor(message: string, span?: Span | undefined, code?: string, hint?: string | undefined);
|
|
12
|
+
}
|
|
13
|
+
export interface Runtime {
|
|
14
|
+
vals: RValue[];
|
|
15
|
+
rand: RandState;
|
|
16
|
+
/** Text printed in this tick (print() inside methods). */
|
|
17
|
+
printed?: string[];
|
|
18
|
+
/** What a write outside an array overwrote (memory.ts), for the log's notes (plain and Markdown); the executor
|
|
19
|
+
* empties it. */
|
|
20
|
+
notes?: {
|
|
21
|
+
text: string;
|
|
22
|
+
markdown: string;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
export type Fn = (rt: Runtime) => RValue;
|
|
26
|
+
/** Static C type of evaluated expressions; 'f32' is C `float` (random()). */
|
|
27
|
+
export type EType = CType | 'f32';
|
|
28
|
+
export interface VarInfo {
|
|
29
|
+
slot: number;
|
|
30
|
+
type: CType;
|
|
31
|
+
dims: number[];
|
|
32
|
+
}
|
|
33
|
+
export interface EvalContext {
|
|
34
|
+
info(v: CVar): VarInfo;
|
|
35
|
+
/** Display name of a variable for messages. */
|
|
36
|
+
label(v: CVar): string;
|
|
37
|
+
/** KIELER's struct of the chart's variables, for indices outside an array (memory.ts). */
|
|
38
|
+
memory?: Memory;
|
|
39
|
+
}
|
|
40
|
+
/** An index outside its array, as the flat (row-major) element number C computes from it: C reads or writes whatever
|
|
41
|
+
* is stored there (memory.ts). */
|
|
42
|
+
export declare class Far {
|
|
43
|
+
readonly flat: number;
|
|
44
|
+
constructor(flat: number);
|
|
45
|
+
}
|
|
46
|
+
export interface Compiled {
|
|
47
|
+
fn: Fn;
|
|
48
|
+
type: EType;
|
|
49
|
+
}
|
|
50
|
+
/** KIELER's isFloatExpression (KExpressionsTypeExtensions.inferType == FLOAT): decides the (int) cast. */
|
|
51
|
+
export declare function isFloatExpression(e: CExpr): boolean;
|
|
52
|
+
export declare class ExprCompiler {
|
|
53
|
+
readonly ctx: EvalContext;
|
|
54
|
+
constructor(ctx: EvalContext);
|
|
55
|
+
/**
|
|
56
|
+
* What a conditional without an else part (`c ? a`) gives when `c` is false. KIELER's C code generator writes it
|
|
57
|
+
* as `c ? a : __CONDSELF__` and replaces the placeholder by the target of the assignment it is in (`x = 1 +
|
|
58
|
+
* (c ? 2)` is `x = 1 + (c ? 2 : x)`, `x += c ? 1` doubles x) or, for a condition, by the guard variable that holds
|
|
59
|
+
* the condition's value (the value it had when last computed, exec.ts). Elsewhere gcc rejects the placeholder
|
|
60
|
+
* (codegen.ts); the innermost enclosing one counts.
|
|
61
|
+
*/
|
|
62
|
+
private readonly selves;
|
|
63
|
+
/** Compiles with `self` as the value of a conditional without an else (see `selves`). */
|
|
64
|
+
withSelf<T>(self: Compiled | undefined, compile: () => T): T;
|
|
65
|
+
compile(e: CExpr): Compiled;
|
|
66
|
+
/** Reads a variable or an array element. */
|
|
67
|
+
read(r: CRef): Compiled;
|
|
68
|
+
/**
|
|
69
|
+
* Evaluates the indices of a reference. C only computes an address from them: indices of a multi-dimensional
|
|
70
|
+
* array that are out of their range but land inside the array are that element (`m[0][3]` of `int m[2][3]` is
|
|
71
|
+
* `m[1][0]`); outside the array the access goes to whatever KIELER stores there (`Far`, memory.ts), when the guide
|
|
72
|
+
* knows it, and is a runtime error otherwise.
|
|
73
|
+
*/
|
|
74
|
+
indexer(r: CRef, info: VarInfo): (rt: Runtime) => number[] | Far;
|
|
75
|
+
private op;
|
|
76
|
+
/** The divisor as the chart writes it (`b`, `b - 1`, `pre(n)`), for a division's hint; undefined when the guide
|
|
77
|
+
* cannot tell (a value KIELER computes in a variable of its own). */
|
|
78
|
+
divisorName(e: CExpr | undefined): string | undefined;
|
|
79
|
+
/** `known`: the right operand's value when gcc knows it at compile time (literals only), where gcc folds the
|
|
80
|
+
* operation instead of leaving it to the machine (probes tests/engine/kieler/codegen/probe-literal-*). */
|
|
81
|
+
private binary;
|
|
82
|
+
private unary;
|
|
83
|
+
private arithmetic;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* An expression of the working model as the chart writes it, with the reader's names (`label`): `b - 1`, `a[i]`,
|
|
87
|
+
* `pre(n)`, `val(S)`. Undefined when it has parts the reader did not write (KIELER's own variables, host code).
|
|
88
|
+
*/
|
|
89
|
+
export declare function sourceText(e: CExpr, label: (v: CVar) => string): string | undefined;
|
|
90
|
+
/** What an executed effect did, for the log. */
|
|
91
|
+
export interface Write {
|
|
92
|
+
v: CVar;
|
|
93
|
+
value: RValue;
|
|
94
|
+
/** Array element written (undefined for the whole variable). */
|
|
95
|
+
index?: number[];
|
|
96
|
+
}
|
|
97
|
+
export type EffectFn = (rt: Runtime, printed: string[]) => Write | undefined;
|
|
98
|
+
export declare function compileEffect(f: CEffect, ec: ExprCompiler): EffectFn;
|
|
99
|
+
export type { CString };
|