@tsplc/compiler 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/backends/codesys/config.ts +54 -0
  4. package/backends/codesys/emit.ts +1063 -0
  5. package/backends/codesys/engineering.ts +88 -0
  6. package/backends/codesys/http.ts +598 -0
  7. package/backends/codesys/index.ts +12 -0
  8. package/backends/codesys/io-paths.ts +103 -0
  9. package/backends/codesys/names.ts +76 -0
  10. package/backends/codesys/numeric.ts +356 -0
  11. package/backends/codesys/plan.ts +512 -0
  12. package/backends/codesys/publication.ts +59 -0
  13. package/backends/codesys/storage.ts +63 -0
  14. package/backends/codesys/task-access.ts +118 -0
  15. package/backends/codesys/types.ts +178 -0
  16. package/backends/codesys/vendor.ts +108 -0
  17. package/dist/cli.js +740 -0
  18. package/dist/cli.js.map +13 -0
  19. package/dist/clock.js +8 -0
  20. package/dist/clock.js.map +10 -0
  21. package/dist/codesys.js +2587 -0
  22. package/dist/codesys.js.map +22 -0
  23. package/dist/elaborate-capture.js +118 -0
  24. package/dist/elaborate-capture.js.map +10 -0
  25. package/dist/index.js +6859 -0
  26. package/dist/index.js.map +25 -0
  27. package/dist/ir.js +1888 -0
  28. package/dist/ir.js.map +22 -0
  29. package/dist/math.js +24 -0
  30. package/dist/math.js.map +10 -0
  31. package/dist/project.js +423 -0
  32. package/dist/project.js.map +11 -0
  33. package/ir/aggregates.ts +333 -0
  34. package/ir/allocation.ts +74 -0
  35. package/ir/core-model.ts +116 -0
  36. package/ir/core.ts +63 -0
  37. package/ir/declarations.ts +201 -0
  38. package/ir/diagnostics.ts +43 -0
  39. package/ir/domains.ts +96 -0
  40. package/ir/index.ts +7 -0
  41. package/ir/link.ts +176 -0
  42. package/ir/model.ts +268 -0
  43. package/ir/normalization-error.ts +10 -0
  44. package/ir/routine.ts +826 -0
  45. package/ir/scalars.ts +675 -0
  46. package/ir/types.ts +70 -0
  47. package/package.json +105 -4
  48. package/project/artifacts.ts +277 -0
  49. package/project/cli.ts +282 -0
  50. package/project/index.ts +1 -0
  51. package/project/project.ts +298 -0
  52. package/project/server.ts +83 -0
  53. package/src/frontend/async.ts +1060 -0
  54. package/src/frontend/blocks.ts +419 -0
  55. package/src/frontend/configuration.ts +167 -0
  56. package/src/frontend/const-functions.ts +153 -0
  57. package/src/frontend/cooperative.ts +75 -0
  58. package/src/frontend/elaborate/capture.ts +138 -0
  59. package/src/frontend/elaborate/graph.ts +94 -0
  60. package/src/frontend/elaborate/index.ts +302 -0
  61. package/src/frontend/elaborate/layouts.ts +390 -0
  62. package/src/frontend/elaborate/model.ts +177 -0
  63. package/src/frontend/elaborate/specialize.ts +2280 -0
  64. package/src/frontend/exposure.ts +147 -0
  65. package/src/frontend/module-graph.ts +63 -0
  66. package/src/frontend/promises.ts +751 -0
  67. package/src/frontend/services.ts +435 -0
  68. package/src/frontend/types.ts +578 -0
  69. package/src/frontend/typescript.ts +2442 -0
  70. package/src/index.ts +7 -0
  71. package/stdlib/clock.ts +2 -0
  72. package/stdlib/math.ts +19 -0
  73. package/types/async.d.ts +81 -0
  74. package/types/clock.d.ts +4 -0
  75. package/types/config.d.ts +2 -0
  76. package/types/data-types.d.ts +31 -0
  77. package/types/globals.d.ts +40 -0
  78. package/types/index.d.ts +111 -0
  79. package/types/plc.d.ts +5 -0
package/dist/ir.js.map ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../ir/diagnostics.ts", "../ir/types.ts", "../ir/model.ts", "../ir/core-model.ts", "../ir/scalars.ts", "../ir/domains.ts", "../ir/aggregates.ts", "../ir/normalization-error.ts", "../ir/declarations.ts", "../ir/allocation.ts", "../ir/routine.ts", "../ir/link.ts", "../ir/core.ts"],
4
+ "sourcesContent": [
5
+ "export interface SourceSpan {\n file: string;\n start: number;\n end: number;\n line: number;\n column: number;\n}\n\nexport interface Diagnostic {\n origin: \"typescript\" | \"plc\" | \"config\" | \"backend\" | \"vendor\";\n code: string;\n severity: \"error\" | \"warning\";\n message: string;\n span?: SourceSpan;\n notes?: readonly string[];\n related?: readonly { span: SourceSpan; message: string }[];\n}\n\nexport function error(code: string, message: string, span?: SourceSpan): Diagnostic {\n return { origin: \"plc\", code, severity: \"error\", message, ...(span && { span }) };\n}\n\nexport function hasErrors(diagnostics: readonly Diagnostic[]): boolean {\n return diagnostics.some((diagnostic) => diagnostic.severity === \"error\");\n}\n\nexport function formatDiagnostic(diagnostic: Diagnostic, source?: string): string {\n const { span } = diagnostic;\n const location = span ? `${span.file}:${span.line}:${span.column}: ` : \"\";\n let result = `${location}${diagnostic.code}: ${diagnostic.message}`;\n if (source !== undefined && span) {\n const line = source.split(/\\r?\\n/)[span.line - 1];\n if (line !== undefined) {\n const width = Math.max(1, Math.min(span.end - span.start, line.length - span.column + 2));\n result += `\\n${span.line} | ${line}\\n${\" \".repeat(String(span.line).length + 3 + span.column - 1)}${\"^\".repeat(width)}`;\n }\n }\n for (const related of diagnostic.related ?? []) {\n result += `\\n ${related.span.file}:${related.span.line}:${related.span.column}: ${related.message}`;\n }\n for (const note of diagnostic.notes ?? []) result += `\\n ${note}`;\n return result;\n}\n",
6
+ "export type TypeId = string;\nexport type SymbolId = string;\n\nexport interface Field {\n name: string;\n type: TypeId;\n readonly: boolean;\n mode?: \"inOut\";\n}\n\nexport type PlcType =\n | { id: TypeId; kind: \"bool\" }\n | { id: TypeId; kind: \"integer\"; bits: 8 | 16 | 32 | 64; signed: boolean }\n | { id: TypeId; kind: \"bits\"; bits: 8 | 16 | 32 | 64 }\n | { id: TypeId; kind: \"float\"; bits: 32 | 64 }\n | { id: TypeId; kind: \"duration\" }\n | { id: TypeId; kind: \"calendar\"; domain: \"date\" | \"timeOfDay\" | \"dateTime\" }\n | { id: TypeId; kind: \"string\"; capacity: number; encoding: \"utf8\" | \"utf16\" }\n | {\n id: TypeId;\n kind: \"array\";\n element: TypeId;\n length: number;\n lowerBound: number;\n /** `Record<Enum, T>`: the enum whose contiguous member values are the bounds and the only indexes. */\n index?: TypeId;\n }\n | { id: TypeId; kind: \"record\"; fields: readonly Field[] }\n | { id: TypeId; kind: \"enum\"; base: TypeId; members: readonly { name: string; value: string }[] }\n | { id: TypeId; kind: \"block\"; block: SymbolId; output?: TypeId };\n\n/** The block allocated by a type: a block itself, or a fixed array of one. */\nexport const instancedBlock = (\n id: TypeId,\n types: ReadonlyMap<TypeId, PlcType>,\n): Extract<PlcType, { kind: \"block\" }> | undefined => {\n const type = types.get(id);\n const element = type?.kind === \"array\" ? types.get(type.element) : type;\n return element?.kind === \"block\" ? element : undefined;\n};\n\nexport const primitiveTypes: readonly PlcType[] = [\n { id: \"BOOL\", kind: \"bool\" },\n ...(\n [\n [\"SINT\", \"USINT\", \"BYTE\", 8],\n [\"INT\", \"UINT\", \"WORD\", 16],\n [\"DINT\", \"UDINT\", \"DWORD\", 32],\n [\"LINT\", \"ULINT\", \"LWORD\", 64],\n ] as const\n ).flatMap(([signed, unsigned, bitstring, bits]) => [\n { id: signed, kind: \"integer\" as const, bits, signed: true },\n { id: unsigned, kind: \"integer\" as const, bits, signed: false },\n { id: bitstring, kind: \"bits\" as const, bits },\n ]),\n { id: \"REAL\", kind: \"float\", bits: 32 },\n { id: \"LREAL\", kind: \"float\", bits: 64 },\n { id: \"TIME\", kind: \"duration\" },\n { id: \"DATE\", kind: \"calendar\", domain: \"date\" },\n { id: \"TIME_OF_DAY\", kind: \"calendar\", domain: \"timeOfDay\" },\n { id: \"DATE_AND_TIME\", kind: \"calendar\", domain: \"dateTime\" },\n];\n\nexport function integerRange(\n type: Extract<PlcType, { kind: \"integer\" | \"bits\" }>,\n): readonly [bigint, bigint] {\n const signed = type.kind === \"integer\" && type.signed;\n const limit = 1n << BigInt(type.bits - (signed ? 1 : 0));\n return signed ? [-limit, limit - 1n] : [0n, limit - 1n];\n}\n",
7
+ "import type { SourceSpan, Diagnostic } from \"./diagnostics.ts\";\nimport type { PlcType, SymbolId, TypeId } from \"./types.ts\";\n\nexport type Constant =\n | { kind: \"bool\"; value: boolean }\n | { kind: \"integer\"; value: string }\n | { kind: \"float\"; value: number }\n | { kind: \"duration\"; nanoseconds: string }\n | { kind: \"calendar\"; value: string }\n | { kind: \"string\"; value: string }\n | { kind: \"array\"; items: readonly Constant[] }\n | { kind: \"record\"; fields: Readonly<Record<string, Constant>> };\n\nexport interface Variable {\n id: SymbolId;\n name: string;\n type: TypeId;\n storage:\n | \"module\"\n | \"local\"\n | \"parameter\"\n | \"input\"\n | \"output\"\n | \"field\"\n | \"instance\"\n | \"constant\"\n | \"blockOutput\";\n mutable: boolean;\n retain: boolean;\n exported?: true;\n exposure?: { name: string; version: string };\n mode?: \"inOut\";\n initial?: Constant;\n span: SourceSpan;\n}\n\nexport interface Place {\n root: SymbolId;\n path: readonly ({ kind: \"field\"; name: string } | { kind: \"index\"; value: Expression })[];\n}\n\nexport type BinaryOperator =\n | \"add\"\n | \"subtract\"\n | \"multiply\"\n | \"divide\"\n | \"remainder\"\n | \"equal\"\n | \"notEqual\"\n | \"less\"\n | \"lessEqual\"\n | \"greater\"\n | \"greaterEqual\"\n | \"and\"\n | \"or\"\n | \"bitAnd\"\n | \"bitOr\"\n | \"bitXor\"\n | \"shiftLeft\"\n | \"shiftRight\";\n\nexport const comparisonOperators: ReadonlySet<BinaryOperator> = new Set([\n \"equal\",\n \"notEqual\",\n \"less\",\n \"lessEqual\",\n \"greater\",\n \"greaterEqual\",\n]);\n\nexport type Expression = { type: TypeId; span: SourceSpan } & (\n | { kind: \"constant\"; value: Constant }\n | { kind: \"load\"; place: Place }\n | {\n kind: \"unary\";\n operator: \"not\" | \"negate\" | \"bitNot\" | \"timeToMilliseconds\" | \"clock\";\n operand: Expression;\n }\n | {\n kind: \"binary\";\n operator: BinaryOperator;\n left: Expression;\n right: Expression;\n policy?: \"wrap\" | \"saturate\";\n }\n | {\n kind: \"call\";\n function: SymbolId;\n instance?: SymbolId;\n index?: Expression;\n arguments: readonly Expression[];\n }\n | { kind: \"conditional\"; condition: Expression; then: Expression; else: Expression }\n | { kind: \"convert\"; operand: Expression; policy: \"exact\" | \"wrap\" | \"saturate\" }\n | { kind: \"borrow\"; place: Place }\n | { kind: \"length\"; operand: Expression }\n | { kind: \"copy\"; operand: Expression }\n | { kind: \"record\"; fields: Readonly<Record<string, Expression>> }\n | { kind: \"array\"; items: readonly Expression[] }\n);\n\nexport type Statement = { span: SourceSpan } & (\n | { kind: \"assign\"; destination: Place; value: Expression }\n | { kind: \"if\"; condition: Expression; then: readonly Statement[]; else: readonly Statement[] }\n | {\n kind: \"switch\";\n value: Expression;\n cases: readonly { values: readonly Constant[]; body: readonly Statement[] }[];\n fallback: readonly Statement[];\n }\n | {\n kind: \"for\";\n counter: SymbolId;\n /** Existing storage remains observable after the loop exits. */\n counterScope?: \"existing\";\n start: Expression;\n limit: Expression;\n step: string;\n exclusive?: true;\n maxIterations: number;\n body: readonly Statement[];\n }\n | {\n kind: \"invoke\";\n function: SymbolId;\n instance?: SymbolId;\n index?: Expression;\n arguments: readonly Expression[];\n destination?: Place;\n }\n | {\n kind: \"blockUpdate\";\n instance: SymbolId;\n index?: Expression;\n inputs: Readonly<Record<string, Expression>>;\n }\n | { kind: \"return\"; value?: Expression }\n | { kind: \"break\" | \"continue\" }\n);\n\nexport interface MethodOwner {\n block: SymbolId;\n access: \"public\" | \"private\" | \"protected\";\n}\n\nexport interface PlcFunction {\n owner?: MethodOwner;\n id: SymbolId;\n name: string;\n parameters: readonly Variable[];\n locals: readonly Variable[];\n result?: TypeId;\n /** A `@tsplc/compiler/math` helper, whose result range follows from its arguments' ranges. */\n bounds?: MathHelper;\n body: readonly Statement[];\n span: SourceSpan;\n}\nexport type MathHelper = \"min\" | \"max\" | \"clamp\";\n\n// Native vendor blocks under their TypeScript names. Ports are [name, native name, type];\n// every output starts FALSE or T#0s, matching the vendor library blocks.\nconst timer = (input: string, output: string) =>\n ({\n inputs: [\n [input, \"IN\", \"BOOL\"],\n [\"duration\", \"PT\", \"TIME\"],\n ],\n outputs: [\n [output, \"Q\", \"BOOL\"],\n [\"elapsed\", \"ET\", \"TIME\"],\n ],\n }) as const;\nexport const standardBlocks = {\n OnDelayTimer: { native: \"TON\", ...timer(\"enabled\", \"done\") },\n OffDelayTimer: { native: \"TOF\", ...timer(\"enabled\", \"active\") },\n PulseTimer: { native: \"TP\", ...timer(\"start\", \"active\") },\n RisingEdge: {\n native: \"R_TRIG\",\n inputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n outputs: [[\"rose\", \"Q\", \"BOOL\"]],\n },\n FallingEdge: {\n native: \"F_TRIG\",\n inputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n outputs: [[\"fell\", \"Q\", \"BOOL\"]],\n },\n Blinker: {\n native: \"Util.BLINK\",\n inputs: [\n [\"enabled\", \"ENABLE\", \"BOOL\"],\n [\"offTime\", \"TIMELOW\", \"TIME\"],\n [\"onTime\", \"TIMEHIGH\", \"TIME\"],\n ],\n outputs: [[\"on\", \"OUT\", \"BOOL\"]],\n },\n} as const;\nexport type StandardBlock = keyof typeof standardBlocks;\n\nexport interface FunctionBlock {\n id: SymbolId;\n name: string;\n inputs: readonly Variable[];\n outputs: readonly Variable[];\n state: readonly Variable[];\n locals: readonly Variable[];\n body: readonly Statement[];\n result?: TypeId;\n standard?: StandardBlock;\n runtime?:\n | { kind: \"mailbox\" }\n | { kind: \"backgroundHost\" }\n | { kind: \"rpc\"; path: string }\n | {\n kind: \"http\";\n url: string;\n method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n json: boolean;\n };\n span: SourceSpan;\n}\n\nexport interface PlcProgram {\n id: SymbolId;\n name: string;\n entry: SymbolId;\n continuation?: { instance: string; file: string };\n background?: { intervalNanoseconds: string; priority: number; mailbox: string; worker: string };\n}\n\nexport interface PlcModule {\n types: readonly PlcType[];\n variables: readonly Variable[];\n functions: readonly PlcFunction[];\n blocks: readonly FunctionBlock[];\n programs: readonly PlcProgram[];\n}\n\nexport interface Task {\n name: string;\n intervalNanoseconds: string;\n priority: number;\n programs: readonly string[];\n}\n\nexport interface Deployment {\n tasks: readonly Task[];\n}\n\nexport interface Artifact {\n path: string;\n content: string;\n}\n\nexport interface GeneratedObject {\n parent?: SymbolId;\n sourcePath?: string;\n id: SymbolId;\n kind: \"program\" | \"function\" | \"functionBlock\" | \"method\" | \"globalList\" | \"dataType\";\n name: string;\n declaration: string;\n implementation?: string;\n}\n\nexport interface EmitResult {\n artifacts: readonly Artifact[];\n objects: readonly GeneratedObject[];\n diagnostics: readonly Diagnostic[];\n}\n",
8
+ "import type { SourceSpan } from \"./diagnostics.ts\";\nimport type {\n Variable,\n Constant,\n BinaryOperator,\n FunctionBlock,\n PlcProgram,\n MethodOwner,\n} from \"./model.ts\";\nimport type { PlcType } from \"./types.ts\";\n\n// Core expressions contain no source-level calls. Their effects have already\n// become ordered statements, and every place has passed storage/bounds checks.\nexport type CorePath = readonly (\n | { readonly kind: \"field\"; readonly name: string }\n | { readonly kind: \"index\"; readonly value: CoreExpression }\n)[];\nexport interface CheckedPlace {\n readonly root: string;\n readonly path: CorePath;\n}\nexport type CoreExpression = { readonly type: string; readonly span: SourceSpan } & (\n | { readonly kind: \"borrow\"; readonly place: CheckedPlace }\n | { readonly kind: \"constant\"; readonly value: Constant }\n | { readonly kind: \"load\"; readonly root: string; readonly path?: CorePath }\n | {\n readonly kind: \"unary\";\n readonly operator: \"not\" | \"negate\" | \"bitNot\" | \"timeToMilliseconds\" | \"clock\";\n readonly operand: CoreExpression;\n }\n | {\n readonly kind: \"binary\";\n readonly operator: BinaryOperator;\n readonly left: CoreExpression;\n readonly right: CoreExpression;\n readonly policy?: \"wrap\" | \"saturate\";\n }\n | {\n readonly kind: \"convert\";\n readonly operand: CoreExpression;\n readonly policy: \"exact\" | \"wrap\" | \"saturate\";\n }\n);\nexport type CoreStatement = { readonly span: SourceSpan } & (\n | {\n readonly kind: \"assign\";\n readonly root: string;\n readonly path?: CorePath;\n readonly value: CoreExpression;\n }\n | {\n readonly kind: \"if\";\n readonly condition: CoreExpression;\n readonly then: readonly CoreStatement[];\n readonly else: readonly CoreStatement[];\n }\n | {\n readonly kind: \"switch\";\n readonly value: CoreExpression;\n readonly cases: readonly { values: readonly Constant[]; body: readonly CoreStatement[] }[];\n readonly fallback: readonly CoreStatement[];\n }\n | {\n readonly kind: \"for\";\n readonly counter: string;\n readonly counterScope?: \"existing\";\n readonly start: Constant;\n readonly limit: Constant;\n readonly step: string;\n readonly dynamic?: {\n readonly start: CoreExpression;\n readonly limit: CoreExpression;\n readonly exclusive?: true;\n };\n readonly maxIterations: number;\n readonly body: readonly CoreStatement[];\n }\n | {\n readonly kind: \"invoke\";\n readonly function: string;\n readonly instance?: string;\n readonly index?: CoreExpression;\n readonly arguments: readonly CoreExpression[];\n readonly destination?: string;\n }\n | {\n readonly kind: \"blockUpdate\";\n readonly instance: string;\n readonly index?: CoreExpression;\n readonly inputs: Readonly<Record<string, CoreExpression>>;\n }\n | { readonly kind: \"return\"; readonly value?: CoreExpression }\n | { readonly kind: \"break\" | \"continue\" }\n);\nexport interface CoreFunction {\n readonly owner?: MethodOwner;\n readonly id: string;\n readonly name: string;\n readonly parameters: readonly Variable[];\n readonly result?: string;\n readonly locals: readonly Variable[];\n readonly body: readonly CoreStatement[];\n readonly span: SourceSpan;\n}\nexport interface CoreFunctionBlock extends Readonly<Omit<FunctionBlock, \"body\">> {\n readonly body: readonly CoreStatement[];\n}\nexport const verified: unique symbol = Symbol(\"verified core\");\nexport interface VerifiedCoreModule {\n readonly [verified]: true;\n readonly types: readonly PlcType[];\n readonly variables: readonly Variable[];\n readonly functions: readonly CoreFunction[];\n readonly blocks: readonly CoreFunctionBlock[];\n readonly programs: readonly PlcProgram[];\n}\n",
9
+ "import {\n comparisonOperators,\n type Constant,\n type Expression,\n type MathHelper,\n type Variable,\n} from \"./model.ts\";\nimport { integerRange, type PlcType } from \"./types.ts\";\n\nexport function integerType(type: PlcType): type is Extract<PlcType, { kind: \"integer\" | \"bits\" }> {\n return type.kind === \"integer\" || type.kind === \"bits\";\n}\nexport function floatMaximum(type: Extract<PlcType, { kind: \"float\" }>): number {\n return type.bits === 32 ? Math.fround((2 - 2 ** -23) * 2 ** 127) : Number.MAX_VALUE;\n}\n\nexport function saturateFloat(value: number, type: Extract<PlcType, { kind: \"float\" }>): number {\n // Clamp before target rounding so a finite source cannot round to infinity.\n // Comparisons leave signed zero intact; min/max substitution is unnecessary.\n const maximum = floatMaximum(type);\n const clipped = value < -maximum ? -maximum : value > maximum ? maximum : value;\n return type.bits === 32 ? Math.fround(clipped) : clipped;\n}\n\nexport function parseInteger(text: string): bigint {\n const clean = text.replaceAll(\"_\", \"\").replace(/n$/, \"\");\n const negative = clean.startsWith(\"-\");\n const unsigned = negative ? clean.slice(1) : clean;\n if (/^0[xob]/i.test(unsigned)) return (negative ? -1n : 1n) * BigInt(unsigned);\n const match = /^(\\d+)(?:\\.(\\d*))?(?:e([+-]?\\d+))?$/i.exec(unsigned);\n if (!match) throw new Error(\"Expected an exact integer literal.\");\n const fraction = match[2] ?? \"\";\n const exponent = Number(match[3] ?? 0) - fraction.length;\n if (!Number.isSafeInteger(exponent) || Math.abs(exponent) > 400)\n throw new Error(\"Integer literal exponent is out of range.\");\n let value = BigInt(match[1]! + fraction);\n if (exponent >= 0) value *= 10n ** BigInt(exponent);\n else {\n const divisor = 10n ** BigInt(-exponent);\n if (value % divisor) throw new Error(\"Integer literals cannot have a fractional part.\");\n value /= divisor;\n }\n return negative ? -value : value;\n}\nexport function constantFits(value: Constant, type: PlcType): boolean {\n if (type.kind === \"bool\") return value.kind === \"bool\" && typeof value.value === \"boolean\";\n if (integerType(type)) {\n if (value.kind !== \"integer\" || !/^(?:0|-?[1-9][0-9]*)$/.test(value.value)) return false;\n const [minimum, maximum] = integerRange(type),\n number = BigInt(value.value);\n return number >= minimum && number <= maximum;\n }\n if (type.kind === \"float\")\n return (\n value.kind === \"float\" &&\n Number.isFinite(value.value) &&\n (type.bits === 64 || Object.is(Math.fround(value.value), value.value))\n );\n return false;\n}\nexport function canAssign(source: PlcType, destination: PlcType, value?: Constant): boolean {\n if (value) {\n if (source.kind !== destination.kind || !constantFits(value, destination)) return false;\n if (\n source.kind === \"float\" &&\n destination.kind === \"float\" &&\n source.bits > destination.bits &&\n value.kind === \"float\"\n )\n return Object.is(Math.fround(value.value), value.value);\n return true;\n }\n if (source.id === destination.id) return true;\n if (source.kind === \"integer\" && destination.kind === \"integer\") {\n const [fromMin, fromMax] = integerRange(source),\n [toMin, toMax] = integerRange(destination);\n return fromMin >= toMin && fromMax <= toMax;\n }\n return source.kind === \"float\" && destination.kind === \"float\" && source.bits <= destination.bits;\n}\nexport function fold(\n expression: Expression,\n variables: ReadonlyMap<string, Variable>,\n types?: ReadonlyMap<string, PlcType>,\n): Constant | undefined {\n if (expression.kind === \"constant\") return expression.value;\n if (expression.kind === \"copy\") return fold(expression.operand, variables, types);\n if (expression.kind === \"length\") {\n const type = types?.get(expression.operand.type);\n const receiver =\n expression.operand.kind === \"load\" ? variables.get(expression.operand.place.root) : undefined;\n const pure =\n expression.operand.kind === \"load\" &&\n expression.operand.place.path.every((segment) => segment.kind === \"field\") &&\n Boolean(receiver?.initial || receiver?.storage === \"input\" || receiver?.storage === \"output\");\n if (type?.kind === \"array\" && (pure || fold(expression.operand, variables, types)))\n return { kind: \"integer\", value: String(type.length) };\n return undefined;\n }\n if (expression.kind === \"record\") {\n const fields: Record<string, Constant> = Object.create(null);\n for (const [name, operand] of Object.entries(expression.fields)) {\n const value = fold(operand, variables, types);\n if (!value) return undefined;\n fields[name] = value;\n }\n return { kind: \"record\", fields };\n }\n if (expression.kind === \"array\") {\n const items = expression.items.map((item) => fold(item, variables, types));\n return items.every((item): item is Constant => item !== undefined)\n ? { kind: \"array\", items }\n : undefined;\n }\n if (expression.kind === \"load\" && !expression.place.path.length) {\n const variable = variables.get(expression.place.root);\n return variable?.storage === \"constant\" ? variable.initial : undefined;\n }\n if (expression.kind === \"convert\") {\n const value = fold(expression.operand, variables, types);\n const target = types?.get(expression.type);\n if (value?.kind === \"integer\" && target) {\n if (integerType(target))\n return {\n kind: \"integer\",\n value: String(\n expression.policy === \"exact\"\n ? BigInt(value.value)\n : applyIntegerPolicy(BigInt(value.value), target, expression.policy),\n ),\n };\n if (target.kind === \"float\")\n return {\n kind: \"float\",\n value: target.bits === 32 ? Math.fround(Number(value.value)) : Number(value.value),\n };\n }\n if (value?.kind === \"float\" && target?.kind === \"float\")\n return {\n kind: \"float\",\n value:\n expression.policy === \"saturate\"\n ? saturateFloat(value.value, target)\n : target.bits === 32\n ? Math.fround(value.value)\n : value.value,\n };\n return undefined;\n }\n if (expression.kind === \"unary\") {\n const value = fold(expression.operand, variables, types);\n if (value?.kind === \"duration\" && expression.operator === \"timeToMilliseconds\")\n return { kind: \"integer\", value: String(BigInt(value.nanoseconds) / 1_000_000n) };\n if (value?.kind === \"bool\" && expression.operator === \"not\")\n return { kind: \"bool\", value: !value.value };\n if (value?.kind === \"integer\" && expression.operator === \"bitNot\") {\n const target = types?.get(expression.type);\n if (target?.kind === \"bits\")\n return {\n kind: \"integer\",\n value: String(applyIntegerPolicy(~BigInt(value.value), target, \"wrap\")),\n };\n }\n if (value?.kind === \"integer\" && expression.operator === \"negate\")\n return { kind: \"integer\", value: String(-BigInt(value.value)) };\n if (value?.kind === \"float\" && expression.operator === \"negate\")\n return { kind: \"float\", value: -value.value };\n }\n if (expression.kind === \"binary\") {\n const left = fold(expression.left, variables, types),\n right = fold(expression.right, variables, types);\n if (!left || !right || left.kind !== right.kind) return undefined;\n if (left.kind === \"bool\" && right.kind === \"bool\") {\n if (expression.operator === \"and\") return { kind: \"bool\", value: left.value && right.value };\n if (expression.operator === \"or\") return { kind: \"bool\", value: left.value || right.value };\n if (expression.operator === \"equal\")\n return { kind: \"bool\", value: left.value === right.value };\n if (expression.operator === \"notEqual\")\n return { kind: \"bool\", value: left.value !== right.value };\n }\n if (\n (left.kind === \"integer\" && right.kind === \"integer\") ||\n (left.kind === \"float\" && right.kind === \"float\") ||\n (left.kind === \"duration\" && right.kind === \"duration\") ||\n (left.kind === \"calendar\" && right.kind === \"calendar\") ||\n (left.kind === \"string\" && right.kind === \"string\")\n ) {\n const a =\n left.kind === \"integer\"\n ? BigInt(left.value)\n : left.kind === \"duration\"\n ? BigInt(left.nanoseconds)\n : left.value;\n const b =\n right.kind === \"integer\"\n ? BigInt(right.value)\n : right.kind === \"duration\"\n ? BigInt(right.nanoseconds)\n : right.value;\n switch (expression.operator) {\n case \"equal\":\n return { kind: \"bool\", value: a === b };\n case \"notEqual\":\n return { kind: \"bool\", value: a !== b };\n case \"less\":\n return { kind: \"bool\", value: a < b };\n case \"lessEqual\":\n return { kind: \"bool\", value: a <= b };\n case \"greater\":\n return { kind: \"bool\", value: a > b };\n case \"greaterEqual\":\n return { kind: \"bool\", value: a >= b };\n }\n if (left.kind !== \"integer\" && left.kind !== \"float\") return undefined;\n if (typeof a === \"bigint\" && typeof b === \"bigint\") {\n let value: bigint;\n switch (expression.operator) {\n case \"add\":\n value = a + b;\n break;\n case \"subtract\":\n value = a - b;\n break;\n case \"multiply\":\n value = a * b;\n break;\n case \"divide\":\n if (b === 0n) return undefined;\n value = a / b;\n break;\n case \"remainder\":\n if (b === 0n) return undefined;\n value = a % b;\n break;\n case \"bitAnd\":\n value = a & b;\n break;\n case \"bitOr\":\n value = a | b;\n break;\n case \"bitXor\":\n value = a ^ b;\n break;\n case \"shiftLeft\":\n if (b < 0n || b > 63n) return undefined;\n value = a << b;\n break;\n case \"shiftRight\":\n if (b < 0n || b > 63n) return undefined;\n value = a >> b;\n break;\n default:\n return undefined;\n }\n const target = types?.get(expression.type);\n if (target && integerType(target) && (expression.policy || target.kind === \"bits\"))\n value = applyIntegerPolicy(value, target, expression.policy ?? \"wrap\");\n return { kind: \"integer\", value: String(value) };\n }\n if (typeof a === \"number\" && typeof b === \"number\") {\n let value: number;\n switch (expression.operator) {\n case \"add\":\n value = a + b;\n break;\n case \"subtract\":\n value = a - b;\n break;\n case \"multiply\":\n value = a * b;\n break;\n case \"divide\":\n value = a / b;\n break;\n case \"remainder\":\n value = a % b;\n break;\n default:\n return undefined;\n }\n return {\n kind: \"float\",\n value:\n types?.get(expression.type)?.kind === \"float\" && expression.type === \"REAL\"\n ? Math.fround(value)\n : value,\n };\n }\n }\n }\n return undefined;\n}\nexport type IntegerInterval = readonly [bigint, bigint];\nexport function interval(\n expression: Expression,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n): IntegerInterval | undefined {\n if (expression.kind === \"length\") {\n const array = types.get(expression.operand.type);\n if (array?.kind === \"array\") return [BigInt(array.length), BigInt(array.length)];\n }\n const value = fold(expression, variables, types);\n if (value?.kind === \"integer\") return [BigInt(value.value), BigInt(value.value)];\n const type = types.get(expression.type);\n if (!type || !integerType(type)) return undefined;\n if (expression.kind === \"load\") return ranges.get(expression.place.root) ?? integerRange(type);\n if (expression.kind === \"convert\")\n return expression.policy === \"exact\"\n ? interval(expression.operand, types, variables, ranges)\n : integerRange(type);\n if (expression.kind === \"unary\" && expression.operator === \"negate\") {\n const operand = interval(expression.operand, types, variables, ranges);\n return operand && [-operand[1], -operand[0]];\n }\n if (expression.kind === \"binary\" && !expression.policy) {\n const a = interval(expression.left, types, variables, ranges),\n b = interval(expression.right, types, variables, ranges);\n if (!a || !b) return undefined;\n const [minimum, maximum] = integerRange(type);\n const unwrapped = (low: bigint, high: bigint): [bigint, bigint] =>\n low < minimum || high > maximum ? [minimum, maximum] : [low, high];\n switch (expression.operator) {\n case \"add\":\n return unwrapped(a[0] + b[0], a[1] + b[1]);\n case \"subtract\":\n return unwrapped(a[0] - b[1], a[1] - b[0]);\n case \"multiply\": {\n const values = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]];\n return unwrapped(\n values.reduce((x, y) => (x < y ? x : y)),\n values.reduce((x, y) => (x > y ? x : y)),\n );\n }\n case \"divide\": {\n if (b[0] <= 0n && b[1] >= 0n) return undefined;\n const values = [a[0] / b[0], a[0] / b[1], a[1] / b[0], a[1] / b[1]];\n return [values.reduce((x, y) => (x < y ? x : y)), values.reduce((x, y) => (x > y ? x : y))];\n }\n case \"remainder\": {\n if (b[0] <= 0n && b[1] >= 0n) return undefined;\n const maximum =\n [b[0], b[1]].map((n) => (n < 0n ? -n : n)).reduce((x, y) => (x > y ? x : y)) - 1n;\n return [a[0] < 0n ? -maximum : 0n, a[1] > 0n ? maximum : 0n];\n }\n }\n }\n return integerRange(type);\n}\n// FOR iterations from first to last inclusive; step is nonzero.\nexport function loopIterations(first: bigint, last: bigint, step: bigint): bigint {\n if (step > 0n) return last >= first ? (last - first) / step + 1n : 0n;\n return last <= first ? (first - last) / -step + 1n : 0n;\n}\nexport function loopBounds(\n start: IntegerInterval,\n limit: IntegerInterval,\n step: bigint,\n exclusive = false,\n) {\n const first = step > 0n ? start[0] : start[1];\n const last = step > 0n ? limit[1] - (exclusive ? 1n : 0n) : limit[0] + (exclusive ? 1n : 0n);\n const count = loopIterations(first, last, step);\n const range: IntegerInterval = first <= last ? [first, last] : [last, first];\n return { first, last, count, range };\n}\n\n// Only storage no statement can change carries branch refinements: loop counters,\n// by-value parameters and const locals, so the proof survives through the branch.\nexport function narrowRanges(\n condition: Expression,\n truth: boolean,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval>,\n): Map<string, IntegerInterval> {\n const narrowed = new Map(ranges);\n if (condition.kind !== \"binary\") return narrowed;\n if (condition.operator === \"and\")\n return truth\n ? narrowRanges(\n condition.right,\n truth,\n types,\n variables,\n narrowRanges(condition.left, truth, types, variables, ranges),\n )\n : narrowed;\n if (condition.left.kind !== \"load\" || condition.left.place.path.length) return narrowed;\n const root = condition.left.place.root,\n variable = variables.get(root),\n type = types.get(condition.left.type),\n fixed =\n variable &&\n ((variable.storage === \"parameter\" && !variable.mode) ||\n (variable.storage === \"local\" && !variable.mutable)),\n current =\n ranges.get(root) ?? (fixed && type && integerType(type) ? integerRange(type) : undefined),\n bound = interval(condition.right, types, variables, ranges);\n if (!current || !bound || bound[0] !== bound[1]) return narrowed;\n const value = bound[0];\n let lower = current[0],\n upper = current[1];\n switch (condition.operator) {\n case \"less\":\n if (truth) upper = value - 1n < upper ? value - 1n : upper;\n else lower = value > lower ? value : lower;\n break;\n case \"lessEqual\":\n if (truth) upper = value < upper ? value : upper;\n else lower = value + 1n > lower ? value + 1n : lower;\n break;\n case \"greater\":\n if (truth) lower = value + 1n > lower ? value + 1n : lower;\n else upper = value < upper ? value : upper;\n break;\n case \"greaterEqual\":\n if (truth) lower = value > lower ? value : lower;\n else upper = value - 1n < upper ? value - 1n : upper;\n break;\n }\n if (lower <= upper) narrowed.set(root, [lower, upper]);\n return narrowed;\n}\n\n/** Plain integer +, - and * are native IEC arithmetic, which wraps on overflow as hand-written ST does. */\nexport function wrapsNatively(expression: {\n kind: string;\n operator?: string;\n policy?: string;\n}): boolean {\n return (\n expression.kind === \"binary\" &&\n !expression.policy &&\n (expression.operator === \"add\" ||\n expression.operator === \"subtract\" ||\n expression.operator === \"multiply\")\n );\n}\n\nconst lowest = (a: bigint, b: bigint): bigint => (a < b ? a : b);\nconst highest = (a: bigint, b: bigint): bigint => (a > b ? a : b);\n\n/** A value's proved integer range; a math helper's result follows from its arguments. */\nexport function valueRange(\n expression: Expression,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval>,\n functions: ReadonlyMap<string, { bounds?: MathHelper }>,\n): IntegerInterval | undefined {\n if (expression.kind !== \"call\") return interval(expression, types, variables, ranges);\n const helper = functions.get(expression.function)?.bounds;\n return (\n helper &&\n mathHelperRange(\n helper,\n expression.arguments.map((argument) =>\n valueRange(argument, types, variables, ranges, functions),\n ),\n )\n );\n}\n\nfunction mathHelperRange(\n helper: MathHelper,\n [first, second, third]: readonly (IntegerInterval | undefined)[],\n): IntegerInterval | undefined {\n if (!first || !second) return undefined;\n if (helper === \"min\") return [lowest(first[0], second[0]), lowest(first[1], second[1])];\n if (helper === \"max\") return [highest(first[0], second[0]), highest(first[1], second[1])];\n // clamp(value, lower, upper) returns one of its three arguments, never outside lower..upper,\n // and only lower or upper when the bounds are reversed.\n if (!third) return undefined;\n return [lowest(second[0], third[0]), highest(second[1], third[1])];\n}\n\nexport function applyIntegerPolicy(\n value: bigint,\n type: Extract<PlcType, { kind: \"integer\" | \"bits\" }>,\n policy: \"wrap\" | \"saturate\",\n): bigint {\n const [minimum, maximum] = integerRange(type);\n if (policy === \"saturate\") return value < minimum ? minimum : value > maximum ? maximum : value;\n return type.kind === \"integer\" && type.signed\n ? BigInt.asIntN(type.bits, value)\n : BigInt.asUintN(type.bits, value);\n}\n\nexport function scalarIssue(\n expression: Expression,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n): string | undefined {\n const type = types.get(expression.type);\n if (!type || ![\"bool\", \"integer\", \"bits\", \"float\"].includes(type.kind))\n return \"Unknown scalar expression type.\";\n if (expression.kind === \"constant\")\n return constantFits(expression.value, type)\n ? undefined\n : \"Literal is outside its PLC type or has the wrong domain.\";\n if (expression.kind === \"load\" || expression.kind === \"call\") return undefined;\n if (\n (\"operand\" in expression && !types.has(expression.operand.type)) ||\n (\"left\" in expression &&\n (!types.has(expression.left.type) || !types.has(expression.right.type)))\n )\n return \"Unknown operand type.\";\n // Operand types were checked above.\n const operand = (value: Expression): PlcType => types.get(value.type)!;\n if (expression.kind === \"convert\") {\n if (![\"exact\", \"wrap\", \"saturate\"].includes(expression.policy))\n return \"Unknown numeric conversion policy.\";\n const source = operand(expression.operand),\n value = fold(expression.operand, variables, types);\n if (source.kind === \"bool\" || type.kind === \"bool\")\n return \"Numeric conversions cannot use BOOL.\";\n if (expression.policy === \"exact\") {\n if (\n canAssign(source, type, value) ||\n (value && integerType(source) && integerType(type) && constantFits(value, type))\n )\n return undefined;\n if (integerType(source) && type.kind === \"float\") {\n if (value?.kind === \"integer\") {\n const converted =\n type.bits === 32 ? Math.fround(Number(value.value)) : Number(value.value);\n if (\n Number.isFinite(converted) &&\n Number.isInteger(converted) &&\n BigInt(converted) === BigInt(value.value)\n )\n return undefined;\n }\n const [minimum, maximum] =\n interval(expression.operand, types, variables, ranges) ?? integerRange(source);\n const limit = 1n << BigInt(type.bits === 32 ? 24 : 53);\n if (minimum >= -limit && maximum <= limit) return undefined;\n }\n if (integerType(source) && integerType(type)) {\n const [fromMin, fromMax] =\n interval(expression.operand, types, variables, ranges) ?? integerRange(source),\n [toMin, toMax] = integerRange(type);\n if (fromMin >= toMin && fromMax <= toMax) return undefined;\n }\n return \"Exact conversion cannot be proved lossless.\";\n }\n if (expression.policy === \"saturate\" && source.kind === \"float\" && type.kind === \"float\")\n return undefined;\n return integerType(source) && integerType(type)\n ? undefined\n : expression.policy === \"saturate\"\n ? \"Saturate conversions require two integer/bit-string operands or two floating operands.\"\n : \"Wrap conversions require integer or bit-string operands.\";\n }\n if (expression.kind === \"unary\") {\n const source = operand(expression.operand);\n if (expression.operator === \"clock\")\n return type.id === \"DINT\" ? undefined : \"now() returns DINT milliseconds.\";\n if (expression.operator === \"timeToMilliseconds\")\n return source.id === \"TIME\" && source.kind === \"duration\" && type.id === \"UDINT\"\n ? undefined\n : \"timeToMilliseconds requires TIME and returns UDINT.\";\n if (expression.operator === \"not\")\n return type.kind === \"bool\" && source.kind === \"bool\"\n ? undefined\n : \"Logical negation requires BOOL.\";\n if (expression.operator === \"bitNot\")\n return type.kind === \"bits\" && source.id === type.id\n ? undefined\n : \"Bitwise complement requires a bit string.\";\n if (source.id !== type.id || !(type.kind === \"integer\" || type.kind === \"float\"))\n return \"Numeric negation requires one arithmetic type.\";\n } else if (expression.kind === \"binary\") {\n const left = operand(expression.left),\n right = operand(expression.right);\n if (expression.operator === \"and\" || expression.operator === \"or\")\n return type.kind === \"bool\" && left.kind === \"bool\" && right.kind === \"bool\"\n ? undefined\n : \"Logical operators require BOOL.\";\n if (comparisonOperators.has(expression.operator))\n return type.kind === \"bool\" &&\n left.id === right.id &&\n [\"bool\", \"integer\", \"bits\", \"float\"].includes(left.kind) &&\n (left.kind !== \"bool\" || [\"equal\", \"notEqual\"].includes(expression.operator))\n ? undefined\n : \"Comparison operands need the same PLC domain.\";\n if ([\"bitAnd\", \"bitOr\", \"bitXor\", \"shiftLeft\", \"shiftRight\"].includes(expression.operator)) {\n if (type.kind !== \"bits\" || left.id !== type.id)\n return \"Bitwise operators require bit strings.\";\n if (expression.operator === \"shiftLeft\" || expression.operator === \"shiftRight\") {\n const count = fold(expression.right, variables, types);\n return count?.kind === \"integer\" &&\n BigInt(count.value) >= 0n &&\n BigInt(count.value) < BigInt(type.bits)\n ? undefined\n : \"Shift count must be a compile-time integer within the bit width.\";\n }\n return right.id === type.id ? undefined : \"Bit-string widths differ.\";\n }\n if (\n left.id !== type.id ||\n right.id !== type.id ||\n (type.kind !== \"integer\" && type.kind !== \"float\")\n )\n return \"Arithmetic operands need one integer or floating type.\";\n if (expression.policy)\n return type.kind === \"integer\" &&\n [\"add\", \"subtract\", \"multiply\"].includes(expression.operator)\n ? undefined\n : \"Explicit arithmetic policies require integer addition, subtraction or multiplication.\";\n if (\n (expression.operator === \"divide\" || expression.operator === \"remainder\") &&\n type.kind === \"integer\"\n ) {\n const divisor = interval(expression.right, types, variables, ranges);\n if (!divisor || (divisor[0] <= 0n && divisor[1] >= 0n))\n return \"Division requires a proved nonzero divisor.\";\n const dividend = interval(expression.left, types, variables, ranges);\n const [minimum] = integerRange(type);\n if (\n type.signed &&\n dividend &&\n dividend[0] <= minimum &&\n divisor[0] <= -1n &&\n divisor[1] >= -1n\n )\n return \"Signed minimum divided by -1 cannot be represented.\";\n }\n } else return \"Expression has not been reduced to a scalar operation.\";\n if (integerType(type)) {\n const result = interval(expression, types, variables, ranges),\n [minimum, maximum] = integerRange(type);\n if (\n !(wrapsNatively(expression) && !fold(expression, variables, types)) &&\n (!result || result[0] < minimum || result[1] > maximum)\n )\n return \"Arithmetic may overflow; widen the result or use an explicit wrap/saturate operation.\";\n } else if (type.kind === \"float\") {\n const result = fold(expression, variables, types);\n if (result)\n return constantFits(result, type)\n ? undefined\n : \"Floating result is not finite or representable.\";\n if (expression.kind === \"binary\") {\n const lhs = fold(expression.left, variables, types);\n const rhs = fold(expression.right, variables, types);\n if (\n [\"add\", \"subtract\"].includes(expression.operator) &&\n (lhs?.kind === \"float\" || rhs?.kind === \"float\")\n ) {\n // Addition/subtraction and nearest rounding are monotone. Checking both\n // finite endpoints proves every finite input without changing its arithmetic.\n const maximum = floatMaximum(type);\n const finite = [-maximum, maximum].every((endpoint) => {\n const a = lhs?.kind === \"float\" ? lhs.value : endpoint;\n const b = rhs?.kind === \"float\" ? rhs.value : endpoint;\n const value = expression.operator === \"add\" ? a + b : a - b;\n return Number.isFinite(type.bits === 32 ? Math.fround(value) : value);\n });\n if (finite) return undefined;\n }\n if (\n rhs?.kind === \"float\" &&\n rhs.value === 1 &&\n [\"multiply\", \"divide\"].includes(expression.operator)\n )\n return undefined;\n } else if (expression.kind === \"unary\") return undefined;\n return \"Floating arithmetic must prove a finite result.\";\n }\n return undefined;\n}\n",
10
+ "import { comparisonOperators, type Constant, type Expression } from \"./model.ts\";\nimport type { PlcType } from \"./types.ts\";\n\nexport function durationLiteral(text: string, scaleNanoseconds: bigint): Constant | undefined {\n const clean = text.replaceAll(\"_\", \"\").replace(/^(-?)\\./, (_, sign: string) => `${sign}0.`);\n const match = /^(-?)(\\d+)(?:\\.(\\d*))?(?:e([+-]?\\d+))?$/i.exec(clean);\n if (!match) return undefined;\n const fraction = match[3] ?? \"\",\n exponent = Number(match[4] ?? 0) - fraction.length;\n if (!Number.isSafeInteger(exponent) || Math.abs(exponent) > 400) return undefined;\n let value = BigInt(match[2]! + fraction) * scaleNanoseconds;\n if (exponent >= 0) value *= 10n ** BigInt(exponent);\n else {\n const divisor = 10n ** BigInt(-exponent);\n if (value % divisor) return undefined;\n value /= divisor;\n }\n if (match[1]) value = -value;\n return validDuration(value) ? { kind: \"duration\", nanoseconds: String(value) } : undefined;\n}\n// TIME stores unsigned 32-bit milliseconds.\nfunction validDuration(nanoseconds: bigint): boolean {\n return (\n nanoseconds >= 0n && nanoseconds <= 4_294_967_295_000_000n && nanoseconds % 1_000_000n === 0n\n );\n}\nfunction validDate(text: string): boolean {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(text);\n if (!match) return false;\n const year = Number(match[1]),\n month = Number(match[2]),\n day = Number(match[3]);\n const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n const length = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];\n return Boolean(\n length && day >= 1 && day <= length && text >= \"1970-01-01\" && text <= \"2106-02-07\",\n );\n}\nfunction validClock(text: string, milliseconds: boolean): boolean {\n const match = (\n milliseconds ? /^(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})$/ : /^(\\d{2}):(\\d{2}):(\\d{2})$/\n ).exec(text);\n return Boolean(match && Number(match[1]) < 24 && Number(match[2]) < 60 && Number(match[3]) < 60);\n}\nexport function calendarLiteral(\n domain: Extract<PlcType, { kind: \"calendar\" }>[\"domain\"],\n text: string,\n): Constant | undefined {\n if (domain === \"date\") return validDate(text) ? { kind: \"calendar\", value: text } : undefined;\n if (domain === \"timeOfDay\") {\n const canonical = /^\\d{2}:\\d{2}:\\d{2}$/.test(text) ? `${text}.000` : text;\n return validClock(canonical, true) ? { kind: \"calendar\", value: canonical } : undefined;\n }\n return text.length === 19 &&\n text[10] === \"T\" &&\n validDate(text.slice(0, 10)) &&\n validClock(text.slice(11), false) &&\n text <= \"2106-02-07T06:28:15\"\n ? { kind: \"calendar\", value: text }\n : undefined;\n}\nexport function domainConstantFits(value: Constant, type: PlcType): boolean {\n if (type.kind === \"duration\")\n return (\n value.kind === \"duration\" &&\n /^(?:0|[1-9][0-9]*)$/.test(value.nanoseconds) &&\n validDuration(BigInt(value.nanoseconds))\n );\n if (type.kind === \"calendar\" && value.kind === \"calendar\") {\n const parsed = calendarLiteral(type.domain, value.value);\n return parsed?.kind === \"calendar\" && parsed.value === value.value;\n }\n return false;\n}\nexport function domainIssue(\n value: Expression,\n types: ReadonlyMap<string, PlcType>,\n): string | undefined {\n const type = types.get(value.type);\n if (value.kind === \"constant\")\n return type && domainConstantFits(value.value, type)\n ? undefined\n : \"Invalid TIME/calendar constant.\";\n if (value.kind === \"load\" || value.kind === \"call\" || value.kind === \"conditional\")\n return undefined;\n if (value.kind === \"binary\" && comparisonOperators.has(value.operator)) {\n const left = types.get(value.left.type);\n return value.type === \"BOOL\" &&\n left &&\n [\"duration\", \"calendar\"].includes(left.kind) &&\n value.left.type === value.right.type\n ? undefined\n : \"Time comparisons require matching domains.\";\n }\n return \"TIME and calendar domains permit storage, typed copies and comparisons; implicit numeric arithmetic is unsupported.\";\n}\n",
11
+ "import {\n comparisonOperators,\n type Constant,\n type Expression,\n type Variable,\n type Place,\n} from \"./model.ts\";\nimport { constantFits, interval, scalarIssue, type IntegerInterval } from \"./scalars.ts\";\nimport { domainConstantFits, domainIssue } from \"./domains.ts\";\nimport { primitiveTypes, type PlcType } from \"./types.ts\";\n\nexport function aggregate(type: PlcType | undefined): boolean {\n return type?.kind === \"record\" || type?.kind === \"array\";\n}\nexport function valueFits(\n value: Constant,\n type: PlcType,\n types: ReadonlyMap<string, PlcType>,\n): boolean {\n if (type.kind === \"duration\" || type.kind === \"calendar\") return domainConstantFits(value, type);\n if (type.kind === \"enum\")\n return value.kind === \"integer\" && type.members.some((member) => member.value === value.value);\n if (type.kind === \"string\")\n return (\n value.kind === \"string\" &&\n !value.value.includes(\"\\0\") &&\n (type.encoding === \"utf8\"\n ? new TextEncoder().encode(value.value).length <= type.capacity\n : value.value.length <= type.capacity)\n );\n if (type.kind === \"array\")\n return (\n value.kind === \"array\" &&\n value.items.length === type.length &&\n value.items.every((item) => valueFits(item, types.get(type.element)!, types))\n );\n if (type.kind === \"record\")\n return (\n value.kind === \"record\" &&\n Object.keys(value.fields).length === type.fields.length &&\n type.fields.every(\n (field) =>\n Object.hasOwn(value.fields, field.name) &&\n valueFits(value.fields[field.name]!, types.get(field.type)!, types),\n )\n );\n return constantFits(value, type);\n}\nexport function defaultValue(typeId: string, types: ReadonlyMap<string, PlcType>): Constant {\n const type = types.get(typeId);\n if (!type) throw new Error(\"Unknown default-value type\");\n if (type.kind === \"bool\") return { kind: \"bool\", value: false };\n if (type.kind === \"float\") return { kind: \"float\", value: 0 };\n if (type.kind === \"string\") return { kind: \"string\", value: \"\" };\n if (type.kind === \"enum\")\n return {\n kind: \"integer\",\n value: type.members.find((member) => member.value === \"0\")?.value ?? type.members[0]!.value,\n };\n if (type.kind === \"array\")\n return {\n kind: \"array\",\n items: Array.from({ length: type.length }, () => defaultValue(type.element, types)),\n };\n if (type.kind === \"record\")\n return {\n kind: \"record\",\n fields: Object.fromEntries(\n type.fields.map((field) => [field.name, defaultValue(field.type, types)]),\n ),\n };\n if (type.kind === \"duration\") return { kind: \"duration\", nanoseconds: \"0\" };\n if (type.kind === \"calendar\")\n return {\n kind: \"calendar\",\n value:\n type.domain === \"date\"\n ? \"1970-01-01\"\n : type.domain === \"timeOfDay\"\n ? \"00:00:00.000\"\n : \"1970-01-01T00:00:00\",\n };\n if (type.kind === \"integer\" || type.kind === \"bits\") return { kind: \"integer\", value: \"0\" };\n throw new Error(\"Unsupported default-value type\");\n}\nexport function placeType(\n place: Place,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n writable = false,\n): { type?: string; issue?: string } {\n const root = variables.get(place.root);\n if (!root) return { issue: \"Unknown storage root.\" };\n if (\n writable &&\n (root.storage === \"input\" ||\n root.storage === \"constant\" ||\n root.storage === \"blockOutput\" ||\n (root.storage === \"parameter\" && root.mode !== \"inOut\") ||\n (!place.path.length && !root.mutable))\n )\n return { issue: \"This storage is read-only.\" };\n let id = root.type;\n for (const segment of place.path) {\n const type = types.get(id);\n if (segment.kind === \"field\") {\n if (type?.kind === \"block\" && segment.name === \"out\" && type.output) {\n if (writable) return { issue: \"Function block output views are read-only.\" };\n id = type.output;\n continue;\n }\n if (type?.kind !== \"record\") return { issue: \"Field access requires a record.\" };\n const field = type.fields.find((field) => field.name === segment.name);\n if (!field) return { issue: \"Unknown record field.\" };\n if (writable && field.readonly) return { issue: \"This field is read-only.\" };\n id = field.type;\n } else {\n if (type?.kind !== \"array\") return { issue: \"Index access requires a fixed array.\" };\n // Enum values are closed, and the layout check below proves its members are the bounds.\n // An integer, such as a for…of counter, still needs its bounds proof.\n if (type.index && segment.value.type === type.index) {\n id = type.element;\n continue;\n }\n const indexType = types.get(segment.value.type),\n bounds = interval(segment.value, types, variables, ranges);\n if (\n indexType?.kind !== \"integer\" ||\n !bounds ||\n bounds[0] < BigInt(type.lowerBound) ||\n bounds[1] >= BigInt(type.lowerBound + type.length)\n )\n return { issue: \"Array index must be proved within the declared bounds.\" };\n id = type.element;\n }\n }\n return { type: id };\n}\nexport function aggregateIssue(\n value: Expression,\n types: ReadonlyMap<string, PlcType>,\n): string | undefined {\n const type = types.get(value.type);\n if (!type) return \"Unknown expression type.\";\n if (value.kind === \"constant\")\n return valueFits(value.value, type, types)\n ? undefined\n : \"Constant does not fit its closed PLC layout.\";\n if (value.kind === \"record\")\n return type.kind === \"record\" &&\n Object.keys(value.fields).length === type.fields.length &&\n type.fields.every(\n (field) =>\n Object.hasOwn(value.fields, field.name) && value.fields[field.name]?.type === field.type,\n )\n ? undefined\n : \"Record expression differs from its layout.\";\n if (value.kind === \"array\")\n return type.kind === \"array\" &&\n value.items.length === type.length &&\n value.items.every((item) => item.type === type.element)\n ? undefined\n : \"Array expression differs from its layout.\";\n if (value.kind === \"copy\")\n return aggregate(type) && value.operand.type === value.type\n ? undefined\n : \"Copy requires one matching fixed aggregate.\";\n if (value.kind === \"convert\") {\n const source = types.get(value.operand.type);\n return type.kind === \"string\" &&\n source?.kind === \"string\" &&\n source.encoding === type.encoding &&\n source.capacity <= type.capacity &&\n value.policy === \"exact\"\n ? undefined\n : \"Unsupported aggregate/domain conversion.\";\n }\n if (value.kind === \"load\" || value.kind === \"call\" || value.kind === \"conditional\")\n return undefined;\n if (value.kind === \"binary\" && comparisonOperators.has(value.operator)) {\n const left = types.get(value.left.type);\n return value.type === \"BOOL\" &&\n left &&\n [\"enum\", \"string\"].includes(left.kind) &&\n value.left.type === value.right.type &&\n (left.kind !== \"enum\" || [\"equal\", \"notEqual\"].includes(value.operator))\n ? undefined\n : \"Comparison requires compatible scalar domains; object identity is unsupported.\";\n }\n return \"Operation is unsupported for this PLC domain.\";\n}\n\n// Route a reduced expression to the checker that owns its PLC domain. A binary\n// operation belongs to its operand domain, e.g. a TIME comparison yields BOOL.\nexport function expressionIssue(\n value: Expression,\n types: ReadonlyMap<string, PlcType>,\n variables: ReadonlyMap<string, Variable>,\n ranges: ReadonlyMap<string, IntegerInterval>,\n): string | undefined {\n const kinds = [value.type, ...(value.kind === \"binary\" ? [value.left.type] : [])].map(\n (id) => types.get(id)?.kind ?? \"\",\n );\n if (kinds.some((kind) => [\"duration\", \"calendar\"].includes(kind)))\n return domainIssue(value, types);\n if (\n [\"copy\", \"record\", \"array\"].includes(value.kind) ||\n kinds.some((kind) => [\"record\", \"array\", \"enum\", \"string\"].includes(kind))\n )\n return aggregateIssue(value, types);\n return scalarIssue(value, types, variables, ranges);\n}\n\n// Validate all layout edges once before constants or places can traverse them.\nexport function layoutIssue(types: ReadonlyMap<string, PlcType>): string | undefined {\n for (const type of types.values()) {\n const canonical = primitiveTypes.find((item) => item.id === type.id);\n if (canonical) {\n if (\n type.kind !== canonical.kind ||\n (\"bits\" in canonical && (!(\"bits\" in type) || type.bits !== canonical.bits)) ||\n (\"signed\" in canonical && (!(\"signed\" in type) || type.signed !== canonical.signed)) ||\n (\"domain\" in canonical && (!(\"domain\" in type) || type.domain !== canonical.domain))\n )\n return `Conflicting primitive type ${type.id}`;\n continue;\n }\n if (type.kind === \"record\") {\n if (\n !type.fields.length ||\n new Set(type.fields.map((field) => field.name)).size !== type.fields.length ||\n type.fields.some(\n (field) =>\n !field.name ||\n typeof field.readonly !== \"boolean\" ||\n (field.mode && field.mode !== \"inOut\") ||\n !types.has(field.type),\n )\n )\n return `Invalid closed record layout ${type.id}`;\n } else if (type.kind === \"array\") {\n if (\n !types.has(type.element) ||\n !Number.isSafeInteger(type.length) ||\n type.length < 1 ||\n type.length > 1_000_000 ||\n !Number.isInteger(type.lowerBound) ||\n type.lowerBound < -2147483648 ||\n type.lowerBound + type.length - 1 > 2147483647\n )\n return `Invalid fixed array layout ${type.id}`;\n if (type.index !== undefined) {\n const index = types.get(type.index);\n if (\n index?.kind !== \"enum\" ||\n index.members.length !== type.length ||\n index.members.some(\n (member) =>\n Number(member.value) < type.lowerBound ||\n Number(member.value) >= type.lowerBound + type.length,\n )\n )\n return `Invalid enum-keyed array layout ${type.id}`;\n }\n } else if (type.kind === \"enum\") {\n if (\n type.base !== \"DINT\" ||\n types.get(type.base)?.kind !== \"integer\" ||\n !type.members.length ||\n new Set(type.members.map((member) => member.name)).size !== type.members.length ||\n new Set(type.members.map((member) => member.value)).size !== type.members.length ||\n type.members.some(\n (member) =>\n !member.name ||\n !constantFits({ kind: \"integer\", value: member.value }, types.get(type.base)!),\n )\n )\n return `Invalid enum layout ${type.id}`;\n } else if (type.kind === \"string\") {\n if (\n !Number.isInteger(type.capacity) ||\n type.capacity < 1 ||\n type.capacity > 65535 ||\n ![\"utf8\", \"utf16\"].includes(type.encoding)\n )\n return `Invalid bounded string layout ${type.id}`;\n } else if (type.kind === \"block\") {\n if (!type.block || (type.output && types.get(type.output)?.kind !== \"record\"))\n return `Invalid block type ${type.id}`;\n } else return `Unsupported core type definition ${type.id}`;\n }\n const active = new Set<string>(),\n layouts = new Map<string, { size: number; height: number }>();\n const count = (id: string, depth: number): { size: number; height: number } => {\n if (active.has(id) || depth > 64)\n throw new Error(`Recursive or excessively nested by-value layout ${id}`);\n const cached = layouts.get(id);\n if (cached) {\n if (depth + cached.height > 64) throw new Error(`Layout nesting exceeds 64 levels ${id}`);\n return cached;\n }\n active.add(id);\n const type = types.get(id)!;\n const children =\n type.kind === \"array\"\n ? [count(type.element, depth + 1)]\n : type.kind === \"record\"\n ? type.fields.map((field) => count(field.type, depth + 1))\n : [];\n const size =\n type.kind === \"array\"\n ? type.length * children[0]!.size\n : type.kind === \"record\"\n ? children.reduce((sum, child) => sum + child.size, 0)\n : 1;\n const height = children.length\n ? 1 + children.reduce((maximum, child) => Math.max(maximum, child.height), 0)\n : 0;\n active.delete(id);\n if (size > 1_000_000) throw new Error(`Layout exceeds one million scalar elements ${id}`);\n if (depth + height > 64) throw new Error(`Layout nesting exceeds 64 levels ${id}`);\n const layout = { size, height };\n layouts.set(id, layout);\n return layout;\n };\n try {\n for (const id of types.keys()) count(id, 0);\n } catch (cause) {\n return cause instanceof Error ? cause.message : \"Invalid layout\";\n }\n return undefined;\n}\n",
12
+ "import { error, type Diagnostic, type SourceSpan } from \"./diagnostics.ts\";\n\nexport class InvalidCore extends Error {\n constructor(readonly diagnostic: Diagnostic) {\n super(diagnostic.message);\n }\n}\nexport function reject(message: string, span?: SourceSpan): never {\n throw new InvalidCore(error(\"PLC6001\", message, span));\n}\n",
13
+ "import type { SourceSpan } from \"./diagnostics.ts\";\nimport {\n standardBlocks,\n type PlcModule,\n type Variable,\n type FunctionBlock,\n type PlcFunction,\n} from \"./model.ts\";\nimport { instancedBlock, type PlcType } from \"./types.ts\";\nimport { layoutIssue, valueFits } from \"./aggregates.ts\";\nimport { reject } from \"./normalization-error.ts\";\n\n// This index owns the module namespace and storage declarations. Routine\n// lowering may claim temporary identifiers, but cannot weaken admission rules.\nexport class ModuleDeclarations {\n private readonly ids = new Set<string>();\n readonly types = new Map<string, PlcType>();\n readonly globals = new Map<string, Variable>();\n readonly blocks: Map<string, FunctionBlock>;\n readonly signatures: Map<string, PlcFunction>;\n\n constructor(module: PlcModule) {\n for (const type of module.types) {\n if (this.types.has(type.id)) reject(`Duplicate type ${type.id}.`);\n this.types.set(type.id, type);\n }\n const invalidLayout = layoutIssue(this.types);\n if (invalidLayout) reject(invalidLayout);\n if (this.types.get(\"BOOL\")?.kind !== \"bool\") reject(\"Missing canonical BOOL type.\");\n\n this.blocks = new Map(module.blocks.map((block) => [block.id, block]));\n for (const item of module.variables) {\n this.checkVariable(item, [\"module\", \"instance\", \"input\", \"output\", \"constant\"]);\n this.globals.set(item.id, item);\n }\n\n this.signatures = new Map(module.functions.map((fn) => [fn.id, fn]));\n for (const fn of module.functions) {\n this.claimId(fn.id, fn.span);\n if (\n fn.owner &&\n (!this.blocks.has(fn.owner.block) ||\n this.blocks.get(fn.owner.block)?.standard ||\n ![\"public\", \"private\", \"protected\"].includes(fn.owner.access))\n )\n reject(\"Methods require a user block owner and a valid access modifier.\", fn.span);\n if (fn.result && !this.isValueType(fn.result))\n reject(\"Unknown or non-value function result type.\", fn.span);\n for (const parameter of fn.parameters) {\n this.checkVariable(parameter, [\"parameter\"], true);\n if (parameter.mutable && !parameter.mode)\n reject(\"Value parameters are readonly.\", parameter.span);\n }\n for (const local of fn.locals) this.checkVariable(local, [\"local\"]);\n }\n\n for (const block of module.blocks) {\n this.claimId(block.id, block.span);\n for (const input of block.inputs) {\n this.checkVariable(input, [\"parameter\"], true);\n if (!input.mode && input.mutable) reject(\"Value block inputs are readonly.\", input.span);\n }\n for (const output of block.outputs) this.checkVariable(output, [\"blockOutput\"]);\n for (const state of block.state) this.checkVariable(state, [\"field\", \"instance\"]);\n for (const local of block.locals) this.checkVariable(local, [\"local\"]);\n for (const ports of [block.inputs, block.outputs]) {\n if (new Set(ports.map((variable) => variable.name)).size !== ports.length)\n reject(\n \"Block input and output names must each be unique within their schema.\",\n block.span,\n );\n }\n const result = block.result ? this.types.get(block.result) : undefined;\n if (\n block.outputs.length\n ? result?.kind !== \"record\" ||\n !this.isValueType(result.id) ||\n result.fields.length !== block.outputs.length ||\n result.fields.some(\n (field) =>\n !block.outputs.some(\n (output) => output.name === field.name && output.type === field.type,\n ),\n )\n : Boolean(block.result)\n )\n reject(\"Block output schema differs from its result record.\", block.span);\n if (block.standard) {\n const expected = Object.hasOwn(standardBlocks, block.standard)\n ? standardBlocks[block.standard]\n : undefined;\n const matches = (\n variables: readonly Variable[],\n schema: readonly (readonly [string, string, string])[],\n ): boolean =>\n variables.length === schema.length &&\n schema.every(([name, , type]) =>\n variables.some(\n (variable) =>\n variable.name === name &&\n variable.type === type &&\n !variable.mode &&\n !variable.retain,\n ),\n );\n if (\n !expected ||\n block.name !== block.standard ||\n block.body.length ||\n block.state.length ||\n block.locals.length ||\n !matches(block.inputs, expected.inputs) ||\n !matches(block.outputs, expected.outputs) ||\n block.outputs.some((output) =>\n output.type === \"BOOL\"\n ? output.initial?.kind !== \"bool\" || output.initial.value !== false\n : output.initial?.kind !== \"duration\" || output.initial.nanoseconds !== \"0\",\n )\n )\n reject(\"Invalid canonical standard block definition.\", block.span);\n }\n }\n\n for (const type of this.types.values())\n if (type.kind === \"block\") {\n const definition = this.blocks.get(type.block);\n if (!definition || definition.result !== type.output)\n reject(\"Block type differs from its definition.\");\n }\n }\n\n hasId(id: string): boolean {\n return this.ids.has(id);\n }\n\n public claimId(id: string, span?: SourceSpan): void {\n if (this.ids.has(id)) reject(`Duplicate symbol ${id}.`, span);\n this.ids.add(id);\n }\n\n public isValueType(id: string, seen = new Set<string>()): boolean {\n if (seen.has(id)) return true;\n seen.add(id);\n const type = this.types.get(id);\n return Boolean(\n type &&\n type.kind !== \"block\" &&\n (type.kind !== \"record\" ||\n type.fields.every((field) => !field.mode && this.isValueType(field.type, seen))) &&\n (type.kind !== \"array\" || this.isValueType(type.element, seen)),\n );\n }\n\n private checkVariable(\n item: Variable,\n storage: readonly Variable[\"storage\"][],\n allowBorrow = false,\n ): void {\n this.claimId(item.id, item.span);\n const type = this.types.get(item.type);\n if (!type || !storage.includes(item.storage))\n reject(\"Invalid storage type or class.\", item.span);\n if (\n item.mode &&\n (item.mode !== \"inOut\" || !allowBorrow || !item.mutable || item.storage !== \"parameter\")\n )\n reject(\"InOut belongs only on mutable parameters.\", item.span);\n const mutableState =\n item.mutable ||\n type.kind === \"array\" ||\n (type.kind === \"record\" && type.fields.some((field) => !field.readonly));\n if (\n item.retain &&\n !(item.storage === \"instance\" || ([\"module\", \"field\"].includes(item.storage) && mutableState))\n )\n reject(\"Only mutable static state or block instances may retain.\", item.span);\n if (item.storage === \"instance\") {\n const instanced = instancedBlock(item.type, this.types);\n if (!instanced || !this.blocks.has(instanced.block) || item.initial || item.mode)\n reject(\n \"Instances require a known static block and cannot have value initializers.\",\n item.span,\n );\n } else if (\n !this.isValueType(item.type) &&\n !(allowBorrow && item.mode === \"inOut\" && type.kind === \"block\")\n )\n reject(\"Block instances and reference schemas cannot be stored as values.\", item.span);\n if (item.storage === \"parameter\" && item.initial)\n reject(\n \"Inputs are supplied at each invocation and cannot have stored initializers.\",\n item.span,\n );\n if (item.initial && !valueFits(item.initial, type, this.types))\n reject(\"Initializer has the wrong type or is out of range.\", item.span);\n if ([\"module\", \"field\", \"constant\", \"blockOutput\"].includes(item.storage) && !item.initial)\n reject(\"Persistent storage requires initialization.\", item.span);\n if ([\"input\", \"constant\", \"blockOutput\"].includes(item.storage) && item.mutable)\n reject(\"Readonly storage marked mutable.\", item.span);\n }\n}\n",
14
+ "import type { PlcModule } from \"./model.ts\";\nimport type { ModuleDeclarations } from \"./declarations.ts\";\nimport { reject } from \"./normalization-error.ts\";\nimport { instancedBlock } from \"./types.ts\";\n\nexport function checkStaticAllocation(module: PlcModule, declarations: ModuleDeclarations): void {\n const { types, blocks } = declarations;\n\n // Declaration admission closes these registries over every referenced type\n // and block before allocation starts; a missing entry cannot be authored here.\n // Static allocation is a separate graph from scan calls: even an unused child\n // consumes memory, and a recursive child cannot be allocated by value.\n const payloads = new Map<string, number>();\n const payload = (id: string): number => {\n const cached = payloads.get(id);\n if (cached !== undefined) return cached;\n const type = types.get(id)!;\n const size =\n type.kind === \"array\"\n ? type.length * payload(type.element)\n : type.kind === \"record\"\n ? type.fields.reduce((sum, field) => sum + payload(field.type), 0)\n : 1;\n payloads.set(id, size);\n return size;\n };\n\n const instanceSize = (id: string): number => {\n const type = types.get(id)!;\n return type.kind === \"array\"\n ? type.length * instanceSize(type.element)\n : allocation(type.kind === \"block\" ? type.block : \"\").size;\n };\n const allocations = new Map<string, { size: number; height: number }>(),\n allocating = new Set<string>();\n const allocation = (id: string): { size: number; height: number } => {\n if (allocating.size >= 64)\n reject(\"Static block allocation nesting exceeds 64 levels.\", blocks.get(id)?.span);\n if (allocating.has(id)) reject(\"Recursive static block allocation.\", blocks.get(id)?.span);\n const cached = allocations.get(id);\n if (cached) return cached;\n allocating.add(id);\n const block = blocks.get(id)!;\n const children = block.state\n .filter((item) => item.storage === \"instance\")\n .map((item) => ({\n height: allocation(instancedBlock(item.type, types)!.block).height,\n size: instanceSize(item.type),\n }));\n const own = [\n ...block.inputs,\n ...block.outputs,\n ...block.state.filter((item) => item.storage !== \"instance\"),\n ].reduce((sum, item) => sum + (item.mode === \"inOut\" ? 1 : payload(item.type)), 1);\n const size = own + children.reduce((sum, child) => sum + child.size, 0),\n height = children.length ? 1 + Math.max(...children.map((child) => child.height)) : 1;\n if (size > 1_000_000 || height > 64)\n reject(\"Static block allocation exceeds its finite budget.\", block.span);\n allocating.delete(id);\n const result = { size, height };\n allocations.set(id, result);\n return result;\n };\n\n for (const block of module.blocks) allocation(block.id);\n const staticPayload = module.variables.reduce((sum, variable) => {\n return (\n sum +\n (instancedBlock(variable.type, types) ? instanceSize(variable.type) : payload(variable.type))\n );\n }, 0);\n if (staticPayload > 1_000_000)\n reject(\"Static module storage exceeds one million scalar elements.\");\n}\n",
15
+ "import type { SourceSpan } from \"./diagnostics.ts\";\nimport type {\n Variable,\n Expression,\n Statement,\n Place,\n PlcFunction,\n FunctionBlock,\n} from \"./model.ts\";\nimport type {\n CoreExpression,\n CoreStatement,\n CorePath,\n CoreFunction,\n CoreFunctionBlock,\n} from \"./core-model.ts\";\nimport {\n fold,\n interval,\n loopBounds,\n narrowRanges,\n valueRange,\n type IntegerInterval,\n} from \"./scalars.ts\";\nimport { instancedBlock, integerRange } from \"./types.ts\";\nimport { aggregate, expressionIssue, placeType, valueFits } from \"./aggregates.ts\";\nimport { reject } from \"./normalization-error.ts\";\nimport type { ModuleDeclarations } from \"./declarations.ts\";\n\ntype Flow = \"fallthrough\" | \"return\" | \"loop\" | \"mixed\";\ninterface BodyResult {\n body: CoreStatement[];\n initialized: Set<string>;\n flow: Flow;\n}\n\n// Only paths that reach the next statement participate in a join. A local is\n// definitely initialized when every such path initialized it; branches that\n// return or leave the loop do not constrain it.\nfunction join(\n branches: readonly BodyResult[],\n initialized: Set<string>,\n): { flow: Flow; initialized: Set<string> } {\n const falling = branches.filter((branch) => branch.flow === \"fallthrough\");\n if (falling.length)\n return {\n flow: \"fallthrough\",\n initialized: new Set(\n [...falling[0]!.initialized].filter((id) =>\n falling.every((branch) => branch.initialized.has(id)),\n ),\n ),\n };\n const flow = branches[0]!.flow;\n return { flow: branches.every((branch) => branch.flow === flow) ? flow : \"mixed\", initialized };\n}\n\n// All mutable lowering state belongs to one invocation of one authored routine.\n// sourceScope admits authored places; scope additionally contains captured temps.\nexport class RoutineNormalizer {\n private readonly fn: PlcFunction;\n\n private readonly block: FunctionBlock | undefined;\n private readonly owner: FunctionBlock | undefined;\n\n private readonly scope: Map<string, Variable>;\n\n private readonly sourceScope: Map<string, Variable>;\n\n private readonly locals: Variable[];\n\n private readonly ranges = new Map<string, IntegerInterval>();\n\n private readonly counters = new Set<string>();\n\n private readonly callees = new Set<string>();\n\n private temporaryCount = 0;\n\n constructor(\n routine: PlcFunction | FunctionBlock,\n private readonly declarations: ModuleDeclarations,\n ) {\n this.block = \"inputs\" in routine ? routine : undefined;\n this.owner =\n this.block ??\n (\"owner\" in routine && routine.owner\n ? declarations.blocks.get(routine.owner.block)\n : undefined);\n const parameters = \"parameters\" in routine ? routine.parameters : routine.inputs;\n this.fn = {\n id: routine.id,\n name: routine.name,\n ...(\"owner\" in routine && routine.owner && { owner: routine.owner }),\n parameters,\n locals: routine.locals,\n body: routine.body,\n span: routine.span,\n ...(routine.result && { result: routine.result }),\n };\n this.scope = new Map(declarations.globals);\n for (const item of [\n ...parameters,\n ...(this.owner ? [...this.owner.state, ...this.owner.outputs] : []),\n ...routine.locals,\n ])\n this.scope.set(item.id, item);\n this.sourceScope = new Map(this.scope);\n this.locals = [...routine.locals];\n }\n\n normalize(): { routine: CoreFunction | CoreFunctionBlock; callees: ReadonlySet<string> } {\n if (this.block?.standard)\n return { routine: { ...this.block, body: [] }, callees: this.callees };\n const normalized = this.body(this.fn.body, new Set(this.fn.parameters.map((item) => item.id)));\n if (this.fn.result && normalized.flow !== \"return\")\n reject(\"A typed helper must return on every path.\", this.fn.span);\n const routine = this.block\n ? { ...this.block, locals: this.locals, body: normalized.body }\n : { ...this.fn, locals: this.locals, body: normalized.body };\n return { routine, callees: this.callees };\n }\n\n private temporary(type: string, span: SourceSpan): Variable {\n let id: string;\n do {\n id = `${this.fn.id}:temporary:${this.temporaryCount++}`;\n } while (this.declarations.hasId(id));\n this.declarations.claimId(id);\n const item: Variable = {\n id,\n name: `temporary_${this.temporaryCount}`,\n type,\n storage: \"local\",\n mutable: true,\n retain: false,\n span,\n };\n this.scope.set(id, item);\n this.locals.push(item);\n return item;\n }\n\n private load(variable: Variable, span: SourceSpan): CoreExpression {\n return { kind: \"load\", root: variable.id, type: variable.type, span };\n }\n\n private verifyCall(\n id: string,\n arguments_: readonly Expression[],\n span: SourceSpan,\n instance?: string,\n ): PlcFunction {\n const called = this.declarations.signatures.get(id);\n if (!called || called.parameters.length !== arguments_.length)\n reject(\"Unknown helper or wrong argument count.\", span);\n if (called.owner) {\n if (instance) {\n const variable = this.sourceScope.get(instance);\n const type = variable && instancedBlock(variable.type, this.declarations.types);\n if (\n (variable?.storage !== \"instance\" && variable?.mode !== \"inOut\") ||\n type?.block !== called.owner.block\n )\n reject(\"Method calls require a matching static block instance.\", span);\n } else if (this.owner?.id !== called.owner.block)\n reject(\"An implicit method call requires its owning block scope.\", span);\n if (called.owner.access !== \"public\" && this.owner?.id !== called.owner.block)\n reject(\"Private and protected methods require their owning block scope.\", span);\n } else if (instance) reject(\"Ordinary functions cannot have an instance receiver.\", span);\n this.callees.add(id);\n arguments_.forEach((argument, index) => {\n if (argument.type !== called.parameters[index]?.type)\n reject(\"Helper argument has the wrong PLC type.\", argument.span);\n });\n return called;\n }\n\n private expression(\n value: Expression,\n initialized: Set<string>,\n output: CoreStatement[],\n allowAggregateLoad = false,\n ): CoreExpression {\n const type = this.declarations.types.get(value.type);\n if (!type || !this.declarations.isValueType(value.type))\n reject(\"Unknown or non-value expression type.\", value.span);\n if (value.kind === \"borrow\")\n reject(\"Borrowed places are only valid in block update arguments.\", value.span);\n const common = { type: value.type, span: value.span };\n if (value.kind === \"length\") {\n const array = this.declarations.types.get(value.operand.type);\n if (array?.kind !== \"array\" || value.type !== \"DINT\")\n reject(\"Length requires a fixed array and DINT result.\", value.span);\n if (value.operand.kind === \"load\") {\n const source = this.sourceScope.get(value.operand.place.root),\n checked = placeType(\n value.operand.place,\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n );\n if (\n !source ||\n checked.issue ||\n checked.type !== value.operand.type ||\n (source.storage === \"local\" && !initialized.has(source.id))\n )\n reject(checked.issue ?? \"Invalid array receiver.\", value.span);\n this.normalizePath(value.operand.place, initialized, output);\n } else this.expression(value.operand, initialized, output, true);\n return {\n ...common,\n kind: \"constant\",\n value: { kind: \"integer\", value: String(array.length) },\n };\n }\n if (value.kind === \"conditional\") {\n if (\n value.condition.type !== \"BOOL\" ||\n value.then.type !== value.type ||\n value.else.type !== value.type\n )\n reject(\"Invalid conditional types.\", value.span);\n const condition = this.expression(value.condition, initialized, output),\n result = this.temporary(value.type, value.span);\n const branch = (operand: Expression): CoreStatement[] => {\n const statements: CoreStatement[] = [];\n const evaluated = this.expression(operand, new Set(initialized), statements);\n statements.push({ kind: \"assign\", root: result.id, value: evaluated, span: value.span });\n return statements;\n };\n output.push({\n kind: \"if\",\n condition,\n // biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n then: branch(value.then),\n else: branch(value.else),\n span: value.span,\n });\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n if (value.kind === \"call\") {\n const called = this.verifyCall(value.function, value.arguments, value.span, value.instance);\n if (called.result !== value.type)\n reject(\"Expression call requires a matching result type.\", value.span);\n const index =\n value.instance &&\n this.instanceIndex(value.instance, value.index, initialized, output, value.span);\n const arguments_ = this.arguments(called.parameters, value.arguments, initialized, output);\n const result = this.temporary(value.type, value.span);\n output.push({\n kind: \"invoke\",\n function: value.function,\n ...(value.instance && { instance: value.instance }),\n ...(index && { index }),\n arguments: arguments_,\n destination: result.id,\n span: value.span,\n });\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n const issue = expressionIssue(value, this.declarations.types, this.scope, this.ranges);\n if (issue) reject(issue, value.span);\n switch (value.kind) {\n case \"copy\":\n return this.expression(value.operand, initialized, output, true);\n case \"record\":\n case \"array\": {\n const result = this.temporary(value.type, value.span);\n if (value.kind === \"record\") {\n for (const [name, operand] of Object.entries(value.fields))\n output.push({\n kind: \"assign\",\n root: result.id,\n path: [{ kind: \"field\", name }],\n value: this.expression(operand, initialized, output),\n span: operand.span,\n });\n } else {\n const array = this.declarations.types.get(value.type)!;\n if (array.kind !== \"array\") reject(\"Invalid array construction.\", value.span);\n value.items.forEach((operand, index) => {\n output.push({\n kind: \"assign\",\n root: result.id,\n path: [\n {\n kind: \"index\",\n value: {\n kind: \"constant\",\n type: \"DINT\",\n value: { kind: \"integer\", value: String(array.lowerBound + index) },\n span: operand.span,\n },\n },\n ],\n value: this.expression(operand, initialized, output),\n span: operand.span,\n });\n });\n }\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n case \"constant\": {\n if (!aggregate(type)) return { ...common, kind: \"constant\", value: value.value };\n const result = this.temporary(value.type, value.span);\n output.push({\n kind: \"assign\",\n root: result.id,\n value: { ...common, kind: \"constant\", value: value.value },\n span: value.span,\n });\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n case \"load\": {\n const source = this.sourceScope.get(value.place.root),\n checked = placeType(value.place, this.declarations.types, this.sourceScope, this.ranges);\n if (!source || checked.issue || checked.type !== value.type)\n reject(checked.issue ?? \"Invalid PLC load.\", value.span);\n if (aggregate(type) && !allowAggregateLoad)\n reject(\"Aggregate loads require explicit copy or a readonly value argument.\", value.span);\n if (source.storage === \"local\" && !initialized.has(source.id))\n reject(\"Local read before initialization.\", value.span);\n // The virtual .out view is not a vendor record value. Snapshot its\n // declared fields, rather than copying the whole FB instance.\n const first = value.place.path[0];\n if (\n source.storage === \"instance\" &&\n value.place.path.length === 1 &&\n first?.kind === \"field\" &&\n first.name === \"out\" &&\n type.kind === \"record\"\n ) {\n const result = this.temporary(value.type, value.span);\n for (const field of type.fields) {\n const selected: Expression = {\n kind: \"load\",\n type: field.type,\n place: {\n root: source.id,\n path: [...value.place.path, { kind: \"field\", name: field.name }],\n },\n span: value.span,\n };\n const captured = this.expression(selected, initialized, output, true);\n output.push({\n kind: \"assign\",\n root: result.id,\n path: [{ kind: \"field\", name: field.name }],\n value: captured,\n span: value.span,\n });\n }\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n const path = this.normalizePath(value.place, initialized, output);\n if (source.storage === \"constant\" && source.initial && !path.length)\n return { ...common, kind: \"constant\", value: source.initial };\n // Capture now, before a later operand can invoke an effectful helper.\n const result = this.temporary(value.type, value.span);\n output.push({\n kind: \"assign\",\n root: result.id,\n value: { ...common, kind: \"load\", root: source.id, ...(path.length && { path }) },\n span: value.span,\n });\n const bound = interval(value, this.declarations.types, this.scope, this.ranges);\n if (bound) this.ranges.set(result.id, bound);\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n case \"unary\": {\n const operand = this.expression(value.operand, initialized, output),\n constant = fold(value, this.scope, this.declarations.types);\n return constant\n ? { ...common, kind: \"constant\", value: constant }\n : { ...common, kind: \"unary\", operator: value.operator, operand };\n }\n case \"convert\": {\n const operand = this.expression(value.operand, initialized, output),\n constant = fold(value, this.scope, this.declarations.types);\n if (value.type === value.operand.type) return operand;\n return constant\n ? { ...common, kind: \"constant\", value: constant }\n : { ...common, kind: \"convert\", operand, policy: value.policy };\n }\n case \"binary\": {\n const left = this.expression(value.left, initialized, output);\n if (value.operator === \"and\" || value.operator === \"or\") {\n const result = this.temporary(\"BOOL\", value.span),\n branch: CoreStatement[] = [];\n output.push({ kind: \"assign\", root: result.id, value: left, span: value.span });\n const right = this.expression(value.right, new Set(initialized), branch);\n branch.push({ kind: \"assign\", root: result.id, value: right, span: value.span });\n const condition: CoreExpression =\n value.operator === \"and\"\n ? this.load(result, value.span)\n : {\n kind: \"unary\",\n operator: \"not\",\n operand: this.load(result, value.span),\n type: \"BOOL\",\n span: value.span,\n };\n output.push({\n kind: \"if\",\n condition,\n // biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n then: branch,\n else: [],\n span: value.span,\n });\n initialized.add(result.id);\n return this.load(result, value.span);\n }\n const right = this.expression(value.right, initialized, output),\n constant = fold(value, this.scope, this.declarations.types);\n if (constant) return { ...common, kind: \"constant\", value: constant };\n return {\n ...common,\n kind: \"binary\",\n operator: value.operator,\n left,\n right,\n ...(value.policy && { policy: value.policy }),\n };\n }\n }\n }\n\n private normalizePath(place: Place, initialized: Set<string>, output: CoreStatement[]): CorePath {\n // An index is evaluated and captured once, before later arguments can change\n // its source storage. The resulting path denotes that selected cell.\n return place.path.map((segment) =>\n segment.kind === \"field\"\n ? segment\n : { kind: \"index\", value: this.expression(segment.value, initialized, output) },\n );\n }\n\n private destination(\n place: Place,\n type: string,\n initialized: Set<string>,\n span: SourceSpan,\n ): Variable {\n const target = this.sourceScope.get(place.root),\n initializing =\n target?.storage === \"local\" && !initialized.has(place.root) && !place.path.length;\n const checked = placeType(\n place,\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n !initializing,\n );\n if (!target || checked.issue || checked.type !== type || this.counters.has(place.root))\n reject(checked.issue ?? \"Invalid assignment destination.\", span);\n if (place.path.length && target.storage === \"local\" && !initialized.has(target.id))\n reject(\"Initialize the whole aggregate before assigning fields.\", span);\n return target;\n }\n\n private instanceIndex(\n instance: string,\n index: Expression | undefined,\n initialized: Set<string>,\n output: CoreStatement[],\n span: SourceSpan,\n ): CoreExpression | undefined {\n if (!index) return undefined;\n const checked = placeType(\n { root: instance, path: [{ kind: \"index\", value: index }] },\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n );\n if (checked.issue) reject(checked.issue, span);\n return this.expression(index, initialized, output);\n }\n\n private blockUpdate(\n item: Extract<Statement, { kind: \"blockUpdate\" }>,\n initialized: Set<string>,\n output: CoreStatement[],\n ): void {\n const instance = this.sourceScope.get(item.instance),\n type = instance && instancedBlock(instance.type, this.declarations.types);\n const called = type && this.declarations.blocks.get(type.block);\n if ((instance?.storage !== \"instance\" && instance?.mode !== \"inOut\") || !called)\n reject(\"Updates require a statically allocated block instance.\", item.span);\n const index = this.instanceIndex(item.instance, item.index, initialized, output, item.span);\n const keys = Object.keys(item.inputs);\n if (\n keys.length !== called.inputs.length ||\n called.inputs.some((input) => !Object.hasOwn(item.inputs, input.name))\n )\n reject(\"Block update must supply every named input exactly once.\", item.span);\n this.callees.add(called.id);\n const arguments_ = this.arguments(\n keys.map((name) => called.inputs.find((input) => input.name === name)!),\n keys.map((name) => item.inputs[name]!),\n initialized,\n output,\n );\n const inputs = Object.fromEntries(keys.map((name, index) => [name, arguments_[index]!]));\n output.push({\n kind: \"blockUpdate\",\n instance: instance.id,\n ...(index && { index }),\n inputs,\n span: item.span,\n });\n }\n\n private arguments(\n parameters: readonly Variable[],\n values: readonly Expression[],\n initialized: Set<string>,\n output: CoreStatement[],\n ): CoreExpression[] {\n const arguments_: CoreExpression[] = [];\n for (const [index, value] of values.entries()) {\n const input = parameters[index]!;\n if (value.type !== input.type)\n reject(\"Block input differs from its concrete PLC type.\", value.span);\n const block = this.declarations.types.get(value.type)?.kind === \"block\";\n if (input.mode === \"inOut\" && value.kind !== \"borrow\") {\n // A value with no writable address reaches the callee through a temporary.\n if (block) reject(\"Pass a block instance by name.\", value.span);\n const temporary = this.temporary(value.type, value.span);\n output.push({\n kind: \"assign\",\n root: temporary.id,\n value: this.expression(value, initialized, output),\n span: value.span,\n });\n initialized.add(temporary.id);\n arguments_.push({\n kind: \"borrow\",\n type: value.type,\n place: { root: temporary.id, path: [] },\n span: value.span,\n });\n } else if (input.mode === \"inOut\" && value.kind === \"borrow\") {\n const root = this.sourceScope.get(value.place.root),\n checked = placeType(\n value.place,\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n !block,\n );\n if (\n !root ||\n checked.issue ||\n checked.type !== value.type ||\n (!block && !this.declarations.isValueType(value.type)) ||\n this.counters.has(root.id) ||\n (root.storage === \"local\" && !initialized.has(root.id))\n )\n reject(\n checked.issue ?? \"Borrow requires initialized mutable value storage of the exact type.\",\n value.span,\n );\n arguments_.push({\n kind: \"borrow\",\n type: value.type,\n place: {\n root: value.place.root,\n path: this.normalizePath(value.place, initialized, output),\n },\n span: value.span,\n });\n } else {\n if (value.kind === \"borrow\")\n reject(\"Readonly value inputs cannot receive borrowed references.\", value.span);\n arguments_.push(this.expression(value, initialized, output, true));\n }\n }\n return arguments_;\n }\n\n private body(\n statements: readonly Statement[],\n initialized: Set<string>,\n inLoop = false,\n ): BodyResult {\n const output: CoreStatement[] = [];\n let flow: Flow = \"fallthrough\";\n for (const item of statements) {\n if (flow !== \"fallthrough\") break;\n switch (item.kind) {\n case \"assign\": {\n this.destination(item.destination, item.value.type, initialized, item.span);\n const path = this.normalizePath(item.destination, initialized, output);\n // A const is assigned once, so its initializer's range holds wherever it is read.\n const bound =\n !path.length &&\n this.scope.get(item.destination.root)?.mutable === false &&\n valueRange(\n item.value,\n this.declarations.types,\n this.scope,\n this.ranges,\n this.declarations.signatures,\n );\n const value = this.expression(item.value, initialized, output);\n if (bound) this.ranges.set(item.destination.root, bound);\n if (!path.length) initialized.add(item.destination.root);\n output.push({\n kind: \"assign\",\n root: item.destination.root,\n ...(path.length && { path }),\n value,\n span: item.span,\n });\n break;\n }\n case \"blockUpdate\": {\n this.blockUpdate(item, initialized, output);\n break;\n }\n case \"invoke\": {\n const called = this.verifyCall(item.function, item.arguments, item.span, item.instance);\n if (item.destination) {\n if (item.destination.path.length || !called.result)\n reject(\"Invalid helper destination.\", item.span);\n this.destination(item.destination, called.result, initialized, item.span);\n }\n const index =\n item.instance &&\n this.instanceIndex(item.instance, item.index, initialized, output, item.span);\n // Each argument snapshots its reads before the next argument can invoke\n // a helper that mutates shared state.\n const arguments_ = this.arguments(called.parameters, item.arguments, initialized, output);\n output.push({\n kind: \"invoke\",\n function: item.function,\n ...(item.instance && { instance: item.instance }),\n ...(index && { index }),\n arguments: arguments_,\n span: item.span,\n ...(item.destination && { destination: item.destination.root }),\n });\n if (item.destination) initialized.add(item.destination.root);\n break;\n }\n case \"if\": {\n if (item.condition.type !== \"BOOL\") reject(\"Conditions require BOOL.\", item.span);\n const condition = this.expression(item.condition, initialized, output);\n const originalRanges = new Map(this.ranges);\n const branch = (statements: readonly Statement[], truth: boolean) => {\n this.ranges.clear();\n for (const [root, range] of narrowRanges(\n item.condition,\n truth,\n this.declarations.types,\n this.sourceScope,\n originalRanges,\n ))\n this.ranges.set(root, range);\n try {\n return this.body(statements, new Set(initialized), inLoop);\n } finally {\n this.ranges.clear();\n for (const [root, range] of originalRanges) this.ranges.set(root, range);\n }\n };\n const yes = branch(item.then, true),\n no = branch(item.else, false);\n ({ flow, initialized } = join([yes, no], initialized));\n output.push({\n kind: \"if\",\n condition,\n // biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n then: yes.body,\n else: no.body,\n span: item.span,\n });\n break;\n }\n case \"switch\": {\n const value = this.expression(item.value, initialized, output),\n seen = new Set<string>();\n const branches = item.cases.map((branch) => {\n for (const constant of branch.values) {\n if (\n !valueFits(\n constant,\n this.declarations.types.get(item.value.type)!,\n this.declarations.types,\n )\n )\n reject(\"Invalid case constant.\", item.span);\n const key = JSON.stringify(constant);\n if (seen.has(key)) reject(\"Duplicate case constant.\", item.span);\n seen.add(key);\n }\n return {\n values: branch.values,\n result: this.body(branch.body, new Set(initialized), inLoop),\n };\n });\n const fallback = this.body(item.fallback, new Set(initialized), inLoop);\n ({ flow, initialized } = join(\n [...branches.map((branch) => branch.result), fallback],\n initialized,\n ));\n output.push({\n kind: \"switch\",\n value,\n cases: branches.map((branch) => ({ values: branch.values, body: branch.result.body })),\n fallback: fallback.body,\n span: item.span,\n });\n break;\n }\n case \"for\": {\n const counter = this.sourceScope.get(item.counter);\n const counterType = counter && this.declarations.types.get(counter.type);\n if (\n !counter ||\n !(item.counterScope === \"existing\"\n ? [\"local\", \"module\", \"field\"].includes(counter.storage)\n : counter.storage === \"local\") ||\n !counter.mutable ||\n counterType?.kind !== \"integer\" ||\n this.counters.has(counter.id) ||\n item.start.type !== counter.type ||\n item.limit.type !== counter.type ||\n !/^(-?[1-9][0-9]*)$/.test(item.step)\n )\n reject(\"Invalid bounded loop.\", item.span);\n const start = fold(item.start, this.scope, this.declarations.types);\n const limit = fold(item.limit, this.scope, this.declarations.types);\n const startRange = interval(\n item.start,\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n );\n const limitRange = interval(\n item.limit,\n this.declarations.types,\n this.sourceScope,\n this.ranges,\n );\n if (!startRange || !limitRange)\n reject(\"Loop bounds require finite integer ranges.\", item.span);\n const step = BigInt(item.step);\n const proof = loopBounds(startRange, limitRange, step, item.exclusive);\n const dynamic = start?.kind !== \"integer\" || limit?.kind !== \"integer\";\n const first = proof.first,\n last = proof.last,\n count = proof.count;\n if (\n count > 1_000_000n ||\n Number(count) !== item.maxIterations ||\n !Number.isSafeInteger(item.maxIterations)\n )\n reject(\"Loop iteration proof differs from its bounds.\", item.span);\n if (item.counterScope === \"existing\") {\n const terminal = dynamic\n ? (step > 0n ? proof.range[1] : proof.range[0]) + step\n : first + count * step;\n const [minimum, maximum] = integerRange(counterType);\n if (count > 0n && (terminal < minimum || terminal > maximum))\n reject(\"The existing loop counter overflows on termination.\", item.span);\n }\n const evaluatedStart = this.expression(item.start, initialized, output);\n const evaluatedLimit = this.expression(item.limit, initialized, output);\n initialized.add(counter.id);\n this.counters.add(counter.id);\n this.ranges.set(counter.id, proof.range);\n const nested = this.body(item.body, new Set(initialized), true);\n this.counters.delete(counter.id);\n this.ranges.delete(counter.id);\n if (item.counterScope !== \"existing\") initialized.delete(counter.id);\n output.push({\n kind: \"for\",\n counter: counter.id,\n ...(item.counterScope && { counterScope: item.counterScope }),\n start: { kind: \"integer\", value: String(first) },\n limit: { kind: \"integer\", value: String(last) },\n ...(dynamic && {\n dynamic: {\n start: evaluatedStart,\n limit: evaluatedLimit,\n ...(item.exclusive && { exclusive: item.exclusive }),\n },\n }),\n step: item.step,\n maxIterations: item.maxIterations,\n body: nested.body,\n span: item.span,\n });\n break;\n }\n case \"return\": {\n if (item.value?.type !== this.fn.result)\n reject(\"Return differs from the function signature.\", item.span);\n const value = item.value && this.expression(item.value, initialized, output);\n output.push({ kind: \"return\", span: item.span, ...(value && { value }) });\n flow = \"return\";\n break;\n }\n case \"break\":\n case \"continue\":\n if (!inLoop) reject(\"Loop control appears outside a bounded loop.\", item.span);\n output.push({ kind: item.kind, span: item.span });\n flow = \"loop\";\n break;\n default:\n reject(\"Unknown PLC statement.\");\n }\n }\n return { body: output, initialized, flow };\n }\n}\n",
16
+ "import type { PlcModule } from \"./model.ts\";\nimport type { CoreFunction, CoreFunctionBlock, CoreStatement } from \"./core-model.ts\";\nimport type { ModuleDeclarations } from \"./declarations.ts\";\nimport { reject } from \"./normalization-error.ts\";\nimport { instancedBlock } from \"./types.ts\";\n\n// Validate the complete authored call graph before pruning unreachable code.\n// Static instances keep their child layouts even when a child has no scan call.\nexport function linkModule(\n module: PlcModule,\n declarations: ModuleDeclarations,\n functions: CoreFunction[],\n normalizedBlocks: CoreFunctionBlock[],\n edges: ReadonlyMap<string, ReadonlySet<string>>,\n) {\n const { signatures, blocks, types } = declarations;\n const names = new Set<string>(),\n entries = new Set<string>();\n for (const program of module.programs) {\n declarations.claimId(program.id);\n const entry = signatures.get(program.entry);\n if (!entry || entry.owner || entry.parameters.length || entry.result)\n reject(\"Program entry must be a parameterless void helper.\");\n if (names.has(program.name)) reject(`Duplicate program ${program.name}.`);\n names.add(program.name);\n entries.add(program.entry);\n }\n if (!module.programs.length) reject(\"At least one program is required.\");\n\n // Authored execution cycles are invalid even in unreachable routines. Static\n // allocation has its own cycle check because it does not depend on scan calls.\n const visited = new Set<string>(),\n active = new Set<string>();\n const visit = (id: string): void => {\n if (active.has(id)) reject(\"Recursive scan calls are prohibited.\", signatures.get(id)?.span);\n if (visited.has(id)) return;\n active.add(id);\n for (const child of edges.get(id) ?? []) {\n if (entries.has(child))\n reject(\"Program entries cannot be called as ordinary helpers.\", signatures.get(id)?.span);\n visit(child);\n }\n active.delete(id);\n visited.add(id);\n };\n for (const fn of [...functions, ...normalizedBlocks]) visit(fn.id);\n\n // A bounded loop can only reconstruct its counter if called helpers leave\n // that storage alone. Include transitive calls, not just direct assignments.\n const routines = new Map([...functions, ...normalizedBlocks].map((fn) => [fn.id, fn]));\n const variables = new Map(\n [\n ...module.variables,\n ...functions.flatMap((fn) => [...fn.parameters, ...fn.locals]),\n ...normalizedBlocks.flatMap((block) => [\n ...block.inputs,\n ...block.outputs,\n ...block.state,\n ...block.locals,\n ]),\n ].map((variable) => [variable.id, variable]),\n );\n const calledRoutine = (item: CoreStatement): string | undefined => {\n if (item.kind === \"invoke\") return item.function;\n if (item.kind !== \"blockUpdate\") return undefined;\n const variable = variables.get(item.instance);\n return variable && instancedBlock(variable.type, types)?.block;\n };\n const nestedBodies = (item: CoreStatement): readonly (readonly CoreStatement[])[] => {\n if (item.kind === \"for\") return [item.body];\n if (item.kind === \"if\") return [item.then, item.else];\n if (item.kind === \"switch\") return [...item.cases.map((branch) => branch.body), item.fallback];\n return [];\n };\n const writes = new Map<string, Set<string>>();\n const routineWrites = (id: string): Set<string> => {\n const cached = writes.get(id);\n if (cached) return cached;\n const result = new Set<string>();\n const inspect = (body: readonly CoreStatement[]) => {\n for (const item of body) {\n if (item.kind === \"assign\") result.add(item.root);\n if (item.kind === \"for\") result.add(item.counter);\n if (item.kind === \"invoke\") {\n if (item.destination) result.add(item.destination);\n for (const argument of item.arguments)\n if (argument.kind === \"borrow\") result.add(argument.place.root);\n }\n if (item.kind === \"blockUpdate\")\n for (const input of Object.values(item.inputs))\n if (input.kind === \"borrow\") result.add(input.place.root);\n for (const nested of nestedBodies(item)) inspect(nested);\n }\n };\n inspect(routines.get(id)!.body);\n for (const child of edges.get(id) ?? [])\n for (const root of routineWrites(child)) result.add(root);\n writes.set(id, result);\n return result;\n };\n const checkCalls = (body: readonly CoreStatement[], counters: ReadonlySet<string>) => {\n for (const item of body) {\n const called = calledRoutine(item);\n if (called && [...counters].some((counter) => routineWrites(called).has(counter)))\n reject(\"A called routine may mutate an active loop counter.\", item.span);\n const nestedCounters = item.kind === \"for\" ? new Set([...counters, item.counter]) : counters;\n for (const nested of nestedBodies(item)) checkCalls(nested, nestedCounters);\n }\n };\n for (const routine of routines.values()) checkCalls(routine.body, new Set());\n\n // Only after the complete graph is valid may emission discard unused helpers.\n const reachable = new Set<string>();\n const link = (id: string): void => {\n if (reachable.has(id)) return;\n reachable.add(id);\n for (const child of edges.get(id) ?? []) link(child);\n const owner = signatures.get(id)?.owner;\n if (owner) link(owner.block);\n for (const method of functions.filter((fn) => fn.owner?.block === id)) link(method.id);\n for (const instance of blocks\n .get(id)\n ?.state.filter((variable) => variable.storage === \"instance\") ?? []) {\n const type = instancedBlock(instance.type, types);\n if (type) link(type.block);\n }\n };\n for (const entry of entries) link(entry);\n for (const variable of module.variables) {\n const type = instancedBlock(variable.type, types);\n if (type) link(type.block);\n }\n const linkedFunctions = functions.filter((fn) => reachable.has(fn.id)),\n linkedBlocks = normalizedBlocks.filter((block) => reachable.has(block.id));\n\n // Admission has already validated every referenced type; these lookups are\n // closed over the declaration registry, including dependencies kept by DUTs.\n const usedTypes = new Set<string>();\n const useType = (id: string): void => {\n if (usedTypes.has(id)) return;\n usedTypes.add(id);\n const type = types.get(id)!;\n if (type.kind === \"record\") {\n for (const field of type.fields) useType(field.type);\n }\n if (type.kind === \"array\") {\n useType(type.element);\n if (type.index) useType(type.index);\n }\n if (type.kind === \"enum\") useType(type.base);\n if (type.kind === \"block\" && type.output) useType(type.output);\n };\n // Primitive definitions also support backend-generated numeric helpers.\n types.forEach((type) => {\n if ([\"bool\", \"integer\", \"bits\", \"float\", \"duration\", \"calendar\"].includes(type.kind))\n useType(type.id);\n });\n for (const variable of module.variables) useType(variable.type);\n for (const fn of linkedFunctions) {\n if (fn.result) useType(fn.result);\n for (const variable of [...fn.parameters, ...fn.locals]) useType(variable.type);\n }\n for (const block of linkedBlocks) {\n if (block.result) useType(block.result);\n for (const variable of [...block.inputs, ...block.outputs, ...block.state, ...block.locals]) {\n useType(variable.type);\n }\n }\n return {\n types: module.types.filter((type) => usedTypes.has(type.id)),\n variables: module.variables,\n functions: linkedFunctions,\n blocks: linkedBlocks,\n programs: module.programs,\n };\n}\n",
17
+ "import type { Diagnostic } from \"./diagnostics.ts\";\nimport type { PlcModule } from \"./model.ts\";\nimport {\n verified,\n type VerifiedCoreModule,\n type CoreFunction,\n type CoreFunctionBlock,\n} from \"./core-model.ts\";\nimport { ModuleDeclarations } from \"./declarations.ts\";\nimport { checkStaticAllocation } from \"./allocation.ts\";\nimport { RoutineNormalizer } from \"./routine.ts\";\nimport { linkModule } from \"./link.ts\";\nimport { InvalidCore } from \"./normalization-error.ts\";\n\nexport type {\n CorePath,\n CheckedPlace,\n CoreExpression,\n CoreStatement,\n CoreFunction,\n CoreFunctionBlock,\n VerifiedCoreModule,\n} from \"./core-model.ts\";\n\nconst verifiedModules = new WeakSet<object>();\nexport function isVerifiedCore(value: unknown): value is VerifiedCoreModule {\n return typeof value === \"object\" && value !== null && verifiedModules.has(value);\n}\n\nfunction freeze(value: unknown): void {\n if (typeof value !== \"object\" || value === null || Object.isFrozen(value)) return;\n for (const child of Object.values(value)) freeze(child);\n Object.freeze(value);\n}\n// The module crosses the trust boundary only after admission, lowering and linking.\nexport function normalizeModule(module: PlcModule): {\n core?: VerifiedCoreModule;\n diagnostics: readonly Diagnostic[];\n} {\n try {\n const declarations = new ModuleDeclarations(module);\n checkStaticAllocation(module, declarations);\n\n const functions: CoreFunction[] = [],\n blocks: CoreFunctionBlock[] = [];\n const edges = new Map<string, ReadonlySet<string>>();\n for (const source of [...module.functions, ...module.blocks]) {\n const normalized = new RoutineNormalizer(source, declarations).normalize();\n edges.set(source.id, normalized.callees);\n if (\"inputs\" in normalized.routine) blocks.push(normalized.routine);\n else functions.push(normalized.routine);\n }\n\n const linked = linkModule(module, declarations, functions, blocks, edges);\n const core: VerifiedCoreModule = { ...structuredClone(linked), [verified]: true };\n freeze(core);\n verifiedModules.add(core);\n return { core, diagnostics: [] };\n } catch (cause) {\n if (cause instanceof InvalidCore) return { diagnostics: [cause.diagnostic] };\n throw cause;\n }\n}\n"
18
+ ],
19
+ "mappings": ";AAkBO,SAAS,KAAK,CAAC,MAAc,SAAiB,MAA+B;AAAA,EAClF,OAAO,EAAE,QAAQ,OAAO,MAAM,UAAU,SAAS,YAAa,QAAQ,EAAE,KAAK,EAAG;AAAA;AAG3E,SAAS,SAAS,CAAC,aAA6C;AAAA,EACrE,OAAO,YAAY,KAAK,CAAC,eAAe,WAAW,aAAa,OAAO;AAAA;AAGlE,SAAS,gBAAgB,CAAC,YAAwB,QAAyB;AAAA,EAChF,QAAQ,SAAS;AAAA,EACjB,MAA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GAAG,OAAO,WAAW,GAAG,OAAO,MAAM,GAAG;AAAA,MAC5D,MAAM,aAAa,IAAI,kBAAkB,QAAQ,YAAY,EAAE,UAAU;AAAA,MACzE,MAAM,IAAI,OAAO,IAAI,WAAW,OAAO;AAAA,MACvC,IAAI,YAAY,WAAW;AAAA,QAAS,OAAO,KAAK,WAAW,OAAO;AAAA,MAC7D;AAAA,kBAAU,KAAK,WAAW,OAAO;AAAA,IACxC;AAAA,IAEA,MAAM,SAAS,WAAW,QAAQ,cAAc,WAAW,QAAQ,KAAK;AAAA,IACxE,MAAM,OAA2B,KAAK,gBAAgB,MAAM,IAAI,WAAW,KAAK;AAAA,IAChF,OAAO,IAAI;AAAA,IACX,gBAAgB,IAAI,IAAI;AAAA,IACxB,OAAO,EAAE,MAAM,aAAa,CAAC,EAAE;AAAA,IAC/B,OAAO,OAAO;AAAA,IACd,IAAI,iBAAiB;AAAA,MAAa,OAAO,EAAE,aAAa,CAAC,MAAM,UAAU,EAAE;AAAA,IAC3E,MAAM;AAAA;AAAA;",
20
+ "debugId": "56F86269D01021CE64756E2164756E21",
21
+ "names": []
22
+ }
package/dist/math.js ADDED
@@ -0,0 +1,24 @@
1
+ // packages/compiler/stdlib/math.ts
2
+ function min(left, right) {
3
+ return left < right ? left : right;
4
+ }
5
+ function max(left, right) {
6
+ return left > right ? left : right;
7
+ }
8
+ function clamp(value, lower, upper) {
9
+ if (value < lower) {
10
+ return lower;
11
+ }
12
+ if (value > upper) {
13
+ return upper;
14
+ }
15
+ return value;
16
+ }
17
+ export {
18
+ clamp,
19
+ max,
20
+ min
21
+ };
22
+
23
+ //# debugId=BCABD3CAF678A65664756E2164756E21
24
+ //# sourceMappingURL=math.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../stdlib/math.ts"],
4
+ "sourcesContent": [
5
+ "// PLC implementation source: the frontend specializes these helpers for each\n// concrete scalar domain. The release includes this source for that analysis.\nexport function min<T extends number | bigint>(left: T, right: T): T {\n return left < right ? left : right;\n}\n\nexport function max<T extends number | bigint>(left: T, right: T): T {\n return left > right ? left : right;\n}\n\nexport function clamp<T extends number | bigint>(value: T, lower: T, upper: T): T {\n if (value < lower) {\n return lower;\n }\n if (value > upper) {\n return upper;\n }\n return value;\n}\n"
6
+ ],
7
+ "mappings": ";AAEO,SAAS,GAA8B,CAAC,MAAS,OAAa;AAAA,EACnE,OAAO,OAAO,QAAQ,OAAO;AAAA;AAGxB,SAAS,GAA8B,CAAC,MAAS,OAAa;AAAA,EACnE,OAAO,OAAO,QAAQ,OAAO;AAAA;AAGxB,SAAS,KAAgC,CAAC,OAAU,OAAU,OAAa;AAAA,EAChF,IAAI,QAAQ,OAAO;AAAA,IACjB,OAAO;AAAA,EACT;AAAA,EACA,IAAI,QAAQ,OAAO;AAAA,IACjB,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA;",
8
+ "debugId": "BCABD3CAF678A65664756E2164756E21",
9
+ "names": []
10
+ }