@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
package/dist/index.js ADDED
@@ -0,0 +1,507 @@
1
+ // Public API of the in-browser SCCharts engine (see docs-internal/ARCHITECTURE.md).
2
+ //
3
+ // parse(source) syntax only: the Program (with element ids, resolved transition targets and
4
+ // references, so a diagram can be drawn) and the syntax diagnostics. Never throws.
5
+ // compile(source, options) parse + name resolution + KIELER's validation rules, then the simulator's compilation
6
+ // of the chart (KIELER's transformations, causality and instantaneous-loop analysis,
7
+ // code generation checks): `ok` is false exactly when KIELER rejects the chart.
8
+ // createSimulation(result) runs a compiled chart tick by tick (sim/index.ts); describeTick(tick, program) says
9
+ // in plain English what happened in a tick.
10
+ // parseExpression(source) one expression or effect on its own, with KIELER's grammar (for the operators page:
11
+ // formatExpressionParenthesised in format.ts shows how KIELER grouped it).
12
+ //
13
+ // Diagnostics carry a beginner-friendly message and hint, a stable `code`, and (for linking and validation
14
+ // problems) KIELER's own wording in `kieler`.
15
+ import { assignIds } from "./parser/ids.js";
16
+ import { constantValue, extractInterface } from "./parser/interface.js";
17
+ import { parseProgram, parseStandalone } from "./parser/parser.js";
18
+ import { resolveProgram } from "./parser/resolve.js";
19
+ import { LineMap } from "./parser/source.js";
20
+ import { validateProgram } from "./parser/validate.js";
21
+ import { importTargets } from "./parser/imports.js";
22
+ import { kielerSyntaxWording } from "./parser/kielerWording.js";
23
+ import { compileChart } from "./sim/compile.js";
24
+ import { rememberImports } from "./sim/describe.js";
25
+ import { codeNamingProblems } from "./sim/codegen.js";
26
+ export { extractInterface, constantValue } from "./parser/interface.js";
27
+ export { lex, KEYWORDS } from "./parser/lexer.js";
28
+ export { referenceName } from "./parser/parser.js";
29
+ export { formatExpressionParenthesised, formatEffectParenthesised } from "./format.js";
30
+ export { createSimulation, describeTick, elementName, SIMULATOR_CODES } from "./sim/index.js";
31
+ export { generateC } from "./codegen/index.js";
32
+ function parseOnly(source) {
33
+ const lines = new LineMap(source);
34
+ const { program, diagnostics } = parseProgram(source, lines);
35
+ assignIds(program);
36
+ return { program, syntax: diagnostics, lines };
37
+ }
38
+ /** Parses SCTX. Never throws. Diagnostics are syntax errors (and lexical warnings) only. */
39
+ export function parse(source) {
40
+ let parsed;
41
+ try {
42
+ parsed = parseOnly(source);
43
+ }
44
+ catch (error) {
45
+ return { diagnostics: [internalError(error)] };
46
+ }
47
+ try {
48
+ resolveProgram(parsed.program);
49
+ }
50
+ catch (error) {
51
+ // The model is still useful without resolved names (no transition targets).
52
+ return { program: parsed.program, diagnostics: sortDiagnostics([...parsed.syntax, internalError(error)]) };
53
+ }
54
+ return { program: parsed.program, diagnostics: sortDiagnostics(parsed.syntax) };
55
+ }
56
+ /**
57
+ * Parses one expression or effect on its own, exactly as KIELER's grammar reads it inside a chart (same rules,
58
+ * same backtracking, same messages). `as: 'auto'` (default) reads it as an expression if it is one, otherwise as an
59
+ * effect (`x = a + b`, `x++`, `S(3)` is a call when read as an expression). Names are not resolved. Never throws.
60
+ */
61
+ export function parseExpression(source, options = {}) {
62
+ try {
63
+ const out = parseStandalone(source, options.as ?? 'auto');
64
+ // KIELER's words for the syntax error, where they are known (parser/kielerWording.ts): what KIELER says when
65
+ // the text is the trigger of a transition (`if <text> go to S`) or its effect (`do <text> go to S`). A
66
+ // trigger that starts with a number is a count delay there, so such an expression gets none.
67
+ const error = out.diagnostics.find(d => d.severity === 'error' && d.code === 'parse');
68
+ if (error && error.kieler === undefined && !(out.as === 'expression' && /^\s*[0-9.]/.test(source))) {
69
+ const words = kielerSyntaxWording(source, out.as);
70
+ if (words)
71
+ error.kieler = words;
72
+ }
73
+ return { ...out, diagnostics: sortDiagnostics(out.diagnostics) };
74
+ }
75
+ catch (error) {
76
+ return { as: options.as === 'effect' ? 'effect' : 'expression', diagnostics: [internalError(error)] };
77
+ }
78
+ }
79
+ /** Parses, resolves and validates a chart the way KIELER's front end does. Never throws. */
80
+ export function compile(source, options = {}) {
81
+ try {
82
+ const main = parseOnly(source);
83
+ const others = [];
84
+ for (const [name, text] of Object.entries(options.files ?? {})) {
85
+ if (text === source && !name)
86
+ continue;
87
+ const p = parseOnly(text).program;
88
+ resolveProgram(p);
89
+ others.push(p);
90
+ }
91
+ const externalCharts = others.flatMap(p => p.charts);
92
+ const { index, diagnostics: linking } = resolveProgram(main.program, { externalCharts });
93
+ index.programs.push(...others);
94
+ // describeTick names the elements of an imported chart's copies from them.
95
+ rememberImports(main.program, others);
96
+ const validation = validateProgram(main.program, index, source, { files: options.files });
97
+ // After a syntax error the model is partial. KIELER still links it and reports the names it cannot resolve
98
+ // (a misspelt state, a variable whose declaration did not parse); so does the engine (on the corpus's
99
+ // syntax-broken files the same ones as KIELER, tests/corpus/corpus.test.ts). Validation problems of a
100
+ // partial model are mostly consequences of the syntax error and of how the parser recovered from it ("no
101
+ // initial state" when the initial state did not parse, "unreachable" when a transition into the state was
102
+ // lost): on the corpus's 112 syntax-broken files the engine's validation agrees with KIELER's in 83, with
103
+ // 7 of its 15 unreachable states and 1 of its 5 missing initial states also KIELER's. They wait until the
104
+ // syntax is fixed; only a broken import, which does not depend on the rest of the file, is reported at once.
105
+ const syntaxBroken = main.syntax.some(d => d.severity === 'error');
106
+ const imported = importErrors(main.program, options.files ?? {});
107
+ const diagnostics = syntaxBroken ? [...main.syntax, ...linking, ...validation.filter(d => d.code === 'broken-import'), ...imported] : [...main.syntax, ...linking, ...validation, ...imported];
108
+ let chart;
109
+ if (options.chart !== undefined) {
110
+ chart = main.program.charts.find(c => c.name === options.chart);
111
+ if (!chart) {
112
+ diagnostics.push({
113
+ severity: 'error', code: 'unknown-chart', message: `There is no scchart called ${options.chart} in this file`,
114
+ hint: main.program.charts.length ? `The file contains ${main.program.charts.map(c => c.name).join(', ')}.` : undefined,
115
+ });
116
+ }
117
+ }
118
+ else {
119
+ chart = main.program.charts[0];
120
+ }
121
+ if (!main.program.charts.length && !main.syntax.some(d => d.severity === 'error')) {
122
+ diagnostics.push({
123
+ severity: 'error', code: 'no-chart', message: 'There is no scchart to run',
124
+ kieler: 'There is no SCChart to compile. Add a scchart declaration first.',
125
+ hint: 'A file needs at least one chart: `scchart Name { initial state Start }`.',
126
+ });
127
+ }
128
+ if (chart)
129
+ diagnostics.push(...codeNamingProblems(main.program.pragmas));
130
+ const front = sortDiagnostics(diagnostics);
131
+ const result = {
132
+ ok: !front.some(d => d.severity === 'error'),
133
+ program: main.program,
134
+ chart,
135
+ diagnostics: front,
136
+ interface: chart ? simulationInterface(chart, index) : [],
137
+ index,
138
+ };
139
+ if (chart && result.ok)
140
+ attachSimulator(result, chart, index, front);
141
+ return result;
142
+ }
143
+ catch (error) {
144
+ // Keep whatever parse can still give (the diagram can be drawn even if validation failed).
145
+ const fallback = parse(source);
146
+ return { ok: false, program: fallback.program, diagnostics: [...fallback.diagnostics, internalError(error)], interface: [] };
147
+ }
148
+ }
149
+ // ----- Imported files with errors ---------------------------------------------------------------------------------
150
+ /**
151
+ * KIELER does not compile a chart while a file it imports has errors (its own, or those of a file that one imports);
152
+ * SCCharts Lab says so on the import: "The imported file counter.sctx has errors. Line 5: Couldn't resolve reference
153
+ * to ValuedObject 'missing'." (probes tests/engine/kieler/imports/probe-import-broken*). Each file is checked as KIELER
154
+ * reads it: it sees the charts of the files it imports itself.
155
+ */
156
+ function importErrors(program, files) {
157
+ const names = Object.keys(files);
158
+ if (!program.imports.length || !names.length)
159
+ return [];
160
+ const memo = new Map();
161
+ const programs = new Map();
162
+ const charts = (name) => {
163
+ let p = programs.get(name);
164
+ if (!p) {
165
+ p = parseOnly(files[name]).program;
166
+ resolveProgram(p);
167
+ programs.set(name, p);
168
+ }
169
+ return p.charts;
170
+ };
171
+ // What a file sees: the charts of the files it imports, and of those they import in turn (KIELER's imports are
172
+ // transitive: probe tests/engine/kieler/imports/probe-import-transitive).
173
+ const visible = (name) => {
174
+ const seen = new Set([name]);
175
+ const queue = [name];
176
+ while (queue.length) {
177
+ const f = queue.shift();
178
+ charts(f);
179
+ for (const i of programs.get(f).imports)
180
+ for (const t of importTargets(i, f, names))
181
+ if (!seen.has(t))
182
+ (seen.add(t), queue.push(t));
183
+ }
184
+ seen.delete(name);
185
+ return [...seen];
186
+ };
187
+ const firstError = (name, stack) => {
188
+ if (memo.has(name))
189
+ return memo.get(name);
190
+ if (stack.has(name))
191
+ return undefined;
192
+ stack.add(name);
193
+ const text = files[name];
194
+ const parsed = parseOnly(text);
195
+ const targets = parsed.program.imports.map(i => importTargets(i, name, names));
196
+ const { index, diagnostics: linking } = resolveProgram(parsed.program, { externalCharts: visible(name).flatMap(charts) });
197
+ const own = [...parsed.syntax, ...linking, ...validateProgram(parsed.program, index, text, { files })].filter(d => d.severity === 'error');
198
+ let first;
199
+ const take = (f, at) => { if (!first || at < first.line)
200
+ first = f; };
201
+ for (const d of own)
202
+ take({ file: name, through: [], line: d.span?.line ?? 1, message: d.message, kieler: d.kieler ?? d.message }, d.span?.line ?? 1);
203
+ parsed.program.imports.forEach((_, i) => {
204
+ for (const t of targets[i]) {
205
+ const e = t === name ? undefined : firstError(t, stack);
206
+ if (e) {
207
+ take({ ...e, through: [t, ...e.through] }, parsed.program.importSpans?.[i]?.line ?? 1);
208
+ break;
209
+ }
210
+ }
211
+ });
212
+ stack.delete(name);
213
+ memo.set(name, first);
214
+ return first;
215
+ };
216
+ const out = [];
217
+ program.imports.forEach((name, i) => {
218
+ for (const t of importTargets(name, '', names)) {
219
+ const e = firstError(t, new Set());
220
+ if (!e)
221
+ continue;
222
+ // The file with the error, and the imports it came through (SCCharts Lab's words for an import of an import).
223
+ const via = e.through.length ? ` (imported through ${[t, ...e.through.slice(0, -1)].join(', ')})` : '';
224
+ const viaText = e.through.length ? `, imported through \`${[t, ...e.through.slice(0, -1)].join('`, `')}\`,` : '';
225
+ out.push({
226
+ severity: 'error', code: 'import-errors', span: program.importSpans?.[i] ?? program.span,
227
+ message: `The imported file \`${e.file}\`${viaText} has errors (line ${e.line}: ${e.message})`,
228
+ kieler: `The imported file ${e.file}${via} has errors. Line ${e.line}: ${e.kieler}`,
229
+ hint: `Open \`${e.file}\` and fix it: a chart does not compile while a file it imports has errors.`,
230
+ });
231
+ break;
232
+ }
233
+ });
234
+ return out;
235
+ }
236
+ /**
237
+ * Every variable of the simulated chart a reader may want to trace (the playground's variables picker), in
238
+ * declaration order: the simulation interface (inputs, outputs, the chart's own locals, inherited ones, clocks,
239
+ * KIELER's deltaT and sleepT), the members of the chart's class and struct instances, and the locals of the states
240
+ * and regions inside the chart, each with its scope and declared type. Values: `values` (or `present`) for the
241
+ * ones `inPool`, `trace[key]` for the others. Constants, methods and the inside of referenced charts are left out.
242
+ */
243
+ export function traceableVariables(result) {
244
+ const chart = result.chart;
245
+ if (!chart)
246
+ return [];
247
+ const index = result.index;
248
+ const out = [];
249
+ const chartScope = { kind: 'chart', id: chart.id, name: chart.name };
250
+ for (const v of result.interface) {
251
+ if (v.const)
252
+ continue;
253
+ const entry = index?.vos.get(v.id);
254
+ const declared = entry?.decl?.type;
255
+ const added = !entry && (v.name === 'deltaT' || v.name === 'sleepT');
256
+ const clock = declared === 'clock' || declared === 'clock-time';
257
+ const owner = entry?.owner;
258
+ out.push({
259
+ key: v.name, name: v.name,
260
+ group: added || clock ? 'time' : v.input ? 'input' : v.output ? 'output' : 'local',
261
+ type: clock ? declared : v.type, ...(clock && v.type !== declared ? { simulationType: v.type } : {}),
262
+ signal: v.signal, valued: v.valued, input: v.input, output: v.output, dims: v.dims,
263
+ // Inherited declarations belong to a base chart.
264
+ scope: owner && owner.kind === 'state' && owner !== chart ? { kind: 'chart', id: owner.id, name: owner.name } : chartScope,
265
+ inPool: true, ...(added ? { added: true } : {}),
266
+ });
267
+ }
268
+ const dims = (vo) => vo.cardinalities.map(c => {
269
+ const n = constantValue(c, index);
270
+ return typeof n === 'number' ? n : -1;
271
+ });
272
+ // Members of the chart's own instances (`struct Pt { int x } pt`): the pool has the object `pt`.
273
+ for (const d of chart.declarations) {
274
+ if ((d.declKind !== 'class' && d.declKind !== 'struct') || d.host)
275
+ continue;
276
+ for (const inst of d.valuedObjects) {
277
+ if (inst.cardinalities.length)
278
+ continue;
279
+ for (const m of d.members ?? []) {
280
+ if (m.declKind !== 'variable' || m.const)
281
+ continue;
282
+ for (const mvo of m.valuedObjects) {
283
+ const type = m.type ?? 'pure';
284
+ out.push({
285
+ key: `${inst.name}.${mvo.name}`, name: `${inst.name}.${mvo.name}`, group: 'member', type,
286
+ signal: m.signal, valued: m.signal && type !== 'pure', input: false, output: false, dims: dims(mvo),
287
+ scope: chartScope, inPool: false, member: { instance: inst.name, member: mvo.name },
288
+ });
289
+ }
290
+ }
291
+ }
292
+ }
293
+ const visitScope = (decls, scope, copies = []) => {
294
+ for (const d of decls) {
295
+ if (d.declKind !== 'variable' || d.const || d.input || d.output)
296
+ continue;
297
+ for (const vo of d.valuedObjects) {
298
+ const type = d.type ?? 'pure';
299
+ const base = {
300
+ group: type === 'clock' || type === 'clock-time' ? 'time' : 'local', type,
301
+ signal: d.signal, valued: d.signal && type !== 'pure', input: false, output: false, dims: dims(vo),
302
+ scope, inPool: false,
303
+ };
304
+ if (!copies.length)
305
+ out.push({ key: vo.id, name: vo.name, ...base });
306
+ for (const c of copies)
307
+ out.push({ key: `${vo.id}|${c.region}=${c.value}`, name: `${vo.name} (${c.counter} = ${c.value})`, ...base, copy: c });
308
+ }
309
+ }
310
+ };
311
+ const visitState = (st, copies) => {
312
+ if (st !== chart)
313
+ visitScope(st.declarations, { kind: 'state', id: st.id, name: st.name }, copies);
314
+ if (st.reference)
315
+ return;
316
+ for (const r of st.regions) {
317
+ // A for-region's own declarations are shared by its copies (KIELER moves them out of the region); its
318
+ // states' are each copy's (structure.md S-21).
319
+ visitScope(r.declarations, { kind: 'region', id: r.id, name: r.name ?? `a region of ${st.name}` }, copies);
320
+ const values = r.forLoop ? forValues(r.forLoop, index) : undefined;
321
+ const inner = values ? values.map(value => ({ region: r.id, counter: r.forLoop.variable, value })) : copies;
322
+ for (const c of r.states)
323
+ visitState(c, inner);
324
+ }
325
+ };
326
+ visitState(chart, []);
327
+ return out;
328
+ }
329
+ /** The counter values of a for-region in KIELER's order of its copies (passes/forRegion.ts range; S-22). */
330
+ function forValues(loop, index) {
331
+ let first = 0;
332
+ let last = -1;
333
+ const from = constantValue(loop.from, index);
334
+ const to = loop.to ? constantValue(loop.to, index) : undefined;
335
+ if (typeof from === 'number' && typeof to === 'number') {
336
+ first = from;
337
+ last = to;
338
+ }
339
+ else if (!loop.to && loop.from.kind === 'ref') {
340
+ const vo = loop.from.decl ? index?.vos.get(loop.from.decl)?.vo : undefined;
341
+ const size = vo?.cardinalities[0] ? constantValue(vo.cardinalities[0], index) : undefined;
342
+ if (typeof size === 'number')
343
+ last = size - 1;
344
+ }
345
+ else {
346
+ return [];
347
+ }
348
+ const out = [];
349
+ if (first <= last)
350
+ for (let i = first; i <= last; i++)
351
+ out.push(i);
352
+ else
353
+ for (let i = first; i >= last; i--)
354
+ out.push(i);
355
+ return out;
356
+ }
357
+ /**
358
+ * A chart that extends others has their public declarations in front of its own (KIELER's Inheritance processor,
359
+ * passes/inheritance.ts); a name the chart declares itself is its own.
360
+ */
361
+ function inheritedInterface(chart, index) {
362
+ if (!chart.baseStates?.length)
363
+ return [];
364
+ const own = new Set(chart.declarations.flatMap(d => d.valuedObjects.map(v => v.name)));
365
+ const out = [];
366
+ const seen = new Set([chart]);
367
+ const work = [...(index.baseStates.get(chart) ?? [])];
368
+ while (work.length) {
369
+ const base = work.shift();
370
+ if (seen.has(base))
371
+ continue;
372
+ seen.add(base);
373
+ const priv = new Set(base.declarations.filter(d => d.access === 'private' || d.access === 'protected').flatMap(d => d.valuedObjects.map(v => v.id)));
374
+ for (const v of extractInterface(base, index)) {
375
+ if (priv.has(v.id) || own.has(v.name))
376
+ continue;
377
+ own.add(v.name);
378
+ out.push(v);
379
+ }
380
+ work.push(...(index.baseStates.get(base) ?? []));
381
+ }
382
+ return out;
383
+ }
384
+ /**
385
+ * The interface KIELER's simulation has: the inherited declarations, the chart's own, and what the Timed Automata
386
+ * processor adds. In a timed chart, clocks (and `clock-time` variables) are of the clock type, float or, with
387
+ * @IntegerClockType, int: KIELER's data pool and its interface say so, not `clock`.
388
+ */
389
+ function simulationInterface(chart, index) {
390
+ const timing = timingOf(chart, index);
391
+ const own = [...inheritedInterface(chart, index), ...extractInterface(chart, index)];
392
+ if (!timing.timed)
393
+ return own;
394
+ const clockType = timing.integer ? 'int' : 'float';
395
+ return [...own.map(v => (v.type === 'clock' || v.type === 'clock-time' ? { ...v, type: clockType } : v)), ...timedInterface(chart, timing)];
396
+ }
397
+ /** What KIELER's Timed Automata processor sees: clocks and periods, and its annotations, anywhere in the chart. */
398
+ function timingOf(chart, index) {
399
+ let timed = false;
400
+ let integer = false;
401
+ let noSleep = false;
402
+ const seen = new Set();
403
+ const visitChart = (c) => {
404
+ if (seen.has(c))
405
+ return;
406
+ seen.add(c);
407
+ const visit = (value) => {
408
+ if (Array.isArray(value)) {
409
+ value.forEach(visit);
410
+ return;
411
+ }
412
+ if (!value || typeof value !== 'object')
413
+ return;
414
+ const obj = value;
415
+ if (obj.kind === 'declaration' && obj.type === 'clock' && obj.declKind === 'variable')
416
+ timed = true;
417
+ if (obj.kind === 'period')
418
+ timed = true;
419
+ if (obj.kind === 'annotation' && typeof obj.name === 'string') {
420
+ const n = obj.name.toLowerCase();
421
+ if (n === 'integerclocktype' || n === 'integralclocktype')
422
+ integer = true;
423
+ if (n === 'nosleep')
424
+ noSleep = true;
425
+ }
426
+ if (obj.kind === 'scopeCall') {
427
+ const target = index.scopeTargets.get(obj) ?? index.charts.find(x => x.name === obj.target);
428
+ if (target && !obj.super)
429
+ visitChart(target);
430
+ }
431
+ if (obj.kind === 'declaration' && obj.declKind === 'reference') {
432
+ const target = index.refTargets.get(obj);
433
+ if (target && target.kind === 'state')
434
+ visitChart(target);
435
+ }
436
+ for (const [k, v] of Object.entries(obj))
437
+ if (k !== 'span' && v && typeof v === 'object')
438
+ visit(v);
439
+ };
440
+ visit(c);
441
+ };
442
+ visitChart(chart);
443
+ return { timed, integer, noSleep };
444
+ }
445
+ /**
446
+ * KIELER's Timed Automata processor gives a chart with clocks (its own, its referenced charts', or a `period`'s) an
447
+ * input `deltaT` and an output `sleepT` of the clock type (structure.md S-35): the simulation shows them like the
448
+ * chart's own interface. A chart that declares them keeps its declarations; @NoSleep drops sleepT.
449
+ */
450
+ function timedInterface(chart, { timed, integer, noSleep }) {
451
+ if (!timed)
452
+ return [];
453
+ const own = new Set(chart.declarations.flatMap(d => d.valuedObjects.map(v => v.name.toLowerCase())));
454
+ const type = integer ? 'int' : 'float';
455
+ const info = (name, input) => ({
456
+ name, id: `${chart.id}$${name}`, type, signal: false, valued: false, input, output: !input, const: false, dims: [], initialValue: 0,
457
+ });
458
+ const out = [];
459
+ if (!own.has('deltat'))
460
+ out.push(info('deltaT', true));
461
+ if (!own.has('sleept') && !noSleep)
462
+ out.push(info('sleepT', false));
463
+ return out;
464
+ }
465
+ /**
466
+ * The simulator's compilation (KIELER's transformations and acceptance test) runs on first use of `ok`,
467
+ * `diagnostics` or `sim`, so parsing for a diagram stays cheap. The values are computed once.
468
+ */
469
+ function attachSimulator(result, chart, index, front) {
470
+ let done;
471
+ const get = () => {
472
+ if (done)
473
+ return done;
474
+ let sim;
475
+ const all = [...front];
476
+ try {
477
+ sim = compileChart(chart, index);
478
+ all.push(...sim.diagnostics);
479
+ }
480
+ catch (error) {
481
+ all.push(internalError(error));
482
+ }
483
+ const sorted = sortDiagnostics(all);
484
+ const copies = sim?.shared.forCopies;
485
+ const forCopies = copies?.length ? copies.map(c => ({ region: c.region, counter: c.counter, values: [...c.values], ...(c.name ? { name: c.name } : {}) })) : undefined;
486
+ done = { ok: !sorted.some(d => d.severity === 'error'), diagnostics: sorted, sim, forCopies };
487
+ return done;
488
+ };
489
+ Object.defineProperty(result, 'ok', { get: () => get().ok, set: v => { get().ok = v; }, enumerable: true, configurable: true });
490
+ Object.defineProperty(result, 'diagnostics', { get: () => get().diagnostics, set: v => { get().diagnostics = v; }, enumerable: true, configurable: true });
491
+ Object.defineProperty(result, 'sim', { get: () => get().sim, set: v => { get().sim = v; }, enumerable: true, configurable: true });
492
+ Object.defineProperty(result, 'forCopies', { get: () => get().forCopies, set: v => { get().forCopies = v; }, enumerable: true, configurable: true });
493
+ }
494
+ function sortDiagnostics(list) {
495
+ return list
496
+ .map((d, i) => ({ d, i }))
497
+ .sort((a, b) => (a.d.span?.start ?? Infinity) - (b.d.span?.start ?? Infinity) || a.i - b.i)
498
+ .map(x => x.d);
499
+ }
500
+ function internalError(error) {
501
+ return {
502
+ severity: 'error', code: 'internal',
503
+ message: `The engine failed on this input: ${error instanceof Error ? error.message : String(error)}`,
504
+ hint: 'This is a bug in the guide\'s engine, not in your chart. The official KIELER tools may still accept it.',
505
+ };
506
+ }
507
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,EAAE;AACF,yGAAyG;AACzG,8GAA8G;AAC9G,mHAAmH;AACnH,gHAAgH;AAChH,2GAA2G;AAC3G,iHAAiH;AACjH,uEAAuE;AACvE,iHAAiH;AACjH,sGAAsG;AACtG,EAAE;AACF,2GAA2G;AAC3G,8CAA8C;AAG9C,OAAO,EAAE,SAAS,EAAE,wBAAoB;AACxC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,8BAA0B;AACpE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAuB,2BAAuB;AACpF,OAAO,EAAE,cAAc,EAAmB,4BAAwB;AAClE,OAAO,EAAE,OAAO,EAAE,2BAAuB;AACzC,OAAO,EAAE,eAAe,EAAE,6BAAyB;AACnD,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,EAAE,YAAY,EAAsB,yBAAqB;AAChE,OAAO,EAAE,eAAe,EAAE,0BAAsB;AAChD,OAAO,EAAE,kBAAkB,EAAE,yBAAqB;AAKlD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,8BAA0B;AACpE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,0BAAsB;AAC9C,OAAO,EAAE,aAAa,EAAuB,2BAAuB;AACpE,OAAO,EAAE,6BAA6B,EAAE,yBA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AAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SAC1F,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACtB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO;QACH,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU;QACnC,OAAO,EAAE,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACrG,IAAI,EAAE,yGAAyG;KAClH,CAAA;AACL,CAAC","sourcesContent":["// Public API of the in-browser SCCharts engine (see docs-internal/ARCHITECTURE.md).\n//\n// parse(source) syntax only: the Program (with element ids, resolved transition targets and\n// references, so a diagram can be drawn) and the syntax diagnostics. Never throws.\n// compile(source, options) parse + name resolution + KIELER's validation rules, then the simulator's compilation\n// of the chart (KIELER's transformations, causality and instantaneous-loop analysis,\n// code generation checks): `ok` is false exactly when KIELER rejects the chart.\n// createSimulation(result) runs a compiled chart tick by tick (sim/index.ts); describeTick(tick, program) says\n// in plain English what happened in a tick.\n// parseExpression(source) one expression or effect on its own, with KIELER's grammar (for the operators page:\n// formatExpressionParenthesised in format.ts shows how KIELER grouped it).\n//\n// Diagnostics carry a beginner-friendly message and hint, a stable `code`, and (for linking and validation\n// problems) KIELER's own wording in `kieler`.\n\nimport type { Declaration, Diagnostic, Effect, Expression, ForCopies, ParseResult, Program, Region, State, ValuedObject, ValueType, VariableInfo } from './types'\nimport { assignIds } from './parser/ids'\nimport { constantValue, extractInterface } from './parser/interface'\nimport { parseProgram, parseStandalone, type StandaloneMode } from './parser/parser'\nimport { resolveProgram, type ModelIndex } from './parser/resolve'\nimport { LineMap } from './parser/source'\nimport { validateProgram } from './parser/validate'\nimport { importTargets } from './parser/imports'\nimport { kielerSyntaxWording } from './parser/kielerWording'\nimport { compileChart, type CompiledChart } from './sim/compile'\nimport { rememberImports } from './sim/describe'\nimport { codeNamingProblems } from './sim/codegen'\n\n// The data contract (the model, diagnostics, tick results), also published on its own as @sccharts-lab/engine/types.\nexport type * from './types'\nexport type { ModelIndex, VOEntry } from './parser/resolve'\nexport { extractInterface, constantValue } from './parser/interface'\nexport { lex, KEYWORDS } from './parser/lexer'\nexport { referenceName, type StandaloneMode } from './parser/parser'\nexport { formatExpressionParenthesised, formatEffectParenthesised, type ParenthesiseOptions } from './format'\nexport { createSimulation, describeTick, elementName, SIMULATOR_CODES, type DescribeOptions, type PoolValue, type Simulation, type SimulationOptions, type SimTickResult } from './sim/index'\nexport { generateC, type CNaming, type CVariable, type GenerateCOptions, type GeneratedC } from './codegen/index'\n\nexport interface CompileOptions {\n /** Name of the scchart to simulate (default: the first one in the file, as KIELER simulates rootStates.head). */\n chart?: string\n /** Other files, by file name (e.g. \"Beep.sctx\"), for `import` and references to charts in other files. */\n files?: Record<string, string>\n}\n\nexport interface CompileResult {\n /**\n * false if KIELER would reject the chart (errors in diagnostics). Reading `ok`, `diagnostics` or `sim` runs the\n * simulator's compilation once (lazily): until then only the front end (parse, resolve, validate) has run.\n */\n ok: boolean\n /** Available whenever parsing produced a model, even if !ok (for diagrams). */\n program?: Program\n /** The root state that is simulated. */\n chart?: State\n diagnostics: Diagnostic[]\n /**\n * Variables of the simulated chart (inputs, outputs and its top-level locals) as KIELER's simulation has them: the\n * inherited ones in front, `deltaT`/`sleepT` of timed charts at the end, clocks with the clock type (float or int).\n */\n interface: VariableInfo[]\n /** Resolved model: declarations by id, parent links, transition targets (for the simulator). */\n index?: ModelIndex\n /** The simulator's compiled chart (when the front end accepted it): KIELER's core chart, SCG and analysis, for tools. */\n sim?: CompiledChart\n /**\n * The for-regions of the simulated chart and the counter values KIELER copies each one for (structure.md S-21,\n * S-22), when it has any; read like `ok` (it runs the simulator's compilation). Each tick's `copies` says what each\n * copy did. A for-region of a referenced chart is listed under the id the expanded reference gives it.\n */\n forCopies?: ForCopies[]\n}\n\ninterface Parsed {\n program: Program\n syntax: Diagnostic[]\n lines: LineMap\n}\n\nfunction parseOnly(source: string): Parsed {\n const lines = new LineMap(source)\n const { program, diagnostics } = parseProgram(source, lines)\n assignIds(program)\n return { program, syntax: diagnostics, lines }\n}\n\n/** Parses SCTX. Never throws. Diagnostics are syntax errors (and lexical warnings) only. */\nexport function parse(source: string): ParseResult {\n let parsed: Parsed\n try {\n parsed = parseOnly(source)\n } catch (error) {\n return { diagnostics: [internalError(error)] }\n }\n try {\n resolveProgram(parsed.program)\n } catch (error) {\n // The model is still useful without resolved names (no transition targets).\n return { program: parsed.program, diagnostics: sortDiagnostics([...parsed.syntax, internalError(error)]) }\n }\n return { program: parsed.program, diagnostics: sortDiagnostics(parsed.syntax) }\n}\n\nexport interface ExpressionParseResult {\n /** The rule the text was read with: KIELER's `Expression` (a trigger, an initial value) or `Effect` (after `do`). */\n as: 'expression' | 'effect'\n /** Set when `as` is 'expression' and the text parsed. */\n expression?: Expression\n /** Set when `as` is 'effect' and the text parsed. */\n effect?: Effect\n /** Syntax errors (code 'parse', spans in the given text) and lexical warnings; empty when it parsed cleanly. */\n diagnostics: Diagnostic[]\n}\n\n/**\n * Parses one expression or effect on its own, exactly as KIELER's grammar reads it inside a chart (same rules,\n * same backtracking, same messages). `as: 'auto'` (default) reads it as an expression if it is one, otherwise as an\n * effect (`x = a + b`, `x++`, `S(3)` is a call when read as an expression). Names are not resolved. Never throws.\n */\nexport function parseExpression(source: string, options: { as?: StandaloneMode } = {}): ExpressionParseResult {\n try {\n const out = parseStandalone(source, options.as ?? 'auto')\n // KIELER's words for the syntax error, where they are known (parser/kielerWording.ts): what KIELER says when\n // the text is the trigger of a transition (`if <text> go to S`) or its effect (`do <text> go to S`). A\n // trigger that starts with a number is a count delay there, so such an expression gets none.\n const error = out.diagnostics.find(d => d.severity === 'error' && d.code === 'parse')\n if (error && error.kieler === undefined && !(out.as === 'expression' && /^\\s*[0-9.]/.test(source))) {\n const words = kielerSyntaxWording(source, out.as)\n if (words) error.kieler = words\n }\n return { ...out, diagnostics: sortDiagnostics(out.diagnostics) }\n } catch (error) {\n return { as: options.as === 'effect' ? 'effect' : 'expression', diagnostics: [internalError(error)] }\n }\n}\n\n/** Parses, resolves and validates a chart the way KIELER's front end does. Never throws. */\nexport function compile(source: string, options: CompileOptions = {}): CompileResult {\n try {\n const main = parseOnly(source)\n const others: Program[] = []\n for (const [name, text] of Object.entries(options.files ?? {})) {\n if (text === source && !name) continue\n const p = parseOnly(text).program\n resolveProgram(p)\n others.push(p)\n }\n const externalCharts = others.flatMap(p => p.charts)\n const { index, diagnostics: linking } = resolveProgram(main.program, { externalCharts })\n index.programs.push(...others)\n // describeTick names the elements of an imported chart's copies from them.\n rememberImports(main.program, others)\n const validation = validateProgram(main.program, index, source, { files: options.files })\n // After a syntax error the model is partial. KIELER still links it and reports the names it cannot resolve\n // (a misspelt state, a variable whose declaration did not parse); so does the engine (on the corpus's\n // syntax-broken files the same ones as KIELER, tests/corpus/corpus.test.ts). Validation problems of a\n // partial model are mostly consequences of the syntax error and of how the parser recovered from it (\"no\n // initial state\" when the initial state did not parse, \"unreachable\" when a transition into the state was\n // lost): on the corpus's 112 syntax-broken files the engine's validation agrees with KIELER's in 83, with\n // 7 of its 15 unreachable states and 1 of its 5 missing initial states also KIELER's. They wait until the\n // syntax is fixed; only a broken import, which does not depend on the rest of the file, is reported at once.\n const syntaxBroken = main.syntax.some(d => d.severity === 'error')\n const imported = importErrors(main.program, options.files ?? {})\n const diagnostics = syntaxBroken ? [...main.syntax, ...linking, ...validation.filter(d => d.code === 'broken-import'), ...imported] : [...main.syntax, ...linking, ...validation, ...imported]\n let chart: State | undefined\n if (options.chart !== undefined) {\n chart = main.program.charts.find(c => c.name === options.chart)\n if (!chart) {\n diagnostics.push({\n severity: 'error', code: 'unknown-chart', message: `There is no scchart called ${options.chart} in this file`,\n hint: main.program.charts.length ? `The file contains ${main.program.charts.map(c => c.name).join(', ')}.` : undefined,\n })\n }\n } else {\n chart = main.program.charts[0]\n }\n if (!main.program.charts.length && !main.syntax.some(d => d.severity === 'error')) {\n diagnostics.push({\n severity: 'error', code: 'no-chart', message: 'There is no scchart to run',\n kieler: 'There is no SCChart to compile. Add a scchart declaration first.',\n hint: 'A file needs at least one chart: `scchart Name { initial state Start }`.',\n })\n }\n if (chart) diagnostics.push(...codeNamingProblems(main.program.pragmas))\n const front = sortDiagnostics(diagnostics)\n const result: CompileResult = {\n ok: !front.some(d => d.severity === 'error'),\n program: main.program,\n chart,\n diagnostics: front,\n interface: chart ? simulationInterface(chart, index) : [],\n index,\n }\n if (chart && result.ok) attachSimulator(result, chart, index, front)\n return result\n } catch (error) {\n // Keep whatever parse can still give (the diagram can be drawn even if validation failed).\n const fallback = parse(source)\n return { ok: false, program: fallback.program, diagnostics: [...fallback.diagnostics, internalError(error)], interface: [] }\n }\n}\n\n// ----- Imported files with errors ---------------------------------------------------------------------------------\n\n/**\n * KIELER does not compile a chart while a file it imports has errors (its own, or those of a file that one imports);\n * SCCharts Lab says so on the import: \"The imported file counter.sctx has errors. Line 5: Couldn't resolve reference\n * to ValuedObject 'missing'.\" (probes tests/engine/kieler/imports/probe-import-broken*). Each file is checked as KIELER\n * reads it: it sees the charts of the files it imports itself.\n */\nfunction importErrors(program: Program, files: Record<string, string>): Diagnostic[] {\n const names = Object.keys(files)\n if (!program.imports.length || !names.length) return []\n // A file's first error: the file it is in (the file itself, or one it imports, perhaps through others), its line.\n type Found = { file: string; through: string[]; line: number; message: string; kieler: string }\n const memo = new Map<string, Found | undefined>()\n const programs = new Map<string, Program>()\n const charts = (name: string) => {\n let p = programs.get(name)\n if (!p) {\n p = parseOnly(files[name]).program\n resolveProgram(p)\n programs.set(name, p)\n }\n return p.charts\n }\n // What a file sees: the charts of the files it imports, and of those they import in turn (KIELER's imports are\n // transitive: probe tests/engine/kieler/imports/probe-import-transitive).\n const visible = (name: string): string[] => {\n const seen = new Set([name])\n const queue = [name]\n while (queue.length) {\n const f = queue.shift()!\n charts(f)\n for (const i of programs.get(f)!.imports) for (const t of importTargets(i, f, names)) if (!seen.has(t)) (seen.add(t), queue.push(t))\n }\n seen.delete(name)\n return [...seen]\n }\n const firstError = (name: string, stack: Set<string>): Found | undefined => {\n if (memo.has(name)) return memo.get(name)\n if (stack.has(name)) return undefined\n stack.add(name)\n const text = files[name]\n const parsed = parseOnly(text)\n const targets = parsed.program.imports.map(i => importTargets(i, name, names))\n const { index, diagnostics: linking } = resolveProgram(parsed.program, { externalCharts: visible(name).flatMap(charts) })\n const own = [...parsed.syntax, ...linking, ...validateProgram(parsed.program, index, text, { files })].filter(d => d.severity === 'error')\n let first: Found | undefined\n const take = (f: Found, at: number) => { if (!first || at < first.line) first = f }\n for (const d of own) take({ file: name, through: [], line: d.span?.line ?? 1, message: d.message, kieler: d.kieler ?? d.message }, d.span?.line ?? 1)\n parsed.program.imports.forEach((_, i) => {\n for (const t of targets[i]) {\n const e = t === name ? undefined : firstError(t, stack)\n if (e) {\n take({ ...e, through: [t, ...e.through] }, parsed.program.importSpans?.[i]?.line ?? 1)\n break\n }\n }\n })\n stack.delete(name)\n memo.set(name, first)\n return first\n }\n const out: Diagnostic[] = []\n program.imports.forEach((name, i) => {\n for (const t of importTargets(name, '', names)) {\n const e = firstError(t, new Set())\n if (!e) continue\n // The file with the error, and the imports it came through (SCCharts Lab's words for an import of an import).\n const via = e.through.length ? ` (imported through ${[t, ...e.through.slice(0, -1)].join(', ')})` : ''\n const viaText = e.through.length ? `, imported through \\`${[t, ...e.through.slice(0, -1)].join('`, `')}\\`,` : ''\n out.push({\n severity: 'error', code: 'import-errors', span: program.importSpans?.[i] ?? program.span,\n message: `The imported file \\`${e.file}\\`${viaText} has errors (line ${e.line}: ${e.message})`,\n kieler: `The imported file ${e.file}${via} has errors. Line ${e.line}: ${e.kieler}`,\n hint: `Open \\`${e.file}\\` and fix it: a chart does not compile while a file it imports has errors.`,\n })\n break\n }\n })\n return out\n}\n\n/** A variable a reader may want to trace in a simulation (`traceableVariables`). */\nexport interface TraceableVariable {\n /**\n * Where the value is in each tick: a name of KIELER's data pool (`SimTickResult.values` / `present`; `inPool`),\n * else a key of `SimTickResult.trace` (a local's declaration id `Chart.S$c`, a member `pt.x`).\n */\n key: string\n /** The name as the reader wrote it: `x`, `c`, `pt.x`, `deltaT`. */\n name: string\n /** inputs, outputs, the chart's own and inner locals, members of instances, and time (clocks, deltaT, sleepT). */\n group: 'input' | 'output' | 'local' | 'member' | 'time'\n /** The type as declared (a clock is `clock`; `simulationType` has KIELER's float or int). */\n type: ValueType\n /** KIELER's simulation type, when it differs from `type` (a clock of a timed chart: float, or int). */\n simulationType?: ValueType\n signal: boolean\n valued: boolean\n input: boolean\n output: boolean\n dims: number[]\n /** Where it is declared: the chart itself, or a state or region inside it. */\n scope: { kind: 'chart' | 'state' | 'region'; id: string; name: string }\n /** In KIELER's data pool by this name (the simulation's interface): traced by default. */\n inPool: boolean\n /** Added by KIELER (deltaT and sleepT of a timed chart). */\n added?: boolean\n /** Member of a class or struct instance of the chart: the instance and the member. */\n member?: { instance: string; member: string }\n /**\n * A local of a state inside a for-region: each copy has its own, with a key of its own (`<declaration id>|<region\n * id>=<value>`) and the copy in its name (`k (i = 2)`): the region, its counter and the counter's value.\n */\n copy?: { region: string; counter: string; value: number }\n}\n\n/**\n * Every variable of the simulated chart a reader may want to trace (the playground's variables picker), in\n * declaration order: the simulation interface (inputs, outputs, the chart's own locals, inherited ones, clocks,\n * KIELER's deltaT and sleepT), the members of the chart's class and struct instances, and the locals of the states\n * and regions inside the chart, each with its scope and declared type. Values: `values` (or `present`) for the\n * ones `inPool`, `trace[key]` for the others. Constants, methods and the inside of referenced charts are left out.\n */\nexport function traceableVariables(result: Pick<CompileResult, 'chart' | 'index' | 'interface'>): TraceableVariable[] {\n const chart = result.chart\n if (!chart) return []\n const index = result.index\n const out: TraceableVariable[] = []\n const chartScope = { kind: 'chart' as const, id: chart.id, name: chart.name }\n for (const v of result.interface) {\n if (v.const) continue\n const entry = index?.vos.get(v.id)\n const declared = entry?.decl?.type\n const added = !entry && (v.name === 'deltaT' || v.name === 'sleepT')\n const clock = declared === 'clock' || declared === 'clock-time'\n const owner = entry?.owner\n out.push({\n key: v.name, name: v.name,\n group: added || clock ? 'time' : v.input ? 'input' : v.output ? 'output' : 'local',\n type: clock ? declared! : v.type, ...(clock && v.type !== declared ? { simulationType: v.type } : {}),\n signal: v.signal, valued: v.valued, input: v.input, output: v.output, dims: v.dims,\n // Inherited declarations belong to a base chart.\n scope: owner && owner.kind === 'state' && owner !== chart ? { kind: 'chart', id: owner.id, name: owner.name } : chartScope,\n inPool: true, ...(added ? { added: true } : {}),\n })\n }\n const dims = (vo: ValuedObject) => vo.cardinalities.map(c => {\n const n = constantValue(c, index)\n return typeof n === 'number' ? n : -1\n })\n // Members of the chart's own instances (`struct Pt { int x } pt`): the pool has the object `pt`.\n for (const d of chart.declarations) {\n if ((d.declKind !== 'class' && d.declKind !== 'struct') || d.host) continue\n for (const inst of d.valuedObjects) {\n if (inst.cardinalities.length) continue\n for (const m of d.members ?? []) {\n if (m.declKind !== 'variable' || m.const) continue\n for (const mvo of m.valuedObjects) {\n const type = m.type ?? 'pure'\n out.push({\n key: `${inst.name}.${mvo.name}`, name: `${inst.name}.${mvo.name}`, group: 'member', type,\n signal: m.signal, valued: m.signal && type !== 'pure', input: false, output: false, dims: dims(mvo),\n scope: chartScope, inPool: false, member: { instance: inst.name, member: mvo.name },\n })\n }\n }\n }\n }\n // Locals of inner states and regions (not of referenced charts: their states are another chart's).\n type Copy = NonNullable<TraceableVariable['copy']>\n const visitScope = (decls: Declaration[], scope: TraceableVariable['scope'], copies: Copy[] = []) => {\n for (const d of decls) {\n if (d.declKind !== 'variable' || d.const || d.input || d.output) continue\n for (const vo of d.valuedObjects) {\n const type = d.type ?? 'pure'\n const base = {\n group: type === 'clock' || type === 'clock-time' ? 'time' as const : 'local' as const, type,\n signal: d.signal, valued: d.signal && type !== 'pure', input: false, output: false, dims: dims(vo),\n scope, inPool: false,\n }\n if (!copies.length) out.push({ key: vo.id, name: vo.name, ...base })\n for (const c of copies) out.push({ key: `${vo.id}|${c.region}=${c.value}`, name: `${vo.name} (${c.counter} = ${c.value})`, ...base, copy: c })\n }\n }\n }\n const visitState = (st: State, copies: Copy[]) => {\n if (st !== chart) visitScope(st.declarations, { kind: 'state', id: st.id, name: st.name }, copies)\n if (st.reference) return\n for (const r of st.regions) {\n // A for-region's own declarations are shared by its copies (KIELER moves them out of the region); its\n // states' are each copy's (structure.md S-21).\n visitScope(r.declarations, { kind: 'region', id: r.id, name: r.name ?? `a region of ${st.name}` }, copies)\n const values = r.forLoop ? forValues(r.forLoop, index) : undefined\n const inner = values ? values.map(value => ({ region: r.id, counter: r.forLoop!.variable, value })) : copies\n for (const c of r.states) visitState(c, inner)\n }\n }\n visitState(chart, [])\n return out\n}\n\n/** The counter values of a for-region in KIELER's order of its copies (passes/forRegion.ts range; S-22). */\nfunction forValues(loop: NonNullable<Region['forLoop']>, index: ModelIndex | undefined): number[] {\n let first = 0\n let last = -1\n const from = constantValue(loop.from, index)\n const to = loop.to ? constantValue(loop.to, index) : undefined\n if (typeof from === 'number' && typeof to === 'number') {\n first = from\n last = to\n } else if (!loop.to && loop.from.kind === 'ref') {\n const vo = loop.from.decl ? index?.vos.get(loop.from.decl)?.vo : undefined\n const size = vo?.cardinalities[0] ? constantValue(vo.cardinalities[0], index) : undefined\n if (typeof size === 'number') last = size - 1\n } else {\n return []\n }\n const out: number[] = []\n if (first <= last) for (let i = first; i <= last; i++) out.push(i)\n else for (let i = first; i >= last; i--) out.push(i)\n return out\n}\n\n/**\n * A chart that extends others has their public declarations in front of its own (KIELER's Inheritance processor,\n * passes/inheritance.ts); a name the chart declares itself is its own.\n */\nfunction inheritedInterface(chart: State, index: ModelIndex): VariableInfo[] {\n if (!chart.baseStates?.length) return []\n const own = new Set(chart.declarations.flatMap(d => d.valuedObjects.map(v => v.name)))\n const out: VariableInfo[] = []\n const seen = new Set<State>([chart])\n const work = [...(index.baseStates.get(chart) ?? [])]\n while (work.length) {\n const base = work.shift()!\n if (seen.has(base)) continue\n seen.add(base)\n const priv = new Set(base.declarations.filter(d => d.access === 'private' || d.access === 'protected').flatMap(d => d.valuedObjects.map(v => v.id)))\n for (const v of extractInterface(base, index)) {\n if (priv.has(v.id) || own.has(v.name)) continue\n own.add(v.name)\n out.push(v)\n }\n work.push(...(index.baseStates.get(base) ?? []))\n }\n return out\n}\n\n/**\n * The interface KIELER's simulation has: the inherited declarations, the chart's own, and what the Timed Automata\n * processor adds. In a timed chart, clocks (and `clock-time` variables) are of the clock type, float or, with\n * @IntegerClockType, int: KIELER's data pool and its interface say so, not `clock`.\n */\nfunction simulationInterface(chart: State, index: ModelIndex): VariableInfo[] {\n const timing = timingOf(chart, index)\n const own = [...inheritedInterface(chart, index), ...extractInterface(chart, index)]\n if (!timing.timed) return own\n const clockType = timing.integer ? 'int' : 'float'\n return [...own.map(v => (v.type === 'clock' || v.type === 'clock-time' ? { ...v, type: clockType } as VariableInfo : v)), ...timedInterface(chart, timing)]\n}\n\ninterface Timing {\n /** The chart, a chart it references or a `period` uses clocks. */\n timed: boolean\n /** @IntegerClockType (or @IntegralClockType) anywhere. */\n integer: boolean\n /** @NoSleep anywhere. */\n noSleep: boolean\n}\n\n/** What KIELER's Timed Automata processor sees: clocks and periods, and its annotations, anywhere in the chart. */\nfunction timingOf(chart: State, index: ModelIndex): Timing {\n let timed = false\n let integer = false\n let noSleep = false\n const seen = new Set<State>()\n const visitChart = (c: State) => {\n if (seen.has(c)) return\n seen.add(c)\n const visit = (value: unknown) => {\n if (Array.isArray(value)) { value.forEach(visit); return }\n if (!value || typeof value !== 'object') return\n const obj = value as Record<string, unknown>\n if (obj.kind === 'declaration' && obj.type === 'clock' && obj.declKind === 'variable') timed = true\n if (obj.kind === 'period') timed = true\n if (obj.kind === 'annotation' && typeof obj.name === 'string') {\n const n = obj.name.toLowerCase()\n if (n === 'integerclocktype' || n === 'integralclocktype') integer = true\n if (n === 'nosleep') noSleep = true\n }\n if (obj.kind === 'scopeCall') {\n const target = index.scopeTargets.get(obj as never) ?? index.charts.find(x => x.name === obj.target)\n if (target && !obj.super) visitChart(target)\n }\n if (obj.kind === 'declaration' && obj.declKind === 'reference') {\n const target = index.refTargets.get(obj as never)\n if (target && target.kind === 'state') visitChart(target)\n }\n for (const [k, v] of Object.entries(obj)) if (k !== 'span' && v && typeof v === 'object') visit(v)\n }\n visit(c)\n }\n visitChart(chart)\n return { timed, integer, noSleep }\n}\n\n/**\n * KIELER's Timed Automata processor gives a chart with clocks (its own, its referenced charts', or a `period`'s) an\n * input `deltaT` and an output `sleepT` of the clock type (structure.md S-35): the simulation shows them like the\n * chart's own interface. A chart that declares them keeps its declarations; @NoSleep drops sleepT.\n */\nfunction timedInterface(chart: State, { timed, integer, noSleep }: Timing): VariableInfo[] {\n if (!timed) return []\n const own = new Set(chart.declarations.flatMap(d => d.valuedObjects.map(v => v.name.toLowerCase())))\n const type = integer ? 'int' : 'float'\n const info = (name: string, input: boolean): VariableInfo => ({\n name, id: `${chart.id}$${name}`, type, signal: false, valued: false, input, output: !input, const: false, dims: [], initialValue: 0,\n })\n const out: VariableInfo[] = []\n if (!own.has('deltat')) out.push(info('deltaT', true))\n if (!own.has('sleept') && !noSleep) out.push(info('sleepT', false))\n return out\n}\n\n/**\n * The simulator's compilation (KIELER's transformations and acceptance test) runs on first use of `ok`,\n * `diagnostics` or `sim`, so parsing for a diagram stays cheap. The values are computed once.\n */\nfunction attachSimulator(result: CompileResult, chart: State, index: ModelIndex, front: Diagnostic[]) {\n let done: { ok: boolean; diagnostics: Diagnostic[]; sim?: CompiledChart; forCopies?: ForCopies[] } | undefined\n const get = () => {\n if (done) return done\n let sim: CompiledChart | undefined\n const all = [...front]\n try {\n sim = compileChart(chart, index)\n all.push(...sim.diagnostics)\n } catch (error) {\n all.push(internalError(error))\n }\n const sorted = sortDiagnostics(all)\n const copies = sim?.shared.forCopies as ForCopies[] | undefined\n const forCopies = copies?.length ? copies.map(c => ({ region: c.region, counter: c.counter, values: [...c.values], ...(c.name ? { name: c.name } : {}) })) : undefined\n done = { ok: !sorted.some(d => d.severity === 'error'), diagnostics: sorted, sim, forCopies }\n return done\n }\n Object.defineProperty(result, 'ok', { get: () => get().ok, set: v => { get().ok = v }, enumerable: true, configurable: true })\n Object.defineProperty(result, 'diagnostics', { get: () => get().diagnostics, set: v => { get().diagnostics = v }, enumerable: true, configurable: true })\n Object.defineProperty(result, 'sim', { get: () => get().sim, set: v => { get().sim = v }, enumerable: true, configurable: true })\n Object.defineProperty(result, 'forCopies', { get: () => get().forCopies, set: v => { get().forCopies = v }, enumerable: true, configurable: true })\n}\n\nfunction sortDiagnostics(list: Diagnostic[]): Diagnostic[] {\n return list\n .map((d, i) => ({ d, i }))\n .sort((a, b) => (a.d.span?.start ?? Infinity) - (b.d.span?.start ?? Infinity) || a.i - b.i)\n .map(x => x.d)\n}\n\nfunction internalError(error: unknown): Diagnostic {\n return {\n severity: 'error', code: 'internal',\n message: `The engine failed on this input: ${error instanceof Error ? error.message : String(error)}`,\n hint: 'This is a bug in the guide\\'s engine, not in your chart. The official KIELER tools may still accept it.',\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { allScopes, type CVar } from "./sim/model.js";
@@ -0,0 +1,4 @@
1
+ // Not part of the public API: what the other @sccharts-lab packages use of the engine's internals. They pin the
2
+ // engine's exact version, so this may change in any release.
3
+ export { allScopes } from "./sim/model.js";
4
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,6DAA6D;AAE7D,OAAO,EAAE,SAAS,EAAa,uBAAmB","sourcesContent":["// Not part of the public API: what the other @sccharts-lab packages use of the engine's internals. They pin the\n// engine's exact version, so this may change in any release.\n\nexport { allScopes, type CVar } from './sim/model'\n"]}