@tsplc/compiler 0.2.14 → 0.2.17
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/backends/codesys/debug.ts +509 -0
- package/backends/codesys/emit.ts +701 -9
- package/backends/codesys/http.ts +110 -34
- package/backends/codesys/index.ts +2 -1
- package/backends/codesys/io-paths.ts +3 -1
- package/backends/codesys/manifest.ts +312 -0
- package/backends/codesys/plan.ts +39 -9
- package/backends/codesys/publication.ts +2 -2
- package/backends/codesys/storage.ts +10 -3
- package/backends/codesys/task-access.ts +51 -1
- package/backends/codesys/telemetry.ts +593 -0
- package/backends/codesys/types.ts +2 -1
- package/dist/cli.js +190 -33
- package/dist/cli.js.map +6 -6
- package/dist/codesys.js +2148 -432
- package/dist/codesys.js.map +14 -11
- package/dist/elaborate-capture.js +7 -1
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +877 -459
- package/dist/index.js.map +16 -15
- package/dist/ir.js +87 -23
- package/dist/ir.js.map +10 -9
- package/dist/project.js +42 -9
- package/dist/project.js.map +3 -3
- package/dist/telemetry.js +83 -0
- package/dist/telemetry.js.map +12 -0
- package/ir/core-model.ts +13 -0
- package/ir/core.ts +1 -0
- package/ir/errors.ts +20 -0
- package/ir/index.ts +1 -0
- package/ir/link.ts +17 -8
- package/ir/model.ts +39 -0
- package/ir/routine.ts +62 -29
- package/ir/types.ts +7 -1
- package/package.json +12 -6
- package/project/cli.ts +96 -6
- package/project/plant.ts +58 -9
- package/project/project.ts +56 -10
- package/src/frontend/async.ts +284 -195
- package/src/frontend/configuration.ts +7 -21
- package/src/frontend/const-functions.ts +44 -38
- package/src/frontend/elaborate/capture.ts +7 -0
- package/src/frontend/elaborate/index.ts +135 -61
- package/src/frontend/elaborate/layouts.ts +8 -0
- package/src/frontend/elaborate/model.ts +13 -0
- package/src/frontend/elaborate/specialize.ts +302 -111
- package/src/frontend/exposure.ts +28 -26
- package/src/frontend/positions.ts +272 -0
- package/src/frontend/promises.ts +52 -47
- package/src/frontend/services.ts +16 -26
- package/src/frontend/types.ts +14 -0
- package/src/frontend/typescript.ts +185 -65
- package/stdlib/telemetry.ts +72 -0
- package/types/telemetry.d.ts +44 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { errorName } from "../ir/errors.ts";
|
|
4
|
+
import { now } from "./clock.ts";
|
|
5
|
+
|
|
6
|
+
type Reported = Readonly<Record<string, unknown>>;
|
|
7
|
+
class Text {
|
|
8
|
+
constructor(readonly value: string) {}
|
|
9
|
+
}
|
|
10
|
+
type Value = boolean | number | bigint | string | Text;
|
|
11
|
+
type Properties = Readonly<Record<string, Value>>;
|
|
12
|
+
|
|
13
|
+
const module = fileURLToPath(import.meta.url);
|
|
14
|
+
let collector: ((record: Reported) => void) | undefined;
|
|
15
|
+
|
|
16
|
+
/** The program's call: the first stack frame outside this module, relative to the working directory. */
|
|
17
|
+
const source = () => {
|
|
18
|
+
for (const line of new Error().stack?.split("\n") ?? []) {
|
|
19
|
+
const frame = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line);
|
|
20
|
+
if (frame && frame[1] !== module)
|
|
21
|
+
return `${relative(process.cwd(), frame[1]!).replaceAll("\\", "/")}:${frame[2]}`;
|
|
22
|
+
}
|
|
23
|
+
return "";
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const report = (record: Reported, properties: Properties = {}) =>
|
|
27
|
+
collector?.({
|
|
28
|
+
...record,
|
|
29
|
+
properties: Object.fromEntries(
|
|
30
|
+
Object.entries(properties).map(([name, value]) => [
|
|
31
|
+
name,
|
|
32
|
+
value instanceof Text ? value.value : typeof value === "bigint" ? Number(value) : value,
|
|
33
|
+
]),
|
|
34
|
+
),
|
|
35
|
+
source: source(),
|
|
36
|
+
scan: 0,
|
|
37
|
+
time: now(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/** What a PLC program's `telemetry` calls do under Bun; see `types/telemetry.d.ts`. */
|
|
41
|
+
export const telemetry = {
|
|
42
|
+
capture: (event: string, properties?: Properties) => report({ kind: "event", event }, properties),
|
|
43
|
+
info: (message: string, properties?: Properties) =>
|
|
44
|
+
report({ kind: "log", level: "info", message }, properties),
|
|
45
|
+
warn: (message: string, properties?: Properties) =>
|
|
46
|
+
report({ kind: "log", level: "warn", message }, properties),
|
|
47
|
+
error: (message: string, properties?: Properties) =>
|
|
48
|
+
report({ kind: "log", level: "error", message }, properties),
|
|
49
|
+
// Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.
|
|
50
|
+
captureException: (error: unknown, properties?: Properties) => {
|
|
51
|
+
const code = typeof error === "number" ? error : 0;
|
|
52
|
+
const name =
|
|
53
|
+
typeof error === "number"
|
|
54
|
+
? errorName(error)
|
|
55
|
+
: error instanceof Error
|
|
56
|
+
? error.message
|
|
57
|
+
: String(error);
|
|
58
|
+
report({ kind: "exception", code, ...(name && { name }), handled: true }, properties);
|
|
59
|
+
},
|
|
60
|
+
text: (bytes: readonly number[], length: number) => {
|
|
61
|
+
const sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));
|
|
62
|
+
const end = sent.indexOf(0);
|
|
63
|
+
return new Text(new TextDecoder().decode(Uint8Array.from(end < 0 ? sent : sent.slice(0, end))));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const onTelemetry = (next: (record: Reported) => void) => {
|
|
68
|
+
collector = next;
|
|
69
|
+
return () => {
|
|
70
|
+
if (collector === next) collector = undefined;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BYTE } from "./index.d.ts";
|
|
2
|
+
|
|
3
|
+
declare const textBrand: unique symbol;
|
|
4
|
+
/** A byte array sent as text; made by `telemetry.text`. */
|
|
5
|
+
export interface TelemetryText {
|
|
6
|
+
readonly [textBrand]: true;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A property value: BOOL, an integer, REAL or LREAL, an enum (sent as its member's name), a
|
|
10
|
+
* STRING, or `telemetry.text`.
|
|
11
|
+
*/
|
|
12
|
+
export type TelemetryValue = boolean | number | bigint | string | TelemetryText;
|
|
13
|
+
/** At most 8 properties, written as an object literal. */
|
|
14
|
+
export type TelemetryProperties = Readonly<Record<string, TelemetryValue>>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reports what the program decides is worth knowing. Names and messages are string literals;
|
|
18
|
+
* the compiler adds the call's `file:line`, the task's scan and its PLC clock. Report changes,
|
|
19
|
+
* not every scan: each call fills a slot of a fixed ring the task sends to its server.
|
|
20
|
+
*/
|
|
21
|
+
export interface Telemetry {
|
|
22
|
+
/** An event, such as `"bin scanned"`. */
|
|
23
|
+
capture(event: string, properties?: TelemetryProperties): void;
|
|
24
|
+
info(message: string, properties?: TelemetryProperties): void;
|
|
25
|
+
warn(message: string, properties?: TelemetryProperties): void;
|
|
26
|
+
error(message: string, properties?: TelemetryProperties): void;
|
|
27
|
+
/**
|
|
28
|
+
* A failure: a `catch` binding, which holds the error code, or any code the program picks.
|
|
29
|
+
* Known job error codes are sent with their meaning.
|
|
30
|
+
*/
|
|
31
|
+
captureException(error: unknown, properties?: TelemetryProperties): void;
|
|
32
|
+
/** The first `length` bytes of `bytes`, up to the first 0, as text: a barcode in its buffer. */
|
|
33
|
+
text(bytes: readonly BYTE[], length: number): TelemetryText;
|
|
34
|
+
}
|
|
35
|
+
export declare const telemetry: Telemetry;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Where records go when the program runs under Bun, such as in its tests, until the returned
|
|
39
|
+
* function is called; each is a `TelemetryRecord` of `@tsplc/server`. Without a collector, records
|
|
40
|
+
* are dropped.
|
|
41
|
+
*/
|
|
42
|
+
export declare function onTelemetry(
|
|
43
|
+
collector: (record: Readonly<Record<string, unknown>>) => void,
|
|
44
|
+
): () => void;
|