@tsplc/tmp-compiler 0.0.0-stage → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/cli.js +2325 -0
- package/dist/cli.js.map +26 -0
- package/dist/clock.js +11 -0
- package/dist/clock.js.map +11 -0
- package/dist/codesys.js +6558 -0
- package/dist/codesys.js.map +51 -0
- package/dist/collections.js +399 -0
- package/dist/collections.js.map +10 -0
- package/dist/index.js +16076 -0
- package/dist/index.js.map +61 -0
- package/dist/ir.js +3948 -0
- package/dist/ir.js.map +35 -0
- package/dist/retain.js +10 -0
- package/dist/retain.js.map +10 -0
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +121 -0
- package/dist/telemetry.js.map +12 -0
- package/package.json +122 -4
- package/src/codesys/config.ts +50 -0
- package/src/codesys/debug.ts +655 -0
- package/src/codesys/emit.ts +185 -0
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +96 -0
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +149 -0
- package/src/codesys/expressions.ts +100 -0
- package/src/codesys/global-lists.ts +284 -0
- package/src/codesys/global-names.ts +66 -0
- package/src/codesys/http.ts +1078 -0
- package/src/codesys/index.ts +13 -0
- package/src/codesys/instrumentation.ts +574 -0
- package/src/codesys/io-paths.ts +149 -0
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +684 -0
- package/src/codesys/names.ts +58 -0
- package/src/codesys/numeric.ts +516 -0
- package/src/codesys/plan.ts +688 -0
- package/src/codesys/programs.ts +138 -0
- package/src/codesys/publication.ts +99 -0
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +247 -0
- package/src/codesys/scan-clock.ts +103 -0
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +24 -0
- package/src/codesys/sources.ts +118 -0
- package/src/codesys/st-files.ts +219 -0
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +150 -0
- package/src/codesys/symbols.ts +240 -0
- package/src/codesys/task-access.ts +186 -0
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +852 -0
- package/src/codesys/types.ts +310 -0
- package/src/codesys/vendor.ts +113 -0
- package/src/frontend/analyzer.ts +779 -0
- package/src/frontend/async.ts +530 -0
- package/src/frontend/blocks.ts +578 -0
- package/src/frontend/configuration.ts +83 -0
- package/src/frontend/const-functions.ts +204 -0
- package/src/frontend/control-flow.ts +787 -0
- package/src/frontend/cooperative.ts +114 -0
- package/src/frontend/coroutines.ts +1336 -0
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +224 -0
- package/src/frontend/elaborate/assignments.ts +343 -0
- package/src/frontend/elaborate/calls.ts +1342 -0
- package/src/frontend/elaborate/capture-protocol.ts +237 -0
- package/src/frontend/elaborate/capture.ts +388 -0
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +473 -0
- package/src/frontend/elaborate/expressions.ts +2171 -0
- package/src/frontend/elaborate/filtered-arrays.ts +643 -0
- package/src/frontend/elaborate/frame.ts +145 -0
- package/src/frontend/elaborate/generics.ts +123 -0
- package/src/frontend/elaborate/graph.ts +141 -0
- package/src/frontend/elaborate/imports.ts +105 -0
- package/src/frontend/elaborate/index.ts +851 -0
- package/src/frontend/elaborate/initializers.ts +235 -0
- package/src/frontend/elaborate/iterators.ts +1541 -0
- package/src/frontend/elaborate/layouts.ts +1025 -0
- package/src/frontend/elaborate/model.ts +478 -0
- package/src/frontend/elaborate/names.ts +134 -0
- package/src/frontend/elaborate/reduce.ts +900 -0
- package/src/frontend/elaborate/references.ts +727 -0
- package/src/frontend/elaborate/retention.ts +284 -0
- package/src/frontend/elaborate/specialize.ts +1137 -0
- package/src/frontend/elaborate/statements.ts +1220 -0
- package/src/frontend/elaborate/storage.ts +836 -0
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +200 -0
- package/src/frontend/elaborate/writes.ts +415 -0
- package/src/frontend/expressions.ts +1382 -0
- package/src/frontend/generated-names.ts +95 -0
- package/src/frontend/intrinsics.ts +382 -0
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +156 -0
- package/src/frontend/positions.ts +359 -0
- package/src/frontend/promise-chains.ts +872 -0
- package/src/frontend/promises.ts +419 -0
- package/src/frontend/routines.ts +239 -0
- package/src/frontend/sdk.ts +187 -0
- package/src/frontend/services.ts +609 -0
- package/src/frontend/statements.ts +871 -0
- package/src/frontend/tasks.ts +526 -0
- package/src/frontend/telemetry.ts +174 -0
- package/src/frontend/types.ts +1073 -0
- package/src/frontend/typescript.ts +651 -0
- package/src/index.ts +9 -0
- package/src/ir/aggregates.ts +291 -0
- package/src/ir/allocation.ts +96 -0
- package/src/ir/conditions.ts +855 -0
- package/src/ir/core-model.ts +289 -0
- package/src/ir/declarations.ts +281 -0
- package/src/ir/diagnostics.ts +68 -0
- package/src/ir/domains.ts +151 -0
- package/src/ir/fold.ts +279 -0
- package/src/ir/identity.ts +19 -0
- package/src/ir/index.ts +137 -0
- package/src/ir/job-errors.ts +69 -0
- package/src/ir/layouts.ts +211 -0
- package/src/ir/link.ts +302 -0
- package/src/ir/model.ts +394 -0
- package/src/ir/normalization-error.ts +10 -0
- package/src/ir/normalize.ts +52 -0
- package/src/ir/numeric.ts +163 -0
- package/src/ir/operands.ts +160 -0
- package/src/ir/ranges.ts +420 -0
- package/src/ir/routine.ts +1116 -0
- package/src/ir/scalars.ts +453 -0
- package/src/ir/share.ts +790 -0
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +138 -0
- package/src/ir/types.ts +151 -0
- package/src/project/artifacts.ts +424 -0
- package/src/project/cli.ts +211 -0
- package/src/project/debugger.ts +111 -0
- package/src/project/deployments.ts +387 -0
- package/src/project/flags.ts +14 -0
- package/src/project/git.ts +35 -0
- package/src/project/plant.ts +629 -0
- package/src/project/project-commands.ts +507 -0
- package/src/project/project.ts +559 -0
- package/src/project/release.ts +152 -0
- package/src/project/server-check.ts +54 -0
- package/src/project/server.ts +165 -0
- package/src/project/terminal.ts +45 -0
- package/src/runtime/async.ts +207 -0
- package/src/runtime/launch.ts +59 -0
- package/src/runtime/main.ts +59 -0
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +177 -0
- package/src/runtime/program.ts +109 -0
- package/src/runtime/retain.ts +108 -0
- package/src/runtime/runtime.ts +324 -0
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +456 -0
- package/src/runtime/symbols.ts +97 -0
- package/src/runtime/telemetry.ts +154 -0
- package/src/runtime/transport.ts +168 -0
- package/stdlib/clock.ts +8 -0
- package/stdlib/collections.ts +534 -0
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +4 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +89 -0
- package/types/async.d.ts +87 -0
- package/types/clock.d.ts +8 -0
- package/types/config.d.ts +2 -0
- package/types/data-types.d.ts +31 -0
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +10 -0
- package/types/index.d.ts +212 -0
- package/types/retain.d.ts +12 -0
- package/types/telemetry.d.ts +47 -0
package/dist/retain.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../stdlib/retain.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** `retain` as a program running under Bun sees it: retention is the PLC's, so the value passes through. */\nexport const retain = <T>(value: T): T => value;\n/** `persist` as a program running under Bun sees it: as `retain`, the value passes through. */\nexport const persist = <T>(value: T): T => value;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AACO,IAAM,SAAS,CAAI,UAAgB;AAEnC,IAAM,UAAU,CAAI,UAAgB;",
|
|
8
|
+
"debugId": "285AE75D69F13A9864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/signals.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// packages/compiler/stdlib/signals.ts
|
|
2
|
+
var elapsedSince = (last, now) => last === undefined ? 0 : Math.max(now - last, 0);
|
|
3
|
+
|
|
4
|
+
class OnDelayTimer {
|
|
5
|
+
durationMs;
|
|
6
|
+
heldMs = 0;
|
|
7
|
+
previous = false;
|
|
8
|
+
lastNow;
|
|
9
|
+
constructor(durationMs) {
|
|
10
|
+
this.durationMs = durationMs;
|
|
11
|
+
}
|
|
12
|
+
get elapsedMs() {
|
|
13
|
+
return this.heldMs;
|
|
14
|
+
}
|
|
15
|
+
get output() {
|
|
16
|
+
return this.previous && this.heldMs >= this.durationMs;
|
|
17
|
+
}
|
|
18
|
+
update(now, input) {
|
|
19
|
+
const step = elapsedSince(this.lastNow, now);
|
|
20
|
+
this.lastNow = now;
|
|
21
|
+
this.heldMs = input && this.previous ? Math.min(this.heldMs + step, this.durationMs) : 0;
|
|
22
|
+
this.previous = input;
|
|
23
|
+
return this.output;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class OffDelayTimer {
|
|
28
|
+
durationMs;
|
|
29
|
+
offMs = 0;
|
|
30
|
+
previous = false;
|
|
31
|
+
on = false;
|
|
32
|
+
lastNow;
|
|
33
|
+
constructor(durationMs) {
|
|
34
|
+
this.durationMs = durationMs;
|
|
35
|
+
}
|
|
36
|
+
get elapsedMs() {
|
|
37
|
+
return this.offMs;
|
|
38
|
+
}
|
|
39
|
+
get output() {
|
|
40
|
+
return this.on;
|
|
41
|
+
}
|
|
42
|
+
update(now, input) {
|
|
43
|
+
const step = elapsedSince(this.lastNow, now);
|
|
44
|
+
this.lastNow = now;
|
|
45
|
+
if (input) {
|
|
46
|
+
this.on = true;
|
|
47
|
+
this.offMs = 0;
|
|
48
|
+
} else if (this.on) {
|
|
49
|
+
this.offMs = this.previous ? 0 : Math.min(this.offMs + step, this.durationMs);
|
|
50
|
+
this.on = this.offMs < this.durationMs;
|
|
51
|
+
}
|
|
52
|
+
this.previous = input;
|
|
53
|
+
return this.on;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class PulseTimer {
|
|
58
|
+
durationMs;
|
|
59
|
+
onMs = 0;
|
|
60
|
+
previous = false;
|
|
61
|
+
on = false;
|
|
62
|
+
lastNow;
|
|
63
|
+
constructor(durationMs) {
|
|
64
|
+
this.durationMs = durationMs;
|
|
65
|
+
}
|
|
66
|
+
get elapsedMs() {
|
|
67
|
+
return this.onMs;
|
|
68
|
+
}
|
|
69
|
+
get output() {
|
|
70
|
+
return this.on;
|
|
71
|
+
}
|
|
72
|
+
update(now, input) {
|
|
73
|
+
const step = elapsedSince(this.lastNow, now);
|
|
74
|
+
this.lastNow = now;
|
|
75
|
+
if (this.on) {
|
|
76
|
+
this.onMs = Math.min(this.onMs + step, this.durationMs);
|
|
77
|
+
this.on = this.onMs < this.durationMs;
|
|
78
|
+
} else if (input && !this.previous) {
|
|
79
|
+
this.on = true;
|
|
80
|
+
this.onMs = 0;
|
|
81
|
+
}
|
|
82
|
+
this.previous = input;
|
|
83
|
+
return this.on;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class RisingEdge {
|
|
88
|
+
previous = false;
|
|
89
|
+
rose = false;
|
|
90
|
+
update(input) {
|
|
91
|
+
this.rose = input && !this.previous;
|
|
92
|
+
this.previous = input;
|
|
93
|
+
return this.rose;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class FallingEdge {
|
|
98
|
+
previous = false;
|
|
99
|
+
fell = false;
|
|
100
|
+
update(input) {
|
|
101
|
+
this.fell = this.previous && !input;
|
|
102
|
+
this.previous = input;
|
|
103
|
+
return this.fell;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
FallingEdge,
|
|
108
|
+
OffDelayTimer,
|
|
109
|
+
OnDelayTimer,
|
|
110
|
+
PulseTimer,
|
|
111
|
+
RisingEdge
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//# debugId=A826A69143FC38D864756E2164756E21
|
|
115
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../stdlib/signals.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// PLC implementation source: timers and edge detectors for a plain TypeScript program. Each is an\n// ordinary class the compiler specializes like a program's own, and the same classes run under Bun\n// for tests and simulation. Every update takes the scan's `now()`, so one scan reads one time.\n\n/**\n * Milliseconds since `last`, the previous update's `now()`. The PLC clock is a DINT that wraps\n * after 24.8 days: on the PLC the subtraction wraps with it, and under Bun the one negative step\n * across the wrap counts as none, so a timer measures scan by scan instead of from a start time.\n */\nconst elapsedSince = (last: number | undefined, now: number): number =>\n\tlast === undefined ? 0 : Math.max(now - last, 0);\n\n/** Turns its output on once the input has been on for `durationMs`, and off as soon as the input goes off. IEC `TON`. */\nexport class OnDelayTimer {\n\tprivate heldMs = 0;\n\tprivate previous = false;\n\tprivate lastNow: number | undefined;\n\n\tconstructor(readonly durationMs: number) {}\n\n\t/** How long the input has been on, up to `durationMs`. */\n\tget elapsedMs(): number {\n\t\treturn this.heldMs;\n\t}\n\n\tget output(): boolean {\n\t\treturn this.previous && this.heldMs >= this.durationMs;\n\t}\n\n\t/** Takes this scan's input and `now()`, and returns the output. */\n\tupdate(now: number, input: boolean): boolean {\n\t\tconst step = elapsedSince(this.lastNow, now);\n\t\tthis.lastNow = now;\n\t\tthis.heldMs =\n\t\t\tinput && this.previous\n\t\t\t\t? Math.min(this.heldMs + step, this.durationMs)\n\t\t\t\t: 0;\n\t\tthis.previous = input;\n\t\treturn this.output;\n\t}\n}\n\n/** Turns its output on with the input, and off once the input has been off for `durationMs`. IEC `TOF`. */\nexport class OffDelayTimer {\n\tprivate offMs = 0;\n\tprivate previous = false;\n\tprivate on = false;\n\tprivate lastNow: number | undefined;\n\n\tconstructor(readonly durationMs: number) {}\n\n\t/** How long the input has been off since the output last turned on, up to `durationMs`. */\n\tget elapsedMs(): number {\n\t\treturn this.offMs;\n\t}\n\n\tget output(): boolean {\n\t\treturn this.on;\n\t}\n\n\t/** Takes this scan's input and `now()`, and returns the output. */\n\tupdate(now: number, input: boolean): boolean {\n\t\tconst step = elapsedSince(this.lastNow, now);\n\t\tthis.lastNow = now;\n\t\tif (input) {\n\t\t\tthis.on = true;\n\t\t\tthis.offMs = 0;\n\t\t} else if (this.on) {\n\t\t\tthis.offMs = this.previous\n\t\t\t\t? 0\n\t\t\t\t: Math.min(this.offMs + step, this.durationMs);\n\t\t\tthis.on = this.offMs < this.durationMs;\n\t\t}\n\t\tthis.previous = input;\n\t\treturn this.on;\n\t}\n}\n\n/**\n * Turns its output on for `durationMs` when the input rises, whatever the input does meanwhile. A\n * new pulse needs the input to rise again after the last one ends. IEC `TP`.\n */\nexport class PulseTimer {\n\tprivate onMs = 0;\n\tprivate previous = false;\n\tprivate on = false;\n\tprivate lastNow: number | undefined;\n\n\tconstructor(readonly durationMs: number) {}\n\n\t/** How long the current pulse has lasted, up to `durationMs`. */\n\tget elapsedMs(): number {\n\t\treturn this.onMs;\n\t}\n\n\tget output(): boolean {\n\t\treturn this.on;\n\t}\n\n\t/** Takes this scan's input and `now()`, and returns the output. */\n\tupdate(now: number, input: boolean): boolean {\n\t\tconst step = elapsedSince(this.lastNow, now);\n\t\tthis.lastNow = now;\n\t\tif (this.on) {\n\t\t\tthis.onMs = Math.min(this.onMs + step, this.durationMs);\n\t\t\tthis.on = this.onMs < this.durationMs;\n\t\t} else if (input && !this.previous) {\n\t\t\tthis.on = true;\n\t\t\tthis.onMs = 0;\n\t\t}\n\t\tthis.previous = input;\n\t\treturn this.on;\n\t}\n}\n\n/** True for the one scan in which its input goes from off to on, including an input already on at the first scan. IEC `R_TRIG`. */\nexport class RisingEdge {\n\tprivate previous = false;\n\t/** Whether the last update saw the input rise. */\n\trose = false;\n\n\t/** Takes this scan's input, and returns whether it rose. */\n\tupdate(input: boolean): boolean {\n\t\tthis.rose = input && !this.previous;\n\t\tthis.previous = input;\n\t\treturn this.rose;\n\t}\n}\n\n/** True for the one scan in which its input goes from on to off. An input off from the first scan never falls. */\nexport class FallingEdge {\n\tprivate previous = false;\n\t/** Whether the last update saw the input fall. */\n\tfell = false;\n\n\t/** Takes this scan's input, and returns whether it fell. */\n\tupdate(input: boolean): boolean {\n\t\tthis.fell = this.previous && !input;\n\t\tthis.previous = input;\n\t\treturn this.fell;\n\t}\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AASA,IAAM,eAAe,CAAC,MAA0B,QAC/C,SAAS,YAAY,IAAI,KAAK,IAAI,MAAM,MAAM,CAAC;AAAA;AAGzC,MAAM,aAAa;AAAA,EAKJ;AAAA,EAJb,SAAS;AAAA,EACT,WAAW;AAAA,EACX;AAAA,EAER,WAAW,CAAU,YAAoB;AAAA,IAApB;AAAA;AAAA,MAGjB,SAAS,GAAW;AAAA,IACvB,OAAO,KAAK;AAAA;AAAA,MAGT,MAAM,GAAY;AAAA,IACrB,OAAO,KAAK,YAAY,KAAK,UAAU,KAAK;AAAA;AAAA,EAI7C,MAAM,CAAC,KAAa,OAAyB;AAAA,IAC5C,MAAM,OAAO,aAAa,KAAK,SAAS,GAAG;AAAA,IAC3C,KAAK,UAAU;AAAA,IACf,KAAK,SACJ,SAAS,KAAK,WACX,KAAK,IAAI,KAAK,SAAS,MAAM,KAAK,UAAU,IAC5C;AAAA,IACJ,KAAK,WAAW;AAAA,IAChB,OAAO,K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AAS,CAAC,KAAK,UAAU;AAAA,MACnC,KAAK,KAAK;AAAA,MACV,KAAK,OAAO;AAAA,IACb;AAAA,IACA,KAAK,WAAW;AAAA,IAChB,OAAO,KAAK;AAAA;AAEd;AAAA;AAGO,MAAM,WAAW;AAAA,EACf,WAAW;AAAA,EAEnB,OAAO;AAAA,EAGP,MAAM,CAAC,OAAyB;AAAA,IAC/B,KAAK,OAAO,SAAS,CAAC,KAAK;AAAA,IAC3B,KAAK,WAAW;AAAA,IAChB,OAAO,KAAK;AAAA;AAEd;AAAA;AAGO,MAAM,YAAY;AAAA,EAChB,WAAW;AAAA,EAEnB,OAAO;AAAA,EAGP,MAAM,CAAC,OAAyB;AAAA,IAC/B,KAAK,OAAO,KAAK,YAAY,CAAC;AAAA,IAC9B,KAAK,WAAW;AAAA,IAChB,OAAO,KAAK;AAAA;AAEd;",
|
|
8
|
+
"debugId": "A826A69143FC38D864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// packages/compiler/stdlib/telemetry.ts
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// packages/compiler/src/ir/job-errors.ts
|
|
6
|
+
var jobError = {
|
|
7
|
+
cancelled: 1,
|
|
8
|
+
timeout: 2,
|
|
9
|
+
tooLarge: 3,
|
|
10
|
+
malformedResponse: 4,
|
|
11
|
+
network: 5,
|
|
12
|
+
tls: 6,
|
|
13
|
+
noRequestSlot: 7,
|
|
14
|
+
codeChanged: 11001
|
|
15
|
+
};
|
|
16
|
+
var httpBase = 1e4;
|
|
17
|
+
var httpErrors = {
|
|
18
|
+
base: httpBase,
|
|
19
|
+
last: 10999,
|
|
20
|
+
refused: httpBase + 400
|
|
21
|
+
};
|
|
22
|
+
var errorMeanings = {
|
|
23
|
+
[jobError.cancelled]: "cancelled",
|
|
24
|
+
[jobError.timeout]: "timeout",
|
|
25
|
+
[jobError.tooLarge]: "request or response too large to encode",
|
|
26
|
+
[jobError.malformedResponse]: "malformed response",
|
|
27
|
+
[jobError.network]: "network error or server restarted",
|
|
28
|
+
[jobError.tls]: "TLS error",
|
|
29
|
+
[jobError.noRequestSlot]: "no free request slot",
|
|
30
|
+
[jobError.codeChanged]: "an online change replaced the job's code while it ran"
|
|
31
|
+
};
|
|
32
|
+
var jobErrors = {
|
|
33
|
+
...errorMeanings,
|
|
34
|
+
[httpErrors.base]: `HTTP status: ${httpErrors.base} + status code`
|
|
35
|
+
};
|
|
36
|
+
var errorName = (code) => {
|
|
37
|
+
if (code > httpErrors.base && code <= httpErrors.last) {
|
|
38
|
+
return `HTTP ${code - httpErrors.base}`;
|
|
39
|
+
}
|
|
40
|
+
return errorMeanings[code];
|
|
41
|
+
};
|
|
42
|
+
var failureCode = (reason) => typeof reason === "number" ? reason : 0;
|
|
43
|
+
var failureName = (reason) => {
|
|
44
|
+
if (typeof reason === "number") {
|
|
45
|
+
return errorName(reason);
|
|
46
|
+
}
|
|
47
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// packages/compiler/stdlib/plc-time.ts
|
|
51
|
+
var plcTime = () => Math.floor(performance.now()) >>> 0;
|
|
52
|
+
|
|
53
|
+
// packages/compiler/stdlib/telemetry.ts
|
|
54
|
+
class Text {
|
|
55
|
+
value;
|
|
56
|
+
constructor(value) {
|
|
57
|
+
this.value = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var module = fileURLToPath(import.meta.url);
|
|
61
|
+
var collector;
|
|
62
|
+
var source = () => {
|
|
63
|
+
for (const line of new Error().stack?.split(`
|
|
64
|
+
`) ?? []) {
|
|
65
|
+
const [, file, lineNumber] = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line) ?? [];
|
|
66
|
+
if (file && file !== module) {
|
|
67
|
+
return `${relative(process.cwd(), file).replaceAll("\\", "/")}:${lineNumber}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return "";
|
|
71
|
+
};
|
|
72
|
+
var reportedValue = (value) => {
|
|
73
|
+
if (value instanceof Text) {
|
|
74
|
+
return value.value;
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === "bigint") {
|
|
77
|
+
return Number(value);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
};
|
|
81
|
+
var report = (record, properties = {}) => collector?.({
|
|
82
|
+
...record,
|
|
83
|
+
properties: Object.fromEntries(Object.entries(properties).map(([name, value]) => [
|
|
84
|
+
name,
|
|
85
|
+
reportedValue(value)
|
|
86
|
+
])),
|
|
87
|
+
source: source(),
|
|
88
|
+
scan: 0,
|
|
89
|
+
time: plcTime()
|
|
90
|
+
});
|
|
91
|
+
var telemetry = {
|
|
92
|
+
capture: (event, properties) => report({ kind: "event", event }, properties),
|
|
93
|
+
info: (message, properties) => report({ kind: "log", level: "info", message }, properties),
|
|
94
|
+
warn: (message, properties) => report({ kind: "log", level: "warn", message }, properties),
|
|
95
|
+
error: (message, properties) => report({ kind: "log", level: "error", message }, properties),
|
|
96
|
+
captureException: (error, properties) => {
|
|
97
|
+
const code = failureCode(error);
|
|
98
|
+
const name = failureName(error);
|
|
99
|
+
report({ kind: "exception", code, ...name && { name }, handled: true }, properties);
|
|
100
|
+
},
|
|
101
|
+
text: (bytes, length) => {
|
|
102
|
+
const sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));
|
|
103
|
+
const end = sent.indexOf(0);
|
|
104
|
+
return new Text(new TextDecoder().decode(Uint8Array.from(end < 0 ? sent : sent.slice(0, end))));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var onTelemetry = (next) => {
|
|
108
|
+
collector = next;
|
|
109
|
+
return () => {
|
|
110
|
+
if (collector === next) {
|
|
111
|
+
collector = undefined;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
onTelemetry,
|
|
117
|
+
telemetry
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//# debugId=A73F9037C038FC8864756E2164756E21
|
|
121
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../stdlib/telemetry.ts", "../src/ir/job-errors.ts", "../stdlib/plc-time.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { failureCode, failureName } from \"../src/ir/job-errors\";\nimport { plcTime } from \"./plc-time\";\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 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: plcTime(),\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 = failureCode(error);\n\t\tconst name = failureName(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 by meaning, as generated async blocks and service calls set them. */\nexport const jobError = {\n\tcancelled: 1,\n\ttimeout: 2,\n\ttooLarge: 3,\n\tmalformedResponse: 4,\n\tnetwork: 5,\n\ttls: 6,\n\tnoRequestSlot: 7,\n\t/**\n\t * An online change replaced the code of a job that was running: its step and stored state\n\t * were made for the old code, so it stops instead of resuming in the new. Like `cancelled`,\n\t * it skips `catch`, so a retry can't send a request twice.\n\t */\n\tcodeChanged: 11001,\n} as const;\n\nconst httpBase = 10000;\n\n/**\n * An HTTP response fails a job with `base` + its status, up to `last`. `refused` is a 400: the\n * server can't take the request, so sending it again cannot succeed.\n */\nexport const httpErrors = {\n\tbase: httpBase,\n\tlast: 10999,\n\trefused: httpBase + 400,\n};\n\n/** Codes tsPLC itself reports from 11000 on, which a program's own `throw` may not use. */\nexport const reservedErrors = { first: 11000, last: 11099 };\n\nconst errorMeanings: Record<number, string> = {\n\t[jobError.cancelled]: \"cancelled\",\n\t[jobError.timeout]: \"timeout\",\n\t[jobError.tooLarge]: \"request or response too large to encode\",\n\t[jobError.malformedResponse]: \"malformed response\",\n\t[jobError.network]: \"network error or server restarted\",\n\t[jobError.tls]: \"TLS error\",\n\t[jobError.noRequestSlot]: \"no free request slot\",\n\t[jobError.codeChanged]:\n\t\t\"an online change replaced the job's code while it ran\",\n};\n\n/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n\t...errorMeanings,\n\t[httpErrors.base]: `HTTP status: ${httpErrors.base} + status code`,\n};\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 errorMeanings[code];\n};\n\n/** The code a failure reports: its job error code, or 0 for anything else thrown, such as an Error under Bun. */\nexport const failureCode = (reason: unknown): number =>\n\ttypeof reason === \"number\" ? reason : 0;\n\n/** What an exception record calls a failure: a job error's meaning, or a thrown Error's message. */\nexport const failureName = (reason: unknown): string | undefined => {\n\tif (typeof reason === \"number\") {\n\t\treturn errorName(reason);\n\t}\n\treturn reason instanceof Error ? reason.message : String(reason);\n};\n",
|
|
7
|
+
"/** Milliseconds since the process started, as the PLC's `TIME()` counts them in a UDINT, which telemetry's `time` carries. */\nexport const plcTime = (): number => Math.floor(performance.now()) >>> 0;\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AAAA;AACA;;;ACAO,IAAM,WAAW;AAAA,EACvB,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,SAA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,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": "A73F9037C038FC8864756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,124 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsplc/tmp-compiler",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
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.6.2",
|
|
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
|
+
"./clock": {
|
|
39
|
+
"types": "./types/clock.d.ts",
|
|
40
|
+
"bun": "./stdlib/clock.ts",
|
|
41
|
+
"default": "./dist/clock.js"
|
|
42
|
+
},
|
|
43
|
+
"./telemetry": {
|
|
44
|
+
"types": "./types/telemetry.d.ts",
|
|
45
|
+
"bun": "./stdlib/telemetry.ts",
|
|
46
|
+
"default": "./dist/telemetry.js"
|
|
47
|
+
},
|
|
48
|
+
"./retain": {
|
|
49
|
+
"types": "./types/retain.d.ts",
|
|
50
|
+
"bun": "./stdlib/retain.ts",
|
|
51
|
+
"default": "./dist/retain.js"
|
|
52
|
+
},
|
|
53
|
+
"./collections": {
|
|
54
|
+
"types": "./stdlib/collections.ts",
|
|
55
|
+
"bun": "./stdlib/collections.ts",
|
|
56
|
+
"default": "./dist/collections.js"
|
|
57
|
+
},
|
|
58
|
+
"./signals": {
|
|
59
|
+
"types": "./stdlib/signals.ts",
|
|
60
|
+
"bun": "./stdlib/signals.ts",
|
|
61
|
+
"default": "./dist/signals.js"
|
|
62
|
+
},
|
|
63
|
+
"./types": {
|
|
64
|
+
"types": "./types/index.d.ts",
|
|
65
|
+
"default": "./types/index.d.ts"
|
|
66
|
+
},
|
|
67
|
+
"./globals": {
|
|
68
|
+
"types": "./types/globals.d.ts",
|
|
69
|
+
"default": "./types/globals.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./async": {
|
|
72
|
+
"types": "./types/async.d.ts",
|
|
73
|
+
"default": "./types/async.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./config": {
|
|
76
|
+
"types": "./types/config.d.ts",
|
|
77
|
+
"default": "./types/config.d.ts"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"files": [
|
|
81
|
+
"dist",
|
|
82
|
+
"src",
|
|
83
|
+
"types",
|
|
84
|
+
"stdlib",
|
|
85
|
+
"!**/*.test.ts",
|
|
86
|
+
"!**/*.fixtures.ts",
|
|
87
|
+
"!**/test_*.py",
|
|
88
|
+
"!**/__pycache__/**",
|
|
89
|
+
"!**/*.pyc",
|
|
90
|
+
"!**/tests/**"
|
|
91
|
+
],
|
|
92
|
+
"engines": {
|
|
93
|
+
"bun": ">=1.4.3"
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"@tsplc/agent": "npm:@tsplc/tmp-agent@0.6.2",
|
|
97
|
+
"@tsplc/build": "npm:@tsplc/tmp-build@0.6.2",
|
|
98
|
+
"@tsplc/config": "npm:@tsplc/tmp-config@0.6.2",
|
|
99
|
+
"@tsplc/debug": "npm:@tsplc/tmp-debug@0.6.2",
|
|
100
|
+
"@tsplc/opcua": "npm:@tsplc/tmp-opcua@0.6.2",
|
|
101
|
+
"@tsplc/typegen": "npm:@tsplc/tmp-typegen@0.6.2",
|
|
102
|
+
"typescript": "6.0.3",
|
|
103
|
+
"zod": "4.3.6",
|
|
104
|
+
"@types/bun": "1.4.2",
|
|
105
|
+
"@tsplc/server": "npm:@tsplc/tmp-server@0.6.2",
|
|
106
|
+
"@tsplc/iec": "npm:@tsplc/tmp-iec@0.6.2"
|
|
107
|
+
},
|
|
108
|
+
"bin": {
|
|
109
|
+
"tsplc": "./dist/cli.js"
|
|
110
|
+
},
|
|
111
|
+
"buildEntries": {
|
|
112
|
+
"./dist/cli.js": {
|
|
113
|
+
"source": "./src/project/cli.ts"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"imports": {
|
|
117
|
+
"#elaborate-capture": "./src/frontend/elaborate/capture.ts",
|
|
118
|
+
"#bun-runtime": "./src/runtime/main.ts",
|
|
119
|
+
"#server-check": "./src/project/server-check.ts"
|
|
120
|
+
},
|
|
121
|
+
"publishConfig": {
|
|
122
|
+
"access": "public"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildTargetSchema,
|
|
3
|
+
httpOptionsSchema,
|
|
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";
|
|
10
|
+
import { isIecIdentifier } from "./names";
|
|
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().nonempty(),
|
|
22
|
+
z
|
|
23
|
+
.string()
|
|
24
|
+
.refine(isIecIdentifier, "Use a valid, non-reserved IEC identifier."),
|
|
25
|
+
)
|
|
26
|
+
.default({});
|
|
27
|
+
export const optionsSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
engineering: engineeringSchema,
|
|
30
|
+
http: httpOptionsSchema,
|
|
31
|
+
io: z.record(z.string().nonempty(), 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
|
+
}
|