@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,140 @@
1
+ // Deep copies of parts of the working model (EMF's copy): a region with its states, inner regions, transitions,
2
+ // actions and declarations. Variables declared inside get copies of their own, and every reference inside the copy
3
+ // is redirected to them; effects keep their marks and origins (copyEffect).
4
+ import { CAction, CRegion, CState, CTransition, CVar, copyEffect, copyExpr, setTarget, } from "../model.js";
5
+ import { rewriteScope, rewriteStatements } from "./rewrite.js";
6
+ export function copyVar(v) {
7
+ const c = new CVar(v.name, v.type);
8
+ c.hostType = v.hostType;
9
+ c.signal = v.signal;
10
+ c.input = v.input;
11
+ c.output = v.output;
12
+ c.const = v.const;
13
+ c.static = v.static;
14
+ c.extern = v.extern;
15
+ c.global = v.global;
16
+ c.dims = v.dims.map(d => copyExpr(d));
17
+ c.init = copyExpr(v.init);
18
+ c.combine = v.combine;
19
+ c.decl = v.decl;
20
+ c.display = v.display;
21
+ c.role = v.role;
22
+ c.of = v.of;
23
+ c.generated = v.generated;
24
+ c.span = v.span;
25
+ c.tags = new Set(v.tags);
26
+ c.declKind = v.declKind;
27
+ if (v.instance)
28
+ c.instance = { ...v.instance, args: v.instance.args.map(a => ({ ...a, expr: copyExpr(a.expr) })) };
29
+ return c;
30
+ }
31
+ function copyStatements(list) {
32
+ // Rewriting with no changes rebuilds every statement and expression.
33
+ return rewriteStatements(list, {});
34
+ }
35
+ function copyMethod(m, vars) {
36
+ const frame = (v) => {
37
+ const c = copyVar(v);
38
+ vars.set(v, c);
39
+ return c;
40
+ };
41
+ return { ...m, params: m.params.map(frame), locals: m.locals.map(frame), body: copyStatements(m.body) };
42
+ }
43
+ function copyAction(a) {
44
+ const c = new CAction(a.kind);
45
+ c.delay = a.delay;
46
+ c.preemption = a.preemption;
47
+ c.weak = a.weak;
48
+ c.triggerDelay = a.triggerDelay;
49
+ c.trigger = copyExpr(a.trigger);
50
+ c.effects = a.effects.map(copyEffect);
51
+ c.origin = a.origin;
52
+ c.about = a.about;
53
+ c.span = a.span;
54
+ c.annotations = [...a.annotations];
55
+ return c;
56
+ }
57
+ /** Copies a region (not attached anywhere: `parent` is the original's until the caller adds it). */
58
+ export function copyRegion(region) {
59
+ const vars = new Map();
60
+ const states = new Map();
61
+ const pending = [];
62
+ const decls = (from, to) => {
63
+ for (const v of from.decls) {
64
+ const c = copyVar(v);
65
+ c.scope = to;
66
+ if (v.method)
67
+ c.method = copyMethod(v.method, vars);
68
+ vars.set(v, c);
69
+ to.decls.push(c);
70
+ }
71
+ };
72
+ const copyR = (r, parent) => {
73
+ const c = new CRegion();
74
+ c.name = r.name;
75
+ c.label = r.label;
76
+ c.parent = parent;
77
+ c.origin = r.origin;
78
+ c.about = r.about;
79
+ c.dataflow = r.dataflow;
80
+ c.final = r.final;
81
+ c.abort = r.abort;
82
+ c.override = r.override;
83
+ c.annotations = new Map(r.annotations);
84
+ c.ext = { ...r.ext };
85
+ decls(r, c);
86
+ c.actions = r.actions.map(copyAction);
87
+ for (const s of r.states)
88
+ c.states.push(copyS(s, c));
89
+ return c;
90
+ };
91
+ const copyS = (s, parent) => {
92
+ const c = new CState(s.name);
93
+ c.label = s.label;
94
+ c.parent = parent;
95
+ c.initial = s.initial;
96
+ c.final = s.final;
97
+ c.connector = s.connector;
98
+ c.violation = s.violation;
99
+ c.origin = s.origin;
100
+ c.about = s.about;
101
+ c.annotations = new Map(s.annotations);
102
+ c.ext = { ...s.ext };
103
+ states.set(s, c);
104
+ decls(s, c);
105
+ c.actions = s.actions.map(copyAction);
106
+ for (const r of s.regions)
107
+ c.regions.push(copyR(r, c));
108
+ pending.push([s, c]);
109
+ return c;
110
+ };
111
+ const copy = copyR(region, region.parent);
112
+ for (const [s, c] of pending) {
113
+ for (const t of s.out) {
114
+ const n = new CTransition();
115
+ n.source = c;
116
+ c.out.push(n);
117
+ setTarget(n, states.get(t.target) ?? t.target);
118
+ n.delay = t.delay;
119
+ n.preemption = t.preemption;
120
+ n.trigger = copyExpr(t.trigger);
121
+ n.effects = t.effects.map(copyEffect);
122
+ n.triggerDelay = t.triggerDelay;
123
+ n.history = t.history;
124
+ n.deferred = t.deferred;
125
+ n.origin = t.origin;
126
+ n.about = t.about;
127
+ n.checks = t.checks;
128
+ n.annotations = new Map(t.annotations);
129
+ n.span = t.span;
130
+ }
131
+ }
132
+ // References to variables declared inside go to their copies.
133
+ const redirect = (r) => {
134
+ const v = vars.get(r.v);
135
+ return v ? { ...r, v } : undefined;
136
+ };
137
+ rewriteScope(copy, { read: redirect, target: redirect });
138
+ return copy;
139
+ }
140
+ //# sourceMappingURL=copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy.js","sourceRoot":"","sources":["../../../src/sim/structure/copy.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,mHAAmH;AACnH,4EAA4E;AAE5E,OAAO,EACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,GAC/E,oBAAgB;AACjB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,qBAAiB;AAE3D,MAAM,UAAU,OAAO,CAAC,CAAO;IAC3B,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAA;IACvB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACjB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACjB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IACrC,CAAC,CAAC,IAAI,GAAG,QAAQ,C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YACnB,CAAC,CAAC,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;YACtC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAA;QACnB,CAAC;IACL,CAAC;IACD,8DAA8D;IAC9D,MAAM,QAAQ,GAAG,CAAC,CAAO,EAAoB,EAAE;QAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACvB,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IACtC,CAAC,CAAA;IACD,YAAY,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IACxD,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["// Deep copies of parts of the working model (EMF's copy): a region with its states, inner regions, transitions,\n// actions and declarations. Variables declared inside get copies of their own, and every reference inside the copy\n// is redirected to them; effects keep their marks and origins (copyEffect).\n\nimport {\n CAction, CRegion, CState, CTransition, CVar, copyEffect, copyExpr, setTarget, type CMethod, type CRef, type CStmt,\n} from '../model'\nimport { rewriteScope, rewriteStatements } from './rewrite'\n\nexport function copyVar(v: CVar): CVar {\n const c = new CVar(v.name, v.type)\n c.hostType = v.hostType\n c.signal = v.signal\n c.input = v.input\n c.output = v.output\n c.const = v.const\n c.static = v.static\n c.extern = v.extern\n c.global = v.global\n c.dims = v.dims.map(d => copyExpr(d))\n c.init = copyExpr(v.init)\n c.combine = v.combine\n c.decl = v.decl\n c.display = v.display\n c.role = v.role\n c.of = v.of\n c.generated = v.generated\n c.span = v.span\n c.tags = new Set(v.tags)\n c.declKind = v.declKind\n if (v.instance) c.instance = { ...v.instance, args: v.instance.args.map(a => ({ ...a, expr: copyExpr(a.expr) })) }\n return c\n}\n\nfunction copyStatements(list: CStmt[]): CStmt[] {\n // Rewriting with no changes rebuilds every statement and expression.\n return rewriteStatements(list, {})\n}\n\nfunction copyMethod(m: CMethod, vars: Map<CVar, CVar>): CMethod {\n const frame = (v: CVar) => {\n const c = copyVar(v)\n vars.set(v, c)\n return c\n }\n return { ...m, params: m.params.map(frame), locals: m.locals.map(frame), body: copyStatements(m.body) }\n}\n\nfunction copyAction(a: CAction): CAction {\n const c = new CAction(a.kind)\n c.delay = a.delay\n c.preemption = a.preemption\n c.weak = a.weak\n c.triggerDelay = a.triggerDelay\n c.trigger = copyExpr(a.trigger)\n c.effects = a.effects.map(copyEffect)\n c.origin = a.origin\n c.about = a.about\n c.span = a.span\n c.annotations = [...a.annotations]\n return c\n}\n\n/** Copies a region (not attached anywhere: `parent` is the original's until the caller adds it). */\nexport function copyRegion(region: CRegion): CRegion {\n const vars = new Map<CVar, CVar>()\n const states = new Map<CState, CState>()\n const pending: [CState, CState][] = []\n\n const decls = (from: CState | CRegion, to: CState | CRegion) => {\n for (const v of from.decls) {\n const c = copyVar(v)\n c.scope = to\n if (v.method) c.method = copyMethod(v.method, vars)\n vars.set(v, c)\n to.decls.push(c)\n }\n }\n const copyR = (r: CRegion, parent: CState): CRegion => {\n const c = new CRegion()\n c.name = r.name\n c.label = r.label\n c.parent = parent\n c.origin = r.origin\n c.about = r.about\n c.dataflow = r.dataflow\n c.final = r.final\n c.abort = r.abort\n c.override = r.override\n c.annotations = new Map(r.annotations)\n c.ext = { ...r.ext }\n decls(r, c)\n c.actions = r.actions.map(copyAction)\n for (const s of r.states) c.states.push(copyS(s, c))\n return c\n }\n const copyS = (s: CState, parent: CRegion): CState => {\n const c = new CState(s.name)\n c.label = s.label\n c.parent = parent\n c.initial = s.initial\n c.final = s.final\n c.connector = s.connector\n c.violation = s.violation\n c.origin = s.origin\n c.about = s.about\n c.annotations = new Map(s.annotations)\n c.ext = { ...s.ext }\n states.set(s, c)\n decls(s, c)\n c.actions = s.actions.map(copyAction)\n for (const r of s.regions) c.regions.push(copyR(r, c))\n pending.push([s, c])\n return c\n }\n const copy = copyR(region, region.parent)\n for (const [s, c] of pending) {\n for (const t of s.out) {\n const n = new CTransition()\n n.source = c\n c.out.push(n)\n setTarget(n, states.get(t.target) ?? t.target)\n n.delay = t.delay\n n.preemption = t.preemption\n n.trigger = copyExpr(t.trigger)\n n.effects = t.effects.map(copyEffect)\n n.triggerDelay = t.triggerDelay\n n.history = t.history\n n.deferred = t.deferred\n n.origin = t.origin\n n.about = t.about\n n.checks = t.checks\n n.annotations = new Map(t.annotations)\n n.span = t.span\n }\n }\n // References to variables declared inside go to their copies.\n const redirect = (r: CRef): CRef | undefined => {\n const v = vars.get(r.v)\n return v ? { ...r, v } : undefined\n }\n rewriteScope(copy, { read: redirect, target: redirect })\n return copy\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { type CAction, type CExpr, type CState, type CTransition } from "../model.js";
2
+ import type { Diagnostic, ValueType } from "../../types.js";
3
+ export interface OperatorUse {
4
+ /** The holder whose expressions contain it. */
5
+ holder: CTransition | CAction;
6
+ /** KIELER's enclosingState of the action: a transition's source's parent state, an action's state. */
7
+ parent: CState | undefined;
8
+ /** The operator expression (as found; replaced through `replace`). */
9
+ expr: Extract<CExpr, {
10
+ k: 'op';
11
+ }>;
12
+ }
13
+ /** Uses of an operator in triggers and effects, outermost first, in the chart's containment order. */
14
+ export declare function operatorUses(root: CState, op: string): OperatorUse[];
15
+ /** Replaces one expression node (by identity) in its holder's trigger and effects. */
16
+ export declare function replaceIn(holder: CTransition | CAction, target: CExpr, replacement: CExpr): void;
17
+ /**
18
+ * KIELER's inferType (KExpressionsTypeExtensions): from the leaves only (literals and variables; a conditional's
19
+ * condition is skipped, operators do not count): float if arithmetic with a float leaf, else the type all leaves
20
+ * share, else UNKNOWN, which KIELER's simulation cannot serialise (the chart is rejected).
21
+ */
22
+ export declare function inferType(e: CExpr): ValueType | 'unknown';
23
+ /** The helper variable's type, or an error like KIELER's when it has none (see inferType). */
24
+ export declare function helperType(e: CExpr, report: (d: Diagnostic) => void, op: string, by: string | undefined): ValueType;
25
+ /**
26
+ * KIELER names some helper variables without making them unique (FollowedBy's `__fbp_next<i>`, and InitOperator's
27
+ * and SequentialFollowedBy's shared `__iop_<k>`). Locals of inner states are renamed when the netlist code generator
28
+ * moves them to the root, but two of the root's own get the same name in the C data struct, which gcc rejects.
29
+ */
30
+ export declare function rootHelperClash(parent: CState, name: string, report: (d: Diagnostic) => void, span: CExpr['span'], by: string | undefined): void;
@@ -0,0 +1,127 @@
1
+ // Shared by KIELER's Init Operator, Followed By and Sequential Followed By processors (passes/initOperator.ts,
2
+ // passes/followedBy.ts, passes/sequentialFollowedBy.ts; structure.md S-28 .. S-30): finding the operator's uses in
3
+ // KIELER's containment order, the state that receives the helper region, and the helper variable's type.
4
+ import { allActionSites, isRegion } from "../model.js";
5
+ /** Uses of an operator in triggers and effects, outermost first, in the chart's containment order. */
6
+ export function operatorUses(root, op) {
7
+ const out = [];
8
+ for (const site of allActionSites(root)) {
9
+ const holder = site.transition ?? site.action;
10
+ const parent = site.transition ? site.transition.source.parent?.parent : isRegion(site.owner) ? site.owner.parent : site.owner;
11
+ const visit = (e) => {
12
+ if (!e)
13
+ return;
14
+ if (e.k === 'op') {
15
+ if (e.op === op)
16
+ out.push({ holder, parent, expr: e });
17
+ e.args.forEach(visit);
18
+ }
19
+ else if (e.k === 'ref')
20
+ e.idx.forEach(visit);
21
+ else if (e.k === 'vector')
22
+ e.values.forEach(visit);
23
+ else if (e.k === 'call')
24
+ e.args.forEach(visit);
25
+ };
26
+ visit(holder.trigger);
27
+ for (const f of holder.effects) {
28
+ if (f.k === 'assign') {
29
+ f.ref.idx.forEach(visit);
30
+ visit(f.expr);
31
+ }
32
+ else if (f.k === 'emit')
33
+ visit(f.value);
34
+ else if (f.k === 'print')
35
+ f.args.forEach(visit);
36
+ else if (f.k === 'call')
37
+ f.call.args.forEach(visit);
38
+ }
39
+ }
40
+ return out;
41
+ }
42
+ /** Replaces one expression node (by identity) in its holder's trigger and effects. */
43
+ export function replaceIn(holder, target, replacement) {
44
+ const map = (e) => (e === target ? replacement : mapOne(e, map));
45
+ if (holder.trigger)
46
+ holder.trigger = map(holder.trigger);
47
+ holder.effects = holder.effects.map(f => {
48
+ switch (f.k) {
49
+ case 'assign': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(map) }, expr: f.expr ? map(f.expr) : undefined };
50
+ case 'emit': return { ...f, value: f.value ? map(f.value) : undefined };
51
+ case 'print': return { ...f, args: f.args.map(map) };
52
+ case 'call': return { ...f, call: { ...f.call, args: f.call.args.map(map) } };
53
+ default: return f;
54
+ }
55
+ });
56
+ }
57
+ function mapOne(e, map) {
58
+ switch (e.k) {
59
+ case 'op': return { ...e, args: e.args.map(map) };
60
+ case 'ref': return { ...e, idx: e.idx.map(map) };
61
+ case 'vector': return { ...e, values: e.values.map(map) };
62
+ case 'call': return { ...e, args: e.args.map(map) };
63
+ default: return e;
64
+ }
65
+ }
66
+ /**
67
+ * KIELER's inferType (KExpressionsTypeExtensions): from the leaves only (literals and variables; a conditional's
68
+ * condition is skipped, operators do not count): float if arithmetic with a float leaf, else the type all leaves
69
+ * share, else UNKNOWN, which KIELER's simulation cannot serialise (the chart is rejected).
70
+ */
71
+ export function inferType(e) {
72
+ const leafType = (x) => {
73
+ if (x.k === 'lit')
74
+ return x.t;
75
+ if (x.k === 'ref') {
76
+ let r = x;
77
+ while (r.sub)
78
+ r = r.sub;
79
+ return r.v.type;
80
+ }
81
+ return undefined;
82
+ };
83
+ const operands = (x) => (x.op === '?:' ? x.args.slice(1) : x.args);
84
+ const has = (x, t) => (x.k === 'op' ? operands(x).some(a => has(a, t)) : leafType(x) === t);
85
+ const all = (x, t) => (x.k === 'op' ? operands(x).every(a => all(a, t)) : leafType(x) === t);
86
+ const arithmetic = !has(e, 'bool') && !has(e, 'string') && (has(e, 'int') || has(e, 'float'));
87
+ if (arithmetic && has(e, 'float'))
88
+ return 'float';
89
+ if (all(e, 'bool'))
90
+ return 'bool';
91
+ if (all(e, 'int'))
92
+ return 'int';
93
+ if (all(e, 'float'))
94
+ return 'float';
95
+ if (all(e, 'string'))
96
+ return 'string';
97
+ return 'unknown';
98
+ }
99
+ /** The helper variable's type, or an error like KIELER's when it has none (see inferType). */
100
+ export function helperType(e, report, op, by) {
101
+ const t = inferType(e);
102
+ if (t !== 'unknown')
103
+ return t;
104
+ report({
105
+ severity: 'error', code: 'unknown-type', span: e.span, related: by ? [by] : undefined,
106
+ message: `KIELER cannot give the \`${op}\` expression a type: its values mix booleans, numbers or strings`,
107
+ kieler: 'Cannot serialize simulation interface. Unsupported type: UNKNOWN',
108
+ hint: `KIELER stores \`${op}\` in a helper variable whose type comes from all the values and variables in the expression. Make them all one type, for example write \`level > 3\` into a \`bool\` variable first and use that variable here.`,
109
+ });
110
+ return 'int';
111
+ }
112
+ /**
113
+ * KIELER names some helper variables without making them unique (FollowedBy's `__fbp_next<i>`, and InitOperator's
114
+ * and SequentialFollowedBy's shared `__iop_<k>`). Locals of inner states are renamed when the netlist code generator
115
+ * moves them to the root, but two of the root's own get the same name in the C data struct, which gcc rejects.
116
+ */
117
+ export function rootHelperClash(parent, name, report, span, by) {
118
+ if (!parent.root || !parent.decls.some(v => v.name === name))
119
+ return;
120
+ report({
121
+ severity: 'error', code: 'duplicate-declaration', span, related: by ? [by] : undefined,
122
+ message: `KIELER gives two helper variables of the chart the same name (\`${name}\`), so its generated C code does not compile`,
123
+ kieler: `duplicate member ‘${name}’\nCompiler did not return success (exit value != 0)`,
124
+ hint: 'KIELER names the helper variables of `fby` (and of `->` together with `sfby`) by position, so two of them directly in the chart\'s top level clash. Move one of the expressions into a superstate, or compute it with `pre(...)` instead.',
125
+ });
126
+ }
127
+ //# sourceMappingURL=delays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delays.js","sourceRoot":"","sources":["../../../src/sim/structure/delays.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,mHAAmH;AACnH,yGAAyG;AAEzG,OAAO,EAAE,cAAc,EAAE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EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;QACrF,OAAO,EAAE,4BAA4B,EAAE,mEAAmE;QAC1G,MAAM,EAAE,kEAAkE;QAC1E,IAAI,EAAE,mBAAmB,EAAE,kNAAkN;KAChP,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAY,EAAE,MAA+B,EAAE,IAAmB,EAAE,EAAsB;IACtI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAM;IACpE,MAAM,CAAC;QACH,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;QACtF,OAAO,EAAE,mEAAmE,IAAI,+CAA+C;QAC/H,MAAM,EAAE,qBAAqB,IAAI,sDAAsD;QACvF,IAAI,EAAE,2OAA2O;KACpP,CAAC,CAAA;AACN,CAAC","sourcesContent":["// Shared by KIELER's Init Operator, Followed By and Sequential Followed By processors (passes/initOperator.ts,\n// passes/followedBy.ts, passes/sequentialFollowedBy.ts; structure.md S-28 .. S-30): finding the operator's uses in\n// KIELER's containment order, the state that receives the helper region, and the helper variable's type.\n\nimport { allActionSites, isRegion, type CAction, type CExpr, type CState, type CTransition } from '../model'\nimport type { Diagnostic, ValueType } from '../../types'\n\nexport interface OperatorUse {\n /** The holder whose expressions contain it. */\n holder: CTransition | CAction\n /** KIELER's enclosingState of the action: a transition's source's parent state, an action's state. */\n parent: CState | undefined\n /** The operator expression (as found; replaced through `replace`). */\n expr: Extract<CExpr, { k: 'op' }>\n}\n\n/** Uses of an operator in triggers and effects, outermost first, in the chart's containment order. */\nexport function operatorUses(root: CState, op: string): OperatorUse[] {\n const out: OperatorUse[] = []\n for (const site of allActionSites(root)) {\n const holder = site.transition ?? site.action!\n const parent = site.transition ? site.transition.source.parent?.parent : isRegion(site.owner) ? site.owner.parent : site.owner\n const visit = (e: CExpr | undefined) => {\n if (!e) return\n if (e.k === 'op') {\n if (e.op === op) out.push({ holder, parent, expr: e })\n e.args.forEach(visit)\n } else if (e.k === 'ref') e.idx.forEach(visit)\n else if (e.k === 'vector') e.values.forEach(visit)\n else if (e.k === 'call') e.args.forEach(visit)\n }\n visit(holder.trigger)\n for (const f of holder.effects) {\n if (f.k === 'assign') { f.ref.idx.forEach(visit); visit(f.expr) }\n else if (f.k === 'emit') visit(f.value)\n else if (f.k === 'print') f.args.forEach(visit)\n else if (f.k === 'call') f.call.args.forEach(visit)\n }\n }\n return out\n}\n\n/** Replaces one expression node (by identity) in its holder's trigger and effects. */\nexport function replaceIn(holder: CTransition | CAction, target: CExpr, replacement: CExpr) {\n const map = (e: CExpr): CExpr => (e === target ? replacement : mapOne(e, map))\n if (holder.trigger) holder.trigger = map(holder.trigger)\n holder.effects = holder.effects.map(f => {\n switch (f.k) {\n case 'assign': return { ...f, ref: { ...f.ref, idx: f.ref.idx.map(map) }, expr: f.expr ? map(f.expr) : undefined }\n case 'emit': return { ...f, value: f.value ? map(f.value) : undefined }\n case 'print': return { ...f, args: f.args.map(map) }\n case 'call': return { ...f, call: { ...f.call, args: f.call.args.map(map) } }\n default: return f\n }\n })\n}\n\nfunction mapOne(e: CExpr, map: (e: CExpr) => CExpr): CExpr {\n switch (e.k) {\n case 'op': return { ...e, args: e.args.map(map) }\n case 'ref': return { ...e, idx: e.idx.map(map) }\n case 'vector': return { ...e, values: e.values.map(map) }\n case 'call': return { ...e, args: e.args.map(map) }\n default: return e\n }\n}\n\n/**\n * KIELER's inferType (KExpressionsTypeExtensions): from the leaves only (literals and variables; a conditional's\n * condition is skipped, operators do not count): float if arithmetic with a float leaf, else the type all leaves\n * share, else UNKNOWN, which KIELER's simulation cannot serialise (the chart is rejected).\n */\nexport function inferType(e: CExpr): ValueType | 'unknown' {\n const leafType = (x: CExpr): string | undefined => {\n if (x.k === 'lit') return x.t\n if (x.k === 'ref') {\n let r = x\n while (r.sub) r = r.sub\n return r.v.type\n }\n return undefined\n }\n const operands = (x: Extract<CExpr, { k: 'op' }>) => (x.op === '?:' ? x.args.slice(1) : x.args)\n const has = (x: CExpr, t: string): boolean => (x.k === 'op' ? operands(x).some(a => has(a, t)) : leafType(x) === t)\n const all = (x: CExpr, t: string): boolean => (x.k === 'op' ? operands(x).every(a => all(a, t)) : leafType(x) === t)\n const arithmetic = !has(e, 'bool') && !has(e, 'string') && (has(e, 'int') || has(e, 'float'))\n if (arithmetic && has(e, 'float')) return 'float'\n if (all(e, 'bool')) return 'bool'\n if (all(e, 'int')) return 'int'\n if (all(e, 'float')) return 'float'\n if (all(e, 'string')) return 'string'\n return 'unknown'\n}\n\n/** The helper variable's type, or an error like KIELER's when it has none (see inferType). */\nexport function helperType(e: CExpr, report: (d: Diagnostic) => void, op: string, by: string | undefined): ValueType {\n const t = inferType(e)\n if (t !== 'unknown') return t\n report({\n severity: 'error', code: 'unknown-type', span: e.span, related: by ? [by] : undefined,\n message: `KIELER cannot give the \\`${op}\\` expression a type: its values mix booleans, numbers or strings`,\n kieler: 'Cannot serialize simulation interface. Unsupported type: UNKNOWN',\n hint: `KIELER stores \\`${op}\\` in a helper variable whose type comes from all the values and variables in the expression. Make them all one type, for example write \\`level > 3\\` into a \\`bool\\` variable first and use that variable here.`,\n })\n return 'int'\n}\n\n/**\n * KIELER names some helper variables without making them unique (FollowedBy's `__fbp_next<i>`, and InitOperator's\n * and SequentialFollowedBy's shared `__iop_<k>`). Locals of inner states are renamed when the netlist code generator\n * moves them to the root, but two of the root's own get the same name in the C data struct, which gcc rejects.\n */\nexport function rootHelperClash(parent: CState, name: string, report: (d: Diagnostic) => void, span: CExpr['span'], by: string | undefined) {\n if (!parent.root || !parent.decls.some(v => v.name === name)) return\n report({\n severity: 'error', code: 'duplicate-declaration', span, related: by ? [by] : undefined,\n message: `KIELER gives two helper variables of the chart the same name (\\`${name}\\`), so its generated C code does not compile`,\n kieler: `duplicate member ‘${name}’\\nCompiler did not return success (exit value != 0)`,\n hint: 'KIELER names the helper variables of `fby` (and of `->` together with `sfby`) by position, so two of them directly in the chart\\'s top level clash. Move one of the expressions into a superstate, or compute it with `pre(...)` instead.',\n })\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { Span, State } from "../../types.js";
2
+ import type { ModelIndex } from "../../parser/resolve.js";
3
+ import { type LowerResult } from "../lower.js";
4
+ import { type CState } from "../model.js";
5
+ /** Separates a reference state's id from the ids of the chart drawn (and simulated) inside it. */
6
+ export declare const REFERENCE_SEPARATOR = "/";
7
+ /**
8
+ * A deep copy of a chart whose ids are prefixed (states, regions, transitions, actions, declarations, references
9
+ * to declarations). `span`, when given, replaces every span (a chart from another file has no place in this one).
10
+ */
11
+ export declare function prefixedChart(chart: State, prefix: string, span?: Span): State;
12
+ /** The chart, lowered as the body of one instance: a state (not a root) with the chart's declarations, actions, regions. */
13
+ export declare function lowerInstance(chart: State, index: ModelIndex | undefined, prefix: string, span?: Span): LowerResult;
14
+ /** Every scope of a lowered instance (for walking its declarations). */
15
+ export declare function instanceScopes(root: CState): import("../model.js").Scope[];
@@ -0,0 +1,69 @@
1
+ // Instances of referenced charts (structure.md S-4): KIELER's Reference processor copies the referenced chart into
2
+ // the referencing state. The simulator lowers a fresh copy of the chart's AST for every instance, with every element
3
+ // id prefixed by `<referencing state id>/` (the ids the diagram gives a reference drawn expanded, diagram/layout.ts),
4
+ // so the instance's states, transitions and actions report ids of their own and its variables are its own.
5
+ //
6
+ // Taken Transition Signaling only numbers the simulated chart's own transitions (S-15): an instance's transitions
7
+ // carry `take` marks with index -1 (no KIELER effect; they drive the source-level configuration only), and the
8
+ // instance gets no counter reset.
9
+ import { lowerChart } from "../lower.js";
10
+ import { allScopes, allTransitions } from "../model.js";
11
+ /** Separates a reference state's id from the ids of the chart drawn (and simulated) inside it. */
12
+ export const REFERENCE_SEPARATOR = '/';
13
+ /**
14
+ * A deep copy of a chart whose ids are prefixed (states, regions, transitions, actions, declarations, references
15
+ * to declarations). `span`, when given, replaces every span (a chart from another file has no place in this one).
16
+ */
17
+ export function prefixedChart(chart, prefix, span) {
18
+ const visit = (value) => {
19
+ if (Array.isArray(value))
20
+ return value.map(visit);
21
+ if (!value || typeof value !== 'object')
22
+ return value;
23
+ const obj = value;
24
+ const out = {};
25
+ for (const [k, v] of Object.entries(obj)) {
26
+ if (k === 'span' || k === 'nameSpan' || k === 'targetSpan' || k === 'bindingSpan' || k === 'referenceSpan')
27
+ out[k] = span ?? v;
28
+ else
29
+ out[k] = visit(v);
30
+ }
31
+ if (typeof obj.id === 'string' && obj.id)
32
+ out.id = prefix + obj.id;
33
+ if (obj.kind === 'transition') {
34
+ if (typeof obj.source === 'string')
35
+ out.source = prefix + obj.source;
36
+ if (typeof obj.target === 'string')
37
+ out.target = prefix + obj.target;
38
+ }
39
+ if (obj.kind === 'ref' && typeof obj.decl === 'string')
40
+ out.decl = prefix + obj.decl;
41
+ if (obj.kind === 'special' && typeof obj.state === 'string')
42
+ out.state = prefix + obj.state;
43
+ if (typeof obj.bindingDecl === 'string')
44
+ out.bindingDecl = prefix + obj.bindingDecl;
45
+ return out;
46
+ };
47
+ return { ...visit(chart), isRoot: false };
48
+ }
49
+ /** The chart, lowered as the body of one instance: a state (not a root) with the chart's declarations, actions, regions. */
50
+ export function lowerInstance(chart, index, prefix, span) {
51
+ const copy = prefixedChart(chart, prefix, span);
52
+ const lowered = lowerChart({ ...copy, isRoot: true }, index);
53
+ const root = lowered.root;
54
+ root.root = false;
55
+ // No Taken Transition Signaling for instances: the marks stay as tracker hooks only, the reset goes.
56
+ for (const t of allTransitions(root)) {
57
+ for (const f of t.effects)
58
+ if (f.k === 'mark' && f.m.kind === 'take')
59
+ f.m.index = -1;
60
+ }
61
+ root.actions = root.actions.filter(a => !a.effects.some(f => f.k === 'mark' && f.m.kind === 'ttsReset'));
62
+ lowered.takenOrder = [];
63
+ return lowered;
64
+ }
65
+ /** Every scope of a lowered instance (for walking its declarations). */
66
+ export function instanceScopes(root) {
67
+ return allScopes(root);
68
+ }
69
+ //# sourceMappingURL=instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.js","sourceRoot":"","sources":["../../../src/sim/structure/instance.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,qHAAqH;AACrH,sHAAsH;AACtH,2GAA2G;AAC3G,EAAE;AACF,kHAAkH;AAClH,+GAA+G;AAC/G,kCAAkC;AAIlC,OAAO,EAAE,UAAU,EAAoB,oBAAgB;AACvD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAe,oBAAgB;AAEjE,kGAAkG;AAClG,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAEtC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,MAAc,EAAE,IAAW;IACnE,MAAM,KAAK,GAAG,CAAC,KAAc,EAAW,EAAE;QACtC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACjD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACrD,MAAM,GAAG,GAAG,KAAgC,CAAA;QAC5C,MAAM,GAAG,GAA4B,EAAE,CAAA;QACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,YAAY,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,eAAe;gBAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI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AAM,EAAE,IAAI,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAA;IAC5D,MAAM,IAAI,GAAW,OAAO,CAAC,IAAI,CAAA;IACjC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAA;IACjB,qGAAqG;IACrG,KAAK,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;YAAE,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM;gBAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IACxF,CAAC;IACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAA;IACxG,OAAO,CAAC,UAAU,GAAG,EAAE,CAAA;IACvB,OAAO,OAAO,CAAA;AAClB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,IAAY;IACvC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["// Instances of referenced charts (structure.md S-4): KIELER's Reference processor copies the referenced chart into\n// the referencing state. The simulator lowers a fresh copy of the chart's AST for every instance, with every element\n// id prefixed by `<referencing state id>/` (the ids the diagram gives a reference drawn expanded, diagram/layout.ts),\n// so the instance's states, transitions and actions report ids of their own and its variables are its own.\n//\n// Taken Transition Signaling only numbers the simulated chart's own transitions (S-15): an instance's transitions\n// carry `take` marks with index -1 (no KIELER effect; they drive the source-level configuration only), and the\n// instance gets no counter reset.\n\nimport type { Span, State } from '../../types'\nimport type { ModelIndex } from '../../parser/resolve'\nimport { lowerChart, type LowerResult } from '../lower'\nimport { allScopes, allTransitions, type CState } from '../model'\n\n/** Separates a reference state's id from the ids of the chart drawn (and simulated) inside it. */\nexport const REFERENCE_SEPARATOR = '/'\n\n/**\n * A deep copy of a chart whose ids are prefixed (states, regions, transitions, actions, declarations, references\n * to declarations). `span`, when given, replaces every span (a chart from another file has no place in this one).\n */\nexport function prefixedChart(chart: State, prefix: string, span?: Span): State {\n const visit = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(visit)\n if (!value || typeof value !== 'object') return value\n const obj = value as Record<string, unknown>\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(obj)) {\n if (k === 'span' || k === 'nameSpan' || k === 'targetSpan' || k === 'bindingSpan' || k === 'referenceSpan') out[k] = span ?? v\n else out[k] = visit(v)\n }\n if (typeof obj.id === 'string' && obj.id) out.id = prefix + obj.id\n if (obj.kind === 'transition') {\n if (typeof obj.source === 'string') out.source = prefix + obj.source\n if (typeof obj.target === 'string') out.target = prefix + obj.target\n }\n if (obj.kind === 'ref' && typeof obj.decl === 'string') out.decl = prefix + obj.decl\n if (obj.kind === 'special' && typeof obj.state === 'string') out.state = prefix + obj.state\n if (typeof obj.bindingDecl === 'string') out.bindingDecl = prefix + obj.bindingDecl\n return out\n }\n return { ...(visit(chart) as State), isRoot: false }\n}\n\n/** The chart, lowered as the body of one instance: a state (not a root) with the chart's declarations, actions, regions. */\nexport function lowerInstance(chart: State, index: ModelIndex | undefined, prefix: string, span?: Span): LowerResult {\n const copy = prefixedChart(chart, prefix, span)\n const lowered = lowerChart({ ...copy, isRoot: true }, index)\n const root: CState = lowered.root\n root.root = false\n // No Taken Transition Signaling for instances: the marks stay as tracker hooks only, the reset goes.\n for (const t of allTransitions(root)) {\n for (const f of t.effects) if (f.k === 'mark' && f.m.kind === 'take') f.m.index = -1\n }\n root.actions = root.actions.filter(a => !a.effects.some(f => f.k === 'mark' && f.m.kind === 'ttsReset'))\n lowered.takenOrder = []\n return lowered\n}\n\n/** Every scope of a lowered instance (for walking its declarations). */\nexport function instanceScopes(root: CState) {\n return allScopes(root)\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Diagnostic } from "../../types.js";
2
+ import { type Compiled, type ExprCompiler } from "../eval.js";
3
+ import { type CExpr, type CMethod } from "../model.js";
4
+ import type { SCG } from "../scg.js";
5
+ /** A call of a method: evaluates the arguments, binds the parameters, runs the body, gives the return value. */
6
+ export declare function compileMethodCall(ec: ExprCompiler, call: Extract<CExpr, {
7
+ k: 'call';
8
+ }>, m: CMethod): Compiled;
9
+ /** KIELER inlines a method's calls: a simple one, or one marked `@inline` (one with a loop cannot be, see inlineMethods). */
10
+ export declare function isInlined(m: CMethod): boolean;
11
+ /**
12
+ * KIELER's isSimpleMethod: the method's SCG has fewer than 30 nodes, no loop and no call. Its nodes are the entry,
13
+ * the exit and one per assignment, `if` and `return`; labels and gotos are control flow only (a backward `goto` is
14
+ * no loop to KIELER: it gets no loop annotation, so the method is inlined and the jump becomes a cycle in the tick,
15
+ * probes kieler/rare/probe-goto-*).
16
+ */
17
+ export declare function isSimple(m: CMethod): boolean;
18
+ /** Inlines the calls of simple methods into the SCG (after the superfluous fork removal, as KIELER does). */
19
+ export declare function inlineMethods(scg: SCG): Diagnostic[];