@tsplc/compiler 0.2.17 → 0.2.19

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 (157) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +920 -943
  3. package/dist/cli.js.map +13 -10
  4. package/dist/codesys.js +3893 -3352
  5. package/dist/codesys.js.map +29 -20
  6. package/dist/elaborate-capture.js +33 -17
  7. package/dist/elaborate-capture.js.map +3 -3
  8. package/dist/index.js +8787 -6855
  9. package/dist/index.js.map +40 -20
  10. package/dist/ir.js +1575 -1072
  11. package/dist/ir.js.map +21 -17
  12. package/dist/math.js.map +2 -2
  13. package/dist/project.js +154 -60
  14. package/dist/project.js.map +5 -5
  15. package/dist/telemetry.js +27 -9
  16. package/dist/telemetry.js.map +5 -5
  17. package/package.json +112 -112
  18. package/src/codesys/config.ts +50 -0
  19. package/src/codesys/debug.ts +670 -0
  20. package/src/codesys/emit.ts +142 -0
  21. package/src/codesys/engineering.ts +109 -0
  22. package/src/codesys/expressions.ts +92 -0
  23. package/src/codesys/global-lists.ts +250 -0
  24. package/src/codesys/global-names.ts +68 -0
  25. package/src/codesys/http.ts +890 -0
  26. package/src/codesys/index.ts +30 -0
  27. package/src/codesys/instrumentation.ts +430 -0
  28. package/src/codesys/io-paths.ts +140 -0
  29. package/src/codesys/manifest.ts +643 -0
  30. package/src/codesys/names.ts +81 -0
  31. package/src/codesys/numeric.ts +409 -0
  32. package/src/codesys/operands.ts +62 -0
  33. package/src/codesys/plan.ts +605 -0
  34. package/src/codesys/programs.ts +53 -0
  35. package/src/codesys/publication.ts +171 -0
  36. package/src/codesys/routines.ts +603 -0
  37. package/src/codesys/sources.ts +71 -0
  38. package/src/codesys/st-files.ts +115 -0
  39. package/src/codesys/storage.ts +97 -0
  40. package/src/codesys/symbols.ts +220 -0
  41. package/src/codesys/task-access.ts +320 -0
  42. package/src/codesys/telemetry.ts +732 -0
  43. package/src/codesys/types.ts +250 -0
  44. package/src/codesys/vendor.ts +150 -0
  45. package/src/frontend/analyzer.ts +794 -0
  46. package/src/frontend/async.ts +317 -1137
  47. package/src/frontend/blocks.ts +537 -403
  48. package/src/frontend/configuration.ts +176 -144
  49. package/src/frontend/const-functions.ts +183 -148
  50. package/src/frontend/cooperative.ts +73 -43
  51. package/src/frontend/coroutines.ts +1032 -0
  52. package/src/frontend/elaborate/calls.ts +535 -0
  53. package/src/frontend/elaborate/capture.ts +157 -101
  54. package/src/frontend/elaborate/dialect.ts +257 -0
  55. package/src/frontend/elaborate/expressions.ts +992 -0
  56. package/src/frontend/elaborate/frame.ts +53 -0
  57. package/src/frontend/elaborate/graph.ts +116 -71
  58. package/src/frontend/elaborate/imports.ts +70 -0
  59. package/src/frontend/elaborate/index.ts +435 -331
  60. package/src/frontend/elaborate/initializers.ts +198 -0
  61. package/src/frontend/elaborate/layouts.ts +591 -384
  62. package/src/frontend/elaborate/model.ts +264 -169
  63. package/src/frontend/elaborate/specialize.ts +343 -2586
  64. package/src/frontend/elaborate/statements.ts +606 -0
  65. package/src/frontend/elaborate/storage.ts +546 -0
  66. package/src/frontend/elaborate/values.ts +58 -0
  67. package/src/frontend/elaborate/writes.ts +100 -0
  68. package/src/frontend/exposure.ts +172 -140
  69. package/src/frontend/expressions.ts +1383 -0
  70. package/src/frontend/intrinsics.ts +337 -0
  71. package/src/frontend/module-graph.ts +89 -59
  72. package/src/frontend/positions.ts +271 -200
  73. package/src/frontend/promise-chains.ts +897 -0
  74. package/src/frontend/promises.ts +390 -747
  75. package/src/frontend/routines.ts +181 -0
  76. package/src/frontend/sdk.ts +82 -0
  77. package/src/frontend/services.ts +506 -372
  78. package/src/frontend/statements.ts +855 -0
  79. package/src/frontend/tasks.ts +471 -0
  80. package/src/frontend/telemetry.ts +174 -0
  81. package/src/frontend/types.ts +845 -551
  82. package/src/frontend/typescript.ts +323 -2543
  83. package/src/index.ts +5 -5
  84. package/src/ir/aggregates.ts +275 -0
  85. package/src/ir/allocation.ts +84 -0
  86. package/src/ir/core-model.ts +146 -0
  87. package/src/ir/declarations.ts +295 -0
  88. package/src/ir/diagnostics.ts +61 -0
  89. package/src/ir/domains.ts +152 -0
  90. package/src/ir/fold.ts +342 -0
  91. package/src/ir/index.ts +90 -0
  92. package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
  93. package/src/ir/layouts.ts +181 -0
  94. package/src/ir/link.ts +354 -0
  95. package/src/ir/model.ts +386 -0
  96. package/{ir → src/ir}/normalization-error.ts +4 -4
  97. package/src/ir/normalize.ts +70 -0
  98. package/src/ir/numeric.ts +171 -0
  99. package/src/ir/ranges.ts +256 -0
  100. package/src/ir/routine.ts +1163 -0
  101. package/src/ir/scalars.ts +321 -0
  102. package/src/ir/types.ts +127 -0
  103. package/src/project/artifacts.ts +342 -0
  104. package/src/project/cli.ts +177 -0
  105. package/src/project/debugger.ts +82 -0
  106. package/src/project/index.ts +6 -0
  107. package/src/project/plant.ts +467 -0
  108. package/src/project/project-commands.ts +372 -0
  109. package/src/project/project.ts +457 -0
  110. package/src/project/release.ts +153 -0
  111. package/src/project/server.ts +150 -0
  112. package/src/project/terminal.ts +32 -0
  113. package/stdlib/math.ts +14 -10
  114. package/stdlib/telemetry.ts +71 -47
  115. package/types/async.d.ts +46 -40
  116. package/types/data-types.d.ts +26 -26
  117. package/types/globals.d.ts +41 -38
  118. package/types/index.d.ts +96 -51
  119. package/types/plc.d.ts +3 -4
  120. package/types/telemetry.d.ts +14 -14
  121. package/backends/codesys/config.ts +0 -54
  122. package/backends/codesys/debug.ts +0 -509
  123. package/backends/codesys/emit.ts +0 -1738
  124. package/backends/codesys/engineering.ts +0 -88
  125. package/backends/codesys/global-names.ts +0 -49
  126. package/backends/codesys/http.ts +0 -675
  127. package/backends/codesys/index.ts +0 -13
  128. package/backends/codesys/io-paths.ts +0 -105
  129. package/backends/codesys/manifest.ts +0 -312
  130. package/backends/codesys/names.ts +0 -76
  131. package/backends/codesys/numeric.ts +0 -356
  132. package/backends/codesys/plan.ts +0 -457
  133. package/backends/codesys/publication.ts +0 -59
  134. package/backends/codesys/storage.ts +0 -70
  135. package/backends/codesys/task-access.ts +0 -293
  136. package/backends/codesys/telemetry.ts +0 -593
  137. package/backends/codesys/types.ts +0 -179
  138. package/backends/codesys/vendor.ts +0 -108
  139. package/ir/aggregates.ts +0 -333
  140. package/ir/allocation.ts +0 -74
  141. package/ir/core-model.ts +0 -129
  142. package/ir/core.ts +0 -64
  143. package/ir/declarations.ts +0 -208
  144. package/ir/diagnostics.ts +0 -43
  145. package/ir/domains.ts +0 -96
  146. package/ir/index.ts +0 -8
  147. package/ir/link.ts +0 -185
  148. package/ir/model.ts +0 -346
  149. package/ir/routine.ts +0 -859
  150. package/ir/scalars.ts +0 -675
  151. package/ir/types.ts +0 -76
  152. package/project/artifacts.ts +0 -277
  153. package/project/cli.ts +0 -395
  154. package/project/index.ts +0 -1
  155. package/project/plant.ts +0 -509
  156. package/project/project.ts +0 -358
  157. package/project/server.ts +0 -113
package/dist/telemetry.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { relative } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
- // packages/compiler/ir/errors.ts
5
+ // packages/compiler/src/ir/job-errors.ts
6
6
  var jobErrors = {
7
7
  "1": "cancelled",
8
8
  "2": "timeout",
@@ -15,8 +15,9 @@ var jobErrors = {
15
15
  };
16
16
  var httpErrors = { base: 1e4, last: 10999 };
17
17
  var errorName = (code) => {
18
- if (code > httpErrors.base && code <= httpErrors.last)
18
+ if (code > httpErrors.base && code <= httpErrors.last) {
19
19
  return `HTTP ${code - httpErrors.base}`;
20
+ }
20
21
  return code < httpErrors.base ? jobErrors[code] : undefined;
21
22
  };
22
23
 
@@ -35,17 +36,33 @@ var collector;
35
36
  var source = () => {
36
37
  for (const line of new Error().stack?.split(`
37
38
  `) ?? []) {
38
- const frame = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line);
39
- if (frame && frame[1] !== module)
40
- return `${relative(process.cwd(), frame[1]).replaceAll("\\", "/")}:${frame[2]}`;
39
+ const [, file, lineNumber] = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line) ?? [];
40
+ if (file && file !== module) {
41
+ return `${relative(process.cwd(), file).replaceAll("\\", "/")}:${lineNumber}`;
42
+ }
41
43
  }
42
44
  return "";
43
45
  };
46
+ var reportedValue = (value) => {
47
+ if (value instanceof Text) {
48
+ return value.value;
49
+ }
50
+ if (typeof value === "bigint") {
51
+ return Number(value);
52
+ }
53
+ return value;
54
+ };
55
+ var exceptionName = (error) => {
56
+ if (typeof error === "number") {
57
+ return errorName(error);
58
+ }
59
+ return error instanceof Error ? error.message : String(error);
60
+ };
44
61
  var report = (record, properties = {}) => collector?.({
45
62
  ...record,
46
63
  properties: Object.fromEntries(Object.entries(properties).map(([name, value]) => [
47
64
  name,
48
- value instanceof Text ? value.value : typeof value === "bigint" ? Number(value) : value
65
+ reportedValue(value)
49
66
  ])),
50
67
  source: source(),
51
68
  scan: 0,
@@ -58,7 +75,7 @@ var telemetry = {
58
75
  error: (message, properties) => report({ kind: "log", level: "error", message }, properties),
59
76
  captureException: (error, properties) => {
60
77
  const code = typeof error === "number" ? error : 0;
61
- const name = typeof error === "number" ? errorName(error) : error instanceof Error ? error.message : String(error);
78
+ const name = exceptionName(error);
62
79
  report({ kind: "exception", code, ...name && { name }, handled: true }, properties);
63
80
  },
64
81
  text: (bytes, length) => {
@@ -70,8 +87,9 @@ var telemetry = {
70
87
  var onTelemetry = (next) => {
71
88
  collector = next;
72
89
  return () => {
73
- if (collector === next)
90
+ if (collector === next) {
74
91
  collector = undefined;
92
+ }
75
93
  };
76
94
  };
77
95
  export {
@@ -79,5 +97,5 @@ export {
79
97
  telemetry
80
98
  };
81
99
 
82
- //# debugId=7C05A3D7FEB8199164756E2164756E21
100
+ //# debugId=80AC1E2249312EFF64756E2164756E21
83
101
  //# sourceMappingURL=telemetry.js.map
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../stdlib/telemetry.ts", "../ir/errors.ts", "../stdlib/clock.ts"],
3
+ "sources": ["../stdlib/telemetry.ts", "../src/ir/job-errors.ts", "../stdlib/clock.ts"],
4
4
  "sourcesContent": [
5
- "import { relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { errorName } from \"../ir/errors.ts\";\nimport { now } from \"./clock.ts\";\n\ntype Reported = Readonly<Record<string, unknown>>;\nclass Text {\n constructor(readonly value: string) {}\n}\ntype Value = boolean | number | bigint | string | Text;\ntype Properties = Readonly<Record<string, Value>>;\n\nconst module = fileURLToPath(import.meta.url);\nlet collector: ((record: Reported) => void) | undefined;\n\n/** The program's call: the first stack frame outside this module, relative to the working directory. */\nconst source = () => {\n for (const line of new Error().stack?.split(\"\\n\") ?? []) {\n const frame = /\\(?((?:\\/|[A-Za-z]:\\\\)[^():]+):(\\d+):\\d+\\)?$/.exec(line);\n if (frame && frame[1] !== module)\n return `${relative(process.cwd(), frame[1]!).replaceAll(\"\\\\\", \"/\")}:${frame[2]}`;\n }\n return \"\";\n};\n\nconst report = (record: Reported, properties: Properties = {}) =>\n collector?.({\n ...record,\n properties: Object.fromEntries(\n Object.entries(properties).map(([name, value]) => [\n name,\n value instanceof Text ? value.value : typeof value === \"bigint\" ? Number(value) : value,\n ]),\n ),\n source: source(),\n scan: 0,\n time: now(),\n });\n\n/** What a PLC program's `telemetry` calls do under Bun; see `types/telemetry.d.ts`. */\nexport const telemetry = {\n capture: (event: string, properties?: Properties) => report({ kind: \"event\", event }, properties),\n info: (message: string, properties?: Properties) =>\n report({ kind: \"log\", level: \"info\", message }, properties),\n warn: (message: string, properties?: Properties) =>\n report({ kind: \"log\", level: \"warn\", message }, properties),\n error: (message: string, properties?: Properties) =>\n report({ kind: \"log\", level: \"error\", message }, properties),\n // Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.\n captureException: (error: unknown, properties?: Properties) => {\n const code = typeof error === \"number\" ? error : 0;\n const name =\n typeof error === \"number\"\n ? errorName(error)\n : error instanceof Error\n ? error.message\n : String(error);\n report({ kind: \"exception\", code, ...(name && { name }), handled: true }, properties);\n },\n text: (bytes: readonly number[], length: number) => {\n const sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));\n const end = sent.indexOf(0);\n return new Text(new TextDecoder().decode(Uint8Array.from(end < 0 ? sent : sent.slice(0, end))));\n },\n};\n\nexport const onTelemetry = (next: (record: Reported) => void) => {\n collector = next;\n return () => {\n if (collector === next) collector = undefined;\n };\n};\n",
6
- "/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n \"1\": \"cancelled\",\n \"2\": \"timeout\",\n \"3\": \"request or response too large to encode\",\n \"4\": \"malformed response\",\n \"5\": \"network error or server restarted\",\n \"6\": \"TLS error\",\n \"7\": \"no free request slot\",\n \"10000\": \"HTTP status: 10000 + status code\",\n};\n\n/** An HTTP response fails a job with `base` + its status, up to `last`. */\nexport const httpErrors = { base: 10000, last: 10999 };\n\n/** What a telemetry exception record calls an error code: its meaning when it is a job error. */\nexport const errorName = (code: number): string | undefined => {\n if (code > httpErrors.base && code <= httpErrors.last) return `HTTP ${code - httpErrors.base}`;\n return code < httpErrors.base ? jobErrors[code] : undefined;\n};\n",
5
+ "import { relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { errorName } from \"../src/ir/job-errors.ts\";\nimport { now } from \"./clock.ts\";\n\ntype Reported = Readonly<Record<string, unknown>>;\nclass Text {\n\tconstructor(readonly value: string) {}\n}\ntype Value = boolean | number | bigint | string | Text;\ntype Properties = Readonly<Record<string, Value>>;\n\nconst module = fileURLToPath(import.meta.url);\nlet collector: ((record: Reported) => void) | undefined;\n\n/** The program's call: the first stack frame outside this module, relative to the working directory. */\nconst source = () => {\n\tfor (const line of new Error().stack?.split(\"\\n\") ?? []) {\n\t\tconst [, file, lineNumber] =\n\t\t\t/\\(?((?:\\/|[A-Za-z]:\\\\)[^():]+):(\\d+):\\d+\\)?$/.exec(line) ?? [];\n\t\tif (file && file !== module) {\n\t\t\treturn `${relative(process.cwd(), file).replaceAll(\"\\\\\", \"/\")}:${lineNumber}`;\n\t\t}\n\t}\n\treturn \"\";\n};\n\nconst reportedValue = (value: Value) => {\n\tif (value instanceof Text) {\n\t\treturn value.value;\n\t}\n\tif (typeof value === \"bigint\") {\n\t\treturn Number(value);\n\t}\n\treturn value;\n};\n\nconst exceptionName = (error: unknown) => {\n\tif (typeof error === \"number\") {\n\t\treturn errorName(error);\n\t}\n\treturn error instanceof Error ? error.message : String(error);\n};\n\nconst report = (record: Reported, properties: Properties = {}) =>\n\tcollector?.({\n\t\t...record,\n\t\tproperties: Object.fromEntries(\n\t\t\tObject.entries(properties).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\treportedValue(value),\n\t\t\t]),\n\t\t),\n\t\tsource: source(),\n\t\tscan: 0,\n\t\ttime: now(),\n\t});\n\n/** What a PLC program's `telemetry` calls do under Bun; see `types/telemetry.d.ts`. */\nexport const telemetry = {\n\tcapture: (event: string, properties?: Properties) =>\n\t\treport({ kind: \"event\", event }, properties),\n\tinfo: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"info\", message }, properties),\n\twarn: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"warn\", message }, properties),\n\terror: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"error\", message }, properties),\n\t// Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.\n\tcaptureException: (error: unknown, properties?: Properties) => {\n\t\tconst code = typeof error === \"number\" ? error : 0;\n\t\tconst name = exceptionName(error);\n\t\treport(\n\t\t\t{ kind: \"exception\", code, ...(name && { name }), handled: true },\n\t\t\tproperties,\n\t\t);\n\t},\n\ttext: (bytes: readonly number[], length: number) => {\n\t\tconst sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));\n\t\tconst end = sent.indexOf(0);\n\t\treturn new Text(\n\t\t\tnew TextDecoder().decode(\n\t\t\t\tUint8Array.from(end < 0 ? sent : sent.slice(0, end)),\n\t\t\t),\n\t\t);\n\t},\n};\n\nexport const onTelemetry = (next: (record: Reported) => void) => {\n\tcollector = next;\n\treturn () => {\n\t\tif (collector === next) {\n\t\t\tcollector = undefined;\n\t\t}\n\t};\n};\n",
6
+ "/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n\t\"1\": \"cancelled\",\n\t\"2\": \"timeout\",\n\t\"3\": \"request or response too large to encode\",\n\t\"4\": \"malformed response\",\n\t\"5\": \"network error or server restarted\",\n\t\"6\": \"TLS error\",\n\t\"7\": \"no free request slot\",\n\t\"10000\": \"HTTP status: 10000 + status code\",\n};\n\n/** An HTTP response fails a job with `base` + its status, up to `last`. */\nexport const httpErrors = { base: 10000, last: 10999 };\n\n/** What a telemetry exception record calls an error code: its meaning when it is a job error. */\nexport const errorName = (code: number): string | undefined => {\n\tif (code > httpErrors.base && code <= httpErrors.last) {\n\t\treturn `HTTP ${code - httpErrors.base}`;\n\t}\n\treturn code < httpErrors.base ? jobErrors[code] : undefined;\n};\n",
7
7
  "/** Milliseconds since the process started, as the PLC's `now()` counts them; used when a program runs under Bun. */\nexport const now = (): number => Math.floor(performance.now());\n"
8
8
  ],
9
- "mappings": ";AAAA;AACA;;;ACAO,IAAM,YAAoC;AAAA,EAC/C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,SAAS;AACX;AAGO,IAAM,aAAa,EAAE,MAAM,KAAO,MAAM,MAAM;AAG9C,IAAM,YAAY,CAAC,SAAqC;AAAA,EAC7D,IAAI,OAAO,WAAW,QAAQ,QAAQ,WAAW;AAAA,IAAM,OAAO,QAAQ,OAAO,WAAW;AAAA,EACxF,OAAO,OAAO,WAAW,OAAO,UAAU,QAAQ;AAAA;;;ACjB7C,IAAM,MAAM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M,GAAG,UAAU;AAAA,EAC5C,MAAM,CAAC,SAAiB,eACvB,OAAO,EAAE,MAAM,OAAO,OAAO,QAAQ,QAAQ,GAAG,UAAU;AAAA,EAC3D,MAAM,CAAC,SAAiB,eACvB,OAAO,EAAE,MAAM,OAAO,OAAO,QAAQ,QAAQ,GAAG,UAAU;AAAA,EAC3D,OAAO,CAAC,SAAiB,eACxB,OAAO,EAAE,MAAM,OAAO,OAAO,SAAS,QAAQ,GAAG,UAAU;AAAA,EAE5D,kBAAkB,CAAC,OAAgB,eAA4B;AAAA,IAC9D,MAAM,OAAO,OAAO,UAAU,WAAW,QAAQ;AAAA,IACjD,MAAM,OAAO,cAAc,KAAK;AAAA,IAChC,OACC,EAAE,MAAM,aAAa,SAAU,QAAQ,EAAE,KAAK,GAAI,SAAS,KAAK,GAChE,UACD;AAAA;AAAA,EAED,MAAM,CAAC,OAA0B,WAAmB;AAAA,IACnD,MAAM,OAAO,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,MAAM,MAAM,CAAC,CAAC;AAAA,IACvE,MAAM,MAAM,KAAK,QAAQ,CAAC;AAAA,IAC1B,OAAO,IAAI,KACV,IAAI,YAAY,EAAE,OACjB,WAAW,KAAK,MAAM,IAAI,OAAO,KAAK,MAAM,GAAG,GAAG,CAAC,CACpD,CACD;AAAA;AAEF;AAEO,IAAM,cAAc,CAAC,SAAqC;AAAA,EAChE,YAAY;AAAA,EACZ,OAAO,MAAM;AAAA,IACZ,IAAI,cAAc,MAAM;AAAA,MACvB,YAAY;AAAA,IACb;AAAA;AAAA;",
10
+ "debugId": "80AC1E2249312EFF64756E2164756E21",
11
11
  "names": []
12
12
  }
package/package.json CHANGED
@@ -1,114 +1,114 @@
1
1
  {
2
- "name": "@tsplc/compiler",
3
- "license": "MIT",
4
- "description": "Write CODESYS PLC programs in TypeScript and compile them to IEC 61131-3 Structured Text. Provides the tsplc CLI.",
5
- "keywords": [
6
- "plc",
7
- "codesys",
8
- "iec-61131-3",
9
- "structured-text",
10
- "typescript",
11
- "compiler"
12
- ],
13
- "homepage": "https://github.com/livingforjesus/tsplc#readme",
14
- "bugs": "https://github.com/livingforjesus/tsplc/issues",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/livingforjesus/tsplc.git",
18
- "directory": "packages/compiler"
19
- },
20
- "version": "0.2.17",
21
- "type": "module",
22
- "exports": {
23
- ".": {
24
- "types": "./src/index.ts",
25
- "bun": "./src/index.ts",
26
- "default": "./dist/index.js"
27
- },
28
- "./ir": {
29
- "types": "./ir/index.ts",
30
- "bun": "./ir/index.ts",
31
- "default": "./dist/ir.js"
32
- },
33
- "./codesys": {
34
- "types": "./backends/codesys/index.ts",
35
- "bun": "./backends/codesys/index.ts",
36
- "default": "./dist/codesys.js"
37
- },
38
- "./project": {
39
- "types": "./project/index.ts",
40
- "bun": "./project/index.ts",
41
- "default": "./dist/project.js"
42
- },
43
- "./clock": {
44
- "types": "./types/clock.d.ts",
45
- "bun": "./stdlib/clock.ts",
46
- "default": "./dist/clock.js"
47
- },
48
- "./telemetry": {
49
- "types": "./types/telemetry.d.ts",
50
- "bun": "./stdlib/telemetry.ts",
51
- "default": "./dist/telemetry.js"
52
- },
53
- "./math": {
54
- "types": "./stdlib/math.ts",
55
- "bun": "./stdlib/math.ts",
56
- "default": "./dist/math.js"
57
- },
58
- "./types": {
59
- "types": "./types/index.d.ts",
60
- "default": "./types/index.d.ts"
61
- },
62
- "./data-types": {
63
- "types": "./types/data-types.d.ts",
64
- "default": "./types/data-types.d.ts"
65
- },
66
- "./globals": {
67
- "types": "./types/globals.d.ts",
68
- "default": "./types/globals.d.ts"
69
- },
70
- "./async": {
71
- "types": "./types/async.d.ts",
72
- "default": "./types/async.d.ts"
73
- },
74
- "./config": {
75
- "types": "./types/config.d.ts",
76
- "default": "./types/config.d.ts"
77
- },
78
- "./plc": {
79
- "types": "./types/plc.d.ts",
80
- "default": "./types/plc.d.ts"
81
- }
82
- },
83
- "files": [
84
- "dist",
85
- "src",
86
- "ir",
87
- "backends",
88
- "project",
89
- "types",
90
- "stdlib",
91
- "!**/*.test.ts",
92
- "!**/__tests__/**"
93
- ],
94
- "engines": {
95
- "bun": ">=1.4.3"
96
- },
97
- "dependencies": {
98
- "@tsplc/agent": "0.2.17",
99
- "@tsplc/build": "0.2.17",
100
- "@tsplc/config": "0.2.17",
101
- "@tsplc/debug": "0.2.17",
102
- "@tsplc/typegen": "0.2.17",
103
- "typescript": "6.0.3",
104
- "zod": "4.3.6",
105
- "@types/bun": "1.4.2",
106
- "@tsplc/server": "0.2.17"
107
- },
108
- "bin": {
109
- "tsplc": "./dist/cli.js"
110
- },
111
- "publishConfig": {
112
- "access": "public"
113
- }
2
+ "name": "@tsplc/compiler",
3
+ "license": "MIT",
4
+ "description": "Write CODESYS PLC programs in TypeScript and compile them to IEC 61131-3 Structured Text. Provides the tsplc CLI.",
5
+ "keywords": [
6
+ "plc",
7
+ "codesys",
8
+ "iec-61131-3",
9
+ "structured-text",
10
+ "typescript",
11
+ "compiler"
12
+ ],
13
+ "homepage": "https://github.com/rip-technologies/tsplc#readme",
14
+ "bugs": "https://github.com/rip-technologies/tsplc/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/rip-technologies/tsplc.git",
18
+ "directory": "packages/compiler"
19
+ },
20
+ "version": "0.2.19",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./src/index.ts",
25
+ "bun": "./src/index.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./ir": {
29
+ "types": "./src/ir/index.ts",
30
+ "bun": "./src/ir/index.ts",
31
+ "default": "./dist/ir.js"
32
+ },
33
+ "./codesys": {
34
+ "types": "./src/codesys/index.ts",
35
+ "bun": "./src/codesys/index.ts",
36
+ "default": "./dist/codesys.js"
37
+ },
38
+ "./project": {
39
+ "types": "./src/project/index.ts",
40
+ "bun": "./src/project/index.ts",
41
+ "default": "./dist/project.js"
42
+ },
43
+ "./clock": {
44
+ "types": "./types/clock.d.ts",
45
+ "bun": "./stdlib/clock.ts",
46
+ "default": "./dist/clock.js"
47
+ },
48
+ "./telemetry": {
49
+ "types": "./types/telemetry.d.ts",
50
+ "bun": "./stdlib/telemetry.ts",
51
+ "default": "./dist/telemetry.js"
52
+ },
53
+ "./math": {
54
+ "types": "./stdlib/math.ts",
55
+ "bun": "./stdlib/math.ts",
56
+ "default": "./dist/math.js"
57
+ },
58
+ "./types": {
59
+ "types": "./types/index.d.ts",
60
+ "default": "./types/index.d.ts"
61
+ },
62
+ "./data-types": {
63
+ "types": "./types/data-types.d.ts",
64
+ "default": "./types/data-types.d.ts"
65
+ },
66
+ "./globals": {
67
+ "types": "./types/globals.d.ts",
68
+ "default": "./types/globals.d.ts"
69
+ },
70
+ "./async": {
71
+ "types": "./types/async.d.ts",
72
+ "default": "./types/async.d.ts"
73
+ },
74
+ "./config": {
75
+ "types": "./types/config.d.ts",
76
+ "default": "./types/config.d.ts"
77
+ },
78
+ "./plc": {
79
+ "types": "./types/plc.d.ts",
80
+ "default": "./types/plc.d.ts"
81
+ },
82
+ "./testing/machine": "./testing/machine.fixtures.ts"
83
+ },
84
+ "files": [
85
+ "dist",
86
+ "src",
87
+ "types",
88
+ "stdlib",
89
+ "!**/*.test.ts",
90
+ "!**/*.fixtures.ts"
91
+ ],
92
+ "engines": {
93
+ "bun": ">=1.4.3"
94
+ },
95
+ "dependencies": {
96
+ "@tsplc/agent": "0.2.19",
97
+ "@tsplc/build": "0.2.19",
98
+ "@tsplc/config": "0.2.19",
99
+ "@tsplc/debug": "0.2.19",
100
+ "@tsplc/opcua": "0.2.19",
101
+ "@tsplc/typegen": "0.2.19",
102
+ "typescript": "6.0.3",
103
+ "zod": "4.3.6",
104
+ "@types/bun": "1.4.2",
105
+ "@tsplc/server": "0.2.19",
106
+ "@tsplc/iec": "0.2.19"
107
+ },
108
+ "bin": {
109
+ "tsplc": "./dist/cli.js"
110
+ },
111
+ "publishConfig": {
112
+ "access": "public"
113
+ }
114
114
  }
@@ -0,0 +1,50 @@
1
+ import {
2
+ httpOptionsSchema,
3
+ buildTargetSchema,
4
+ publicationSchema,
5
+ type TargetDescriptor,
6
+ } from "@tsplc/config";
7
+ import { directIoBindingSchema } from "@tsplc/config/build";
8
+ import { z } from "zod";
9
+ import { engineeringSchema } from "./engineering.ts";
10
+ import { isIecIdentifier } from "./names.ts";
11
+
12
+ const addressSchema = directIoBindingSchema.extend({
13
+ kind: z.literal("direct"),
14
+ // A generated device tree maps this bit or byte channel to its target
15
+ // variable, so the scan needs no AT wire or copy.
16
+ mapped: z.boolean().optional(),
17
+ });
18
+ // Explicit IEC object names keep their exact spelling, so they must already be valid.
19
+ const iecNames = z
20
+ .record(
21
+ z.string().min(1),
22
+ z
23
+ .string()
24
+ .refine(isIecIdentifier, "Use a valid, non-reserved IEC identifier."),
25
+ )
26
+ .optional();
27
+ export const optionsSchema = z
28
+ .object({
29
+ engineering: engineeringSchema,
30
+ http: httpOptionsSchema,
31
+ io: z.record(z.string().min(1), addressSchema),
32
+ publish: publicationSchema.default({ production: [], development: [] }),
33
+ buildTarget: buildTargetSchema.default("production"),
34
+ programNames: iecNames,
35
+ })
36
+ .strict();
37
+ export type CodesysOptions = z.infer<typeof optionsSchema>;
38
+ export function codesys(
39
+ options: z.input<typeof optionsSchema>,
40
+ ): TargetDescriptor<z.input<typeof optionsSchema>> {
41
+ return { kind: "codesys", options };
42
+ }
43
+ // tsPLC binds nothing at 64-bit addresses, so `%IL`/`%QL` are not offered.
44
+ export function direct(
45
+ address:
46
+ | `%${"I" | "Q"}X${number}.${number}`
47
+ | `%${"I" | "Q"}${"B" | "W" | "D"}${number}`,
48
+ ): z.infer<typeof addressSchema> {
49
+ return { kind: "direct", address };
50
+ }