@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,772 @@
1
+ // The simulator's working model: a mutable copy of the chart in KIELER's SCCharts metamodel terms (states,
2
+ // regions, transitions, local actions, valued objects), which the desugaring passes rewrite into core SCCharts
3
+ // exactly as KIELER's processors do, and which scg.ts then turns into a sequentially constructive graph.
4
+ //
5
+ // Everything carries provenance back to the source: `origin` is the id (types.ts) of the source element a
6
+ // model element is, `about` the source element a generated element implements, and effects carry the
7
+ // source element that ran them. The helpers below mirror KIELER's extension methods
8
+ // (SCChartsStateExtensions, SCChartsTransitionExtensions, SCChartsActionExtensions, ...) with the same
9
+ // semantics, including their quirks, because the passes are ported from KIELER line by line.
10
+ let uidCounter = 0;
11
+ const nextUid = () => ++uidCounter;
12
+ export class CVar {
13
+ uid = nextUid();
14
+ name;
15
+ type;
16
+ hostType;
17
+ signal = false;
18
+ input = false;
19
+ output = false;
20
+ const = false;
21
+ static = false;
22
+ extern = false;
23
+ global = false;
24
+ /** Array cardinalities (int literals after const inlining). */
25
+ dims = [];
26
+ init;
27
+ combine;
28
+ /** Declaration scope. */
29
+ scope;
30
+ /** Source ValuedObject id (types.ts `<scopeId>$<name>`) of the declaration this variable is or implements. */
31
+ decl;
32
+ /** Name the reader knows the variable by (the signal's name for `V_val`, the variable's for `_pre_x`). */
33
+ display;
34
+ /** What a generated variable is for: 'value' | 'curval' | 'pre' | 'reg' | 'term' | 'trig' | 'exit' | ... */
35
+ role;
36
+ /** The source variable a generated one belongs to (the signal of `V_val`, the operand of `_pre_x`). */
37
+ of;
38
+ /** Created by a pass (KIELER prefixes such names with `_`; they are not in KIELER's data pool). */
39
+ generated = false;
40
+ /** Declaration span (for diagnostics). */
41
+ span;
42
+ /** Annotations by name (KIELER's tag annotations on valued objects, e.g. `_termination_delayed`). */
43
+ tags = new Set();
44
+ /** The source declaration kind when it is not a plain variable (method, class, ...): handled by other passes. */
45
+ declKind;
46
+ /** A method (declKind 'method', or a code effect's generated `_effect<n>`): its parameters and SCL body. */
47
+ method;
48
+ /** A member of a class or struct instance (lower.ts declareMembers): the instance and the member's name. */
49
+ member;
50
+ /** `ref Chart x(args)` (declKind 'reference'): the chart it instantiates (structure.md S-18, S-33). */
51
+ instance;
52
+ /** A declaration of a state inside a for-region copy (passes/forRegion.ts): the source region and the counter's
53
+ * value in that copy. */
54
+ forCopy;
55
+ constructor(name, type) {
56
+ this.name = name;
57
+ this.type = type;
58
+ }
59
+ /** A pure signal before the Signal pass (no value). */
60
+ get pureSignal() {
61
+ return this.signal && (this.type === 'pure' || this.type === undefined);
62
+ }
63
+ }
64
+ export class CAction {
65
+ uid = nextUid();
66
+ kind;
67
+ delay = 'undefined';
68
+ /** Entry and exit actions: KIELER's PreemptionActionType; the metamodel default is strong. */
69
+ preemption = 'strong';
70
+ /** `weak suspend` */
71
+ weak = false;
72
+ triggerDelay;
73
+ trigger;
74
+ effects = [];
75
+ /** Source action id when this is a source action (types.ts `<stateId>!<kind><n>`). */
76
+ origin;
77
+ /** Source element a generated action implements. */
78
+ about;
79
+ span;
80
+ /** Names of the source action's annotations (`@HardReset period 300`). */
81
+ annotations = [];
82
+ constructor(kind) {
83
+ this.kind = kind;
84
+ }
85
+ }
86
+ export class CTransition {
87
+ uid = nextUid();
88
+ source;
89
+ target;
90
+ delay = 'undefined';
91
+ preemption = 'weak';
92
+ trigger;
93
+ effects = [];
94
+ triggerDelay;
95
+ history;
96
+ deferred;
97
+ /** Source transition id when this is (a move or a SurfaceDepth copy of) a source transition. */
98
+ origin;
99
+ /** Source element a generated transition implements (the abort it realises, the action it runs, ...). */
100
+ about;
101
+ /** The source transition whose trigger this generated transition tests (an abort's copies), for the log. */
102
+ checks;
103
+ /** String annotations by name (KIELER's `_termination` annotation and similar markers). */
104
+ annotations = new Map();
105
+ span;
106
+ }
107
+ export class CRegion {
108
+ uid = nextUid();
109
+ name;
110
+ label;
111
+ parent;
112
+ states = [];
113
+ decls = [];
114
+ actions = [];
115
+ /** Source region id. */
116
+ origin;
117
+ /** Source element a generated region implements. */
118
+ about;
119
+ dataflow = false;
120
+ final = false;
121
+ abort = false;
122
+ override = false;
123
+ annotations = new Map();
124
+ /** Extension point for the structure passes (for-regions, dataflow equations, references). */
125
+ ext = {};
126
+ get isRegion() { return true; }
127
+ }
128
+ export class CState {
129
+ uid = nextUid();
130
+ name;
131
+ label;
132
+ parent;
133
+ initial = false;
134
+ final = false;
135
+ connector = false;
136
+ violation = false;
137
+ /** The scchart itself. */
138
+ root = false;
139
+ decls = [];
140
+ actions = [];
141
+ regions = [];
142
+ /** Outgoing transitions in priority order. */
143
+ out = [];
144
+ /** Incoming transitions (kept in sync by the helpers below). */
145
+ incoming = [];
146
+ /** Source state id. */
147
+ origin;
148
+ /** Source element a generated state implements (the superstate whose abort it realises, ...). */
149
+ about;
150
+ annotations = new Map();
151
+ /** Extension point for the structure passes (references `is`, ...). */
152
+ ext = {};
153
+ constructor(name) {
154
+ this.name = name;
155
+ }
156
+ get isRegion() { return false; }
157
+ }
158
+ export function isRegion(s) {
159
+ return s.isRegion;
160
+ }
161
+ // ---------------------------------------------------------------------------------------------------
162
+ // Constructors and structural edits (SCChartsStateExtensions, SCChartsTransitionExtensions, ...)
163
+ // ---------------------------------------------------------------------------------------------------
164
+ export function createState(region, name) {
165
+ const s = new CState(name);
166
+ s.parent = region;
167
+ region.states.push(s);
168
+ return s;
169
+ }
170
+ export function createInitialState(region, name) {
171
+ const s = createState(region, name);
172
+ s.initial = true;
173
+ return s;
174
+ }
175
+ export function createFinalState(region, name) {
176
+ const s = createState(region, name);
177
+ s.final = true;
178
+ return s;
179
+ }
180
+ /** KIELER's createControlflowRegion(state, id): reuses a single empty implicit region instead of adding one. */
181
+ export function createControlflowRegion(state, name) {
182
+ if (state.regions.length === 1 && !state.regions[0].dataflow && allContainedStates(state.regions[0]).length === 0) {
183
+ const implicit = state.regions[0];
184
+ implicit.name = name;
185
+ return implicit;
186
+ }
187
+ const r = new CRegion();
188
+ r.name = name;
189
+ r.parent = state;
190
+ state.regions.push(r);
191
+ return r;
192
+ }
193
+ export function addRegion(state, region, index) {
194
+ if (region.parent && region.parent !== state) {
195
+ const list = region.parent.regions;
196
+ const i = list.indexOf(region);
197
+ if (i >= 0)
198
+ list.splice(i, 1);
199
+ }
200
+ region.parent = state;
201
+ if (index === undefined)
202
+ state.regions.push(region);
203
+ else
204
+ state.regions.splice(index, 0, region);
205
+ }
206
+ /** Moves a state into a region (EMF containment: it leaves its previous region). */
207
+ export function addState(region, state) {
208
+ if (state.parent) {
209
+ const list = state.parent.states;
210
+ const i = list.indexOf(state);
211
+ if (i >= 0)
212
+ list.splice(i, 1);
213
+ }
214
+ state.parent = region;
215
+ region.states.push(state);
216
+ }
217
+ /** Detaches a state from its region. Its transitions stay attached to it (as in EMF). */
218
+ export function removeState(state) {
219
+ if (!state.parent)
220
+ return;
221
+ const list = state.parent.states;
222
+ const i = list.indexOf(state);
223
+ if (i >= 0)
224
+ list.splice(i, 1);
225
+ }
226
+ export function setTarget(t, target) {
227
+ if (t.target) {
228
+ const i = t.target.incoming.indexOf(t);
229
+ if (i >= 0)
230
+ t.target.incoming.splice(i, 1);
231
+ }
232
+ t.target = target;
233
+ target.incoming.push(t);
234
+ }
235
+ /** Moves a transition to a new source (appended: lowest priority), as KIELER's setSourceState. */
236
+ export function setSource(t, source, index) {
237
+ if (t.source) {
238
+ const i = t.source.out.indexOf(t);
239
+ if (i >= 0)
240
+ t.source.out.splice(i, 1);
241
+ }
242
+ t.source = source;
243
+ if (index === undefined)
244
+ source.out.push(t);
245
+ else
246
+ source.out.splice(index, 0, t);
247
+ }
248
+ /** Removes a transition from its source and target. */
249
+ export function removeTransition(t) {
250
+ const i = t.source.out.indexOf(t);
251
+ if (i >= 0)
252
+ t.source.out.splice(i, 1);
253
+ const j = t.target?.incoming.indexOf(t) ?? -1;
254
+ if (j >= 0)
255
+ t.target.incoming.splice(j, 1);
256
+ }
257
+ export function createTransitionTo(source, target, index) {
258
+ const t = new CTransition();
259
+ setTarget(t, target);
260
+ setSource(t, source, index);
261
+ return t;
262
+ }
263
+ export function createImmediateTransitionTo(source, target) {
264
+ const t = createTransitionTo(source, target);
265
+ t.delay = 'immediate';
266
+ return t;
267
+ }
268
+ export function setHighestPriority(t) {
269
+ setSource(t, t.source, 0);
270
+ }
271
+ export function setLowestPriority(t) {
272
+ setSource(t, t.source);
273
+ }
274
+ /** KIELER's setSpecificPriority (1-based). */
275
+ export function setSpecificPriority(t, priority) {
276
+ const list = t.source.out;
277
+ list.splice(list.indexOf(t), 1);
278
+ const index = priority > list.length ? list.length : priority - 1;
279
+ list.splice(index, 0, t);
280
+ }
281
+ /** SCChartsTransitionExtensions.isImplicitlyImmediate. */
282
+ export function isImplicitlyImmediate(t) {
283
+ return t.delay === 'immediate' || t.source.connector ||
284
+ (t.preemption === 'termination' && t.trigger === undefined && t.delay !== 'delayed');
285
+ }
286
+ /** SCChartsActionExtensions.isImmediate: the delay is IMMEDIATE (entry and exit actions always are). */
287
+ export function isImmediate(a) {
288
+ if (a instanceof CAction && (a.kind === 'entry' || a.kind === 'exit'))
289
+ return true;
290
+ return a.delay === 'immediate';
291
+ }
292
+ /** setImmediate(boolean) on an action or transition: IMMEDIATE or UNDEFINED. */
293
+ export function setImmediate(a, immediate = true) {
294
+ a.delay = immediate ? 'immediate' : 'undefined';
295
+ }
296
+ export const isTermination = (t) => t.preemption === 'termination';
297
+ export const isStrongAbort = (t) => t.preemption === 'strong';
298
+ export const isWeakAbort = (t) => t.preemption === 'weak';
299
+ export function createAction(scope, kind, index) {
300
+ const a = new CAction(kind);
301
+ if (index === undefined)
302
+ scope.actions.push(a);
303
+ else
304
+ scope.actions.splice(index, 0, a);
305
+ return a;
306
+ }
307
+ export function createEntryAction(scope, index) {
308
+ return createAction(scope, 'entry', index);
309
+ }
310
+ export function createImmediateDuringAction(scope) {
311
+ const a = createAction(scope, 'during');
312
+ a.delay = 'immediate';
313
+ return a;
314
+ }
315
+ export function removeAction(scope, action) {
316
+ const i = scope.actions.indexOf(action);
317
+ if (i >= 0)
318
+ scope.actions.splice(i, 1);
319
+ }
320
+ export function addVar(scope, v, index) {
321
+ if (v.scope) {
322
+ const list = v.scope.decls;
323
+ const i = list.indexOf(v);
324
+ if (i >= 0)
325
+ list.splice(i, 1);
326
+ }
327
+ v.scope = scope;
328
+ if (index === undefined)
329
+ scope.decls.push(v);
330
+ else
331
+ scope.decls.splice(index, 0, v);
332
+ }
333
+ /** A generated (hidden) variable, as KIELER's createValuedObject(...).uniqueName in a scope. */
334
+ export function createVar(scope, name, type, role) {
335
+ const v = new CVar(name, type);
336
+ v.generated = name.startsWith('_');
337
+ v.role = role;
338
+ addVar(scope, v);
339
+ return v;
340
+ }
341
+ // ----- queries -----
342
+ /**
343
+ * A state's name as the reader knows it: the compiler's own states (`_AC`, `__df_main`, KIELER names them with `_`)
344
+ * are named after the nearest enclosing state the chart has.
345
+ */
346
+ export function readableName(s) {
347
+ for (let x = s; x; x = x.parent?.parent)
348
+ if (!x.name.startsWith('_'))
349
+ return x.name;
350
+ return undefined;
351
+ }
352
+ /** A name in code font (a diagnostic's message or hint is inline Markdown); undefined stays undefined. */
353
+ export function quoted(name) {
354
+ return name === undefined ? undefined : `\`${name}\``;
355
+ }
356
+ /** A region's name, unless the compiler made it (then undefined: "a region of S"). */
357
+ export function readableRegionName(r) {
358
+ return r?.name && !r.name.startsWith('_') ? r.name : undefined;
359
+ }
360
+ export function isRootState(s) {
361
+ return s.root;
362
+ }
363
+ export function isHierarchical(s) {
364
+ return s.regions.length > 0;
365
+ }
366
+ export function controlflowRegions(s) {
367
+ return s.regions.filter(r => !r.dataflow);
368
+ }
369
+ /** SCChartsControlflowRegionExtensions.controlflowRegionsContainStates (a referencing region counts as well). */
370
+ export function controlflowRegionsContainStates(s) {
371
+ return controlflowRegions(s).some(r => r.states.length > 0 || r.ext.reference !== undefined);
372
+ }
373
+ export function containsInnerActions(s) {
374
+ return s.actions.some(a => a.kind === 'during' || a.kind === 'exit' || a.kind === 'entry');
375
+ }
376
+ export function actionsOf(scope, kind) {
377
+ return scope.actions.filter(a => a.kind === kind);
378
+ }
379
+ export function finalStates(r) {
380
+ return r.states.filter(s => s.final);
381
+ }
382
+ export function initialState(r) {
383
+ return r.states.find(s => s.initial);
384
+ }
385
+ /** regionsMayTerminate: every non-final control-flow region has a final state. */
386
+ export function regionsMayTerminate(s) {
387
+ return controlflowRegions(s).filter(r => !r.final).every(r => finalStates(r).length > 0);
388
+ }
389
+ /** SCChartsTransformationExtension.isImmediatelyReachable (from an initial state by implicitly immediate transitions). */
390
+ export function isImmediatelyReachable(finalState) {
391
+ if (finalState.initial)
392
+ return true;
393
+ const visited = new Set([finalState]);
394
+ const next = finalState.incoming.filter(isImplicitlyImmediate);
395
+ while (next.length) {
396
+ const t = next.shift();
397
+ if (!visited.has(t.source)) {
398
+ if (t.source.initial)
399
+ return true;
400
+ visited.add(t.source);
401
+ next.push(...t.source.incoming.filter(isImplicitlyImmediate));
402
+ }
403
+ }
404
+ return false;
405
+ }
406
+ export function canImmediateTerminateRegion(r) {
407
+ return r.states.filter(s => s.final).some(isImmediatelyReachable);
408
+ }
409
+ export function canImmediateTerminate(s) {
410
+ return controlflowRegions(s).every(canImmediateTerminateRegion);
411
+ }
412
+ export function canImmediateAborted(s) {
413
+ return s.out.some(t => (isStrongAbort(t) || isWeakAbort(t)) && isImplicitlyImmediate(t));
414
+ }
415
+ /** A final state without outgoing transitions, inner behaviour or actions (getSimpleFinalStates). */
416
+ export function simpleFinalState(r) {
417
+ return finalStates(r).find(s => s.out.length === 0 && !controlflowRegionsContainStates(s) && s.actions.length === 0);
418
+ }
419
+ export function getOrCreateSimpleFinalState(r, name) {
420
+ return simpleFinalState(r) ?? createFinalState(r, name);
421
+ }
422
+ /** StateIterator.getStateIterator: pre-order over states, a state's regions in order, each region's states in order. */
423
+ export function allStates(s, includeRoot = true) {
424
+ const out = [];
425
+ const visit = (state, include) => {
426
+ if (include)
427
+ out.push(state);
428
+ for (const r of state.regions)
429
+ for (const c of r.states)
430
+ visit(c, true);
431
+ };
432
+ visit(s, includeRoot);
433
+ return out;
434
+ }
435
+ /** All states inside a state or region (not the scope itself). */
436
+ export function allContainedStates(scope) {
437
+ if (isRegion(scope)) {
438
+ const out = [];
439
+ for (const c of scope.states)
440
+ out.push(...allStates(c, true));
441
+ return out;
442
+ }
443
+ return allStates(scope, false);
444
+ }
445
+ /** sccAllScopes: every state and region, in pre-order (a state, then each of its regions and their contents). */
446
+ export function allScopes(s) {
447
+ const out = [];
448
+ const visit = (state) => {
449
+ out.push(state);
450
+ for (const r of state.regions) {
451
+ out.push(r);
452
+ for (const c of r.states)
453
+ visit(c);
454
+ }
455
+ };
456
+ visit(s);
457
+ return out;
458
+ }
459
+ export function allRegions(s) {
460
+ return allScopes(s).filter(isRegion);
461
+ }
462
+ /** Every transition of the chart (pre-order over states, each state's transitions in priority order). */
463
+ export function allTransitions(s) {
464
+ return allStates(s).flatMap(x => x.out);
465
+ }
466
+ /** The state that contains a scope's declarations at run time (a region's declarations belong to its parent). */
467
+ export function owningState(scope) {
468
+ return isRegion(scope) ? scope.parent : scope;
469
+ }
470
+ /** Nearest enclosing state of a region (its parent) or of a state (its parent region's parent). */
471
+ export function parentState(s) {
472
+ return s.parent?.parent;
473
+ }
474
+ // ---------------------------------------------------------------------------------------------------
475
+ // Expressions: copying, walking, building
476
+ // ---------------------------------------------------------------------------------------------------
477
+ export function copyExpr(e) {
478
+ if (!e)
479
+ return e;
480
+ switch (e.k) {
481
+ case 'lit':
482
+ case 'null':
483
+ case 'random':
484
+ case 'host':
485
+ case 'ignore':
486
+ case 'unsupported': return { ...e };
487
+ case 'ref': return copyRef(e);
488
+ case 'op': return { ...e, args: e.args.map(a => copyExpr(a)) };
489
+ case 'vector': return { ...e, values: e.values.map(a => copyExpr(a)) };
490
+ case 'call': return { ...e, args: e.args.map(a => copyExpr(a)), target: e.target ? copyRef(e.target) : undefined };
491
+ }
492
+ }
493
+ export function copyRef(r) {
494
+ return { k: 'ref', v: r.v, idx: r.idx.map(i => copyExpr(i)), sub: r.sub ? copyRef(r.sub) : undefined, span: r.span };
495
+ }
496
+ export function copyEffect(f) {
497
+ const o = { ...f.o };
498
+ switch (f.k) {
499
+ case 'assign': return { ...f, ref: copyRef(f.ref), expr: copyExpr(f.expr), o };
500
+ case 'emit': return { ...f, ref: copyRef(f.ref), value: copyExpr(f.value), o };
501
+ case 'print': return { ...f, args: f.args.map(a => copyExpr(a)), o };
502
+ case 'call': return { ...f, call: copyExpr(f.call), o };
503
+ default: return { ...f, o };
504
+ }
505
+ }
506
+ export function ref(v, idx = []) {
507
+ return { k: 'ref', v, idx };
508
+ }
509
+ export const TRUE = { k: 'lit', t: 'bool', v: true };
510
+ export const FALSE = { k: 'lit', t: 'bool', v: false };
511
+ export const lit = (v, t = typeof v === 'boolean' ? 'bool' : 'int') => ({ k: 'lit', t, v });
512
+ export function op(o, ...args) {
513
+ return { k: 'op', op: o, args };
514
+ }
515
+ /** KIELER's `and` of a list (null entries skipped; a single expression stays itself). */
516
+ export function and(list) {
517
+ const items = list.filter((e) => e !== undefined);
518
+ if (!items.length)
519
+ return undefined;
520
+ if (items.length === 1)
521
+ return items[0];
522
+ return { k: 'op', op: '&&', args: items };
523
+ }
524
+ export function or(list) {
525
+ const items = list.filter((e) => e !== undefined);
526
+ if (!items.length)
527
+ return undefined;
528
+ if (items.length === 1)
529
+ return items[0];
530
+ return { k: 'op', op: '||', args: items };
531
+ }
532
+ export function assign(v, expr, o = { hidden: true }, operator = '=') {
533
+ return { k: 'assign', ref: ref(v), op: operator, expr, o };
534
+ }
535
+ /** Calls `fn` on every expression node (pre-order), including indices and call arguments. */
536
+ export function walkExpr(e, fn) {
537
+ if (!e)
538
+ return;
539
+ fn(e);
540
+ switch (e.k) {
541
+ case 'ref':
542
+ walkRef(e, fn);
543
+ break;
544
+ case 'op':
545
+ for (const a of e.args)
546
+ walkExpr(a, fn);
547
+ break;
548
+ case 'vector':
549
+ for (const a of e.values)
550
+ walkExpr(a, fn);
551
+ break;
552
+ case 'call':
553
+ for (const a of e.args)
554
+ walkExpr(a, fn);
555
+ if (e.target)
556
+ walkRef(e.target, fn);
557
+ break;
558
+ default: break;
559
+ }
560
+ }
561
+ function walkRef(r, fn) {
562
+ for (const i of r.idx)
563
+ walkExpr(i, fn);
564
+ if (r.sub)
565
+ walkExpr(r.sub, fn);
566
+ }
567
+ /** Every expression of an effect (the target reference included). */
568
+ export function effectExprs(f) {
569
+ switch (f.k) {
570
+ case 'assign': return f.expr ? [f.ref, f.expr] : [f.ref];
571
+ case 'emit': return f.value ? [f.ref, f.value] : [f.ref];
572
+ case 'print': return f.args;
573
+ case 'call': return [f.call];
574
+ default: return [];
575
+ }
576
+ }
577
+ /** Rebuilds an expression bottom-up: `fn` may return a replacement for a node (after its children were mapped). */
578
+ export function mapExpr(e, fn) {
579
+ let mapped;
580
+ switch (e.k) {
581
+ case 'ref':
582
+ mapped = mapRefParts(e, fn);
583
+ break;
584
+ case 'op':
585
+ mapped = { ...e, args: e.args.map(a => mapExpr(a, fn)) };
586
+ break;
587
+ case 'vector':
588
+ mapped = { ...e, values: e.values.map(a => mapExpr(a, fn)) };
589
+ break;
590
+ case 'call':
591
+ mapped = { ...e, args: e.args.map(a => mapExpr(a, fn)), target: e.target ? mapRefParts(e.target, fn) : undefined };
592
+ break;
593
+ default: mapped = e;
594
+ }
595
+ return fn(mapped) ?? mapped;
596
+ }
597
+ function mapRefParts(r, fn) {
598
+ return { ...r, idx: r.idx.map(i => mapExpr(i, fn)), sub: r.sub ? mapRefParts(r.sub, fn) : undefined };
599
+ }
600
+ /** Maps the expressions of an effect; the target reference's indices are mapped, the target itself is kept. */
601
+ export function mapEffect(f, fn) {
602
+ switch (f.k) {
603
+ case 'assign': return { ...f, ref: mapRefParts(f.ref, fn), expr: f.expr ? mapExpr(f.expr, fn) : undefined };
604
+ case 'emit': return { ...f, ref: mapRefParts(f.ref, fn), value: f.value ? mapExpr(f.value, fn) : undefined };
605
+ case 'print': return { ...f, args: f.args.map(a => mapExpr(a, fn)) };
606
+ case 'call': return { ...f, call: mapExpr(f.call, fn) };
607
+ default: return f;
608
+ }
609
+ }
610
+ export function allActionSites(root) {
611
+ const out = [];
612
+ for (const scope of allScopes(root)) {
613
+ for (const a of scope.actions)
614
+ out.push({ owner: scope, action: a });
615
+ if (!isRegion(scope))
616
+ for (const t of scope.out)
617
+ out.push({ owner: scope, transition: t });
618
+ }
619
+ return out;
620
+ }
621
+ /** Applies `fn` to the trigger and every effect expression of every transition and action below (and of) `root`. */
622
+ export function mapAllExpressions(root, fn) {
623
+ const states = isRegion(root) ? allContainedStates(root) : allStates(root);
624
+ const scopes = isRegion(root) ? [root, ...states.flatMap(s => [s, ...s.regions])] : allScopes(root);
625
+ const seen = new Set();
626
+ for (const scope of scopes) {
627
+ if (seen.has(scope))
628
+ continue;
629
+ seen.add(scope);
630
+ for (const a of scope.actions) {
631
+ if (a.trigger)
632
+ a.trigger = mapExpr(a.trigger, fn);
633
+ a.effects = a.effects.map(f => mapEffect(f, fn));
634
+ }
635
+ if (!isRegion(scope)) {
636
+ for (const t of scope.out) {
637
+ if (t.trigger)
638
+ t.trigger = mapExpr(t.trigger, fn);
639
+ t.effects = t.effects.map(f => mapEffect(f, fn));
640
+ }
641
+ }
642
+ for (const v of scope.decls) {
643
+ if (v.init)
644
+ v.init = mapExpr(v.init, fn);
645
+ }
646
+ }
647
+ }
648
+ /** Structural equality of expressions (KIELER's KExpressionsCompareExtensions.equals2). */
649
+ export function sameExpr(a, b) {
650
+ if (a === b)
651
+ return true;
652
+ if (!a || !b || a.k !== b.k)
653
+ return false;
654
+ switch (a.k) {
655
+ case 'lit': return a.t === b.t && a.v === b.v;
656
+ case 'null':
657
+ case 'random':
658
+ case 'ignore': return true;
659
+ case 'host': return a.text === b.text;
660
+ case 'unsupported': return false;
661
+ case 'ref': return sameRef(a, b);
662
+ case 'op': {
663
+ const o = b;
664
+ return a.op === o.op && a.args.length === o.args.length && a.args.every((x, i) => sameExpr(x, o.args[i]));
665
+ }
666
+ case 'vector': {
667
+ const o = b;
668
+ return !!a.range === !!o.range && a.values.length === o.values.length && a.values.every((x, i) => sameExpr(x, o.values[i]));
669
+ }
670
+ case 'call': {
671
+ const o = b;
672
+ return a.name === o.name && a.args.length === o.args.length && a.args.every((x, i) => sameExpr(x, o.args[i]));
673
+ }
674
+ }
675
+ }
676
+ function sameRef(a, b) {
677
+ return a.v === b.v && a.idx.length === b.idx.length && a.idx.every((x, i) => sameExpr(x, b.idx[i])) &&
678
+ (a.sub === undefined ? b.sub === undefined : b.sub !== undefined && sameRef(a.sub, b.sub));
679
+ }
680
+ /** True if the expression references `v` anywhere. */
681
+ export function mentions(e, v) {
682
+ let found = false;
683
+ walkExpr(e, x => { if (x.k === 'ref' && x.v === v)
684
+ found = true; });
685
+ return found;
686
+ }
687
+ /** Debug printing of the working model (for tests and for comparing with KIELER's model dump). */
688
+ export function printExpr(e) {
689
+ if (!e)
690
+ return '';
691
+ switch (e.k) {
692
+ case 'lit': return e.t === 'string' ? JSON.stringify(e.v) : String(e.v);
693
+ case 'null': return 'null';
694
+ case 'ref': return printRef(e);
695
+ case 'op': {
696
+ if (e.op === 'neg')
697
+ return `-${printExpr(e.args[0])}`;
698
+ if (e.op === '!' || e.op === '~')
699
+ return `${e.op}${printExpr(e.args[0])}`;
700
+ if (e.op === 'pre' || e.op === 'val')
701
+ return `${e.op}(${e.args.map(printExpr).join(', ')})`;
702
+ if (e.op === '?:')
703
+ return `(${printExpr(e.args[0])} ? ${printExpr(e.args[1])} : ${printExpr(e.args[2])})`;
704
+ return `(${e.args.map(printExpr).join(` ${e.op} `)})`;
705
+ }
706
+ case 'vector': return `{${e.values.map(printExpr).join(', ')}}`;
707
+ case 'call': return `${e.extern ? 'extern ' : ''}${e.name}(${e.args.map(printExpr).join(', ')})`;
708
+ case 'random': return 'random()';
709
+ case 'host': return '`' + e.text + '`';
710
+ case 'ignore': return '_';
711
+ case 'unsupported': return `<${e.what}>`;
712
+ }
713
+ }
714
+ function printRef(r) {
715
+ return r.v.name + r.idx.map(i => `[${printExpr(i)}]`).join('') + (r.sub ? '.' + printRef(r.sub) : '');
716
+ }
717
+ export function printEffect(f) {
718
+ switch (f.k) {
719
+ case 'assign': return f.op === '++' || f.op === '--' ? `${printRef(f.ref)}${f.op}` : `${printRef(f.ref)} ${f.op} ${printExpr(f.expr)}`;
720
+ case 'emit': return f.value ? `${printRef(f.ref)}(${printExpr(f.value)})` : printRef(f.ref);
721
+ case 'print': return `print(${f.args.map(printExpr).join(', ')})`;
722
+ case 'call': return printExpr(f.call);
723
+ case 'host': return '`' + f.text + '`';
724
+ case 'randomize': return 'randomize()';
725
+ case 'mark': return `#${f.m.kind}${'transition' in f.m ? '[' + f.m.index + ']' : 'action' in f.m ? '[' + f.m.action + ']' : ''}`;
726
+ case 'unsupported': return `<${f.what}>`;
727
+ }
728
+ }
729
+ /** Prints the working model in an SCTX-like notation (debugging aid; mirrors KIELER's model dump). */
730
+ export function printModel(root) {
731
+ const lines = [];
732
+ const ind = (n) => ' '.repeat(n);
733
+ const decls = (scope, d) => {
734
+ for (const v of scope.decls) {
735
+ const mods = [v.input && 'input', v.output && 'output', v.const && 'const', v.signal && 'signal'].filter(Boolean).join(' ');
736
+ lines.push(`${ind(d)}${mods ? mods + ' ' : ''}${v.type} ${v.name}${v.dims.map(x => `[${printExpr(x)}]`).join('')}${v.init ? ' = ' + printExpr(v.init) : ''}${v.combine ? ' combine ' + v.combine : ''}`);
737
+ }
738
+ };
739
+ const actions = (scope, d) => {
740
+ for (const a of scope.actions) {
741
+ const head = [a.kind === 'entry' || a.kind === 'exit' ? a.preemption : '', a.delay === 'immediate' && a.kind !== 'entry' && a.kind !== 'exit' ? 'immediate' : '', a.kind].filter(Boolean).join(' ');
742
+ lines.push(`${ind(d)}${head}${a.trigger ? ' if ' + printExpr(a.trigger) : ''}${a.effects.length ? ' do ' + a.effects.map(printEffect).join('; ') : ''}`);
743
+ }
744
+ };
745
+ const state = (s, d) => {
746
+ const mods = [s.initial && 'initial', s.final && 'final', s.connector && 'connector'].filter(Boolean).join(' ');
747
+ const head = s.root ? `scchart ${s.name}` : `${mods ? mods + ' ' : ''}state ${s.name}`;
748
+ const hasBody = s.root || s.decls.length || s.actions.length || s.regions.length;
749
+ lines.push(`${ind(d)}${head}${hasBody ? ' {' : ''}`);
750
+ if (hasBody) {
751
+ decls(s, d + 1);
752
+ actions(s, d + 1);
753
+ for (const r of s.regions) {
754
+ lines.push(`${ind(d + 1)}${r.final ? 'final ' : ''}region ${r.name ?? ''}${r.dataflow ? ' (dataflow)' : ''} {`);
755
+ decls(r, d + 2);
756
+ actions(r, d + 2);
757
+ for (const c of r.states)
758
+ state(c, d + 2);
759
+ lines.push(`${ind(d + 1)}}`);
760
+ }
761
+ lines.push(`${ind(d)}}`);
762
+ }
763
+ for (const t of s.out) {
764
+ const kw = t.preemption === 'termination' ? 'join to' : t.preemption === 'strong' ? 'abort to' : 'go to';
765
+ const delay = t.delay === 'immediate' ? 'immediate ' : t.delay === 'delayed' ? 'delayed ' : '';
766
+ lines.push(`${ind(d)}${delay}${t.trigger ? 'if ' + printExpr(t.trigger) + ' ' : ''}${t.effects.length ? 'do ' + t.effects.map(printEffect).join('; ') + ' ' : ''}${kw} ${t.target.name}`);
767
+ }
768
+ };
769
+ state(root, 0);
770
+ return lines.join('\n');
771
+ }
772
+ //# sourceMappingURL=model.js.map