@tsplc/tmp-compiler 0.0.0-stage → 0.6.2

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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/cli.js +2325 -0
  4. package/dist/cli.js.map +26 -0
  5. package/dist/clock.js +11 -0
  6. package/dist/clock.js.map +11 -0
  7. package/dist/codesys.js +6558 -0
  8. package/dist/codesys.js.map +51 -0
  9. package/dist/collections.js +399 -0
  10. package/dist/collections.js.map +10 -0
  11. package/dist/index.js +16076 -0
  12. package/dist/index.js.map +61 -0
  13. package/dist/ir.js +3948 -0
  14. package/dist/ir.js.map +35 -0
  15. package/dist/retain.js +10 -0
  16. package/dist/retain.js.map +10 -0
  17. package/dist/signals.js +115 -0
  18. package/dist/signals.js.map +10 -0
  19. package/dist/telemetry.js +121 -0
  20. package/dist/telemetry.js.map +12 -0
  21. package/package.json +122 -4
  22. package/src/codesys/config.ts +50 -0
  23. package/src/codesys/debug.ts +655 -0
  24. package/src/codesys/emit.ts +185 -0
  25. package/src/codesys/endpoints.ts +111 -0
  26. package/src/codesys/engineering.ts +96 -0
  27. package/src/codesys/explain/expressions.ts +445 -0
  28. package/src/codesys/explain/flags.ts +134 -0
  29. package/src/codesys/explain/parameters.ts +53 -0
  30. package/src/codesys/explain/rows.ts +182 -0
  31. package/src/codesys/explain/tables.ts +79 -0
  32. package/src/codesys/explain/tasks.ts +68 -0
  33. package/src/codesys/explain/writes.ts +497 -0
  34. package/src/codesys/explain.ts +149 -0
  35. package/src/codesys/expressions.ts +100 -0
  36. package/src/codesys/global-lists.ts +284 -0
  37. package/src/codesys/global-names.ts +66 -0
  38. package/src/codesys/http.ts +1078 -0
  39. package/src/codesys/index.ts +13 -0
  40. package/src/codesys/instrumentation.ts +574 -0
  41. package/src/codesys/io-paths.ts +149 -0
  42. package/src/codesys/loops.ts +101 -0
  43. package/src/codesys/manifest.ts +684 -0
  44. package/src/codesys/names.ts +58 -0
  45. package/src/codesys/numeric.ts +516 -0
  46. package/src/codesys/plan.ts +688 -0
  47. package/src/codesys/programs.ts +138 -0
  48. package/src/codesys/publication.ts +99 -0
  49. package/src/codesys/required.ts +8 -0
  50. package/src/codesys/routines.ts +247 -0
  51. package/src/codesys/scan-clock.ts +103 -0
  52. package/src/codesys/scheduling.ts +96 -0
  53. package/src/codesys/service-channels.ts +24 -0
  54. package/src/codesys/sources.ts +118 -0
  55. package/src/codesys/st-files.ts +219 -0
  56. package/src/codesys/statements.ts +409 -0
  57. package/src/codesys/storage.ts +150 -0
  58. package/src/codesys/symbols.ts +240 -0
  59. package/src/codesys/task-access.ts +186 -0
  60. package/src/codesys/telemetry-settings.ts +19 -0
  61. package/src/codesys/telemetry.ts +852 -0
  62. package/src/codesys/types.ts +310 -0
  63. package/src/codesys/vendor.ts +113 -0
  64. package/src/frontend/analyzer.ts +779 -0
  65. package/src/frontend/async.ts +530 -0
  66. package/src/frontend/blocks.ts +578 -0
  67. package/src/frontend/configuration.ts +83 -0
  68. package/src/frontend/const-functions.ts +204 -0
  69. package/src/frontend/control-flow.ts +787 -0
  70. package/src/frontend/cooperative.ts +114 -0
  71. package/src/frontend/coroutines.ts +1336 -0
  72. package/src/frontend/dialect-names.ts +104 -0
  73. package/src/frontend/elaborate/array-searches.ts +224 -0
  74. package/src/frontend/elaborate/assignments.ts +343 -0
  75. package/src/frontend/elaborate/calls.ts +1342 -0
  76. package/src/frontend/elaborate/capture-protocol.ts +237 -0
  77. package/src/frontend/elaborate/capture.ts +388 -0
  78. package/src/frontend/elaborate/declarations.ts +124 -0
  79. package/src/frontend/elaborate/dialect.ts +473 -0
  80. package/src/frontend/elaborate/expressions.ts +2171 -0
  81. package/src/frontend/elaborate/filtered-arrays.ts +643 -0
  82. package/src/frontend/elaborate/frame.ts +145 -0
  83. package/src/frontend/elaborate/generics.ts +123 -0
  84. package/src/frontend/elaborate/graph.ts +141 -0
  85. package/src/frontend/elaborate/imports.ts +105 -0
  86. package/src/frontend/elaborate/index.ts +851 -0
  87. package/src/frontend/elaborate/initializers.ts +235 -0
  88. package/src/frontend/elaborate/iterators.ts +1541 -0
  89. package/src/frontend/elaborate/layouts.ts +1025 -0
  90. package/src/frontend/elaborate/model.ts +478 -0
  91. package/src/frontend/elaborate/names.ts +134 -0
  92. package/src/frontend/elaborate/reduce.ts +900 -0
  93. package/src/frontend/elaborate/references.ts +727 -0
  94. package/src/frontend/elaborate/retention.ts +284 -0
  95. package/src/frontend/elaborate/specialize.ts +1137 -0
  96. package/src/frontend/elaborate/statements.ts +1220 -0
  97. package/src/frontend/elaborate/storage.ts +836 -0
  98. package/src/frontend/elaborate/time-constructors.ts +34 -0
  99. package/src/frontend/elaborate/values.ts +200 -0
  100. package/src/frontend/elaborate/writes.ts +415 -0
  101. package/src/frontend/expressions.ts +1382 -0
  102. package/src/frontend/generated-names.ts +95 -0
  103. package/src/frontend/intrinsics.ts +382 -0
  104. package/src/frontend/lowering-key.ts +23 -0
  105. package/src/frontend/module-graph.ts +156 -0
  106. package/src/frontend/positions.ts +359 -0
  107. package/src/frontend/promise-chains.ts +872 -0
  108. package/src/frontend/promises.ts +419 -0
  109. package/src/frontend/routines.ts +239 -0
  110. package/src/frontend/sdk.ts +187 -0
  111. package/src/frontend/services.ts +609 -0
  112. package/src/frontend/statements.ts +871 -0
  113. package/src/frontend/tasks.ts +526 -0
  114. package/src/frontend/telemetry.ts +174 -0
  115. package/src/frontend/types.ts +1073 -0
  116. package/src/frontend/typescript.ts +651 -0
  117. package/src/index.ts +9 -0
  118. package/src/ir/aggregates.ts +291 -0
  119. package/src/ir/allocation.ts +96 -0
  120. package/src/ir/conditions.ts +855 -0
  121. package/src/ir/core-model.ts +289 -0
  122. package/src/ir/declarations.ts +281 -0
  123. package/src/ir/diagnostics.ts +68 -0
  124. package/src/ir/domains.ts +151 -0
  125. package/src/ir/fold.ts +279 -0
  126. package/src/ir/identity.ts +19 -0
  127. package/src/ir/index.ts +137 -0
  128. package/src/ir/job-errors.ts +69 -0
  129. package/src/ir/layouts.ts +211 -0
  130. package/src/ir/link.ts +302 -0
  131. package/src/ir/model.ts +394 -0
  132. package/src/ir/normalization-error.ts +10 -0
  133. package/src/ir/normalize.ts +52 -0
  134. package/src/ir/numeric.ts +163 -0
  135. package/src/ir/operands.ts +160 -0
  136. package/src/ir/ranges.ts +420 -0
  137. package/src/ir/routine.ts +1116 -0
  138. package/src/ir/scalars.ts +453 -0
  139. package/src/ir/share.ts +790 -0
  140. package/src/ir/short-circuit.ts +140 -0
  141. package/src/ir/tables.ts +111 -0
  142. package/src/ir/temporaries.ts +138 -0
  143. package/src/ir/types.ts +151 -0
  144. package/src/project/artifacts.ts +424 -0
  145. package/src/project/cli.ts +211 -0
  146. package/src/project/debugger.ts +111 -0
  147. package/src/project/deployments.ts +387 -0
  148. package/src/project/flags.ts +14 -0
  149. package/src/project/git.ts +35 -0
  150. package/src/project/plant.ts +629 -0
  151. package/src/project/project-commands.ts +507 -0
  152. package/src/project/project.ts +559 -0
  153. package/src/project/release.ts +152 -0
  154. package/src/project/server-check.ts +54 -0
  155. package/src/project/server.ts +165 -0
  156. package/src/project/terminal.ts +45 -0
  157. package/src/runtime/async.ts +207 -0
  158. package/src/runtime/launch.ts +59 -0
  159. package/src/runtime/main.ts +59 -0
  160. package/src/runtime/missing-file.ts +3 -0
  161. package/src/runtime/process.ts +177 -0
  162. package/src/runtime/program.ts +109 -0
  163. package/src/runtime/retain.ts +108 -0
  164. package/src/runtime/runtime.ts +324 -0
  165. package/src/runtime/settings.ts +27 -0
  166. package/src/runtime/storage.ts +456 -0
  167. package/src/runtime/symbols.ts +97 -0
  168. package/src/runtime/telemetry.ts +154 -0
  169. package/src/runtime/transport.ts +168 -0
  170. package/stdlib/clock.ts +8 -0
  171. package/stdlib/collections.ts +534 -0
  172. package/stdlib/plc-time.ts +2 -0
  173. package/stdlib/retain.ts +4 -0
  174. package/stdlib/signals.ts +142 -0
  175. package/stdlib/telemetry.ts +89 -0
  176. package/types/async.d.ts +87 -0
  177. package/types/clock.d.ts +8 -0
  178. package/types/config.d.ts +2 -0
  179. package/types/data-types.d.ts +31 -0
  180. package/types/dialect.d.ts +49 -0
  181. package/types/globals.d.ts +10 -0
  182. package/types/index.d.ts +212 -0
  183. package/types/retain.d.ts +12 -0
  184. package/types/telemetry.d.ts +47 -0
@@ -0,0 +1,51 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/codesys/index.ts", "../src/codesys/config.ts", "../src/codesys/engineering.ts", "../src/codesys/http.ts", "../src/codesys/required.ts", "../src/codesys/types.ts", "../src/codesys/names.ts", "../src/codesys/numeric.ts", "../src/codesys/programs.ts", "../src/codesys/scan-clock.ts", "../src/codesys/statements.ts", "../src/codesys/expressions.ts", "../src/codesys/instrumentation.ts", "../src/codesys/debug.ts", "../src/codesys/storage.ts", "../src/codesys/task-access.ts", "../src/codesys/io-paths.ts", "../src/codesys/manifest.ts", "../src/codesys/global-lists.ts", "../src/codesys/telemetry.ts", "../src/codesys/endpoints.ts", "../src/codesys/sources.ts", "../src/codesys/telemetry-settings.ts", "../src/codesys/loops.ts", "../src/codesys/emit.ts", "../src/codesys/explain.ts", "../src/codesys/explain/expressions.ts", "../src/codesys/explain/parameters.ts", "../src/codesys/explain/flags.ts", "../src/codesys/explain/rows.ts", "../src/codesys/explain/tables.ts", "../src/codesys/explain/tasks.ts", "../src/codesys/explain/writes.ts", "../src/codesys/plan.ts", "../src/codesys/publication.ts", "../src/codesys/scheduling.ts", "../src/codesys/routines.ts", "../src/codesys/symbols.ts", "../src/codesys/global-names.ts", "../src/codesys/service-channels.ts", "../src/codesys/st-files.ts", "../src/codesys/vendor.ts"],
4
+ "sourcesContent": [
5
+ "export { engineeringBuildSchema } from \"@tsplc/config/build\";\nexport { type CodesysOptions, codesys, direct } from \"./config\";\nexport { emitCodesys, type SourceMapping } from \"./emit\";\nexport {\n\tbuildCodesys,\n\ttype CodesysEngineeringBuild,\n\tcodesysBuildConfig,\n} from \"./engineering\";\nexport { ioTargets } from \"./io-paths\";\nexport type { ProjectHardware } from \"./manifest\";\nexport { type CodesysPlan, type CodesysProject, planCodesys } from \"./plan\";\nexport { publicationSelectors } from \"./publication\";\nexport { diagnoseCodesys } from \"./vendor\";\n",
6
+ "import {\n\tbuildTargetSchema,\n\thttpOptionsSchema,\n\tpublicationSchema,\n\ttype TargetDescriptor,\n} from \"@tsplc/config\";\nimport { directIoBindingSchema } from \"@tsplc/config/build\";\nimport { z } from \"zod\";\nimport { engineeringSchema } from \"./engineering\";\nimport { isIecIdentifier } from \"./names\";\n\nconst addressSchema = directIoBindingSchema.extend({\n\tkind: z.literal(\"direct\"),\n\t// A generated device tree maps this bit or byte channel to its target\n\t// variable, so the scan needs no AT wire or copy.\n\tmapped: z.boolean().optional(),\n});\n// Explicit IEC object names keep their exact spelling, so they must already be valid.\nconst iecNames = z\n\t.record(\n\t\tz.string().nonempty(),\n\t\tz\n\t\t\t.string()\n\t\t\t.refine(isIecIdentifier, \"Use a valid, non-reserved IEC identifier.\"),\n\t)\n\t.default({});\nexport const optionsSchema = z\n\t.object({\n\t\tengineering: engineeringSchema,\n\t\thttp: httpOptionsSchema,\n\t\tio: z.record(z.string().nonempty(), addressSchema),\n\t\tpublish: publicationSchema.default({ production: [], development: [] }),\n\t\tbuildTarget: buildTargetSchema.default(\"production\"),\n\t\tprogramNames: iecNames,\n\t})\n\t.strict();\nexport type CodesysOptions = z.infer<typeof optionsSchema>;\nexport function codesys(\n\toptions: z.input<typeof optionsSchema>,\n): TargetDescriptor<z.input<typeof optionsSchema>> {\n\treturn { kind: \"codesys\", options };\n}\n// tsPLC binds nothing at 64-bit addresses, so `%IL`/`%QL` are not offered.\nexport function direct(\n\taddress:\n\t\t| `%${\"I\" | \"Q\"}X${number}.${number}`\n\t\t| `%${\"I\" | \"Q\"}${\"B\" | \"W\" | \"D\"}${number}`,\n): z.infer<typeof addressSchema> {\n\treturn { kind: \"direct\", address };\n}\n",
7
+ "import { resolve } from \"node:path\";\nimport {\n\tcompileStructuredText,\n\ttype InstalledLibrary,\n\ttype ProgressOptions,\n} from \"@tsplc/build\";\nimport type { Controller, DeviceTree } from \"@tsplc/config\";\nimport { engineeringBuildSchema, resolveConfig } from \"@tsplc/config/build\";\nimport { z } from \"zod\";\nimport type { CodesysBundle } from \"./emit\";\nimport { httpLibraryReferences } from \"./http\";\nimport type { CodesysPlan } from \"./plan\";\nimport { taskPrograms } from \"./programs\";\nimport { required } from \"./required\";\n\nexport const engineeringSchema = z.strictObject({\n\tkind: z.literal(\"v3.5\"),\n\tbuild: engineeringBuildSchema.optional(),\n});\nexport type CodesysEngineeringBuild = z.input<typeof engineeringBuildSchema>;\n\nexport function codesysBuildConfig(\n\tplan: CodesysPlan,\n\tbundle: Pick<CodesysBundle, \"objects\">,\n\tpaths: {\n\t\tconfigFile: string;\n\t\tsourceDir: string;\n\t\toutDir: string;\n\t\tlibraries?: InstalledLibrary[];\n\t\tdeviceTree?: DeviceTree;\n\t\tcontroller?: Controller;\n\t},\n) {\n\tconst settings = plan.options.engineering.build;\n\tif (!settings) {\n\t\tthrow new Error(\n\t\t\t'Compiling with CODESYS needs a build section in the config, for example build: { outDir: \"build/codesys\" }. Add one, or emit the Structured Text only with build --emit-only.',\n\t\t);\n\t}\n\tconst [first] = plan.core.programs;\n\tif (!first) {\n\t\tthrow new Error(\"CODESYS build requires a generated PROGRAM entry.\");\n\t}\n\tconst programs = new Map(\n\t\tbundle.objects\n\t\t\t.filter((object) => object.kind === \"program\")\n\t\t\t.map((object) => [object.id, object]),\n\t);\n\tconst programIds = new Map(\n\t\tplan.core.programs.map((program) => [program.name, program.id]),\n\t);\n\tconst programObject = (id: string) => required(programs.get(id));\n\tconst tasks = plan.deployment.tasks.map((task) => {\n\t\tconst { configured, wrapper } = taskPrograms(plan, task);\n\t\treturn {\n\t\t\t...task,\n\t\t\tprograms: [\n\t\t\t\t...configured.map(\n\t\t\t\t\t(name) => programObject(required(programIds.get(name))).name,\n\t\t\t\t),\n\t\t\t\tprogramObject(wrapper.id).name,\n\t\t\t],\n\t\t};\n\t});\n\tconst entry = programObject(first.id);\n\tconst sourceDir = resolve(paths.sourceDir);\n\treturn resolveConfig(\n\t\t{\n\t\t\t...settings,\n\t\t\tlibraryReferences: [\n\t\t\t\t...settings.libraryReferences,\n\t\t\t\t...httpLibraryReferences(plan),\n\t\t\t],\n\t\t\t...(paths.libraries ? { libraries: paths.libraries } : {}),\n\t\t\t...(paths.deviceTree ? { deviceTree: paths.deviceTree } : {}),\n\t\t\t...(paths.controller ? { controller: paths.controller } : {}),\n\t\t\tsourceDir,\n\t\t\tentry: resolve(sourceDir, entry.sourcePath),\n\t\t\toutDir: resolve(paths.outDir),\n\t\t\ttasks,\n\t\t},\n\t\tpaths.configFile,\n\t);\n}\n\nexport async function buildCodesys(\n\tplan: CodesysPlan,\n\tbundle: Pick<CodesysBundle, \"objects\">,\n\tpaths: Parameters<typeof codesysBuildConfig>[2],\n\toptions: ProgressOptions = {},\n) {\n\treturn compileStructuredText(\n\t\tcodesysBuildConfig(plan, bundle, paths),\n\t\toptions,\n\t);\n}\n",
8
+ "import {\n\ttype CoreFunctionBlock,\n\ttype FunctionBlock,\n\ttype GeneratedObject,\n\thttpErrors,\n\tjobError,\n\ttype PlcType,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport { instrumentationFields } from \"@tsplc/debug/manifest\";\nimport {\n\telementaryType,\n\telementaryTypes,\n\tfitsNumber,\n\tintegerRange,\n} from \"@tsplc/iec\";\nimport { maxRecordFields } from \"@tsplc/server/contract\";\nimport { requestHeader } from \"@tsplc/server/requests\";\nimport {\n\tepochLength,\n\tplcBufferBytes,\n\ttype ServiceChannel,\n\tserviceOfPath,\n\tslotIdLength,\n\tslotStatus,\n} from \"@tsplc/server/wire\";\nimport type { NativeEndpoint } from \"./endpoints\";\nimport type { CodesysPlan } from \"./plan\";\nimport { required } from \"./required\";\nimport type { EmissionContext, GlobalSymbols } from \"./symbols\";\nimport { type CodesysTypes, stStringLiteral } from \"./types\";\n\nconst opcuaServiceCapacity = 16;\n\n/** The native client's request and response buffers, in bytes, each with room for its terminating NUL. */\nconst wireBytes = 8192;\n/** The most bytes a response's headers may take. */\nconst headerBytes = 4096;\n\n/*\n * SysSocket Interfaces' SOCKET_SOL, the socket level, and SOCKET_SO_KEEPALIVE, which the project\n * doesn't reference by name.\n */\nconst socketLevel = \"16#FFFF\";\nconst socketKeepAliveOption = \"16#8\";\nconst keepAliveIdleMs = 2000;\nconst keepAliveIntervalMs = 1000;\nconst keepAliveProbes = 3;\n\n/** The procedure a service block calls, as the server names it; its path when that isn't a service path. */\nexport const serviceName = (path: string) => serviceOfPath(path) ?? path;\n\n/** The most characters an integer prints as in decimal, its sign included. */\nexport const decimalLength = (layout: Parameters<typeof integerRange>[0]) =>\n\tMath.max(...integerRange(layout).map((bound) => String(bound).length));\n\n/** The unsigned IEC integer, at least DINT-wide, that ST widens a value of `bits` to. */\nexport const unsignedWidening = (bits: number): string => {\n\tconst type = elementaryTypes.find(\n\t\t(item) =>\n\t\t\titem.family === \"integer\" &&\n\t\t\t!item.signed &&\n\t\t\titem.bits >= Math.max(bits, 32),\n\t);\n\tif (!type) {\n\t\tthrow new Error(`No unsigned integer holds ${bits} bits.`);\n\t}\n\treturn type.name;\n};\n\n/**\n * A scalar as JSON: the most bytes it takes, the ST that appends `value` with the encoder methods\n * of `jsonEncoders`, and, when a 32-bit read holds it, the ST that reads it into `value` from\n * `payload`, flagging a malformed one.\n */\ninterface JsonScalar {\n\tsize: number;\n\tencode: (value: string) => string;\n\tdecode?: (value: string, target: CodesysTypes) => string;\n}\n\n/** The ST that reads a JSON integer into `assign`'s target, flagging one outside `range` as malformed. */\nconst readInteger = (range: readonly [bigint, bigint], assign: string) =>\n\t`ReadInteger(); IF numberValue < ${range[0]} OR numberValue > ${range[1]} THEN malformed:=TRUE; ELSE ${assign} END_IF;`;\n\n/** A BOOL, integer, bit string or UTF-8 STRING as JSON. */\nexport const jsonScalar = (type: PlcType): JsonScalar | undefined => {\n\tif (\n\t\ttype.kind === \"string\" &&\n\t\ttype.encoding === \"utf8\" &&\n\t\ttype.capacity <= plcBufferBytes\n\t) {\n\t\treturn {\n\t\t\tsize: type.capacity * 6 + 2,\n\t\t\tencode: (value) => `WriteString(${value});`,\n\t\t\tdecode: (value) =>\n\t\t\t\t`ReadString(); IF ByteLength(token) > ${type.capacity} THEN malformed := TRUE; ELSE ${value} := token; END_IF;`,\n\t\t};\n\t}\n\tif (type.kind === \"bool\") {\n\t\treturn {\n\t\t\tsize: 5,\n\t\t\tencode: (value) =>\n\t\t\t\t`IF ${value} THEN Append('true'); ELSE Append('false'); END_IF;`,\n\t\t\tdecode: (value) =>\n\t\t\t\t`IF MatchLiteral('true') THEN ${value}:=TRUE; ELSIF MatchLiteral('false') THEN ${value}:=FALSE; ELSE malformed:=TRUE;END_IF;`,\n\t\t};\n\t}\n\tif (type.kind !== \"bits\" && type.kind !== \"integer\") {\n\t\treturn undefined;\n\t}\n\tconst layout = {\n\t\tbits: type.bits,\n\t\tsigned: type.kind === \"integer\" && type.signed,\n\t};\n\tconst wide = unsignedWidening(type.bits);\n\treturn {\n\t\tsize: decimalLength(layout),\n\t\tencode: (value) =>\n\t\t\ttype.kind === \"bits\"\n\t\t\t\t? `Append(${wide}_TO_STRING(TO_${wide}(${value})));`\n\t\t\t\t: `Append(${type.id}_TO_STRING(${value}));`,\n\t\t...(fitsNumber(elementaryType(type.id)) && {\n\t\t\tdecode: (value: string, target: CodesysTypes) =>\n\t\t\t\treadInteger(\n\t\t\t\t\tintegerRange(layout),\n\t\t\t\t\t`${value}:=TO_${target.name(type.id)}(numberValue);`,\n\t\t\t\t),\n\t\t}),\n\t};\n};\n\n/** A scalar a service record carries: a strict enum as its DINT base, else a scalar a 32-bit read holds. */\nconst serviceScalar = (type: PlcType): Required<JsonScalar> | undefined => {\n\tif (type.kind === \"enum\") {\n\t\treturn {\n\t\t\tsize: Math.max(...type.members.map((member) => member.value.length)),\n\t\t\tencode: (value) => `Append(DINT_TO_STRING(TO_DINT(${value})));`,\n\t\t\tdecode: (value, target) =>\n\t\t\t\treadInteger(\n\t\t\t\t\tintegerRange(elementaryType(\"DINT\")),\n\t\t\t\t\t`CASE numberValue OF ${type.members.map((m) => `${m.value}: ${value}:=${target.name(type.id)}.${target.field(type.id, m.name)};`).join(\" \")} ELSE malformed:=TRUE; END_CASE;`,\n\t\t\t\t),\n\t\t};\n\t}\n\tconst scalar = jsonScalar(type);\n\treturn scalar?.decode && { ...scalar, decode: scalar.decode };\n};\n\ntype RecordLayout = Extract<PlcType, { kind: \"record\" }>;\n\n/** A service block's request and response ports and their records. */\ninterface HttpLayout {\n\trequest: Variable;\n\tresponse: Variable;\n\trequestLayout: RecordLayout;\n\tresponseLayout: RecordLayout;\n}\n\n/**\n * A service block's layout, or why its JSON cannot be exchanged: a record the codecs cannot\n * encode, or one whose worst case overflows the buffer.\n */\nexport const httpLayout = (\n\tblock: CoreFunctionBlock,\n\ttypes: ReadonlyMap<string, PlcType>,\n): HttpLayout | { error: string } => {\n\tconst request = block.inputs.find((v) => v.name === \"request\");\n\tconst response = block.outputs.find((v) => v.name === \"result\");\n\tif (!request || !response) {\n\t\treturn { error: \"Missing HTTP record ports.\" };\n\t}\n\tconst requestLayout = types.get(request.type);\n\tconst responseLayout = types.get(response.type);\n\tif (\n\t\trequestLayout?.kind !== \"record\" ||\n\t\tresponseLayout?.kind !== \"record\" ||\n\t\tresponseLayout.fields.length === 0 ||\n\t\tresponseLayout.fields.length > maxRecordFields\n\t) {\n\t\treturn {\n\t\t\terror: `HTTP requires closed request/response records with 1..${maxRecordFields} response fields.`,\n\t\t};\n\t}\n\tconst scalarSize = (id: string): number | undefined => {\n\t\tconst type = types.get(id);\n\t\treturn type && serviceScalar(type)?.size;\n\t};\n\tconst fieldSize = (\n\t\tfield: RecordLayout[\"fields\"][number],\n\t\tresponse: boolean,\n\t): number | undefined => {\n\t\tconst type = types.get(field.type);\n\t\tif (type?.kind !== \"array\" || response) {\n\t\t\treturn scalarSize(field.type);\n\t\t}\n\t\tconst element = scalarSize(type.element);\n\t\treturn element === undefined ? undefined : 2 + type.length * (element + 1);\n\t};\n\tfor (const [record, response] of [\n\t\t[requestLayout, false],\n\t\t[responseLayout, true],\n\t] as const) {\n\t\tconst sizes = record.fields.map((field) => fieldSize(field, response));\n\t\tif (!sizes.every((size): size is number => size !== undefined)) {\n\t\t\treturn {\n\t\t\t\terror:\n\t\t\t\t\t\"HTTP JSON supports bounded UTF-8 strings, BOOL, enums, and integers up to 32 bits.\",\n\t\t\t};\n\t\t}\n\t\tconst size = record.fields.reduce(\n\t\t\t(total, field) => total + field.name.length + 4,\n\t\t\tsizes.reduce((total, value) => total + value, 2),\n\t\t);\n\t\tif (size > plcBufferBytes) {\n\t\t\treturn {\n\t\t\t\terror: `The worst-case HTTP JSON payload exceeds the native ${plcBufferBytes}-byte buffer; reduce record/string/array bounds.`,\n\t\t\t};\n\t\t}\n\t}\n\treturn { request, response, requestLayout, responseLayout };\n};\n\n/** A service block's typed JSON codecs and ports; no application protocol lives here. */\ninterface ServiceCodecs {\n\tport: (label: string) => string;\n\t/** Appends the request record's fields as JSON. */\n\trequestCode: string;\n\t/** Decodes the response record from `payload`, setting `error` to `jobError.malformedResponse` when it is malformed. */\n\tdecodeResponse: string;\n\tinputs: string;\n\toutputs: string;\n}\n\nconst serviceCodecs = (\n\tblock: CoreFunctionBlock,\n\tfields: ReadonlyMap<string, string>,\n\ttypes: ReadonlyMap<string, PlcType>,\n\ttarget: CodesysTypes,\n): ServiceCodecs => {\n\tconst port = (label: string) => {\n\t\tconst variable = [...block.inputs, ...block.outputs].find(\n\t\t\t(v) => v.name === label,\n\t\t);\n\t\tif (!variable) {\n\t\t\tthrow new Error(`Missing HTTP port ${label}`);\n\t\t}\n\t\treturn required(fields.get(variable.id));\n\t};\n\tconst layout = httpLayout(block, types);\n\tif (\"error\" in layout) {\n\t\tthrow new Error(layout.error);\n\t}\n\tconst { request, response, requestLayout, responseLayout } = layout;\n\tconst typeOf = (id: string) => required(types.get(id));\n\tconst scalarOf = (type: PlcType) => required(serviceScalar(type));\n\tconst encode = (type: PlcType, value: string): string =>\n\t\ttype.kind === \"array\"\n\t\t\t? Array.from(\n\t\t\t\t\t{ length: type.length },\n\t\t\t\t\t(_, i) =>\n\t\t\t\t\t\t`${i ? \"Append(',');\" : \"\"}${encode(typeOf(type.element), `${value}[${i + type.lowerBound}]`)}`,\n\t\t\t\t).join(\"\\n\")\n\t\t\t: scalarOf(type).encode(value);\n\tconst requestCode = requestLayout.fields\n\t\t.map((field, i) => {\n\t\t\tconst type = typeOf(field.type);\n\t\t\tconst value = `${port(\"request\")}.${target.field(request.type, field.name)}`;\n\t\t\treturn `Append(${stStringLiteral(`${i ? \",\" : \"\"}\"${field.name}\":`)});${type.kind === \"array\" ? \"Append('[');\" : \"\"}${encode(type, value)}${type.kind === \"array\" ? \"Append(']');\" : \"\"}`;\n\t\t})\n\t\t.join(\"\\n\");\n\t// `seen` has a bit for each response field, so a record has at most `maxRecordFields`.\n\tconst responseCode = responseLayout.fields\n\t\t.map((field, i) => {\n\t\t\tconst value = `${port(\"result\")}.${target.field(response.type, field.name)}`;\n\t\t\tconst decode = scalarOf(typeOf(field.type)).decode(value, target);\n\t\t\treturn `${i === 0 ? \"IF\" : \"ELSIF\"} part = ${stStringLiteral(field.name)} THEN IF (seen AND SHL(DWORD#1,${i})) <> 0 THEN malformed:=TRUE; END_IF; seen:=seen OR SHL(DWORD#1,${i}); ${decode}`;\n\t\t})\n\t\t.join(\"\\n\");\n\tconst declarations = (variables: readonly Variable[]) =>\n\t\tvariables\n\t\t\t.map((v) => `${required(fields.get(v.id))} : ${target.name(v.type)};`)\n\t\t\t.join(\"\\n\");\n\tconst inputs = declarations(block.inputs);\n\tconst outputs = declarations(block.outputs);\n\tconst decodeResponse = `cursor:=1;malformed:=FALSE;seen:=0;\nSkipWhitespace();Expect(123);SkipWhitespace();\nWHILE cursor<=TO_UINT(ByteLength(payload)) AND NOT malformed DO\n IF payload[cursor-1]=125 THEN cursor:=cursor+1;EXIT;END_IF;\n ReadString();part:=token;SkipWhitespace();Expect(58);SkipWhitespace();\n ${responseCode} ELSE malformed:=TRUE;END_IF;\n SkipWhitespace();\n IF payload[cursor-1]=44 THEN cursor:=cursor+1;SkipWhitespace();IF payload[cursor-1]=125 THEN malformed:=TRUE;END_IF;\n ELSIF payload[cursor-1]<>125 THEN malformed:=TRUE;END_IF;\nEND_WHILE;\nSkipWhitespace();\nIF malformed OR cursor<>TO_UINT(ByteLength(payload))+1 OR seen<>DWORD#${2 ** responseLayout.fields.length - 1} THEN ${port(\"error\")}:=${jobError.malformedResponse};END_IF;`;\n\treturn { port, requestCode, decodeResponse, inputs, outputs };\n};\n\n/**\n * The global list an OPC UA client's calls to `path` go through, and its slots as channels for the\n * server's gateway. Requests are read-only to the gateway; replies and connection epochs it writes.\n */\nexport const rpcSlots = (\n\tsymbols: GlobalSymbols,\n\tid: string,\n\towner: string,\n\tpath: string,\n): { list: GeneratedObject; channels: ServiceChannel[] } => {\n\tconst name = symbols.names.allocateObject(\"GVL\", `TsplcRpc_${owner}`);\n\treturn {\n\t\tlist: {\n\t\t\tid: `${id}:rpc`,\n\t\t\tkind: \"globalList\",\n\t\t\tname,\n\t\t\tdeclaration: `{attribute 'qualified_only'}\nVAR_GLOBAL\n {attribute 'symbol' := 'read'} requests:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});\n {attribute 'symbol' := 'read'} requestIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${slotIdLength});\n {attribute 'symbol' := 'readwrite'} replyIds:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${slotIdLength});\n {attribute 'symbol' := 'readwrite'} replies:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${plcBufferBytes});\n {attribute 'symbol' := 'readwrite'} epochs:ARRAY[1..${opcuaServiceCapacity}] OF STRING(${epochLength});\n inUse:ARRAY[1..${opcuaServiceCapacity}] OF __XWORD;\n sequence:ARRAY[1..${opcuaServiceCapacity}] OF UDINT;\nEND_VAR`,\n\t\t},\n\t\tchannels: Array.from({ length: opcuaServiceCapacity }, (_, index) => ({\n\t\t\tpath,\n\t\t\trequest: `${name}.requests[${index + 1}]`,\n\t\t\treply: `${name}.replies[${index + 1}]`,\n\t\t\trequestId: `${name}.requestIds[${index + 1}]`,\n\t\t\treplyId: `${name}.replyIds[${index + 1}]`,\n\t\t\tepoch: `${name}.epochs[${index + 1}]`,\n\t\t})),\n\t};\n};\n\n/** The ASCII code of a one-character string, as a reply's bytes are compared. */\nconst ascii = (character: string) => character.charCodeAt(0);\n\n/**\n * A client block that exchanges what `body` appends to `payload` and its reply through a slot of\n * `rpcGlobal`, as `nativeHttp` does over HTTP. A reply whose status is `slotStatus.refused` is\n * reported as HTTP 400, and any status but `slotStatus.ok` as a network error. On success `decode`\n * runs over the reply's body in `payload`.\n */\nexport const opcuaClient = ({\n\tid,\n\tname,\n\tports,\n\tport,\n\ttimeoutMs,\n\trpcGlobal,\n\tbody,\n\tdecode,\n}: {\n\tid: string;\n\tname: string;\n\t/** Its input and output declarations, with `start`, `cancel`, `busy`, `done` and `error`. */\n\tports: string;\n\tport: (label: string) => string;\n\ttimeoutMs: number;\n\trpcGlobal: string;\n\tbody: string;\n\tdecode: string;\n}): GeneratedObject => {\n\tconst channel = (field: string, index = \"slotIndex\") =>\n\t\t`${rpcGlobal}.${field}[${index}]`;\n\treturn {\n\t\tid,\n\t\tkind: \"functionBlock\",\n\t\tname,\n\t\tdeclaration: `FUNCTION_BLOCK ${name}\n${ports}\nVAR\n timeout:TON;stage:UINT;slotIndex:UINT;candidate:UINT;\n identity:STRING(${slotIdLength});epoch:STRING(${epochLength});prefix:STRING(80);\n payload:STRING(${plcBufferBytes});token:STRING(${plcBufferBytes});part:STRING(${plcBufferBytes});\n cursor:UINT;malformed:BOOL;seen:DWORD;numberValue:LINT;tokenUsed:UINT;\nEND_VAR`,\n\t\timplementation: `IF NOT ${port(\"start\")} OR ${port(\"cancel\")} THEN\n IF slotIndex>0 THEN ${channel(\"requestIds\")}:='';${channel(\"requests\")}:='';${channel(\"inUse\")}:=0;END_IF;\n slotIndex:=0;stage:=0;timeout(IN:=FALSE);${port(\"busy\")}:=FALSE;${port(\"done\")}:=FALSE;${port(\"error\")}:=0;RETURN;\nEND_IF;\nIF stage=0 THEN\n FOR candidate:=1 TO ${opcuaServiceCapacity} DO\n (* __COMPARE_AND_SWAP can fail spuriously on ARM64; retry while the slot reads free. *)\n WHILE slotIndex=0 AND ${channel(\"epochs\", \"candidate\")}<>'' AND ${channel(\"inUse\", \"candidate\")}=0 DO\n IF __COMPARE_AND_SWAP(ADR(${channel(\"inUse\", \"candidate\")}),0,1) THEN slotIndex:=candidate;END_IF;\n END_WHILE;\n IF slotIndex>0 THEN EXIT;END_IF;\n END_FOR;\n IF slotIndex=0 THEN ${port(\"error\")}:=${jobError.noRequestSlot};stage:=90;\n ELSE\n ${channel(\"sequence\")}:=${channel(\"sequence\")}+1;\n IF ${channel(\"sequence\")}=0 THEN ${channel(\"epochs\")}:='';${port(\"error\")}:=${jobError.network};stage:=90;\n ELSE\n epoch:=${channel(\"epochs\")};identity:=CONCAT(CONCAT(epoch,':'),UDINT_TO_STRING(${channel(\"sequence\")}));\n prefix:=CONCAT(identity,'|');payload:='';malformed:=FALSE;\n ${body}\n IF malformed THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSIF ByteLength(payload)+LEN(prefix)>${plcBufferBytes} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSE\n FOR candidate:=0 TO LEN(prefix)-1 DO ${channel(\"requests\")}[candidate]:=prefix[candidate];END_FOR;\n FOR candidate:=0 TO ByteLength(payload)-1 DO ${channel(\"requests\")}[candidate+LEN(prefix)]:=payload[candidate];END_FOR;\n ${channel(\"requests\")}[ByteLength(payload)+LEN(prefix)]:=0;${channel(\"requestIds\")}:=identity;stage:=1;\n END_IF;\n END_IF;\n END_IF;\nEND_IF;\ntimeout(IN:=stage<90,PT:=T#${timeoutMs}ms);\nIF timeout.Q THEN ${port(\"error\")}:=${jobError.timeout};stage:=90;END_IF;\nIF stage=1 THEN\n IF ${channel(\"epochs\")}<>epoch THEN ${port(\"error\")}:=${jobError.network};stage:=90;\n ELSIF ${channel(\"replyIds\")}=identity AND_THEN LEFT(${channel(\"replies\")},LEN(prefix))=prefix THEN\n payload:='';cursor:=LEN(prefix);\n IF ByteLength(${channel(\"replies\")})<cursor+4 THEN ${port(\"error\")}:=${jobError.malformedResponse};\n ELSIF ${channel(\"replies\")}[cursor+1]<>${ascii(\"|\")} THEN ${port(\"error\")}:=${jobError.network};\n ELSIF ${channel(\"replies\")}[cursor]=${ascii(String(slotStatus.refused))} THEN ${port(\"error\")}:=${httpErrors.refused};\n ELSIF ${channel(\"replies\")}[cursor]<>${ascii(String(slotStatus.ok))} THEN ${port(\"error\")}:=${jobError.network};\n ELSE\n FOR candidate:=cursor+2 TO ByteLength(${channel(\"replies\")})-1 DO payload[candidate-cursor-2]:=${channel(\"replies\")}[candidate];END_FOR;\n payload[ByteLength(${channel(\"replies\")})-cursor-2]:=0;\n ${decode}\n END_IF;\n stage:=90;\n END_IF;\nEND_IF;\n${port(\"busy\")}:=stage<90;\nIF stage=90 THEN\n IF slotIndex>0 THEN ${channel(\"requestIds\")}:='';${channel(\"requests\")}:='';${channel(\"inUse\")}:=0;slotIndex:=0;END_IF;\n timeout(IN:=FALSE);${port(\"busy\")}:=FALSE;${port(\"done\")}:=TRUE;\nEND_IF;`,\n\t};\n};\n\ntype HttpRuntime = Extract<\n\tNonNullable<FunctionBlock[\"runtime\"]>,\n\t{ kind: \"http\" }\n>;\n\n/** An HTTP service block: a native client that sends the request record and decodes the response. */\nconst httpServiceBlock = (\n\tid: string,\n\truntime: HttpRuntime,\n\tname: string,\n\t{ port, requestCode, decodeResponse, inputs, outputs }: ServiceCodecs,\n\tendpoint: NativeEndpoint,\n\tnetwork: string,\n\t/** The requesting job's id input and this block's request counter, sent as `requestHeader`. */\n\ttrace: { job: string; sequence: string } | undefined,\n): [GeneratedObject, ...GeneratedObject[]] =>\n\tnativeHttp({\n\t\tid,\n\t\tname,\n\t\tports: `VAR_INPUT\n${inputs}${trace ? `\\n${trace.job} : ${instrumentationFields.job};` : \"\"}\nEND_VAR\nVAR_OUTPUT\n${outputs}\nEND_VAR`,\n\t\tport,\n\t\tendpoint,\n\t\tnetwork,\n\t\tmethod: runtime.method,\n\t\tjson: runtime.json,\n\t\tbody: runtime.json ? `Append('{'); ${requestCode} Append('}');` : \"\",\n\t\tdecode: decodeResponse,\n\t\t...(trace && { trace }),\n\t});\n\n/**\n * A native HTTP/1.1 client block over Net Base Services: it sends what `body` appends to\n * `payload` and, on a 2xx response, runs `decode` over the response body in `payload`.\n */\nexport const nativeHttp = ({\n\tid,\n\tname,\n\tports,\n\tport,\n\tendpoint,\n\tnetwork,\n\tmethod,\n\tjson,\n\tbody,\n\tdecode,\n\ttrace,\n}: {\n\tid: string;\n\tname: string;\n\t/** Its input and output declarations, with `start`, `cancel`, `busy`, `done` and `error`. */\n\tports: string;\n\tport: (label: string) => string;\n\tendpoint: NativeEndpoint;\n\tnetwork: string;\n\tmethod: string;\n\tjson: boolean;\n\tbody: string;\n\tdecode: string;\n\t/** The requesting job's id input and this block's request counter, sent as `requestHeader`. */\n\ttrace?: { job: string; sequence: string };\n}): [GeneratedObject, ...GeneratedObject[]] => {\n\tconst tracedRequest = trace\n\t\t? `AppendWire(UDINT_TO_STRING(${trace.job}));AppendWire(':');AppendWire(UDINT_TO_STRING(${trace.sequence}));AppendWire('$R$NContent-Length: ');`\n\t\t: \"\";\n\tconst release =\n\t\t\"resolver(xExecute:=FALSE,itfIPAddress:=remoteIP);client(xEnable:=FALSE);writer(xExecute:=FALSE);reader(xEnable:=FALSE);timeout(IN:=FALSE);\";\n\tconst block: GeneratedObject = {\n\t\tid,\n\t\tkind: \"functionBlock\",\n\t\tname,\n\t\tdeclaration: `FUNCTION_BLOCK ${name}\n${ports}\nVAR\n remoteAddress : NBS.IPv4Address;\n remoteIP : NBS.IIPAddress := remoteAddress;\n resolver : NBS.ResolveHostname := (itfAsyncProperty:=${network});\n ${endpoint.tls ? `certificateVerifier : ${name}_CertificateVerifier;\\n tlsContext : NBS.TLSContext := (itfCertVerifer:=certificateVerifier,sUseCaseName:='tsPLC HTTPS',ePurpose:=NBS.PURPOSE.CLIENT_SIDE,sTLSVersion:='1.2',sHostname:=${stStringLiteral(endpoint.host)},udiVerificationMode:=2);` : \"\"}\n client : NBS.TCP_Client := (itfAsyncProperty:=${network},itfIPAddress:=remoteAddress,uiPort:=${endpoint.port},udiTimeOut:=${endpoint.timeoutMs * 1000}${endpoint.tls ? \",itfTLSContext:=tlsContext\" : \"\"});\n writer : NBS.TCP_Write;\n reader : NBS.TCP_Read;\n timeout : TON;\n keepAlive : ${name}_KeepAlive;\n stage : UINT;\n wire : STRING(${wireBytes});\n received : STRING(${wireBytes});\n chunk : ARRAY[0..${wireBytes - 1}] OF BYTE;\n payload : STRING(${plcBufferBytes});\n token : STRING(${plcBufferBytes});\n part : STRING(${plcBufferBytes});\n used : UINT;\n headerEnd : UINT;\n contentLength : DINT;\n status : UINT;\n cursor : UINT;\n malformed : BOOL;\n seen : DWORD;\n numberValue : LINT;\n wireUsed : UINT;\n tokenUsed : UINT;\n index : UINT;${trace ? `\\n ${trace.sequence} : ${instrumentationFields.sequence};` : \"\"}\nEND_VAR\n`,\n\t\t// The host goes in the resolver call, not an initial value: an online change keeps the values\n\t\t// an instance already holds, so a changed host would otherwise wait for a download.\n\t\timplementation: `IF NOT ${port(\"start\")} OR ${port(\"cancel\")} THEN\n ${release}\n stage:=0; ${port(\"busy\")}:=FALSE; ${port(\"done\")}:=FALSE; ${port(\"error\")}:=0;\n RETURN;\nEND_IF;\nIF stage=0 THEN\n client.SetOptionProvider(itfOptionProvider:=keepAlive);\n payload:=''; malformed:=FALSE; used:=0; received:='';${trace ? `\\n ${trace.sequence}:=${trace.sequence}+1;` : \"\"}\n ${body}\n IF malformed THEN ${port(\"error\")}:=${jobError.tooLarge}; stage:=90;\n ELSE\n wire:='';wireUsed:=0;\n AppendWire(${stStringLiteral(`${method} ${endpoint.path} HTTP/1.1\\r\\nHost: ${endpoint.authority}\\r\\n${endpoint.token ? `Authorization: Bearer ${endpoint.token}\\r\\n` : \"\"}${json ? \"Content-Type: application/json\\r\\n\" : \"\"}Accept: application/json\\r\\nConnection: close\\r\\n${trace ? `${requestHeader}: ` : \"Content-Length: \"}`)});${tracedRequest}\n AppendWire(UINT_TO_STRING(ByteLength(payload)));AppendWire('$R$N$R$N');AppendWire(payload); stage:=10;\n END_IF;\nEND_IF;\ntimeout(IN:=stage<90,PT:=T#${endpoint.timeoutMs}ms);\nIF timeout.Q THEN ${port(\"error\")}:=${jobError.timeout}; stage:=90; END_IF;\n${port(\"busy\")}:=stage<90;\nIF stage=10 THEN\n resolver(xExecute:=TRUE,sHostname:=${stStringLiteral(endpoint.host)},itfIPAddress:=remoteIP);\n IF resolver.xError THEN ${port(\"error\")}:=${jobError.network};stage:=90;ELSIF resolver.xDone THEN stage:=1;END_IF;\nEND_IF;\nIF stage=1 THEN\n client(xEnable:=TRUE);\n IF client.xError THEN ${port(\"error\")}:=${endpoint.tls ? jobError.tls : jobError.network};stage:=90; ELSIF client.xActive THEN stage:=2;END_IF;\nEND_IF;\nIF stage=2 THEN\n writer(xExecute:=TRUE,itfConnection:=client.itfConnection,pData:=ADR(wire),udiSize:=UINT_TO_UDINT(wireUsed));\n IF writer.xError THEN ${port(\"error\")}:=${jobError.network};stage:=90;ELSIF writer.xDone THEN stage:=3;END_IF;\nEND_IF;\nIF stage=3 THEN\n IF used>=${wireBytes - 1} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSE\n reader(xEnable:=TRUE,itfConnection:=client.itfConnection,pData:=ADR(chunk),udiSize:=${wireBytes - 1});\n IF reader.xError THEN ${port(\"error\")}:=${jobError.network};stage:=90;\n ELSIF reader.xReady AND reader.udiCount>0 THEN\n IF TO_UDINT(used)+reader.udiCount>${wireBytes - 1} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSE\n FOR index:=0 TO TO_UINT(reader.udiCount)-1 DO received[used+index]:=chunk[index];END_FOR;\n used:=used+TO_UINT(reader.udiCount);received[used]:=0;\n FindHeaders();\n IF headerEnd=0 AND used>${headerBytes} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;END_IF;\n IF headerEnd>0 THEN\n IF headerEnd>${headerBytes} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSE\n ReadHeaders();\n IF malformed OR contentLength<0 OR contentLength>${plcBufferBytes} THEN ${port(\"error\")}:=${jobError.tooLarge};stage:=90;\n ELSIF TO_DINT(used)>=TO_DINT(headerEnd)+3+contentLength THEN\n IF status<200 OR status>=300 THEN ${port(\"error\")}:=${httpErrors.base}+status;stage:=90;\n ELSE\n payload:='';IF contentLength>0 THEN FOR index:=0 TO TO_UINT(contentLength)-1 DO payload[index]:=received[headerEnd+3+index]; END_FOR;END_IF;payload[TO_UINT(contentLength)]:=0; ${decode}\n stage:=90;\n END_IF;\n END_IF;\n END_IF;\n END_IF;\n END_IF;\n END_IF;\n END_IF;\nEND_IF;\nIF stage=90 THEN\n ${release}\n ${port(\"busy\")}:=FALSE;${port(\"done\")}:=TRUE;\nEND_IF;\n`,\n\t};\n\t// CODESYS calls FB_exit before a download, reset or application stop discards the instance, and\n\t// with bInCopyCode before an online change copies it. A connection still open then keeps the\n\t// Net Base Services task in a socket call, and the runtime can't delete the old application's\n\t// tasks until it restarts. A request this interrupts completes as a network error rather than\n\t// being sent again, since tsPLC never repeats a remote side effect.\n\tconst exit: GeneratedObject = {\n\t\tid: `${id}:FB_exit`,\n\t\tparent: id,\n\t\tkind: \"method\",\n\t\tname: \"FB_exit\",\n\t\tdeclaration:\n\t\t\t\"METHOD PUBLIC FB_exit : BOOL\\nVAR_INPUT\\n bInCopyCode : BOOL;\\nEND_VAR\",\n\t\timplementation: `IF stage>0 AND stage<90 THEN ${port(\"error\")}:=${jobError.network};stage:=90;END_IF;\n${release}\nFB_exit:=TRUE;`,\n\t};\n\treturn [block, exit, ...tcpKeepAlive(id, name)];\n};\n\n/**\n * TCP keep-alive for an HTTP client's connection, as an option provider the client applies to each socket it opens. A\n * connection whose peer vanished without closing it, as when the server's PC drops off the network, otherwise stays active\n * (Net Base Services' TCP_Client documentation), and a read on it holds the Net Base Services task every client shares,\n * cutting the PLC off from its server, and a download then finds the task unable to stop. With keep-alive, such a\n * connection fails within seconds and the task moves on. A live peer's TCP stack answers the probes however long its\n * server takes to reply, so they never end a slow request.\n */\nconst tcpKeepAlive = (owner: string, name: string): GeneratedObject[] => {\n\tconst id = `${owner}:keepAlive`;\n\treturn [\n\t\t{\n\t\t\tid,\n\t\t\tkind: \"functionBlock\",\n\t\t\tname: `${name}_KeepAlive`,\n\t\t\t// SysSocket Interfaces' RTS_SOCKET_SO_VALUE_TCP_KEEPALIVE, laid out as its seven 32-bit members: bOn, probes,\n\t\t\t// probesResult, timeout (ms idle before the first probe), timeoutResult, interval (ms between probes),\n\t\t\t// intervalResult. Three unanswered probes, the first after 2 s idle and a second apart, end it in 5 s.\n\t\t\tdeclaration: `FUNCTION_BLOCK ${name}_KeepAlive IMPLEMENTS NBS.IOptionProvider\nVAR\n keepAlive : ARRAY[0..6] OF DINT := [1, ${keepAliveProbes}, 0, ${keepAliveIdleMs}, 0, ${keepAliveIntervalMs}, 0];\nEND_VAR`,\n\t\t\timplementation: \"\",\n\t\t},\n\t\t{\n\t\t\tid: `${id}:GetOptionCount`,\n\t\t\tparent: id,\n\t\t\tkind: \"method\",\n\t\t\tname: \"GetOptionCount\",\n\t\t\tdeclaration: `METHOD PUBLIC GetOptionCount : USINT\nVAR_OUTPUT eErrorID : NBS.ERROR; END_VAR`,\n\t\t\timplementation: \"GetOptionCount:=1;eErrorID:=NBS.ERROR.NO_ERROR;\",\n\t\t},\n\t\t{\n\t\t\tid: `${id}:GetParams`,\n\t\t\tparent: id,\n\t\t\tkind: \"method\",\n\t\t\tname: \"GetParams\",\n\t\t\tdeclaration: `METHOD PUBLIC GetParams : NBS.ERROR\nVAR_INPUT usiIndex : USINT; END_VAR\nVAR_OUTPUT eOperation : NBS.OPERATION; optOption : NBS.OPTION; END_VAR`,\n\t\t\timplementation: `eOperation:=NBS.OPERATION.SET_OPTION;\noptOption.diLevel:=${socketLevel};\noptOption.diOption:=${socketKeepAliveOption};\noptOption.pdiOptionValue:=ADR(keepAlive);\noptOption.udiOptionLen:=SIZEOF(keepAlive);\nGetParams:=NBS.ERROR.NO_ERROR;`,\n\t\t},\n\t\t{\n\t\t\tid: `${id}:SetResult`,\n\t\t\tparent: id,\n\t\t\tkind: \"method\",\n\t\t\tname: \"SetResult\",\n\t\t\tdeclaration: `METHOD PUBLIC SetResult : NBS.ERROR\nVAR_INPUT usiIndex : USINT; udiResult : UDINT; END_VAR`,\n\t\t\t// A platform without keep-alive leaves the connection as it was before: nothing to undo.\n\t\t\timplementation: \"SetResult:=NBS.ERROR.NO_ERROR;\",\n\t\t},\n\t];\n};\n\nexport const httpCertificateVerifier = (\n\towner: string,\n\tname: string,\n\tendpoint: NativeEndpoint,\n): GeneratedObject[] => {\n\tif (!endpoint.tls) {\n\t\treturn [];\n\t}\n\tconst id = `${owner}:certificateVerifier`;\n\t// NBS represents certificate handles as pointers; verification keeps the native trust result.\n\tconst ipv4 = /^\\d+\\.\\d+\\.\\d+\\.\\d+$/.test(endpoint.host);\n\treturn [\n\t\t{\n\t\t\tid,\n\t\t\tkind: \"functionBlock\",\n\t\t\tname: `${name}_CertificateVerifier`,\n\t\t\tdeclaration: `FUNCTION_BLOCK ${name}_CertificateVerifier IMPLEMENTS NBS.ICertificateVerifier\nVAR\n hostname:STRING(255):=${stStringLiteral(endpoint.host)};\n ${ipv4 ? `address:ARRAY[0..3] OF BYTE := [${endpoint.host.split(\".\").join(\",\")}];` : \"\"}\nEND_VAR`,\n\t\t\timplementation: \"\",\n\t\t},\n\t\t{\n\t\t\tid: `${id}:VerifyCertificate`,\n\t\t\tparent: id,\n\t\t\tkind: \"method\",\n\t\t\tname: \"VerifyCertificate\",\n\t\t\tdeclaration: `METHOD PUBLIC VerifyCertificate : UDINT\nVAR_INPUT hCert:POINTER TO BYTE;eCurState:UDINT;END_VAR\nVAR matched:BOOL;result:UDINT;END_VAR`,\n\t\t\timplementation: `VerifyCertificate:=eCurState;\nIF eCurState<>0 THEN RETURN;END_IF;\nmatched:=CmpX509Cert_Implementation.${ipv4 ? \"X509CertCheckIP(hCert,ADR(address),0,ADR(result))\" : \"X509CertCheckHost(hCert,ADR(hostname),4,ADR(result))\"};\nIF result<>0 THEN VerifyCertificate:=result;ELSIF NOT matched THEN VerifyCertificate:=1;END_IF;`,\n\t\t},\n\t];\n};\n\nconst privateMethod = (\n\towner: string,\n\tname: string,\n\tdeclaration: string,\n\timplementation: string,\n\tresult?: string,\n): GeneratedObject => ({\n\tid: `${owner}:${name}`,\n\tparent: owner,\n\tkind: \"method\",\n\tname,\n\tdeclaration: `METHOD PRIVATE ${name}${result ? ` : ${result}` : \"\"}\\n${declaration}`,\n\timplementation,\n});\n\n// Standard string helpers accept STRING(255); native buffers must retain their full byte length.\nconst byteLengthMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ByteLength\",\n\t\t`VAR_INPUT value:STRING(${wireBytes});END_VAR\\nVAR i:UINT;END_VAR`,\n\t\t`ByteLength:=0;FOR i:=0 TO ${wireBytes - 1} DO IF value[i]=0 THEN ByteLength:=i;RETURN;END_IF;END_FOR;ByteLength:=${wireBytes};`,\n\t\t\"UINT\",\n\t);\n\nconst appendMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"Append\",\n\t\t`VAR_INPUT value : STRING(${plcBufferBytes}); END_VAR\\nVAR offset:UINT;i:UINT;END_VAR`,\n\t\t`offset:=TO_UINT(ByteLength(payload));IF offset+TO_UINT(ByteLength(value))>${plcBufferBytes} THEN malformed:=TRUE; ELSE IF ByteLength(value)>0 THEN FOR i:=0 TO TO_UINT(ByteLength(value))-1 DO payload[offset+i]:=value[i];END_FOR;END_IF;payload[offset+TO_UINT(ByteLength(value))]:=0;END_IF;`,\n\t);\n\nconst appendWireMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"AppendWire\",\n\t\t`VAR_INPUT value:STRING(${wireBytes});END_VAR\\nVAR i:UINT;END_VAR`,\n\t\t`IF wireUsed+TO_UINT(ByteLength(value))>${wireBytes - 1} THEN malformed:=TRUE;RETURN;END_IF;IF ByteLength(value)>0 THEN FOR i:=0 TO TO_UINT(ByteLength(value))-1 DO wire[wireUsed+i]:=value[i];END_FOR;END_IF;wireUsed:=wireUsed+TO_UINT(ByteLength(value));wire[wireUsed]:=0;`,\n\t);\n\nconst findHeadersMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"FindHeaders\",\n\t\t\"VAR i:UINT;END_VAR\",\n\t\t`headerEnd:=0;IF used<4 THEN RETURN;END_IF;\nFOR i:=0 TO used-4 DO IF received[i]=13 AND received[i+1]=10 AND received[i+2]=13 AND received[i+3]=10 THEN headerEnd:=i+1;RETURN;END_IF;END_FOR;`,\n\t);\n\nconst matchLiteralMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"MatchLiteral\",\n\t\t\"VAR_INPUT value:STRING(8);END_VAR\\nVAR i:UINT;size:UINT;END_VAR\",\n\t\t`MatchLiteral:=FALSE;size:=TO_UINT(ByteLength(value));IF cursor+size-1>TO_UINT(ByteLength(payload)) THEN RETURN;END_IF;\nFOR i:=0 TO size-1 DO IF payload[cursor-1+i]<>value[i] THEN RETURN;END_IF;END_FOR;cursor:=cursor+size;MatchLiteral:=TRUE;`,\n\t\t\"BOOL\",\n\t);\n\nconst readHeadersMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ReadHeaders\",\n\t\t`VAR lineStart:UINT;lineEnd:UINT;i:UINT;j:UINT;key:STRING(64);octet:BYTE;found:BOOL;digits:UINT;END_VAR`,\n\t\t`malformed:=FALSE;found:=FALSE;contentLength:=-1;\nIF LEFT(received,9)<>'HTTP/1.1 ' AND LEFT(received,9)<>'HTTP/1.0 ' THEN malformed:=TRUE;RETURN;END_IF;\nstatus:=0;FOR i:=9 TO 11 DO IF received[i]<48 OR received[i]>57 THEN malformed:=TRUE;RETURN;END_IF;status:=status*10+TO_UINT(received[i]-48);END_FOR;\nlineStart:=1;\nWHILE lineStart<headerEnd DO\n lineEnd:=lineStart;WHILE lineEnd<headerEnd AND received[lineEnd-1]<>13 DO lineEnd:=lineEnd+1;END_WHILE;\n key:='';j:=0;i:=lineStart;\n WHILE i<lineEnd AND received[i-1]<>58 AND j<63 DO octet:=received[i-1];IF octet>=65 AND octet<=90 THEN octet:=octet+32;END_IF;key[j]:=octet;j:=j+1;i:=i+1;END_WHILE;key[j]:=0;\n IF key='transfer-encoding' THEN malformed:=TRUE;RETURN;END_IF;\n IF key='content-length' THEN\n IF found THEN malformed:=TRUE;RETURN;END_IF;found:=TRUE;contentLength:=0;digits:=0;i:=i+1;\n WHILE i<lineEnd AND received[i-1]=32 DO i:=i+1;END_WHILE;\n WHILE i<lineEnd DO octet:=received[i-1];IF octet<48 OR octet>57 OR digits>=5 THEN malformed:=TRUE;RETURN;END_IF;contentLength:=contentLength*10+TO_DINT(octet-48);digits:=digits+1;i:=i+1;END_WHILE;\n IF digits=0 THEN malformed:=TRUE;RETURN;END_IF;\n END_IF;\n lineStart:=lineEnd+2;\nEND_WHILE;`,\n\t);\n\nconst writeStringMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"WriteString\",\n\t\t`VAR_INPUT value : STRING(${plcBufferBytes}); END_VAR\\nVAR i:UINT; one:STRING(1); hex:STRING(16):='0123456789abcdef'; END_VAR`,\n\t\t`Append('\"');IF ByteLength(value)>0 THEN FOR i:=0 TO ByteLength(value)-1 DO\n one[0]:=value[i];one[1]:=0;\n IF value[i]=34 OR value[i]=92 THEN Append('\\\\');Append(one);\n ELSIF value[i]<32 THEN Append('\\\\u00');one[0]:=hex[SHR(value[i],4)];Append(one);one[0]:=hex[value[i] AND 15];Append(one);\n ELSE Append(one);END_IF;\n END_FOR;END_IF;Append('\"');`,\n\t);\n\nconst skipWhitespaceMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"SkipWhitespace\",\n\t\t\"\",\n\t\t`WHILE cursor<=TO_UINT(ByteLength(payload)) DO IF payload[cursor-1]<>32 AND payload[cursor-1]<>9 AND payload[cursor-1]<>10 AND payload[cursor-1]<>13 THEN EXIT;END_IF;cursor:=cursor+1;END_WHILE;`,\n\t);\n\nconst expectMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"Expect\",\n\t\t\"VAR_INPUT value:BYTE; END_VAR\",\n\t\t`IF cursor>TO_UINT(ByteLength(payload)) OR_ELSE payload[cursor-1]<>value THEN malformed:=TRUE;ELSE cursor:=cursor+1;END_IF;`,\n\t);\n\nconst tokenByteMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"TokenByte\",\n\t\t\"VAR_INPUT value:BYTE;END_VAR\",\n\t\t`IF tokenUsed>=${plcBufferBytes} OR value=0 THEN malformed:=TRUE;RETURN;END_IF;token[tokenUsed]:=value;tokenUsed:=tokenUsed+1;token[tokenUsed]:=0;`,\n\t);\n\nconst readHexMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ReadHex\",\n\t\t\"VAR value:UDINT;i:UINT;octet:BYTE;END_VAR\",\n\t\t`numberValue:=0;FOR i:=1 TO 4 DO\nIF cursor>TO_UINT(ByteLength(payload)) THEN malformed:=TRUE;RETURN;END_IF;\noctet:=payload[cursor-1];cursor:=cursor+1;\nIF octet>=48 AND octet<=57 THEN value:=TO_UDINT(octet-48);ELSIF octet>=65 AND octet<=70 THEN value:=TO_UDINT(octet-55);ELSIF octet>=97 AND octet<=102 THEN value:=TO_UDINT(octet-87);ELSE malformed:=TRUE;RETURN;END_IF;\nnumberValue:=numberValue*16+TO_LINT(value);END_FOR;`,\n\t);\n\nconst readStringMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ReadString\",\n\t\t`VAR octet:BYTE;point:UDINT;high:UDINT;END_VAR`,\n\t\t`token:='';tokenUsed:=0;Expect(34);\nWHILE cursor<=TO_UINT(ByteLength(payload)) AND NOT malformed DO\n octet:=payload[cursor-1];cursor:=cursor+1;\n IF octet=34 THEN ValidateUtf8();RETURN;END_IF;\n IF octet=92 THEN\n IF cursor>TO_UINT(ByteLength(payload)) THEN malformed:=TRUE;RETURN;END_IF;\n octet:=payload[cursor-1];cursor:=cursor+1;\n CASE octet OF\n 34,47,92: TokenByte(octet);\n 98:TokenByte(8);102:TokenByte(12);110:TokenByte(10);114:TokenByte(13);116:TokenByte(9);\n 117:\n ReadHex();point:=TO_UDINT(numberValue);\n IF point>=55296 AND point<=56319 THEN\n high:=point;Expect(92);Expect(117);ReadHex();\n IF numberValue<56320 OR numberValue>57343 THEN malformed:=TRUE;RETURN;END_IF;\n point:=65536+(high-55296)*1024+TO_UDINT(numberValue)-56320;\n ELSIF point>=56320 AND point<=57343 THEN malformed:=TRUE;RETURN;END_IF;\n IF point<128 THEN TokenByte(TO_BYTE(point));\n ELSIF point<2048 THEN TokenByte(TO_BYTE(192+SHR(point,6)));TokenByte(TO_BYTE(128+(point AND 63)));\n ELSIF point<65536 THEN TokenByte(TO_BYTE(224+SHR(point,12)));TokenByte(TO_BYTE(128+(SHR(point,6) AND 63)));TokenByte(TO_BYTE(128+(point AND 63)));\n ELSE TokenByte(TO_BYTE(240+SHR(point,18)));TokenByte(TO_BYTE(128+(SHR(point,12) AND 63)));TokenByte(TO_BYTE(128+(SHR(point,6) AND 63)));TokenByte(TO_BYTE(128+(point AND 63)));END_IF;\n ELSE malformed:=TRUE;RETURN;\n END_CASE;\n ELSIF octet<32 THEN malformed:=TRUE;RETURN;ELSE TokenByte(octet);END_IF;\nEND_WHILE;malformed:=TRUE;`,\n\t);\n\nconst validateUtf8Method = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ValidateUtf8\",\n\t\t\"VAR i:UINT;j:UINT;count:UINT;first:BYTE;next:BYTE;END_VAR\",\n\t\t`i:=0;\nWHILE i<tokenUsed AND NOT malformed DO\n first:=token[i];\n IF first<128 THEN i:=i+1;\n ELSE\n IF first>=194 AND first<=223 THEN count:=1;ELSIF first>=224 AND first<=239 THEN count:=2;ELSIF first>=240 AND first<=244 THEN count:=3;ELSE malformed:=TRUE;RETURN;END_IF;\n IF i+count>=tokenUsed THEN malformed:=TRUE;RETURN;END_IF;\n next:=token[i+1];\n IF (first=224 AND next<160) OR (first=237 AND next>=160) OR (first=240 AND next<144) OR (first=244 AND next>=144) THEN malformed:=TRUE;RETURN;END_IF;\n FOR j:=1 TO count DO IF token[i+j]<128 OR token[i+j]>191 THEN malformed:=TRUE;RETURN;END_IF;END_FOR;\n i:=i+count+1;\n END_IF;\nEND_WHILE;`,\n\t);\n\nconst readIntegerMethod = (owner: string) =>\n\tprivateMethod(\n\t\towner,\n\t\t\"ReadInteger\",\n\t\t\"VAR negative:BOOL;digits:UINT;octet:BYTE;END_VAR\",\n\t\t`numberValue:=0;negative:=FALSE;digits:=0;\nIF payload[cursor-1]=45 THEN negative:=TRUE;cursor:=cursor+1;END_IF;\nWHILE cursor<=TO_UINT(ByteLength(payload)) DO\n octet:=payload[cursor-1];IF octet<48 OR octet>57 THEN EXIT;END_IF;\n IF digits>=10 THEN malformed:=TRUE;RETURN;END_IF;\n IF digits>0 AND numberValue=0 THEN malformed:=TRUE;RETURN;END_IF;numberValue:=numberValue*10+TO_LINT(octet-48);digits:=digits+1;cursor:=cursor+1;\nEND_WHILE;\nIF digits=0 THEN malformed:=TRUE;END_IF;IF negative THEN numberValue:=-numberValue;END_IF;`,\n\t);\n\n/** What the telemetry writer appends its records with. */\nexport const jsonEncoders = (owner: string): GeneratedObject[] => [\n\tbyteLengthMethod(owner),\n\tappendMethod(owner),\n\twriteStringMethod(owner),\n];\n\nconst jsonDecoders = (owner: string): GeneratedObject[] => [\n\tskipWhitespaceMethod(owner),\n\texpectMethod(owner),\n\ttokenByteMethod(owner),\n\treadHexMethod(owner),\n\treadStringMethod(owner),\n\tvalidateUtf8Method(owner),\n\treadIntegerMethod(owner),\n];\n\n/** The methods of a native HTTP client: the JSON codec's and those that frame its request and read the response's headers. */\nexport const httpClientMethods = (owner: string): GeneratedObject[] => [\n\tbyteLengthMethod(owner),\n\tappendMethod(owner),\n\tappendWireMethod(owner),\n\tfindHeadersMethod(owner),\n\tmatchLiteralMethod(owner),\n\treadHeadersMethod(owner),\n\twriteStringMethod(owner),\n\t...jsonDecoders(owner),\n];\n\n/** The methods of an OPC UA client: the JSON codec's. */\nexport const opcuaClientMethods = (owner: string): GeneratedObject[] => [\n\tbyteLengthMethod(owner),\n\tappendMethod(owner),\n\tmatchLiteralMethod(owner),\n\twriteStringMethod(owner),\n\t...jsonDecoders(owner),\n];\n\ntype ServiceRuntime = Extract<\n\tNonNullable<FunctionBlock[\"runtime\"]>,\n\t{ kind: \"http\" | \"rpc\" }\n>;\n\n/** A block that calls a service: its body is the request state machine `emitServiceBlock` writes. */\nexport const serviceBlock = <Block extends Pick<FunctionBlock, \"runtime\">>(\n\tblock: Block,\n): block is Block & { runtime: ServiceRuntime } =>\n\tblock.runtime?.kind === \"http\" || block.runtime?.kind === \"rpc\";\n\n/** A service-call block: its HTTP or OPC UA client, the client's methods and, over OPC UA, its slots' global list. */\nexport function emitServiceBlock(\n\t{ plan, symbols, instrumentation }: EmissionContext,\n\tnetworkName: string | undefined,\n\tfn: CoreFunctionBlock,\n): { objects: GeneratedObject[]; rpcChannels: ServiceChannel[] } {\n\tconst endpoint = required(plan.http[fn.id]);\n\tconst name = required(symbols.blockNames.get(fn.id));\n\tconst runtime = fn.runtime;\n\tconst codecs = serviceCodecs(\n\t\tfn,\n\t\trequired(symbols.blockFields.get(fn.id)),\n\t\tsymbols.typeMap,\n\t\tsymbols.targetTypes,\n\t);\n\tif (endpoint.transport === \"opcua\") {\n\t\tconst slots = rpcSlots(symbols, fn.id, name, endpoint.path);\n\t\treturn {\n\t\t\tobjects: [\n\t\t\t\tslots.list,\n\t\t\t\topcuaClient({\n\t\t\t\t\tid: fn.id,\n\t\t\t\t\tname,\n\t\t\t\t\tports: `VAR_INPUT ${codecs.inputs} END_VAR\\nVAR_OUTPUT ${codecs.outputs} END_VAR`,\n\t\t\t\t\tport: codecs.port,\n\t\t\t\t\ttimeoutMs: endpoint.timeoutMs,\n\t\t\t\t\trpcGlobal: slots.list.name,\n\t\t\t\t\tbody: `Append('{');${codecs.requestCode}Append('}');`,\n\t\t\t\t\tdecode: codecs.decodeResponse,\n\t\t\t\t}),\n\t\t\t\t...opcuaClientMethods(fn.id),\n\t\t\t],\n\t\t\trpcChannels: slots.channels,\n\t\t};\n\t}\n\tif (runtime?.kind !== \"http\") {\n\t\tthrow new Error(`Service block ${fn.id} has no HTTP runtime.`);\n\t}\n\tconst requestFields = instrumentation.fields.get(fn.id);\n\treturn {\n\t\tobjects: [\n\t\t\t...httpServiceBlock(\n\t\t\t\tfn.id,\n\t\t\t\truntime,\n\t\t\t\tname,\n\t\t\t\tcodecs,\n\t\t\t\tendpoint,\n\t\t\t\t`${required(networkName)}.network`,\n\t\t\t\trequestFields?.job && requestFields.sequence\n\t\t\t\t\t? { job: requestFields.job, sequence: requestFields.sequence }\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t\t...httpClientMethods(fn.id),\n\t\t\t...httpCertificateVerifier(fn.id, name, endpoint),\n\t\t],\n\t\trpcChannels: [],\n\t};\n}\n\n/** The endpoints the program's HTTP clients call: its service blocks' and the telemetry sender's. */\nconst nativeEndpoints = ({ http, telemetry }: CodesysPlan): NativeEndpoint[] =>\n\t[...Object.values(http), ...(telemetry ? [telemetry.endpoint] : [])].filter(\n\t\t(endpoint) => endpoint.transport === \"http\",\n\t);\n\n/** The libraries the program's HTTP clients reference, beyond what the project template does. */\nexport function httpLibraryReferences(plan: CodesysPlan): string[] {\n\tconst endpoints = nativeEndpoints(plan);\n\treturn [\n\t\t...(endpoints.length ? [\"Net Base Services, 4.0.0.0 (CODESYS)\"] : []),\n\t\t...(endpoints.some((endpoint) => endpoint.tls)\n\t\t\t? [\"CmpX509Cert Implementation, 3.5.22.0 (System)\"]\n\t\t\t: []),\n\t];\n}\n\n/** `GVL_TsplcNetwork`, the Net Base Services task every HTTP client runs on, when one does. */\nexport function httpNetwork(\n\tplan: CodesysPlan,\n\tsymbols: GlobalSymbols,\n): GeneratedObject | undefined {\n\tif (!nativeEndpoints(plan).length) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tid: \"runtime:httpNetwork\",\n\t\tkind: \"globalList\",\n\t\tname: symbols.names.allocateObject(\"GVL\", \"TsplcNetwork\"),\n\t\t// Blocks in other global lists take this in their initializers, so it must initialize first.\n\t\tdeclaration: `{attribute 'qualified_only'}\n{attribute 'global_init_slot' := '40000'}\nVAR_GLOBAL\nnetwork:NBS.AsyncProperty := (usiTaskPrio:=15,udiTaskInterval:=1000,tnTaskName:='tsPLC HTTP');\nEND_VAR\n`,\n\t};\n}\n",
9
+ "// All symbol relationships were checked by normalization and planning. Failure\n// here is an emitter invariant violation, rather than a recoverable source error.\nexport function required<T>(value: T | undefined): T {\n\tif (value === undefined) {\n\t\tthrow new Error(\"Missing verified CODESYS symbol.\");\n\t}\n\treturn value;\n}\n",
10
+ "import type { Constant, GeneratedObject, PlcType } from \"@tsplc/compiler/ir\";\nimport { instancedBlock } from \"@tsplc/compiler/ir\";\nimport {\n\tarrayTypeText,\n\tnanosecondsPerMillisecond,\n\tstringTypeText,\n} from \"@tsplc/iec\";\nimport { escapeString } from \"@tsplc/iec/st\";\nimport { Names } from \"./names\";\nimport { scalarLiteral } from \"./numeric\";\nimport { required } from \"./required\";\n\n/** A type's name as its source declares it: the last segment of its id. */\nexport const sourceTypeName = (id: string) => id.slice(id.lastIndexOf(\":\") + 1);\n\n/** The elementary type that holds a string type's text. */\nexport const stringTypeName = (type: Extract<PlcType, { kind: \"string\" }>) =>\n\ttype.encoding === \"utf8\" ? \"STRING\" : \"WSTRING\";\n\nconst stEscapes: ReadonlyMap<string, string> = new Map([\n\t[\"$\", \"$$\"],\n\t[\"'\", \"$'\"],\n\t[\"\\r\", \"$R\"],\n\t[\"\\n\", \"$N\"],\n]);\n/**\n * An ST STRING literal of text the compiler generates, such as an HTTP request line. Program\n * constants go through `CodesysTypes.literal`, which writes every control character as its code.\n */\nexport const stStringLiteral = (text: string) =>\n\t`'${[...text].map((character) => stEscapes.get(character) ?? character).join(\"\")}'`;\n\n/** The text of a string or array type: `STRING(n)`, or `ARRAY[l..u] OF T` of its element's name. */\nconst typeText = (\n\ttype: Extract<PlcType, { kind: \"string\" | \"array\" }>,\n\telement: (id: string) => string,\n) =>\n\ttype.kind === \"string\"\n\t\t? stringTypeText({\n\t\t\t\twide: type.encoding !== \"utf8\",\n\t\t\t\tcapacity: type.capacity,\n\t\t\t})\n\t\t: arrayTypeText({\n\t\t\t\tlower: type.lowerBound,\n\t\t\t\tupper: type.lowerBound + type.length - 1,\n\t\t\t\telement: element(type.element),\n\t\t\t});\n\nexport class CodesysTypes {\n\treadonly objects: GeneratedObject[] = [];\n\tprivate readonly names = new Map<string, string>();\n\tprivate readonly fields = new Map<string, Map<string, string>>();\n\n\tconstructor(\n\t\tprivate readonly types: ReadonlyMap<string, PlcType>,\n\t\tnames: Names,\n\t\tblockNames: ReadonlyMap<string, string>,\n\t) {\n\t\t// Register every type and member name before following layout dependencies.\n\t\tfor (const type of types.values()) {\n\t\t\tswitch (type.kind) {\n\t\t\t\tcase \"block\":\n\t\t\t\t\tthis.names.set(type.id, required(blockNames.get(type.block)));\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"record\":\n\t\t\t\tcase \"enum\": {\n\t\t\t\t\tconst prefix = type.kind === \"record\" ? \"ST\" : \"E\";\n\t\t\t\t\tthis.names.set(\n\t\t\t\t\t\ttype.id,\n\t\t\t\t\t\tnames.allocateObject(prefix, sourceTypeName(type.id)),\n\t\t\t\t\t);\n\t\t\t\t\tconst members = new Names();\n\t\t\t\t\tthis.fields.set(\n\t\t\t\t\t\ttype.id,\n\t\t\t\t\t\tnew Map(\n\t\t\t\t\t\t\t(type.kind === \"record\" ? type.fields : type.members).map(\n\t\t\t\t\t\t\t\t(member) => [member.name, members.allocate(member.name)],\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"array\":\n\t\t\t\tcase \"string\":\n\t\t\t\t\tif (!this.inline(type)) {\n\t\t\t\t\t\tthis.names.set(\n\t\t\t\t\t\t\ttype.id,\n\t\t\t\t\t\t\tnames.allocate(`T_${sourceTypeName(type.id)}`),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Verified layouts are acyclic.\n\t\tconst emitted = new Set<string>();\n\t\tconst emit = (type: PlcType): void => {\n\t\t\tif (type.kind === \"array\" && this.inline(type)) {\n\t\t\t\temit(this.type(type.element));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tinstancedBlock(type.id, types) ||\n\t\t\t\t!this.names.has(type.id) ||\n\t\t\t\temitted.has(type.id)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (type.kind === \"array\") {\n\t\t\t\temit(this.type(type.element));\n\t\t\t}\n\t\t\tif (type.kind === \"record\") {\n\t\t\t\tfor (const field of type.fields) {\n\t\t\t\t\temit(this.type(field.type));\n\t\t\t\t}\n\t\t\t}\n\t\t\temitted.add(type.id);\n\t\t\tconst name = this.name(type.id);\n\t\t\tconst declaration = this.dutDeclaration(type, name);\n\t\t\tthis.objects.push({ id: type.id, kind: \"dataType\", name, declaration });\n\t\t};\n\t\tfor (const type of types.values()) {\n\t\t\temit(type);\n\t\t}\n\t}\n\n\t/** The declaration of a data type's DUT. */\n\tprivate dutDeclaration(type: PlcType, name: string): string {\n\t\tif (type.kind === \"record\") {\n\t\t\tconst fields = type.fields\n\t\t\t\t.map(\n\t\t\t\t\t(field) =>\n\t\t\t\t\t\t` ${this.field(type.id, field.name)} : ${this.name(field.type)};`,\n\t\t\t\t)\n\t\t\t\t.join(\"\\n\");\n\t\t\treturn `TYPE ${name} :\nSTRUCT\n${fields}\nEND_STRUCT\nEND_TYPE\n`;\n\t\t}\n\t\tif (type.kind === \"array\") {\n\t\t\t// Typegen publishes each key of a `Record<Enum, T>` as its own contract variable.\n\t\t\treturn `${type.index ? \"{attribute 'tsplc_keyed'}\\n\" : \"\"}TYPE ${name} : ${typeText(type, (id) => this.name(id))};\nEND_TYPE\n`;\n\t\t}\n\t\tif (type.kind === \"string\") {\n\t\t\treturn `TYPE ${name} : ${typeText(type, (id) => this.name(id))};\nEND_TYPE\n`;\n\t\t}\n\t\tif (type.kind === \"enum\") {\n\t\t\tconst members = type.members\n\t\t\t\t.map(\n\t\t\t\t\t(member) =>\n\t\t\t\t\t\t` ${this.field(type.id, member.name)} := ${member.value}`,\n\t\t\t\t)\n\t\t\t\t.join(\",\\n\");\n\t\t\treturn `{attribute 'qualified_only'}\n{attribute 'strict'}\nTYPE ${name} : (\n${members}\n) DINT;\nEND_TYPE\n`;\n\t\t}\n\t\tthrow new Error(\"Unsupported verified data type\");\n\t}\n\n\tprivate type(id: string): PlcType {\n\t\treturn required(this.types.get(id));\n\t}\n\n\tname(id: string): string {\n\t\tconst named = this.names.get(id);\n\t\tif (named !== undefined) {\n\t\t\treturn named;\n\t\t}\n\t\tconst type = this.types.get(id);\n\t\tif (\n\t\t\t(type?.kind === \"string\" || type?.kind === \"array\") &&\n\t\t\tthis.inline(type)\n\t\t) {\n\t\t\treturn typeText(type, (element) => this.name(element));\n\t\t}\n\t\treturn id;\n\t}\n\n\t/**\n\t * Whether a type is declared in place rather than as a data type of its own. A named alias of\n\t * an array or a string would name its length, so a length change would change the variable's\n\t * type, which an online change refuses; in place it changes only the variable's layout. A block\n\t * array is always in place: a function block cannot be a data type's element. Keyed arrays keep\n\t * their alias, whose attribute publishes each key.\n\t */\n\tprivate inline(type: PlcType): boolean {\n\t\tif (type.kind === \"string\") {\n\t\t\treturn true;\n\t\t}\n\t\treturn (\n\t\t\ttype.kind === \"array\" &&\n\t\t\t(!type.index || instancedBlock(type.id, this.types) !== undefined)\n\t\t);\n\t}\n\n\tfield(id: string, name: string): string {\n\t\treturn required(this.fields.get(id)?.get(name));\n\t}\n\n\tdeclarationInitializer(value: Constant, id: string): string {\n\t\tconst type = this.type(id);\n\t\t// Our DUT fields have no custom initializers. CODESYS initializes their\n\t\t// numbers/BOOL/strings to zero/false/empty, including nested arrays/records.\n\t\t// Keep explicit nonzero enum members and signed floating zero: omission must\n\t\t// not change the initial value selected by PLC semantics.\n\t\tif (\n\t\t\t(type.kind === \"record\" || type.kind === \"array\") &&\n\t\t\tthis.isZero(value)\n\t\t) {\n\t\t\treturn \"\";\n\t\t}\n\t\treturn ` := ${this.initializer(value, id)}`;\n\t}\n\n\t/**\n\t * A declaration's initial value. A record initializer names only the fields that are not zero,\n\t * which CODESYS initializes as it would an omitted one; an enum field is always named. A record\n\t * that is all zero but must still be written, as an element of an array, is written in full.\n\t */\n\tprivate initializer(value: Constant, id: string): string {\n\t\tconst type = this.type(id);\n\t\tif (type.kind === \"array\" && value.kind === \"array\") {\n\t\t\treturn `[${value.items.map((item) => this.initializer(item, type.element)).join(\", \")}]`;\n\t\t}\n\t\tif (type.kind !== \"record\" || value.kind !== \"record\") {\n\t\t\treturn this.literal(value, id);\n\t\t}\n\t\tconst fields = type.fields.flatMap((field) => {\n\t\t\tconst initial = required(value.fields[field.name]);\n\t\t\treturn this.type(field.type).kind !== \"enum\" && this.isZero(initial)\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t`${this.field(id, field.name)} := ${this.initializer(initial, field.type)}`,\n\t\t\t\t\t];\n\t\t});\n\t\treturn fields.length ? `(${fields.join(\", \")})` : this.literal(value, id);\n\t}\n\n\tprivate isZero(value: Constant): boolean {\n\t\tif (value.kind === \"bool\") {\n\t\t\treturn !value.value;\n\t\t}\n\t\tif (value.kind === \"integer\") {\n\t\t\treturn value.value === \"0\";\n\t\t}\n\t\tif (value.kind === \"float\") {\n\t\t\treturn Object.is(value.value, 0);\n\t\t}\n\t\tif (value.kind === \"string\") {\n\t\t\treturn value.value === \"\";\n\t\t}\n\t\tif (value.kind === \"array\") {\n\t\t\treturn value.items.every((item) => this.isZero(item));\n\t\t}\n\t\tif (value.kind === \"record\") {\n\t\t\treturn Object.values(value.fields).every((item) => this.isZero(item));\n\t\t}\n\t\t// Time/calendar values remain explicit without relying on target defaults.\n\t\treturn false;\n\t}\n\n\tliteral(value: Constant, id: string): string {\n\t\tconst type = this.type(id);\n\t\tif (type.kind === \"enum\" && value.kind === \"integer\") {\n\t\t\tconst member = required(\n\t\t\t\ttype.members.find((member) => member.value === value.value),\n\t\t\t);\n\t\t\treturn `${this.name(id)}.${this.field(id, member.name)}`;\n\t\t}\n\t\tif (type.kind === \"string\" && value.kind === \"string\") {\n\t\t\tconst delimiter = type.encoding === \"utf16\" ? '\"' : \"'\";\n\t\t\treturn `${delimiter}${escapeString(value.value, delimiter)}${delimiter}`;\n\t\t}\n\t\tif (type.kind === \"array\" && value.kind === \"array\") {\n\t\t\treturn `[${value.items.map((item) => this.literal(item, type.element)).join(\", \")}]`;\n\t\t}\n\t\tif (type.kind === \"record\" && value.kind === \"record\") {\n\t\t\tconst fields = type.fields.map(\n\t\t\t\t(field) =>\n\t\t\t\t\t`${this.field(id, field.name)} := ${this.literal(required(value.fields[field.name]), field.type)}`,\n\t\t\t);\n\t\t\treturn `(${fields.join(\", \")})`;\n\t\t}\n\t\tif (type.kind === \"duration\" && value.kind === \"duration\") {\n\t\t\treturn `T#${BigInt(value.nanoseconds) / nanosecondsPerMillisecond}ms`;\n\t\t}\n\t\tif (type.kind === \"calendar\" && value.kind === \"calendar\") {\n\t\t\tif (type.domain === \"date\") {\n\t\t\t\treturn `D#${value.value}`;\n\t\t\t}\n\t\t\tif (type.domain === \"timeOfDay\") {\n\t\t\t\treturn `TOD#${value.value}`;\n\t\t\t}\n\t\t\treturn `DT#${value.value.replace(\"T\", \"-\")}`;\n\t\t}\n\t\treturn scalarLiteral(value, id);\n\t}\n}\n",
11
+ "import { generatedNamePattern, isReservedName } from \"@tsplc/iec/st\";\n\nexport function isIecIdentifier(name: string): boolean {\n\treturn (\n\t\tgeneratedNamePattern.test(name) &&\n\t\t!name.includes(\"__\") &&\n\t\t!isReservedName(name)\n\t);\n}\n\nconst identifierBody = (label: string): string =>\n\tlabel\n\t\t.replace(/[^A-Za-z0-9_]/g, \"_\")\n\t\t.replace(/_+/g, \"_\")\n\t\t.replace(/^_+|_+$/g, \"\") || \"name\";\n\nexport class Names {\n\tprivate readonly used = new Set<string>();\n\n\tconstructor(reserved: Iterable<string> = []) {\n\t\tfor (const name of reserved) {\n\t\t\tthis.reserve(name);\n\t\t}\n\t}\n\n\tallocateObject(\n\t\tprefix: \"FB\" | \"F\" | \"PRG\" | \"ST\" | \"E\" | \"GVL\",\n\t\tlabel: string,\n\t): string {\n\t\tconst source = prefix === \"F\" ? label.replace(/^PRG_/, \"\") : label;\n\t\tconst kind = prefix === \"F\" && source.startsWith(\"FUN_\") ? \"FUN\" : prefix;\n\t\tconst body = source.startsWith(`${kind}_`)\n\t\t\t? source.slice(kind.length + 1)\n\t\t\t: source;\n\t\treturn this.allocate(`${kind}_${identifierBody(body)}`);\n\t}\n\n\treserve(name: string): void {\n\t\tthis.used.add(name.toUpperCase());\n\t\t// Qualified native types must keep their library prefix resolvable in the\n\t\t// declaration scope, not merely reserve the complete dotted spelling.\n\t\tconst prefix = name.split(\".\")[0];\n\t\tif (prefix) {\n\t\t\tthis.used.add(prefix.toUpperCase());\n\t\t}\n\t}\n\tallocate(label: string): string {\n\t\tconst base = isIecIdentifier(label)\n\t\t\t? label\n\t\t\t: `plc_${identifierBody(label)}`;\n\t\tlet name = base;\n\t\tfor (let suffix = 2; this.used.has(name.toUpperCase()); suffix++) {\n\t\t\tname = `${base}_${suffix}`;\n\t\t}\n\t\tthis.reserve(name);\n\t\treturn name;\n\t}\n}\n",
12
+ "import {\n\ttype Constant,\n\ttype CoreExpression,\n\ttype CoreStatement,\n\texactIntegerLimit,\n\ttype GeneratedObject,\n\tintegerRange,\n\tintegerType,\n\tnestedBodies,\n\ttype PlcType,\n\tpathIndexes,\n\tstatementExpressions,\n\tsubexpressions,\n} from \"@tsplc/compiler/ir\";\nimport {\n\ttype BinaryOperator,\n\ttype ElementaryFunction,\n\tfloatMaximum,\n\tisElementary,\n} from \"@tsplc/iec/arithmetic\";\nimport { required } from \"./required\";\n\n/** The Structured Text function each elementary function is. */\nconst elementaryNames: Readonly<Record<ElementaryFunction, string>> = {\n\tsqrt: \"SQRT\",\n\tln: \"LN\",\n\tlog10: \"LOG\",\n\texp: \"EXP\",\n\tsin: \"SIN\",\n\tcos: \"COS\",\n\ttan: \"TAN\",\n\tasin: \"ASIN\",\n\tacos: \"ACOS\",\n\tatan: \"ATAN\",\n};\n\n/** The operators written as an ST operator between their operands, and their tokens. */\ntype InfixOperator = Exclude<\n\tBinaryOperator,\n\t\"and\" | \"or\" | \"power\" | \"shiftLeft\" | \"shiftRight\"\n>;\nconst operatorTokens: Readonly<Record<InfixOperator, string>> = {\n\tadd: \"+\",\n\tsubtract: \"-\",\n\tmultiply: \"*\",\n\tdivide: \"/\",\n\tremainder: \"MOD\",\n\tequal: \"=\",\n\tnotEqual: \"<>\",\n\tless: \"<\",\n\tlessEqual: \"<=\",\n\tgreater: \">\",\n\tgreaterEqual: \">=\",\n\tbitAnd: \"AND\",\n\tbitOr: \"OR\",\n\tbitXor: \"XOR\",\n};\nconst isInfix = (operator: BinaryOperator): operator is InfixOperator =>\n\tObject.hasOwn(operatorTokens, operator);\n\nexport function scalarLiteral(value: Constant, type: string): string {\n\tif (value.kind === \"bool\") {\n\t\treturn value.value ? \"TRUE\" : \"FALSE\";\n\t}\n\tif (value.kind === \"integer\") {\n\t\treturn `${type}#${value.value}`;\n\t}\n\tif (value.kind === \"float\") {\n\t\t// String(-0) loses the IEEE sign; keep it explicit in target float literals.\n\t\tconst text = Object.is(value.value, -0)\n\t\t\t? \"-0.0\"\n\t\t\t: String(value.value).replace(/e/i, \"E\");\n\t\treturn `${type}#${text}`;\n\t}\n\tthrow new Error(\"Expected verified scalar constant\");\n}\n\nexport class NumericLowering {\n\treadonly objects: GeneratedObject[] = [];\n\tprivate readonly helpers = new Map<string, string>();\n\n\tconstructor(\n\t\tprivate readonly types: ReadonlyMap<string, PlcType>,\n\t\tprivate readonly allocate: (label: string) => string,\n\t\t/** What a `now()` reads; undefined for a program that never calls it. */\n\t\tprivate readonly scanClock: string | undefined,\n\t) {}\n\n\tprivate prepare(value: CoreExpression): void {\n\t\tfor (const operand of subexpressions(value)) {\n\t\t\tthis.prepare(operand);\n\t\t}\n\t\tif (value.kind === \"binary\" && value.policy) {\n\t\t\tthis.arithmetic(value.type, value.operator, value.policy);\n\t\t}\n\t\tif (value.kind === \"convert\" && value.policy === \"saturate\") {\n\t\t\tthis.saturation(value.operand.type, value.type);\n\t\t}\n\t\tif (value.kind === \"unary\" && value.operator === \"truncate\") {\n\t\t\tthis.truncation(value.type);\n\t\t}\n\t}\n\n\tprepareStatements(items: readonly CoreStatement[]): void {\n\t\tfor (const item of items) {\n\t\t\t// Helpers are emitted in the order they are found, and the build id hashes that order,\n\t\t\t// so an assignment's value keeps being prepared before its place's indexes.\n\t\t\tconst values =\n\t\t\t\titem.kind === \"assign\"\n\t\t\t\t\t? [item.value, ...pathIndexes(item.path)]\n\t\t\t\t\t: statementExpressions(item);\n\t\t\tfor (const value of values) {\n\t\t\t\tthis.prepare(value);\n\t\t\t}\n\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\tthis.prepareStatements(body);\n\t\t\t}\n\t\t}\n\t}\n\n\trender(value: CoreExpression, operands: readonly string[]): string {\n\t\tif (value.kind === \"convert\") {\n\t\t\treturn value.policy === \"saturate\"\n\t\t\t\t? `${this.saturation(value.operand.type, value.type)}(${operands[0]})`\n\t\t\t\t: `TO_${value.type}(${operands[0]})`;\n\t\t}\n\t\tif (value.kind === \"unary\") {\n\t\t\t// Avoid signed intermediate casts: TIME spans the complete UDINT range.\n\t\t\tif (value.operator === \"timeToMilliseconds\") {\n\t\t\t\treturn `TIME_TO_UDINT(${operands[0]})`;\n\t\t\t}\n\t\t\tif (value.operator === \"clock\") {\n\t\t\t\treturn required(this.scanClock);\n\t\t\t}\n\t\t\tif (isElementary(value.operator)) {\n\t\t\t\treturn `${elementaryNames[value.operator]}(${operands[0]})`;\n\t\t\t}\n\t\t\tif (value.operator === \"truncate\") {\n\t\t\t\treturn `${this.truncation(value.type)}(${operands[0]})`;\n\t\t\t}\n\t\t\tif (value.operator === \"not\") {\n\t\t\t\treturn `(NOT ${operands[0]})`;\n\t\t\t}\n\t\t\tconst sign = value.operator === \"negate\" ? \"-\" : \"NOT \";\n\t\t\treturn `TO_${value.type}(${sign}${operands[0]})`;\n\t\t}\n\t\tif (value.kind !== \"binary\") {\n\t\t\tthrow new Error(\"Expected numeric operation\");\n\t\t}\n\t\tif (value.policy) {\n\t\t\treturn `${this.arithmetic(value.type, value.operator, value.policy)}(${operands.join(\", \")})`;\n\t\t}\n\t\tswitch (value.operator) {\n\t\t\tcase \"power\":\n\t\t\t\treturn `EXPT(${operands.join(\", \")})`;\n\t\t\tcase \"shiftLeft\":\n\t\t\tcase \"shiftRight\": {\n\t\t\t\tconst shift = value.operator === \"shiftLeft\" ? \"SHL\" : \"SHR\";\n\t\t\t\treturn `TO_${value.type}(${shift}(${operands.join(\", \")}))`;\n\t\t\t}\n\t\t\tcase \"and\":\n\t\t\tcase \"or\":\n\t\t\t\tthrow new Error(\"Boolean short-circuit operation was not normalized\");\n\t\t\tdefault: {\n\t\t\t\tconst text =\n\t\t\t\t\tvalue.operator === \"remainder\"\n\t\t\t\t\t\t? `(${operands[0]} - (${operands[0]} / ${operands[1]}) * ${operands[1]})`\n\t\t\t\t\t\t: `(${operands[0]} ${operatorTokens[value.operator]} ${operands[1]})`;\n\t\t\t\treturn value.type === \"BOOL\" ? text : `TO_${value.type}(${text})`;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate helper(\n\t\tkey: string,\n\t\ttype: string,\n\t\tinputs: readonly [string, string][],\n\t\tbody: (name: string) => string,\n\t\tlocals = \"\",\n\t): string {\n\t\tconst existing = this.helpers.get(key);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\t\tconst name = this.allocate(`numeric_${key}`);\n\t\tthis.helpers.set(key, name);\n\t\tconst parameters = inputs\n\t\t\t.map(([input, inputType]) => ` ${input} : ${inputType};`)\n\t\t\t.join(\"\\n\");\n\t\tconst variables = locals\n\t\t\t? `VAR\n${locals}\nEND_VAR\n`\n\t\t\t: \"\";\n\t\tconst declaration = `FUNCTION ${name} : ${type}\nVAR_INPUT\n${parameters}\nEND_VAR\n${variables}`;\n\t\tthis.objects.push({\n\t\t\tid: `numeric:${key}`,\n\t\t\tkind: \"function\",\n\t\t\tname,\n\t\t\tdeclaration,\n\t\t\timplementation: body(name),\n\t\t});\n\t\treturn name;\n\t}\n\n\t/** Modulo 2^64 addition that does not rely on target integer overflow. */\n\tprivate add64(): string {\n\t\treturn this.helper(\n\t\t\t\"add64\",\n\t\t\t\"LWORD\",\n\t\t\t[\n\t\t\t\t[\"a\", \"LWORD\"],\n\t\t\t\t[\"b\", \"LWORD\"],\n\t\t\t],\n\t\t\t(name) => `x := a;\ny := b;\nFOR i := 1 TO 64 DO\n carry := SHL(x AND y, 1);\n x := x XOR y;\n y := carry;\nEND_FOR;\n${name} := x;\n`,\n\t\t\t` x, y, carry : LWORD;\n i : UINT;`,\n\t\t);\n\t}\n\n\tprivate wrap64(operator: InfixOperator): string {\n\t\tconst add = this.add64();\n\t\tif (operator === \"add\") {\n\t\t\treturn add;\n\t\t}\n\t\tif (operator === \"subtract\") {\n\t\t\treturn this.helper(\n\t\t\t\t\"subtract64\",\n\t\t\t\t\"LWORD\",\n\t\t\t\t[\n\t\t\t\t\t[\"a\", \"LWORD\"],\n\t\t\t\t\t[\"b\", \"LWORD\"],\n\t\t\t\t],\n\t\t\t\t(name) => `${name} := ${add}(a, ${add}(NOT b, LWORD#1));\n`,\n\t\t\t);\n\t\t}\n\t\tif (operator !== \"multiply\") {\n\t\t\tthrow new Error(\"Unsupported verified wrapping operation\");\n\t\t}\n\t\treturn this.helper(\n\t\t\t\"multiply64\",\n\t\t\t\"LWORD\",\n\t\t\t[\n\t\t\t\t[\"a\", \"LWORD\"],\n\t\t\t\t[\"b\", \"LWORD\"],\n\t\t\t],\n\t\t\t(name) => `x := a;\ny := b;\nresult := LWORD#0;\nFOR i := 1 TO 64 DO\n IF (y AND LWORD#1) <> LWORD#0 THEN\n result := ${add}(result, x);\n END_IF;\n x := SHL(x, 1);\n y := SHR(y, 1);\nEND_FOR;\n${name} := result;\n`,\n\t\t\t` x, y, result : LWORD;\n i : UINT;`,\n\t\t);\n\t}\n\n\tprivate arithmetic(\n\t\ttypeId: string,\n\t\toperator: BinaryOperator,\n\t\tpolicy: \"wrap\" | \"saturate\",\n\t): string {\n\t\tconst type = this.types.get(typeId);\n\t\tif (type?.kind !== \"integer\" || !isInfix(operator)) {\n\t\t\tthrow new Error(\"Expected verified integer arithmetic\");\n\t\t}\n\t\tconst token = operatorTokens[operator];\n\t\tconst key = `${policy}_${operator}_${typeId}`;\n\t\tif (policy === \"wrap\") {\n\t\t\tif (type.bits === 64) {\n\t\t\t\tconst operation = this.wrap64(operator);\n\t\t\t\treturn this.helper(\n\t\t\t\t\tkey,\n\t\t\t\t\ttypeId,\n\t\t\t\t\t[\n\t\t\t\t\t\t[\"a\", typeId],\n\t\t\t\t\t\t[\"b\", typeId],\n\t\t\t\t\t],\n\t\t\t\t\t(\n\t\t\t\t\t\tname,\n\t\t\t\t\t) => `${name} := LWORD_TO_${typeId}(${operation}(${typeId}_TO_LWORD(a), ${typeId}_TO_LWORD(b)));\n`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst wide = !type.signed && operator !== \"subtract\" ? \"ULINT\" : \"LINT\";\n\t\t\treturn this.helper(\n\t\t\t\tkey,\n\t\t\t\ttypeId,\n\t\t\t\t[\n\t\t\t\t\t[\"a\", typeId],\n\t\t\t\t\t[\"b\", typeId],\n\t\t\t\t],\n\t\t\t\t(\n\t\t\t\t\tname,\n\t\t\t\t) => `${name} := ${wide}_TO_${typeId}(${typeId}_TO_${wide}(a) ${token} ${typeId}_TO_${wide}(b));\n`,\n\t\t\t);\n\t\t}\n\n\t\tconst [minimum, maximum] = integerRange(type);\n\t\tconst min = `${typeId}#${minimum}`;\n\t\tconst max = `${typeId}#${maximum}`;\n\t\tconst zero = `${typeId}#0`;\n\t\treturn this.helper(\n\t\t\tkey,\n\t\t\ttypeId,\n\t\t\t[\n\t\t\t\t[\"a\", typeId],\n\t\t\t\t[\"b\", typeId],\n\t\t\t],\n\t\t\t(name) => {\n\t\t\t\tconst clamp = (\n\t\t\t\t\tcondition: string,\n\t\t\t\t\tendpoint: string,\n\t\t\t\t\tdepth = \"\",\n\t\t\t\t) => `${depth}IF ${condition} THEN\n${depth} ${name} := ${endpoint};\n${depth} RETURN;\n${depth}END_IF;\n`;\n\t\t\t\tconst guard = (): string => {\n\t\t\t\t\tif (!type.signed) {\n\t\t\t\t\t\t// Unsigned subtraction has only underflow; the other operations have only overflow.\n\t\t\t\t\t\tif (operator === \"add\") {\n\t\t\t\t\t\t\treturn clamp(`a > ${max} - b`, max);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (operator === \"subtract\") {\n\t\t\t\t\t\t\treturn clamp(\"a < b\", zero);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn `IF b <> ${zero} THEN\n${clamp(`a > ${max} / b`, max, \" \")}END_IF;\n`;\n\t\t\t\t\t}\n\t\t\t\t\tif (operator === \"add\") {\n\t\t\t\t\t\treturn `IF b > ${zero} THEN\n${clamp(`a > ${max} - b`, max, \" \")}ELSIF b < ${zero} THEN\n${clamp(`a < ${min} - b`, min, \" \")}END_IF;\n`;\n\t\t\t\t\t}\n\t\t\t\t\tif (operator === \"subtract\") {\n\t\t\t\t\t\treturn `IF b < ${zero} THEN\n${clamp(`a > ${max} + b`, max, \" \")}ELSIF b > ${zero} THEN\n${clamp(`a < ${min} + b`, min, \" \")}END_IF;\n`;\n\t\t\t\t\t}\n\t\t\t\t\t// Handle zero first, then divide the endpoint before multiplying. Each sign\n\t\t\t\t\t// quadrant tests representability without forming an overflowing product.\n\t\t\t\t\treturn (\n\t\t\t\t\t\tclamp(`a = ${zero}`, zero) +\n\t\t\t\t\t\tclamp(`b = ${zero}`, zero) +\n\t\t\t\t\t\t`IF a > ${zero} THEN\n IF b > ${zero} THEN\n${clamp(`a > ${max} / b`, max, \" \")} ELSE\n${clamp(`b < ${min} / a`, min, \" \")} END_IF;\nELSE\n IF b > ${zero} THEN\n${clamp(`a < ${min} / b`, min, \" \")} ELSE\n${clamp(`a < ${max} / b`, max, \" \")} END_IF;\nEND_IF;\n`\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\treturn `${guard()}${name} := a ${token} b;\n`;\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * A float toward zero, as a float. TRUNC returns DINT, so the whole part goes through LINT, which\n\t * holds every float below the size where each float is already whole; those stay as they are.\n\t */\n\tprivate truncation(typeId: string): string {\n\t\tconst type = this.types.get(typeId);\n\t\tif (type?.kind !== \"float\") {\n\t\t\tthrow new Error(\"Expected verified float truncation\");\n\t\t}\n\t\tconst whole = scalarLiteral(\n\t\t\t{ kind: \"float\", value: Number(exactIntegerLimit(type) / 2n) },\n\t\t\ttypeId,\n\t\t);\n\t\treturn this.helper(\n\t\t\t`truncate_${typeId}`,\n\t\t\ttypeId,\n\t\t\t[[\"value\", typeId]],\n\t\t\t(name) => `IF ABS(value) >= ${whole} THEN\n ${name} := value;\n RETURN;\nEND_IF;\nnearest := TO_LINT(value);\nIF value >= 0 AND TO_${typeId}(nearest) > value THEN\n nearest := nearest - 1;\nELSIF value < 0 AND TO_${typeId}(nearest) < value THEN\n nearest := nearest + 1;\nEND_IF;\n${name} := TO_${typeId}(nearest);\n`,\n\t\t\t\" nearest : LINT;\",\n\t\t);\n\t}\n\n\t/**\n\t * A float toward zero, clamped to an integer type. The upper test is against the first float\n\t * past the maximum, a power of two each float type holds, since the maximum itself may round\n\t * up. NaN fails every comparison and so lands on zero, as `saturateFloatToInteger` gives.\n\t */\n\tprivate floatToInteger(\n\t\tsource: Extract<PlcType, { kind: \"float\" }>,\n\t\ttarget: Extract<PlcType, { kind: \"integer\" | \"bits\" }>,\n\t): string {\n\t\tconst [minimum, maximum] = integerRange(target);\n\t\tconst literal = (value: bigint): string =>\n\t\t\tscalarLiteral({ kind: \"float\", value: Number(value) }, source.id);\n\t\tconst truncate = this.truncation(source.id);\n\t\treturn this.helper(\n\t\t\t`saturate_${source.id}_${target.id}`,\n\t\t\ttarget.id,\n\t\t\t[[\"value\", source.id]],\n\t\t\t(\n\t\t\t\tname,\n\t\t\t) => `IF (value > ${literal(minimum)}) AND (value < ${literal(maximum + 1n)}) THEN\n ${name} := TO_${target.id}(${truncate}(value));\nELSIF value >= ${literal(maximum + 1n)} THEN\n ${name} := ${target.id}#${maximum};\nELSIF value <= ${literal(minimum)} THEN\n ${name} := ${target.id}#${minimum};\nELSE\n ${name} := ${target.id}#0;\nEND_IF;\n`,\n\t\t);\n\t}\n\n\tprivate saturation(sourceId: string, targetId: string): string {\n\t\tconst source = this.types.get(sourceId);\n\t\tconst target = this.types.get(targetId);\n\t\tif (source?.kind === \"float\" && target?.kind === \"float\") {\n\t\t\t// Widening cannot exceed the destination's finite range. Identity\n\t\t\t// conversions are removed by normalization; neither needs a helper.\n\t\t\tif (source.bits <= target.bits) {\n\t\t\t\treturn `TO_${targetId}`;\n\t\t\t}\n\t\t\tconst maximum = floatMaximum(target);\n\t\t\tconst literal = (value: number, type: string): string =>\n\t\t\t\tscalarLiteral({ kind: \"float\", value }, type);\n\t\t\treturn this.helper(\n\t\t\t\t`saturate_${sourceId}_${targetId}`,\n\t\t\t\ttargetId,\n\t\t\t\t[[\"value\", sourceId]],\n\t\t\t\t(name) => `IF value < ${literal(-maximum, sourceId)} THEN\n ${name} := ${literal(-maximum, targetId)};\n RETURN;\nEND_IF;\nIF value > ${literal(maximum, sourceId)} THEN\n ${name} := ${literal(maximum, targetId)};\n RETURN;\nEND_IF;\n${name} := TO_${targetId}(value);\n`,\n\t\t\t);\n\t\t}\n\t\tif (source?.kind === \"float\" && target && integerType(target)) {\n\t\t\treturn this.floatToInteger(source, target);\n\t\t}\n\t\tif (!source || !target || !integerType(source) || !integerType(target)) {\n\t\t\tthrow new Error(\"Expected verified integer saturation\");\n\t\t}\n\t\tconst [fromMin, fromMax] = integerRange(source);\n\t\tconst [toMin, toMax] = integerRange(target);\n\t\treturn this.helper(\n\t\t\t`saturate_${sourceId}_${targetId}`,\n\t\t\ttargetId,\n\t\t\t[[\"value\", sourceId]],\n\t\t\t(name) => {\n\t\t\t\tconst below =\n\t\t\t\t\tfromMin < toMin\n\t\t\t\t\t\t? `IF value < ${sourceId}#${toMin} THEN\n ${name} := ${targetId}#${toMin};\n RETURN;\nEND_IF;\n`\n\t\t\t\t\t\t: \"\";\n\t\t\t\tconst above =\n\t\t\t\t\tfromMax > toMax\n\t\t\t\t\t\t? `IF value > ${sourceId}#${toMax} THEN\n ${name} := ${targetId}#${toMax};\n RETURN;\nEND_IF;\n`\n\t\t\t\t\t\t: \"\";\n\t\t\t\treturn `${below}${above}${name} := TO_${targetId}(value);\n`;\n\t\t\t},\n\t\t);\n\t}\n}\n",
13
+ "import {\n\tcoreTables,\n\ttype GeneratedObject,\n\ttype PlcProgram,\n\ttype Task,\n} from \"@tsplc/compiler/ir\";\nimport type { IoChannel } from \"./global-lists\";\nimport type { CodesysPlan } from \"./plan\";\nimport { required } from \"./required\";\nimport { latchScanClock, restoreScanClock, runtimeClock } from \"./scan-clock\";\nimport { noResult } from \"./statements\";\nimport type { EmissionContext } from \"./symbols\";\nimport { accessedStorage } from \"./task-access\";\n\n/** The PROGRAM a task calls for a program: its IO scan around a call of the authored routine. */\nexport function emitScanProgram(\n\t{ plan, symbols, instrumentation }: EmissionContext,\n\tioChannels: readonly IoChannel[],\n\tprogram: PlcProgram,\n): GeneratedObject {\n\tconst { core } = plan;\n\tconst name =\n\t\tplan.programNames.get(program.name) ??\n\t\tsymbols.names.allocateObject(\"PRG\", program.name);\n\tconst used = accessedStorage(\n\t\tcoreTables(core).functionOf(program.entry),\n\t\tcore,\n\t);\n\tconst channels = ioChannels.filter((channel) => used.has(channel.root));\n\tconst stateful = symbols.programRoutines.has(program.entry);\n\tconst call = `${required(symbols.functionNames.get(program.entry))}();`;\n\t// A task's first program starts its cycle: it reads the scan's clock before anything else runs,\n\t// then a task with a ring runs its sender, which counts the scan.\n\tconst task = plan.deployment.tasks.find(\n\t\t(item) => item.programs[0] === program.name,\n\t);\n\tconst ring = task && instrumentation.rings.get(task.name);\n\tconst clock = task && instrumentation.scanClocks.get(task.name);\n\t// The scan snapshots physical inputs before the authored routine and commits outputs\n\t// afterwards. RETURN in an authored routine cannot skip that epilogue.\n\tconst lines = [\n\t\t...(task && symbols.scanClock\n\t\t\t? latchScanClock(symbols.scanClock, task.name)\n\t\t\t: []),\n\t\t...(ring ? [`${instrumentation.global}.${ring}();`] : []),\n\t\t...(clock\n\t\t\t? [\n\t\t\t\t\t`${instrumentation.global}.${clock} := ${symbols.scanClock?.now ?? runtimeClock};`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t...channels\n\t\t\t.filter((channel) => channel.input)\n\t\t\t.map(\n\t\t\t\t({ target, wire, inverted }) =>\n\t\t\t\t\t`${target} := ${inverted ? \"NOT \" : \"\"}${wire};`,\n\t\t\t),\n\t\tstateful ? call : `plc_discard := ${call}`,\n\t\t...channels\n\t\t\t.filter((channel) => !channel.input)\n\t\t\t.map(({ target, wire }) => `${wire} := ${target};`),\n\t];\n\treturn {\n\t\tid: program.id,\n\t\tkind: \"program\",\n\t\tname,\n\t\tdeclaration: stateful\n\t\t\t? `PROGRAM ${name}\\n`\n\t\t\t: `PROGRAM ${name}\\nVAR\\n plc_discard : ${noResult.type};\\nEND_VAR\\n`,\n\t\timplementation: `${lines.join(\"\\n\")}\\n`,\n\t};\n}\n\n/**\n * How a task's program list splits: the programs its configuration names, which it calls itself,\n * and the ones the compiler adds (detached continuations, background jobs), which it calls through\n * one wrapper. A task's configuration then depends on the project's configuration alone, so adding\n * a continuation or a background job at an existing interval changes code, which an online change\n * applies, never the task configuration, which it refuses.\n */\nexport const taskPrograms = (plan: CodesysPlan, task: Task) => {\n\tconst programs = new Map(\n\t\tplan.core.programs.map((program) => [program.name, program]),\n\t);\n\tconst generated = (name: string) => {\n\t\tconst program = programs.get(name);\n\t\treturn Boolean(program?.continuation || program?.background);\n\t};\n\tconst background = task.programs.every(\n\t\t(name) => programs.get(name)?.background,\n\t);\n\treturn {\n\t\tconfigured: task.programs.filter((name) => !generated(name)),\n\t\twrapped: task.programs.filter(generated),\n\t\twrapper: {\n\t\t\tid: `tsplc:task:${task.name}`,\n\t\t\tlabel: background ? task.name : `TsplcContinuations_${task.name}`,\n\t\t},\n\t};\n};\n\n/**\n * Each task's wrapper PROGRAM, which calls the programs the compiler added to it in their order.\n * It is the last program of the task's cycle, so it ends the scan's clock.\n */\nexport function emitTaskWrappers(\n\t{ plan, symbols }: EmissionContext,\n\tobjects: readonly GeneratedObject[],\n): GeneratedObject[] {\n\tconst programObjects = new Map(\n\t\tplan.core.programs.map((program) => [\n\t\t\tprogram.name,\n\t\t\trequired(\n\t\t\t\tobjects.find(\n\t\t\t\t\t(object) => object.id === program.id && object.kind === \"program\",\n\t\t\t\t),\n\t\t\t),\n\t\t]),\n\t);\n\treturn plan.deployment.tasks.map((task) => {\n\t\tconst { wrapped, wrapper } = taskPrograms(plan, task);\n\t\tconst name = symbols.names.allocateObject(\"PRG\", wrapper.label);\n\t\tconst calls = [\n\t\t\t...wrapped.map(\n\t\t\t\t(program) => `${required(programObjects.get(program)).name}();`,\n\t\t\t),\n\t\t\t...(symbols.scanClock\n\t\t\t\t? restoreScanClock(symbols.scanClock, task.name)\n\t\t\t\t: []),\n\t\t];\n\t\treturn {\n\t\t\tid: wrapper.id,\n\t\t\tkind: \"program\",\n\t\t\tname,\n\t\t\tdeclaration: `PROGRAM ${name}\\n`,\n\t\t\timplementation: calls.length ? `${calls.join(\"\\n\")}\\n` : \";\\n\",\n\t\t};\n\t});\n}\n",
14
+ "import type {\n\tCoreExpression,\n\tCoreStatement,\n\tGeneratedObject,\n\tTask,\n\tVerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport {\n\tnestedBodies,\n\tstatementExpressions,\n\tsubexpressions,\n} from \"@tsplc/compiler/ir\";\nimport { scanClockType } from \"@tsplc/debug/manifest\";\nimport { Names } from \"./names\";\n\n/** Milliseconds since the runtime started; DINT wraps after 24.8 days, so subtract to compare. */\nexport const runtimeClock = `TO_${scanClockType}(TIME_TO_UDINT(TIME()))`;\n\n/** The scan's clock of a program that calls `now()`: where a scan's time is held while the scan runs. */\nexport interface ScanClock {\n\t/** The global list that holds the clock. */\n\tlist: string;\n\t/** The time the running scan began, which every `now()` reads. */\n\tnow: string;\n\t/**\n\t * By task, where its scan keeps the clock of the scan it interrupted. A program with one task\n\t * has none.\n\t */\n\tinterrupted: ReadonlyMap<string, string>;\n}\n\nconst readsClock = (value: CoreExpression): boolean =>\n\t(value.kind === \"unary\" && value.operator === \"clock\") ||\n\tsubexpressions(value).some(readsClock);\n\nconst anyReadsClock = (items: readonly CoreStatement[]): boolean =>\n\titems.some(\n\t\t(item) =>\n\t\t\tstatementExpressions(item).some(readsClock) ||\n\t\t\tnestedBodies(item).some(anyReadsClock),\n\t);\n\n/** The scan clock's names, for a program in which some routine calls `now()`. */\nexport function planScanClock(\n\tcore: VerifiedCoreModule,\n\ttasks: readonly Task[],\n\tobjectNames: Names,\n): ScanClock | undefined {\n\tif (\n\t\t![...core.functions, ...core.blocks].some((routine) =>\n\t\t\tanyReadsClock(routine.body),\n\t\t)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst list = objectNames.allocateObject(\"GVL\", \"TsplcScan\");\n\tconst fields = new Names();\n\tconst now = fields.allocate(\"clock\");\n\treturn {\n\t\tlist,\n\t\tnow: `${list}.${now}`,\n\t\tinterrupted: new Map(\n\t\t\ttasks.length > 1\n\t\t\t\t? tasks.map((task) => [\n\t\t\t\t\t\ttask.name,\n\t\t\t\t\t\t`${list}.${fields.allocate(`interrupted_${task.name}`)}`,\n\t\t\t\t\t])\n\t\t\t\t: [],\n\t\t),\n\t};\n}\n\nconst field = (qualified: string) =>\n\tqualified.slice(qualified.indexOf(\".\") + 1);\n\nexport const emitScanClock = (clock: ScanClock): GeneratedObject => ({\n\tid: \"tsplc:scanClock\",\n\tkind: \"globalList\",\n\tname: clock.list,\n\tdeclaration: `{attribute 'qualified_only'}\nVAR_GLOBAL\n${[clock.now, ...clock.interrupted.values()].map((name) => ` ${field(name)} : ${scanClockType};\\n`).join(\"\")}END_VAR\n`,\n});\n\n/**\n * What a task's cycle starts with: it reads the runtime's clock once, so every `now()` of the scan\n * returns one time. A task that interrupts another's scan runs to its end before that scan\n * resumes, so it keeps the interrupted scan's time for `restoreScanClock` to put back.\n */\nexport const latchScanClock = (clock: ScanClock, task: string): string[] => {\n\tconst interrupted = clock.interrupted.get(task);\n\treturn [\n\t\t...(interrupted ? [`${interrupted} := ${clock.now};`] : []),\n\t\t`${clock.now} := ${runtimeClock};`,\n\t];\n};\n\n/** What a task's cycle ends with when it may have interrupted another task's scan. */\nexport const restoreScanClock = (clock: ScanClock, task: string): string[] => {\n\tconst interrupted = clock.interrupted.get(task);\n\treturn interrupted ? [`${clock.now} := ${interrupted};`] : [];\n};\n",
15
+ "import {\n\ttype Constant,\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\tcoreTables,\n\tdefaultValue,\n\ttype SourceSpan,\n} from \"@tsplc/compiler/ir\";\nimport { instrumentationFields } from \"@tsplc/debug/manifest\";\nimport {\n\texpressionText,\n\tplaceText,\n\ttype StorageScope,\n\tstorageName,\n} from \"./expressions\";\nimport {\n\ttype BlockInstrumentation,\n\tjobField,\n\ttype RoutineProbes,\n\tringTarget,\n\twriteProbes,\n} from \"./instrumentation\";\nimport { writeLoop } from \"./loops\";\nimport type { Names } from \"./names\";\nimport { required } from \"./required\";\nimport type { EmissionContext } from \"./symbols\";\nimport { callParameters } from \"./telemetry\";\n\n/** What a function without a result returns: a CODESYS function returns a value, which its callers discard. */\nexport const noResult = { type: \"BOOL\", value: \"TRUE\" } as const;\n\n/** A routine being written: its lines, the names its ST uses, and what its statements read. */\nexport interface RoutineWriter {\n\tcontext: EmissionContext;\n\tfn: CoreFunction | CoreFunctionBlock;\n\t/** The routine's object name, which a function also assigns its result to. */\n\tname: string;\n\t/** The routine itself when it is a block. */\n\tblock: CoreFunctionBlock | undefined;\n\towner: CoreFunctionBlock | undefined;\n\tmethod: boolean;\n\tprogram: boolean;\n\tstorage: StorageScope;\n\tprobes: RoutineProbes;\n\t/** The routine's own scope, which names the variables its lowering adds. */\n\tlocals: Names;\n\t/** A mailbox method's lock. */\n\tmutex: string | undefined;\n\ttracked: BlockInstrumentation | undefined;\n\t/** Appends an implementation line, mapped to `source` when given. */\n\twrite: (line: string, depth: number, source?: SourceSpan) => void;\n\t/** Declares a temporary variable the lowering adds, mapped to `span`. */\n\tdeclare: (declaration: string, span: SourceSpan) => void;\n}\n\n/**\n * Takes the routine's mailbox lock, or returns a default result when another caller holds it.\n * ARM64 implements __COMPARE_AND_SWAP with load-linked/store-conditional, which can fail even when\n * the word holds the expected value, so the swap is retried while the lock reads free.\n */\nexport const writeAcquire = ({\n\tcontext,\n\tfn,\n\tname,\n\tlocals,\n\tmutex,\n\twrite,\n\tdeclare,\n}: RoutineWriter) => {\n\tconst { targetTypes, typeMap } = context.symbols;\n\tconst lock = required(mutex);\n\tconst acquired = locals.allocate(\"plc_acquired\");\n\tdeclare(` ${acquired} : BOOL;`, fn.span);\n\twrite(`${acquired} := FALSE;`, 0);\n\twrite(`WHILE NOT ${acquired} AND ${lock} = 0 DO`, 0);\n\twrite(`${acquired} := __COMPARE_AND_SWAP(ADR(${lock}), 0, 1);`, 1);\n\twrite(\"END_WHILE;\", 0);\n\twrite(`IF NOT ${acquired} THEN`, 0);\n\tif (fn.result) {\n\t\tconst unavailable = locals.allocate(\"plc_unavailable\");\n\t\tdeclare(\n\t\t\t` ${unavailable} : ${targetTypes.name(fn.result)} := ${targetTypes.literal(defaultValue(fn.result, typeMap), fn.result)};`,\n\t\t\tfn.span,\n\t\t);\n\t\twrite(`${name} := ${unavailable};`, 1);\n\t}\n\twrite(\"RETURN;\", 1);\n\twrite(\"END_IF;\", 0);\n};\n\n/** Releases the routine's mailbox lock. Only the holder releases, so a failed swap is spurious, as in the acquire; retry it. */\nexport const writeRelease = (\n\t{ mutex, write }: RoutineWriter,\n\tdepth: number,\n\tsource?: SourceSpan,\n) => {\n\tconst lock = required(mutex);\n\twrite(`WHILE NOT __COMPARE_AND_SWAP(ADR(${lock}), 1, 0) DO`, depth, source);\n\twrite(\";\", depth + 1);\n\twrite(\"END_WHILE;\", depth);\n};\n\n/** Assigns a constant; ST allows aggregate literals only in declarations, so aggregates go leaf by leaf. */\nconst assignConstant = (\n\troutine: RoutineWriter,\n\tdestination: string,\n\tvalue: Constant,\n\tid: string,\n\tdepth: number,\n\tspan: SourceSpan,\n): void => {\n\tconst { typeMap, targetTypes } = routine.context.symbols;\n\tconst type = required(typeMap.get(id));\n\tif (type.kind === \"record\" && value.kind === \"record\") {\n\t\ttype.fields.forEach((field) => {\n\t\t\tassignConstant(\n\t\t\t\troutine,\n\t\t\t\t`${destination}.${targetTypes.field(id, field.name)}`,\n\t\t\t\trequired(value.fields[field.name]),\n\t\t\t\tfield.type,\n\t\t\t\tdepth,\n\t\t\t\tspan,\n\t\t\t);\n\t\t});\n\t} else if (type.kind === \"array\" && value.kind === \"array\") {\n\t\tvalue.items.forEach((item, index) => {\n\t\t\tassignConstant(\n\t\t\t\troutine,\n\t\t\t\t`${destination}[${type.lowerBound + index}]`,\n\t\t\t\titem,\n\t\t\t\ttype.element,\n\t\t\t\tdepth,\n\t\t\t\tspan,\n\t\t\t);\n\t\t});\n\t} else {\n\t\troutine.write(\n\t\t\t`${destination} := ${targetTypes.literal(value, id)};`,\n\t\t\tdepth,\n\t\t\tspan,\n\t\t);\n\t}\n};\n\nconst assign = (\n\troutine: RoutineWriter,\n\tdestination: string,\n\tvalue: CoreExpression,\n\tdepth: number,\n\tspan: SourceSpan,\n): void => {\n\tif (value.kind === \"constant\") {\n\t\tassignConstant(routine, destination, value.value, value.type, depth, span);\n\t} else {\n\t\troutine.write(\n\t\t\t`${destination} := ${expressionText(routine.storage, value)};`,\n\t\t\tdepth,\n\t\t\tspan,\n\t\t);\n\t}\n};\n\n/** A routine's statements as ST, at `depth`. */\nexport function writeStatements(\n\troutine: RoutineWriter,\n\titems: readonly CoreStatement[],\n\tdepth: number,\n): void {\n\tfor (const item of items) {\n\t\twriteStatement(routine, item, depth);\n\t}\n}\n\nfunction writeStatement(\n\troutine: RoutineWriter,\n\titem: CoreStatement,\n\tdepth: number,\n): void {\n\tconst { context, storage, probes, block, tracked, write } = routine;\n\tconst { plan, symbols, instrumentation } = context;\n\tswitch (item.kind) {\n\t\tcase \"assign\":\n\t\t\twriteProbes(probes, write, item, depth);\n\t\t\tif (\n\t\t\t\ttracked?.step &&\n\t\t\t\tblock?.job &&\n\t\t\t\titem.root === block.state.find((field) => field.name === \"step\")?.id\n\t\t\t) {\n\t\t\t\twrite(\n\t\t\t\t\t`${tracked.step} := ${jobField(storage, block, \"step\")};`,\n\t\t\t\t\tdepth,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tassign(\n\t\t\t\troutine,\n\t\t\t\tplaceText(storage, item.root, item.path),\n\t\t\t\titem.value,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t\treturn;\n\t\tcase \"blockUpdate\": {\n\t\t\tconst target = coreTables(plan.core).updatedBlock(item);\n\t\t\tconst arguments_ = Object.entries(item.inputs).map(([input, value]) => {\n\t\t\t\tconst formal = required(\n\t\t\t\t\ttarget.inputs.find((field) => field.name === input),\n\t\t\t\t);\n\t\t\t\treturn `${required(required(symbols.blockFields.get(target.id)).get(formal.id))} := ${expressionText(storage, value)}`;\n\t\t\t});\n\t\t\t// Service calls report the job that made them: a single-instance job passes its own id,\n\t\t\t// and everything between it and the call passes the id it was given.\n\t\t\tconst job = instrumentation.fields.get(target.id)?.job;\n\t\t\tconst id = instrumentation.jobIds.get(item.instance);\n\t\t\tconst given =\n\t\t\t\troutine.owner && instrumentation.fields.get(routine.owner.id)?.job;\n\t\t\tif (job && (id || given)) {\n\t\t\t\targuments_.push(\n\t\t\t\t\t`${job} := ${id ? `${instrumentationFields.job}#${id}` : given}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst receiver = item.index\n\t\t\t\t? `${storageName(storage, item.instance)}[${expressionText(storage, item.index)}]`\n\t\t\t\t: storageName(storage, item.instance);\n\t\t\twrite(`${receiver}(${arguments_.join(\", \")});`, depth, item.span);\n\t\t\treturn;\n\t\t}\n\t\tcase \"invoke\":\n\t\t\twriteInvoke(routine, item, depth);\n\t\t\treturn;\n\t\tcase \"if\":\n\t\t\twrite(\n\t\t\t\t`IF ${expressionText(storage, item.condition)} THEN`,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t\twriteStatements(routine, item.then, depth + 1);\n\t\t\tif (item.else.length) {\n\t\t\t\twrite(\"ELSE\", depth, item.span);\n\t\t\t\twriteStatements(routine, item.else, depth + 1);\n\t\t\t}\n\t\t\twrite(\"END_IF;\", depth, item.span);\n\t\t\treturn;\n\t\tcase \"switch\": {\n\t\t\tfor (const [index, branch] of item.cases.entries()) {\n\t\t\t\tconst conditions = branch.values.map(\n\t\t\t\t\t(value) =>\n\t\t\t\t\t\t`(${expressionText(storage, item.value)} = ${symbols.targetTypes.literal(value, item.value.type)})`,\n\t\t\t\t);\n\t\t\t\twrite(\n\t\t\t\t\t`${index ? \"ELSIF\" : \"IF\"} ${conditions.join(\" OR \")} THEN`,\n\t\t\t\t\tdepth,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t\twriteStatements(routine, branch.body, depth + 1);\n\t\t\t}\n\t\t\tif (!item.cases.length) {\n\t\t\t\twriteStatements(routine, item.fallback, depth);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (item.fallback.length) {\n\t\t\t\twrite(\"ELSE\", depth, item.span);\n\t\t\t}\n\t\t\twriteStatements(routine, item.fallback, depth + 1);\n\t\t\twrite(\"END_IF;\", depth, item.span);\n\t\t\treturn;\n\t\t}\n\t\tcase \"for\":\n\t\t\twriteLoop(routine, item, depth, (body, inner) => {\n\t\t\t\twriteStatements(routine, body, inner);\n\t\t\t});\n\t\t\treturn;\n\t\tcase \"return\":\n\t\t\twriteProbes(probes, write, item, depth);\n\t\t\twriteReturn(routine, item, depth);\n\t\t\tif (routine.mutex) {\n\t\t\t\twriteRelease(routine, depth, item.span);\n\t\t\t}\n\t\t\tif (tracked?.track) {\n\t\t\t\twrite(`${tracked.track}();`, depth);\n\t\t\t}\n\t\t\twrite(\"RETURN;\", depth, item.span);\n\t\t\treturn;\n\t\tcase \"break\":\n\t\t\twrite(\"EXIT;\", depth, item.span);\n\t\t\treturn;\n\t\tcase \"continue\":\n\t\t\twrite(\"CONTINUE;\", depth, item.span);\n\t\t\treturn;\n\t\tcase \"telemetry\": {\n\t\t\tconst site = required(plan.telemetry?.calls.get(item));\n\t\t\tconst arguments_ = callParameters(item).map(\n\t\t\t\t({ name, value }) => `${name} := ${expressionText(storage, value)}`,\n\t\t\t);\n\t\t\twrite(\n\t\t\t\t`${ringTarget(instrumentation, site.task)}.Record${site.id}(${arguments_.join(\", \")});`,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nfunction writeInvoke(\n\troutine: RoutineWriter,\n\titem: Extract<CoreStatement, { kind: \"invoke\" }>,\n\tdepth: number,\n): void {\n\tconst { storage, write } = routine;\n\tconst { plan, symbols } = routine.context;\n\tconst receiver = item.instance\n\t\t? `${storageName(storage, item.instance)}${item.index ? `[${expressionText(storage, item.index)}]` : \"\"}.`\n\t\t: \"\";\n\tconst called = coreTables(plan.core).functionOf(item.function);\n\tconst programCall = symbols.programRoutines.has(called.id);\n\tconst arguments_ = item.arguments.map((value, index) => {\n\t\tif (\n\t\t\t!called.owner &&\n\t\t\t!programCall &&\n\t\t\t!called.parameters.some((parameter) => parameter.mode === \"inOut\")\n\t\t) {\n\t\t\treturn expressionText(storage, value);\n\t\t}\n\t\tconst parameter = required(called.parameters[index]);\n\t\tconst formal = required(\n\t\t\trequired(symbols.routineScopes.get(called.id)).references.get(\n\t\t\t\tparameter.id,\n\t\t\t),\n\t\t);\n\t\treturn `${formal} := ${expressionText(storage, value)}`;\n\t});\n\tconst call = `${receiver}${required(symbols.functionNames.get(item.function))}(${arguments_.join(\", \")})`;\n\tif (programCall) {\n\t\twrite(`${call};`, depth, item.span);\n\t\tif (item.destination) {\n\t\t\twrite(\n\t\t\t\t`${storageName(storage, item.destination)} := ${required(symbols.functionNames.get(called.id))}.${required(symbols.programResults.get(called.id))};`,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\twrite(\n\t\titem.destination\n\t\t\t? `${storageName(storage, item.destination)} := ${call};`\n\t\t\t: `${call};`,\n\t\tdepth,\n\t\titem.span,\n\t);\n}\n\n/** What a `return` hands back: a block's outputs, a stateful program's result, or a function's value. */\nfunction writeReturn(\n\troutine: RoutineWriter,\n\titem: Extract<CoreStatement, { kind: \"return\" }>,\n\tdepth: number,\n): void {\n\tconst { block, storage, write, name, fn } = routine;\n\tconst { symbols } = routine.context;\n\tconst { value } = item;\n\tif (block) {\n\t\tif (value?.kind === \"constant\" && value.value.kind === \"record\") {\n\t\t\tfor (const output of block.outputs) {\n\t\t\t\tassignConstant(\n\t\t\t\t\troutine,\n\t\t\t\t\tstorageName(storage, output.id),\n\t\t\t\t\trequired(value.value.fields[output.name]),\n\t\t\t\t\toutput.type,\n\t\t\t\t\tdepth,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (value) {\n\t\t\tconst returned = expressionText(storage, value);\n\t\t\tfor (const output of block.outputs) {\n\t\t\t\twrite(\n\t\t\t\t\t`${storageName(storage, output.id)} := ${returned}.${symbols.targetTypes.field(required(block.result), output.name)};`,\n\t\t\t\t\tdepth,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\tif (routine.program) {\n\t\tif (value) {\n\t\t\tassign(\n\t\t\t\troutine,\n\t\t\t\trequired(symbols.programResults.get(fn.id)),\n\t\t\t\tvalue,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tif (routine.method && !fn.result) {\n\t\treturn;\n\t}\n\tif (value) {\n\t\tassign(routine, name, value, depth, item.span);\n\t} else {\n\t\twrite(`${name} := ${noResult.value};`, depth, item.span);\n\t}\n}\n",
16
+ "import type { CoreExpression, CorePath, CoreTables } from \"@tsplc/compiler/ir\";\nimport { required } from \"./required\";\nimport type { CodesysSymbols } from \"./symbols\";\n\n/** The storage a routine's ST can name (module storage, IO and its own variables), and each variable's declaration. */\nexport interface StorageScope {\n\tsymbols: CodesysSymbols;\n\tnames: ReadonlyMap<string, string>;\n\tvariableOf: CoreTables[\"variableOf\"];\n}\n\nexport const storageName = ({ names }: StorageScope, id: string): string => {\n\tconst value = names.get(id);\n\tif (!value) {\n\t\tthrow new Error(`Missing verified storage ${id}.`);\n\t}\n\treturn value;\n};\n\nexport const placeText = (\n\tscope: StorageScope,\n\tid: string,\n\tpath: CorePath = [],\n): string => {\n\tconst { typeMap, blocks, blockFields, targetTypes } = scope.symbols;\n\tconst place = (\n\t\ttext: string,\n\t\ttypeId: string,\n\t\t[segment, ...rest]: CorePath,\n\t): string => {\n\t\tif (!segment) {\n\t\t\treturn text;\n\t\t}\n\t\tconst type = required(typeMap.get(typeId));\n\t\t// Block output records are a source abstraction; target FB fields are direct.\n\t\tif (\n\t\t\tsegment.kind === \"field\" &&\n\t\t\ttype.kind === \"block\" &&\n\t\t\tsegment.name === \"out\"\n\t\t) {\n\t\t\tconst [field, ...after] = rest;\n\t\t\tif (!field) {\n\t\t\t\treturn text;\n\t\t\t}\n\t\t\tconst output = required(\n\t\t\t\trequired(blocks.get(type.block)).outputs.find(\n\t\t\t\t\t(item) => field.kind === \"field\" && item.name === field.name,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn place(\n\t\t\t\t`${text}.${required(required(blockFields.get(type.block)).get(output.id))}`,\n\t\t\t\toutput.type,\n\t\t\t\tafter,\n\t\t\t);\n\t\t}\n\t\tif (segment.kind === \"field\" && type.kind === \"record\") {\n\t\t\treturn place(\n\t\t\t\t`${text}.${targetTypes.field(typeId, segment.name)}`,\n\t\t\t\trequired(type.fields.find((field) => field.name === segment.name)).type,\n\t\t\t\trest,\n\t\t\t);\n\t\t}\n\t\tif (segment.kind === \"index\" && type.kind === \"array\") {\n\t\t\t// A strict enum converts explicitly to its DINT base, as HTTP JSON encoding does.\n\t\t\tconst index =\n\t\t\t\ttypeMap.get(segment.value.type)?.kind === \"enum\"\n\t\t\t\t\t? `TO_DINT(${expressionText(scope, segment.value)})`\n\t\t\t\t\t: expressionText(scope, segment.value);\n\t\t\treturn place(`${text}[${index}]`, type.element, rest);\n\t\t}\n\t\tthrow new Error(\"Invalid verified place\");\n\t};\n\treturn place(storageName(scope, id), scope.variableOf(id).type, path);\n};\n\nexport const expressionText = (\n\tscope: StorageScope,\n\tvalue: CoreExpression,\n): string => {\n\tconst { typeMap, targetTypes, numeric } = scope.symbols;\n\tif (value.kind === \"constant\") {\n\t\treturn targetTypes.literal(value.value, value.type);\n\t}\n\tif (value.kind === \"load\") {\n\t\treturn placeText(scope, value.root, value.path);\n\t}\n\tif (value.kind === \"borrow\") {\n\t\treturn placeText(scope, value.place.root, value.place.path);\n\t}\n\tif (value.kind === \"convert\" && typeMap.get(value.type)?.kind === \"string\") {\n\t\treturn expressionText(scope, value.operand);\n\t}\n\tif (value.kind === \"unary\" || value.kind === \"convert\") {\n\t\treturn numeric.render(value, [expressionText(scope, value.operand)]);\n\t}\n\treturn numeric.render(value, [\n\t\texpressionText(scope, value.left),\n\t\texpressionText(scope, value.right),\n\t]);\n};\n",
17
+ "import { createHash } from \"node:crypto\";\nimport {\n\ttype CoreExpression,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\ttype GeneratedObject,\n\tjobError,\n\ttype SourceSpan,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type { ResolvedDebugConfig } from \"@tsplc/config\";\nimport {\n\ttype DebugManifest,\n\ttype jobStateFields,\n\tscanClockType,\n\twriterSlotType,\n} from \"@tsplc/debug/manifest\";\nimport { createPaths, TooManyMatches } from \"@tsplc/debug/paths\";\nimport { elementaryType, integerRange } from \"@tsplc/iec\";\nimport { buildIdLength } from \"@tsplc/server/telemetry\";\nimport type { ServiceChannel } from \"@tsplc/server/wire\";\nimport { isOutputAddress } from \"@tsplc/typegen/hardware\";\nimport {\n\tDebugAnalysis,\n\tinstanceText,\n\ttype Operand,\n\ttype Output,\n\ttypescriptPath,\n} from \"./debug\";\nimport {\n\texpressionText,\n\tplaceText,\n\ttype StorageScope,\n\tstorageName,\n} from \"./expressions\";\nimport { rpcSlots, unsignedWidening } from \"./http\";\nimport {\n\tisStoragePath,\n\tresolveStoragePath,\n\ttype StorageBinding,\n} from \"./io-paths\";\nimport { dataDebugType, ioAddress } from \"./manifest\";\nimport { Names } from \"./names\";\nimport type { CodesysPlan, Report } from \"./plan\";\nimport { required } from \"./required\";\nimport type { EmissionContext, GlobalSymbols } from \"./symbols\";\nimport {\n\tfillBuildId,\n\ttype TelemetryTransport,\n\ttelemetryClient,\n\ttelemetryObjects,\n} from \"./telemetry\";\nimport { stStringLiteral } from \"./types\";\n\n/**\n * The most storage paths `debug.writers.paths` may match. Each is a slot in `GVL_TsplcDebug` and\n * a store on every statement that writes it.\n */\nexport const maxWriterPaths = 256;\n\n/** Module storage as the debugger's paths name it, for expanding `debug.writers.paths`. Blocks are leaves: their fields aren't module storage. */\nconst storagePaths = (core: VerifiedCoreModule) =>\n\tcreatePaths({\n\t\troots: core.variables.flatMap((variable) => {\n\t\t\tconst path =\n\t\t\t\tvariable.storage === \"module\" ? typescriptPath(variable) : undefined;\n\t\t\treturn path\n\t\t\t\t? [{ path, target: \"\", type: variable.type, readable: true }]\n\t\t\t\t: [];\n\t\t}),\n\t\tio: [],\n\t\tconstants: [],\n\t\ttypes: Object.fromEntries(\n\t\t\tcore.types.flatMap((type) =>\n\t\t\t\ttype.kind === \"block\"\n\t\t\t\t\t? []\n\t\t\t\t\t: [[type.id, dataDebugType(type, (_, field) => field)]],\n\t\t\t),\n\t\t),\n\t});\n\n/**\n * The module storage paths `debug.writers.paths` matches. A pattern that names a block's field or\n * anything else that isn't module storage is reported, as is matching more than `maxWriterPaths`.\n */\nexport function writerPaths(\n\tcore: VerifiedCoreModule,\n\tsettings: ResolvedDebugConfig | undefined,\n\treport: Report,\n): StorageBinding[] {\n\tconst writers = settings?.writers;\n\tif (typeof writers !== \"object\") {\n\t\treturn [];\n\t}\n\tconst expanded = (() => {\n\t\ttry {\n\t\t\treturn storagePaths(core).expand(writers.paths, maxWriterPaths);\n\t\t} catch (error) {\n\t\t\tif (error instanceof TooManyMatches) {\n\t\t\t\treport(`debug.writers.paths match more than ${maxWriterPaths} values.`);\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t})();\n\treturn expanded.flatMap((path) => {\n\t\tconst resolved = resolveStoragePath(core, path);\n\t\tif (\"error\" in resolved) {\n\t\t\treport(`debug.writers.paths: ${resolved.error}`);\n\t\t\treturn [];\n\t\t}\n\t\treturn [resolved];\n\t});\n}\n\n/**\n * The debugger's and telemetry's names in the program: `GVL_TsplcDebug` and its fields, each\n * task's ring, and the instrumentation fields of each block, by block id.\n */\nexport type Instrumentation = ReturnType<typeof planInstrumentation> & {\n\tfields: ReadonlyMap<string, BlockInstrumentation>;\n};\n\nexport function planInstrumentation(plan: CodesysPlan, symbols: GlobalSymbols) {\n\tconst { core, options } = plan;\n\tconst settings = plan.project.debug;\n\t// A simulation build binds no fieldbus I/O, but its outputs are still the configured ones.\n\tconst hardware = plan.project.hardware;\n\tconst outputs: Output[] = [\n\t\t...core.variables\n\t\t\t.filter((variable) => variable.storage === \"output\")\n\t\t\t.map((root) => ({ key: root.name, root, segments: [] })),\n\t\t...(hardware\n\t\t\t? Object.entries(hardware.config.io).flatMap(([key, binding]) => {\n\t\t\t\t\tconst address = ioAddress(hardware, binding);\n\t\t\t\t\tif (\n\t\t\t\t\t\t!isStoragePath(key) ||\n\t\t\t\t\t\taddress === undefined ||\n\t\t\t\t\t\t!isOutputAddress(address)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tconst resolved = resolveStoragePath(core, key);\n\t\t\t\t\treturn \"error\" in resolved ? [] : [resolved];\n\t\t\t\t})\n\t\t\t: plan.storageBindings.filter(({ key }) =>\n\t\t\t\t\tisOutputAddress(required(options.io[key]).address),\n\t\t\t\t)),\n\t];\n\tfor (const binding of plan.writerPaths) {\n\t\tif (!outputs.some((output) => output.key === binding.key)) {\n\t\t\toutputs.push(binding);\n\t\t}\n\t}\n\tconst analysis = new DebugAnalysis(core, plan.deployment, settings, outputs);\n\tconst global = symbols.names.allocateObject(\"GVL\", \"TsplcDebug\");\n\tconst names = new Names();\n\tconst slots = {\n\t\tbuildId: names.allocate(\"buildId\"),\n\t\tdecisions: names.allocate(\"decisions\"),\n\t\twriters: names.allocate(\"writers\"),\n\t};\n\t/** Each task's ring and sender in `GVL_TsplcDebug`. */\n\tconst rings = new Map<string, string>();\n\tconst telemetry = plan.telemetry;\n\tif (telemetry) {\n\t\tconst tasks = new Set([\n\t\t\t...[...telemetry.calls.values(), ...telemetry.failures.values()].map(\n\t\t\t\t(site) => site.task,\n\t\t\t),\n\t\t\t...analysis.events.map((site) => site.task),\n\t\t]);\n\t\tfor (const task of plan.deployment.tasks) {\n\t\t\tif (tasks.has(task.name)) {\n\t\t\t\trings.set(task.name, names.allocate(task.name));\n\t\t\t}\n\t\t}\n\t}\n\tconst telemetryNames = rings.size\n\t\t? {\n\t\t\t\twriter: symbols.names.allocateObject(\"FB\", \"TsplcTelemetry\"),\n\t\t\t\trecord: symbols.names.allocateObject(\"ST\", \"TsplcRecord\"),\n\t\t\t\tclient: symbols.names.allocateObject(\n\t\t\t\t\t\"FB\",\n\t\t\t\t\ttelemetry?.endpoint.transport === \"opcua\"\n\t\t\t\t\t\t? \"TsplcTelemetryOpcUa\"\n\t\t\t\t\t\t: \"TsplcTelemetryHttp\",\n\t\t\t\t),\n\t\t\t}\n\t\t: undefined;\n\t/**\n\t * Job instances in manifest order, each with its id and instance text, and the job id each\n\t * single-instance declaration passes to its service calls.\n\t */\n\tconst jobs = core.blocks\n\t\t.filter((block) => block.job)\n\t\t.flatMap((block) =>\n\t\t\trequired(analysis.instances.get(block.id)).map((path) => ({\n\t\t\t\tblock,\n\t\t\t\tpath,\n\t\t\t})),\n\t\t)\n\t\t.map((job, index) => ({\n\t\t\t...job,\n\t\t\tid: index + 1,\n\t\t\tinstance: instanceText(job.path),\n\t\t}));\n\tconst jobIds = new Map<string, number>();\n\tfor (const { path, id } of jobs) {\n\t\tconst declared = required(path.at(-1)).variable;\n\t\tif (analysis.owningPath(declared) === path) {\n\t\t\tjobIds.set(declared.id, id);\n\t\t}\n\t}\n\t/** Raw bytes over each assembly, in `GVL_TsplcDebug`, by device. */\n\tconst devices = new Map<\n\t\tstring,\n\t\tPartial<\n\t\t\tRecord<\n\t\t\t\t\"input\" | \"output\",\n\t\t\t\t{ field: string; address: string; bytes: number }\n\t\t\t>\n\t\t>\n\t>();\n\tif (settings && hardware?.tree) {\n\t\tfor (const device of hardware.catalog.devices) {\n\t\t\tdevices.set(\n\t\t\t\tdevice.id,\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tdevice.assemblies.map((assembly) => [\n\t\t\t\t\t\tassembly.direction,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: names.allocate(`${device.id}_${assembly.direction}s`),\n\t\t\t\t\t\t\taddress: assembly.address,\n\t\t\t\t\t\t\tbytes: assembly.size,\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\t// Without a ring, a task whose writers the debugger follows records the clock itself.\n\tconst scanClocks = new Map<string, string>(\n\t\tplan.writerPaths.length\n\t\t\t? plan.deployment.tasks.flatMap((task) =>\n\t\t\t\t\trings.has(task.name)\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: [[task.name, names.allocate(`scanClock_${task.name}`)]],\n\t\t\t\t)\n\t\t\t: [],\n\t);\n\treturn {\n\t\tanalysis,\n\t\tglobal,\n\t\tslots,\n\t\trings,\n\t\t/** Each task's clock field in `GVL_TsplcDebug`, by task, when it has no ring that reads the clock. */\n\t\tscanClocks,\n\t\ttelemetryNames,\n\t\tjobs,\n\t\tjobIds,\n\t\tdevices,\n\t};\n}\n\n/** Instrumentation fields of a block: its job state and the requesting job's id. */\nexport interface BlockInstrumentation {\n\tbusy?: string;\n\t/** The method that records the job starting and finishing, allocated with `busy`. */\n\ttrack?: string;\n\tstep?: string;\n\tstartedAt?: string;\n\tjob?: string;\n\tsequence?: string;\n}\n\n/** The telemetry sender and its client; over OPC UA also the client's slots and their channels. */\nexport function emitTelemetry(\n\tplan: CodesysPlan,\n\tsymbols: GlobalSymbols,\n\tinstrumentation: Instrumentation,\n\tnetworkName: string | undefined,\n): { objects: GeneratedObject[]; rpcChannels: ServiceChannel[] } {\n\tconst { telemetry } = plan;\n\tconst names = instrumentation.telemetryNames;\n\tif (!telemetry || !names) {\n\t\treturn { objects: [], rpcChannels: [] };\n\t}\n\tconst { endpoint } = telemetry;\n\tconst objects = (transport: TelemetryTransport) =>\n\t\ttelemetryObjects({\n\t\t\tplan: telemetry,\n\t\t\tnames,\n\t\t\ttarget: symbols.targetTypes,\n\t\t\ttransport,\n\t\t\ttypes: symbols.typeMap,\n\t\t});\n\tif (endpoint.transport === \"opcua\") {\n\t\tconst slots = rpcSlots(\n\t\t\tsymbols,\n\t\t\ttelemetryClient,\n\t\t\tnames.client,\n\t\t\tendpoint.path,\n\t\t);\n\t\treturn {\n\t\t\tobjects: [\n\t\t\t\tslots.list,\n\t\t\t\t...objects({\n\t\t\t\t\tkind: \"opcua\",\n\t\t\t\t\ttimeoutMs: endpoint.timeoutMs,\n\t\t\t\t\trpcGlobal: slots.list.name,\n\t\t\t\t}),\n\t\t\t],\n\t\t\trpcChannels: slots.channels,\n\t\t};\n\t}\n\treturn {\n\t\tobjects: objects({\n\t\t\tkind: \"http\",\n\t\t\tendpoint,\n\t\t\tnetwork: `${required(networkName)}.network`,\n\t\t}),\n\t\trpcChannels: [],\n\t};\n}\n\n/**\n * `GVL_TsplcDebug` holds the build id, which identifies this ST and its manifest, so the id is\n * computed over everything else first.\n */\nexport function emitDebugGlobal(\n\tplan: CodesysPlan,\n\tinstrumentation: Instrumentation,\n\tobjects: GeneratedObject[],\n\tmanifest: DebugManifest,\n): DebugManifest {\n\tconst hash = createHash(\"sha256\");\n\tfor (const object of objects) {\n\t\thash.update(\n\t\t\t`${object.name}\\n${object.declaration}\\n${object.implementation ?? \"\"}\\n`,\n\t\t);\n\t}\n\thash.update(JSON.stringify(manifest));\n\tconst id = hash.digest(\"hex\").slice(0, buildIdLength);\n\n\tfillBuildId(objects, id);\n\n\tconst fields = [\n\t\t`${instrumentation.slots.buildId} : STRING(${buildIdLength}) := '${id}'`,\n\t];\n\tfor (const field of instrumentation.scanClocks.values()) {\n\t\tfields.push(`${field} : ${scanClockType}`);\n\t}\n\tfor (const [task, field] of instrumentation.rings) {\n\t\tfields.push(\n\t\t\t`${field} : ${required(instrumentation.telemetryNames).writer} := (task := '${task}')`,\n\t\t);\n\t}\n\tconst settings = plan.project.debug;\n\tif (settings) {\n\t\tif (instrumentation.analysis.decisions.size) {\n\t\t\tfields.push(\n\t\t\t\t`${instrumentation.slots.decisions} : ARRAY[0..${instrumentation.analysis.decisions.size - 1}] OF DINT`,\n\t\t\t);\n\t\t}\n\t\tif (settings.writers && instrumentation.analysis.outputs.length) {\n\t\t\tfields.push(\n\t\t\t\t`${instrumentation.slots.writers} : ARRAY[0..${instrumentation.analysis.outputs.length - 1}] OF ${writerSlotType}`,\n\t\t\t);\n\t\t}\n\t\tfor (const raw of [...instrumentation.devices.values()].flatMap((device) =>\n\t\t\tObject.values(device),\n\t\t)) {\n\t\t\tfields.push(\n\t\t\t\t`${raw.field} AT ${raw.address} : ARRAY[0..${raw.bytes - 1}] OF BYTE`,\n\t\t\t);\n\t\t}\n\t}\n\tobjects.push({\n\t\tid: \"debug\",\n\t\tkind: \"globalList\",\n\t\tname: instrumentation.global,\n\t\t// Nothing in the program reads the build id; linkalways keeps it in the application.\n\t\tdeclaration: `{attribute 'linkalways'}\n{attribute 'qualified_only'}\nVAR_GLOBAL\n${fields.map((field) => ` ${field};\\n`).join(\"\")}END_VAR\n`,\n\t});\n\treturn { ...manifest, build: { ...manifest.build, id } };\n}\n\n/** What a routine's probes read, and the task whose ring they record into unless told otherwise. */\nexport interface RoutineProbes {\n\tcontext: EmissionContext;\n\tstorage: StorageScope;\n\ttask: string | undefined;\n}\n\n/** Appends a line of a routine's implementation, mapped to `source` when given. */\ntype WriteLine = (line: string, depth: number, source?: SourceSpan) => void;\n\nexport const ringTarget = (\n\t{ global, rings }: Instrumentation,\n\ttask: string | undefined,\n) => `${global}.${required(rings.get(required(task)))}`;\n\nconst [dintMinimum, dintMaximum] = integerRange(elementaryType(\"DINT\"));\n\n// Trace operands are DINTs: BOOL as 0/1, enums by value, integers clamped to the DINT range.\nconst traceOperand = (storage: StorageScope, value: CoreExpression): string => {\n\tconst type = required(storage.symbols.typeMap.get(value.type));\n\tconst text = expressionText(storage, value);\n\tif (type.kind === \"bool\") {\n\t\treturn `BOOL_TO_DINT(${text})`;\n\t}\n\tif (type.kind !== \"integer\" && type.kind !== \"bits\") {\n\t\treturn `TO_DINT(${text})`;\n\t}\n\tconst signed = type.kind === \"integer\" && type.signed;\n\tconst [minimum, maximum] = integerRange({ bits: type.bits, signed });\n\tif (minimum >= dintMinimum && maximum <= dintMaximum) {\n\t\treturn `TO_DINT(${text})`;\n\t}\n\tif (signed) {\n\t\treturn `TO_DINT(LIMIT(LINT#${dintMinimum}, ${text}, LINT#${dintMaximum}))`;\n\t}\n\tconst wide = unsignedWidening(type.bits);\n\treturn `TO_DINT(MIN(TO_${wide}(${text}), ${wide}#${dintMaximum}))`;\n};\n\n// CODESYS requires every input, so operands a site lacks are passed as 0.\nconst traceCall = (\n\t{ context, storage, task }: RoutineProbes,\n\tsite: number,\n\tvalue: string,\n\toperands: readonly Operand[],\n): string => {\n\tconst captured = Array.from(\n\t\t{ length: required(context.plan.telemetry?.traceOperands) },\n\t\t(_, index) => {\n\t\t\tconst operand = operands[index];\n\t\t\treturn `, operand${index} := ${operand ? traceOperand(storage, operand.capture) : \"DINT#0\"}`;\n\t\t},\n\t);\n\treturn `${ringTarget(context.instrumentation, task)}.Trace(site := UINT#${site}, value := ${value}, operands := USINT#${operands.length}${captured.join(\"\")});`;\n};\n\n/** The writer and trace probes the debug analysis placed on a statement, written before it. */\nexport function writeProbes(\n\tprobes: RoutineProbes,\n\twrite: WriteLine,\n\titem: CoreStatement,\n\tdepth: number,\n): void {\n\tconst { instrumentation } = probes.context;\n\tconst { storage } = probes;\n\tfor (const probe of instrumentation.analysis.probes.get(item) ?? []) {\n\t\tif (probe.kind === \"writer\") {\n\t\t\tconst writer = `${instrumentation.global}.${instrumentation.slots.writers}[${probe.output}] := UINT#${probe.site};`;\n\t\t\tif (!probe.when.length) {\n\t\t\t\twrite(writer, depth, item.span);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst reached = probe.when.map(\n\t\t\t\t({ index, value }) =>\n\t\t\t\t\t`TO_DINT(${expressionText(storage, index)}) = DINT#${value}`,\n\t\t\t);\n\t\t\twrite(`IF ${reached.join(\" AND \")} THEN`, depth, item.span);\n\t\t\twrite(writer, depth + 1, item.span);\n\t\t\twrite(\"END_IF;\", depth, item.span);\n\t\t\tcontinue;\n\t\t}\n\t\tconst value = `TO_DINT(${expressionText(storage, probe.value)})`;\n\t\tif (item.kind === \"assign\") {\n\t\t\twrite(\n\t\t\t\t`IF ${placeText(storage, item.root, item.path)} <> ${expressionText(storage, probe.value)} THEN`,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t} else {\n\t\t\tconst last = `${instrumentation.global}.${instrumentation.slots.decisions}[${required(probe.slot)}]`;\n\t\t\twrite(`IF ${value} <> ${last} THEN`, depth, item.span);\n\t\t\twrite(`${last} := ${value};`, depth + 1, item.span);\n\t\t}\n\t\twrite(\n\t\t\ttraceCall(probes, probe.site, value, probe.operands),\n\t\t\tdepth + 1,\n\t\t\titem.span,\n\t\t);\n\t\twrite(\"END_IF;\", depth, item.span);\n\t}\n}\n\nexport const jobField = (\n\tstorage: StorageScope,\n\tjob: CoreFunctionBlock,\n\tname: keyof typeof jobStateFields,\n) =>\n\tstorageName(\n\t\tstorage,\n\t\trequired(job.state.find((item) => item.name === name)).id,\n\t);\n\n/**\n * The job's tracking method, which records it starting or finishing. The job calls it on\n * entry and on every exit: its caller stops calling it once it is done, so only the call that\n * finishes it sees the finish.\n */\nexport function jobTracking(\n\tprobes: RoutineProbes,\n\tjob: CoreFunctionBlock,\n\tfields: BlockInstrumentation,\n): string {\n\tconst { plan, instrumentation } = probes.context;\n\tconst busy = jobField(probes.storage, job, \"busy\");\n\tconst sites = instrumentation.analysis.jobSites.get(job.id);\n\tconst failure = plan.telemetry?.failures.get(job.id);\n\tconst lines: string[] = [];\n\tconst line = (text: string, depth: number) =>\n\t\tlines.push(\" \".repeat(depth) + text);\n\tline(`IF ${busy} = ${required(fields.busy)} THEN`, 0);\n\tline(\"RETURN;\", 1);\n\tline(\"END_IF;\", 0);\n\tif (fields.startedAt || sites) {\n\t\tline(`IF ${busy} THEN`, 0);\n\t\tif (fields.startedAt) {\n\t\t\tline(`${fields.startedAt} := TIME_TO_UDINT(TIME());`, 1);\n\t\t}\n\t\tif (sites) {\n\t\t\tline(\n\t\t\t\ttraceCall(\n\t\t\t\t\tprobes,\n\t\t\t\t\tsites.start,\n\t\t\t\t\t`TO_DINT(${jobField(probes.storage, job, \"step\")})`,\n\t\t\t\t\t[],\n\t\t\t\t),\n\t\t\t\t1,\n\t\t\t);\n\t\t}\n\t\tline(\"END_IF;\", 0);\n\t}\n\tif (sites || failure) {\n\t\tconst error = jobField(probes.storage, job, \"error\");\n\t\tline(`IF NOT ${busy} THEN`, 0);\n\t\tif (sites) {\n\t\t\tline(`IF ${error} <> 0 THEN`, 1);\n\t\t\tline(traceCall(probes, sites.completion, `-TO_DINT(${error})`, []), 2);\n\t\t\tline(\"ELSE\", 1);\n\t\t\tline(\n\t\t\t\ttraceCall(\n\t\t\t\t\tprobes,\n\t\t\t\t\tsites.completion,\n\t\t\t\t\t`TO_DINT(${required(fields.step)})`,\n\t\t\t\t\t[],\n\t\t\t\t),\n\t\t\t\t2,\n\t\t\t);\n\t\t\tline(\"END_IF;\", 1);\n\t\t}\n\t\t// Cancellation is asked for, so it isn't a failure.\n\t\tif (failure) {\n\t\t\tline(`IF ${error} <> 0 AND ${error} <> ${jobError.cancelled} THEN`, 1);\n\t\t\tline(\n\t\t\t\t`${ringTarget(instrumentation, failure.task)}.Failure${failure.id}(code := ${error}, step := ${required(fields.step)}${failure.instance === null ? \"\" : `, instance := ${stStringLiteral(failure.instance)}`});`,\n\t\t\t\t2,\n\t\t\t);\n\t\t\tline(\"END_IF;\", 1);\n\t\t}\n\t\tline(\"END_IF;\", 0);\n\t}\n\tline(`${fields.busy} := ${busy};`, 0);\n\treturn `${lines.join(\"\\n\")}\\n`;\n}\n",
18
+ "import {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\ttype CoreTables,\n\tconstantIndex,\n\tcoreTables,\n\ttype Deployment,\n\tdirectWrites,\n\tinstancedBlock,\n\tisBlockRoutine,\n\tisTemporary,\n\tnestedBodies,\n\ttype SourceSpan,\n\ttype Variable,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type { ResolvedDebugConfig } from \"@tsplc/config\";\nimport { neverWrittenSlot } from \"@tsplc/debug/manifest\";\nimport { required } from \"./required\";\nimport { storagePath } from \"./storage\";\nimport { routineTasks } from \"./task-access\";\n\ntype Routine = CoreFunction | CoreFunctionBlock;\n\n/** A guard leaf captured at an event site; `capture` is evaluated at the site. */\nexport interface Operand {\n\tcapture: CoreExpression;\n\tspan: SourceSpan;\n\tpath?: string;\n\tstable: boolean;\n}\n\ntype Probe =\n\t| {\n\t\t\tkind: \"state\" | \"decision\";\n\t\t\tsite: number;\n\t\t\tvalue: CoreExpression;\n\t\t\toperands: readonly Operand[];\n\t\t\t/** A decision's last-value slot. */\n\t\t\tslot?: number;\n\t }\n\t| {\n\t\t\tkind: \"writer\";\n\t\t\tsite: number;\n\t\t\toutput: number;\n\t\t\t/** Dynamic indexes that must equal the output's index for this write to reach it. */\n\t\t\twhen: readonly { index: CoreExpression; value: number }[];\n\t };\n\ninterface EventSite {\n\tid: number;\n\tkind: \"state\" | \"decision\" | \"job\";\n\t/** A job site's block and whether the job starts or finishes there. */\n\tjob?: { block: string; phase: \"started\" | \"finished\" };\n\tpath: string;\n\troutine?: string;\n\ttype: string;\n\tspan: SourceSpan;\n\t/** Defaults to the source text of `span`. */\n\ttext?: string;\n\ttask: string;\n\toperands: readonly Operand[];\n}\n\ninterface WriterSite {\n\tid: number;\n\troutine: string;\n\tspan: SourceSpan;\n\tstatement: CoreStatement;\n}\n\n/** An output the program drives: a logical output, or a storage path bound to a %Q address. */\nexport interface Output {\n\tkey: string;\n\troot: Variable;\n\tsegments: readonly (\n\t\t| { kind: \"field\"; name: string }\n\t\t| { kind: \"index\"; value: number }\n\t)[];\n}\n\n/** One declared block instance, from its module root down: each variable and its array index. */\nexport type InstancePath = readonly { variable: Variable; index?: number }[];\n\ntype Load = CoreExpression & { kind: \"load\" };\n\n/** A call in a loop may run any number of times a scan: counted as two, it is never the only call. */\nconst callsInLoop = 2;\n\n/** The place a statement writes directly: an assignment's, or a call's stored result, written as directly. */\nconst writtenPlace = (\n\titem: CoreStatement,\n): { root: string; path: CorePath } | undefined => {\n\tif (item.kind === \"assign\") {\n\t\treturn { root: item.root, path: item.path ?? [] };\n\t}\n\treturn item.kind === \"invoke\" && item.destination\n\t\t? { root: item.destination, path: [] }\n\t\t: undefined;\n};\n\n/** The root a statement assigns as a whole: a plain assignment's, or a call result's. */\nconst wholeTarget = (item: CoreStatement): string | undefined => {\n\tif (item.kind === \"assign\" && !item.path?.length) {\n\t\treturn item.root;\n\t}\n\treturn item.kind === \"invoke\" ? item.destination : undefined;\n};\n\n/** Every declared instance of each block, from its module root down. */\nexport function blockInstances(\n\tcore: VerifiedCoreModule,\n): Map<string, InstancePath[]> {\n\tconst { types, blockOf } = coreTables(core);\n\tconst instances = new Map<string, InstancePath[]>(\n\t\tcore.blocks.map((block) => [block.id, []]),\n\t);\n\tconst visit = (\n\t\tvariable: Variable,\n\t\tblock: string,\n\t\tpath: InstancePath,\n\t): void => {\n\t\tconst type = types.get(variable.type);\n\t\tconst declared =\n\t\t\ttype?.kind === \"array\"\n\t\t\t\t? Array.from({ length: type.length }, (_, offset) => [\n\t\t\t\t\t\t...path,\n\t\t\t\t\t\t{ variable, index: type.lowerBound + offset },\n\t\t\t\t\t])\n\t\t\t\t: [[...path, { variable }]];\n\t\tfor (const instance of declared) {\n\t\t\trequired(instances.get(block)).push(instance);\n\t\t\tfor (const child of blockOf(block).state) {\n\t\t\t\tconst instanced = instancedBlock(child.type, types);\n\t\t\t\tif (instanced) {\n\t\t\t\t\tvisit(child, instanced.block, instance);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\tfor (const variable of core.variables) {\n\t\tconst instanced = instancedBlock(variable.type, types);\n\t\tif (instanced) {\n\t\t\tvisit(variable, instanced.block, []);\n\t\t}\n\t}\n\treturn instances;\n}\n\n/** The TypeScript path of a module storage place, when every index is constant. */\nexport function typescriptPath(\n\troot: Variable,\n\tpath: CorePath = [],\n): string | undefined {\n\tconst logical = root.storage === \"input\" || root.storage === \"output\";\n\tif (!logical && root.storage !== \"module\" && root.storage !== \"instance\") {\n\t\treturn undefined;\n\t}\n\tconst segments: string[] = [];\n\tfor (const segment of path) {\n\t\tif (segment.kind === \"field\") {\n\t\t\tsegments.push(`.${segment.name}`);\n\t\t\tcontinue;\n\t\t}\n\t\tconst index = constantIndex(segment.value);\n\t\tif (index === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tsegments.push(`[${index}]`);\n\t}\n\treturn `${logical ? root.name : storagePath(root)}${segments.join(\"\")}`;\n}\n\n/** The TypeScript path of a block instance. */\nexport const instanceText = (path: InstancePath): string =>\n\tpath\n\t\t.map(({ variable, index }, position) => {\n\t\t\tconst name =\n\t\t\t\tposition === 0\n\t\t\t\t\t? (typescriptPath(variable) ?? variable.name)\n\t\t\t\t\t: `.${variable.name}`;\n\t\t\treturn index === undefined ? name : `${name}[${index}]`;\n\t\t})\n\t\t.join(\"\");\n\n/**\n * Where the debugger looks: which task runs each routine, every block instance, and the\n * probes each instrumented statement gets. Probes follow `debug`; with no settings there are none.\n */\nexport class DebugAnalysis {\n\treadonly tasks;\n\treadonly instances;\n\treadonly probes = new Map<CoreStatement, Probe[]>();\n\treadonly events: EventSite[] = [];\n\treadonly writers: WriterSite[][];\n\t/**\n\t * Event sites of each job block: its start, with the entry step, and its completion, with the\n\t * last step or the negated error. Steps in between are not recorded: a job that polls would fill the ring.\n\t */\n\treadonly jobSites = new Map<string, { start: number; completion: number }>();\n\t/** Decision slots by routine. */\n\treadonly decisions = new Map<string, number>();\n\t/**\n\t * Call sites per routine, a call in a loop counting as many. A decision has one last-value slot,\n\t * so a function called more than once per scan would flip it on every call and flood the ring.\n\t */\n\tprivate readonly callSites = new Map<string, number>();\n\t/** Blocks that contain a service call, so they carry the requesting job's id down to it. */\n\treadonly carriers = new Set<string>();\n\tprivate readonly tables: CoreTables;\n\tprivate readonly routineWrites = new Map<string, ReadonlySet<string>>();\n\tprivate readonly temporaries = new Map<\n\t\tstring,\n\t\tReadonlyMap<string, readonly CoreStatement[]>\n\t>();\n\t/** The last writer site id given out; the first follows the id of a slot never written. */\n\tprivate writerSites = neverWrittenSlot;\n\n\tconstructor(\n\t\tprivate readonly core: VerifiedCoreModule,\n\t\tdeployment: Deployment,\n\t\tsettings: ResolvedDebugConfig | undefined,\n\t\treadonly outputs: readonly Output[],\n\t) {\n\t\tthis.tables = coreTables(core);\n\t\tthis.writers = outputs.map(() => []);\n\t\tthis.tasks = routineTasks(core, deployment);\n\t\tthis.instances = blockInstances(core);\n\t\tthis.findCarriers();\n\t\tif (!settings) {\n\t\t\treturn;\n\t\t}\n\t\tconst routines = [\n\t\t\t...core.functions,\n\t\t\t...core.blocks.filter((block) => !block.standard),\n\t\t];\n\t\tfor (const routine of routines) {\n\t\t\tthis.countCalls(routine.body, 1);\n\t\t}\n\t\tfor (const routine of routines) {\n\t\t\tthis.walk(settings, routine, routine.body, [], []);\n\t\t}\n\t\tif (settings.trace) {\n\t\t\tfor (const block of core.blocks) {\n\t\t\t\tconst { job } = block;\n\t\t\t\tconst task = this.tasks.get(block.id);\n\t\t\t\tif (!job || !task || this.instances.get(block.id)?.length !== 1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst site = (type: string, phase: \"started\" | \"finished\") =>\n\t\t\t\t\tthis.site({\n\t\t\t\t\t\tkind: \"job\",\n\t\t\t\t\t\tjob: { block: block.id, phase },\n\t\t\t\t\t\tpath: job.name,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tspan: job.span,\n\t\t\t\t\t\ttext: `${job.name}: ${phase}`,\n\t\t\t\t\t\ttask,\n\t\t\t\t\t});\n\t\t\t\tthis.jobSites.set(block.id, {\n\t\t\t\t\tstart: site(\"UINT\", \"started\"),\n\t\t\t\t\tcompletion: site(\"DINT\", \"finished\"),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The instance path of a job declaration, when it declares exactly one instance. */\n\towningPath(variable: Variable): InstancePath | undefined {\n\t\tconst type = this.tables.types.get(variable.type);\n\t\tconst block =\n\t\t\ttype?.kind === \"block\" ? this.tables.blockOf(type.block) : undefined;\n\t\tif (!block?.job) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst paths = required(this.instances.get(block.id)).filter(\n\t\t\t(path) => path.at(-1)?.variable.id === variable.id,\n\t\t);\n\t\treturn paths.length === 1 ? paths[0] : undefined;\n\t}\n\n\tprivate site(\n\t\tsite: Omit<EventSite, \"id\" | \"operands\"> & { operands?: Operand[] },\n\t): number {\n\t\tconst id = this.events.length + 1;\n\t\tthis.events.push({ ...site, id, operands: site.operands ?? [] });\n\t\treturn id;\n\t}\n\n\tprivate findCarriers(): void {\n\t\tconst carries = (id: string): boolean => {\n\t\t\tconst block = this.tables.blockOf(id);\n\t\t\tif (block.runtime?.kind === \"http\") {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn block.state.some((child) => {\n\t\t\t\tconst type = instancedBlock(child.type, this.tables.types);\n\t\t\t\treturn type !== undefined && carries(type.block);\n\t\t\t});\n\t\t};\n\t\tfor (const block of this.core.blocks) {\n\t\t\tif (carries(block.id)) {\n\t\t\t\tthis.carriers.add(block.id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate countCalls(items: readonly CoreStatement[], weight: number): void {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"invoke\") {\n\t\t\t\tthis.callSites.set(\n\t\t\t\t\titem.function,\n\t\t\t\t\t(this.callSites.get(item.function) ?? 0) + weight,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\tthis.countCalls(body, item.kind === \"for\" ? callsInLoop : weight);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Storage a routine can assign, including through every routine it calls. */\n\tprivate writes(routine: Routine): ReadonlySet<string> {\n\t\tconst cached = this.routineWrites.get(routine.id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst result = new Set<string>();\n\t\tthis.routineWrites.set(routine.id, result);\n\t\tfor (const root of this.statementWrites(routine.body)) {\n\t\t\tresult.add(root);\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate statementWrites(items: readonly CoreStatement[]): Set<string> {\n\t\tconst result = new Set<string>();\n\t\tfor (const item of items) {\n\t\t\tfor (const root of directWrites(item)) {\n\t\t\t\tresult.add(root);\n\t\t\t}\n\t\t\tconst called = this.tables.calledRoutineOf(item);\n\t\t\tif (called) {\n\t\t\t\tfor (const root of this.writes(called)) {\n\t\t\t\t\tresult.add(root);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\tfor (const root of this.statementWrites(body)) {\n\t\t\t\t\tresult.add(root);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Visit each statement with the statements that precede it on its path, one list per\n\t * nesting level, and the `if`/`switch` guards enclosing it, innermost last.\n\t */\n\tprivate walk(\n\t\tsettings: ResolvedDebugConfig,\n\t\troutine: Routine,\n\t\titems: readonly CoreStatement[],\n\t\tprefixes: readonly (readonly CoreStatement[])[],\n\t\tguards: readonly { conditions: readonly CoreExpression[]; depth: number }[],\n\t): void {\n\t\tfor (const [index, item] of items.entries()) {\n\t\t\tconst here = [...prefixes, items.slice(0, index)];\n\t\t\tthis.probe(settings, routine, item, here, guards);\n\t\t\tconst guard = (conditions: readonly CoreExpression[]) => [\n\t\t\t\t...guards,\n\t\t\t\t{ conditions, depth: here.length },\n\t\t\t];\n\t\t\tif (item.kind === \"if\") {\n\t\t\t\tthis.walk(settings, routine, item.then, here, guard([item.condition]));\n\t\t\t\tthis.walk(settings, routine, item.else, here, guard([item.condition]));\n\t\t\t}\n\t\t\tif (item.kind === \"switch\") {\n\t\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\t\tthis.walk(settings, routine, body, here, guard([item.value]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (item.kind === \"for\") {\n\t\t\t\tthis.walk(settings, routine, item.body, here, guards);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate probe(\n\t\tsettings: ResolvedDebugConfig,\n\t\troutine: Routine,\n\t\titem: CoreStatement,\n\t\tprefixes: readonly (readonly CoreStatement[])[],\n\t\tguards: readonly { conditions: readonly CoreExpression[]; depth: number }[],\n\t): void {\n\t\tconst task = this.tasks.get(routine.id);\n\t\tconst probes: Probe[] = [];\n\t\tconst written = writtenPlace(item);\n\t\tconst reached =\n\t\t\twritten && settings.writers\n\t\t\t\t? this.outputs.flatMap((output, index) => {\n\t\t\t\t\t\tconst when = this.reaches(written.root, written.path, output);\n\t\t\t\t\t\treturn when ? [{ index, when }] : [];\n\t\t\t\t\t})\n\t\t\t\t: [];\n\t\tif (reached.length) {\n\t\t\tconst site = ++this.writerSites;\n\t\t\tfor (const { index, when } of reached) {\n\t\t\t\trequired(this.writers[index]).push({\n\t\t\t\t\tid: site,\n\t\t\t\t\troutine: routine.id,\n\t\t\t\t\tspan: item.span,\n\t\t\t\t\tstatement: item,\n\t\t\t\t});\n\t\t\t\tprobes.push({ kind: \"writer\", site, output: index, when });\n\t\t\t}\n\t\t}\n\t\tif (settings.trace && task) {\n\t\t\tif (item.kind === \"assign\") {\n\t\t\t\tconst root = this.tables.variableOf(item.root);\n\t\t\t\tconst type = this.tables.placeType(root.type, item.path ?? []);\n\t\t\t\tconst path =\n\t\t\t\t\troot.storage === \"module\"\n\t\t\t\t\t\t? typescriptPath(root, item.path)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (type?.kind === \"enum\" && path) {\n\t\t\t\t\tconst operands = this.operands(\n\t\t\t\t\t\troutine,\n\t\t\t\t\t\tprefixes,\n\t\t\t\t\t\tguards,\n\t\t\t\t\t\tsettings.trace,\n\t\t\t\t\t);\n\t\t\t\t\tconst site = this.site({\n\t\t\t\t\t\tkind: \"state\",\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\troutine: routine.id,\n\t\t\t\t\t\ttype: type.id,\n\t\t\t\t\t\tspan: item.span,\n\t\t\t\t\t\ttask,\n\t\t\t\t\t\toperands,\n\t\t\t\t\t});\n\t\t\t\t\tprobes.push({ kind: \"state\", value: item.value, site, operands });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\titem.kind === \"return\" &&\n\t\t\t\titem.value &&\n\t\t\t\t!isBlockRoutine(routine) &&\n\t\t\t\troutine.result &&\n\t\t\t\tthis.callSites.get(routine.id) === 1\n\t\t\t) {\n\t\t\t\tconst type = this.tables.types.get(routine.result);\n\t\t\t\tif (type?.kind === \"enum\") {\n\t\t\t\t\tconst slot = this.decisions.get(routine.id) ?? this.decisions.size;\n\t\t\t\t\tthis.decisions.set(routine.id, slot);\n\t\t\t\t\tconst path = routine.origin?.instance\n\t\t\t\t\t\t? `${routine.origin.instance}.${routine.origin.name.split(\".\").at(-1)}`\n\t\t\t\t\t\t: (routine.origin?.name ?? routine.name);\n\t\t\t\t\tconst operands = this.operands(\n\t\t\t\t\t\troutine,\n\t\t\t\t\t\tprefixes,\n\t\t\t\t\t\tguards,\n\t\t\t\t\t\tsettings.trace,\n\t\t\t\t\t);\n\t\t\t\t\tconst site = this.site({\n\t\t\t\t\t\tkind: \"decision\",\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\troutine: routine.id,\n\t\t\t\t\t\ttype: type.id,\n\t\t\t\t\t\tspan: item.span,\n\t\t\t\t\t\ttask,\n\t\t\t\t\t\toperands,\n\t\t\t\t\t});\n\t\t\t\t\tprobes.push({\n\t\t\t\t\t\tkind: \"decision\",\n\t\t\t\t\t\tvalue: item.value,\n\t\t\t\t\t\tsite,\n\t\t\t\t\t\tslot,\n\t\t\t\t\t\toperands,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (probes.length) {\n\t\t\tthis.probes.set(item, probes);\n\t\t}\n\t}\n\n\t/** Undefined when the write can't reach the output; otherwise the dynamic indexes it depends on. */\n\tprivate reaches(root: string, path: CorePath, output: Output) {\n\t\tif (root !== output.root.id) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst when: { index: CoreExpression; value: number }[] = [];\n\t\tfor (const [index, written] of path.entries()) {\n\t\t\tconst bound = output.segments[index];\n\t\t\tif (!bound) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (written.kind === \"field\") {\n\t\t\t\tif (bound.kind !== \"field\" || bound.name !== written.name) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (bound.kind !== \"index\") {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst value = constantIndex(written.value);\n\t\t\tif (value === undefined) {\n\t\t\t\twhen.push({ index: written.value, value: bound.value });\n\t\t\t} else if (value !== bound.value) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t\treturn when;\n\t}\n\n\tprivate isTemporary(routine: Routine, root: string): boolean {\n\t\treturn isTemporary(routine.id, this.tables.variableOf(root));\n\t}\n\n\t/** The statements that assign each temporary of a routine. */\n\tprivate definitions(\n\t\troutine: Routine,\n\t): ReadonlyMap<string, readonly CoreStatement[]> {\n\t\tconst cached = this.temporaries.get(routine.id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst definitions = new Map<string, CoreStatement[]>();\n\t\tconst define = (items: readonly CoreStatement[]): void => {\n\t\t\tfor (const item of items) {\n\t\t\t\tconst target = wholeTarget(item);\n\t\t\t\tif (target && this.isTemporary(routine, target)) {\n\t\t\t\t\tdefinitions.set(target, [...(definitions.get(target) ?? []), item]);\n\t\t\t\t}\n\t\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\t\tdefine(body);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tdefine(routine.body);\n\t\tthis.temporaries.set(routine.id, definitions);\n\t\treturn definitions;\n\t}\n\n\t/** The leaves of the enclosing guards, innermost first, as the site can still read them. */\n\tprivate operands(\n\t\troutine: Routine,\n\t\tprefixes: readonly (readonly CoreStatement[])[],\n\t\tguards: readonly { conditions: readonly CoreExpression[]; depth: number }[],\n\t\ttrace: Exclude<ResolvedDebugConfig[\"trace\"], false>,\n\t): Operand[] {\n\t\tconst definitions = this.definitions(routine);\n\t\tconst result: Operand[] = [];\n\t\tconst seen = new Set<string>();\n\t\tfor (const guard of [...guards].reverse()) {\n\t\t\tconst executed = new Set(prefixes.slice(0, guard.depth).flat());\n\t\t\tconst between = this.statementWrites(prefixes.slice(guard.depth).flat());\n\t\t\t/** `read` is the storage the leaf reads; a call result has none. */\n\t\t\tconst add = (\n\t\t\t\tspan: SourceSpan,\n\t\t\t\tcapture: CoreExpression,\n\t\t\t\tread?: Load,\n\t\t\t): void => {\n\t\t\t\tconst kind = this.tables.types.get(capture.type)?.kind;\n\t\t\t\tconst key = `${span.file}:${span.start}:${span.end}`;\n\t\t\t\tif (\n\t\t\t\t\tseen.has(key) ||\n\t\t\t\t\t![\"bool\", \"enum\", \"integer\", \"bits\"].includes(kind ?? \"\")\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tseen.add(key);\n\t\t\t\tconst path =\n\t\t\t\t\tread && typescriptPath(this.tables.variableOf(read.root), read.path);\n\t\t\t\tresult.push({\n\t\t\t\t\tcapture,\n\t\t\t\t\tspan,\n\t\t\t\t\t...(path && { path }),\n\t\t\t\t\tstable: !read || !between.has(read.root),\n\t\t\t\t});\n\t\t\t};\n\t\t\t// A leaf the guard may have skipped is read again at the site, when that has no effects.\n\t\t\tconst direct = (value: Load) =>\n\t\t\t\t(value.path ?? []).every(\n\t\t\t\t\t(segment) =>\n\t\t\t\t\t\tsegment.kind === \"field\" ||\n\t\t\t\t\t\tconstantIndex(segment.value) !== undefined,\n\t\t\t\t);\n\t\t\tconst visit = (value: CoreExpression, evaluated: boolean): void => {\n\t\t\t\tif (value.kind === \"unary\" || value.kind === \"convert\") {\n\t\t\t\t\tvisit(value.operand, evaluated);\n\t\t\t\t}\n\t\t\t\tif (value.kind === \"binary\") {\n\t\t\t\t\tvisit(value.left, evaluated);\n\t\t\t\t\tvisit(value.right, evaluated);\n\t\t\t\t}\n\t\t\t\tif (value.kind !== \"load\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!this.isTemporary(routine, value.root)) {\n\t\t\t\t\tif (evaluated || direct(value)) {\n\t\t\t\t\t\tadd(value.span, value, value);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst defined = definitions.get(value.root) ?? [];\n\t\t\t\tconst [item] = defined;\n\t\t\t\tif (!item || defined.length !== 1) {\n\t\t\t\t\tfor (const definition of defined) {\n\t\t\t\t\t\tif (definition.kind === \"assign\") {\n\t\t\t\t\t\t\tvisit(definition.value, evaluated && executed.has(definition));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst reached = evaluated && executed.has(item);\n\t\t\t\tif (item.kind === \"invoke\") {\n\t\t\t\t\tif (reached) {\n\t\t\t\t\t\tadd(item.span, value);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (item.kind !== \"assign\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst source = item.value;\n\t\t\t\tif (source.kind === \"load\" && !this.isTemporary(routine, source.root)) {\n\t\t\t\t\tconst read = {\n\t\t\t\t\t\t...source,\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tpath: [...(source.path ?? []), ...(value.path ?? [])],\n\t\t\t\t\t};\n\t\t\t\t\tif (reached) {\n\t\t\t\t\t\tadd(source.span, value, read);\n\t\t\t\t\t} else if (direct(read)) {\n\t\t\t\t\t\tadd(source.span, read, read);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvisit(source, reached);\n\t\t\t};\n\t\t\tfor (const condition of guard.conditions) {\n\t\t\t\tvisit(condition, true);\n\t\t\t}\n\t\t}\n\t\treturn result.slice(0, trace.operands);\n\t}\n}\n",
19
+ "import { basename } from \"node:path\";\nimport {\n\tcoreTables,\n\tinstancedBlock,\n\tisLogicalIo,\n\ttype Variable,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\n\n/** Which section of its module's global lists a variable goes in. */\nexport type GlobalStorage = \"constants\" | \"persistent\" | \"retained\" | \"state\";\n\n/** A section of a global list: the variables one `VAR_GLOBAL` qualifier declares. */\ninterface GlobalSection {\n\tstorage: GlobalStorage;\n\tvariables: Variable[];\n}\n\n/**\n * A module's constants, its mutable storage, or its persistent storage. Retained and ordinary state\n * share one list in separate sections, so retaining a variable never changes the path it is\n * published at. Persistent storage has a list of its own: CODESYS keeps everything a persistent\n * list declares through a download, ordinary state included.\n */\ninterface GlobalList {\n\tid: string;\n\tmodule: string;\n\tkind: GlobalListKind;\n\tsections: GlobalSection[];\n\tvariables: Variable[];\n}\n\n/**\n * The module a symbol id names, such as the module that declares a module-level variable. Spans\n * point at what the user wrote, which for elaborated storage is not the module the elaborator\n * made for it.\n */\nexport const moduleFile = (id: string): string => id.split(\":\", 1)[0] ?? id;\n\n/** The module's name: its file name without extension. */\nexport const moduleName = (variable: Variable): string =>\n\tbasename(moduleFile(variable.id)).replace(/\\.[^.]+$/, \"\");\n\n/** A module-level variable as TypeScript names it: `Module.variable`. */\nexport const storagePath = (variable: Variable): string =>\n\t`${moduleName(variable)}.${variable.name}`;\n\n/** The kinds of global list: each holds the sections of one or more `GlobalStorage`. */\nexport type GlobalListKind = Exclude<GlobalStorage, \"retained\">;\n\nconst sectionOrder: readonly GlobalStorage[] = [\n\t\"constants\",\n\t\"state\",\n\t\"retained\",\n\t\"persistent\",\n];\n\nconst globalStorage = (\n\tvariable: Variable,\n\tretainedVariables: ReadonlySet<string>,\n): GlobalStorage => {\n\tif (variable.storage === \"constant\") {\n\t\treturn \"constants\";\n\t}\n\tif (variable.retention === \"persist\") {\n\t\treturn \"persistent\";\n\t}\n\treturn retainedVariables.has(variable.id) ? \"retained\" : \"state\";\n};\n\nconst listKind = (storage: GlobalStorage): GlobalListKind =>\n\tstorage === \"retained\" ? \"state\" : storage;\n\n/** CODESYS promotes an enclosing instance when private child state is retained. */\nexport function storageLayout(core: VerifiedCoreModule) {\n\tconst { types, blockOf } = coreTables(core);\n\tconst retention = new Map<string, boolean>();\n\tconst blockRetained = (id: string): boolean => {\n\t\tconst cached = retention.get(id);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst retained = blockOf(id).state.some((field) => {\n\t\t\tconst type = instancedBlock(field.type, types);\n\t\t\treturn (\n\t\t\t\tfield.retention === \"retain\" ||\n\t\t\t\t(type !== undefined && blockRetained(type.block))\n\t\t\t);\n\t\t});\n\t\tretention.set(id, retained);\n\t\treturn retained;\n\t};\n\n\tconst retainedBlocks = new Set(\n\t\tcore.blocks\n\t\t\t.filter((block) => blockRetained(block.id))\n\t\t\t.map((block) => block.id),\n\t);\n\tconst retainedVariables = new Set(\n\t\t[...core.variables, ...core.blocks.flatMap((block) => block.state)]\n\t\t\t.filter((variable) => {\n\t\t\t\tconst type = instancedBlock(variable.type, types);\n\t\t\t\treturn (\n\t\t\t\t\tvariable.retention === \"retain\" ||\n\t\t\t\t\t(variable.retention === \"none\" &&\n\t\t\t\t\t\ttype !== undefined &&\n\t\t\t\t\t\tretainedBlocks.has(type.block))\n\t\t\t\t);\n\t\t\t})\n\t\t\t.map((variable) => variable.id),\n\t);\n\n\tconst groups = new Map<string, Omit<GlobalList, \"variables\">>();\n\tfor (const variable of core.variables) {\n\t\tif (isLogicalIo(variable)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst storage = globalStorage(variable, retainedVariables);\n\t\tconst kind = listKind(storage);\n\t\tconst id = `${moduleFile(variable.id)}:${kind}`;\n\t\tconst group = groups.get(id) ?? {\n\t\t\tid,\n\t\t\tmodule: moduleName(variable),\n\t\t\tkind,\n\t\t\tsections: [],\n\t\t};\n\t\tgroups.set(id, group);\n\t\tconst section = group.sections.find((item) => item.storage === storage);\n\t\tif (section) {\n\t\t\tsection.variables.push(variable);\n\t\t} else {\n\t\t\tgroup.sections.push({ storage, variables: [variable] });\n\t\t}\n\t}\n\treturn {\n\t\tretainedBlocks,\n\t\tretainedVariables,\n\t\tglobalLists: [...groups.values()].map((group): GlobalList => {\n\t\t\t// Ordinary state comes first, so retaining a variable leaves the others' lines in place.\n\t\t\tconst sections = sectionOrder.flatMap((storage) =>\n\t\t\t\tgroup.sections.filter((section) => section.storage === storage),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...group,\n\t\t\t\tsections,\n\t\t\t\tvariables: sections.flatMap((section) => section.variables),\n\t\t\t};\n\t\t}),\n\t};\n}\n",
20
+ "import type {\n\tCoreExpression,\n\tCoreFunction,\n\tCoreFunctionBlock,\n\tCoreStatement,\n\tDeployment,\n\tPlcProgram,\n\tVerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport {\n\tcoreTables,\n\tnestedBodies,\n\tstatementExpressions,\n\tsubexpressions,\n} from \"@tsplc/compiler/ir\";\nimport type { Report } from \"./plan\";\n\n/** The task that runs each function and block; undefined for one more than one task runs. */\nexport function routineTasks(\n\tcore: VerifiedCoreModule,\n\tdeployment: Deployment,\n): Map<string, string | undefined> {\n\tconst tasks = new Map<string, string | undefined>();\n\tconst { functionOf, calledRoutineOf } = coreTables(core);\n\tconst programs = new Map(core.programs.map((item) => [item.name, item]));\n\tfor (const task of deployment.tasks) {\n\t\tfor (const name of task.programs) {\n\t\t\t// `validateTasks` reports a program the module lacks.\n\t\t\tconst program = programs.get(name);\n\t\t\tif (!program) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst seen = new Set<string>();\n\t\t\tconst visit = (routine: CoreFunction | CoreFunctionBlock): void => {\n\t\t\t\tif (seen.has(routine.id)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tseen.add(routine.id);\n\t\t\t\ttasks.set(\n\t\t\t\t\troutine.id,\n\t\t\t\t\ttasks.has(routine.id) && tasks.get(routine.id) !== task.name\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: task.name,\n\t\t\t\t);\n\t\t\t\tconst inspect = (items: readonly CoreStatement[]): void => {\n\t\t\t\t\tfor (const item of items) {\n\t\t\t\t\t\tconst called = calledRoutineOf(item);\n\t\t\t\t\t\tif (called) {\n\t\t\t\t\t\t\tvisit(called);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\t\t\t\tinspect(body);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tinspect(routine.body);\n\t\t\t};\n\t\t\tvisit(functionOf(program.entry));\n\t\t}\n\t}\n\treturn tasks;\n}\n\n/** The generated worker may enter its host, and only mailbox roots are shared between tasks. */\nexport function taskStorageOwnership(\n\tcore: VerifiedCoreModule,\n\treport: Report,\n): (task: string, program: PlcProgram) => void {\n\tconst owners = new Map<string, string>();\n\tconst globals = new Map(core.variables.map((item) => [item.id, item]));\n\tconst { types, functionOf, blockOf } = coreTables(core);\n\tconst runtimeOf = (type: string) => {\n\t\tconst block = types.get(type);\n\t\treturn block?.kind === \"block\"\n\t\t\t? blockOf(block.block).runtime?.kind\n\t\t\t: undefined;\n\t};\n\n\treturn (task, program) => {\n\t\tconst fn = functionOf(program.entry);\n\t\tconst worker = program.background?.worker;\n\t\tconst host = worker\n\t\t\t? core.variables.find(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\titem.name === worker &&\n\t\t\t\t\t\titem.span.file === fn.span.file &&\n\t\t\t\t\t\truntimeOf(item.type) === \"backgroundHost\",\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tfor (const id of storageAccess(fn, core, host?.id ?? null)) {\n\t\t\tconst item = globals.get(id);\n\t\t\tif (\n\t\t\t\t!item ||\n\t\t\t\titem.storage === \"constant\" ||\n\t\t\t\truntimeOf(item.type) === \"mailbox\"\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst ownsWorker =\n\t\t\t\tworker === item.name && item.span.file === fn.span.file;\n\t\t\tif (program.background && (!ownsWorker || item.id === host?.id)) {\n\t\t\t\treport(\n\t\t\t\t\t`Background task ${program.name} accesses scan-owned storage ${item.name}; pass value snapshots through the mailbox.`,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst owner = owners.get(id);\n\t\t\tif (owner && owner !== task) {\n\t\t\t\treport(\n\t\t\t\t\t`Storage ${item.name} is shared across cyclic tasks ${owner} and ${task}.`,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\towners.set(id, task);\n\t\t}\n\t};\n}\n\n// Follow both helper calls and instance updates. Borrow addresses count as storage\n// access, so scheduling cannot accidentally give one mutable record two owners.\nexport const accessedStorage = (\n\tfn: CoreFunction,\n\tcore: VerifiedCoreModule,\n): Set<string> => storageAccess(fn, core, null);\n\n/**\n * The storage a function reaches, where `scheduledHost` is the background host whose worker call\n * the generated entry makes: only that call may borrow its host. Ordinary calls reached through\n * the async body still count as access to scan-owned storage.\n */\nfunction storageAccess(\n\tfn: CoreFunction,\n\tcore: VerifiedCoreModule,\n\tscheduledHost: string | null,\n): Set<string> {\n\tconst scheduledCall =\n\t\tscheduledHost === null\n\t\t\t? undefined\n\t\t\t: fn.body.find(\n\t\t\t\t\t(item) => item.kind === \"invoke\" && item.instance === scheduledHost,\n\t\t\t\t);\n\tconst result = new Set<string>();\n\tconst seen = new Set<string>();\n\tconst { calledRoutineOf } = coreTables(core);\n\n\tconst expression = (value: CoreExpression): void => {\n\t\tif (value.kind === \"load\") {\n\t\t\tresult.add(value.root);\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\tresult.add(value.place.root);\n\t\t}\n\t\tsubexpressions(value).forEach(expression);\n\t};\n\n\tconst body = (items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"assign\") {\n\t\t\t\tresult.add(item.root);\n\t\t\t}\n\t\t\tif (item.kind === \"invoke\" && item.instance && item !== scheduledCall) {\n\t\t\t\tresult.add(item.instance);\n\t\t\t}\n\t\t\tif (item.kind === \"blockUpdate\") {\n\t\t\t\tresult.add(item.instance);\n\t\t\t}\n\t\t\tstatementExpressions(item).forEach(expression);\n\t\t\tif (item.kind === \"for\") {\n\t\t\t\tresult.add(item.counter);\n\t\t\t}\n\t\t\tif (item.kind === \"invoke\" && item.destination) {\n\t\t\t\tresult.add(item.destination);\n\t\t\t}\n\t\t\tconst called = calledRoutineOf(item);\n\t\t\tif (called && !seen.has(called.id)) {\n\t\t\t\tseen.add(called.id);\n\t\t\t\tbody(called.body);\n\t\t\t}\n\t\t\tnestedBodies(item).forEach(body);\n\t\t}\n\t};\n\n\tseen.add(fn.id);\n\tbody(fn.body);\n\treturn result;\n}\n",
21
+ "import {\n\tcoreTables,\n\tisLogicalIo,\n\ttype PlcType,\n\ttype Variable,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport { arrayTypeText } from \"@tsplc/iec\";\nimport { type IoTarget, ioLayout } from \"@tsplc/typegen/hardware\";\nimport { moduleName, storagePath } from \"./storage\";\n\ntype StorageSegment =\n\t| { kind: \"field\"; record: string; name: string }\n\t| { kind: \"index\"; value: number };\n\n/** An `io` key that names a field of authored module storage, e.g. `PlantIO.Motor.Output.Run`. */\nexport interface StorageBinding {\n\tkey: string;\n\troot: Variable;\n\tsegments: readonly StorageSegment[];\n\ttype: PlcType;\n}\n\nconst pathPattern =\n\t/^([\\w$-]+)\\.([A-Za-z_$][\\w$]*)((?:\\.[A-Za-z_$][\\w$]*|\\[-?\\d+\\])*)$/;\n\nexport const isStoragePath = (key: string): boolean =>\n\tkey.includes(\".\") || key.includes(\"[\");\n\n/** Resolve a storage path against verified types; the error explains the first unresolvable segment. */\nexport function resolveStoragePath(\n\tcore: VerifiedCoreModule,\n\tkey: string,\n): StorageBinding | { error: string } {\n\tconst match = pathPattern.exec(key);\n\tif (!match) {\n\t\treturn {\n\t\t\terror: `${key}: expected Module.variable followed by .field or [index].`,\n\t\t};\n\t}\n\tconst [, module, name, rest = \"\"] = match;\n\tconst roots = core.variables.filter(\n\t\t(item) =>\n\t\t\titem.storage === \"module\" &&\n\t\t\titem.name === name &&\n\t\t\tmoduleName(item) === module,\n\t);\n\tconst [root] = roots;\n\tif (!root || roots.length !== 1) {\n\t\treturn {\n\t\t\terror: root\n\t\t\t\t? `${key}: ${module}.${name} is declared by more than one module named ${module}.`\n\t\t\t\t: `${key}: no mutable module variable ${module}.${name}.`,\n\t\t};\n\t}\n\tconst { typeOf } = coreTables(core);\n\tlet type = typeOf(root.type);\n\tconst segments: StorageSegment[] = [];\n\tfor (const [, field, index] of rest.matchAll(\n\t\t/\\.([A-Za-z_$][\\w$]*)|\\[(-?\\d+)\\]/g,\n\t)) {\n\t\tif (field !== undefined) {\n\t\t\tconst member =\n\t\t\t\ttype.kind === \"record\"\n\t\t\t\t\t? type.fields.find((f) => f.name === field)\n\t\t\t\t\t: undefined;\n\t\t\tif (!member) {\n\t\t\t\treturn { error: `${key}: no field ${field}.` };\n\t\t\t}\n\t\t\tsegments.push({ kind: \"field\", record: type.id, name: field });\n\t\t\ttype = typeOf(member.type);\n\t\t} else {\n\t\t\tconst value = Number(index);\n\t\t\tif (type.kind !== \"array\") {\n\t\t\t\treturn { error: `${key}: ${index} indexes a non-array value.` };\n\t\t\t}\n\t\t\tif (value < type.lowerBound || value >= type.lowerBound + type.length) {\n\t\t\t\treturn {\n\t\t\t\t\terror: `${key}: index ${value} is outside ${type.lowerBound}..${type.lowerBound + type.length - 1}.`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tsegments.push({ kind: \"index\", value });\n\t\t\ttype = typeOf(type.element);\n\t\t}\n\t}\n\treturn { key, root, segments, type };\n}\n\n/** IEC spelling of a bindable type, as typegen spells channels; undefined for records, enums, strings. */\nexport function iecSpelling(\n\ttype: PlcType,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined {\n\tif (\n\t\ttype.kind === \"bool\" ||\n\t\ttype.kind === \"integer\" ||\n\t\ttype.kind === \"bits\" ||\n\t\ttype.kind === \"float\" ||\n\t\ttype.kind === \"duration\" ||\n\t\ttype.kind === \"calendar\"\n\t) {\n\t\treturn type.id;\n\t}\n\tif (type.kind !== \"array\") {\n\t\treturn undefined;\n\t}\n\tconst element = types.get(type.element);\n\tconst spelling = element && iecSpelling(element, types);\n\treturn spelling && element.kind !== \"array\"\n\t\t? arrayTypeText({\n\t\t\t\tlower: type.lowerBound,\n\t\t\t\tupper: type.lowerBound + type.length - 1,\n\t\t\t\telement: spelling,\n\t\t\t})\n\t\t: undefined;\n}\n\n/** Every key an `io` mapping may use: logical IO names and paths into mutable module storage. */\nexport function ioTargets(core: VerifiedCoreModule): IoTarget[] {\n\tconst { types, typeOf } = coreTables(core);\n\tconst targets: IoTarget[] = [];\n\tconst add = (key: string, type: PlcType) => {\n\t\tconst spelling = iecSpelling(type, types);\n\t\tconst layout = spelling && ioLayout(spelling);\n\t\tif (layout) {\n\t\t\ttargets.push({ key, layout });\n\t\t}\n\t};\n\tconst visit = (key: string, type: PlcType): void => {\n\t\tadd(key, type);\n\t\tif (type.kind === \"record\") {\n\t\t\tfor (const field of type.fields) {\n\t\t\t\tvisit(`${key}.${field.name}`, typeOf(field.type));\n\t\t\t}\n\t\t}\n\t\t// Typegen writes keys as template literal types, so any index matches here.\n\t\tif (type.kind === \"array\") {\n\t\t\tvisit(`${key}[\\${number}]`, typeOf(type.element));\n\t\t}\n\t};\n\tfor (const variable of core.variables) {\n\t\tif (isLogicalIo(variable)) {\n\t\t\tadd(variable.name, typeOf(variable.type));\n\t\t} else if (variable.storage === \"module\") {\n\t\t\tvisit(storagePath(variable), typeOf(variable.type));\n\t\t}\n\t}\n\treturn targets;\n}\n",
22
+ "import {\n\ttype Constant,\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\tcoreTables,\n\tinstancedBlock,\n\tinstanceFields,\n\tisBlockRoutine,\n\tjobErrors,\n\tnestedBodies,\n\ttype PlcModule,\n\ttype PlcType,\n\tstandardBlocks,\n\tstatementExpressions,\n\tsubexpressions,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport type { ResolvedTsplcConfig } from \"@tsplc/config\";\nimport { encodeConstant } from \"@tsplc/debug/constant\";\nimport {\n\ttype DebugConstant,\n\ttype DebugDevice,\n\ttype DebugEventSite,\n\ttype DebugFunction,\n\ttype DebugIo,\n\ttype DebugJob,\n\ttype DebugManifest,\n\ttype DebugType,\n\tinstrumentationFields,\n\ttype SourceRange,\n} from \"@tsplc/debug/manifest\";\nimport { nanosecondsPerMillisecond } from \"@tsplc/iec\";\nimport {\n\tdeviceChannel,\n\ttype HardwareCatalog,\n\tisOutputAddress,\n\tisPayloadByte,\n\tmodbusServerName,\n} from \"@tsplc/typegen/hardware\";\nimport { version } from \"../../package.json\";\nimport { type InstancePath, typescriptPath } from \"./debug\";\nimport { ioTarget } from \"./global-lists\";\nimport { serviceName } from \"./http\";\nimport type { Instrumentation } from \"./instrumentation\";\nimport { required } from \"./required\";\nimport type { Sources } from \"./sources\";\nimport type { CodesysSymbols, EmissionContext } from \"./symbols\";\nimport { generated } from \"./telemetry\";\nimport { sourceTypeName, stringTypeName } from \"./types\";\n\n/** The configured hardware a manifest describes; `tree` when this build generates the device tree. */\nexport interface ProjectHardware {\n\tcatalog: HardwareCatalog;\n\tconfig: Pick<ResolvedTsplcConfig, \"devices\" | \"io\">;\n\ttree: boolean;\n}\n\n/**\n * A value type as the debugger reads it, with TypeScript names; `field` gives a record field's name\n * in the target.\n */\nexport function dataDebugType(\n\ttype: Exclude<PlcType, { kind: \"block\" }>,\n\tfield: (record: string, name: string) => string,\n): DebugType {\n\tswitch (type.kind) {\n\t\tcase \"bool\":\n\t\tcase \"integer\":\n\t\tcase \"bits\":\n\t\tcase \"float\":\n\t\tcase \"duration\":\n\t\tcase \"calendar\":\n\t\t\treturn { kind: \"scalar\", iec: type.id };\n\t\tcase \"string\":\n\t\t\treturn {\n\t\t\t\tkind: \"scalar\",\n\t\t\t\tiec: stringTypeName(type),\n\t\t\t\tcapacity: type.capacity,\n\t\t\t};\n\t\tcase \"enum\": {\n\t\t\tconst texts = type.members.flatMap((member) =>\n\t\t\t\tmember.text === undefined ? [] : [[member.name, member.text]],\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"enum\",\n\t\t\t\tname: sourceTypeName(type.id),\n\t\t\t\tmembers: Object.fromEntries(\n\t\t\t\t\ttype.members.map((member) => [member.name, Number(member.value)]),\n\t\t\t\t),\n\t\t\t\t...(texts.length && { texts: Object.fromEntries(texts) }),\n\t\t\t};\n\t\t}\n\t\tcase \"array\":\n\t\t\treturn {\n\t\t\t\tkind: \"array\",\n\t\t\t\telement: type.element,\n\t\t\t\tlength: type.length,\n\t\t\t\tlower: type.lowerBound,\n\t\t\t\t...(type.index && { index: type.index }),\n\t\t\t};\n\t\tcase \"record\":\n\t\t\treturn {\n\t\t\t\tkind: \"record\",\n\t\t\t\tname: sourceTypeName(type.id),\n\t\t\t\tfields: type.fields.map((item) => ({\n\t\t\t\t\tname: item.name,\n\t\t\t\t\ttarget: field(type.id, item.name),\n\t\t\t\t\ttype: item.type,\n\t\t\t\t})),\n\t\t\t};\n\t}\n}\n\n/** A block instance's type: its ports and state, then the fields the compiler adds for the debugger. */\nfunction blockDebugType(\n\t{ symbols, instrumentation }: EmissionContext,\n\tblock: CoreFunctionBlock,\n\tsources: Sources,\n): DebugType {\n\tconst native = block.standard && standardBlocks[block.standard];\n\tconst generated = Boolean(block.job || block.runtime);\n\tconst declaration = sources.range(block.span);\n\tconst fields = required(symbols.blockFields.get(block.id));\n\tconst added = new Map(\n\t\tObject.entries(instrumentation.fields.get(block.id) ?? {}),\n\t);\n\treturn {\n\t\tkind: \"record\",\n\t\tname: block.job?.name ?? block.name,\n\t\t...(declaration && { declaration }),\n\t\tfields: [\n\t\t\t...instanceFields(block).map((variable) => {\n\t\t\t\tconst declaration = !native && sources.range(variable.span);\n\t\t\t\treturn {\n\t\t\t\t\tname: variable.name,\n\t\t\t\t\ttarget: required(fields.get(variable.id)),\n\t\t\t\t\ttype: variable.type,\n\t\t\t\t\t...(declaration && { declaration }),\n\t\t\t\t\t...(generated && { generated: true as const }),\n\t\t\t\t};\n\t\t\t}),\n\t\t\t...Object.entries(instrumentationFields).flatMap(([key, type]) => {\n\t\t\t\tconst name = added.get(key);\n\t\t\t\treturn name\n\t\t\t\t\t? [{ name, target: name, type, generated: true as const }]\n\t\t\t\t\t: [];\n\t\t\t}),\n\t\t],\n\t};\n}\n\n/** A folded constant's JSON value. */\nexport const constantValue = (value: Constant): unknown => {\n\tswitch (value.kind) {\n\t\tcase \"integer\":\n\t\t\treturn encodeConstant({ kind: \"integer\", value: BigInt(value.value) });\n\t\tcase \"duration\":\n\t\t\treturn encodeConstant({\n\t\t\t\tkind: \"duration\",\n\t\t\t\tnanoseconds: BigInt(value.nanoseconds),\n\t\t\t});\n\t\tcase \"array\":\n\t\t\treturn value.items.map(constantValue);\n\t\tcase \"record\":\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries(value.fields).map(([field, item]) => [\n\t\t\t\t\tfield,\n\t\t\t\t\tconstantValue(item),\n\t\t\t\t]),\n\t\t\t);\n\t\tdefault:\n\t\t\treturn value.value;\n\t}\n};\n\n/** For folded values without a declared type, such as strings: named by the IEC type that holds them. */\nconst constantTypes: Record<Constant[\"kind\"], string> = {\n\tbool: \"BOOL\",\n\tinteger: \"LINT\",\n\tfloat: \"LREAL\",\n\tduration: \"TIME\",\n\tcalendar: \"DATE_AND_TIME\",\n\tstring: \"STRING\",\n\tarray: \"ARRAY\",\n\trecord: \"STRUCT\",\n};\n\nconst debugConstants = (\n\tfolded: NonNullable<PlcModule[\"folded\"]>,\n\tsources: Sources,\n): DebugConstant[] =>\n\tfolded.map((item) => {\n\t\tconst declaration = sources.range(item.span);\n\t\treturn {\n\t\t\tpath: item.path,\n\t\t\ttype: item.type ?? constantTypes[item.value.kind],\n\t\t\tvalue: constantValue(item.value),\n\t\t\t...(declaration && { declaration }),\n\t\t};\n\t});\n\n/** The `%I`/`%Q` address a configured binding uses: its own, or its device channel's. */\nexport const ioAddress = (\n\t{ catalog }: ProjectHardware,\n\tbinding: ProjectHardware[\"config\"][\"io\"][string],\n) =>\n\t\"address\" in binding\n\t\t? binding.address\n\t\t: deviceChannel(catalog, binding)?.address;\n\n/**\n * Each configured `io` binding joined with its device channel and the target that holds its\n * value, and each device with its assemblies, named channels and driver state. A generated\n * device tree names each adapter after its device, with a `<device>_Modbus` server for its\n * registers, so the debugger reads their state there.\n */\nfunction debugHardware(\n\tcontext: EmissionContext,\n\thardware: ProjectHardware,\n): { io: DebugIo[]; devices: DebugDevice[] } {\n\tconst { instrumentation } = context;\n\tconst { catalog, config } = hardware;\n\tconst rows = Object.entries(config.io).flatMap(\n\t\t([key, binding]): DebugIo[] => {\n\t\t\tconst held = ioTarget(context, key);\n\t\t\tif (!held) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst address = ioAddress(hardware, binding);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tpath: key,\n\t\t\t\t\t...held,\n\t\t\t\t\tdirection:\n\t\t\t\t\t\taddress !== undefined && isOutputAddress(address)\n\t\t\t\t\t\t\t? \"output\"\n\t\t\t\t\t\t\t: \"input\",\n\t\t\t\t\t...(\"device\" in binding && {\n\t\t\t\t\t\tdevice: binding.device,\n\t\t\t\t\t\tchannel: binding.channel,\n\t\t\t\t\t}),\n\t\t\t\t\t...(address && { address }),\n\t\t\t\t\t...(binding.inverted && { inverted: true as const }),\n\t\t\t\t\t...(binding.shared && { shared: true as const }),\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t);\n\treturn {\n\t\tio: rows,\n\t\tdevices: catalog.devices.map((device) => {\n\t\t\tconst descriptor = catalog.descriptors.find(\n\t\t\t\t(item) => item.file === device.descriptor,\n\t\t\t);\n\t\t\tconst network = config.devices[device.id]?.network;\n\t\t\tconst raw = instrumentation.devices.get(device.id);\n\t\t\tconst status = {\n\t\t\t\t...device.statusSymbols,\n\t\t\t\t...(hardware.tree &&\n\t\t\t\t\tdevice.modbus && {\n\t\t\t\t\t\t\"Modbus error\": `${modbusServerName(device.id)}.xError`,\n\t\t\t\t\t\t\"Modbus error code\": `${modbusServerName(device.id)}.byModbusError`,\n\t\t\t\t\t}),\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tid: device.id,\n\t\t\t\t...(descriptor && {\n\t\t\t\t\tproduct: descriptor.name,\n\t\t\t\t\tvendor: descriptor.vendor,\n\t\t\t\t\tproductCode: descriptor.productCode,\n\t\t\t\t}),\n\t\t\t\t...(network?.address && {\n\t\t\t\t\tnetwork: {\n\t\t\t\t\t\taddress: network.address,\n\t\t\t\t\t\t...(network.rpi && {\n\t\t\t\t\t\t\trpiMs:\n\t\t\t\t\t\t\t\tNumber(network.rpi.nanoseconds) /\n\t\t\t\t\t\t\t\tNumber(nanosecondsPerMillisecond),\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\t...(device.connection && { connection: device.connection.name }),\n\t\t\t\tassemblies: device.assemblies.map((assembly) => {\n\t\t\t\t\tconst field = raw?.[assembly.direction]?.field;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdirection: assembly.direction,\n\t\t\t\t\t\tbytes: assembly.size,\n\t\t\t\t\t\taddress: assembly.address,\n\t\t\t\t\t\t...(field && { raw: `${instrumentation.global}.${field}` }),\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t\t...(hardware.tree && {\n\t\t\t\t\thealth: {\n\t\t\t\t\t\tstate: `${device.id}.eState`,\n\t\t\t\t\t\tdiagnostic: `${device.id}.xDiagnosticAvailable`,\n\t\t\t\t\t\tmessage: `${device.id}.sDiagString`,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\t...(Object.keys(status).length && { status }),\n\t\t\t\t// Byte and bit expansions of an assembly are covered by its raw bytes.\n\t\t\t\tchannels: device.channels\n\t\t\t\t\t.filter((channel) => !channel.parent && !isPayloadByte(channel))\n\t\t\t\t\t.map((channel) => ({\n\t\t\t\t\t\tid: channel.id,\n\t\t\t\t\t\tname: channel.name,\n\t\t\t\t\t\tdirection: channel.direction,\n\t\t\t\t\t\ttype: channel.type,\n\t\t\t\t\t\toffsetBits: channel.offsetBits,\n\t\t\t\t\t\tbits: channel.bits,\n\t\t\t\t\t\t...(channel.address && { address: channel.address }),\n\t\t\t\t\t\t...(channel.unit && { unit: channel.unit }),\n\t\t\t\t\t\t...(channel.description && { description: channel.description }),\n\t\t\t\t\t})),\n\t\t\t};\n\t\t}),\n\t};\n}\n\n/** The IEC path of a block instance. */\nfunction instancePath(symbols: CodesysSymbols, path: InstancePath): string {\n\treturn path\n\t\t.map(({ variable, index }, position) => {\n\t\t\tconst holder = path[position - 1];\n\t\t\tconst name = holder\n\t\t\t\t? `.${required(\n\t\t\t\t\t\trequired(\n\t\t\t\t\t\t\tsymbols.blockFields.get(\n\t\t\t\t\t\t\t\trequired(instancedBlock(holder.variable.type, symbols.typeMap))\n\t\t\t\t\t\t\t\t\t.block,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t).get(variable.id),\n\t\t\t\t\t)}`\n\t\t\t\t: required(symbols.references.get(variable.id));\n\t\t\treturn index === undefined ? name : `${name}[${index}]`;\n\t\t})\n\t\t.join(\"\");\n}\n\n/**\n * The job a service call is made for in debug.json: the id the PLC sends with the call's request,\n * which only a job declared once passes down, so such a job nested in another replaces its caller's.\n */\nconst requestingJob = (\n\t{ jobIds }: Pick<Instrumentation, \"jobIds\">,\n\tdeclaration: string,\n\tcaller: number | undefined,\n): number | undefined => jobIds.get(declaration) ?? caller;\n\n/** The job a service call is made for in explain.json: the innermost job instance whose path holds the call's. */\nexport const enclosingJob = (\n\t{ jobs }: Pick<Instrumentation, \"jobs\">,\n\tinstance: string,\n): number | undefined =>\n\tjobs\n\t\t.filter((job) => instance.startsWith(`${job.instance}.`))\n\t\t.sort((a, b) => b.instance.length - a.instance.length)[0]?.id;\n\n/** Service calls a job instance makes, and those of the jobs it starts. */\nfunction requests(\n\tcontext: EmissionContext,\n\tid: string,\n\tprefix: string,\n\tjob: number | undefined,\n): DebugJob[\"requests\"] {\n\tconst { plan, symbols, instrumentation } = context;\n\tconst block = required(symbols.blocks.get(id));\n\treturn block.state.flatMap((child) => {\n\t\tconst instance = instancedBlock(child.type, symbols.typeMap);\n\t\tif (!instance) {\n\t\t\treturn [];\n\t\t}\n\t\tconst caller = requestingJob(instrumentation, child.id, job);\n\t\tconst type = required(symbols.typeMap.get(child.type));\n\t\tconst field = `${prefix}.${required(required(symbols.blockFields.get(id)).get(child.id))}`;\n\t\tconst targets =\n\t\t\ttype.kind === \"array\"\n\t\t\t\t? Array.from(\n\t\t\t\t\t\t{ length: type.length },\n\t\t\t\t\t\t(_, index) => `${field}[${type.lowerBound + index}]`,\n\t\t\t\t\t)\n\t\t\t\t: [field];\n\t\tconst sequence = instrumentation.fields.get(instance.block)?.sequence;\n\t\tconst path = plan.http[instance.block]?.path;\n\t\treturn targets.flatMap((target) =>\n\t\t\tsequence && path\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tservice: serviceName(path),\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\tsequence: `${target}.${sequence}`,\n\t\t\t\t\t\t\t...(caller !== undefined && { job: caller }),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: requests(context, instance.block, target, caller),\n\t\t);\n\t});\n}\n\n/** Static member reads in a body, by TypeScript path. */\nfunction reads(\n\tvariables: ReadonlyMap<string, Variable>,\n\tbody: readonly CoreStatement[],\n\tsources: Sources,\n): DebugFunction[\"reads\"] {\n\tconst reads = new Map<string, DebugFunction[\"reads\"][number]>();\n\tconst expression = (value: CoreExpression): void => {\n\t\t// A borrow is not a read, and the manifest does not list the indexes of its place either.\n\t\tif (value.kind === \"borrow\") {\n\t\t\treturn;\n\t\t}\n\t\tsubexpressions(value).forEach(expression);\n\t\tif (value.kind !== \"load\") {\n\t\t\treturn;\n\t\t}\n\t\tconst read = typescriptPath(\n\t\t\trequired(variables.get(value.root)),\n\t\t\tvalue.path,\n\t\t);\n\t\tconst range = read && sources.range(value.span);\n\t\tif (range) {\n\t\t\treads.set(`${JSON.stringify(range)}${read}`, { range, path: read });\n\t\t}\n\t};\n\tconst statements = (items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tstatementExpressions(item).forEach(expression);\n\t\t\tnestedBodies(item).forEach(statements);\n\t\t}\n\t};\n\tstatements(body);\n\treturn [...reads.values()];\n}\n\n/** How the debugger names a routine, and where it shows its declaration: a job's own, else the authored function's. */\nexport const routineLabel = (routine: CoreFunction | CoreFunctionBlock) =>\n\tisBlockRoutine(routine)\n\t\t? {\n\t\t\t\tname: routine.job?.name ?? routine.name,\n\t\t\t\tspan: routine.job?.span ?? routine.span,\n\t\t\t}\n\t\t: { name: routine.origin?.name ?? routine.name, span: routine.span };\n\n/** The IEC name of a routine: its function block, a method under its block, or its function or PROGRAM. */\nconst routineTarget = (\n\tsymbols: CodesysSymbols,\n\troutine: CoreFunction | CoreFunctionBlock,\n): string => {\n\tif (isBlockRoutine(routine)) {\n\t\treturn required(symbols.blockNames.get(routine.id));\n\t}\n\tconst name = required(symbols.functionNames.get(routine.id));\n\treturn routine.owner\n\t\t? `${required(symbols.blockNames.get(routine.owner.block))}.${name}`\n\t\t: name;\n};\n\n/**\n * The debugger's view of an emitted program, and the id of each function it lists by routine. Its\n * build id is filled in once the id is known.\n */\nexport function debugManifest(\n\tcontext: EmissionContext,\n\tsources: Sources,\n): { manifest: DebugManifest; functionIds: ReadonlyMap<string, number> } {\n\tconst { plan, symbols, instrumentation } = context;\n\tconst { core, project, deployment, options } = plan;\n\tconst settings = project.debug;\n\tconst global = (field: string) => `${instrumentation.global}.${field}`;\n\n\tconst declaredFunctions = new Map<\n\t\tstring,\n\t\t{ id: number; range: SourceRange }\n\t>();\n\tconst { functions: routines } = coreTables(core);\n\tconst { variables } = coreTables(plan.specialized);\n\tconst functions = [\n\t\t...plan.specialized.functions,\n\t\t...plan.specialized.blocks.filter(\n\t\t\t(block) => !block.standard && !block.runtime,\n\t\t),\n\t].flatMap((routine): DebugFunction[] => {\n\t\tconst label = routineLabel(routine);\n\t\tconst declaration = sources.range(label.span);\n\t\tif (!declaration) {\n\t\t\treturn [];\n\t\t}\n\t\t// An instance whose routine was merged runs as the routine shared with the others. A\n\t\t// routine that only returned a constant was replaced by it, and has nothing to describe.\n\t\tconst runs = isBlockRoutine(routine)\n\t\t\t? symbols.blocks.get(routine.id)\n\t\t\t: routines.get(plan.sharedRoutines.get(routine.id) ?? routine.id);\n\t\tif (!runs) {\n\t\t\treturn [];\n\t\t}\n\t\tconst id = declaredFunctions.size;\n\t\tdeclaredFunctions.set(routine.id, { id, range: declaration });\n\t\tconst task = instrumentation.analysis.tasks.get(runs.id);\n\t\tconst origin = isBlockRoutine(routine) ? undefined : routine.origin;\n\t\treturn [\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tname: label.name,\n\t\t\t\tdeclaration,\n\t\t\t\t...(origin?.instance && { instance: origin.instance }),\n\t\t\t\t...(task && { task }),\n\t\t\t\ttarget: routineTarget(symbols, runs),\n\t\t\t\treads: reads(variables, routine.body, sources),\n\t\t\t},\n\t\t];\n\t});\n\tconst declared = (routine: string | undefined) =>\n\t\troutine === undefined ? undefined : declaredFunctions.get(routine);\n\n\tconst events = instrumentation.analysis.events.flatMap(\n\t\t(site): DebugEventSite[] => {\n\t\t\tconst { job } = site;\n\t\t\tconst owner = declared(site.routine);\n\t\t\tconst range = sources.range(site.span) ?? owner?.range;\n\t\t\tif (!range) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: site.id,\n\t\t\t\t\tkind: site.kind,\n\t\t\t\t\t...(job && {\n\t\t\t\t\t\tjob: required(\n\t\t\t\t\t\t\tinstrumentation.jobs.find(({ block }) => block.id === job.block),\n\t\t\t\t\t\t).id,\n\t\t\t\t\t\tphase: job.phase,\n\t\t\t\t\t}),\n\t\t\t\t\tpath: site.path,\n\t\t\t\t\t...(owner && { function: owner.id }),\n\t\t\t\t\ttype: site.type,\n\t\t\t\t\trange,\n\t\t\t\t\ttext: site.text ?? sources.text(site.span) ?? \"\",\n\t\t\t\t\ttask: site.task,\n\t\t\t\t\toperands: site.operands.map((operand) => ({\n\t\t\t\t\t\ttext: sources.text(operand.span) ?? \"\",\n\t\t\t\t\t\trange: sources.range(operand.span) ?? range,\n\t\t\t\t\t\ttype: operand.capture.type,\n\t\t\t\t\t\t...(operand.path && { path: operand.path }),\n\t\t\t\t\t\tstable: operand.stable,\n\t\t\t\t\t})),\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t);\n\n\tconst jobs = instrumentation.jobs.flatMap(\n\t\t({ block, path, id }): DebugJob[] => {\n\t\t\tconst job = required(block.job);\n\t\t\tconst declaration = sources.range(job.span);\n\t\t\tif (!declaration) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst target = instancePath(symbols, path);\n\t\t\tconst startedAt = instrumentation.fields.get(block.id)?.startedAt;\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid,\n\t\t\t\t\tname: job.name,\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t...(job.instance && { instance: job.instance }),\n\t\t\t\t\ttarget,\n\t\t\t\t\tsteps: job.steps.map((step) => ({\n\t\t\t\t\t\tstep: step.step,\n\t\t\t\t\t\tkind: step.kind,\n\t\t\t\t\t\trange: sources.range(step.span) ?? declaration,\n\t\t\t\t\t\ttext: step.text,\n\t\t\t\t\t})),\n\t\t\t\t\t...(startedAt && { startedAt: `${target}.${startedAt}` }),\n\t\t\t\t\trequests: requests(context, block.id, target, undefined),\n\t\t\t\t\t...(generated(job.name) && { generated: true as const }),\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t);\n\n\tconst writers = settings?.writers\n\t\t? instrumentation.analysis.outputs.map((output, index) => ({\n\t\t\t\toutput: output.key,\n\t\t\t\ttarget: global(`${instrumentation.slots.writers}[${index}]`),\n\t\t\t\tsites: required(instrumentation.analysis.writers[index]).flatMap(\n\t\t\t\t\t(site) => {\n\t\t\t\t\t\tconst owner = declared(site.routine);\n\t\t\t\t\t\treturn owner\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: site.id,\n\t\t\t\t\t\t\t\t\t\trange: sources.range(site.span) ?? owner.range,\n\t\t\t\t\t\t\t\t\t\tfunction: owner.id,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t: [];\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t}))\n\t\t: [];\n\n\tconst roots = core.variables.flatMap((variable) => {\n\t\tconst path = typescriptPath(variable);\n\t\tif (path === undefined) {\n\t\t\treturn [];\n\t\t}\n\t\tconst declaration = sources.range(variable.span);\n\t\treturn [\n\t\t\t{\n\t\t\t\tpath,\n\t\t\t\ttarget: required(symbols.references.get(variable.id)),\n\t\t\t\ttype: variable.type,\n\t\t\t\t...(declaration && { declaration }),\n\t\t\t\treadable: true,\n\t\t\t\t...(generated(variable.name) && { generated: true as const }),\n\t\t\t},\n\t\t];\n\t});\n\n\tconst types = Object.fromEntries(\n\t\tcore.types.map((type): [string, DebugType] => [\n\t\t\ttype.id,\n\t\t\ttype.kind === \"block\"\n\t\t\t\t? blockDebugType(\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\trequired(symbols.blocks.get(type.block)),\n\t\t\t\t\t\tsources,\n\t\t\t\t\t)\n\t\t\t\t: dataDebugType(type, (record, field) =>\n\t\t\t\t\t\tsymbols.targetTypes.field(record, field),\n\t\t\t\t\t),\n\t\t]),\n\t);\n\tconst hardware = debugHardware(\n\t\tcontext,\n\t\tproject.hardware ?? {\n\t\t\tcatalog: { descriptors: [], devices: [] },\n\t\t\tconfig: { devices: {}, io: options.io },\n\t\t\ttree: false,\n\t\t},\n\t);\n\tconst constants = debugConstants(core.folded ?? [], sources);\n\n\tconst manifest: DebugManifest = {\n\t\tkind: \"tsplc-debug\",\n\t\tversion: 1,\n\t\tbuild: {\n\t\t\tid: \"\",\n\t\t\ttarget: global(instrumentation.slots.buildId),\n\t\t\tcompiler: `@tsplc/compiler ${version}`,\n\t\t},\n\t\tsources: sources.files,\n\t\ttypes,\n\t\troots,\n\t\tconstants,\n\t\t...hardware,\n\t\tfunctions,\n\t\tjobs,\n\t\tevents,\n\t\twriters,\n\t\ttasks: deployment.tasks.map((task) => {\n\t\t\t// The task's ring sender reads the clock at the start of its first program.\n\t\t\tconst ring = instrumentation.rings.get(task.name);\n\t\t\tconst clock = ring\n\t\t\t\t? `${ring}.now`\n\t\t\t\t: instrumentation.scanClocks.get(task.name);\n\t\t\treturn {\n\t\t\t\tname: task.name,\n\t\t\t\tintervalMs:\n\t\t\t\t\tNumber(task.intervalNanoseconds) / Number(nanosecondsPerMillisecond),\n\t\t\t\tpriority: task.priority,\n\t\t\t\t...(clock && { clock: global(clock) }),\n\t\t\t};\n\t\t}),\n\t\terrors: jobErrors,\n\t};\n\treturn {\n\t\tmanifest,\n\t\tfunctionIds: new Map(\n\t\t\t[...declaredFunctions].map(([routine, { id }]) => [routine, id]),\n\t\t),\n\t};\n}\n",
23
+ "import {\n\tdefaultValue,\n\ttype GeneratedObject,\n\tinstancedBlock,\n\tisLogicalIo,\n\ttype SourceSpan,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport { isOutputAddress } from \"@tsplc/typegen/hardware\";\nimport {\n\tisStoragePath,\n\tresolveStoragePath,\n\ttype StorageBinding,\n} from \"./io-paths\";\nimport { Names } from \"./names\";\nimport type { CodesysPlan } from \"./plan\";\nimport { required } from \"./required\";\nimport type { ObjectMapping } from \"./st-files\";\nimport type { GlobalStorage } from \"./storage\";\nimport type { EmissionContext, GlobalSymbols } from \"./symbols\";\n\nconst globalSections = {\n\tconstants: \"VAR_GLOBAL CONSTANT\",\n\t// The build makes a list with this section CODESYS's one persistent variable list.\n\tpersistent: \"VAR_GLOBAL PERSISTENT RETAIN\",\n\tretained: \"VAR_GLOBAL RETAIN\",\n\tstate: \"VAR_GLOBAL\",\n} as const satisfies Record<GlobalStorage, string>;\n\n/** Each `io` binding: an AT wire copied to or from its logical target around the scan. */\nexport interface IoChannel {\n\tkey: string;\n\troot: string;\n\tinput: boolean;\n\ttarget: string;\n\twire: string;\n\tinverted?: boolean;\n}\n\n/** A variable a generated device tree maps to its bit or byte channel. */\nexport interface IoMapping {\n\tkey: string;\n\taddress: string;\n\tvariable: string;\n}\n\nconst globalInitializer = (\n\t{ typeMap, targetTypes }: GlobalSymbols,\n\tstorage: GlobalStorage,\n\titem: Variable,\n): string => {\n\tif (instancedBlock(item.type, typeMap)) {\n\t\treturn \"\";\n\t}\n\tconst value = item.initial ?? defaultValue(item.type, typeMap);\n\t// CONSTANT declarations always keep their initializer. Mutable zero\n\t// aggregates use the same implicit initialization as the original ST.\n\treturn storage === \"constants\"\n\t\t? ` := ${targetTypes.literal(value, item.type)}`\n\t\t: targetTypes.declarationInitializer(value, item.type);\n};\n\n/** Whether the build target publishes a variable, which clients may then read and write. */\nexport const isPublished = (\n\tplan: CodesysPlan,\n): ((variable: Variable) => boolean) => {\n\tconst published = new Set(plan.publication[plan.options.buildTarget]);\n\treturn (variable) => published.has(variable.id);\n};\n\n/** A list's declaration lines and the source each declares, in the order it writes them. */\nconst listLines = (object: string, header: readonly string[]) => {\n\tconst lines = [...header];\n\tconst mappings: ObjectMapping[] = [];\n\treturn {\n\t\tlines,\n\t\tmappings,\n\t\t/** Appends a line; one that declares `span` maps back to it. */\n\t\twrite: (line: string, span?: SourceSpan) => {\n\t\t\tlines.push(line);\n\t\t\tif (span) {\n\t\t\t\tmappings.push({\n\t\t\t\t\tobject,\n\t\t\t\t\tfile: \"declaration\",\n\t\t\t\t\tline: lines.length,\n\t\t\t\t\tspan,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n};\n\n/** The global lists of module storage, and the global symbol of each variable they declare. */\nexport function emitGlobalLists(\n\tplan: CodesysPlan,\n\tsymbols: GlobalSymbols,\n): {\n\tobjects: GeneratedObject[];\n\tmappings: ObjectMapping[];\n\treferences: Map<string, string>;\n} {\n\tconst { globals, targetTypes } = symbols;\n\tconst objects: GeneratedObject[] = [];\n\tconst mappings: ObjectMapping[] = [];\n\tconst references = new Map<string, string>();\n\tconst published = isPublished(plan);\n\tfor (const group of globals) {\n\t\tconst { name, fields } = group;\n\t\tconst publish = group.variables.some(published);\n\t\tconst list = listLines(group.id, [\n\t\t\t...(publish ? [\"{attribute 'linkalways'}\"] : []),\n\t\t\t\"{attribute 'qualified_only'}\",\n\t\t]);\n\t\tfor (const section of group.sections) {\n\t\t\tlist.write(globalSections[section.storage]);\n\t\t\tfor (const item of section.variables) {\n\t\t\t\tconst field = required(fields.get(item.id));\n\t\t\t\treferences.set(item.id, `${name}.${field}`);\n\t\t\t\tif (published(item)) {\n\t\t\t\t\tlist.write(\" {attribute 'symbol' := 'readwrite'}\");\n\t\t\t\t}\n\t\t\t\tconst initial = globalInitializer(symbols, section.storage, item);\n\t\t\t\tlist.write(\n\t\t\t\t\t` ${field} : ${targetTypes.name(item.type)}${initial};`,\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlist.write(\"END_VAR\");\n\t\t}\n\t\tobjects.push({\n\t\t\tid: group.id,\n\t\t\tkind: \"globalList\",\n\t\t\tname,\n\t\t\tdeclaration: `${list.lines.join(\"\\n\")}\\n`,\n\t\t});\n\t\tmappings.push(...list.mappings);\n\t}\n\treturn { objects, mappings, references };\n}\n\n/** The id of the I/O list, which no source module places. */\nexport const ioListId = \"io\";\n\n/** `GVL_IO`: logical IO and the AT wires of `io` bindings, and logical IO's global symbols. */\nexport function emitIoList(\n\tplan: CodesysPlan,\n\tsymbols: GlobalSymbols,\n\treferences: ReadonlyMap<string, string>,\n): {\n\tobjects: GeneratedObject[];\n\tmappings: ObjectMapping[];\n\tchannels: IoChannel[];\n\tioMappings: IoMapping[];\n\treferences: Map<string, string>;\n} {\n\tconst { core, options } = plan;\n\tconst { names, targetTypes, typeMap } = symbols;\n\tconst channels: IoChannel[] = [];\n\tconst ioMappings: IoMapping[] = [];\n\tconst ioReferences = new Map<string, string>();\n\tconst ioName = names.allocate(\"GVL_IO\");\n\tconst ioFields = new Names(symbols.blockNames.values());\n\tconst header = [\n\t\t\"{attribute 'linkalways'}\",\n\t\t\"{attribute 'qualified_only'}\",\n\t\t\"VAR_GLOBAL\",\n\t];\n\tconst list = listLines(ioListId, header);\n\tfor (const item of core.variables.filter(isLogicalIo)) {\n\t\tconst field = ioFields.allocate(item.name);\n\t\tconst initial = item.initial ?? defaultValue(item.type, typeMap);\n\t\tconst binding = required(options.io[item.name]);\n\t\tconst declaration = ` ${field} : ${targetTypes.name(item.type)} := ${targetTypes.literal(initial, item.type)};`;\n\t\tioReferences.set(item.id, `${ioName}.${field}`);\n\t\tif (binding.mapped) {\n\t\t\tioMappings.push({\n\t\t\t\tkey: item.name,\n\t\t\t\taddress: binding.address,\n\t\t\t\tvariable: `${ioName}.${field}`,\n\t\t\t});\n\t\t\tlist.write(\" {attribute 'symbol' := 'read'}\");\n\t\t\tlist.write(declaration, item.span);\n\t\t\tcontinue;\n\t\t}\n\t\tconst wire = ioFields.allocate(`${item.name}_physical`);\n\t\tchannels.push({\n\t\t\tkey: item.name,\n\t\t\troot: item.id,\n\t\t\tinput: item.storage === \"input\",\n\t\t\ttarget: `${ioName}.${field}`,\n\t\t\twire: `${ioName}.${wire}`,\n\t\t\tinverted: binding.inverted,\n\t\t});\n\t\tlist.write(\n\t\t\t` ${wire} AT ${binding.address} : ${targetTypes.name(item.type)};`,\n\t\t\titem.span,\n\t\t);\n\t\t// Publish the scan's logical value for monitoring. Physical wires stay\n\t\t// private; external writes cannot alter the controller's IO snapshot.\n\t\tlist.write(\" {attribute 'symbol' := 'read'}\");\n\t\tlist.write(declaration, item.span);\n\t}\n\tfor (const { key, root, segments, type } of plan.storageBindings) {\n\t\tconst { address, mapped, inverted } = required(options.io[key]);\n\t\tconst target = bindingTarget(symbols, references, { root, segments });\n\t\tif (mapped) {\n\t\t\tioMappings.push({ key, address, variable: target });\n\t\t\tcontinue;\n\t\t}\n\t\tconst wire = ioFields.allocate(\n\t\t\t`${key.replace(/\\W+/g, \"_\").replace(/_+$/, \"\")}_physical`,\n\t\t);\n\t\t// The wire takes the target's own type, so equal-width EDS types need no conversion.\n\t\tlist.write(` ${wire} AT ${address} : ${targetTypes.name(type.id)};`);\n\t\tchannels.push({\n\t\t\tkey,\n\t\t\troot: root.id,\n\t\t\tinput: !isOutputAddress(address),\n\t\t\ttarget,\n\t\t\twire: `${ioName}.${wire}`,\n\t\t\tinverted,\n\t\t});\n\t}\n\t// Mapped storage bindings need no IO list; mapped logical IO is declared here.\n\tconst declares = list.lines.length > header.length;\n\tlist.write(\"END_VAR\");\n\treturn {\n\t\tobjects: declares\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: ioListId,\n\t\t\t\t\t\tkind: \"globalList\",\n\t\t\t\t\t\tname: ioName,\n\t\t\t\t\t\tdeclaration: `${list.lines.join(\"\\n\")}\\n`,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [],\n\t\tmappings: list.mappings,\n\t\tchannels,\n\t\tioMappings,\n\t\treferences: ioReferences,\n\t};\n}\n\n/** The target symbol of an `io` storage path. */\nfunction bindingTarget(\n\t{ targetTypes }: GlobalSymbols,\n\treferences: ReadonlyMap<string, string>,\n\t{ root, segments }: Pick<StorageBinding, \"root\" | \"segments\">,\n): string {\n\treturn segments.reduce(\n\t\t(path, segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? `${path}.${targetTypes.field(segment.record, segment.name)}`\n\t\t\t\t: `${path}[${segment.value}]`,\n\t\trequired(references.get(root.id)),\n\t);\n}\n\n/** The target symbol and type that hold an `io` key's value, when this program has it. */\nexport function ioTarget(\n\t{ plan: { core }, symbols }: EmissionContext,\n\tkey: string,\n): { target: string; type: string } | undefined {\n\tconst logical = core.variables.find(\n\t\t(variable) => isLogicalIo(variable) && variable.name === key,\n\t);\n\tif (logical) {\n\t\treturn {\n\t\t\ttarget: required(symbols.references.get(logical.id)),\n\t\t\ttype: logical.type,\n\t\t};\n\t}\n\tif (!isStoragePath(key)) {\n\t\treturn undefined;\n\t}\n\tconst resolved = resolveStoragePath(core, key);\n\treturn \"error\" in resolved\n\t\t? undefined\n\t\t: {\n\t\t\t\ttarget: bindingTarget(symbols, symbols.references, resolved),\n\t\t\t\ttype: resolved.type.id,\n\t\t\t};\n}\n",
24
+ "import {\n\ttype CoreStatement,\n\tcoreTables,\n\ttype Deployment,\n\terrorName,\n\ttype GeneratedObject,\n\thttpErrors,\n\tinstancedBlock,\n\tjobErrors,\n\tnestedBodies,\n\ttype PlcType,\n\ttype SourceSpan,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport {\n\ttype Environment,\n\ttype ResolvedTelemetryConfig,\n\tserverBaseUrl,\n} from \"@tsplc/config\";\nimport { elementaryType } from \"@tsplc/iec\";\nimport {\n\tbuildIdLength,\n\ttaskNameLength,\n\ttelemetryPath,\n} from \"@tsplc/server/telemetry\";\nimport { plcBufferBytes } from \"@tsplc/server/wire\";\nimport type { CodesysOptions } from \"./config\";\nimport { blockInstances, type InstancePath } from \"./debug\";\nimport {\n\ttype HttpEndpoint,\n\ttype NativeEndpoint,\n\tresolveHttpEndpoint,\n\trouteBase,\n} from \"./endpoints\";\nimport {\n\tdecimalLength,\n\thttpCertificateVerifier,\n\thttpClientMethods,\n\tjsonEncoders,\n\tjsonScalar,\n\tnativeHttp,\n\topcuaClient,\n\topcuaClientMethods,\n} from \"./http\";\nimport type { Report } from \"./plan\";\nimport { required } from \"./required\";\nimport { Sources } from \"./sources\";\nimport { routineTasks } from \"./task-access\";\nimport { ringSettings, telemetrySendIntervalMs } from \"./telemetry-settings\";\nimport { type CodesysTypes, stStringLiteral } from \"./types\";\n\n/** The id of the sender's client block. */\nexport const telemetryClient = \"tsplc:telemetry\";\nconst telemetryWriter = \"tsplc:telemetryWriter\";\n/** Stands for the build id in the sender until the id, a hash over everything else, is known. */\nconst buildPlaceholder = \"<build>\";\n\ntype TelemetryStatement = Extract<CoreStatement, { kind: \"telemetry\" }>;\n\n/** A telemetry call: `record` is the JSON its method writes before the properties' values. */\ninterface CallSite {\n\tid: number;\n\ttask: string;\n\trecord: string;\n\tcall: TelemetryStatement;\n}\n\n/**\n * A root job's unhandled failure; its source is that of the step it failed at. Failures that\n * differ only in their instance share a method, which takes `instance` as its JSON member.\n */\ninterface FailureSite {\n\tid: number;\n\ttask: string;\n\trecord: string;\n\t/** The `\"instance\":…,` member this job passes, or null when its function has no instance. */\n\tinstance: string | null;\n\tsources: readonly { source: string; steps: readonly number[] }[];\n}\n\nexport interface TelemetryPlan extends ResolvedTelemetryConfig {\n\t/** Where the senders post their batches. */\n\tendpoint: HttpEndpoint;\n\tcalls: ReadonlyMap<CoreStatement, CallSite>;\n\t/** By job block id. */\n\tfailures: ReadonlyMap<string, FailureSite>;\n\t/** `debug.trace`'s operand count, when the trace is on. */\n\ttraceOperands?: number;\n}\n\n/** A string as JSON text in ASCII, so it can sit in an ST literal. */\nconst asciiJson = (value: string) =>\n\tJSON.stringify(value).replace(\n\t\t/[^ -~]/g,\n\t\t(character) =>\n\t\t\t`\\\\u${character.charCodeAt(0).toString(16).padStart(4, \"0\")}`,\n\t);\n\n/** Compiler-made jobs, such as a service call's own, carry this prefix. */\nexport const generated = (name: string) => name.startsWith(\"tsplc\");\n\nconst maximum = (values: readonly number[]) =>\n\tvalues.reduce((a, b) => Math.max(a, b), 0);\n\nconst digits = {\n\tuint: decimalLength(elementaryType(\"UINT\")),\n\tdint: decimalLength(elementaryType(\"DINT\")),\n\tudint: decimalLength(elementaryType(\"UDINT\")),\n\tulint: decimalLength(elementaryType(\"ULINT\")),\n};\n\n/** The members `Commit` ends every record with, and the writer's UDINT each one prints. */\nconst commitMembers = [\n\t{ member: ',\"scan\":', value: \"scan\" },\n\t{ member: ',\"time\":', value: \"now\" },\n] as const;\nconst commitSize =\n\tcommitMembers.reduce(\n\t\t(total, { member }) => total + member.length + digits.udint,\n\t\t0,\n\t) + \"}\".length;\n\nconst codeMember = ',\"code\":';\nconst nameMember = ',\"name\":';\nconst errorNames = Object.keys(jobErrors).flatMap((code) => {\n\tconst name = errorName(Number(code));\n\treturn name === undefined ? [] : [[code, name] as const];\n});\n/** What an exception record's error code and its name take after its properties. */\nconst codeSize =\n\tcodeMember.length +\n\tdigits.udint +\n\tnameMember.length +\n\tmaximum([\n\t\t...errorNames.map(([, name]) => asciiJson(name).length),\n\t\tasciiJson(`HTTP ${httpErrors.last - httpErrors.base}`).length,\n\t]);\n\nconst nullJson = \"null\";\n\n/** A property's value in a record: the most bytes it takes, and the ST that appends parameter `value`. */\nfunction propertyJson(\n\ttype: PlcType,\n\ttext: boolean,\n): { size: number; encode: (value: string, target: CodesysTypes) => string } {\n\tif (text && type.kind === \"array\") {\n\t\treturn {\n\t\t\tsize: type.length * 6 + 2,\n\t\t\tencode: (value) =>\n\t\t\t\t`WriteText(ADR(${value}), LINT_TO_DINT(LIMIT(0, TO_LINT(${value}Length), ${type.length})));`,\n\t\t};\n\t}\n\tif (type.kind === \"enum\") {\n\t\tconst texts = type.members.map((member) =>\n\t\t\tasciiJson(member.text ?? member.name),\n\t\t);\n\t\treturn {\n\t\t\tsize: maximum([nullJson.length, ...texts.map((item) => item.length)]),\n\t\t\tencode: (value, target) =>\n\t\t\t\t`CASE ${value} OF ${type.members.map((member, index) => `${target.name(type.id)}.${target.field(type.id, member.name)}: Append(${stStringLiteral(required(texts[index]))});`).join(\" \")} ELSE Append('${nullJson}'); END_CASE;`,\n\t\t};\n\t}\n\tif (type.kind === \"float\") {\n\t\treturn {\n\t\t\tsize: type.bits === 32 ? 16 : 25,\n\t\t\tencode: (value) =>\n\t\t\t\t`IF ${value} = ${value} AND ABS(${value}) < ${type.id}#${type.bits === 32 ? \"3.4E38\" : \"1.7E308\"} THEN Append(${type.id}_TO_STRING(${value})); ELSE Append('${nullJson}'); END_IF;`,\n\t\t};\n\t}\n\tconst scalar = jsonScalar(type);\n\tif (!scalar) {\n\t\tthrow new Error(`Unverified telemetry value type ${type.id}.`);\n\t}\n\treturn scalar;\n}\n\n/** A call's record up to its source: its kind and what it names. */\nconst recordHead = (record: TelemetryStatement[\"record\"]): string => {\n\tswitch (record.kind) {\n\t\tcase \"event\":\n\t\t\treturn `{\"kind\":\"event\",\"event\":${asciiJson(record.event)}`;\n\t\tcase \"log\":\n\t\t\treturn `{\"kind\":\"log\",\"level\":\"${record.level}\",\"message\":${asciiJson(record.message)}`;\n\t\tcase \"exception\":\n\t\t\treturn '{\"kind\":\"exception\",\"handled\":true';\n\t}\n};\n\n/** A `debug.trace` record with `operands` operands: the ST of the writer's `Trace`, and the most bytes it takes. */\nconst traceRecord = (operands: number) => {\n\tconst site = '{\"kind\":\"trace\",\"site\":';\n\tconst value = ',\"value\":';\n\tconst list = ',\"operands\":[';\n\treturn {\n\t\timplementation: `${[\n\t\t\t\"payload := '';\",\n\t\t\t`Append(${stStringLiteral(site)});`,\n\t\t\t\"Append(UINT_TO_STRING(site));\",\n\t\t\t`Append(${stStringLiteral(value)});`,\n\t\t\t\"Append(DINT_TO_STRING(value));\",\n\t\t\t`Append(${stStringLiteral(list)});`,\n\t\t\t...Array.from(\n\t\t\t\t{ length: operands },\n\t\t\t\t(_, index) =>\n\t\t\t\t\t`IF operands > ${index} THEN ${index ? \"Append(','); \" : \"\"}Append(DINT_TO_STRING(operand${index})); END_IF;`,\n\t\t\t),\n\t\t\t\"Append(']');\",\n\t\t\t\"Commit();\",\n\t\t].join(\"\\n\")}\\n`,\n\t\tsize:\n\t\t\tsite.length +\n\t\t\tdigits.uint +\n\t\t\tvalue.length +\n\t\t\tdigits.dint +\n\t\t\tlist.length +\n\t\t\toperands * (digits.dint + \",\".length) +\n\t\t\t\"]\".length +\n\t\t\tcommitSize,\n\t};\n};\n\nfunction telemetryCalls(core: VerifiedCoreModule) {\n\tconst routines = [\n\t\t...core.functions,\n\t\t...core.blocks.filter((block) => !block.standard),\n\t];\n\tconst statements: { routine: string; call: TelemetryStatement }[] = [];\n\tconst find = (routine: string, items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"telemetry\") {\n\t\t\t\tstatements.push({ routine, call: item });\n\t\t\t}\n\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\tfind(routine, body);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const routine of routines) {\n\t\tfind(routine.id, routine.body);\n\t}\n\treturn statements;\n}\n\ninterface JobFailure {\n\ttask: string;\n\tfunction: string;\n\tinstance?: string;\n\tspan: SourceSpan;\n\tsources: { source: string; steps: readonly number[] }[];\n\tfallback: string;\n}\n\n/** Root jobs own the unhandled record. Awaiting jobs own their children's errors. */\nfunction planJobFailures(\n\tcore: VerifiedCoreModule,\n\ttasks: ReadonlyMap<string, string | undefined>,\n\tlocation: (span: SourceSpan) => string,\n): ReadonlyMap<string, JobFailure> {\n\tconst { types, blockOf } = coreTables(core);\n\tconst failures = new Map<string, JobFailure>();\n\tconst instances = blockInstances(core);\n\tconst awaited = (path: InstancePath) =>\n\t\tpath.slice(0, -1).some(({ variable }) => {\n\t\t\tconst type = instancedBlock(variable.type, types);\n\t\t\treturn type !== undefined && blockOf(type.block).job !== undefined;\n\t\t});\n\n\tfor (const block of core.blocks) {\n\t\tconst { job } = block;\n\t\tconst task = tasks.get(block.id);\n\t\tconst paths = required(instances.get(block.id));\n\t\tif (!job || !task || !paths.length || paths.some(awaited)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// A generated detached wrapper reports its one authored child by name.\n\t\tconst children = block.state.flatMap((child) => {\n\t\t\tconst type = types.get(child.type);\n\t\t\tconst called =\n\t\t\t\ttype?.kind === \"block\" ? blockOf(type.block).job : undefined;\n\t\t\treturn called && !generated(called.name) ? [called] : [];\n\t\t});\n\t\tconst [onlyChild] = children;\n\t\tconst named =\n\t\t\tgenerated(job.name) && children.length === 1 && onlyChild\n\t\t\t\t? onlyChild\n\t\t\t\t: job;\n\t\tconst fallback = location(job.span);\n\t\tconst steps = new Map<string, number[]>();\n\t\tfor (const step of job.steps) {\n\t\t\tconst source = location(step.span) || fallback;\n\t\t\tsteps.set(source, [...(steps.get(source) ?? []), step.step]);\n\t\t}\n\t\tfailures.set(block.id, {\n\t\t\ttask,\n\t\t\tfunction: named.name,\n\t\t\t...(named.instance && { instance: named.instance }),\n\t\t\tspan: job.span,\n\t\t\tsources: [...steps].map(([source, numbers]) => ({\n\t\t\t\tsource,\n\t\t\t\tsteps: numbers,\n\t\t\t})),\n\t\t\tfallback,\n\t\t});\n\t}\n\n\treturn failures;\n}\n\n/**\n * Whether a build has telemetry: the program calls `@tsplc/compiler/telemetry`, `telemetry` is\n * configured, or `debug.trace` is on. Then every task with something to record gets a ring and\n * a sender, root jobs' unhandled failures included; otherwise nothing is added.\n */\nexport function planTelemetry(\n\tcore: VerifiedCoreModule,\n\tdeployment: Deployment,\n\toptions: CodesysOptions,\n\tproject: {\n\t\troot: string;\n\t\ttelemetry?: ResolvedTelemetryConfig;\n\t\ttrace?: { capacity: number; operands: number } | false;\n\t\tserver?: { transport: \"http\" | \"opcua\"; baseUrlEnv?: string };\n\t\tenvironment: Environment;\n\t},\n\treport: Report,\n): TelemetryPlan | undefined {\n\tconst { typeOf } = coreTables(core);\n\tconst statements = telemetryCalls(core);\n\tif (!statements.length && !project.telemetry && !project.trace) {\n\t\treturn undefined;\n\t}\n\n\tconst settings = ringSettings(project.telemetry, project.trace);\n\tconst sources = new Sources(project.root);\n\tconst location = (span: SourceSpan) => {\n\t\tconst range = sources.range(span);\n\t\treturn range ? `${sources.files[range.file]}:${range.line}` : \"\";\n\t};\n\tconst tasks = routineTasks(core, deployment);\n\tconst tooLarge = (size: number, what: string, span?: SourceSpan) => {\n\t\tif (size > settings.recordBytes) {\n\t\t\treport(\n\t\t\t\t`${what} can take ${size} bytes of JSON, more than telemetry.recordBytes (${settings.recordBytes}). Use fewer or shorter properties, smaller STRING or byte array bounds, or raise recordBytes.`,\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t};\n\n\tconst calls = new Map<CoreStatement, CallSite>();\n\tconst recordIds = new Map<string, number>();\n\tfor (const { routine, call } of statements) {\n\t\tconst task = tasks.get(routine);\n\t\tif (!task) {\n\t\t\treport(\n\t\t\t\t\"Telemetry calls must be in code that one task runs: each task writes its own records.\",\n\t\t\t\tcall.span,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst source = asciiJson(location(call.span));\n\t\tconst { record } = call;\n\t\tconst prefix = `${recordHead(record)},\"source\":${source},\"properties\":{`;\n\t\tconst size =\n\t\t\tprefix.length +\n\t\t\tcall.properties.reduce(\n\t\t\t\t(total, { name, value, length }, index) =>\n\t\t\t\t\ttotal +\n\t\t\t\t\t(index ? 1 : 0) +\n\t\t\t\t\tasciiJson(name).length +\n\t\t\t\t\t1 +\n\t\t\t\t\tpropertyJson(typeOf(value.type), length !== undefined).size,\n\t\t\t\t0,\n\t\t\t) +\n\t\t\t1 +\n\t\t\t(record.kind === \"exception\" ? codeSize : 0) +\n\t\t\tcommitSize;\n\t\ttooLarge(size, \"This telemetry record\", call.span);\n\t\t// Calls that write the same record with the same parameters, such as one call site in\n\t\t// several instances, share a method.\n\t\tconst key = JSON.stringify([\n\t\t\tprefix,\n\t\t\trecord.kind,\n\t\t\tcall.properties.map(({ name }) => name),\n\t\t\tcallParameters(call).map(({ name, value, text }) => [\n\t\t\t\tname,\n\t\t\t\tvalue.type,\n\t\t\t\ttext,\n\t\t\t]),\n\t\t]);\n\t\tconst id = recordIds.get(key) ?? recordIds.size + 1;\n\t\trecordIds.set(key, id);\n\t\tcalls.set(call, { id, task, record: prefix, call });\n\t}\n\n\tconst failures = new Map<string, FailureSite>();\n\tconst failureIds = new Map<string, number>();\n\tfor (const [block, job] of planJobFailures(core, tasks, location)) {\n\t\tconst record = `{\"kind\":\"exception\",\"handled\":false,\"function\":${asciiJson(job.function)},`;\n\t\tconst instance = job.instance\n\t\t\t? `\"instance\":${asciiJson(job.instance)},`\n\t\t\t: null;\n\t\ttooLarge(\n\t\t\trecord.length +\n\t\t\t\t(instance?.length ?? 0) +\n\t\t\t\t'\"properties\":{}'.length +\n\t\t\t\tcodeSize +\n\t\t\t\t',\"source\":\"\"'.length +\n\t\t\t\tmaximum(\n\t\t\t\t\t[...job.sources.map(({ source }) => source), job.fallback].map(\n\t\t\t\t\t\t(source) => asciiJson(source).length - 2,\n\t\t\t\t\t),\n\t\t\t\t) +\n\t\t\t\tcommitSize,\n\t\t\t`The failure record of ${job.function}`,\n\t\t\tjob.span,\n\t\t);\n\t\tconst key = JSON.stringify([record, instance !== null, job.sources]);\n\t\tconst id = failureIds.get(key) ?? failureIds.size + 1;\n\t\tfailureIds.set(key, id);\n\t\tfailures.set(block, {\n\t\t\tid,\n\t\t\ttask: job.task,\n\t\t\trecord,\n\t\t\tinstance,\n\t\t\tsources: job.sources,\n\t\t});\n\t}\n\n\tif (project.trace) {\n\t\ttooLarge(\n\t\t\ttraceRecord(project.trace.operands).size,\n\t\t\t\"A debug.trace record with its operands\",\n\t\t);\n\t}\n\n\tconst base = serverBaseUrl(project, project.environment);\n\tconst plan = {\n\t\t...settings,\n\t\tcalls,\n\t\tfailures,\n\t\t...(project.trace && { traceOperands: project.trace.operands }),\n\t};\n\tif (project.server?.transport === \"opcua\") {\n\t\treturn {\n\t\t\t...plan,\n\t\t\tendpoint: {\n\t\t\t\ttransport: \"opcua\",\n\t\t\t\tpath: telemetryPath,\n\t\t\t\ttimeoutMs: options.http.timeoutMs,\n\t\t\t},\n\t\t};\n\t}\n\tif (!base) {\n\t\treport(\n\t\t\t`Telemetry posts to the app server: set server.baseUrlEnv and that environment variable to its base URL.`,\n\t\t);\n\t\treturn undefined;\n\t}\n\tconst endpoint = resolveHttpEndpoint(\n\t\t`${routeBase(base)}${telemetryPath}`,\n\t\toptions.http,\n\t\tproject.environment,\n\t);\n\tif (\"error\" in endpoint) {\n\t\treport(endpoint.error);\n\t\treturn undefined;\n\t}\n\treturn { ...plan, endpoint };\n}\n\n/** A call's method parameters, in declaration order: `p<n>` for each property, `code` for an exception. */\nexport const callParameters = ({ record, properties }: TelemetryStatement) => [\n\t...properties.flatMap(({ value, length }, index) => [\n\t\t{ name: `p${index}`, value, text: length !== undefined },\n\t\t...(length\n\t\t\t? [{ name: `p${index}Length`, value: length, text: false }]\n\t\t\t: []),\n\t]),\n\t...(record.kind === \"exception\"\n\t\t? [{ name: \"code\", value: record.code, text: false }]\n\t\t: []),\n];\n\n/** The first site of each method id, in id order. */\nfunction firstOfEach<Site extends { id: number }>(sites: Iterable<Site>) {\n\tconst first = new Map<number, Site>();\n\tfor (const site of sites) {\n\t\tif (!first.has(site.id)) {\n\t\t\tfirst.set(site.id, site);\n\t\t}\n\t}\n\treturn [...first.values()].sort((a, b) => a.id - b.id);\n}\n\n/** The batch header's literal parts, before and after the task's name. */\nconst header = (build: string) => ({\n\tstart: `{\"build\":${asciiJson(build)},\"task\":\"`,\n\trest: [\n\t\t'\",\"now\":',\n\t\t',\"scan\":',\n\t\t',\"first\":',\n\t\t',\"dropped\":',\n\t\t',\"records\":[',\n\t] as const,\n});\n\n/** Records that always fit a batch beside its header: a sender with this many unsent sends at once. */\nconst batchRecords = (recordBytes: number) => {\n\tconst { start, rest } = header(\"0\".repeat(buildIdLength));\n\tconst fixed =\n\t\tstart.length +\n\t\ttaskNameLength +\n\t\trest.join(\"\").length +\n\t\t2 * digits.udint +\n\t\t2 * digits.ulint +\n\t\t\"]}\".length;\n\treturn Math.max(1, Math.floor((plcBufferBytes - fixed) / (recordBytes + 1)));\n};\n\n/** How the sender reaches the server: its HTTP client's endpoint and network, or the OPC UA slots it posts through. */\nexport type TelemetryTransport =\n\t| { kind: \"http\"; endpoint: NativeEndpoint; network: string }\n\t| { kind: \"opcua\"; timeoutMs: number; rpcGlobal: string };\n\n/**\n * The ring and sender of a task, `FB_TsplcTelemetry`: one method per call site and root job, a\n * shared `Trace`, and a body each scan runs first that counts the scan, reads the clock and\n * sends. It encodes with the HTTP blocks' JSON methods, and sends through a native HTTP block\n * or over OPC UA. Its batches name the build once `fillBuildId` has run.\n */\nexport function telemetryObjects({\n\tplan,\n\tnames,\n\ttarget,\n\ttransport,\n\ttypes,\n}: {\n\tplan: TelemetryPlan;\n\tnames: { writer: string; record: string; client: string };\n\ttarget: CodesysTypes;\n\ttransport: TelemetryTransport;\n\ttypes: ReadonlyMap<string, PlcType>;\n}): GeneratedObject[] {\n\tconst { capacity, recordBytes } = plan;\n\tconst method = (\n\t\tname: string,\n\t\tdeclaration: string,\n\t\timplementation: string,\n\t\taccess = \"\",\n\t): GeneratedObject => ({\n\t\tid: `${telemetryWriter}:${name}`,\n\t\tparent: telemetryWriter,\n\t\tkind: \"method\",\n\t\tname,\n\t\tdeclaration: `METHOD ${access}${name}\\n${declaration}`,\n\t\timplementation,\n\t});\n\n\tconst calls = firstOfEach(plan.calls.values()).map(({ id, record, call }) => {\n\t\tconst parameters = callParameters(call);\n\t\tconst inputs = parameters.filter((parameter) => !parameter.text);\n\t\tconst references = parameters.filter((parameter) => parameter.text);\n\t\tconst properties = call.properties.map(({ name, value, length }, index) => {\n\t\t\tconst code = propertyJson(\n\t\t\t\trequired(types.get(value.type)),\n\t\t\t\tlength !== undefined,\n\t\t\t).encode(`p${index}`, target);\n\t\t\treturn `Append(${stStringLiteral(`${index ? \",\" : \"\"}${asciiJson(name)}:`)});\\n${code}`;\n\t\t});\n\t\treturn method(\n\t\t\t`Record${id}`,\n\t\t\t[\n\t\t\t\t...(inputs.length\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t\"VAR_INPUT\",\n\t\t\t\t\t\t\t...inputs.map(\n\t\t\t\t\t\t\t\t(input) =>\n\t\t\t\t\t\t\t\t\t` ${input.name} : ${target.name(input.value.type)};`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\"END_VAR\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t\t...(references.length\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t\"VAR_IN_OUT\",\n\t\t\t\t\t\t\t...references.map(\n\t\t\t\t\t\t\t\t(input) =>\n\t\t\t\t\t\t\t\t\t` ${input.name} : ${target.name(input.value.type)};`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\"END_VAR\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t]\n\t\t\t\t.map((line) => `${line}\\n`)\n\t\t\t\t.join(\"\"),\n\t\t\t`${[\n\t\t\t\t\"payload := '';\",\n\t\t\t\t`Append(${stStringLiteral(record)});`,\n\t\t\t\t...properties,\n\t\t\t\t\"Append('}');\",\n\t\t\t\t...(call.record.kind === \"exception\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`Append(${stStringLiteral(codeMember)});`,\n\t\t\t\t\t\t\t\"Append(UDINT_TO_STRING(code));\",\n\t\t\t\t\t\t\t\"ErrorName(code);\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t\t\"Commit();\",\n\t\t\t].join(\"\\n\")}\\n`,\n\t\t);\n\t});\n\n\tconst failures = firstOfEach(plan.failures.values()).map(\n\t\t({ id, record, sources }) => {\n\t\t\tconst instances = [...plan.failures.values()].flatMap((failure) =>\n\t\t\t\tfailure.id === id && failure.instance !== null\n\t\t\t\t\t? [failure.instance.length]\n\t\t\t\t\t: [],\n\t\t\t);\n\t\t\treturn method(\n\t\t\t\t`Failure${id}`,\n\t\t\t\t`VAR_INPUT\\n code : UDINT;\\n step : UINT;\\n${instances.length ? ` instance : STRING(${maximum(instances)});\\n` : \"\"}END_VAR\\n`,\n\t\t\t\t`${[\n\t\t\t\t\t\"payload := '';\",\n\t\t\t\t\t`Append(${stStringLiteral(record)});`,\n\t\t\t\t\t...(instances.length ? [\"Append(instance);\"] : []),\n\t\t\t\t\t`Append(${stStringLiteral(`\"properties\":{}${codeMember}`)});`,\n\t\t\t\t\t\"Append(UDINT_TO_STRING(code));\",\n\t\t\t\t\t\"ErrorName(code);\",\n\t\t\t\t\t`Append(',\"source\":\"');`,\n\t\t\t\t\t\"CASE step OF\",\n\t\t\t\t\t...sources.map(\n\t\t\t\t\t\t({ source, steps }) =>\n\t\t\t\t\t\t\t`${steps.join(\", \")}: Append(${stStringLiteral(asciiJson(source).slice(1, -1))});`,\n\t\t\t\t\t),\n\t\t\t\t\t\"END_CASE;\",\n\t\t\t\t\t\"Append('\\\"');\",\n\t\t\t\t\t\"Commit();\",\n\t\t\t\t].join(\"\\n\")}\\n`,\n\t\t\t);\n\t\t},\n\t);\n\n\tconst operands = plan.traceOperands;\n\tconst trace =\n\t\toperands === undefined\n\t\t\t? []\n\t\t\t: [\n\t\t\t\t\tmethod(\n\t\t\t\t\t\t\"Trace\",\n\t\t\t\t\t\t`${[\n\t\t\t\t\t\t\t\"VAR_INPUT\",\n\t\t\t\t\t\t\t\" site : UINT;\",\n\t\t\t\t\t\t\t\" value : DINT;\",\n\t\t\t\t\t\t\t\" operands : USINT;\",\n\t\t\t\t\t\t\t...Array.from(\n\t\t\t\t\t\t\t\t{ length: operands },\n\t\t\t\t\t\t\t\t(_, index) => ` operand${index} : DINT;`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\"END_VAR\",\n\t\t\t\t\t\t].join(\"\\n\")}\\n`,\n\t\t\t\t\t\ttraceRecord(operands).implementation,\n\t\t\t\t\t),\n\t\t\t\t];\n\n\tconst { start, rest } = header(buildPlaceholder);\n\tconst clientPorts = `VAR_INPUT\\nstart : BOOL;\\ncancel : BOOL;\\nEND_VAR\\nVAR_IN_OUT\\nbody : STRING(${plcBufferBytes});\\nEND_VAR\\nVAR_OUTPUT\\nbusy : BOOL;\\ndone : BOOL;\\nerror : UDINT;\\nEND_VAR`;\n\tconst clientObjects =\n\t\ttransport.kind === \"opcua\"\n\t\t\t? [\n\t\t\t\t\topcuaClient({\n\t\t\t\t\t\tid: telemetryClient,\n\t\t\t\t\t\tname: names.client,\n\t\t\t\t\t\tports: clientPorts,\n\t\t\t\t\t\tport: (label) => label,\n\t\t\t\t\t\ttimeoutMs: transport.timeoutMs,\n\t\t\t\t\t\trpcGlobal: transport.rpcGlobal,\n\t\t\t\t\t\tbody: \"Append(body);\",\n\t\t\t\t\t\tdecode: \"\",\n\t\t\t\t\t}),\n\t\t\t\t\t...opcuaClientMethods(telemetryClient),\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t...nativeHttp({\n\t\t\t\t\t\tid: telemetryClient,\n\t\t\t\t\t\tname: names.client,\n\t\t\t\t\t\tports: clientPorts,\n\t\t\t\t\t\tport: (label) => label,\n\t\t\t\t\t\tendpoint: transport.endpoint,\n\t\t\t\t\t\tnetwork: transport.network,\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tjson: true,\n\t\t\t\t\t\tbody: \"Append(body);\",\n\t\t\t\t\t\tdecode: \"\",\n\t\t\t\t\t}),\n\t\t\t\t\t...httpClientMethods(telemetryClient),\n\t\t\t\t\t...httpCertificateVerifier(\n\t\t\t\t\t\ttelemetryClient,\n\t\t\t\t\t\tnames.client,\n\t\t\t\t\t\ttransport.endpoint,\n\t\t\t\t\t),\n\t\t\t\t];\n\treturn [\n\t\t{\n\t\t\tid: \"tsplc:telemetryRecord\",\n\t\t\tkind: \"dataType\",\n\t\t\tname: names.record,\n\t\t\tdeclaration: `TYPE ${names.record} :\\nSTRUCT\\n sequence : ULINT;\\n json : STRING(${recordBytes});\\nEND_STRUCT\\nEND_TYPE\\n`,\n\t\t},\n\t\t{\n\t\t\tid: telemetryWriter,\n\t\t\tkind: \"functionBlock\",\n\t\t\tname: names.writer,\n\t\t\tdeclaration: `FUNCTION_BLOCK ${names.writer}\nVAR_INPUT\n task : STRING(${taskNameLength});\nEND_VAR\nVAR_OUTPUT\n scan : UDINT;\n now : UDINT;\nEND_VAR\nVAR\n head : ULINT;\n sent : ULINT;\n dropped : ULINT;\n records : ARRAY[0..${capacity - 1}] OF ${names.record};\n payload : STRING(${plcBufferBytes});\n malformed : BOOL;\n text : STRING(${recordBytes});\n batch : STRING(${plcBufferBytes});\n batched : ULINT;\n sending : BOOL;\n lastSend : UDINT;\n client : ${names.client};\nEND_VAR\n`,\n\t\t\t// Idle, a scan costs the clock and two comparisons. A 400 means the server can't take\n\t\t\t// these records, so they are dropped rather than sent forever.\n\t\t\timplementation: `scan := scan + 1;\nnow := TIME_TO_UDINT(TIME());\nIF sending THEN\n client(start := TRUE, cancel := FALSE, body := batch);\n IF client.done THEN\n IF client.error = ${httpErrors.refused} THEN\n dropped := dropped + (batched - sent);\n END_IF;\n IF client.error = 0 OR client.error = ${httpErrors.refused} THEN\n sent := batched;\n END_IF;\n sending := FALSE;\n lastSend := now;\n client(start := FALSE, cancel := FALSE, body := batch);\n END_IF;\nELSIF head <> sent AND_THEN (head - sent >= ${batchRecords(recordBytes)} OR now - lastSend >= ${telemetrySendIntervalMs}) THEN\n Send();\nEND_IF;\n`,\n\t\t},\n\t\tmethod(\n\t\t\t\"Send\",\n\t\t\t\"VAR\\n slot : UDINT;\\nEND_VAR\\n\",\n\t\t\t`IF head - sent > ${capacity} THEN\n dropped := dropped + (head - sent - ${capacity});\n sent := head - ${capacity};\nEND_IF;\npayload := '';\nAppend(${stStringLiteral(start)});\nAppend(task);\nAppend(${stStringLiteral(rest[0])});\nAppend(UDINT_TO_STRING(now));\nAppend(${stStringLiteral(rest[1])});\nAppend(UDINT_TO_STRING(scan));\nAppend(${stStringLiteral(rest[2])});\nAppend(ULINT_TO_STRING(sent + 1));\nAppend(${stStringLiteral(rest[3])});\nAppend(ULINT_TO_STRING(dropped));\nAppend(${stStringLiteral(rest[4])});\nbatched := sent;\nWHILE batched <> head DO\n slot := ULINT_TO_UDINT((batched + 1) MOD ${capacity});\n IF ByteLength(payload) + ByteLength(records[slot].json) + 3 > ${plcBufferBytes} THEN\n EXIT;\n END_IF;\n IF batched <> sent THEN\n Append(',');\n END_IF;\n Append(records[slot].json);\n batched := batched + 1;\nEND_WHILE;\nAppend(']}');\nbatch := payload;\nsending := TRUE;\nclient(start := TRUE, cancel := FALSE, body := batch);\n`,\n\t\t\t\"PRIVATE \",\n\t\t),\n\t\t// The whole record is written before \\`head\\` moves, so a reader of the ring can tell a torn one.\n\t\tmethod(\n\t\t\t\"Commit\",\n\t\t\t\"VAR\\n slot : UDINT;\\nEND_VAR\\n\",\n\t\t\t`${commitMembers.map(({ member, value }) => `Append(${stStringLiteral(member)});\\nAppend(UDINT_TO_STRING(${value}));\\n`).join(\"\")}Append('}');\nslot := ULINT_TO_UDINT((head + 1) MOD ${capacity});\nrecords[slot].json := payload;\nrecords[slot].sequence := head + 1;\nhead := head + 1;\n`,\n\t\t\t\"PRIVATE \",\n\t\t),\n\t\tmethod(\n\t\t\t\"ErrorName\",\n\t\t\t\"VAR_INPUT\\n code : UDINT;\\nEND_VAR\\n\",\n\t\t\t`CASE code OF\n${errorNames.map(([code, name]) => `${code}: Append(${stStringLiteral(`${nameMember}${asciiJson(name)}`)});`).join(\"\\n\")}\n${httpErrors.base + 1}..${httpErrors.last}: Append(${stStringLiteral(`${nameMember}\"HTTP `)}); Append(UDINT_TO_STRING(code - ${httpErrors.base})); Append('\"');\nEND_CASE;\n`,\n\t\t\t\"PRIVATE \",\n\t\t),\n\t\tmethod(\n\t\t\t\"WriteText\",\n\t\t\t\"VAR_INPUT\\n data : POINTER TO BYTE;\\n length : DINT;\\nEND_VAR\\nVAR\\n index : DINT;\\nEND_VAR\\n\",\n\t\t\t`index := 0;\nWHILE index < length AND_THEN data[index] <> 0 DO\n text[index] := data[index];\n index := index + 1;\nEND_WHILE;\ntext[index] := 0;\nWriteString(text);\n`,\n\t\t\t\"PRIVATE \",\n\t\t),\n\t\t...jsonEncoders(telemetryWriter),\n\t\t...calls,\n\t\t...failures,\n\t\t...trace,\n\t\t...clientObjects,\n\t];\n}\n\n/** Writes the build id into the sender's batch header, where `telemetryObjects` left a placeholder. */\nexport function fillBuildId(\n\tobjects: readonly GeneratedObject[],\n\tbuild: string,\n): void {\n\tconst send = objects.find(\n\t\t(object) => object.id === `${telemetryWriter}:Send`,\n\t);\n\tif (send?.implementation !== undefined) {\n\t\tsend.implementation = send.implementation.replace(buildPlaceholder, build);\n\t}\n}\n",
25
+ "import { type Environment, type HttpOptions, secretValue } from \"@tsplc/config\";\n\n/** Where a client sends its requests: a server over HTTP(S), or a route of the app server's OPC UA gateway. */\nexport type HttpEndpoint =\n\t| {\n\t\t\ttransport: \"http\";\n\t\t\thost: string;\n\t\t\tport: number;\n\t\t\tauthority: string;\n\t\t\tpath: string;\n\t\t\ttoken: string;\n\t\t\ttimeoutMs: number;\n\t\t\ttls: boolean;\n\t }\n\t| { transport: \"opcua\"; path: string; timeoutMs: number };\n\nexport type NativeEndpoint = Extract<HttpEndpoint, { transport: \"http\" }>;\n\nconst invalidUrl = { error: \"Invalid URL\" };\n\n/** Each configured credential's bearer token, by the exact origin it is sent to. */\nexport const resolveHttpCredentials = (\n\tcredentials: HttpOptions[\"credentials\"],\n\tenvironment: Environment,\n): { tokens: ReadonlyMap<string, string> } | { error: string } => {\n\tconst tokens = new Map<string, string>();\n\tfor (const credential of credentials) {\n\t\tconst configured = environment[credential.originEnv];\n\t\tconst secret = environment[credential.bearerTokenEnv];\n\t\tif (!configured || !secret) {\n\t\t\treturn {\n\t\t\t\terror: `HTTP credentials require ${credential.originEnv} and ${credential.bearerTokenEnv}.`,\n\t\t\t};\n\t\t}\n\t\tconst origin = URL.parse(configured);\n\t\tif (!origin) {\n\t\t\treturn invalidUrl;\n\t\t}\n\t\tif (\n\t\t\t![\"http:\", \"https:\"].includes(origin.protocol) ||\n\t\t\torigin.username ||\n\t\t\torigin.password ||\n\t\t\torigin.pathname !== \"/\" ||\n\t\t\torigin.search ||\n\t\t\torigin.hash\n\t\t) {\n\t\t\treturn {\n\t\t\t\terror: `HTTP credential origin ${credential.originEnv} must contain only a scheme, host and port.`,\n\t\t\t};\n\t\t}\n\t\tif (tokens.has(origin.origin)) {\n\t\t\treturn { error: \"HTTP credential origins must be unique.\" };\n\t\t}\n\t\tif (!secretValue.safeParse(secret).success) {\n\t\t\treturn { error: `Invalid bearer token in ${credential.bearerTokenEnv}.` };\n\t\t}\n\t\ttokens.set(origin.origin, secret);\n\t}\n\treturn { tokens };\n};\n\nexport const resolveHttpEndpoint = (\n\tvalue: string,\n\tinput: HttpOptions,\n\tenvironment: Environment,\n): NativeEndpoint | { error: string } => {\n\tconst url = URL.parse(value);\n\tif (!url) {\n\t\treturn invalidUrl;\n\t}\n\tif (\n\t\t![\"http:\", \"https:\"].includes(url.protocol) ||\n\t\turl.username ||\n\t\turl.password ||\n\t\turl.hash ||\n\t\turl.hostname.includes(\":\")\n\t) {\n\t\treturn {\n\t\t\terror:\n\t\t\t\t\"fetch requires an HTTP(S) URL with an IPv4 address or DNS hostname, without credentials or fragment.\",\n\t\t};\n\t}\n\tconst port = Number(url.port || (url.protocol === \"https:\" ? 443 : 80));\n\tif (\n\t\t(url.pathname + url.search).length > 2048 ||\n\t\turl.hostname.length > 253 ||\n\t\tport === 0\n\t) {\n\t\treturn {\n\t\t\terror:\n\t\t\t\t\"HTTP URL exceeds the native host/path limits or has an invalid port.\",\n\t\t};\n\t}\n\tconst credentials = resolveHttpCredentials(input.credentials, environment);\n\tif (\"error\" in credentials) {\n\t\treturn credentials;\n\t}\n\treturn {\n\t\ttransport: \"http\",\n\t\thost: url.hostname,\n\t\tport,\n\t\tauthority: url.host,\n\t\tpath: url.pathname + url.search,\n\t\ttoken: credentials.tokens.get(url.origin) ?? \"\",\n\t\ttimeoutMs: input.timeoutMs,\n\t\ttls: url.protocol === \"https:\",\n\t};\n};\n\n/** A server base URL as routes such as the telemetry path are appended to it, by the PLC and the Bun runtime alike. */\nexport const routeBase = (baseUrl: string) => baseUrl.replace(/\\/+$/, \"\");\n",
26
+ "import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative, resolve } from \"node:path\";\nimport type { SourceSpan } from \"@tsplc/compiler/ir\";\nimport type { SourceRange } from \"@tsplc/debug/manifest\";\nimport { required } from \"./required\";\n\n/**\n * Whether a compiled file is the project's own source: anything but an installed dependency. A\n * monorepo's workspace packages count wherever they sit, as their files resolve to their real paths.\n */\nconst projectSource = (root: string, file: string): boolean => {\n\tconst path = relative(root, file);\n\treturn !isAbsolute(path) && !path.split(/[\\\\/]/).includes(\"node_modules\");\n};\n\n/** The nearest directory at or above `directory` that holds a `package.json`. */\nconst packageDirectory = (directory: string): string | undefined => {\n\tif (existsSync(join(directory, \"package.json\"))) {\n\t\treturn directory;\n\t}\n\tconst parent = dirname(directory);\n\treturn parent === directory ? undefined : packageDirectory(parent);\n};\n\n/**\n * The folders a source module's objects go in, without a leading `src`: its path in the project,\n * or a workspace package's own, so its objects keep the folders they would have in its own project.\n * `undefined` for a module that is not the project's own source.\n */\nexport const sourceFolders = (\n\troot: string,\n\tmodule: string,\n): string[] | undefined => {\n\tif (!/^[\\w./ -]+\\.tsx?$/.test(module)) {\n\t\treturn undefined;\n\t}\n\tconst file = resolve(root, module);\n\tif (!projectSource(root, file)) {\n\t\treturn undefined;\n\t}\n\tconst base = relative(root, file).startsWith(\"..\")\n\t\t? (packageDirectory(dirname(file)) ?? dirname(file))\n\t\t: root;\n\tconst segments = relative(base, file).replaceAll(\"\\\\\", \"/\").split(\"/\");\n\tconst folders = segments.slice(0, -1);\n\treturn folders[0] === \"src\" ? folders.slice(1) : folders;\n};\n\n/** A file's text and the offset each of its lines starts at. */\nconst lineStarts = (text: string) => ({\n\ttext,\n\tlines: [0, ...[...text.matchAll(/\\n/g)].map(({ index }) => index + 1)],\n});\n\n/** The index of the last line that starts at or before `offset`, by bisection. */\nconst lineIndex = (starts: readonly number[], offset: number): number => {\n\tlet low = 0;\n\tlet high = starts.length - 1;\n\twhile (low < high) {\n\t\tconst middle = (low + high + 1) >> 1;\n\t\tif (required(starts[middle]) <= offset) {\n\t\t\tlow = middle;\n\t\t} else {\n\t\t\thigh = middle - 1;\n\t\t}\n\t}\n\treturn low;\n};\n\n/**\n * Project files by index, as paths relative to the project root, so a workspace package's start with\n * `../`. Spans outside the project's own sources, such as virtual modules and dependencies, have no range.\n */\nexport class Sources {\n\treadonly files: string[] = [];\n\tprivate readonly loaded = new Map<\n\t\tstring,\n\t\t{ text: string; lines: number[] } | undefined\n\t>();\n\n\tconstructor(private readonly root: string) {}\n\n\tprivate load(file: string) {\n\t\tif (this.loaded.has(file)) {\n\t\t\treturn this.loaded.get(file);\n\t\t}\n\t\tconst source =\n\t\t\tprojectSource(this.root, file) && existsSync(file)\n\t\t\t\t? lineStarts(readFileSync(file, \"utf8\"))\n\t\t\t\t: undefined;\n\t\tthis.loaded.set(file, source);\n\t\treturn source;\n\t}\n\n\trange(span: SourceSpan): SourceRange | undefined {\n\t\tconst source = this.load(span.file);\n\t\tif (!source || span.end > source.text.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst position = (offset: number) => {\n\t\t\tconst line = lineIndex(source.lines, offset);\n\t\t\treturn {\n\t\t\t\tline: line + 1,\n\t\t\t\tcolumn: offset - required(source.lines[line]) + 1,\n\t\t\t};\n\t\t};\n\t\tconst path = relative(this.root, span.file).replaceAll(\"\\\\\", \"/\");\n\t\tconst known = this.files.indexOf(path);\n\t\tconst file = known < 0 ? this.files.push(path) - 1 : known;\n\t\tconst start = position(span.start);\n\t\tconst end = position(span.end);\n\t\treturn { file, ...start, endLine: end.line, endColumn: end.column };\n\t}\n\n\ttext(span: SourceSpan): string | undefined {\n\t\treturn this.load(span.file)?.text.slice(span.start, span.end);\n\t}\n}\n",
27
+ "import { type ResolvedTelemetryConfig, telemetrySchema } from \"@tsplc/config\";\n\n/** How long a sender waits for a full batch before it sends what it has, and before it retries. */\nexport const telemetrySendIntervalMs = 200;\n\n/**\n * The configured telemetry settings or their defaults, with rings that also hold `debug.trace`'s\n * records: each task has one ring for both.\n */\nexport const ringSettings = (\n\ttelemetry: ResolvedTelemetryConfig | undefined,\n\ttrace: { capacity: number } | false | undefined,\n): ResolvedTelemetryConfig => {\n\tconst settings = telemetry ?? telemetrySchema.parse({});\n\treturn {\n\t\t...settings,\n\t\tcapacity: Math.max(settings.capacity, trace ? trace.capacity : 0),\n\t};\n};\n",
28
+ "import type { CoreStatement } from \"@tsplc/compiler/ir\";\nimport { expressionText, storageName } from \"./expressions\";\nimport type { RoutineWriter } from \"./statements\";\n\n/**\n * The ST that counts a range's iterations from `first` to `last`, both of type `wide`: `condition`\n * holds when the range runs at all, and `count` is then the number of iterations as a DINT.\n */\nexport const iterationCount = ({\n\tfirst,\n\tlast,\n\tascending,\n\texclusive,\n\tstep,\n\twide,\n}: {\n\tfirst: string;\n\tlast: string;\n\tascending: boolean;\n\texclusive: boolean;\n\t/** The step's magnitude. */\n\tstep: bigint;\n\twide: \"LINT\" | \"ULINT\";\n}) => {\n\tconst distance = ascending ? `${last} - ${first}` : `${first} - ${last}`;\n\tconst excluded = exclusive ? ` - ${wide}#1` : \"\";\n\treturn {\n\t\tcondition: `${first} ${ascending ? \"<\" : \">\"}${exclusive ? \"\" : \"=\"} ${last}`,\n\t\tcount: `${wide}_TO_DINT(((${distance}${excluded}) / ${wide}#${step}) + ${wide}#1)`,\n\t};\n};\n\n/**\n * A counted FOR loop. It iterates a DINT ordinal rather than the authored counter, which would\n * overflow at a width boundary, and reconstructs the counter's typed value each scan.\n */\nexport function writeLoop(\n\troutine: RoutineWriter,\n\titem: Extract<CoreStatement, { kind: \"for\" }>,\n\tdepth: number,\n\twriteBody: (items: readonly CoreStatement[], depth: number) => void,\n): void {\n\tconst { storage, write, locals, declare } = routine;\n\tconst { targetTypes } = routine.context.symbols;\n\tconst counterType = storage.variableOf(item.counter).type;\n\tif (item.start.kind !== \"integer\") {\n\t\tthrow new Error(\"Invalid verified loop\");\n\t}\n\tconst { dynamic } = item;\n\tif (!item.maxIterations) {\n\t\tif (item.counterScope === \"existing\") {\n\t\t\twrite(\n\t\t\t\t`${storageName(storage, item.counter)} := ${dynamic ? expressionText(storage, dynamic.start) : targetTypes.literal(item.start, counterType)};`,\n\t\t\t\tdepth,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tconst ordinal = locals.allocate(\"iteration\");\n\tdeclare(` ${ordinal} : DINT;`, item.span);\n\tconst wide = counterType === \"ULINT\" ? \"ULINT\" : \"LINT\";\n\tconst ascending = BigInt(item.step) > 0n;\n\tconst step = ascending ? BigInt(item.step) : -BigInt(item.step);\n\tconst first = dynamic\n\t\t? `TO_${wide}(${expressionText(storage, dynamic.start)})`\n\t\t: `${wide}#${item.start.value}`;\n\tconst countIterations = ({\n\t\tlimit,\n\t\texclusive,\n\t}: NonNullable<typeof dynamic>): string => {\n\t\tconst counted = iterationCount({\n\t\t\tfirst,\n\t\t\tlast: `TO_${wide}(${expressionText(storage, limit)})`,\n\t\t\tascending,\n\t\t\texclusive: exclusive === true,\n\t\t\tstep,\n\t\t\twide,\n\t\t});\n\t\tconst count = locals.allocate(\"iterationCount\");\n\t\tdeclare(` ${count} : DINT;`, item.span);\n\t\twrite(`${count} := DINT#0;`, depth, item.span);\n\t\twrite(`IF ${counted.condition} THEN`, depth, item.span);\n\t\twrite(`${count} := ${counted.count};`, depth + 1, item.span);\n\t\twrite(\"END_IF;\", depth, item.span);\n\t\treturn count;\n\t};\n\tconst lastOrdinal = dynamic\n\t\t? `${countIterations(dynamic)} - DINT#1`\n\t\t: `DINT#${item.maxIterations - 1}`;\n\twrite(`FOR ${ordinal} := DINT#0 TO ${lastOrdinal} DO`, depth, item.span);\n\tconst counterValue = `${storageName(storage, item.counter)} := TO_${counterType}(${first} ${ascending ? \"+\" : \"-\"} (${wide}#${step} * DINT_TO_${wide}(${ordinal})));`;\n\twrite(counterValue, depth + 1, item.span);\n\twriteBody(item.body, depth + 1);\n\twrite(\"END_FOR;\", depth, item.span);\n\t// CODESYS keeps the ordinal at EXIT and advances it on normal\n\t// completion/CONTINUE. Reconstructing here preserves that distinction.\n\tif (item.counterScope === \"existing\") {\n\t\twrite(counterValue, depth, item.span);\n\t}\n}\n",
29
+ "import { createHash } from \"node:crypto\";\nimport type {\n\tEmitResult,\n\tGeneratedObject,\n\tSourceSpan,\n} from \"@tsplc/compiler/ir\";\nimport { isBlockRoutine } from \"@tsplc/compiler/ir\";\nimport type { Publication } from \"@tsplc/config\";\nimport type { DebugManifest } from \"@tsplc/debug/manifest\";\nimport type { ServiceChannel } from \"@tsplc/server/wire\";\nimport { explainedWriters, explanations } from \"./explain\";\nimport { emitGlobalLists, emitIoList, type IoMapping } from \"./global-lists\";\nimport { emitServiceBlock, httpNetwork, serviceBlock } from \"./http\";\nimport {\n\temitDebugGlobal,\n\temitTelemetry,\n\tplanInstrumentation,\n} from \"./instrumentation\";\nimport { debugManifest } from \"./manifest\";\nimport { type CodesysPlan, isPlanned } from \"./plan\";\nimport { emitScanProgram, emitTaskWrappers } from \"./programs\";\nimport { publishedSymbols } from \"./publication\";\nimport { emitRoutine } from \"./routines\";\nimport { emitScanClock } from \"./scan-clock\";\nimport { serviceChannelsFile } from \"./service-channels\";\nimport { Sources } from \"./sources\";\nimport { type ObjectMapping, type PlacedObject, stFiles } from \"./st-files\";\nimport {\n\tallocateBlockMembers,\n\tallocateFunctionNames,\n\tallocateRoutineScope,\n\ttype CodesysSymbols,\n\ttype EmissionContext,\n\tglobalSymbols,\n} from \"./symbols\";\n\nexport interface SourceMapping {\n\tpath: string;\n\tline: number;\n\tspan: SourceSpan;\n}\n\nexport type CodesysBundle = Omit<EmitResult, \"objects\"> & {\n\tobjects: PlacedObject[];\n\t/** Variables a generated device tree maps to their bit or byte channels. */\n\tioMappings: readonly IoMapping[];\n\tmappings: readonly SourceMapping[];\n\tioSymbols: Readonly<Record<string, string>>;\n\tpublication: Publication;\n\t/** The debugger's view of this build; its id is also published as `build.target`. */\n\tdebug: DebugManifest;\n\t/** `explain.json`'s text, whose digest `debug` records. */\n\texplain: string;\n};\n\n/** The routines emitted as objects: every function, and every block CODESYS does not provide. */\nconst emittedRoutines = ({ core }: CodesysPlan) => [\n\t...core.functions,\n\t...core.blocks.filter((block) => !block.standard),\n];\n\n/**\n * Allocates every target name the emitters read, in the order that fixes them, with the objects\n * emitted on the way: types, storage lists, the network, numeric helpers and telemetry. Each\n * routine's scope reserves those objects' names, as an ST local must never shadow a helper,\n * function, FB, or DUT that the implementation calls.\n */\nfunction emissionContext(plan: CodesysPlan) {\n\tconst { core } = plan;\n\tconst global = globalSymbols(plan);\n\tconst planned = planInstrumentation(plan, global);\n\tconst globalLists = emitGlobalLists(plan, global);\n\tconst ioList = emitIoList(plan, global, globalLists.references);\n\tconst network = httpNetwork(plan, global);\n\tconst objects: GeneratedObject[] = [\n\t\t...global.targetTypes.objects,\n\t\t...globalLists.objects,\n\t\t...ioList.objects,\n\t\t...(global.scanClock ? [emitScanClock(global.scanClock)] : []),\n\t\t...(network ? [network] : []),\n\t];\n\n\tconst routineNames = allocateFunctionNames(plan, global);\n\tfor (const routine of [...core.functions, ...core.blocks]) {\n\t\tglobal.numeric.prepareStatements(routine.body);\n\t}\n\tobjects.push(...global.numeric.objects);\n\tconst members = allocateBlockMembers(\n\t\tplan,\n\t\t{ ...global, functionNames: routineNames },\n\t\tplanned,\n\t\tobjects,\n\t);\n\tconst functionNames = new Map([...routineNames, ...members.methods]);\n\tconst instrumentation = { ...planned, fields: members.instrumented };\n\n\tconst telemetry = emitTelemetry(plan, global, instrumentation, network?.name);\n\tobjects.push(...telemetry.objects);\n\tconst scopes = new Map(\n\t\temittedRoutines(plan).map((fn) => [\n\t\t\tfn.id,\n\t\t\tallocateRoutineScope(\n\t\t\t\t{ ...global, functionNames, blockFields: members.fields },\n\t\t\t\tobjects,\n\t\t\t\tinstrumentation.global,\n\t\t\t\tfn,\n\t\t\t),\n\t\t]),\n\t);\n\tconst symbols: CodesysSymbols = {\n\t\t...global,\n\t\treferences: new Map([...globalLists.references, ...ioList.references]),\n\t\tfunctionNames,\n\t\tblockFields: members.fields,\n\t\tmailboxLocks: members.mailboxLocks,\n\t\tprogramResults: new Map(\n\t\t\t[...scopes].flatMap(([id, { result }]) => (result ? [[id, result]] : [])),\n\t\t),\n\t\troutineScopes: new Map([...scopes].map(([id, { scope }]) => [id, scope])),\n\t};\n\tconst context: EmissionContext = { plan, symbols, instrumentation };\n\treturn {\n\t\tcontext,\n\t\tobjects,\n\t\tmappings: [...globalLists.mappings, ...ioList.mappings],\n\t\tioList,\n\t\tnetwork,\n\t\trpcChannels: telemetry.rpcChannels,\n\t};\n}\n\nexport function emitCodesys(plan: CodesysPlan): CodesysBundle {\n\tif (!isPlanned(plan)) {\n\t\tthrow new Error(\"Emission requires a validated CODESYS plan.\");\n\t}\n\tconst { context, objects, mappings, ioList, network, rpcChannels } =\n\t\temissionContext(plan);\n\tconst channels: ServiceChannel[] = [...rpcChannels];\n\tconst lines: ObjectMapping[] = [...mappings];\n\tfor (const fn of emittedRoutines(plan)) {\n\t\tif (isBlockRoutine(fn) && serviceBlock(fn)) {\n\t\t\tconst service = emitServiceBlock(context, network?.name, fn);\n\t\t\tobjects.push(...service.objects);\n\t\t\tchannels.push(...service.rpcChannels);\n\t\t\tcontinue;\n\t\t}\n\t\tconst routine = emitRoutine(context, fn);\n\t\tobjects.push(...routine.objects);\n\t\tlines.push(...routine.mappings);\n\t}\n\tfor (const program of plan.core.programs) {\n\t\tobjects.push(emitScanProgram(context, ioList.channels, program));\n\t}\n\tobjects.push(...emitTaskWrappers(context, objects));\n\t// Explanations index the manifest's sources and functions, and its digest of them feeds the build id.\n\tconst sources = new Sources(plan.project.root);\n\tconst { manifest, functionIds } = debugManifest(context, sources);\n\tconst explained = explanations(context, manifest, sources, functionIds);\n\tconst explain = JSON.stringify(explained.file);\n\tconst debug = emitDebugGlobal(plan, context.instrumentation, objects, {\n\t\t...manifest,\n\t\twriters: explainedWriters(\n\t\t\tmanifest,\n\t\t\texplained,\n\t\t\tcontext.instrumentation.analysis.writers,\n\t\t),\n\t\texplain: { sha256: createHash(\"sha256\").update(explain).digest(\"hex\") },\n\t});\n\tconst placed = stFiles(context, objects, lines);\n\n\treturn {\n\t\tartifacts: [...placed.artifacts, serviceChannelsFile(channels)],\n\t\tobjects: placed.objects,\n\t\tmappings: placed.mappings,\n\t\tioSymbols: Object.fromEntries([\n\t\t\t...ioList.channels.map((channel) => [channel.key, channel.target]),\n\t\t\t...ioList.ioMappings.map((mapping) => [mapping.key, mapping.variable]),\n\t\t]),\n\t\tioMappings: ioList.ioMappings,\n\t\tpublication: publishedSymbols(context, channels),\n\t\tdebug,\n\t\texplain,\n\t\tdiagnostics: [],\n\t};\n}\n",
30
+ "import { type CoreStatement, coreTables } from \"@tsplc/compiler/ir\";\nimport { createExplainer } from \"@tsplc/debug/explain\";\nimport type { ExplainFile } from \"@tsplc/debug/explain-file\";\nimport type { DebugManifest } from \"@tsplc/debug/manifest\";\nimport { blockInstances } from \"./debug\";\nimport { explainEncoder } from \"./explain/expressions\";\nimport { explainFlags } from \"./explain/flags\";\nimport { writtenThroughParameters } from \"./explain/parameters\";\nimport { routineRows } from \"./explain/rows\";\nimport { explainTables } from \"./explain/tables\";\nimport { taskEntries } from \"./explain/tasks\";\nimport { explainWrites } from \"./explain/writes\";\nimport { required } from \"./required\";\nimport type { Sources } from \"./sources\";\nimport type { EmissionContext } from \"./symbols\";\n\n/** A build's `explain.json`, and the assignments of it each statement makes itself. */\nexport interface Explanations {\n\tfile: ExplainFile;\n\tassignmentsOf(statement: CoreStatement): readonly number[];\n}\n\n/**\n * Every statement of the specialized program that writes stored state, per routine instance, with\n * the conditions it runs under and the expressions it evaluates, as `explain.json` holds them.\n * `functionIds` are the manifest's function ids by routine; `sources` is the manifest's, so source\n * ranges index the same files.\n */\nexport function explanations(\n\tcontext: EmissionContext,\n\tmanifest: DebugManifest,\n\tsources: Sources,\n\tfunctionIds: ReadonlyMap<string, number>,\n): Explanations {\n\tconst { plan, instrumentation } = context;\n\tconst program = plan.specialized;\n\tconst core = coreTables(program);\n\tconst instances = blockInstances(program);\n\tconst tables = explainTables(sources);\n\tconst rows = routineRows({\n\t\tprogram,\n\t\tcore,\n\t\tinstances,\n\t\ttables,\n\t\tjobs: instrumentation.jobs,\n\t\tfunctionIds,\n\t});\n\tconst writesThrough = writtenThroughParameters([\n\t\t...program.functions,\n\t\t...program.blocks,\n\t]);\n\tconst encoder = explainEncoder(program, core, tables, writesThrough);\n\tconst { loops, calls, assignments, returns, recorded } = explainWrites({\n\t\trows,\n\t\tcore,\n\t\ttables,\n\t\tencoder,\n\t\twritesThrough,\n\t});\n\tconst { entries, rowTasks } = taskEntries({\n\t\tprogram,\n\t\tdeployment: plan.specializedTasks,\n\t\trows,\n\t\tcalls,\n\t\tcore,\n\t\ttables,\n\t});\n\tconst flags = explainFlags({\n\t\tplan,\n\t\tprogram,\n\t\tinstances,\n\t\tinstrumentation,\n\t\tmanifest,\n\t\ttables,\n\t\tassignments,\n\t\treaders: encoder.readers,\n\t\trowTasks,\n\t});\n\tconst references = Object.fromEntries(\n\t\t(program.references?.objects ?? []).map(({ id, path }) => [\n\t\t\tString(id),\n\t\t\ttables.paths.add(path),\n\t\t]),\n\t);\n\n\tconst file: ExplainFile = {\n\t\tkind: \"tsplc-explain\",\n\t\tversion: 1,\n\t\tpaths: tables.paths.items,\n\t\ttexts: tables.texts.items,\n\t\texpressions: tables.expressions.items,\n\t\tconditions: tables.conditions.items,\n\t\tsites: tables.sites.items,\n\t\troutines: rows.map((row) => ({\n\t\t\t...row.entry,\n\t\t\tpaths: row.slots.paths.items,\n\t\t\tlocals: row.slots.locals.items,\n\t\t\tcalls: row.slots.calls.items,\n\t\t\tloops: row.conditions.loops.map((_, loop) => row.firstLoop + loop),\n\t\t})),\n\t\tloops,\n\t\tassignments,\n\t\tlocals: encoder.locals,\n\t\treturns,\n\t\tcalls,\n\t\tentries,\n\t\tflags,\n\t\treferences,\n\t};\n\treturn { file, assignmentsOf: (statement) => recorded.get(statement) ?? [] };\n}\n\n/**\n * The manifest's last-writer slots with the assignments each site stands for, and whether the slot\n * names its path's writer exactly: when every statement that can write the path writes it directly,\n * where a probe records it. Writes made by a block, a loop counter or through a parameter aren't probed.\n */\nexport function explainedWriters(\n\tmanifest: DebugManifest,\n\texplained: Explanations,\n\tsites: readonly (readonly { id: number; statement: CoreStatement }[])[],\n): DebugManifest[\"writers\"] {\n\tconst explainer = createExplainer(manifest, explained.file);\n\treturn manifest.writers.map((writer, index) => {\n\t\tconst probed = required(sites[index]);\n\t\tconst { writers } = explainer.explain(writer.output);\n\t\tconst exact = writers.every((item) => {\n\t\t\tconst assignment = required(explained.file.assignments[item.assignment]);\n\t\t\treturn (\n\t\t\t\t(assignment.kind === \"assign\" || assignment.kind === \"call\") &&\n\t\t\t\t!assignment.via.length\n\t\t\t);\n\t\t});\n\t\tconst explainedAssignments = new Set(\n\t\t\twriters.map((item) => item.assignment),\n\t\t);\n\t\treturn {\n\t\t\t...writer,\n\t\t\texact,\n\t\t\tsites: writer.sites.map((site) => ({\n\t\t\t\t...site,\n\t\t\t\tassignments: probed\n\t\t\t\t\t.filter((item) => item.id === site.id)\n\t\t\t\t\t.flatMap((item) => [...explained.assignmentsOf(item.statement)])\n\t\t\t\t\t.filter((assignment) => explainedAssignments.has(assignment)),\n\t\t\t})),\n\t\t};\n\t});\n}\n",
31
+ "import {\n\ttype Constant,\n\ttype CoreTables,\n\tinstanceFields,\n\ttype PathCondition,\n\ttype PlcType,\n\ttype ReconstructedSegment,\n\ttype Reconstruction,\n\tstaticNames,\n\ttype Variable,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type {\n\tExplainAssignment,\n\tExplainCondition,\n\tExplainLocal,\n} from \"@tsplc/debug/explain-file\";\nimport { anyIndex, patternOf } from \"@tsplc/debug/paths\";\nimport { typescriptPath } from \"../debug\";\nimport { constantValue } from \"../manifest\";\nimport { storagePath } from \"../storage\";\nimport { parameterKey } from \"./parameters\";\nimport type { Row } from \"./rows\";\nimport type { ExplainTables } from \"./tables\";\n\n/** A place as the debugger names it: a storage path, with a `[*]` for each dynamic index. */\nexport interface Spelled {\n\treadonly text: string;\n\treadonly indexes: readonly number[];\n\treadonly type: PlcType | undefined;\n}\n\nconst aggregateKinds: ReadonlySet<PlcType[\"kind\"]> = new Set([\n\t\"record\",\n\t\"array\",\n\t\"block\",\n]);\n\n/** The storage path of a module variable or constant table; undefined for anything else. */\nexport const storedPath = (variable: Variable): string | undefined =>\n\tvariable.storage === \"constant\"\n\t\t? storagePath(variable)\n\t\t: typescriptPath(variable);\n\n/** The part of a constant at a path of record fields; an element of an array stays a read of the table. */\nconst constantAt = (\n\tvalue: Constant,\n\tnames: readonly string[],\n): Constant | undefined => {\n\tconst [name, ...rest] = names;\n\tif (name === undefined) {\n\t\treturn value;\n\t}\n\tif (value.kind === \"record\") {\n\t\tconst field = value.fields[name];\n\t\treturn field && constantAt(field, rest);\n\t}\n\treturn undefined;\n};\n\n/**\n * Writes reconstructions, conditions and places into `tables` as a row names them, and keeps the\n * locals the rows define and the rows that read each path.\n */\nexport function explainEncoder(\n\tprogram: VerifiedCoreModule,\n\tcore: CoreTables,\n\ttables: ExplainTables,\n\t/** The parameters each routine writes through, by `parameterKey`. */\n\twritesThrough: ReadonlySet<string>,\n) {\n\tconst { paths, texts, expressions } = tables;\n\t/** Fields that hold an object reference, with every index as `[*]`. */\n\tconst referenceFields = new Set(\n\t\t(program.references?.fields ?? []).map(patternOf),\n\t);\n\t/** The rows that read each path. */\n\tconst readers = new Map<string, Set<number>>();\n\tconst locals: ExplainLocal[] = [];\n\tconst rowLocals = new Map<\n\t\tstring,\n\t\t{ index: number; definitions: ExplainLocal[\"definitions\"] }\n\t>();\n\n\t/** A local of a row, by its index in `locals`, made when the row first names it. */\n\tconst local = (row: Row, root: string) => {\n\t\tconst key = `${row.index}:${root}`;\n\t\tconst known = rowLocals.get(key);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst variable = core.variableOf(root);\n\t\tconst created: ExplainLocal = {\n\t\t\troutine: row.index,\n\t\t\tname: variable.name,\n\t\t\tparameter: variable.storage === \"parameter\",\n\t\t\treference: false,\n\t\t\tdefinitions: [],\n\t\t};\n\t\tconst entry = { index: locals.length, definitions: created.definitions };\n\t\tlocals.push(created);\n\t\trowLocals.set(key, entry);\n\t\treturn entry;\n\t};\n\n\tconst fieldType = (\n\t\ttype: PlcType | undefined,\n\t\tname: string,\n\t): PlcType | undefined => {\n\t\tif (type?.kind === \"block\") {\n\t\t\tconst block = core.blockOf(type.block);\n\t\t\tconst field = instanceFields(block).find(\n\t\t\t\t(variable) => variable.name === name,\n\t\t\t);\n\t\t\treturn field && core.types.get(field.type);\n\t\t}\n\t\tif (type?.kind === \"record\") {\n\t\t\tconst field = type.fields.find((item) => item.name === name);\n\t\t\treturn field && core.types.get(field.type);\n\t\t}\n\t\treturn undefined;\n\t};\n\n\t/** A spelled place followed further along a path evaluated in `row`. */\n\tconst extend = (\n\t\trow: Row,\n\t\tspelled: Spelled,\n\t\tpath: readonly ReconstructedSegment[],\n\t): Spelled =>\n\t\tpath.reduce<Spelled>((place, segment) => {\n\t\t\tif (segment.kind === \"field\") {\n\t\t\t\t// Block outputs are fields of the instance itself, so its `out` view adds no segment.\n\t\t\t\tif (place.type?.kind === \"block\" && segment.name === \"out\") {\n\t\t\t\t\tconst { output } = place.type;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: place.text,\n\t\t\t\t\t\tindexes: place.indexes,\n\t\t\t\t\t\ttype: output ? core.types.get(output) : undefined,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\ttext: `${place.text}.${segment.name}`,\n\t\t\t\t\tindexes: place.indexes,\n\t\t\t\t\ttype: fieldType(place.type, segment.name),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst type =\n\t\t\t\tplace.type?.kind === \"array\"\n\t\t\t\t\t? core.types.get(place.type.element)\n\t\t\t\t\t: undefined;\n\t\t\tconst value = segment.value;\n\t\t\tif (value.kind === \"constant\" && value.value.kind === \"integer\") {\n\t\t\t\treturn {\n\t\t\t\t\ttext: `${place.text}[${value.value.value}]`,\n\t\t\t\t\tindexes: place.indexes,\n\t\t\t\t\ttype,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttext: `${place.text}${anyIndex}`,\n\t\t\t\tindexes: [...place.indexes, expression(row, value)],\n\t\t\t\ttype,\n\t\t\t};\n\t\t}, spelled);\n\n\t/** The storage path of a place in a row, or nothing for a temporary, local or parameter. */\n\tconst spell = (\n\t\trow: Row,\n\t\troot: string,\n\t\tpath: readonly ReconstructedSegment[],\n\t): Spelled | undefined => {\n\t\tconst variable = core.variableOf(root);\n\t\tconst field = row.fields.has(root);\n\t\tif (field && row.instance === null) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst start = field\n\t\t\t? `${row.instance}.${variable.name}`\n\t\t\t: storedPath(variable);\n\t\tif (start === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn extend(\n\t\t\trow,\n\t\t\t{ text: start, indexes: [], type: core.types.get(variable.type) },\n\t\t\tpath,\n\t\t);\n\t};\n\n\t/** A place as a record names what it writes or calls. */\n\tconst placeRef = (spelled: Spelled): ExplainAssignment[\"writes\"] =>\n\t\tspelled.indexes.length\n\t\t\t? {\n\t\t\t\t\tkind: \"pattern\",\n\t\t\t\t\tpath: paths.add(spelled.text),\n\t\t\t\t\tindexes: [...spelled.indexes],\n\t\t\t\t}\n\t\t\t: { kind: \"path\", path: paths.add(spelled.text) };\n\n\tconst isAggregate = (spelled: Spelled): boolean =>\n\t\tspelled.type !== undefined && aggregateKinds.has(spelled.type.kind);\n\n\t/** A live read of a stored place at `capturedAt`. */\n\tconst storedRead = (\n\t\trow: Row,\n\t\tspelled: Spelled,\n\t\tread: {\n\t\t\tcapturedAt: number;\n\t\t\tinterleaved?: true;\n\t\t\ttype: string;\n\t\t},\n\t): number => {\n\t\tconst path = row.slots.paths.add(paths.add(spelled.text));\n\t\tconst { capturedAt, interleaved, type } = read;\n\t\treturn expressions.add(\n\t\t\tspelled.indexes.length\n\t\t\t\t? {\n\t\t\t\t\t\tkind: \"pattern\",\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tindexes: [...spelled.indexes],\n\t\t\t\t\t\tcapturedAt,\n\t\t\t\t\t\t...(interleaved && { interleaved }),\n\t\t\t\t\t\ttype,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"read\",\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tcapturedAt,\n\t\t\t\t\t\t...(interleaved && { interleaved }),\n\t\t\t\t\t\ttype,\n\t\t\t\t\t},\n\t\t);\n\t};\n\n\tconst opaque = (\n\t\treason: string,\n\t\ttype: string,\n\t\treads: readonly number[] = [],\n\t): number =>\n\t\texpressions.add({\n\t\t\tkind: \"opaque\",\n\t\t\ttext: texts.add(reason),\n\t\t\treads: [...reads],\n\t\t\ttype,\n\t\t});\n\n\tconst expression = (row: Row, node: Reconstruction): number => {\n\t\tswitch (node.kind) {\n\t\t\tcase \"read\": {\n\t\t\t\t// A constant table read at fixed indexes is its value; there is nothing to read live.\n\t\t\t\tconst table = core.variableOf(node.root);\n\t\t\t\tconst names = staticNames(node.path);\n\t\t\t\tconst fixed =\n\t\t\t\t\ttable.storage === \"constant\" && table.initial && names\n\t\t\t\t\t\t? constantAt(table.initial, names)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (fixed) {\n\t\t\t\t\treturn expressions.add({\n\t\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\t\tvalue: constantValue(fixed),\n\t\t\t\t\t\ttype: node.type,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst spelled = spell(row, node.root, node.path);\n\t\t\t\tif (!spelled) {\n\t\t\t\t\treturn opaque(\"not stored\", node.type);\n\t\t\t\t}\n\t\t\t\tconst read = storedRead(row, spelled, {\n\t\t\t\t\tcapturedAt: node.capturedAt,\n\t\t\t\t\t...(node.interleaved && { interleaved: true as const }),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\t\tconst readBy = readers.get(spelled.text) ?? new Set<number>();\n\t\t\t\treadBy.add(row.index);\n\t\t\t\treaders.set(spelled.text, readBy);\n\t\t\t\t// A field holding an object reference holds the object's id: show the object.\n\t\t\t\treturn referenceFields.has(patternOf(spelled.text))\n\t\t\t\t\t? expressions.add({ kind: \"reference\", operand: read })\n\t\t\t\t\t: read;\n\t\t\t}\n\t\t\tcase \"local\": {\n\t\t\t\tconst names = staticNames(node.path);\n\t\t\t\treturn names\n\t\t\t\t\t? expressions.add({\n\t\t\t\t\t\t\tkind: \"local\",\n\t\t\t\t\t\t\tlocal: row.slots.locals.add(local(row, node.root).index),\n\t\t\t\t\t\t\tpath: names,\n\t\t\t\t\t\t\tat: node.at,\n\t\t\t\t\t\t\ttype: node.type,\n\t\t\t\t\t\t})\n\t\t\t\t\t: opaque(\"a local at a dynamic index\", node.type);\n\t\t\t}\n\t\t\tcase \"parameter\": {\n\t\t\t\tconst names = staticNames(node.path);\n\t\t\t\tif (!names) {\n\t\t\t\t\treturn opaque(\"a parameter at a dynamic index\", node.type);\n\t\t\t\t}\n\t\t\t\tconst written = writesThrough.has(\n\t\t\t\t\tparameterKey(row.routine.id, node.parameter),\n\t\t\t\t);\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"parameter\",\n\t\t\t\t\tparameter: node.parameter,\n\t\t\t\t\tpath: names,\n\t\t\t\t\tat: node.at,\n\t\t\t\t\tlocal: written\n\t\t\t\t\t\t? row.slots.locals.add(local(row, node.root).index)\n\t\t\t\t\t\t: null,\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcase \"call\": {\n\t\t\t\tconst call = row.calls.get(node.call);\n\t\t\t\treturn call === undefined\n\t\t\t\t\t? opaque(\"a call that isn't traced\", node.type)\n\t\t\t\t\t: expressions.add({\n\t\t\t\t\t\t\tkind: \"call\",\n\t\t\t\t\t\t\tcall: row.slots.calls.add(call),\n\t\t\t\t\t\t\tpath: [...node.path],\n\t\t\t\t\t\t\ttype: node.type,\n\t\t\t\t\t\t});\n\t\t\t}\n\t\t\tcase \"constant\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\tvalue: constantValue(node.value),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"clock\":\n\t\t\t\treturn expressions.add({ kind: \"clock\", type: node.type });\n\t\t\tcase \"unary\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"unary\",\n\t\t\t\t\toperator: node.operator,\n\t\t\t\t\toperand: expression(row, node.operand),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"binary\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"binary\",\n\t\t\t\t\toperator: node.operator,\n\t\t\t\t\t...(node.policy && { policy: node.policy }),\n\t\t\t\t\tleft: expression(row, node.left),\n\t\t\t\t\tright: expression(row, node.right),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"convert\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"convert\",\n\t\t\t\t\tpolicy: node.policy,\n\t\t\t\t\toperand: expression(row, node.operand),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"logical\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"logical\",\n\t\t\t\t\toperator: node.operator,\n\t\t\t\t\tleft: expression(row, node.left),\n\t\t\t\t\tright: expression(row, node.right),\n\t\t\t\t});\n\t\t\tcase \"select\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"select\",\n\t\t\t\t\tcondition: expression(row, node.condition),\n\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: a `?:` branch is data, not a thenable.\n\t\t\t\t\tthen: expression(row, node.then),\n\t\t\t\t\telse: expression(row, node.else),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"record\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"record\",\n\t\t\t\t\tfields: Object.fromEntries(\n\t\t\t\t\t\tObject.entries(node.fields).map(([name, value]) => [\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\texpression(row, value),\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"array\":\n\t\t\t\treturn expressions.add({\n\t\t\t\t\tkind: \"array\",\n\t\t\t\t\tlower: node.lower,\n\t\t\t\t\titems: node.items.map((item) => expression(row, item)),\n\t\t\t\t\ttype: node.type,\n\t\t\t\t});\n\t\t\tcase \"opaque\":\n\t\t\t\treturn opaque(\n\t\t\t\t\tnode.reason,\n\t\t\t\t\tnode.type,\n\t\t\t\t\tnode.reads.map((read) => expression(row, read)),\n\t\t\t\t);\n\t\t}\n\t};\n\n\tconst condition = (row: Row, item: PathCondition): ExplainCondition => {\n\t\tswitch (item.kind) {\n\t\t\tcase \"test\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"test\",\n\t\t\t\t\ttest: expression(row, item.test),\n\t\t\t\t\tholds: item.holds,\n\t\t\t\t\tat: item.at,\n\t\t\t\t\ttext: tables.text(item.span),\n\t\t\t\t};\n\t\t\tcase \"cases\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"cases\",\n\t\t\t\t\ttest: expression(row, item.test),\n\t\t\t\t\tvalues: item.values.map(constantValue),\n\t\t\t\t\tmember: item.member,\n\t\t\t\t\tat: item.at,\n\t\t\t\t\ttext: tables.text(item.span),\n\t\t\t\t};\n\t\t\tcase \"exits\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"exits\",\n\t\t\t\t\tany: item.any.map((all) => all.map((part) => condition(row, part))),\n\t\t\t\t};\n\t\t\tcase \"loop\":\n\t\t\tcase \"loopReturns\":\n\t\t\t\treturn { kind: item.kind, loop: item.loop };\n\t\t\tcase \"job\":\n\t\t\t\treturn { kind: \"job\", step: item.step };\n\t\t\tcase \"jobBusy\":\n\t\t\t\treturn { kind: \"jobBusy\" };\n\t\t}\n\t};\n\n\treturn {\n\t\texpression,\n\t\tcondition,\n\t\tspell,\n\t\textend,\n\t\tlocal,\n\t\tplaceRef,\n\t\tisAggregate,\n\t\tstoredRead,\n\t\treaders,\n\t\tlocals,\n\t};\n}\n\nexport type ExplainEncoder = ReturnType<typeof explainEncoder>;\n",
32
+ "import {\n\ttype CoreStatement,\n\tisBlockRoutine,\n\tnestedBodies,\n} from \"@tsplc/compiler/ir\";\nimport type { Routine } from \"./rows\";\n\n/** A parameter of a routine, by its position. */\nexport const parameterKey = (routine: string, index: number) =>\n\t`${routine}#${index}`;\n\n/** The position of `root` among a function's parameters, or -1. */\nexport const parameterIndex = (routine: Routine, root: string): number =>\n\tisBlockRoutine(routine)\n\t\t? -1\n\t\t: routine.parameters.findIndex((parameter) => parameter.id === root);\n\nconst statementsOf = (items: readonly CoreStatement[]): CoreStatement[] =>\n\titems.flatMap((item) => [item, ...nestedBodies(item).flatMap(statementsOf)]);\n\n/**\n * The parameters each routine writes through, by `parameterKey`: those it assigns, and those it\n * passes on to a routine that writes through the parameter it receives them as.\n */\nexport function writtenThroughParameters(\n\troutines: readonly Routine[],\n): ReadonlySet<string> {\n\tconst propagate = (written: ReadonlySet<string>): ReadonlySet<string> => {\n\t\tconst added = routines.flatMap((routine) =>\n\t\t\tstatementsOf(routine.body).flatMap((item) => {\n\t\t\t\tconst indexes = [\n\t\t\t\t\t...(item.kind === \"assign\"\n\t\t\t\t\t\t? [parameterIndex(routine, item.root)]\n\t\t\t\t\t\t: []),\n\t\t\t\t\t...(item.kind === \"invoke\"\n\t\t\t\t\t\t? item.arguments.flatMap((argument, index) =>\n\t\t\t\t\t\t\t\targument.kind === \"borrow\" &&\n\t\t\t\t\t\t\t\twritten.has(parameterKey(item.function, index))\n\t\t\t\t\t\t\t\t\t? [parameterIndex(routine, argument.place.root)]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: []),\n\t\t\t\t];\n\t\t\t\treturn indexes\n\t\t\t\t\t.filter((index) => index >= 0)\n\t\t\t\t\t.map((index) => parameterKey(routine.id, index))\n\t\t\t\t\t.filter((key) => !written.has(key));\n\t\t\t}),\n\t\t);\n\t\treturn added.length ? propagate(new Set([...written, ...added])) : written;\n\t};\n\treturn propagate(new Set());\n}\n",
33
+ "import type { VerifiedCoreModule } from \"@tsplc/compiler/ir\";\nimport type {\n\tExplainAssignment,\n\tExplainFlags,\n} from \"@tsplc/debug/explain-file\";\nimport type { DebugManifest } from \"@tsplc/debug/manifest\";\nimport { createPaths } from \"@tsplc/debug/paths\";\nimport { type InstancePath, instanceText } from \"../debug\";\nimport { isPublished } from \"../global-lists\";\nimport { serviceBlock, serviceName } from \"../http\";\nimport type { Instrumentation } from \"../instrumentation\";\nimport { constantValue, enclosingJob } from \"../manifest\";\nimport type { CodesysPlan } from \"../plan\";\nimport { required } from \"../required\";\nimport { storedPath } from \"./expressions\";\nimport type { ExplainTables } from \"./tables\";\n\n/** What explain.json says about stored paths beyond their writers, each at the shortest path it applies to. */\nexport function explainFlags({\n\tplan,\n\tprogram,\n\tinstances,\n\tinstrumentation,\n\tmanifest,\n\ttables,\n\tassignments,\n\treaders,\n\trowTasks,\n}: {\n\tplan: CodesysPlan;\n\tprogram: VerifiedCoreModule;\n\tinstances: ReadonlyMap<string, readonly InstancePath[]>;\n\tinstrumentation: Instrumentation;\n\tmanifest: DebugManifest;\n\ttables: ExplainTables;\n\tassignments: readonly ExplainAssignment[];\n\t/** The rows that read each path. */\n\treaders: ReadonlyMap<string, ReadonlySet<number>>;\n\trowTasks: ReadonlyMap<number, ReadonlySet<string>>;\n}): ExplainFlags[] {\n\tconst { paths } = tables;\n\tconst clientWritable = isPublished(plan);\n\tconst flags = new Map<string, ExplainFlags>();\n\tconst flag = (path: string): ExplainFlags => {\n\t\tconst known = flags.get(path);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst created: ExplainFlags = {\n\t\t\tpath: paths.add(path),\n\t\t\tinput: null,\n\t\t\tclientWritable: false,\n\t\t\thmiControl: null,\n\t\t\tretained: false,\n\t\t\tconstantTable: false,\n\t\t\twriterTasks: [],\n\t\t\tservice: null,\n\t\t\tinitial: null,\n\t\t\treference: false,\n\t\t};\n\t\tflags.set(path, created);\n\t\treturn created;\n\t};\n\tconst writtenPath = (assignment: ExplainAssignment) =>\n\t\trequired(paths.items[assignment.writes.path]);\n\tconst writtenPaths = new Set(assignments.map(writtenPath));\n\tfor (const variable of program.variables) {\n\t\tconst path = storedPath(variable);\n\t\tif (path === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst published = clientWritable(variable);\n\t\tconst constant = variable.storage === \"constant\";\n\t\tconst retained = variable.retention !== \"none\";\n\t\tif (published || retained || constant) {\n\t\t\tconst item = flag(path);\n\t\t\titem.clientWritable = published;\n\t\t\titem.retained = retained;\n\t\t\titem.constantTable = constant;\n\t\t}\n\t\tif (variable.initial && (constant || !writtenPaths.has(path))) {\n\t\t\tflag(path).initial = constantValue(variable.initial);\n\t\t}\n\t}\n\tmanifest.io.forEach((io, index) => {\n\t\tif (io.direction === \"input\") {\n\t\t\tflag(io.path).input = index;\n\t\t}\n\t});\n\tfor (const block of program.blocks) {\n\t\tconst endpoint = plan.http[block.id];\n\t\tif (!serviceBlock(block) || !endpoint) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const path of required(instances.get(block.id))) {\n\t\t\tconst instance = instanceText(path);\n\t\t\tflag(instance).service = {\n\t\t\t\tjob: enclosingJob(instrumentation, instance) ?? 0,\n\t\t\t\tservice: serviceName(endpoint.path),\n\t\t\t};\n\t\t}\n\t}\n\tfor (const field of program.references?.fields ?? []) {\n\t\tflag(field).reference = true;\n\t}\n\t// An HMI control names the published IEC symbol it writes.\n\tconst targets = createPaths(manifest);\n\tfor (const control of plan.project.hmi?.controls ?? []) {\n\t\tconst path = targets.fromTarget(control.target);\n\t\tif (path) {\n\t\t\tflag(path).hmiControl = control.label;\n\t\t}\n\t}\n\tconst writers = new Map<string, Set<string>>();\n\tfor (const assignment of assignments) {\n\t\tconst path = writtenPath(assignment);\n\t\tconst tasks = writers.get(path) ?? new Set<string>();\n\t\tfor (const task of rowTasks.get(assignment.routine) ?? []) {\n\t\t\ttasks.add(task);\n\t\t}\n\t\twriters.set(path, tasks);\n\t}\n\tfor (const [path, tasks] of writers) {\n\t\tconst readTasks = new Set(\n\t\t\t[...(readers.get(path) ?? [])].flatMap((row) => [\n\t\t\t\t...(rowTasks.get(row) ?? []),\n\t\t\t]),\n\t\t);\n\t\tif (tasks.size > 1 || [...readTasks].some((task) => !tasks.has(task))) {\n\t\t\tflag(path).writerTasks = [...tasks].sort();\n\t\t}\n\t}\n\treturn [...flags.values()];\n}\n",
34
+ "import {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\ttype CoreTables,\n\tinstanceFields,\n\tisBlockRoutine,\n\tpathConditions,\n\ttype RoutineConditions,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type { ExplainCall, ExplainFile } from \"@tsplc/debug/explain-file\";\nimport { type InstancePath, instanceText } from \"../debug\";\nimport { serviceBlock } from \"../http\";\nimport type { Instrumentation } from \"../instrumentation\";\nimport { routineLabel } from \"../manifest\";\nimport { required } from \"../required\";\nimport { type ExplainTables, Interned } from \"./tables\";\n\nexport type Routine = CoreFunction | CoreFunctionBlock;\n\n/** A row's table of global indexes; an expression names an entry by its position here. */\nconst slots = () => new Interned<number, number>((global) => global);\nexport type Slots = ReturnType<typeof slots>;\n\n/** One routine as one instance runs it: a function, or a block body or method on one block instance. */\nexport interface Row {\n\treadonly index: number;\n\treadonly routine: Routine;\n\treadonly conditions: RoutineConditions;\n\t/** The block instance's storage path. */\n\treadonly instance: string | null;\n\t/** The variables of the block the routine runs on, which are fields of `instance`. */\n\treadonly fields: ReadonlySet<string>;\n\t/** Its `routines` entry, but for the slots its records fill. */\n\treadonly entry: Omit<\n\t\tExplainFile[\"routines\"][number],\n\t\t\"paths\" | \"locals\" | \"calls\" | \"loops\"\n\t>;\n\t/**\n\t * The paths, locals and calls its expressions name, each by its slot here: two instances of one\n\t * routine then share their expressions and conditions, and differ only in these tables.\n\t */\n\treadonly slots: { paths: Slots; locals: Slots; calls: Slots };\n\t/** Each call it makes, by its index in `calls`. Expressions name call results, so these come first. */\n\treadonly calls: ReadonlyMap<CoreStatement, number>;\n\t/** The index in `loops` of its first loop; the rest follow in the order of `conditions.loops`. */\n\treadonly firstLoop: number;\n\t/** Each loop's site. */\n\treadonly loopSites: readonly (number | null)[];\n}\n\n/**\n * The rows of a program: a function without a block once, a method or block body once per block\n * instance. `functionIds` are the manifest's function ids by routine.\n */\nexport function routineRows({\n\tprogram,\n\tcore,\n\tinstances,\n\ttables,\n\tjobs,\n\tfunctionIds,\n}: {\n\tprogram: VerifiedCoreModule;\n\tcore: CoreTables;\n\tinstances: ReadonlyMap<string, readonly InstancePath[]>;\n\ttables: ExplainTables;\n\tjobs: Instrumentation[\"jobs\"];\n\tfunctionIds: ReadonlyMap<string, number>;\n}): Row[] {\n\tconst analysed = new Map<string, RoutineConditions>();\n\tconst conditionsOf = (routine: Routine) => {\n\t\tconst known = analysed.get(routine.id);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst conditions = pathConditions(routine, core.variables);\n\t\tanalysed.set(routine.id, conditions);\n\t\treturn conditions;\n\t};\n\tconst rows: Row[] = [];\n\tconst addRow = (routine: Routine, path: InstancePath | null): void => {\n\t\tconst block = isBlockRoutine(routine)\n\t\t\t? routine\n\t\t\t: routine.owner && core.blockOf(routine.owner.block);\n\t\tconst instance = path ? instanceText(path) : null;\n\t\tconst job = jobs.find(\n\t\t\t(item) => item.block.id === routine.id && item.instance === instance,\n\t\t);\n\t\tconst label = routineLabel(routine);\n\t\tconst conditions = conditionsOf(routine);\n\t\tconst callsBefore = rows.reduce((total, row) => total + row.calls.size, 0);\n\t\tconst calls = new Map(\n\t\t\t[...conditions.statements.keys()]\n\t\t\t\t.filter((item) => item.kind === \"invoke\" || item.kind === \"blockUpdate\")\n\t\t\t\t.map((item, index) => [item, callsBefore + index]),\n\t\t);\n\t\tconst row: Row = {\n\t\t\tindex: rows.length,\n\t\t\troutine,\n\t\t\tconditions,\n\t\t\tinstance,\n\t\t\tfields: new Set(\n\t\t\t\tblock ? instanceFields(block).map((variable) => variable.id) : [],\n\t\t\t),\n\t\t\tentry: {\n\t\t\t\tkey: routine.id,\n\t\t\t\tfunction: functionIds.get(routine.id) ?? null,\n\t\t\t\tinstance: instance === null ? null : tables.paths.add(instance),\n\t\t\t\tname: label.name,\n\t\t\t\tdeclaration: tables.range(label.span),\n\t\t\t\tjob: job?.id ?? null,\n\t\t\t},\n\t\t\tslots: { paths: slots(), locals: slots(), calls: slots() },\n\t\t\tcalls,\n\t\t\tfirstLoop: rows.reduce(\n\t\t\t\t(total, row) => total + row.conditions.loops.length,\n\t\t\t\t0,\n\t\t\t),\n\t\t\tloopSites: conditions.loops.map((loop) =>\n\t\t\t\ttables.site(loop.statement.span),\n\t\t\t),\n\t\t};\n\t\tfor (const call of calls.values()) {\n\t\t\trow.slots.calls.add(call);\n\t\t}\n\t\trows.push(row);\n\t};\n\tfor (const fn of program.functions) {\n\t\tconst owner = fn.owner?.block;\n\t\tif (owner === undefined) {\n\t\t\taddRow(fn, null);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const path of required(instances.get(owner))) {\n\t\t\taddRow(fn, path);\n\t\t}\n\t}\n\tfor (const block of program.blocks) {\n\t\tif (block.standard || serviceBlock(block) || !block.body.length) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const path of required(instances.get(block.id))) {\n\t\t\taddRow(block, path);\n\t\t}\n\t}\n\treturn rows;\n}\n\n/** The rows a call can run: its callee on the receiver's instance, or as a function or a method of the caller's own instance. */\nexport const calleeRows = (\n\trows: readonly Row[],\n\t{ paths }: ExplainTables,\n\tcore: CoreTables,\n\tcall: ExplainCall,\n\tcaller: Row,\n): Row[] =>\n\trows\n\t\t.filter((row) => {\n\t\t\tif (row.routine.id !== call.callee) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (call.receiver.kind === \"none\") {\n\t\t\t\treturn row.instance === null;\n\t\t\t}\n\t\t\tif (call.receiver.kind === \"pattern\") {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn paths.items[call.receiver.path] === row.instance;\n\t\t})\n\t\t.concat(\n\t\t\tcall.receiver.kind === \"none\" &&\n\t\t\t\tcaller.instance !== null &&\n\t\t\t\tcore.functions.get(call.callee)?.owner\n\t\t\t\t? rows.filter(\n\t\t\t\t\t\t(row) =>\n\t\t\t\t\t\t\trow.routine.id === call.callee &&\n\t\t\t\t\t\t\trow.instance === caller.instance,\n\t\t\t\t\t)\n\t\t\t\t: [],\n\t\t);\n",
35
+ "import type { SourceSpan } from \"@tsplc/compiler/ir\";\nimport type {\n\tExplainCondition,\n\tExplainExpression,\n\tExplainFile,\n} from \"@tsplc/debug/explain-file\";\nimport type { SourceRange } from \"@tsplc/debug/manifest\";\nimport type { Sources } from \"../sources\";\n\n/** An interning table: each distinct value once, by its key; a value is named by its position. */\nexport class Interned<Value, Key> {\n\treadonly items: Value[] = [];\n\tprivate readonly positions = new Map<Key, number>();\n\n\tconstructor(private readonly key: (value: Value) => Key) {}\n\n\tadd(value: Value): number {\n\t\tconst key = this.key(value);\n\t\tconst known = this.positions.get(key);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\tthis.positions.set(key, this.items.length);\n\t\tthis.items.push(value);\n\t\treturn this.items.length - 1;\n\t}\n}\n\nconst byJson = <Value>() =>\n\tnew Interned<Value, string>((value) => JSON.stringify(value));\n\n/** The most source lines a statement's snippet shows; longer spans are shown by their range alone. */\nconst maxSnippetLines = 8;\n\n/** The tables of `explain.json` that its records name entries of, and where its sites point. */\nexport function explainTables(sources: Sources) {\n\tconst paths = byJson<string>();\n\tconst texts = byJson<string>();\n\tconst expressions = byJson<ExplainExpression>();\n\tconst conditions = byJson<ExplainFile[\"conditions\"][number]>();\n\tconst sites = byJson<ExplainFile[\"sites\"][number]>();\n\n\tconst range = (span: SourceSpan): SourceRange | null =>\n\t\tsources.range(span) ?? null;\n\tconst text = (span: SourceSpan): number | null => {\n\t\tconst source = sources.range(span) && sources.text(span);\n\t\treturn source ? texts.add(source) : null;\n\t};\n\tconst site = (span: SourceSpan): number | null => {\n\t\tconst found = range(span);\n\t\tif (!found) {\n\t\t\treturn null;\n\t\t}\n\t\t// Generated code is mapped to the whole declaration it came from, which is no snippet.\n\t\tconst snippet =\n\t\t\tfound.endLine - found.line < maxSnippetLines ? text(span) : null;\n\t\treturn sites.add({ range: found, text: snippet });\n\t};\n\t/** The tree entry for a list of conditions, outermost first. */\n\tconst conditionsIndex = (list: readonly ExplainCondition[]): number | null =>\n\t\tlist.reduce<number | null>(\n\t\t\t(parent, condition) => conditions.add({ parent, condition }),\n\t\t\tnull,\n\t\t);\n\n\treturn {\n\t\tpaths,\n\t\ttexts,\n\t\texpressions,\n\t\tconditions,\n\t\tsites,\n\t\trange,\n\t\ttext,\n\t\tsite,\n\t\tconditionsIndex,\n\t};\n}\n\nexport type ExplainTables = ReturnType<typeof explainTables>;\n",
36
+ "import type {\n\tCoreTables,\n\tDeployment,\n\tVerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type { ExplainCall, ExplainFile } from \"@tsplc/debug/explain-file\";\nimport { required } from \"../required\";\nimport { calleeRows, type Row } from \"./rows\";\nimport type { ExplainTables } from \"./tables\";\n\n/** The routines each task runs directly, in the order it runs them, and the tasks that reach each row through calls. */\nexport function taskEntries({\n\tprogram,\n\tdeployment,\n\trows,\n\tcalls,\n\tcore,\n\ttables,\n}: {\n\tprogram: VerifiedCoreModule;\n\tdeployment: Deployment;\n\trows: readonly Row[];\n\tcalls: readonly ExplainCall[];\n\tcore: CoreTables;\n\ttables: ExplainTables;\n}): {\n\tentries: ExplainFile[\"entries\"];\n\trowTasks: ReadonlyMap<number, ReadonlySet<string>>;\n} {\n\tconst entries: ExplainFile[\"entries\"] = [];\n\tconst rowTasks = new Map<number, Set<string>>();\n\tfor (const task of deployment.tasks) {\n\t\tconst reached = new Set<number>();\n\t\tconst visit = (row: Row): void => {\n\t\t\tif (reached.has(row.index)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treached.add(row.index);\n\t\t\tconst tasks = rowTasks.get(row.index) ?? new Set<string>();\n\t\t\ttasks.add(task.name);\n\t\t\trowTasks.set(row.index, tasks);\n\t\t\tfor (const call of row.calls.values()) {\n\t\t\t\tconst record = required(calls[call]);\n\t\t\t\tconst targets =\n\t\t\t\t\trecord.receiver.kind === \"pattern\"\n\t\t\t\t\t\t? rows.filter((candidate) => candidate.routine.id === record.callee)\n\t\t\t\t\t\t: calleeRows(rows, tables, core, record, row);\n\t\t\t\ttargets.forEach(visit);\n\t\t\t}\n\t\t};\n\t\tfor (const name of task.programs) {\n\t\t\tconst entry = program.programs.find((item) => item.name === name)?.entry;\n\t\t\tconst row = rows.find(\n\t\t\t\t(candidate) =>\n\t\t\t\t\tcandidate.routine.id === entry && candidate.instance === null,\n\t\t\t);\n\t\t\tif (row) {\n\t\t\t\tentries.push({\n\t\t\t\t\troutine: row.index,\n\t\t\t\t\ttask: task.name,\n\t\t\t\t\torder: entries.filter((item) => item.task === task.name).length,\n\t\t\t\t});\n\t\t\t\tvisit(row);\n\t\t\t}\n\t\t}\n\t}\n\treturn { entries, rowTasks };\n}\n",
37
+ "import {\n\ttype CoreExpression,\n\ttype CorePath,\n\ttype CoreStatement,\n\ttype CoreTables,\n\tisBlockRoutine,\n\tisTemporary,\n\tprojectReconstruction,\n\ttype ReconstructedSegment,\n\ttype StatementConditions,\n\tstandardBlocks,\n\tstaticNames,\n} from \"@tsplc/compiler/ir\";\nimport type {\n\tExplainAssignment,\n\tExplainCall,\n\tExplainFile,\n} from \"@tsplc/debug/explain-file\";\nimport { required } from \"../required\";\nimport type { ExplainEncoder, Spelled } from \"./expressions\";\nimport { parameterIndex, parameterKey } from \"./parameters\";\nimport { calleeRows, type Row } from \"./rows\";\nimport type { ExplainTables } from \"./tables\";\n\ntype Invoke = Extract<CoreStatement, { kind: \"invoke\" }>;\n\n/** What every record of a statement starts with. */\ntype StatementRecord = Pick<\n\tExplainAssignment,\n\t\"routine\" | \"position\" | \"conditions\" | \"site\"\n>;\n\n/**\n * Writes through by-reference parameters are followed this many calls deep: each level fans out\n * to every instance the call can run on.\n */\nconst maxParameterDepth = 16;\n\n/**\n * Every row's loops, calls, returns and the writes of stored state its statements make, the\n * writes through by-reference parameters included, as `explain.json` holds them.\n */\nexport function explainWrites({\n\trows,\n\tcore,\n\ttables,\n\tencoder,\n\twritesThrough,\n}: {\n\trows: readonly Row[];\n\tcore: CoreTables;\n\ttables: ExplainTables;\n\tencoder: ExplainEncoder;\n\t/** The parameters each routine writes through, by `parameterKey`. */\n\twritesThrough: ReadonlySet<string>;\n}) {\n\tconst { expression, condition, spell, extend, local, placeRef, isAggregate } =\n\t\tencoder;\n\tconst loops: ExplainFile[\"loops\"] = [];\n\tconst assignments: ExplainAssignment[] = [];\n\tconst returns: ExplainFile[\"returns\"] = [];\n\tconst callRecords = new Map<number, ExplainCall>();\n\t/** The assignments each statement makes itself, in every instance that runs it. */\n\tconst recorded = new Map<CoreStatement, number[]>();\n\n\tconst segments = (\n\t\trow: Row,\n\t\tpath: CorePath,\n\t\tat: number,\n\t): ReconstructedSegment[] =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"index\",\n\t\t\t\t\t\tvalue: row.conditions.reconstruct(segment.value, at),\n\t\t\t\t\t},\n\t\t);\n\tconst loopOf = (row: Row, loop: number | null): number | null =>\n\t\tloop === null ? null : row.firstLoop + loop;\n\tconst statementRecord = (\n\t\trow: Row,\n\t\titem: CoreStatement,\n\t\tflow: StatementConditions,\n\t): StatementRecord => ({\n\t\troutine: row.index,\n\t\tposition: flow.position,\n\t\tconditions: tables.conditionsIndex(\n\t\t\tflow.conditions.map((part) => condition(row, part)),\n\t\t),\n\t\tsite: tables.site(item.span),\n\t});\n\n\t/** A block instance a call runs on, at the element it indexes. */\n\tconst spellInstance = (\n\t\trow: Row,\n\t\tinstance: string,\n\t\tindex: CoreExpression | undefined,\n\t\tat: number,\n\t) =>\n\t\tspell(\n\t\t\trow,\n\t\t\tinstance,\n\t\t\tindex\n\t\t\t\t? [{ kind: \"index\", value: row.conditions.reconstruct(index, at) }]\n\t\t\t\t: [],\n\t\t);\n\t/** The receiver of a call in a row: a block instance's path, or none for a function. */\n\tconst receiver = (\n\t\trow: Row,\n\t\titem: Invoke,\n\t\tat: number,\n\t): ExplainCall[\"receiver\"] => {\n\t\tif (item.instance === undefined) {\n\t\t\treturn core.functions.get(item.function)?.owner && row.instance !== null\n\t\t\t\t? { kind: \"path\", path: tables.paths.add(row.instance) }\n\t\t\t\t: { kind: \"none\" };\n\t\t}\n\t\tconst spelled = spellInstance(row, item.instance, item.index, at);\n\t\treturn spelled ? placeRef(spelled) : { kind: \"none\" };\n\t};\n\n\tfor (const row of rows) {\n\t\tconst { routine, conditions } = row;\n\t\tconditions.loops.forEach((loop, index) => {\n\t\t\tconst counter = core.variableOf(loop.counter);\n\t\t\tloops.push({\n\t\t\t\troutine: row.index,\n\t\t\t\tposition: loop.position,\n\t\t\t\tcounter: expression(\n\t\t\t\t\trow,\n\t\t\t\t\tconditions.reconstruct(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\t\troot: loop.counter,\n\t\t\t\t\t\t\ttype: counter.type,\n\t\t\t\t\t\t\tspan: loop.statement.span,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tloop.position,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tfirst: expression(row, loop.first),\n\t\t\t\tlimit: expression(row, loop.limit),\n\t\t\t\texclusive: loop.exclusive,\n\t\t\t\tstep: tables.expressions.add({\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\tvalue: Number(loop.step),\n\t\t\t\t\ttype: counter.type,\n\t\t\t\t}),\n\t\t\t\tmaxIterations: loop.maxIterations,\n\t\t\t\tbreaks: loop.breaks.map((all) =>\n\t\t\t\t\tall.map((part) => condition(row, part)),\n\t\t\t\t),\n\t\t\t\tparent: loopOf(row, loop.parent),\n\t\t\t\tsite: required(row.loopSites[index]),\n\t\t\t});\n\t\t});\n\t\tconst block = isBlockRoutine(routine) ? routine : undefined;\n\t\tfor (const [item, flow] of conditions.statements) {\n\t\t\tconst first = assignments.length;\n\t\t\tconst at = flow.position;\n\t\t\tconst record = statementRecord(row, item, flow);\n\t\t\tconst loop = loopOf(row, flow.loop);\n\t\t\tconst reconstruct = (value: CoreExpression) =>\n\t\t\t\texpression(row, conditions.reconstruct(value, at));\n\t\t\t/** A write of `value` to `root`: stored, a local's definition, or nothing for a temporary. */\n\t\t\tconst write = (\n\t\t\t\troot: string,\n\t\t\t\tpath: CorePath,\n\t\t\t\tkind: \"assign\" | \"call\" | \"counter\",\n\t\t\t\tvalue: number | null,\n\t\t\t): void => {\n\t\t\t\tconst variable = core.variableOf(root);\n\t\t\t\tconst parameter = parameterIndex(routine, root);\n\t\t\t\tconst isLocal =\n\t\t\t\t\tvariable.storage === \"local\" &&\n\t\t\t\t\troutine.locals.some((candidate) => candidate.id === root);\n\t\t\t\tif (isLocal && isTemporary(routine.id, variable)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (isLocal || parameter >= 0) {\n\t\t\t\t\tconst names = staticNames(segments(row, path, at));\n\t\t\t\t\tlocal(row, root).definitions.push({\n\t\t\t\t\t\t...record,\n\t\t\t\t\t\tkind: kind === \"counter\" ? \"counter\" : \"assign\",\n\t\t\t\t\t\tpath: names ?? [],\n\t\t\t\t\t\tvalue: names ? value : null,\n\t\t\t\t\t\tcall: null,\n\t\t\t\t\t\tloop,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst spelled = spell(row, root, segments(row, path, at));\n\t\t\t\tif (!spelled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tassignments.push({\n\t\t\t\t\t...record,\n\t\t\t\t\tkind,\n\t\t\t\t\twrites: placeRef(spelled),\n\t\t\t\t\twhole: isAggregate(spelled),\n\t\t\t\t\tvalue,\n\t\t\t\t\tblock: null,\n\t\t\t\t\tvia: [],\n\t\t\t\t\tloop,\n\t\t\t\t});\n\t\t\t};\n\t\t\t/** A local or parameter a call borrows, which the callee writes through. */\n\t\t\tconst borrowed = (\n\t\t\t\tcall: number,\n\t\t\t\targument: CoreExpression,\n\t\t\t\tindex: number,\n\t\t\t\tcallee: string,\n\t\t\t) => {\n\t\t\t\tif (\n\t\t\t\t\targument.kind !== \"borrow\" ||\n\t\t\t\t\t!writesThrough.has(parameterKey(callee, index))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst root = argument.place.root;\n\t\t\t\tconst isLocal =\n\t\t\t\t\troutine.locals.some((candidate) => candidate.id === root) &&\n\t\t\t\t\t!isTemporary(routine.id, core.variableOf(root));\n\t\t\t\tif (!isLocal && parameterIndex(routine, root) < 0) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst names = staticNames(segments(row, argument.place.path, at));\n\t\t\t\tlocal(row, root).definitions.push({\n\t\t\t\t\t...record,\n\t\t\t\t\tkind: \"borrowed\",\n\t\t\t\t\tpath: names ?? [],\n\t\t\t\t\tvalue: null,\n\t\t\t\t\tcall,\n\t\t\t\t\tloop,\n\t\t\t\t});\n\t\t\t};\n\t\t\tswitch (item.kind) {\n\t\t\t\tcase \"assign\":\n\t\t\t\t\twrite(item.root, item.path ?? [], \"assign\", reconstruct(item.value));\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"invoke\": {\n\t\t\t\t\tconst call = required(row.calls.get(item));\n\t\t\t\t\tcallRecords.set(call, {\n\t\t\t\t\t\t...record,\n\t\t\t\t\t\tcallee: item.function,\n\t\t\t\t\t\treceiver: receiver(row, item, at),\n\t\t\t\t\t\targuments: item.arguments.map((argument) => reconstruct(argument)),\n\t\t\t\t\t\tloop,\n\t\t\t\t\t});\n\t\t\t\t\titem.arguments.forEach((argument, index) => {\n\t\t\t\t\t\tborrowed(call, argument, index, item.function);\n\t\t\t\t\t});\n\t\t\t\t\tif (item.destination) {\n\t\t\t\t\t\twrite(\n\t\t\t\t\t\t\titem.destination,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\"call\",\n\t\t\t\t\t\t\ttables.expressions.add({\n\t\t\t\t\t\t\t\tkind: \"call\",\n\t\t\t\t\t\t\t\tcall,\n\t\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\t\ttype: required(core.functionOf(item.function).result),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"blockUpdate\": {\n\t\t\t\t\tconst call = required(row.calls.get(item));\n\t\t\t\t\tconst called = core.updatedBlock(item);\n\t\t\t\t\tconst spelled = spellInstance(row, item.instance, item.index, at);\n\t\t\t\t\tcallRecords.set(call, {\n\t\t\t\t\t\t...record,\n\t\t\t\t\t\tcallee: called.id,\n\t\t\t\t\t\treceiver: spelled ? placeRef(spelled) : { kind: \"none\" },\n\t\t\t\t\t\targuments: called.inputs.flatMap((input) => {\n\t\t\t\t\t\t\tconst value = item.inputs[input.name];\n\t\t\t\t\t\t\treturn value ? [reconstruct(value)] : [];\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tloop,\n\t\t\t\t\t});\n\t\t\t\t\tif (!spelled) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (called.standard) {\n\t\t\t\t\t\tconst native = standardBlocks[called.standard];\n\t\t\t\t\t\tconst elapsed = native.outputs.some(([name]) => name === \"elapsed\")\n\t\t\t\t\t\t\t? extend(row, spelled, [{ kind: \"field\", name: \"elapsed\" }])\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tassignments.push({\n\t\t\t\t\t\t\t...record,\n\t\t\t\t\t\t\tkind: \"block\",\n\t\t\t\t\t\t\twrites: placeRef(spelled),\n\t\t\t\t\t\t\twhole: true,\n\t\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t\tblock: {\n\t\t\t\t\t\t\t\tkind: called.standard,\n\t\t\t\t\t\t\t\tinputs: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.entries(item.inputs).map(([name, value]) => [\n\t\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t\t\treconstruct(value),\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\telapsed: elapsed\n\t\t\t\t\t\t\t\t\t? encoder.storedRead(row, elapsed, {\n\t\t\t\t\t\t\t\t\t\t\tcapturedAt: at,\n\t\t\t\t\t\t\t\t\t\t\ttype: \"TIME\",\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tvia: [],\n\t\t\t\t\t\t\tloop,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcalled.inputs.forEach((input) => {\n\t\t\t\t\t\tconst value = item.inputs[input.name];\n\t\t\t\t\t\tif (!value || value.kind === \"borrow\") {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst field = extend(row, spelled, [\n\t\t\t\t\t\t\t{ kind: \"field\", name: input.name },\n\t\t\t\t\t\t]);\n\t\t\t\t\t\tassignments.push({\n\t\t\t\t\t\t\t...record,\n\t\t\t\t\t\t\tkind: \"input\",\n\t\t\t\t\t\t\twrites: placeRef(field),\n\t\t\t\t\t\t\twhole: isAggregate(field),\n\t\t\t\t\t\t\tvalue: reconstruct(value),\n\t\t\t\t\t\t\tblock: null,\n\t\t\t\t\t\t\tvia: [],\n\t\t\t\t\t\t\tloop,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"for\":\n\t\t\t\t\twrite(item.counter, [], \"counter\", null);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"return\": {\n\t\t\t\t\treturns.push({\n\t\t\t\t\t\t...record,\n\t\t\t\t\t\tvalue: item.value ? reconstruct(item.value) : null,\n\t\t\t\t\t});\n\t\t\t\t\tconst value = item.value;\n\t\t\t\t\tif (!block || !value || row.instance === null) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst returned = conditions.reconstruct(value, at);\n\t\t\t\t\tfor (const output of block.outputs) {\n\t\t\t\t\t\tconst field = spell(row, output.id, []);\n\t\t\t\t\t\tif (!field) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tassignments.push({\n\t\t\t\t\t\t\t...record,\n\t\t\t\t\t\t\tkind: \"return\",\n\t\t\t\t\t\t\twrites: placeRef(field),\n\t\t\t\t\t\t\twhole: isAggregate(field),\n\t\t\t\t\t\t\tvalue: expression(\n\t\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\t\tprojectReconstruction(\n\t\t\t\t\t\t\t\t\treturned,\n\t\t\t\t\t\t\t\t\t[{ kind: \"field\", name: output.name }],\n\t\t\t\t\t\t\t\t\toutput.type,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tblock: null,\n\t\t\t\t\t\t\tvia: [],\n\t\t\t\t\t\t\tloop,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (assignments.length > first) {\n\t\t\t\trecorded.set(item, [\n\t\t\t\t\t...(recorded.get(item) ?? []),\n\t\t\t\t\t...Array.from(\n\t\t\t\t\t\t{ length: assignments.length - first },\n\t\t\t\t\t\t(_, offset) => first + offset,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n\tconst calls = Array.from({ length: callRecords.size }, (_, index) =>\n\t\trequired(callRecords.get(index)),\n\t);\n\n\t// Writes through a by-reference parameter land in the storage each call site passes.\n\tconst throughParameter = (\n\t\ttarget: Spelled,\n\t\tcallee: Row,\n\t\tparameter: number,\n\t\tvia: readonly number[],\n\t\tdepth: number,\n\t): void => {\n\t\tconst root = isBlockRoutine(callee.routine)\n\t\t\t? undefined\n\t\t\t: callee.routine.parameters[parameter]?.id;\n\t\tif (root === undefined || depth > maxParameterDepth) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const [item, flow] of callee.conditions.statements) {\n\t\t\tconst at = flow.position;\n\t\t\tconst record = statementRecord(callee, item, flow);\n\t\t\t// A written place's runtime indexes are evaluated where the place is named, in the\n\t\t\t// outermost caller; one the callee computes itself isn't followed.\n\t\t\tconst fixed = (path: CorePath) =>\n\t\t\t\tpath.every(\n\t\t\t\t\t(segment) =>\n\t\t\t\t\t\tsegment.kind === \"field\" || segment.value.kind === \"constant\",\n\t\t\t\t);\n\t\t\tif (\n\t\t\t\titem.kind === \"assign\" &&\n\t\t\t\titem.root === root &&\n\t\t\t\tfixed(item.path ?? [])\n\t\t\t) {\n\t\t\t\tconst spelled = extend(\n\t\t\t\t\tcallee,\n\t\t\t\t\ttarget,\n\t\t\t\t\tsegments(callee, item.path ?? [], at),\n\t\t\t\t);\n\t\t\t\tassignments.push({\n\t\t\t\t\t...record,\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\twrites: placeRef(spelled),\n\t\t\t\t\twhole: isAggregate(spelled),\n\t\t\t\t\tvalue: expression(\n\t\t\t\t\t\tcallee,\n\t\t\t\t\t\tcallee.conditions.reconstruct(item.value, at),\n\t\t\t\t\t),\n\t\t\t\t\tblock: null,\n\t\t\t\t\tvia: [...via],\n\t\t\t\t\tloop: loopOf(callee, flow.loop),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst call = callee.calls.get(item);\n\t\t\tif (item.kind !== \"invoke\" || call === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst nested = required(calls[call]);\n\t\t\titem.arguments.forEach((argument, index) => {\n\t\t\t\tif (\n\t\t\t\t\targument.kind !== \"borrow\" ||\n\t\t\t\t\targument.place.root !== root ||\n\t\t\t\t\t!fixed(argument.place.path) ||\n\t\t\t\t\t!writesThrough.has(parameterKey(item.function, index))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst inner = extend(\n\t\t\t\t\tcallee,\n\t\t\t\t\ttarget,\n\t\t\t\t\tsegments(callee, argument.place.path, at),\n\t\t\t\t);\n\t\t\t\tfor (const next of calleeRows(rows, tables, core, nested, callee)) {\n\t\t\t\t\tthroughParameter(inner, next, index, [call, ...via], depth + 1);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n\tfor (const row of rows) {\n\t\tfor (const [item, call] of row.calls) {\n\t\t\tif (item.kind !== \"invoke\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst record = required(calls[call]);\n\t\t\tconst at = required(row.conditions.statements.get(item)).position;\n\t\t\titem.arguments.forEach((argument, index) => {\n\t\t\t\tif (\n\t\t\t\t\targument.kind !== \"borrow\" ||\n\t\t\t\t\t!writesThrough.has(parameterKey(item.function, index))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst target = spell(\n\t\t\t\t\trow,\n\t\t\t\t\targument.place.root,\n\t\t\t\t\tsegments(row, argument.place.path, at),\n\t\t\t\t);\n\t\t\t\tif (!target) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfor (const callee of calleeRows(rows, tables, core, record, row)) {\n\t\t\t\t\tthroughParameter(target, callee, index, [call], 0);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\treturn { loops, calls, assignments, returns, recorded };\n}\n",
38
+ "import {\n\ttype Constant,\n\ttype CoreExpression,\n\ttype CoreStatement,\n\ttype CoreTables,\n\tcoreTables,\n\ttype Deployment,\n\ttype Diagnostic,\n\tfoldConstantRoutines,\n\tforwardTemporaries,\n\tfreeze,\n\tinstancedBlock,\n\tisLogicalIo,\n\tisVerifiedCore,\n\tnestedBodies,\n\ttype PlcType,\n\ttype SourceSpan,\n\tshareRoutines,\n\tstatementExpressions,\n\tsubexpressions,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport type {\n\tEnvironment,\n\tPublication,\n\tResolvedDebugConfig,\n\tResolvedHmiConfig,\n\tResolvedTelemetryConfig,\n\tServerConfig,\n} from \"@tsplc/config\";\nimport {\n\tcyclicTasksSchema,\n\tscheduleRepeats,\n\ttaskPriority,\n} from \"@tsplc/config/build\";\nimport { ioScalarBits } from \"@tsplc/iec\";\nimport { addressBits, ioLayout, regionOf } from \"@tsplc/typegen/hardware\";\nimport { type CodesysOptions, optionsSchema } from \"./config\";\nimport { type HttpEndpoint, resolveHttpEndpoint } from \"./endpoints\";\nimport { httpLayout, serviceBlock } from \"./http\";\nimport { writerPaths } from \"./instrumentation\";\nimport {\n\tiecSpelling,\n\tisStoragePath,\n\tresolveStoragePath,\n\ttype StorageBinding,\n} from \"./io-paths\";\nimport type { ProjectHardware } from \"./manifest\";\nimport { isIecIdentifier } from \"./names\";\nimport { resolvePublication } from \"./publication\";\nimport { required } from \"./required\";\nimport { schedulePrograms } from \"./scheduling\";\nimport { storageLayout } from \"./storage\";\nimport {\n\taccessedStorage,\n\troutineTasks,\n\ttaskStorageOwnership,\n} from \"./task-access\";\nimport { planTelemetry, type TelemetryPlan } from \"./telemetry\";\n\n// Only this planner can admit a target configuration for emission: other modules cannot write the\n// brand, and a copy of a plan is not in `plans`.\nconst planned: unique symbol = Symbol(\"CODESYS plan\");\nexport interface CodesysPlan {\n\treadonly [planned]: true;\n\treadonly core: VerifiedCoreModule;\n\t/**\n\t * The module as the frontend specialized it, one routine per instance, before programs are joined\n\t * and routines folded, shared and forwarded, with each task's programs in that module. The debug\n\t * manifest and explanations describe every instance, whatever the emitted routines look like.\n\t */\n\treadonly specialized: VerifiedCoreModule;\n\treadonly specializedTasks: Deployment;\n\t/** The routine each specialized function that `shareRoutines` merged away runs as. */\n\treadonly sharedRoutines: ReadonlyMap<string, string>;\n\treadonly deployment: Deployment;\n\treadonly options: CodesysOptions;\n\t/** The IEC name `programNames` gives a program, by program name. */\n\treadonly programNames: ReadonlyMap<string, string>;\n\t/** `io` keys that name authored storage, resolved against the verified types. */\n\treadonly storageBindings: readonly StorageBinding[];\n\t/** The storage paths `debug.writers.paths` matches, each recorded in a last-writer slot. */\n\treadonly writerPaths: readonly StorageBinding[];\n\treadonly publication: Publication;\n\t/** The endpoint each service block calls, by block id. */\n\treadonly http: Readonly<Record<string, HttpEndpoint>>;\n\treadonly project: CodesysProject;\n\t/** Each task's records and their sender, when the program has telemetry. */\n\treadonly telemetry?: TelemetryPlan;\n}\n\nconst plans = new WeakSet<CodesysPlan>();\n\n/** Whether `plan` is one `planCodesys` returned rather than a copy or a lookalike. */\nexport const isPlanned = (plan: CodesysPlan): boolean => plans.has(plan);\n\n/**\n * What the debug manifest describes beyond the program, the instrumentation `debug` asks for,\n * and the telemetry settings and server its records go to.\n */\nexport interface CodesysProject {\n\t/** Manifest sources and telemetry `source`s are relative to this directory. */\n\troot: string;\n\tdebug?: ResolvedDebugConfig;\n\ttelemetry?: ResolvedTelemetryConfig;\n\tserver?: Pick<ServerConfig, \"transport\" | \"baseUrlEnv\">;\n\thardware?: ProjectHardware;\n\t/** The HMI's controls, whose targets the debugger names as clients that write. */\n\thmi?: Pick<ResolvedHmiConfig, \"controls\">;\n\t/** Where HTTP credentials and the telemetry base URL are read from; this process's environment by default. */\n\tenvironment?: Environment;\n}\n/** Where a check of the plan sends what it refuses, each becoming a diagnostic. */\nexport type Report = (message: string, span?: SourceSpan) => void;\nfunction diagnostic(message: string, span?: SourceSpan): Diagnostic {\n\treturn {\n\t\torigin: \"backend\",\n\t\tcode: \"PLC7001\",\n\t\tseverity: \"error\",\n\t\tmessage,\n\t\t...(span && { span }),\n\t};\n}\n\nexport function planCodesys(\n\tspecialized: VerifiedCoreModule,\n\tdeployment: Deployment,\n\tvalue: unknown,\n\tproject: CodesysProject = { root: process.cwd() },\n): { plan?: CodesysPlan; diagnostics: readonly Diagnostic[] } {\n\tif (!isVerifiedCore(specialized)) {\n\t\treturn {\n\t\t\tdiagnostics: [\n\t\t\t\tdiagnostic(\"CODESYS requires a verified, normalized core module.\"),\n\t\t\t],\n\t\t};\n\t}\n\n\tconst parsed = optionsSchema.safeParse(value);\n\tif (!parsed.success) {\n\t\treturn {\n\t\t\tdiagnostics: parsed.error.issues.map((issue) =>\n\t\t\t\tdiagnostic(`${issue.path.join(\".\")}: ${issue.message}`),\n\t\t\t),\n\t\t};\n\t}\n\n\tconst options = parsed.data;\n\tconst environment = project.environment ?? { ...process.env };\n\tconst diagnostics: Diagnostic[] = [];\n\tconst report = (message: string, span?: SourceSpan): void => {\n\t\tdiagnostics.push(diagnostic(message, span));\n\t};\n\tconst { core, routines, tasks, specializedTasks } = scheduledRoutines(\n\t\tspecialized,\n\t\tdeployment,\n\t\tproject.debug,\n\t\treport,\n\t);\n\tconst scheduled: Deployment = { tasks };\n\tconst { types } = coreTables(core);\n\tconst http = new Map<string, HttpEndpoint>();\n\tfor (const block of core.blocks.filter(serviceBlock)) {\n\t\tconst layout = httpLayout(block, types);\n\t\tif (\"error\" in layout) {\n\t\t\treport(layout.error, block.span);\n\t\t\tcontinue;\n\t\t}\n\t\tconst endpoint: HttpEndpoint | { error: string } =\n\t\t\tblock.runtime.kind === \"rpc\"\n\t\t\t\t? {\n\t\t\t\t\t\ttransport: \"opcua\",\n\t\t\t\t\t\tpath: block.runtime.path,\n\t\t\t\t\t\ttimeoutMs: options.http.timeoutMs,\n\t\t\t\t\t}\n\t\t\t\t: resolveHttpEndpoint(block.runtime.url, options.http, environment);\n\t\tif (\"error\" in endpoint) {\n\t\t\treport(endpoint.error, block.span);\n\t\t\tcontinue;\n\t\t}\n\t\thttp.set(block.id, endpoint);\n\t}\n\n\tconst storageBindings = validateIo(core, options, report);\n\tconst writerBindings = writerPaths(core, project.debug, report);\n\tvalidateTasks(core, scheduled, report);\n\tvalidateProgramNames(core, options.programNames, report);\n\tvalidateRetain(core, report);\n\tvalidateConstants(core, report);\n\tconst telemetry = planTelemetry(\n\t\tcore,\n\t\tscheduled,\n\t\toptions,\n\t\t{ ...project, environment, trace: project.debug?.trace },\n\t\treport,\n\t);\n\tconst { publication, errors } = resolvePublication(core, options.publish);\n\tfor (const error of errors) {\n\t\treport(error);\n\t}\n\n\tif (diagnostics.length) {\n\t\treturn { diagnostics };\n\t}\n\n\tconst plan: CodesysPlan = Object.freeze({\n\t\tcore,\n\t\tspecialized,\n\t\tspecializedTasks: { tasks: specializedTasks },\n\t\tsharedRoutines: routines,\n\t\tdeployment: structuredClone(scheduled),\n\t\toptions,\n\t\tprogramNames: new Map(Object.entries(options.programNames)),\n\t\tstorageBindings,\n\t\twriterPaths: writerBindings,\n\t\tpublication,\n\t\thttp: Object.fromEntries(http),\n\t\tproject,\n\t\t...(telemetry && { telemetry }),\n\t\t[planned]: true as const,\n\t});\n\tfreeze(plan.deployment);\n\tfreeze(plan.specializedTasks);\n\tfreeze(plan.options);\n\tfreeze(plan.storageBindings);\n\tfreeze(plan.writerPaths);\n\tfreeze(plan.publication);\n\tplans.add(plan);\n\treturn { plan, diagnostics: [] };\n}\n\n/**\n * Routines specialized per instance, merged where they run the same code in the same task, calls\n * of routines that only return a constant replaced by it, and temporaries read right after they\n * are written folded into their reader, with each task's programs in the module that results.\n * Continuation programs stay apart: each task's wrapper calls them, and joining them named the\n * joined program after whichever came first.\n * The debugger's instrumentation is written per statement of each routine, so a program built\n * with `debug` keeps every instance's own routine, as does one whose scheduling is invalid or\n * names a program the module lacks: its diagnostics name the routines as written.\n */\nfunction scheduledRoutines(\n\tspecialized: VerifiedCoreModule,\n\tdeployment: Deployment,\n\tdebug: ResolvedDebugConfig | undefined,\n\treport: Report,\n) {\n\tconst issues: string[] = [];\n\tconst specializedTasks = schedulePrograms(\n\t\tspecialized,\n\t\tdeployment.tasks,\n\t\t(message) => {\n\t\t\tissues.push(message);\n\t\t},\n\t);\n\tconst programs = new Set(specialized.programs.map((program) => program.name));\n\tconst unknown = deployment.tasks.some((task) =>\n\t\ttask.programs.some((name) => !programs.has(name)),\n\t);\n\tif (debug || issues.length || unknown) {\n\t\tfor (const message of issues) {\n\t\t\treport(message);\n\t\t}\n\t\treturn {\n\t\t\tcore: specialized,\n\t\t\troutines: new Map<string, string>(),\n\t\t\ttasks: specializedTasks,\n\t\t\tspecializedTasks,\n\t\t};\n\t}\n\tconst folded = foldConstantRoutines(specialized);\n\tconst foldedTasks = routineTasks(folded.core, {\n\t\ttasks: schedulePrograms(folded.core, deployment.tasks, () => {}),\n\t});\n\tconst shared = shareRoutines(folded.core, (routine) =>\n\t\tfoldedTasks.get(routine.id),\n\t);\n\tconst core = forwardTemporaries(shared.core);\n\treturn {\n\t\tcore,\n\t\troutines: shared.routines,\n\t\ttasks: schedulePrograms(core, deployment.tasks, report),\n\t\tspecializedTasks,\n\t};\n}\n\n/** Validate every `io` binding and return the ones that name authored storage. */\nfunction validateIo(\n\tcore: VerifiedCoreModule,\n\toptions: CodesysOptions,\n\treport: Report,\n): StorageBinding[] {\n\tconst tables = coreTables(core);\n\tconst targets: {\n\t\tname: string;\n\t\tbinding: CodesysOptions[\"io\"][string];\n\t\ttype: PlcType;\n\t\tregion: \"I\" | \"Q\";\n\t\tspan?: SourceSpan;\n\t}[] = [];\n\tconst names = new Set<string>();\n\tfor (const item of core.variables.filter(isLogicalIo)) {\n\t\tif (names.has(item.name)) {\n\t\t\treport(\n\t\t\t\t`Ambiguous I/O name ${item.name}; logical I/O names must be unique.`,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tnames.add(item.name);\n\t\tconst binding = Object.hasOwn(options.io, item.name)\n\t\t\t? options.io[item.name]\n\t\t\t: undefined;\n\t\tif (!binding) {\n\t\t\treport(`Missing I/O binding for ${item.name}.`, item.span);\n\t\t\tcontinue;\n\t\t}\n\t\ttargets.push({\n\t\t\tname: item.name,\n\t\t\tbinding,\n\t\t\ttype: tables.typeOf(item.type),\n\t\t\tregion: regionOf(item.storage),\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tconst scheduled = new Set<string>();\n\tfor (const program of core.programs) {\n\t\tfor (const id of accessedStorage(tables.functionOf(program.entry), core)) {\n\t\t\tscheduled.add(id);\n\t\t}\n\t}\n\tconst storageBindings: StorageBinding[] = [];\n\tfor (const [name, binding] of Object.entries(options.io)) {\n\t\tif (names.has(name)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isStoragePath(name)) {\n\t\t\treport(`Unknown I/O binding ${name}.`);\n\t\t\tcontinue;\n\t\t}\n\t\tconst resolved = resolveStoragePath(core, name);\n\t\tif (\"error\" in resolved) {\n\t\t\treport(resolved.error);\n\t\t\tcontinue;\n\t\t}\n\t\tconst overlapping = storageBindings.find((other) =>\n\t\t\tnested(other, resolved),\n\t\t);\n\t\tif (overlapping) {\n\t\t\treport(`${name} overlaps the binding ${overlapping.key}.`);\n\t\t}\n\t\tif (!scheduled.has(resolved.root.id)) {\n\t\t\treport(\n\t\t\t\t`${name}: no scheduled program uses ${resolved.root.name}, so it would never be copied.`,\n\t\t\t);\n\t\t}\n\t\tstorageBindings.push(resolved);\n\t\ttargets.push({\n\t\t\tname,\n\t\t\tbinding,\n\t\t\ttype: resolved.type,\n\t\t\tregion: required(addressBits(binding.address)).region,\n\t\t});\n\t}\n\n\tconst placed: {\n\t\tregion: \"I\" | \"Q\";\n\t\tstart: number;\n\t\tend: number;\n\t\tname: string;\n\t\tshared?: boolean;\n\t}[] = [];\n\tfor (const { name, binding, type, region, span } of targets) {\n\t\t// An array binds at its first element; the remaining elements follow at\n\t\t// consecutive addresses of the same width, like an EDS byte/word span.\n\t\tconst array = type.kind === \"array\" ? type : undefined;\n\t\tconst element = array ? tables.typeOf(array.element) : type;\n\t\t// Typegen spells channels as IEC types; equal layouts bind (an EDS UINT flag word into a WORD).\n\t\tconst layout = ioSpelling(type, tables, ioLayout);\n\t\tif (binding.type && (!layout || ioLayout(binding.type) !== layout)) {\n\t\t\treport(\n\t\t\t\t`I/O type mismatch for ${name}: ${type.id} cannot bind to ${binding.type}.`,\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t\tconst address = required(addressBits(binding.address));\n\t\tif (address.region !== region) {\n\t\t\treport(\n\t\t\t\t`Wrong address region for ${name}: expected %${region}${binding.address.charAt(2)}.`,\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t\tif (region === \"I\" && element.kind === \"float\") {\n\t\t\treport(\n\t\t\t\t\"Floating logical inputs require an explicit runtime nonfinite policy, which is not supported yet.\",\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t\tif (array && element.kind === \"bool\") {\n\t\t\treport(\n\t\t\t\t`BOOL arrays are not bit-packed in CODESYS I/O; bind each element of ${name} separately.`,\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t\tif (ioSpelling(element, tables, ioScalarBits) !== address.bits) {\n\t\t\treport(`Address size does not match ${name}:${type.id}.`, span);\n\t\t}\n\t\tconst start = address.offsetBits;\n\t\tconst end = start + address.bits * (array?.length ?? 1);\n\t\tif (\n\t\t\tbinding.inverted &&\n\t\t\t(region !== \"I\" || element.kind !== \"bool\" || array)\n\t\t) {\n\t\t\treport(`Only a BOOL input can be inverted: ${name}.`, span);\n\t\t}\n\t\tif (binding.shared && region !== \"I\") {\n\t\t\treport(`Only an input can be shared: ${name}.`, span);\n\t\t}\n\t\tconst collision = placed.find(\n\t\t\t(other) =>\n\t\t\t\tother.region === address.region &&\n\t\t\t\tother.start < end &&\n\t\t\t\tstart < other.end &&\n\t\t\t\t!(\n\t\t\t\t\tbinding.shared &&\n\t\t\t\t\tother.shared &&\n\t\t\t\t\tother.start === start &&\n\t\t\t\t\tother.end === end\n\t\t\t\t),\n\t\t);\n\t\tif (collision) {\n\t\t\treport(\n\t\t\t\t`Overlapping I/O address ${binding.address} with ${collision.name}.`,\n\t\t\t\tspan,\n\t\t\t);\n\t\t}\n\t\tplaced.push({\n\t\t\tregion: address.region,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tname,\n\t\t\tshared: binding.shared,\n\t\t});\n\t\t// The address's number, which CODESYS counts in elements of its size: %IW12 is bytes 24-25.\n\t\tconst unit = address.bits === 1 ? 8 : address.bits;\n\t\tif (Math.floor(address.offsetBits / unit) > 0x7fff_ffff) {\n\t\t\treport(`I/O offset is too large: ${binding.address}.`, span);\n\t\t}\n\t}\n\treturn storageBindings;\n}\n\n/** What `read` makes of a type's IEC spelling, or undefined for a type typegen does not spell. */\nconst ioSpelling = <T>(\n\ttype: PlcType,\n\ttables: CoreTables,\n\tread: (spelling: string) => T,\n): T | undefined => {\n\tconst spelling = iecSpelling(type, tables.types);\n\treturn spelling === undefined ? undefined : read(spelling);\n};\n\n/** Two storage bindings conflict when one target contains the other. */\nfunction nested(left: StorageBinding, right: StorageBinding): boolean {\n\treturn (\n\t\tleft.root.id === right.root.id &&\n\t\tleft.segments.every((a, index) => {\n\t\t\tconst b = right.segments[index];\n\t\t\tif (!b) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn a.kind === \"field\"\n\t\t\t\t? b.kind === \"field\" && a.name === b.name\n\t\t\t\t: b.kind === \"index\" && a.value === b.value;\n\t\t})\n\t);\n}\n\n// `planCodesys` callers pass deployments that no config schema has seen, so the planner checks\n// each task against the raw ST schedule's rules, and the rules that need the program: CODESYS\n// task names are identifiers, and each program runs in exactly one task.\nfunction validateTasks(\n\tcore: VerifiedCoreModule,\n\tdeployment: Deployment,\n\treport: Report,\n): void {\n\tconst issues =\n\t\tcyclicTasksSchema.safeParse(deployment.tasks).error?.issues ?? [];\n\tconst refused = (index: number, field: string) =>\n\t\tissues.filter(({ path }) => path[0] === index && path[1] === field);\n\t// zod skips the schema's own repeat check once any task has a type issue.\n\tconst repeats = scheduleRepeats(deployment.tasks);\n\tconst repeated = (task: number, position: number | null) =>\n\t\trepeats.some((item) => item.task === task && item.position === position);\n\tconst programs = new Map(\n\t\tcore.programs.map((program) => [program.name, program]),\n\t);\n\tconst checkOwnership = taskStorageOwnership(core, report);\n\tdeployment.tasks.forEach((task, index) => {\n\t\tif (!isIecIdentifier(task.name)) {\n\t\t\treport(`Invalid task name ${task.name}.`);\n\t\t}\n\t\tif (repeated(index, null)) {\n\t\t\treport(`Duplicate task name ${task.name}.`);\n\t\t}\n\t\tif (refused(index, \"priority\").length) {\n\t\t\treport(\n\t\t\t\t`Task ${task.name} priority must be ${taskPriority.minValue}..${taskPriority.maxValue}.`,\n\t\t\t);\n\t\t}\n\t\tconst interval = refused(index, \"intervalNanoseconds\");\n\t\tif (interval.some(({ code }) => code === \"invalid_format\")) {\n\t\t\treport(`Invalid task interval for ${task.name}.`);\n\t\t} else if (interval.length) {\n\t\t\treport(\n\t\t\t\t`Task ${task.name} requires an exact positive TIME interval in milliseconds.`,\n\t\t\t);\n\t\t}\n\t\tif (refused(index, \"programs\").some(({ path }) => path.length === 2)) {\n\t\t\treport(`Task ${task.name} has no programs.`);\n\t\t}\n\t\ttask.programs.forEach((name, position) => {\n\t\t\tconst program = programs.get(name);\n\t\t\tif (!program) {\n\t\t\t\treport(`Unknown task program ${name}.`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (repeated(index, position)) {\n\t\t\t\treport(`Program ${name} must belong to exactly one task.`);\n\t\t\t}\n\t\t\tcheckOwnership(task.name, program);\n\t\t});\n\t});\n\tconst scheduled = new Set(deployment.tasks.flatMap((task) => task.programs));\n\tfor (const name of programs.keys()) {\n\t\tif (!scheduled.has(name)) {\n\t\t\treport(`Program ${name} has no cyclic task.`);\n\t\t}\n\t}\n}\n\nfunction validateProgramNames(\n\tcore: VerifiedCoreModule,\n\tprogramNames: Readonly<Record<string, string>>,\n\treport: Report,\n): void {\n\tif (core.blocks.some((block) => block.standard === \"Blinker\")) {\n\t\tfor (const target of Object.values(programNames)) {\n\t\t\tif (target.toUpperCase() === \"UTIL\") {\n\t\t\t\treport(\n\t\t\t\t\t`IEC object name ${target} shadows the Util library namespace required by Blinker.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconst programs = new Set(core.programs.map((program) => program.name));\n\tconst explicitNames = new Set<string>();\n\tfor (const [name, target] of Object.entries(programNames)) {\n\t\tif (!programs.has(name)) {\n\t\t\treport(`Unknown program name override ${name}.`);\n\t\t}\n\t\tif (explicitNames.has(target.toUpperCase())) {\n\t\t\treport(`Duplicate IEC program name ${target}.`);\n\t\t}\n\t\texplicitNames.add(target.toUpperCase());\n\t}\n}\n\n/**\n * InOut addresses must not survive a retained restart, including nested children. CODESYS accepts\n * one persistent variable list in an application, so only one module's storage may persist.\n */\nfunction validateRetain(core: VerifiedCoreModule, report: Report): void {\n\tconst { types, blockOf } = coreTables(core);\n\tconst blockHasInOut = (id: string): boolean => {\n\t\tconst block = blockOf(id);\n\t\treturn (\n\t\t\tblock.inputs.some((input) => input.mode === \"inOut\") ||\n\t\t\tblock.state.some((field) => {\n\t\t\t\tconst type = instancedBlock(field.type, types);\n\t\t\t\treturn type !== undefined && blockHasInOut(type.block);\n\t\t\t})\n\t\t);\n\t};\n\n\tconst layout = storageLayout(core);\n\tfor (const block of core.blocks) {\n\t\tif (layout.retainedBlocks.has(block.id) && blockHasInOut(block.id)) {\n\t\t\treport(\n\t\t\t\t\"Retained function blocks cannot contain direct or nested InOut references.\",\n\t\t\t\tblock.span,\n\t\t\t);\n\t\t}\n\t}\n\tfor (const variable of core.variables) {\n\t\tconst type = instancedBlock(variable.type, types);\n\t\tif (variable.retention !== \"none\" && type && blockHasInOut(type.block)) {\n\t\t\treport(\n\t\t\t\t\"Retained function blocks cannot contain direct or nested InOut references.\",\n\t\t\t\tvariable.span,\n\t\t\t);\n\t\t}\n\t}\n\tconst [, ...others] = layout.globalLists.filter(\n\t\t(list) => list.kind === \"persistent\",\n\t);\n\tfor (const list of others) {\n\t\treport(\n\t\t\t\"CODESYS keeps one persistent variable list per application: persist the storage of one module only.\",\n\t\t\tlist.variables[0]?.span,\n\t\t);\n\t}\n}\n\nfunction validateConstants(core: VerifiedCoreModule, report: Report): void {\n\tconst { typeOf } = coreTables(core);\n\tconst constant = (value: Constant, id: string, span?: SourceSpan): void => {\n\t\tconst type = typeOf(id);\n\t\tif (type.kind === \"string\" && value.kind === \"string\") {\n\t\t\tif (\n\t\t\t\ttype.encoding === \"utf8\" &&\n\t\t\t\t[...value.value].some(\n\t\t\t\t\t(character) =>\n\t\t\t\t\t\tcharacter.charCodeAt(0) === 0 || character.charCodeAt(0) > 127,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treport(\n\t\t\t\t\t\"Non-ASCII STRING literals require a verified project-wide UTF8 setting; this profile supports ASCII literals.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (type.encoding === \"utf16\" && /[\\uD800-\\uDFFF]/.test(value.value)) {\n\t\t\t\treport(\n\t\t\t\t\t\"CODESYS WSTRING uses UCS-2 and cannot represent surrogate code units.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"array\" && value.kind === \"array\") {\n\t\t\tfor (const item of value.items) {\n\t\t\t\tconstant(item, type.element, span);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"record\" && value.kind === \"record\") {\n\t\t\tfor (const field of type.fields) {\n\t\t\t\tconstant(required(value.fields[field.name]), field.type, span);\n\t\t\t}\n\t\t}\n\t};\n\tconst constantsInExpression = (value: CoreExpression): void => {\n\t\tif (value.kind === \"constant\") {\n\t\t\tconstant(value.value, value.type, value.span);\n\t\t}\n\t\tsubexpressions(value).forEach(constantsInExpression);\n\t};\n\tconst constantsInBody = (items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tstatementExpressions(item).forEach(constantsInExpression);\n\t\t\tif (item.kind !== \"switch\") {\n\t\t\t\tnestedBodies(item).forEach(constantsInBody);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const branch of item.cases) {\n\t\t\t\tfor (const value of branch.values) {\n\t\t\t\t\tconstant(value, item.value.type, item.span);\n\t\t\t\t}\n\t\t\t\tconstantsInBody(branch.body);\n\t\t\t}\n\t\t\tconstantsInBody(item.fallback);\n\t\t}\n\t};\n\tcore.variables.forEach((variable) => {\n\t\tif (variable.initial) {\n\t\t\tconstant(variable.initial, variable.type, variable.span);\n\t\t}\n\t});\n\tfor (const fn of core.functions) {\n\t\tconstantsInBody(fn.body);\n\t}\n\tcore.blocks.forEach((block) => {\n\t\t[...block.outputs, ...block.state, ...block.locals].forEach((variable) => {\n\t\t\tif (variable.initial) {\n\t\t\t\tconstant(variable.initial, variable.type, variable.span);\n\t\t\t}\n\t\t});\n\t\tconstantsInBody(block.body);\n\t});\n}\n",
39
+ "import { isLogicalIo, type VerifiedCoreModule } from \"@tsplc/compiler/ir\";\nimport type { Publication } from \"@tsplc/config\";\nimport type { ServiceChannel } from \"@tsplc/server/wire\";\nimport { required } from \"./required\";\nimport { moduleFile, moduleName, storagePath } from \"./storage\";\nimport type { EmissionContext } from \"./symbols\";\n\nconst globals = (core: VerifiedCoreModule) =>\n\tcore.variables.filter(\n\t\t(variable) => variable.storage === \"module\" && variable.exported,\n\t);\n\n/** Source names are independent of CODESYS name allocation and the active build target. */\nexport const publicationSelectors = (core: VerifiedCoreModule): string[] => {\n\tconst variables = globals(core);\n\treturn [\n\t\t...new Set(\n\t\t\tvariables.flatMap((variable) => [\n\t\t\t\tmoduleName(variable),\n\t\t\t\tstoragePath(variable),\n\t\t\t]),\n\t\t),\n\t].sort();\n};\n\nexport const resolvePublication = (\n\tcore: VerifiedCoreModule,\n\tpolicy: Publication,\n): { publication: Publication; errors: string[] } => {\n\tconst variables = globals(core);\n\tconst errors: string[] = [];\n\tconst select = (selectors: readonly string[]) => {\n\t\tconst selected = new Set<string>();\n\t\tconst seen = new Set<string>();\n\t\tfor (const selector of selectors) {\n\t\t\tif (seen.has(selector)) {\n\t\t\t\terrors.push(`Duplicate publication selector ${selector}.`);\n\t\t\t}\n\t\t\tseen.add(selector);\n\t\t\tconst candidates = variables.filter(\n\t\t\t\t(variable) =>\n\t\t\t\t\tselector === moduleName(variable) ||\n\t\t\t\t\tselector === storagePath(variable),\n\t\t\t);\n\t\t\tif (!candidates.length) {\n\t\t\t\terrors.push(\n\t\t\t\t\t`Unknown publication selector ${selector}; select an exported state root or a field of one, such as counter or counter.total.`,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (new Set(candidates.map(({ id }) => moduleFile(id))).size !== 1) {\n\t\t\t\terrors.push(`Ambiguous publication selector ${selector}.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const variable of candidates) {\n\t\t\t\tselected.add(variable.id);\n\t\t\t}\n\t\t}\n\t\treturn variables\n\t\t\t.filter((variable) => selected.has(variable.id))\n\t\t\t.map((variable) => variable.id);\n\t};\n\tconst publication = {\n\t\tproduction: select(policy.production),\n\t\tdevelopment: select(policy.development),\n\t};\n\treturn { publication, errors };\n};\n\n/** The global symbols a build publishes for each target: its selected storage, logical IO and service channels. */\nexport const publishedSymbols = (\n\t{ plan, symbols }: EmissionContext,\n\trpcChannels: readonly ServiceChannel[],\n): Publication => {\n\tconst logicalIo = plan.core.variables\n\t\t.filter(isLogicalIo)\n\t\t.map((variable) => variable.id);\n\tconst rpcSymbols = [\n\t\t...new Set(\n\t\t\trpcChannels.flatMap((channel) =>\n\t\t\t\t[\n\t\t\t\t\tchannel.request,\n\t\t\t\t\tchannel.requestId,\n\t\t\t\t\tchannel.reply,\n\t\t\t\t\tchannel.replyId,\n\t\t\t\t\tchannel.epoch,\n\t\t\t\t].map((path) => path.replace(/\\[\\d+\\]$/, \"\")),\n\t\t\t),\n\t\t),\n\t];\n\tconst published = (ids: readonly string[]) =>\n\t\t[...ids, ...logicalIo]\n\t\t\t.map((id) => required(symbols.references.get(id)))\n\t\t\t.concat(rpcSymbols);\n\treturn {\n\t\tproduction: published(plan.publication.production),\n\t\tdevelopment: published(plan.publication.development),\n\t};\n};\n",
40
+ "import {\n\tcoreTables,\n\ttype Task,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport { nanosecondsPerMillisecond } from \"@tsplc/iec\";\nimport type { Report } from \"./plan\";\nimport { accessedStorage } from \"./task-access\";\n\n/** The deployment's tasks, then one per background interval and priority, with detached continuations added after their callers. */\nexport function schedulePrograms(\n\tcore: VerifiedCoreModule,\n\ttasks: readonly Task[],\n\treport: Report,\n): readonly Task[] {\n\tconst background = new Map<string, Task & { programs: string[] }>();\n\tfor (const program of core.programs) {\n\t\tif (!program.background) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst { priority, intervalNanoseconds } = program.background;\n\t\tconst name = `TsplcBackground_${priority}_${BigInt(intervalNanoseconds) / nanosecondsPerMillisecond}`;\n\t\tconst existing = background.get(name);\n\t\tif (existing) {\n\t\t\texisting.programs.push(program.name);\n\t\t\tcontinue;\n\t\t}\n\t\tbackground.set(name, {\n\t\t\tname,\n\t\t\tpriority,\n\t\t\tintervalNanoseconds,\n\t\t\tprograms: [program.name],\n\t\t});\n\t}\n\treturn appendContinuations(core, [...tasks, ...background.values()], report);\n}\n\n/** Detached continuations run after their caller programs in the same cyclic task. */\nfunction appendContinuations(\n\tcore: VerifiedCoreModule,\n\ttasks: readonly Task[],\n\treport: Report,\n): readonly Task[] {\n\tconst continuations = core.programs.flatMap((program) =>\n\t\tprogram.continuation\n\t\t\t? [{ name: program.name, scope: program.continuation }]\n\t\t\t: [],\n\t);\n\tif (!continuations.length) {\n\t\treturn tasks;\n\t}\n\n\tconst { functionOf } = coreTables(core);\n\t// The deployment's program names are checked after scheduling, so an unknown one is skipped here.\n\tconst programs = new Map(\n\t\tcore.programs.map((program) => [program.name, program]),\n\t);\n\tconst placements = tasks.map(\n\t\t(task): { task: Task; roots: Set<string>; additions: string[] } => ({\n\t\t\ttask,\n\t\t\troots: new Set(\n\t\t\t\ttask.programs.flatMap((name) => {\n\t\t\t\t\tconst program = programs.get(name);\n\t\t\t\t\treturn !program || program.background\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: [...accessedStorage(functionOf(program.entry), core)];\n\t\t\t\t}),\n\t\t\t),\n\t\t\tadditions: [],\n\t\t}),\n\t);\n\tfor (const { name, scope } of continuations) {\n\t\tconst root = core.variables.find(\n\t\t\t(variable) =>\n\t\t\t\tvariable.name === scope.instance && variable.span.file === scope.file,\n\t\t);\n\t\tif (!root) {\n\t\t\treport(`Missing continuation owner ${scope.instance}.`);\n\t\t\tcontinue;\n\t\t}\n\t\tconst owners = placements.filter(({ roots }) => roots.has(root.id));\n\t\tconst [owner] = owners;\n\t\tif (!owner || owners.length !== 1) {\n\t\t\treport(\n\t\t\t\t`Continuation owner ${scope.instance} must belong to exactly one caller task.`,\n\t\t\t\troot.span,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\towner.additions.push(name);\n\t}\n\treturn placements.map(({ task, additions }) => ({\n\t\t...task,\n\t\tprograms: task.programs.concat(additions),\n\t}));\n}\n",
41
+ "import {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\tcoreTables,\n\ttype GeneratedObject,\n\tinstancedBlock,\n\tisBlockRoutine,\n\ttype SourceSpan,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport { instrumentationFields } from \"@tsplc/debug/manifest\";\nimport { type StorageScope, storageName } from \"./expressions\";\nimport { jobField, jobTracking, type RoutineProbes } from \"./instrumentation\";\nimport { required } from \"./required\";\nimport type { ObjectMapping } from \"./st-files\";\nimport {\n\tnoResult,\n\ttype RoutineWriter,\n\twriteAcquire,\n\twriteRelease,\n\twriteStatements,\n} from \"./statements\";\nimport {\n\ttype CodesysSymbols,\n\ttype EmissionContext,\n\towningBlock,\n} from \"./symbols\";\n\nfunction routineHeader(\n\tsymbols: CodesysSymbols,\n\tfn: CoreFunction | CoreFunctionBlock,\n\tname: string,\n): { kind: GeneratedObject[\"kind\"]; declaration: string } {\n\tif (isBlockRoutine(fn)) {\n\t\treturn { kind: \"functionBlock\", declaration: `FUNCTION_BLOCK ${name}` };\n\t}\n\tif (fn.owner) {\n\t\treturn {\n\t\t\tkind: \"method\",\n\t\t\tdeclaration: `METHOD ${fn.owner.access.toUpperCase()} ${name}${fn.result ? ` : ${symbols.targetTypes.name(fn.result)}` : \"\"}`,\n\t\t};\n\t}\n\tif (symbols.programRoutines.has(fn.id)) {\n\t\treturn { kind: \"program\", declaration: `PROGRAM ${name}` };\n\t}\n\treturn {\n\t\tkind: \"function\",\n\t\tdeclaration: `FUNCTION ${name} : ${fn.result ? symbols.targetTypes.name(fn.result) : noResult.type}`,\n\t};\n}\n\n/** A function, function block or method: its declaration, its body and, for a tracked job, its tracking method. */\nexport function emitRoutine(\n\tcontext: EmissionContext,\n\tfn: CoreFunction | CoreFunctionBlock,\n): { objects: GeneratedObject[]; mappings: ObjectMapping[] } {\n\tconst { plan, symbols, instrumentation } = context;\n\tconst { targetTypes, typeMap } = symbols;\n\tconst mappings: ObjectMapping[] = [];\n\tconst block = isBlockRoutine(fn) ? fn : undefined;\n\tconst method = isBlockRoutine(fn) ? undefined : fn.owner;\n\tconst program = symbols.programRoutines.has(fn.id);\n\tconst owner = owningBlock(symbols, fn);\n\tconst name = block\n\t\t? required(symbols.blockNames.get(block.id))\n\t\t: required(symbols.functionNames.get(fn.id));\n\tconst inputs = isBlockRoutine(fn) ? fn.inputs : fn.parameters;\n\tconst map = (\n\t\tfile: ObjectMapping[\"file\"],\n\t\tline: number,\n\t\tspan: SourceSpan,\n\t): void => {\n\t\tmappings.push({ object: fn.id, file, line, span });\n\t};\n\tconst scope = required(symbols.routineScopes.get(fn.id));\n\tconst storage: StorageScope = {\n\t\tsymbols,\n\t\tnames: new Map([...symbols.references, ...scope.references]),\n\t\tvariableOf: coreTables(plan.core).variableOf,\n\t};\n\tconst temporaries = fn.locals.map((item) => ({\n\t\tdeclaration: ` ${storageName(storage, item.id)} : ${targetTypes.name(item.type)};`,\n\t\tspan: item.span,\n\t}));\n\tconst declare = (declaration: string, span: SourceSpan): void => {\n\t\ttemporaries.push({ declaration, span });\n\t};\n\tconst mutex =\n\t\tmethod && owner?.runtime?.kind === \"mailbox\"\n\t\t\t? required(symbols.mailboxLocks.get(owner.id))\n\t\t\t: undefined;\n\tconst lines: string[] = [];\n\tconst probes: RoutineProbes = {\n\t\tcontext,\n\t\tstorage,\n\t\ttask: instrumentation.analysis.tasks.get(fn.id),\n\t};\n\tconst tracked = block && instrumentation.fields.get(block.id);\n\tconst routine: RoutineWriter = {\n\t\tcontext,\n\t\tfn,\n\t\tname,\n\t\tblock,\n\t\towner,\n\t\tmethod: method !== undefined,\n\t\tprogram,\n\t\tstorage,\n\t\tprobes,\n\t\tlocals: scope.names,\n\t\tmutex,\n\t\ttracked,\n\t\twrite: (line, depth, source) => {\n\t\t\tlines.push(\" \".repeat(depth) + line);\n\t\t\tif (source) {\n\t\t\t\tmap(\"implementation\", lines.length, source);\n\t\t\t}\n\t\t},\n\t\tdeclare,\n\t};\n\tconst { write } = routine;\n\n\tif (mutex) {\n\t\twriteAcquire(routine);\n\t}\n\tif (block && tracked?.track) {\n\t\t// Before the job's own early return, so a job started since its last call is seen.\n\t\twrite(`${tracked.track}();`, 0);\n\t\tif (tracked.step) {\n\t\t\twrite(`${tracked.step} := ${jobField(storage, block, \"step\")};`, 0);\n\t\t}\n\t}\n\twriteStatements(routine, fn.body, 0);\n\tif (tracked?.track) {\n\t\twrite(`${tracked.track}();`, 0);\n\t}\n\tif (mutex) {\n\t\twriteRelease(routine, 0);\n\t}\n\tif (!block && !method && !program && !fn.result) {\n\t\twrite(`${name} := ${noResult.value};`, 0);\n\t}\n\n\tconst header = routineHeader(symbols, fn, name);\n\tconst declaration = [header.declaration];\n\tmap(\"declaration\", 1, fn.span);\n\tconst section = (keyword: string, items: readonly Variable[]): void => {\n\t\tif (!items.length) {\n\t\t\treturn;\n\t\t}\n\t\tdeclaration.push(keyword);\n\t\tfor (const item of items) {\n\t\t\tmap(\"declaration\", declaration.length + 1, item.span);\n\t\t\tconst initial =\n\t\t\t\titem.initial && !instancedBlock(item.type, typeMap)\n\t\t\t\t\t? targetTypes.declarationInitializer(item.initial, item.type)\n\t\t\t\t\t: \"\";\n\t\t\tdeclaration.push(\n\t\t\t\t` ${storageName(storage, item.id)} : ${targetTypes.name(item.type)}${initial};`,\n\t\t\t);\n\t\t}\n\t\tdeclaration.push(\"END_VAR\");\n\t};\n\n\tsection(\n\t\t\"VAR_INPUT\",\n\t\tinputs.filter((item) => item.mode !== \"inOut\"),\n\t);\n\tsection(\n\t\t\"VAR_IN_OUT\",\n\t\tinputs.filter((item) => item.mode === \"inOut\"),\n\t);\n\tif (tracked?.job) {\n\t\tdeclaration.push(\n\t\t\t\"VAR_INPUT\",\n\t\t\t` ${tracked.job} : ${instrumentationFields.job};`,\n\t\t\t\"END_VAR\",\n\t\t);\n\t}\n\tif (program && !block && fn.result) {\n\t\tdeclaration.push(\n\t\t\t\"VAR_OUTPUT\",\n\t\t\t` ${required(symbols.programResults.get(fn.id))} : ${targetTypes.name(fn.result)};`,\n\t\t\t\"END_VAR\",\n\t\t);\n\t}\n\tif (block) {\n\t\tif (block.runtime?.kind === \"mailbox\") {\n\t\t\tdeclaration.push(\n\t\t\t\t\"VAR\",\n\t\t\t\t` ${required(symbols.mailboxLocks.get(block.id))} : __XWORD;`,\n\t\t\t\t\"END_VAR\",\n\t\t\t);\n\t\t}\n\t\tsection(\"VAR_OUTPUT\", block.outputs);\n\t\tsection(\n\t\t\t\"VAR\",\n\t\t\tblock.state.filter((item) => !symbols.retainedVariables.has(item.id)),\n\t\t);\n\t\tsection(\n\t\t\t\"VAR RETAIN\",\n\t\t\tblock.state.filter((item) => symbols.retainedVariables.has(item.id)),\n\t\t);\n\t\tconst fields = ([\"busy\", \"step\", \"startedAt\"] as const).flatMap((key) => {\n\t\t\tconst field = tracked?.[key];\n\t\t\treturn field ? [` ${field} : ${instrumentationFields[key]};`] : [];\n\t\t});\n\t\tif (fields.length) {\n\t\t\tdeclaration.push(\"VAR\", ...fields, \"END_VAR\");\n\t\t}\n\t}\n\tif (temporaries.length) {\n\t\tdeclaration.push(block || program ? \"VAR_TEMP\" : \"VAR\");\n\t\ttemporaries.forEach(({ span }, index) => {\n\t\t\tmap(\"declaration\", declaration.length + index + 1, span);\n\t\t});\n\t\tdeclaration.push(\n\t\t\t...temporaries.map((temporary) => temporary.declaration),\n\t\t\t\"END_VAR\",\n\t\t);\n\t}\n\n\tconst routineObject: GeneratedObject = {\n\t\tid: fn.id,\n\t\t...(method ? { parent: method.block } : {}),\n\t\tkind: header.kind,\n\t\tname,\n\t\tdeclaration: `${declaration.join(\"\\n\")}\\n`,\n\t\timplementation: `${lines.join(\"\\n\")}\\n`,\n\t};\n\tif (!block || !tracked?.track) {\n\t\treturn { objects: [routineObject], mappings };\n\t}\n\treturn {\n\t\tobjects: [\n\t\t\troutineObject,\n\t\t\t{\n\t\t\t\tid: `${fn.id}:${tracked.track}`,\n\t\t\t\tparent: fn.id,\n\t\t\t\tkind: \"method\",\n\t\t\t\tname: tracked.track,\n\t\t\t\tdeclaration: `METHOD PRIVATE ${tracked.track}\\n`,\n\t\t\t\timplementation: jobTracking(probes, block, tracked),\n\t\t\t},\n\t\t],\n\t\tmappings,\n\t};\n}\n",
42
+ "import {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\tcoreTables,\n\ttype GeneratedObject,\n\tinstanceFields,\n\tisBlockRoutine,\n\tstandardBlocks,\n} from \"@tsplc/compiler/ir\";\nimport { planGlobalNames } from \"./global-names\";\nimport type { BlockInstrumentation, Instrumentation } from \"./instrumentation\";\nimport { Names } from \"./names\";\nimport { NumericLowering } from \"./numeric\";\nimport type { CodesysPlan } from \"./plan\";\nimport { required } from \"./required\";\nimport { planScanClock } from \"./scan-clock\";\nimport { accessedStorage } from \"./task-access\";\n\n/** The names a routine's ST gives its parameters, locals and the block state it reaches. */\nexport interface RoutineScope {\n\tnames: Names;\n\treferences: ReadonlyMap<string, string>;\n}\n\n/** The names fixed before emission: objects of types, blocks, storage lists and routines that hold state. */\nexport type GlobalSymbols = ReturnType<typeof globalSymbols>;\n\n/**\n * The target names of a program: its objects, storage, routines and block fields. `emitCodesys`\n * allocates them in emission order, each scope reserving the objects emitted before it, and they\n * are complete before any routine body is written.\n */\nexport type CodesysSymbols = GlobalSymbols & {\n\t/** The global symbol of each module variable and logical IO. */\n\treferences: ReadonlyMap<string, string>;\n\tfunctionNames: ReadonlyMap<string, string>;\n\tprogramResults: ReadonlyMap<string, string>;\n\tmailboxLocks: ReadonlyMap<string, string>;\n\tblockFields: ReadonlyMap<string, ReadonlyMap<string, string>>;\n\troutineScopes: ReadonlyMap<string, RoutineScope>;\n};\n\n/** A plan with the target names and instrumentation allocated for it: what each emitter reads. */\nexport interface EmissionContext {\n\tplan: CodesysPlan;\n\tsymbols: CodesysSymbols;\n\tinstrumentation: Instrumentation;\n}\n\nexport function globalSymbols(plan: CodesysPlan) {\n\tconst { core } = plan;\n\tconst persistent = new Set(\n\t\tcore.variables\n\t\t\t.filter((item) => item.storage !== \"constant\")\n\t\t\t.map((item) => item.id),\n\t);\n\tconst programRoutines: ReadonlySet<string> = new Set(\n\t\tcore.functions\n\t\t\t.filter(\n\t\t\t\t(fn) =>\n\t\t\t\t\t!fn.owner &&\n\t\t\t\t\t[...accessedStorage(fn, core)].some((id) => persistent.has(id)),\n\t\t\t)\n\t\t\t.map((fn) => fn.id),\n\t);\n\tconst globalNames = planGlobalNames(core, plan.programNames);\n\tconst scanClock = planScanClock(\n\t\tcore,\n\t\tplan.deployment.tasks,\n\t\tglobalNames.names,\n\t);\n\treturn {\n\t\t...globalNames,\n\t\tblocks: coreTables(core).blocks,\n\t\tscanClock,\n\t\tnumeric: new NumericLowering(\n\t\t\tglobalNames.typeMap,\n\t\t\t(label) => globalNames.names.allocate(label),\n\t\t\tscanClock?.now,\n\t\t),\n\t\tprogramRoutines,\n\t};\n}\n\n/** The object name of each function that is not a method. */\nexport function allocateFunctionNames(\n\t{ core }: CodesysPlan,\n\tsymbols: GlobalSymbols,\n): Map<string, string> {\n\tconst entries = new Set(core.programs.map((program) => program.entry));\n\treturn new Map(\n\t\tcore.functions\n\t\t\t.filter((fn) => !fn.owner)\n\t\t\t.map((fn) => {\n\t\t\t\tconst program = symbols.programRoutines.has(fn.id);\n\t\t\t\tconst label =\n\t\t\t\t\tprogram && entries.has(fn.id) ? `${fn.name}_body` : fn.name;\n\t\t\t\treturn [\n\t\t\t\t\tfn.id,\n\t\t\t\t\tsymbols.names.allocateObject(program ? \"PRG\" : \"F\", label),\n\t\t\t\t];\n\t\t\t}),\n\t);\n}\n\n/**\n * The names a routine's or block's own scope must not shadow: the objects emitted so far, the\n * debug global, and every routine and block named so far.\n */\nconst scopeNames = (\n\tsymbols: Pick<CodesysSymbols, \"functionNames\" | \"blockNames\">,\n\tobjects: readonly GeneratedObject[],\n\tglobal: string,\n): Names =>\n\tnew Names([\n\t\t...objects.map((object) => object.name),\n\t\tglobal,\n\t\t...symbols.functionNames.values(),\n\t\t...symbols.blockNames.values(),\n\t]);\n\n/**\n * Each block's field names, its methods' names and its mailbox lock, and the instrumentation fields\n * of the blocks that have any. A block's scope reserves the names of the functions that are not\n * methods.\n */\nexport function allocateBlockMembers(\n\tplan: CodesysPlan,\n\tsymbols: GlobalSymbols & Pick<CodesysSymbols, \"functionNames\">,\n\tinstrumentation: Pick<Instrumentation, \"global\" | \"analysis\">,\n\tobjects: readonly GeneratedObject[],\n) {\n\tconst { core } = plan;\n\tconst fields = new Map<string, ReadonlyMap<string, string>>();\n\tconst methods = new Map<string, string>();\n\tconst mailboxLocks = new Map<string, string>();\n\tconst instrumented = new Map<string, BlockInstrumentation>();\n\tfor (const block of core.blocks) {\n\t\tconst names = scopeNames(symbols, objects, instrumentation.global);\n\t\tfor (const method of core.functions.filter(\n\t\t\t(fn) => fn.owner?.block === block.id,\n\t\t)) {\n\t\t\tmethods.set(method.id, names.allocate(method.name));\n\t\t}\n\t\tconst native = block.standard && standardBlocks[block.standard];\n\t\tfields.set(\n\t\t\tblock.id,\n\t\t\tnew Map(\n\t\t\t\tinstanceFields(block).map((item) => [\n\t\t\t\t\titem.id,\n\t\t\t\t\tnative\n\t\t\t\t\t\t? required(\n\t\t\t\t\t\t\t\t[...native.inputs, ...native.outputs].find(\n\t\t\t\t\t\t\t\t\t([name]) => name === item.name,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)[1]\n\t\t\t\t\t\t: names.allocate(item.name),\n\t\t\t\t]),\n\t\t\t),\n\t\t);\n\t\tif (block.runtime?.kind === \"mailbox\") {\n\t\t\tmailboxLocks.set(block.id, names.allocate(\"plc_mailbox_lock\"));\n\t\t}\n\n\t\tconst settings = plan.project.debug;\n\t\t// Trace sites and an unhandled failure need the step a job finished at.\n\t\tconst stepped =\n\t\t\tinstrumentation.analysis.jobSites.has(block.id) ||\n\t\t\tplan.telemetry?.failures.has(block.id);\n\t\tconst tracked = Boolean(block.job && (settings?.jobs || stepped));\n\t\tconst carries =\n\t\t\tsettings?.jobs && instrumentation.analysis.carriers.has(block.id);\n\t\tif (tracked || carries) {\n\t\t\tinstrumented.set(block.id, {\n\t\t\t\t...(tracked && {\n\t\t\t\t\tbusy: names.allocate(\"tsplcBusy\"),\n\t\t\t\t\ttrack: names.allocate(\"TsplcTrack\"),\n\t\t\t\t}),\n\t\t\t\t...(tracked &&\n\t\t\t\t\tsettings?.jobs && { startedAt: names.allocate(\"startedAt\") }),\n\t\t\t\t...(stepped && { step: names.allocate(\"tsplcStep\") }),\n\t\t\t\t...(carries && { job: names.allocate(\"requestJob\") }),\n\t\t\t\t...(carries &&\n\t\t\t\t\tblock.runtime?.kind === \"http\" && {\n\t\t\t\t\t\tsequence: names.allocate(\"sequence\"),\n\t\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t}\n\treturn { fields, methods, mailboxLocks, instrumented };\n}\n\n/** The names a routine's ST gives its parameters, locals and block state, and a stateful program's result. */\nexport function allocateRoutineScope(\n\tsymbols: GlobalSymbols &\n\t\tPick<CodesysSymbols, \"functionNames\" | \"blockFields\">,\n\tobjects: readonly GeneratedObject[],\n\tglobal: string,\n\tfn: CoreFunction | CoreFunctionBlock,\n): { scope: RoutineScope; result?: string } {\n\tconst block = isBlockRoutine(fn) ? fn : undefined;\n\tconst owner = owningBlock(symbols, fn);\n\tconst names = scopeNames(symbols, objects, global);\n\tconst references = new Map<string, string>();\n\tconst result =\n\t\t!block && symbols.programRoutines.has(fn.id) && fn.result\n\t\t\t? names.allocate(\"plc_result\")\n\t\t\t: undefined;\n\tif (owner) {\n\t\tfor (const item of [...owner.outputs, ...owner.state]) {\n\t\t\tconst name = required(\n\t\t\t\trequired(symbols.blockFields.get(owner.id)).get(item.id),\n\t\t\t);\n\t\t\tnames.reserve(name);\n\t\t\treferences.set(item.id, name);\n\t\t}\n\t}\n\tfor (const item of isBlockRoutine(fn) ? fn.inputs : fn.parameters) {\n\t\tconst name = block\n\t\t\t? required(required(symbols.blockFields.get(block.id)).get(item.id))\n\t\t\t: names.allocate(item.name);\n\t\tnames.reserve(name);\n\t\treferences.set(item.id, name);\n\t}\n\tfor (const item of fn.locals) {\n\t\treferences.set(item.id, names.allocate(item.name));\n\t}\n\treturn { scope: { names, references }, ...(result && { result }) };\n}\n\n/** The block whose state a routine reaches: the block itself, or a method's block. */\nexport const owningBlock = (\n\tsymbols: GlobalSymbols,\n\tfn: CoreFunction | CoreFunctionBlock,\n): CoreFunctionBlock | undefined => {\n\tif (isBlockRoutine(fn)) {\n\t\treturn fn;\n\t}\n\treturn fn.owner && required(symbols.blocks.get(fn.owner.block));\n};\n",
43
+ "import {\n\tcoreTables,\n\tpascalCase,\n\tstandardBlocks,\n\ttype VerifiedCoreModule,\n} from \"@tsplc/compiler/ir\";\nimport { Names } from \"./names\";\nimport { storageLayout } from \"./storage\";\nimport { CodesysTypes } from \"./types\";\n\nexport const planGlobalNames = (\n\tcore: VerifiedCoreModule,\n\tprogramNames: ReadonlyMap<string, string>,\n) => {\n\tconst names = new Names(programNames.values());\n\tconst typeMap = coreTables(core).types;\n\tconst blockNames = new Map(\n\t\tcore.blocks.map((block) => [\n\t\t\tblock.id,\n\t\t\tblock.standard\n\t\t\t\t? standardBlocks[block.standard].native\n\t\t\t\t: names.allocateObject(\"FB\", block.name),\n\t\t]),\n\t);\n\tfor (const name of blockNames.values()) {\n\t\tnames.reserve(name);\n\t}\n\tconst targetTypes = new CodesysTypes(typeMap, names, blockNames);\n\n\tconst { globalLists, retainedVariables } = storageLayout(core);\n\tconst hasExports = (group: (typeof globalLists)[number]) =>\n\t\tgroup.variables.some((variable) => variable.exported);\n\tconst globals = globalLists.map((group) => {\n\t\tconst splitByStorage = globalLists.some(\n\t\t\t(other) =>\n\t\t\t\tother.module === group.module &&\n\t\t\t\tother.kind !== group.kind &&\n\t\t\t\thasExports(other),\n\t\t);\n\t\t// Exported lists are the program's public interface. Private storage stays generated.\n\t\tconst name = hasExports(group)\n\t\t\t? names.allocate(\n\t\t\t\t\tpascalCase(\n\t\t\t\t\t\tsplitByStorage ? `${group.module}-${group.kind}` : group.module,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t: names.allocateObject(\"GVL\", `${group.module}_${group.kind}`);\n\t\tconst fields = new Names(blockNames.values());\n\t\treturn {\n\t\t\t...group,\n\t\t\tname,\n\t\t\tfields: new Map(\n\t\t\t\tgroup.variables.map((item) => [item.id, fields.allocate(item.name)]),\n\t\t\t),\n\t\t};\n\t});\n\n\treturn {\n\t\tnames,\n\t\ttypeMap,\n\t\tblockNames,\n\t\ttargetTypes,\n\t\tglobals,\n\t\tretainedVariables,\n\t};\n};\n",
44
+ "import type { EmitResult } from \"@tsplc/compiler/ir\";\nimport { emittedFiles } from \"@tsplc/config/project-files\";\nimport { type ServiceChannel, serviceChannelSchema } from \"@tsplc/server/wire\";\nimport { publicComment } from \"@tsplc/typegen\";\nimport { z } from \"zod\";\n\n/** `machines.ts`, which lists the service channels for the server and the Bun runtime to read back. */\nexport const serviceChannelsFile = (\n\tchannels: readonly ServiceChannel[],\n): EmitResult[\"artifacts\"][number] => ({\n\tpath: emittedFiles.machines,\n\tcontent: `// Generated service channels. Do not edit.\\n${publicComment}export const serviceChannels=${JSON.stringify(channels, null, 2)} as const;\\n`,\n});\n\n/** The service channels a `machines.ts` lists. */\nexport const parseServiceChannels = (machines: string): ServiceChannel[] => {\n\tconst listed = /export const serviceChannels=([\\s\\S]*?) as const;/.exec(\n\t\tmachines,\n\t);\n\tif (!listed?.[1]) {\n\t\tthrow new Error(`${emittedFiles.machines} lists no service channels.`);\n\t}\n\treturn z.array(serviceChannelSchema).parse(JSON.parse(listed[1]));\n};\n",
45
+ "import type {\n\tEmitResult,\n\tGeneratedObject,\n\tSourceSpan,\n} from \"@tsplc/compiler/ir\";\nimport { generatedDirectory } from \"@tsplc/config/project-files\";\nimport type { SourceMapping } from \"./emit\";\nimport { required } from \"./required\";\nimport { sourceFolders } from \"./sources\";\nimport { moduleFile } from \"./storage\";\nimport type { EmissionContext } from \"./symbols\";\n\n/**\n * A line of an object's file that a source span produced, before `stFiles` places the object.\n * `object` is the object's id.\n */\nexport interface ObjectMapping {\n\tobject: string;\n\tfile: \"declaration\" | \"implementation\";\n\tline: number;\n\tspan: SourceSpan;\n}\n\n/** An object with the files `stFiles` wrote it to. */\nexport type PlacedObject = GeneratedObject & {\n\t/** Its only file, or `declaration.st` beside its implementation. */\n\tsourcePath: string;\n\timplementationPath?: string;\n\t/** Its path below the Application in the CODESYS project, which keeps methods beside their block. */\n\tnativePath: string;\n};\n\n/**\n * Writes each object to its ST files, in its source module's folder: an object without an\n * implementation is one `.st` file, any other a folder with `declaration.st` and\n * `implementation.st`. Returns the objects with their files and each mapping at its file.\n */\nexport function stFiles(\n\tcontext: EmissionContext,\n\tobjects: readonly GeneratedObject[],\n\tmappings: readonly ObjectMapping[],\n): {\n\tartifacts: EmitResult[\"artifacts\"];\n\tobjects: PlacedObject[];\n\tmappings: SourceMapping[];\n} {\n\tconst paths = objectPaths(context, objects);\n\tconst placed = objects.map((object): PlacedObject => {\n\t\tconst { path, nativePath } = paths(object);\n\t\treturn object.implementation === undefined\n\t\t\t? { ...object, sourcePath: `${path}.st`, nativePath }\n\t\t\t: {\n\t\t\t\t\t...object,\n\t\t\t\t\tsourcePath: `${path}/declaration.st`,\n\t\t\t\t\timplementationPath: `${path}/implementation.st`,\n\t\t\t\t\tnativePath,\n\t\t\t\t};\n\t});\n\tconst owners = new Map(placed.map((object) => [object.id, object]));\n\treturn {\n\t\tartifacts: placed.flatMap((object) => [\n\t\t\t{ path: object.sourcePath, content: object.declaration },\n\t\t\t...(object.implementation === undefined\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: required(object.implementationPath),\n\t\t\t\t\t\t\tcontent: object.implementation,\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t]),\n\t\tobjects: placed,\n\t\tmappings: mappings.map(({ object, file, line, span }) => {\n\t\t\tconst owner = required(owners.get(object));\n\t\t\treturn {\n\t\t\t\tpath:\n\t\t\t\t\tfile === \"implementation\"\n\t\t\t\t\t\t? required(owner.implementationPath)\n\t\t\t\t\t\t: owner.sourcePath,\n\t\t\t\tline,\n\t\t\t\tspan,\n\t\t\t};\n\t\t}),\n\t};\n}\n\n/**\n * The folder of an object that no source module places. The IO list is generated too, and a\n * folder of its own could share a name with a program's state list (`io` gives `Io`).\n */\nconst generatedFolder = (object: GeneratedObject) =>\n\tobject.kind === \"dataType\" ? \"Types\" : \"_Generated\";\n\n/** The module an object was emitted from, as the id of its symbol, program entry or variables names it. */\nconst sourceModules = ({ plan, symbols }: EmissionContext) => {\n\tconst groups = new Map(symbols.globals.map((group) => [group.id, group]));\n\tconst programs = new Map(\n\t\tplan.core.programs.map((program) => [program.id, program]),\n\t);\n\treturn (object: GeneratedObject): string => {\n\t\tconst group = groups.get(object.id);\n\t\tif (group) {\n\t\t\t// Variable IDs are relative to tsconfig, unlike their diagnostic spans.\n\t\t\treturn moduleFile(required(group.variables[0]).id);\n\t\t}\n\t\treturn moduleFile(programs.get(object.id)?.entry ?? object.id);\n\t};\n};\n\n/**\n * Each object's path without extension, in its source module's folder or its block's for a\n * method, and its path in the CODESYS project, where a method sits directly below its block.\n */\nfunction objectPaths(\n\tcontext: EmissionContext,\n\tobjects: readonly GeneratedObject[],\n): (object: GeneratedObject) => { path: string; nativePath: string } {\n\tconst byId = new Map(objects.map((item) => [item.id, item]));\n\tconst sourceModule = sourceModules(context);\n\tconst objectPath = (\n\t\tobject: GeneratedObject,\n\t): { path: string; nativePath: string } => {\n\t\tif (object.kind === \"method\") {\n\t\t\tconst parent = objectPath(required(byId.get(required(object.parent))));\n\t\t\treturn {\n\t\t\t\tpath: `${parent.path}/methods/${object.name}`,\n\t\t\t\tnativePath: `${parent.nativePath}/${object.name}`,\n\t\t\t};\n\t\t}\n\t\tconst folders = required(placed.get(object));\n\t\tconst path = [folderPath(folders), object.name].filter(Boolean).join(\"/\");\n\t\treturn { path, nativePath: path };\n\t};\n\tconst placedFolders = (object: GeneratedObject): string[] => {\n\t\tconst folders = sourceFolders(\n\t\t\tcontext.plan.project.root,\n\t\t\tsourceModule(object),\n\t\t);\n\t\tif (!folders) {\n\t\t\treturn [generatedFolder(object)];\n\t\t}\n\t\t// A plain program's state lists and types are generated beside its entry module, whose\n\t\t// folder they belong in: CODESYS would show the hidden directory as a folder of its own.\n\t\tif (folders.at(-1) === generatedDirectory) {\n\t\t\treturn folders.slice(0, -1);\n\t\t}\n\t\t// A DUT directory can also contain sibling input/output layouts. Keep\n\t\t// that directory for every DUT, or its primary type would block the folder.\n\t\treturn object.kind !== \"dataType\" && folders.at(-1) === object.name\n\t\t\t? folders.slice(0, -1)\n\t\t\t: folders;\n\t};\n\tconst placed = new Map(\n\t\tobjects\n\t\t\t.filter((object) => object.kind !== \"method\")\n\t\t\t.map((object) => [object, placedFolders(object)]),\n\t);\n\tconst folderPath = separatedFolders(\n\t\t[...placed].map(([object, folders]) => ({ folders, name: object.name })),\n\t);\n\treturn objectPath;\n}\n\n/**\n * Each folder's path once no folder shares its name with an object beside it. CODESYS refuses that,\n * ignoring case, as when a module's folder is named like an object another module places next to it:\n * the folder takes the next free numbered name. Folders only organize the project, so no IEC name changes.\n */\nexport function separatedFolders(\n\tobjects: readonly { folders: readonly string[]; name: string }[],\n): (folders: readonly string[]) => string {\n\tconst childrenOf = (entries: Iterable<readonly [string, string]>) => {\n\t\tconst children = new Map<string, Set<string>>();\n\t\tfor (const [parent, name] of entries) {\n\t\t\tconst names = children.get(parent) ?? new Set<string>();\n\t\t\tnames.add(name.toLowerCase());\n\t\t\tchildren.set(parent, names);\n\t\t}\n\t\treturn (parent: string) => children.get(parent) ?? new Set<string>();\n\t};\n\tconst objectsIn = childrenOf(\n\t\tobjects.map(({ folders, name }) => [folders.join(\"/\"), name] as const),\n\t);\n\tconst foldersIn = childrenOf(\n\t\tobjects.flatMap(({ folders }) =>\n\t\t\tfolders.map((name, depth) => [folders.slice(0, depth).join(\"/\"), name]),\n\t\t),\n\t);\n\tconst renamed = new Map<string, string>();\n\tconst given = new Map<string, Set<string>>();\n\tconst folderPath = (folders: readonly string[]): string => {\n\t\tconst key = folders.join(\"/\");\n\t\tconst known = renamed.get(key);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\tif (folders.length === 0) {\n\t\t\treturn \"\";\n\t\t}\n\t\tconst parentKey = folders.slice(0, -1).join(\"/\");\n\t\tconst name = required(folders.at(-1));\n\t\tconst taken = given.get(parentKey) ?? new Set<string>();\n\t\tgiven.set(parentKey, taken);\n\t\tconst blocked = (candidate: string) =>\n\t\t\tobjectsIn(parentKey).has(candidate.toLowerCase()) ||\n\t\t\ttaken.has(candidate.toLowerCase()) ||\n\t\t\t(candidate !== name && foldersIn(parentKey).has(candidate.toLowerCase()));\n\t\tconst free = (count: number): string =>\n\t\t\tblocked(`${name}_${count}`) ? free(count + 1) : `${name}_${count}`;\n\t\tconst chosen = blocked(name) ? free(2) : name;\n\t\ttaken.add(chosen.toLowerCase());\n\t\tconst path = [folderPath(folders.slice(0, -1)), chosen]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\"/\");\n\t\trenamed.set(key, path);\n\t\treturn path;\n\t};\n\treturn folderPath;\n}\n",
46
+ "import { CodesysCompilerError } from \"@tsplc/build\";\nimport type { Diagnostic } from \"@tsplc/compiler/ir\";\nimport type { CodesysBundle } from \"./emit\";\n\ntype MappedBundle = Pick<CodesysBundle, \"objects\" | \"mappings\">;\n\n/** An object's path below the Application, when the vendor's identity of it proves one. */\nconst applicationObjectPath = (\n\tidentity: NonNullable<CodesysCompilerError[\"diagnostics\"][number][\"object\"]>,\n): string | undefined => {\n\tif (identity.path.at(-1) !== identity.name) {\n\t\treturn undefined;\n\t}\n\tconst relative = identity.applicationPath;\n\tif (\n\t\trelative?.length &&\n\t\tidentity.isApplicationChild === (relative.length === 1) &&\n\t\tidentity.path.length > relative.length &&\n\t\tidentity.path\n\t\t\t.slice(-relative.length)\n\t\t\t.every((part, index) => part === relative[index])\n\t) {\n\t\treturn relative.join(\"/\");\n\t}\n\tif (\n\t\trelative === undefined &&\n\t\tidentity.isApplicationChild === true &&\n\t\tidentity.path.length >= 2\n\t) {\n\t\treturn identity.name;\n\t}\n\treturn undefined;\n};\n\n/** Map verified vendor locations; preserve raw context for everything else. */\nexport function diagnoseCodesys(\n\tcause: unknown,\n\tbundle: MappedBundle,\n): readonly Diagnostic[] {\n\tconst notes: string[] = [];\n\tlet current = cause;\n\twhile (current instanceof Error) {\n\t\tif (current instanceof CodesysCompilerError && current.diagnostics.length) {\n\t\t\treturn current.diagnostics.map((item) => {\n\t\t\t\t// Observed in CODESYS 3.5 SP22. position itself is an opaque vendor value.\n\t\t\t\tconst location =\n\t\t\t\t\titem.positionText &&\n\t\t\t\t\t/^Line ([1-9][0-9]*)(?:, Column ([1-9][0-9]*))? \\((Decl|Impl)\\)$/.exec(\n\t\t\t\t\t\titem.positionText,\n\t\t\t\t\t);\n\t\t\t\tconst identity = item.object;\n\t\t\t\tconst objectPath = identity && applicationObjectPath(identity);\n\t\t\t\tconst objects = objectPath\n\t\t\t\t\t? bundle.objects.filter(\n\t\t\t\t\t\t\t(object) =>\n\t\t\t\t\t\t\t\tobject.name === identity?.name &&\n\t\t\t\t\t\t\t\tobject.nativePath === objectPath,\n\t\t\t\t\t\t)\n\t\t\t\t\t: [];\n\t\t\t\tconst match = objects.length === 1 ? objects[0] : undefined;\n\t\t\t\tconst path =\n\t\t\t\t\tlocation?.[3] === \"Decl\"\n\t\t\t\t\t\t? match?.sourcePath\n\t\t\t\t\t\t: match?.implementationPath;\n\t\t\t\tconst mappings =\n\t\t\t\t\tlocation && path\n\t\t\t\t\t\t? bundle.mappings.filter(\n\t\t\t\t\t\t\t\t(mapping) =>\n\t\t\t\t\t\t\t\t\tmapping.path === path && mapping.line === Number(location[1]),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: [];\n\t\t\t\tconst mapping = mappings.length === 1 ? mappings[0] : undefined;\n\t\t\t\treturn {\n\t\t\t\t\torigin: \"vendor\",\n\t\t\t\t\tcode: \"PLC8001\",\n\t\t\t\t\tseverity: \"error\",\n\t\t\t\t\tmessage: item.text,\n\t\t\t\t\t...(mapping && { span: mapping.span }),\n\t\t\t\t\tnotes: [\n\t\t\t\t\t\t...notes,\n\t\t\t\t\t\t...(location && path\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\"Generated ST: \" +\n\t\t\t\t\t\t\t\t\t\tpath +\n\t\t\t\t\t\t\t\t\t\t\":\" +\n\t\t\t\t\t\t\t\t\t\tlocation[1] +\n\t\t\t\t\t\t\t\t\t\t(location[2] ? `:${location[2]}` : \"\"),\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t`CODESYS diagnostic: ${JSON.stringify(item)}`,\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t\tnotes.push(current.message);\n\t\tif (current.cause === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tcurrent = current.cause;\n\t\tif (!(current instanceof Error)) {\n\t\t\tnotes.push(String(current));\n\t\t}\n\t}\n\treturn [\n\t\t{\n\t\t\torigin: \"vendor\",\n\t\t\tcode: \"PLC8001\",\n\t\t\tseverity: \"error\",\n\t\t\tmessage: cause instanceof Error ? cause.message : String(cause),\n\t\t\t...(notes.length > 1 && { notes: notes.slice(1) }),\n\t\t},\n\t];\n}\n"
47
+ ],
48
+ "mappings": ";AAAA,mCAAS;;;ACAT;AAAA;AAAA;AAAA;AAAA;AAMA;AACA,cAAS;;;ACPT,oBAAS;AACT;AAAA;AAAA;AAMA;AACA;;;ACRA;AAAA;AAAA;AAAA;AASA;AACA;AAAA;AAAA;AAAA;AAAA,kBAIC;AAAA;AAED;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AChBO,SAAS,QAAW,CAAC,OAAyB;AAAA,EACpD,IAAI,UAAU,WAAW;AAAA,IACxB,MAAM,IAAI,MAAM,kCAAkC;AAAA,EACnD;AAAA,EACA,OAAO;AAAA;;;ACLR;AACA;AAAA;AAAA;AAAA;AAAA;AAKA;;;ACPA;AAEO,SAAS,eAAe,CAAC,MAAuB;AAAA,EACtD,OACC,qBAAqB,KAAK,IAAI,KAC9B,CAAC,KAAK,SAAS,IAAI,KACnB,CAAC,eAAe,IAAI;AAAA;AAItB,IAAM,iBAAiB,CAAC,UACvB,MACE,QAAQ,kBAAkB,GAAG,EAC7B,QAAQ,OAAO,GAAG,EAClB,QAAQ,YAAY,EAAE,KAAK;AAAA;AAEvB,MAAM,MAAM;AAAA,EACD,OAAO,IAAI;AAAA,EAE5B,WAAW,CAAC,WAA6B,CAAC,GAAG;AAAA,IAC5C,WAAW,QAAQ,UAAU;AAAA,MAC5B,KAAK,QAAQ,IAAI;AAAA,IAClB;AAAA;AAAA,EAGD,cAAc,CACb,QACA,OACS;AAAA,IACT,MAAM,SAAS,WAAW,MAAM,MAAM,QAAQ,SAAS,EAAE,IAAI;AAAA,IAC7D,MAAM,OAAO,WAAW,OAAO,OAAO,WAAW,MAAM,IAAI,QAAQ;AAAA,IACnE,MAAM,OAAO,OAAO,WAAW,GAA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