@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.
Files changed (279) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +125 -2
  3. package/dist/codegen/expr.d.ts +36 -0
  4. package/dist/codegen/expr.js +252 -0
  5. package/dist/codegen/expr.js.map +1 -0
  6. package/dist/codegen/index.d.ts +4 -0
  7. package/dist/codegen/index.js +238 -0
  8. package/dist/codegen/index.js.map +1 -0
  9. package/dist/codegen/layout.d.ts +57 -0
  10. package/dist/codegen/layout.js +306 -0
  11. package/dist/codegen/layout.js.map +1 -0
  12. package/dist/codegen/logic.d.ts +31 -0
  13. package/dist/codegen/logic.js +258 -0
  14. package/dist/codegen/logic.js.map +1 -0
  15. package/dist/codegen/methods.d.ts +17 -0
  16. package/dist/codegen/methods.js +242 -0
  17. package/dist/codegen/methods.js.map +1 -0
  18. package/dist/codegen/reset.d.ts +6 -0
  19. package/dist/codegen/reset.js +110 -0
  20. package/dist/codegen/reset.js.map +1 -0
  21. package/dist/codegen/types.d.ts +81 -0
  22. package/dist/codegen/types.js +3 -0
  23. package/dist/codegen/types.js.map +1 -0
  24. package/dist/format.d.ts +136 -0
  25. package/dist/format.js +872 -0
  26. package/dist/format.js.map +1 -0
  27. package/dist/index.d.ts +120 -0
  28. package/dist/index.js +507 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/internal.d.ts +1 -0
  31. package/dist/internal.js +4 -0
  32. package/dist/internal.js.map +1 -0
  33. package/dist/parser/ids.d.ts +4 -0
  34. package/dist/parser/ids.js +172 -0
  35. package/dist/parser/ids.js.map +1 -0
  36. package/dist/parser/imports.d.ts +2 -0
  37. package/dist/parser/imports.js +28 -0
  38. package/dist/parser/imports.js.map +1 -0
  39. package/dist/parser/interface.d.ts +10 -0
  40. package/dist/parser/interface.js +93 -0
  41. package/dist/parser/interface.js.map +1 -0
  42. package/dist/parser/kielerWording.d.ts +2 -0
  43. package/dist/parser/kielerWording.js +196 -0
  44. package/dist/parser/kielerWording.js.map +1 -0
  45. package/dist/parser/lexer.d.ts +25 -0
  46. package/dist/parser/lexer.js +334 -0
  47. package/dist/parser/lexer.js.map +1 -0
  48. package/dist/parser/parser.d.ts +29 -0
  49. package/dist/parser/parser.js +3249 -0
  50. package/dist/parser/parser.js.map +1 -0
  51. package/dist/parser/resolve.d.ts +46 -0
  52. package/dist/parser/resolve.js +919 -0
  53. package/dist/parser/resolve.js.map +1 -0
  54. package/dist/parser/source.d.ts +15 -0
  55. package/dist/parser/source.js +42 -0
  56. package/dist/parser/source.js.map +1 -0
  57. package/dist/parser/validate.d.ts +5 -0
  58. package/dist/parser/validate.js +1430 -0
  59. package/dist/parser/validate.js.map +1 -0
  60. package/dist/sim/abortRegions.d.ts +9 -0
  61. package/dist/sim/abortRegions.js +192 -0
  62. package/dist/sim/abortRegions.js.map +1 -0
  63. package/dist/sim/analysis.d.ts +113 -0
  64. package/dist/sim/analysis.js +1104 -0
  65. package/dist/sim/analysis.js.map +1 -0
  66. package/dist/sim/codegen.d.ts +30 -0
  67. package/dist/sim/codegen.js +730 -0
  68. package/dist/sim/codegen.js.map +1 -0
  69. package/dist/sim/compile.d.ts +43 -0
  70. package/dist/sim/compile.js +1062 -0
  71. package/dist/sim/compile.js.map +1 -0
  72. package/dist/sim/deps.d.ts +73 -0
  73. package/dist/sim/deps.js +481 -0
  74. package/dist/sim/deps.js.map +1 -0
  75. package/dist/sim/describe.d.ts +22 -0
  76. package/dist/sim/describe.js +272 -0
  77. package/dist/sim/describe.js.map +1 -0
  78. package/dist/sim/describePreemption.d.ts +22 -0
  79. package/dist/sim/describePreemption.js +90 -0
  80. package/dist/sim/describePreemption.js.map +1 -0
  81. package/dist/sim/describeStructure.d.ts +75 -0
  82. package/dist/sim/describeStructure.js +293 -0
  83. package/dist/sim/describeStructure.js.map +1 -0
  84. package/dist/sim/eval.d.ts +99 -0
  85. package/dist/sim/eval.js +644 -0
  86. package/dist/sim/eval.js.map +1 -0
  87. package/dist/sim/exec.d.ts +212 -0
  88. package/dist/sim/exec.js +874 -0
  89. package/dist/sim/exec.js.map +1 -0
  90. package/dist/sim/fold.d.ts +2 -0
  91. package/dist/sim/fold.js +40 -0
  92. package/dist/sim/fold.js.map +1 -0
  93. package/dist/sim/goblock.d.ts +16 -0
  94. package/dist/sim/goblock.js +171 -0
  95. package/dist/sim/goblock.js.map +1 -0
  96. package/dist/sim/guardIndices.d.ts +13 -0
  97. package/dist/sim/guardIndices.js +137 -0
  98. package/dist/sim/guardIndices.js.map +1 -0
  99. package/dist/sim/index.d.ts +43 -0
  100. package/dist/sim/index.js +138 -0
  101. package/dist/sim/index.js.map +1 -0
  102. package/dist/sim/lower.d.ts +33 -0
  103. package/dist/sim/lower.js +716 -0
  104. package/dist/sim/lower.js.map +1 -0
  105. package/dist/sim/memory.d.ts +47 -0
  106. package/dist/sim/memory.js +328 -0
  107. package/dist/sim/memory.js.map +1 -0
  108. package/dist/sim/model.d.ts +487 -0
  109. package/dist/sim/model.js +772 -0
  110. package/dist/sim/model.js.map +1 -0
  111. package/dist/sim/passes/abort.d.ts +2 -0
  112. package/dist/sim/passes/abort.js +269 -0
  113. package/dist/sim/passes/abort.js.map +1 -0
  114. package/dist/sim/passes/abortRegion.d.ts +10 -0
  115. package/dist/sim/passes/abortRegion.js +62 -0
  116. package/dist/sim/passes/abortRegion.js.map +1 -0
  117. package/dist/sim/passes/arrayAssignment.d.ts +2 -0
  118. package/dist/sim/passes/arrayAssignment.js +147 -0
  119. package/dist/sim/passes/arrayAssignment.js.map +1 -0
  120. package/dist/sim/passes/codeEffects.d.ts +2 -0
  121. package/dist/sim/passes/codeEffects.js +14 -0
  122. package/dist/sim/passes/codeEffects.js.map +1 -0
  123. package/dist/sim/passes/complexFinalState.d.ts +4 -0
  124. package/dist/sim/passes/complexFinalState.js +77 -0
  125. package/dist/sim/passes/complexFinalState.js.map +1 -0
  126. package/dist/sim/passes/connector.d.ts +2 -0
  127. package/dist/sim/passes/connector.js +18 -0
  128. package/dist/sim/passes/connector.js.map +1 -0
  129. package/dist/sim/passes/contained.d.ts +37 -0
  130. package/dist/sim/passes/contained.js +198 -0
  131. package/dist/sim/passes/contained.js.map +1 -0
  132. package/dist/sim/passes/context.d.ts +39 -0
  133. package/dist/sim/passes/context.js +3 -0
  134. package/dist/sim/passes/context.js.map +1 -0
  135. package/dist/sim/passes/countDelay.d.ts +2 -0
  136. package/dist/sim/passes/countDelay.js +51 -0
  137. package/dist/sim/passes/countDelay.js.map +1 -0
  138. package/dist/sim/passes/dataflow.d.ts +11 -0
  139. package/dist/sim/passes/dataflow.js +319 -0
  140. package/dist/sim/passes/dataflow.js.map +1 -0
  141. package/dist/sim/passes/deferred.d.ts +2 -0
  142. package/dist/sim/passes/deferred.js +345 -0
  143. package/dist/sim/passes/deferred.js.map +1 -0
  144. package/dist/sim/passes/detect.d.ts +10 -0
  145. package/dist/sim/passes/detect.js +33 -0
  146. package/dist/sim/passes/detect.js.map +1 -0
  147. package/dist/sim/passes/during.d.ts +2 -0
  148. package/dist/sim/passes/during.js +67 -0
  149. package/dist/sim/passes/during.js.map +1 -0
  150. package/dist/sim/passes/entry.d.ts +5 -0
  151. package/dist/sim/passes/entry.js +93 -0
  152. package/dist/sim/passes/entry.js.map +1 -0
  153. package/dist/sim/passes/enum.d.ts +2 -0
  154. package/dist/sim/passes/enum.js +22 -0
  155. package/dist/sim/passes/enum.js.map +1 -0
  156. package/dist/sim/passes/exit.d.ts +4 -0
  157. package/dist/sim/passes/exit.js +120 -0
  158. package/dist/sim/passes/exit.js.map +1 -0
  159. package/dist/sim/passes/finalRegion.d.ts +2 -0
  160. package/dist/sim/passes/finalRegion.js +21 -0
  161. package/dist/sim/passes/finalRegion.js.map +1 -0
  162. package/dist/sim/passes/followedBy.d.ts +2 -0
  163. package/dist/sim/passes/followedBy.js +78 -0
  164. package/dist/sim/passes/followedBy.js.map +1 -0
  165. package/dist/sim/passes/forRegion.d.ts +9 -0
  166. package/dist/sim/passes/forRegion.js +230 -0
  167. package/dist/sim/passes/forRegion.js.map +1 -0
  168. package/dist/sim/passes/history.d.ts +12 -0
  169. package/dist/sim/passes/history.js +115 -0
  170. package/dist/sim/passes/history.js.map +1 -0
  171. package/dist/sim/passes/hostCode.d.ts +2 -0
  172. package/dist/sim/passes/hostCode.js +152 -0
  173. package/dist/sim/passes/hostCode.js.map +1 -0
  174. package/dist/sim/passes/index.d.ts +4 -0
  175. package/dist/sim/passes/index.js +84 -0
  176. package/dist/sim/passes/index.js.map +1 -0
  177. package/dist/sim/passes/inheritance.d.ts +8 -0
  178. package/dist/sim/passes/inheritance.js +233 -0
  179. package/dist/sim/passes/inheritance.js.map +1 -0
  180. package/dist/sim/passes/initOperator.d.ts +2 -0
  181. package/dist/sim/passes/initOperator.js +68 -0
  182. package/dist/sim/passes/initOperator.js.map +1 -0
  183. package/dist/sim/passes/initialization.d.ts +2 -0
  184. package/dist/sim/passes/initialization.js +69 -0
  185. package/dist/sim/passes/initialization.js.map +1 -0
  186. package/dist/sim/passes/ode.d.ts +2 -0
  187. package/dist/sim/passes/ode.js +14 -0
  188. package/dist/sim/passes/ode.js.map +1 -0
  189. package/dist/sim/passes/period.d.ts +2 -0
  190. package/dist/sim/passes/period.js +106 -0
  191. package/dist/sim/passes/period.js.map +1 -0
  192. package/dist/sim/passes/prTransitions.d.ts +2 -0
  193. package/dist/sim/passes/prTransitions.js +12 -0
  194. package/dist/sim/passes/prTransitions.js.map +1 -0
  195. package/dist/sim/passes/pre.d.ts +4 -0
  196. package/dist/sim/passes/pre.js +326 -0
  197. package/dist/sim/passes/pre.js.map +1 -0
  198. package/dist/sim/passes/quirks.d.ts +2 -0
  199. package/dist/sim/passes/quirks.js +169 -0
  200. package/dist/sim/passes/quirks.js.map +1 -0
  201. package/dist/sim/passes/reference.d.ts +60 -0
  202. package/dist/sim/passes/reference.js +386 -0
  203. package/dist/sim/passes/reference.js.map +1 -0
  204. package/dist/sim/passes/regionActions.d.ts +2 -0
  205. package/dist/sim/passes/regionActions.js +56 -0
  206. package/dist/sim/passes/regionActions.js.map +1 -0
  207. package/dist/sim/passes/sequentialFollowedBy.d.ts +2 -0
  208. package/dist/sim/passes/sequentialFollowedBy.js +72 -0
  209. package/dist/sim/passes/sequentialFollowedBy.js.map +1 -0
  210. package/dist/sim/passes/signal.d.ts +2 -0
  211. package/dist/sim/passes/signal.js +230 -0
  212. package/dist/sim/passes/signal.js.map +1 -0
  213. package/dist/sim/passes/static.d.ts +5 -0
  214. package/dist/sim/passes/static.js +67 -0
  215. package/dist/sim/passes/static.js.map +1 -0
  216. package/dist/sim/passes/suspend.d.ts +10 -0
  217. package/dist/sim/passes/suspend.js +71 -0
  218. package/dist/sim/passes/suspend.js.map +1 -0
  219. package/dist/sim/passes/termination.d.ts +9 -0
  220. package/dist/sim/passes/termination.js +69 -0
  221. package/dist/sim/passes/termination.js.map +1 -0
  222. package/dist/sim/passes/timedAutomata.d.ts +10 -0
  223. package/dist/sim/passes/timedAutomata.js +437 -0
  224. package/dist/sim/passes/timedAutomata.js.map +1 -0
  225. package/dist/sim/passes/unpackClasses.d.ts +2 -0
  226. package/dist/sim/passes/unpackClasses.js +54 -0
  227. package/dist/sim/passes/unpackClasses.js.map +1 -0
  228. package/dist/sim/passes/userSchedule.d.ts +2 -0
  229. package/dist/sim/passes/userSchedule.js +43 -0
  230. package/dist/sim/passes/userSchedule.js.map +1 -0
  231. package/dist/sim/passes/weakSuspend.d.ts +2 -0
  232. package/dist/sim/passes/weakSuspend.js +145 -0
  233. package/dist/sim/passes/weakSuspend.js.map +1 -0
  234. package/dist/sim/preemptionLog.d.ts +41 -0
  235. package/dist/sim/preemptionLog.js +133 -0
  236. package/dist/sim/preemptionLog.js.map +1 -0
  237. package/dist/sim/random.d.ts +12 -0
  238. package/dist/sim/random.js +40 -0
  239. package/dist/sim/random.js.map +1 -0
  240. package/dist/sim/reasons.d.ts +29 -0
  241. package/dist/sim/reasons.js +168 -0
  242. package/dist/sim/reasons.js.map +1 -0
  243. package/dist/sim/scg.d.ts +124 -0
  244. package/dist/sim/scg.js +723 -0
  245. package/dist/sim/scg.js.map +1 -0
  246. package/dist/sim/sfr.d.ts +4 -0
  247. package/dist/sim/sfr.js +264 -0
  248. package/dist/sim/sfr.js.map +1 -0
  249. package/dist/sim/stringConditions.d.ts +3 -0
  250. package/dist/sim/stringConditions.js +42 -0
  251. package/dist/sim/stringConditions.js.map +1 -0
  252. package/dist/sim/structure/copy.d.ts +4 -0
  253. package/dist/sim/structure/copy.js +140 -0
  254. package/dist/sim/structure/copy.js.map +1 -0
  255. package/dist/sim/structure/delays.d.ts +30 -0
  256. package/dist/sim/structure/delays.js +127 -0
  257. package/dist/sim/structure/delays.js.map +1 -0
  258. package/dist/sim/structure/instance.d.ts +15 -0
  259. package/dist/sim/structure/instance.js +69 -0
  260. package/dist/sim/structure/instance.js.map +1 -0
  261. package/dist/sim/structure/methods.d.ts +19 -0
  262. package/dist/sim/structure/methods.js +550 -0
  263. package/dist/sim/structure/methods.js.map +1 -0
  264. package/dist/sim/structure/rewrite.d.ts +20 -0
  265. package/dist/sim/structure/rewrite.js +113 -0
  266. package/dist/sim/structure/rewrite.js.map +1 -0
  267. package/dist/sim/structure/track.d.ts +22 -0
  268. package/dist/sim/structure/track.js +123 -0
  269. package/dist/sim/structure/track.js.map +1 -0
  270. package/dist/sim/tracker.d.ts +77 -0
  271. package/dist/sim/tracker.js +265 -0
  272. package/dist/sim/tracker.js.map +1 -0
  273. package/dist/sim/values.d.ts +31 -0
  274. package/dist/sim/values.js +103 -0
  275. package/dist/sim/values.js.map +1 -0
  276. package/dist/types.d.ts +670 -0
  277. package/dist/types.js +9 -0
  278. package/dist/types.js.map +1 -0
  279. package/package.json +58 -3
@@ -0,0 +1,272 @@
1
+ // describeTick: a tick in plain English, for the "what happened" panel. One sentence per item, in the order
2
+ // things happened: entries, transitions with the reason they fired, emitted signals, changed outputs,
3
+ // termination, errors. Sentences use the chart's own names, as plain text, or with `markdown: true` as inline
4
+ // Markdown with names, triggers and values in code spans. Elements inside the copy of a referenced chart are named
5
+ // by the reference ("Inside Left (a copy of PushSwitch): Off went to On because press was true"), also when the
6
+ // chart comes from an imported file.
7
+ import { formatExpression, stateDisplayName } from "../format.js";
8
+ import { abortClause, countPhrase, countSuffix, heldPhrase, noteSentences, seenPhrase, suspendedHere, suspendSentences } from "./describePreemption.js";
9
+ import { copyPhrases, elementName as nameIn, instanceLeaves, MARKDOWN, PLAIN, resolveState, resolveTransition, stateInCopy, structureSentences, withinPhrase, withoutCopyNotes, } from "./describeStructure.js";
10
+ const indexCache = new WeakMap();
11
+ /** The programs of the files a program imports (compile() records them), whose charts its references may copy. */
12
+ const importsOf = new WeakMap();
13
+ /** Records the imported programs of a compiled program, for the names of the elements of their charts' copies. */
14
+ export function rememberImports(program, imported) {
15
+ importsOf.set(program, imported);
16
+ indexCache.delete(program);
17
+ }
18
+ function indexProgram(program) {
19
+ const cached = indexCache.get(program);
20
+ if (cached)
21
+ return cached;
22
+ const index = { states: new Map(), transitions: new Map(), parents: new Map(), regions: new Map(), actions: new Map(), charts: new Map() };
23
+ const visit = (s) => {
24
+ index.states.set(s.id, s);
25
+ for (const t of s.transitions)
26
+ index.transitions.set(t.id, t);
27
+ for (const a of s.actions)
28
+ index.actions.set(a.id, { kind: a.kind, owner: s });
29
+ for (const r of s.regions) {
30
+ index.regions.set(r.id, { name: r.name, parent: s });
31
+ for (const a of r.actions)
32
+ index.actions.set(a.id, { kind: a.kind, owner: s });
33
+ for (const c of r.states) {
34
+ index.parents.set(c.id, s);
35
+ visit(c);
36
+ }
37
+ }
38
+ };
39
+ // The imported files' charts first: the program's own come last and win a clash of names.
40
+ for (const p of [...(importsOf.get(program) ?? []), program]) {
41
+ for (const c of p.charts) {
42
+ index.charts.set(c.name, c);
43
+ visit(c);
44
+ }
45
+ }
46
+ indexCache.set(program, index);
47
+ return index;
48
+ }
49
+ /**
50
+ * A readable name for an element id of a tick's result or log (a state, transition, region or local action), also
51
+ * inside the copy of a referenced chart or of a for-region: `{ name: 'Off → On', within: 'inside Left (a copy of
52
+ * PushSwitch)' }`; with `markdown`, names in code spans. Undefined for an id it does not know.
53
+ */
54
+ export function elementName(id, program, options = {}) {
55
+ return nameIn(id, indexProgram(program), options.markdown ? MARKDOWN : PLAIN);
56
+ }
57
+ function show(v) {
58
+ if (v === null)
59
+ return 'null';
60
+ if (Array.isArray(v))
61
+ return `{${v.map(show).join(', ')}}`;
62
+ if (typeof v === 'string')
63
+ return JSON.stringify(v);
64
+ return String(v);
65
+ }
66
+ function names(list) {
67
+ if (list.length <= 1)
68
+ return list.join('');
69
+ return `${list.slice(0, -1).join(', ')} and ${list[list.length - 1]}`;
70
+ }
71
+ /**
72
+ * Sentences describing a tick: what was entered, which transitions fired and why, which signals were emitted,
73
+ * which outputs changed, and whether the chart terminated or stopped with an error. Plain text, or inline Markdown
74
+ * with `markdown: true` (the same sentences, with names, triggers and values in code spans).
75
+ */
76
+ export function describeTick(result, program, previous, options = {}) {
77
+ const f = options.markdown ? MARKDOWN : PLAIN;
78
+ const idx = indexProgram(program);
79
+ const out = [];
80
+ const stateName = (id) => {
81
+ const s = resolveState(id, idx);
82
+ return f.code(s ? stateDisplayName(s) : id);
83
+ };
84
+ if (result.error) {
85
+ // A diagnostic's message and hint are inline Markdown: as they are in Markdown, without the code marks in plain.
86
+ const text = (s) => (f.md ? s : s.replace(/`/g, ''));
87
+ out.push(`The simulation stopped in tick ${result.error.tick ?? result.tick}: ${text(result.error.message)}${result.error.span ? ` (line ${result.error.span.line})` : ''}.`);
88
+ if (result.error.hint)
89
+ out.push(text(result.error.hint));
90
+ return out;
91
+ }
92
+ if (result.tick === 1) {
93
+ const leaves = result.active.filter(id => {
94
+ const s = idx.states.get(id);
95
+ return s && !s.isRoot && !s.regions.some(r => r.states.some(c => result.active.includes(c.id)));
96
+ });
97
+ const inner = instanceLeaves(result, idx, f);
98
+ const shown = leaves.filter(id => !inner.length || !idx.states.get(id)?.reference).map(id => {
99
+ const s = idx.states.get(id);
100
+ return stateDisplayName(s) === '' ? '' : f.code(stateDisplayName(s));
101
+ }).filter(n => n !== '');
102
+ out.push(`The chart starts${shown.length + inner.length ? ` in ${names([...shown, ...inner])}` : ''}.`);
103
+ }
104
+ out.push(...suspendSentences(result, idx, f));
105
+ const structure = structureSentences(result, program, f);
106
+ out.push(...structure.before);
107
+ const fired = result.taken;
108
+ const copies = copyPhrases(result, f);
109
+ // The take events, in the order of `taken`: each says what its trigger read when it was checked (reasons.ts).
110
+ const takes = result.log.filter((e) => e.kind === 'take');
111
+ for (const [i, ev] of takes.entries()) {
112
+ const found = resolveTransition(ev.transition, idx);
113
+ if (!found)
114
+ continue;
115
+ const t = found.t;
116
+ const read = (ev.seen ?? []).map(s => s.name);
117
+ const where = [found.within ? withinPhrase(found.within, f, read) : undefined, copies[i]?.replace(/^This was /, 'in ').replace(/\.$/, '')].filter(Boolean);
118
+ const joined = where.join(', ');
119
+ const lead = where.length ? `${joined.charAt(0).toUpperCase()}${joined.slice(1)}: ` : '';
120
+ const from = stateName(t.source);
121
+ const to = t.target ? stateName(t.target) : f.code(t.targetName ?? '');
122
+ const verb = t.preemption === 'termination' ? `${from} finished and joined to ${to}` : t.preemption === 'strong' ? `${from} was aborted and went to ${to}` : `${from} went to ${to}`;
123
+ const why = f.md && ev.seen?.length ? seenPhrase(ev.seen, f) : ev.reason ?? '';
124
+ const trigger = t.trigger ? f.code(formatExpression(t.trigger)) : '';
125
+ const held = heldPhrase(t, from);
126
+ const inside = abortClause(t, idx, f);
127
+ const plain = t.trigger ? simpleReason(t.trigger, ev.seen, f) : undefined;
128
+ if (t.trigger && ev.unchecked) {
129
+ // P-23: the superstate's last transition, taken after the exit actions without checking its trigger.
130
+ out.push(lead + `${verb} without checking ${trigger}${inside}. When ${from} is left, KIELER picks its transition again after the inside has finished (and the exit actions have run): if none of the others applies then, it takes the last one regardless of its trigger.`);
131
+ continue;
132
+ }
133
+ // A trigger that is just `true` explains nothing (unless it is counted).
134
+ const trivial = t.trigger?.kind === 'bool' && t.trigger.value && !(t.triggerDelay !== undefined && t.triggerDelay > 1);
135
+ const because = plain ? `${plain}${countPhrase(t, from)}` : `${trigger}${why ? ` ${held} (${why})` : ` ${held}`}`;
136
+ out.push(lead + (t.trigger && !trivial ? `${verb} because ${because}${inside}.` : `${verb}${t.delay === 'immediate' || t.preemption === 'termination' ? ' immediately' : ''}${inside}.`));
137
+ }
138
+ out.push(...delayedSentences(result, idx, stateName, f));
139
+ out.push(...noteSentences(withoutCopyNotes(result), f));
140
+ out.push(...structure.after);
141
+ const emitted = Object.entries(result.present).filter(([, p]) => p).map(([name]) => f.code(name));
142
+ if (emitted.length)
143
+ out.push(`${names(emitted)} ${emitted.length === 1 ? 'was' : 'were'} present.`);
144
+ if (previous) {
145
+ const changed = Object.keys(result.values).filter(k => !(k in result.present) && !(k in result.inputs) && !structure.quiet.has(k) && JSON.stringify(result.values[k]) !== JSON.stringify(previous.values[k]));
146
+ if (changed.length)
147
+ out.push(`${names(changed.map(k => `${f.code(k)} is now ${f.code(show(result.values[k]))}`))}.`);
148
+ }
149
+ if (!fired.length && result.tick > 1 && !structure.dataflow) {
150
+ const waiting = result.log.filter(e => e.kind === 'check' && !e.result).map(e => (e.kind === 'check' ? e.transition : ''));
151
+ const ts = [...new Set(waiting)].map(id => ({ id, t: resolveTransition(id, idx)?.t })).filter((x) => !!x.t && !suspendedHere(x.t.source, result, idx));
152
+ if (ts.length) {
153
+ const parts = ts.slice(0, 3).map(({ id, t }) => {
154
+ // The copy a state of a referenced chart is in: the transition's prefix with the state's own id.
155
+ const source = id.includes('/') ? `${id.slice(0, id.lastIndexOf('/') + 1)}${t.source}` : t.source;
156
+ const what = t.trigger ? `${f.code(formatExpression(t.trigger))}${countSuffix(t)}` : t.preemption === 'termination' ? 'its inside to finish' : 'the next tick';
157
+ return `${stateInCopy(source, idx, f) ?? stateName(t.source)} waits for ${what}`;
158
+ });
159
+ out.push(`No transition fired: ${names(parts)}.`);
160
+ }
161
+ else if (!result.log.some(e => e.kind === 'suspend')) {
162
+ out.push('No transition fired.');
163
+ }
164
+ }
165
+ if (result.terminatedNow)
166
+ out.push('Every top-level region reached a final state, so the chart terminated. Nothing happens in later ticks.');
167
+ else if (result.terminated)
168
+ out.push('The chart has terminated: nothing happens any more.');
169
+ if (result.printed.length)
170
+ out.push(`It printed ${names(result.printed.map(p => f.code(JSON.stringify(p))))}.`);
171
+ return out;
172
+ }
173
+ /**
174
+ * A trigger that is one variable or signal, or its negation, said naturally from what it read: "button was true",
175
+ * "S was absent". Undefined for anything else (the caller says "n == 0 held (n was 0)").
176
+ */
177
+ function simpleReason(trigger, seen, f) {
178
+ const negated = trigger.kind === 'op' && trigger.op === '!' && trigger.args[0].kind === 'ref';
179
+ const ref = negated ? trigger.args[0] : trigger;
180
+ if (ref.kind !== 'ref' || ref.indices.length || ref.sub)
181
+ return undefined;
182
+ const s = seen?.find(x => x.name === ref.name);
183
+ if (!s || typeof s.value !== 'boolean')
184
+ return undefined;
185
+ if (s.signal)
186
+ return `${f.code(ref.name)} was ${s.value ? 'present' : 'absent'}`;
187
+ return `${f.code(ref.name)} was ${f.code(String(s.value))}`;
188
+ }
189
+ /**
190
+ * Values at the end of the tick, by name, for checking a trigger that was not checked: a pure signal is its
191
+ * presence, a valued one its value (`val(S)` and presence are told apart by `present`).
192
+ */
193
+ function holdsNow(e, result) {
194
+ const value = (x) => {
195
+ switch (x.kind) {
196
+ case 'bool':
197
+ case 'int':
198
+ case 'float': return x.value;
199
+ case 'ref': {
200
+ if (x.indices.length || x.sub)
201
+ return undefined;
202
+ // A signal on its own is its presence (a valued signal's value is val(S)).
203
+ if (x.name in result.present)
204
+ return result.present[x.name];
205
+ const v = result.values[x.name];
206
+ return v === undefined ? undefined : v;
207
+ }
208
+ case 'op': {
209
+ const args = x.args.map(value);
210
+ if (args.some(a => a === undefined || a === null || typeof a === 'string' || Array.isArray(a)))
211
+ return undefined;
212
+ const [a, b] = args;
213
+ const n = (v) => Number(v);
214
+ switch (x.op) {
215
+ case '!': return !a;
216
+ case '&&': return args.every(Boolean);
217
+ case '||': return args.some(Boolean);
218
+ case '==': return n(a) === n(b);
219
+ case '!=': return n(a) !== n(b);
220
+ case '<': return n(a) < n(b);
221
+ case '<=': return n(a) <= n(b);
222
+ case '>': return n(a) > n(b);
223
+ case '>=': return n(a) >= n(b);
224
+ default: return undefined;
225
+ }
226
+ }
227
+ default: return undefined;
228
+ }
229
+ };
230
+ const v = value(e);
231
+ return typeof v === 'boolean' || typeof v === 'number' ? v : undefined;
232
+ }
233
+ /**
234
+ * States entered in this tick whose delayed transitions' triggers already hold: "coin is true, but Locked was entered
235
+ * in this tick: its transitions are delayed, so they are first checked in tick 2." (A delayed transition is not
236
+ * checked in the tick its state is entered.)
237
+ */
238
+ function delayedSentences(result, idx, stateName, f) {
239
+ const out = [];
240
+ const active = new Set(result.active);
241
+ // A state left and entered again in this tick (a self-loop, a superstate's reset) was just checked: the sentence
242
+ // after "Ready went to Ready because press was true" would only confuse.
243
+ const left = new Set(result.exited);
244
+ for (const id of result.entered) {
245
+ if (!active.has(id) || id.includes('/') || left.has(id))
246
+ continue;
247
+ const s = idx.states.get(id);
248
+ if (!s || s.isRoot || s.connector || s.reference)
249
+ continue;
250
+ const delayed = s.transitions.filter(t => t.delay !== 'immediate' && t.trigger && !(t.triggerDelay !== undefined && t.triggerDelay > 1));
251
+ const holding = delayed.find(t => holdsNow(t.trigger, result) === true);
252
+ if (!holding)
253
+ continue;
254
+ const name = stateName(id);
255
+ const many = s.transitions.filter(t => t.delay !== 'immediate').length > 1;
256
+ out.push(`${holdsText(holding.trigger, result, f)}, but ${name} was entered in this tick: its ${many ? 'transitions are' : 'transition is'} delayed, so ${many ? 'they are' : 'it is'} first checked in tick ${result.tick + 1}.`);
257
+ }
258
+ return out;
259
+ }
260
+ /** "coin is true", "S is present", "n > 2 holds" (at the end of the tick). */
261
+ function holdsText(trigger, result, f) {
262
+ const negated = trigger.kind === 'op' && trigger.op === '!' && trigger.args[0].kind === 'ref';
263
+ const ref = negated ? trigger.args[0] : trigger;
264
+ if (ref.kind === 'ref' && !ref.indices.length && !ref.sub) {
265
+ const signal = ref.name in result.present;
266
+ if (signal)
267
+ return `${f.code(ref.name)} is ${negated ? 'absent' : 'present'}`;
268
+ return `${f.code(ref.name)} is ${f.code(negated ? 'false' : 'true')}`;
269
+ }
270
+ return `${f.code(formatExpression(trigger))} holds`;
271
+ }
272
+ //# sourceMappingURL=describe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/sim/describe.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,sGAAsG;AACtG,8GAA8G;AAC9G,mHAAmH;AACnH,gHAAgH;AAChH,qCAAqC;AAGrC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,qBAAiB;AAC9D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,gCAA4B;AACpJ,OAAO,EACH,WAAW,EAAE,WAAW,IAAI,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EACrI,YAAY,EAAE,gBAAgB,GACjC,+BAA2B;AAgB5B,MAAM,UAAU,GAAG,IAAI,OAAO,EAAkB,CAAA;AAChD,kHAAkH;AAClH,MAAM,SAAS,GAAG,IAAI,OAAO,EAAsB,CAAA;AAEnD,kHAAkH;AAClH,MAAM,UAAU,eAAe,CAAC,OAAgB,EAAE,QAAmB;IACjE,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAChC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,YAAY,CAAC,OAAgB;IAClC,MAAM,MAAM,GAAG,UAAU,CA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OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,CAAA;QACzC,IAAI,MAAM;YAAE,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;QAC7E,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;IACzE,CAAC;IACD,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAA;AACvD,CAAC","sourcesContent":["// describeTick: a tick in plain English, for the \"what happened\" panel. One sentence per item, in the order\n// things happened: entries, transitions with the reason they fired, emitted signals, changed outputs,\n// termination, errors. Sentences use the chart's own names, as plain text, or with `markdown: true` as inline\n// Markdown with names, triggers and values in code spans. Elements inside the copy of a referenced chart are named\n// by the reference (\"Inside Left (a copy of PushSwitch): Off went to On because press was true\"), also when the\n// chart comes from an imported file.\n\nimport type { Expression, Program, State, TickResult, TraceEvent, TraceSeen, Transition, Value } from '../types'\nimport { formatExpression, stateDisplayName } from '../format'\nimport { abortClause, countPhrase, countSuffix, heldPhrase, noteSentences, seenPhrase, suspendedHere, suspendSentences } from './describePreemption'\nimport {\n copyPhrases, elementName as nameIn, instanceLeaves, MARKDOWN, PLAIN, resolveState, resolveTransition, stateInCopy, structureSentences,\n withinPhrase, withoutCopyNotes, type Fmt,\n} from './describeStructure'\n\nexport interface DescribeOptions {\n /** Inline Markdown: state, variable, signal and chart names, triggers and values in code spans. */\n markdown?: boolean\n}\n\ninterface Index {\n states: Map<string, State>\n transitions: Map<string, Transition>\n parents: Map<string, State>\n regions: Map<string, { name?: string; parent: State }>\n actions: Map<string, { kind: string; owner: State }>\n charts: Map<string, State>\n}\n\nconst indexCache = new WeakMap<Program, Index>()\n/** The programs of the files a program imports (compile() records them), whose charts its references may copy. */\nconst importsOf = new WeakMap<Program, Program[]>()\n\n/** Records the imported programs of a compiled program, for the names of the elements of their charts' copies. */\nexport function rememberImports(program: Program, imported: Program[]) {\n importsOf.set(program, imported)\n indexCache.delete(program)\n}\n\nfunction indexProgram(program: Program): Index {\n const cached = indexCache.get(program)\n if (cached) return cached\n const index: Index = { states: new Map(), transitions: new Map(), parents: new Map(), regions: new Map(), actions: new Map(), charts: new Map() }\n const visit = (s: State) => {\n index.states.set(s.id, s)\n for (const t of s.transitions) index.transitions.set(t.id, t)\n for (const a of s.actions) index.actions.set(a.id, { kind: a.kind, owner: s })\n for (const r of s.regions) {\n index.regions.set(r.id, { name: r.name, parent: s })\n for (const a of r.actions) index.actions.set(a.id, { kind: a.kind, owner: s })\n for (const c of r.states) {\n index.parents.set(c.id, s)\n visit(c)\n }\n }\n }\n // The imported files' charts first: the program's own come last and win a clash of names.\n for (const p of [...(importsOf.get(program) ?? []), program]) {\n for (const c of p.charts) {\n index.charts.set(c.name, c)\n visit(c)\n }\n }\n indexCache.set(program, index)\n return index\n}\n\n/**\n * A readable name for an element id of a tick's result or log (a state, transition, region or local action), also\n * inside the copy of a referenced chart or of a for-region: `{ name: 'Off → On', within: 'inside Left (a copy of\n * PushSwitch)' }`; with `markdown`, names in code spans. Undefined for an id it does not know.\n */\nexport function elementName(id: string, program: Program, options: DescribeOptions = {}): { name: string; within?: string } | undefined {\n return nameIn(id, indexProgram(program), options.markdown ? MARKDOWN : PLAIN)\n}\n\nfunction show(v: Value): string {\n if (v === null) return 'null'\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 names(list: string[]): string {\n if (list.length <= 1) return list.join('')\n return `${list.slice(0, -1).join(', ')} and ${list[list.length - 1]}`\n}\n\n/**\n * Sentences describing a tick: what was entered, which transitions fired and why, which signals were emitted,\n * which outputs changed, and whether the chart terminated or stopped with an error. Plain text, or inline Markdown\n * with `markdown: true` (the same sentences, with names, triggers and values in code spans).\n */\nexport function describeTick(result: TickResult, program: Program, previous?: TickResult, options: DescribeOptions = {}): string[] {\n const f: Fmt = options.markdown ? MARKDOWN : PLAIN\n const idx = indexProgram(program)\n const out: string[] = []\n const stateName = (id: string) => {\n const s = resolveState(id, idx)\n return f.code(s ? stateDisplayName(s) : id)\n }\n if (result.error) {\n // A diagnostic's message and hint are inline Markdown: as they are in Markdown, without the code marks in plain.\n const text = (s: string) => (f.md ? s : s.replace(/`/g, ''))\n out.push(`The simulation stopped in tick ${result.error.tick ?? result.tick}: ${text(result.error.message)}${result.error.span ? ` (line ${result.error.span.line})` : ''}.`)\n if (result.error.hint) out.push(text(result.error.hint))\n return out\n }\n if (result.tick === 1) {\n const leaves = result.active.filter(id => {\n const s = idx.states.get(id)\n return s && !s.isRoot && !s.regions.some(r => r.states.some(c => result.active.includes(c.id)))\n })\n const inner = instanceLeaves(result, idx, f)\n const shown = leaves.filter(id => !inner.length || !idx.states.get(id)?.reference).map(id => {\n const s = idx.states.get(id)!\n return stateDisplayName(s) === '' ? '' : f.code(stateDisplayName(s))\n }).filter(n => n !== '')\n out.push(`The chart starts${shown.length + inner.length ? ` in ${names([...shown, ...inner])}` : ''}.`)\n }\n out.push(...suspendSentences(result, idx, f))\n const structure = structureSentences(result, program, f)\n out.push(...structure.before)\n const fired = result.taken\n const copies = copyPhrases(result, f)\n // The take events, in the order of `taken`: each says what its trigger read when it was checked (reasons.ts).\n const takes = result.log.filter((e): e is Extract<TraceEvent, { kind: 'take' }> => e.kind === 'take')\n for (const [i, ev] of takes.entries()) {\n const found = resolveTransition(ev.transition, idx)\n if (!found) continue\n const t = found.t\n const read = (ev.seen ?? []).map(s => s.name)\n const where = [found.within ? withinPhrase(found.within, f, read) : undefined, copies[i]?.replace(/^This was /, 'in ').replace(/\\.$/, '')].filter(Boolean)\n const joined = where.join(', ')\n const lead = where.length ? `${joined.charAt(0).toUpperCase()}${joined.slice(1)}: ` : ''\n const from = stateName(t.source)\n const to = t.target ? stateName(t.target) : f.code(t.targetName ?? '')\n const verb = t.preemption === 'termination' ? `${from} finished and joined to ${to}` : t.preemption === 'strong' ? `${from} was aborted and went to ${to}` : `${from} went to ${to}`\n const why = f.md && ev.seen?.length ? seenPhrase(ev.seen, f) : ev.reason ?? ''\n const trigger = t.trigger ? f.code(formatExpression(t.trigger)) : ''\n const held = heldPhrase(t, from)\n const inside = abortClause(t, idx, f)\n const plain = t.trigger ? simpleReason(t.trigger, ev.seen, f) : undefined\n if (t.trigger && ev.unchecked) {\n // P-23: the superstate's last transition, taken after the exit actions without checking its trigger.\n out.push(lead + `${verb} without checking ${trigger}${inside}. When ${from} is left, KIELER picks its transition again after the inside has finished (and the exit actions have run): if none of the others applies then, it takes the last one regardless of its trigger.`)\n continue\n }\n // A trigger that is just `true` explains nothing (unless it is counted).\n const trivial = t.trigger?.kind === 'bool' && t.trigger.value && !(t.triggerDelay !== undefined && t.triggerDelay > 1)\n const because = plain ? `${plain}${countPhrase(t, from)}` : `${trigger}${why ? ` ${held} (${why})` : ` ${held}`}`\n out.push(lead + (t.trigger && !trivial ? `${verb} because ${because}${inside}.` : `${verb}${t.delay === 'immediate' || t.preemption === 'termination' ? ' immediately' : ''}${inside}.`))\n }\n out.push(...delayedSentences(result, idx, stateName, f))\n out.push(...noteSentences(withoutCopyNotes(result), f))\n out.push(...structure.after)\n const emitted = Object.entries(result.present).filter(([, p]) => p).map(([name]) => f.code(name))\n if (emitted.length) out.push(`${names(emitted)} ${emitted.length === 1 ? 'was' : 'were'} present.`)\n if (previous) {\n const changed = Object.keys(result.values).filter(k => !(k in result.present) && !(k in result.inputs) && !structure.quiet.has(k) && JSON.stringify(result.values[k]) !== JSON.stringify(previous.values[k]))\n if (changed.length) out.push(`${names(changed.map(k => `${f.code(k)} is now ${f.code(show(result.values[k]))}`))}.`)\n }\n if (!fired.length && result.tick > 1 && !structure.dataflow) {\n const waiting = result.log.filter(e => e.kind === 'check' && !e.result).map(e => (e.kind === 'check' ? e.transition : ''))\n const ts = [...new Set(waiting)].map(id => ({ id, t: resolveTransition(id, idx)?.t })).filter((x): x is { id: string; t: Transition } => !!x.t && !suspendedHere(x.t.source, result, idx))\n if (ts.length) {\n const parts = ts.slice(0, 3).map(({ id, t }) => {\n // The copy a state of a referenced chart is in: the transition's prefix with the state's own id.\n const source = id.includes('/') ? `${id.slice(0, id.lastIndexOf('/') + 1)}${t.source}` : t.source\n const what = t.trigger ? `${f.code(formatExpression(t.trigger))}${countSuffix(t)}` : t.preemption === 'termination' ? 'its inside to finish' : 'the next tick'\n return `${stateInCopy(source, idx, f) ?? stateName(t.source)} waits for ${what}`\n })\n out.push(`No transition fired: ${names(parts)}.`)\n } else if (!result.log.some(e => e.kind === 'suspend')) {\n out.push('No transition fired.')\n }\n }\n if (result.terminatedNow) out.push('Every top-level region reached a final state, so the chart terminated. Nothing happens in later ticks.')\n else if (result.terminated) out.push('The chart has terminated: nothing happens any more.')\n if (result.printed.length) out.push(`It printed ${names(result.printed.map(p => f.code(JSON.stringify(p))))}.`)\n return out\n}\n\n/**\n * A trigger that is one variable or signal, or its negation, said naturally from what it read: \"button was true\",\n * \"S was absent\". Undefined for anything else (the caller says \"n == 0 held (n was 0)\").\n */\nfunction simpleReason(trigger: Expression, seen: TraceSeen[] | undefined, f: Fmt): string | undefined {\n const negated = trigger.kind === 'op' && trigger.op === '!' && trigger.args[0].kind === 'ref'\n const ref = negated ? (trigger as Extract<Expression, { kind: 'op' }>).args[0] : trigger\n if (ref.kind !== 'ref' || ref.indices.length || ref.sub) return undefined\n const s = seen?.find(x => x.name === ref.name)\n if (!s || typeof s.value !== 'boolean') return undefined\n if (s.signal) return `${f.code(ref.name)} was ${s.value ? 'present' : 'absent'}`\n return `${f.code(ref.name)} was ${f.code(String(s.value))}`\n}\n\n/**\n * Values at the end of the tick, by name, for checking a trigger that was not checked: a pure signal is its\n * presence, a valued one its value (`val(S)` and presence are told apart by `present`).\n */\nfunction holdsNow(e: Expression, result: TickResult): boolean | number | undefined {\n const value = (x: Expression): Value | undefined => {\n switch (x.kind) {\n case 'bool': case 'int': case 'float': return x.value\n case 'ref': {\n if (x.indices.length || x.sub) return undefined\n // A signal on its own is its presence (a valued signal's value is val(S)).\n if (x.name in result.present) return result.present[x.name]\n const v = result.values[x.name]\n return v === undefined ? undefined : v\n }\n case 'op': {\n const args = x.args.map(value)\n if (args.some(a => a === undefined || a === null || typeof a === 'string' || Array.isArray(a))) return undefined\n const [a, b] = args as (number | boolean)[]\n const n = (v: number | boolean) => Number(v)\n switch (x.op) {\n case '!': return !a\n case '&&': return (args as (number | boolean)[]).every(Boolean)\n case '||': return (args as (number | boolean)[]).some(Boolean)\n case '==': return n(a) === n(b)\n case '!=': return n(a) !== n(b)\n case '<': return n(a) < n(b)\n case '<=': return n(a) <= n(b)\n case '>': return n(a) > n(b)\n case '>=': return n(a) >= n(b)\n default: return undefined\n }\n }\n default: return undefined\n }\n }\n const v = value(e)\n return typeof v === 'boolean' || typeof v === 'number' ? v : undefined\n}\n\n/**\n * States entered in this tick whose delayed transitions' triggers already hold: \"coin is true, but Locked was entered\n * in this tick: its transitions are delayed, so they are first checked in tick 2.\" (A delayed transition is not\n * checked in the tick its state is entered.)\n */\nfunction delayedSentences(result: TickResult, idx: Index, stateName: (id: string) => string, f: Fmt): string[] {\n const out: string[] = []\n const active = new Set(result.active)\n // A state left and entered again in this tick (a self-loop, a superstate's reset) was just checked: the sentence\n // after \"Ready went to Ready because press was true\" would only confuse.\n const left = new Set(result.exited)\n for (const id of result.entered) {\n if (!active.has(id) || id.includes('/') || left.has(id)) continue\n const s = idx.states.get(id)\n if (!s || s.isRoot || s.connector || s.reference) continue\n const delayed = s.transitions.filter(t => t.delay !== 'immediate' && t.trigger && !(t.triggerDelay !== undefined && t.triggerDelay > 1))\n const holding = delayed.find(t => holdsNow(t.trigger!, result) === true)\n if (!holding) continue\n const name = stateName(id)\n const many = s.transitions.filter(t => t.delay !== 'immediate').length > 1\n out.push(`${holdsText(holding.trigger!, result, f)}, but ${name} was entered in this tick: its ${many ? 'transitions are' : 'transition is'} delayed, so ${many ? 'they are' : 'it is'} first checked in tick ${result.tick + 1}.`)\n }\n return out\n}\n\n/** \"coin is true\", \"S is present\", \"n > 2 holds\" (at the end of the tick). */\nfunction holdsText(trigger: Expression, result: TickResult, f: Fmt): string {\n const negated = trigger.kind === 'op' && trigger.op === '!' && trigger.args[0].kind === 'ref'\n const ref = negated ? (trigger as Extract<Expression, { kind: 'op' }>).args[0] : trigger\n if (ref.kind === 'ref' && !ref.indices.length && !ref.sub) {\n const signal = ref.name in result.present\n if (signal) return `${f.code(ref.name)} is ${negated ? 'absent' : 'present'}`\n return `${f.code(ref.name)} is ${f.code(negated ? 'false' : 'true')}`\n }\n return `${f.code(formatExpression(trigger))} holds`\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { State, TickResult, TraceSeen, Transition } from "../types.js";
2
+ import { type Fmt } from "./describeStructure.js";
3
+ export interface DescribeIndex {
4
+ states: Map<string, State>;
5
+ parents: Map<string, State>;
6
+ }
7
+ /** "held" for a trigger, or the count delay's "held for the 3rd time while S was active". */
8
+ export declare function heldPhrase(t: Transition, from: string): string;
9
+ /** A count delay's " for the 3rd time while S was active", or nothing. */
10
+ export declare function countPhrase(t: Transition, from: string): string;
11
+ /** For a waiting count delay: " (the 3rd time)". */
12
+ export declare function countSuffix(t: Transition): string;
13
+ /** What an abort of a superstate meant for its inside (appended to the transition's sentence). */
14
+ export declare function abortClause(t: Transition, idx: DescribeIndex, f?: Fmt): string;
15
+ /** The states suspended in this tick: one sentence each. */
16
+ export declare function suspendSentences(result: TickResult, idx: DescribeIndex, f?: Fmt): string[];
17
+ /** The executor's plain-English notes (history, deferred entries, weak suspension, KIELER's GO block). */
18
+ export declare function noteSentences(result: TickResult, f?: Fmt): string[];
19
+ /** What a trigger read, "n was 0 and S was present", with names and values as code in Markdown (reasons.ts seenText). */
20
+ export declare function seenPhrase(seen: TraceSeen[], f?: Fmt): string;
21
+ /** Is the state (or an ancestor) suspended in this tick? Its transitions are not waiting for their triggers then. */
22
+ export declare function suspendedHere(stateId: string, result: TickResult, idx: DescribeIndex): boolean;
@@ -0,0 +1,90 @@
1
+ // describeTick's sentences for preemption (describe.ts calls these): what a strong or weak abort meant for the
2
+ // inside of a superstate, count delays, suspended states, and the notes the executor logged for history,
3
+ // deferred entries and weak suspension (preemptionLog.ts).
4
+ import { formatExpression, stateDisplayName } from "../format.js";
5
+ import { PLAIN } from "./describeStructure.js";
6
+ function ordinal(n) {
7
+ const tens = n % 100;
8
+ if (tens >= 11 && tens <= 13)
9
+ return `${n}th`;
10
+ switch (n % 10) {
11
+ case 1: return `${n}st`;
12
+ case 2: return `${n}nd`;
13
+ case 3: return `${n}rd`;
14
+ default: return `${n}th`;
15
+ }
16
+ }
17
+ const hasInside = (s) => !!s && s.regions.some(r => r.states.length > 0);
18
+ /** "held" for a trigger, or the count delay's "held for the 3rd time while S was active". */
19
+ export function heldPhrase(t, from) {
20
+ return t.triggerDelay !== undefined && t.triggerDelay > 1 ? `held for the ${ordinal(t.triggerDelay)} time while ${from} was active` : 'held';
21
+ }
22
+ /** A count delay's " for the 3rd time while S was active", or nothing. */
23
+ export function countPhrase(t, from) {
24
+ return t.triggerDelay !== undefined && t.triggerDelay > 1 ? ` for the ${ordinal(t.triggerDelay)} time while ${from} was active` : '';
25
+ }
26
+ /** For a waiting count delay: " (the 3rd time)". */
27
+ export function countSuffix(t) {
28
+ return t.triggerDelay !== undefined && t.triggerDelay > 1 ? ` (the ${ordinal(t.triggerDelay)} time)` : '';
29
+ }
30
+ /** What an abort of a superstate meant for its inside (appended to the transition's sentence). */
31
+ export function abortClause(t, idx, f = PLAIN) {
32
+ const source = idx.states.get(t.source);
33
+ if (!hasInside(source))
34
+ return '';
35
+ const name = f.code(stateDisplayName(source));
36
+ if (t.preemption === 'strong')
37
+ return `, so the inside of ${name} did not react in this tick (a strong abort)`;
38
+ if (t.preemption === 'weak')
39
+ return `, after the inside of ${name} finished its reaction for this tick (a weak abort)`;
40
+ return '';
41
+ }
42
+ /** The states suspended in this tick: one sentence each. */
43
+ export function suspendSentences(result, idx, f = PLAIN) {
44
+ const out = [];
45
+ for (const e of result.log) {
46
+ if (e.kind !== 'suspend')
47
+ continue;
48
+ const s = idx.states.get(e.state);
49
+ if (!s)
50
+ continue;
51
+ const name = f.code(stateDisplayName(s));
52
+ const triggers = s.actions.filter(a => a.kind === 'suspend' && !a.weak && a.trigger).map(a => a.trigger);
53
+ const text = triggers.map(x => f.code(formatExpression(x))).join(' or ');
54
+ // What the triggers read when the suspension was decided (exec.ts), not after the tick.
55
+ const why = f.md && e.seen?.length ? seenPhrase(e.seen, f) : e.reason ?? '';
56
+ out.push(`${name} is suspended${text ? ` because ${text} holds${why ? ` (${why})` : ''}` : ''}: nothing inside ${name} moves in this tick and its own transitions wait too.`);
57
+ }
58
+ return out;
59
+ }
60
+ /** The executor's plain-English notes (history, deferred entries, weak suspension, KIELER's GO block). */
61
+ export function noteSentences(result, f = PLAIN) {
62
+ const out = [];
63
+ for (const e of result.log) {
64
+ if (e.kind !== 'note')
65
+ continue;
66
+ const text = f.md ? e.markdown ?? e.text : e.text;
67
+ if (!out.includes(text))
68
+ out.push(text);
69
+ }
70
+ return out;
71
+ }
72
+ /** What a trigger read, "n was 0 and S was present", with names and values as code in Markdown (reasons.ts seenText). */
73
+ export function seenPhrase(seen, f = PLAIN) {
74
+ const show = (v) => (v === null ? 'null' : Array.isArray(v) ? `{${v.map(show).join(', ')}}` : typeof v === 'string' ? JSON.stringify(v) : String(v));
75
+ const parts = seen.map(s => (s.signal ? `${f.code(s.name)} was ${s.value ? 'present' : 'absent'}` : `${f.code(s.name)} was ${f.code(show(s.value))}`));
76
+ if (parts.length <= 1)
77
+ return parts.join('');
78
+ return `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`;
79
+ }
80
+ /** Is the state (or an ancestor) suspended in this tick? Its transitions are not waiting for their triggers then. */
81
+ export function suspendedHere(stateId, result, idx) {
82
+ const suspended = new Set(result.log.flatMap(e => (e.kind === 'suspend' ? [e.state] : [])));
83
+ if (!suspended.size)
84
+ return false;
85
+ for (let s = idx.states.get(stateId); s; s = idx.parents.get(s.id))
86
+ if (suspended.has(s.id))
87
+ return true;
88
+ return false;
89
+ }
90
+ //# sourceMappingURL=describePreemption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describePreemption.js","sourceRoot":"","sources":["../../src/sim/describePreemption.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,yGAAyG;AACzG,2DAA2D;AAG3D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,qBAAiB;AAC9D,OAAO,EAAE,KAAK,EAAY,+BAA2B;AAOrD,SAAS,OAAO,CAAC,CAAS;IACtB,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,CAAA;IACpB,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC,IAAI,CAAA;IAC7C,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC;QACb,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAA;QACvB,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAA;QACvB,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAA;QACvB,OAAO,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAA;IAC5B,CAAC;AACL,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,CAAoB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,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AAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC3H,OAAO,KAAK,CAAA;AAChB,CAAC","sourcesContent":["// describeTick's sentences for preemption (describe.ts calls these): what a strong or weak abort meant for the\n// inside of a superstate, count delays, suspended states, and the notes the executor logged for history,\n// deferred entries and weak suspension (preemptionLog.ts).\n\nimport type { State, TickResult, TraceSeen, Transition } from '../types'\nimport { formatExpression, stateDisplayName } from '../format'\nimport { PLAIN, type Fmt } from './describeStructure'\n\nexport interface DescribeIndex {\n states: Map<string, State>\n parents: Map<string, State>\n}\n\nfunction ordinal(n: number): string {\n const tens = n % 100\n if (tens >= 11 && tens <= 13) return `${n}th`\n switch (n % 10) {\n case 1: return `${n}st`\n case 2: return `${n}nd`\n case 3: return `${n}rd`\n default: return `${n}th`\n }\n}\n\nconst hasInside = (s: State | undefined) => !!s && s.regions.some(r => r.states.length > 0)\n\n/** \"held\" for a trigger, or the count delay's \"held for the 3rd time while S was active\". */\nexport function heldPhrase(t: Transition, from: string): string {\n return t.triggerDelay !== undefined && t.triggerDelay > 1 ? `held for the ${ordinal(t.triggerDelay)} time while ${from} was active` : 'held'\n}\n\n/** A count delay's \" for the 3rd time while S was active\", or nothing. */\nexport function countPhrase(t: Transition, from: string): string {\n return t.triggerDelay !== undefined && t.triggerDelay > 1 ? ` for the ${ordinal(t.triggerDelay)} time while ${from} was active` : ''\n}\n\n/** For a waiting count delay: \" (the 3rd time)\". */\nexport function countSuffix(t: Transition): string {\n return t.triggerDelay !== undefined && t.triggerDelay > 1 ? ` (the ${ordinal(t.triggerDelay)} time)` : ''\n}\n\n/** What an abort of a superstate meant for its inside (appended to the transition's sentence). */\nexport function abortClause(t: Transition, idx: DescribeIndex, f: Fmt = PLAIN): string {\n const source = idx.states.get(t.source)\n if (!hasInside(source)) return ''\n const name = f.code(stateDisplayName(source!))\n if (t.preemption === 'strong') return `, so the inside of ${name} did not react in this tick (a strong abort)`\n if (t.preemption === 'weak') return `, after the inside of ${name} finished its reaction for this tick (a weak abort)`\n return ''\n}\n\n/** The states suspended in this tick: one sentence each. */\nexport function suspendSentences(result: TickResult, idx: DescribeIndex, f: Fmt = PLAIN): string[] {\n const out: string[] = []\n for (const e of result.log) {\n if (e.kind !== 'suspend') continue\n const s = idx.states.get(e.state)\n if (!s) continue\n const name = f.code(stateDisplayName(s))\n const triggers = s.actions.filter(a => a.kind === 'suspend' && !a.weak && a.trigger).map(a => a.trigger!)\n const text = triggers.map(x => f.code(formatExpression(x))).join(' or ')\n // What the triggers read when the suspension was decided (exec.ts), not after the tick.\n const why = f.md && e.seen?.length ? seenPhrase(e.seen, f) : e.reason ?? ''\n out.push(`${name} is suspended${text ? ` because ${text} holds${why ? ` (${why})` : ''}` : ''}: nothing inside ${name} moves in this tick and its own transitions wait too.`)\n }\n return out\n}\n\n/** The executor's plain-English notes (history, deferred entries, weak suspension, KIELER's GO block). */\nexport function noteSentences(result: TickResult, f: Fmt = PLAIN): string[] {\n const out: string[] = []\n for (const e of result.log) {\n if (e.kind !== 'note') continue\n const text = f.md ? e.markdown ?? e.text : e.text\n if (!out.includes(text)) out.push(text)\n }\n return out\n}\n\n/** What a trigger read, \"n was 0 and S was present\", with names and values as code in Markdown (reasons.ts seenText). */\nexport function seenPhrase(seen: TraceSeen[], f: Fmt = PLAIN): string {\n const show = (v: unknown): string => (v === null ? 'null' : Array.isArray(v) ? `{${v.map(show).join(', ')}}` : typeof v === 'string' ? JSON.stringify(v) : String(v))\n const parts = seen.map(s => (s.signal ? `${f.code(s.name)} was ${s.value ? 'present' : 'absent'}` : `${f.code(s.name)} was ${f.code(show(s.value))}`))\n if (parts.length <= 1) return parts.join('')\n return `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`\n}\n\n/** Is the state (or an ancestor) suspended in this tick? Its transitions are not waiting for their triggers then. */\nexport function suspendedHere(stateId: string, result: TickResult, idx: DescribeIndex): boolean {\n const suspended = new Set(result.log.flatMap(e => (e.kind === 'suspend' ? [e.state] : [])))\n if (!suspended.size) return false\n for (let s: State | undefined = idx.states.get(stateId); s; s = idx.parents.get(s.id)) if (suspended.has(s.id)) return true\n return false\n}\n"]}
@@ -0,0 +1,75 @@
1
+ import type { Program, State, TickResult, Transition } from "../types.js";
2
+ interface Index {
3
+ states: Map<string, State>;
4
+ transitions: Map<string, Transition>;
5
+ }
6
+ /** How describeTick writes names: as they are, or (Markdown) as code. */
7
+ export interface Fmt {
8
+ md: boolean;
9
+ code(s: string): string;
10
+ }
11
+ export declare const PLAIN: Fmt;
12
+ export declare const MARKDOWN: Fmt;
13
+ /** The source state an id stands for, also inside instances. */
14
+ export declare function resolveState(id: string, idx: Index): State | undefined;
15
+ /** One reference an element is inside of: the reference state's (or `ref` declaration's) name and the chart. */
16
+ export interface InstanceInfo {
17
+ name: string;
18
+ chart: string;
19
+ /** The referenced chart's inputs and outputs bound to another name: formal -> the actual as written. */
20
+ bindings: Map<string, string>;
21
+ }
22
+ /** Where an element of an instance is: the references it is inside of (innermost first), or a base chart. */
23
+ export interface Within {
24
+ instances: InstanceInfo[];
25
+ /** Inherited from this chart (passes/inheritance.ts prefixes the inheriting state). */
26
+ inherited?: string;
27
+ }
28
+ /**
29
+ * "Inside `Left` (a copy of `PushSwitch`, with `press` bound to `left`)", innermost reference first; `read` are the
30
+ * names the sentence mentions (bindings of other formals are left out).
31
+ */
32
+ export declare function withinPhrase(w: Within, f: Fmt, read?: string[]): string;
33
+ /** The source transition an id stands for, and where it is when it belongs to a referenced chart's copy. */
34
+ export declare function resolveTransition(id: string, idx: Index): {
35
+ t: Transition;
36
+ within?: Within;
37
+ } | undefined;
38
+ /** "`Off` (inside `Left`)": a state, and the copy it is in when it is in one. */
39
+ export declare function stateInCopy(id: string, idx: Index, f: Fmt): string | undefined;
40
+ /**
41
+ * A readable name for any element id of a tick (states, transitions, regions, actions), also inside the copies of
42
+ * referenced charts and for-region copies: `{ name: 'Off → On', within: 'inside Left (a copy of PushSwitch)' }`.
43
+ * For "Explain this tick" and anything else that shows log events. Undefined for ids it does not know.
44
+ */
45
+ export declare function elementName(id: string, idx: Index & {
46
+ regions?: Map<string, {
47
+ name?: string;
48
+ parent: State;
49
+ }>;
50
+ actions?: Map<string, {
51
+ kind: string;
52
+ owner: State;
53
+ }>;
54
+ }, f?: Fmt): {
55
+ name: string;
56
+ within?: string;
57
+ } | undefined;
58
+ /** For each taken transition (in `result.taken` order), the for-region copy it fired in, as a phrase. */
59
+ export declare function copyPhrases(result: TickResult, f?: Fmt): (string | undefined)[];
60
+ /** The log without the copy notes (they are folded into the transitions' sentences). */
61
+ export declare function withoutCopyNotes(result: TickResult): TickResult;
62
+ /** "`Off` (inside `Left`)" for the instances active in tick 1, as phrases for "The chart starts in ...". */
63
+ export declare function instanceLeaves(result: TickResult, idx: Index, f?: Fmt): string[];
64
+ export type { Program };
65
+ /**
66
+ * Sentences about clocks, periods and dataflow regions: "Time passed: the clock t advanced to 300 (deltaT = 100).",
67
+ * "The dataflow equations computed O = true." `before` come before the transitions (time passes first), `after`
68
+ * after them; `quiet` are the variables these sentences cover (left out of "x is now ...").
69
+ */
70
+ export declare function structureSentences(result: TickResult, program: Program, f?: Fmt): {
71
+ before: string[];
72
+ after: string[];
73
+ quiet: Set<string>;
74
+ dataflow: boolean;
75
+ };