@swf2es/cli 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 (74) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +389 -0
  3. package/README.md +32 -2
  4. package/dist/aot.d.ts +98 -0
  5. package/dist/aot.d.ts.map +1 -0
  6. package/dist/aot.js +145 -0
  7. package/dist/aot.js.map +1 -0
  8. package/dist/args.d.ts +31 -0
  9. package/dist/args.d.ts.map +1 -0
  10. package/dist/args.js +37 -0
  11. package/dist/args.js.map +1 -0
  12. package/dist/commands/compile.d.ts +3 -0
  13. package/dist/commands/compile.d.ts.map +1 -0
  14. package/dist/commands/compile.js +233 -0
  15. package/dist/commands/compile.js.map +1 -0
  16. package/dist/commands/help.d.ts +6 -0
  17. package/dist/commands/help.d.ts.map +1 -0
  18. package/dist/commands/help.js +52 -0
  19. package/dist/commands/help.js.map +1 -0
  20. package/dist/commands/run.d.ts +3 -0
  21. package/dist/commands/run.d.ts.map +1 -0
  22. package/dist/commands/run.js +122 -0
  23. package/dist/commands/run.js.map +1 -0
  24. package/dist/files.d.ts +10 -0
  25. package/dist/files.d.ts.map +1 -0
  26. package/dist/files.js +35 -0
  27. package/dist/files.js.map +1 -0
  28. package/dist/index.d.ts +5 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +5 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/main.d.ts +3 -0
  33. package/dist/main.d.ts.map +1 -0
  34. package/dist/main.js +45 -0
  35. package/dist/main.js.map +1 -0
  36. package/dist/output.d.ts +7 -0
  37. package/dist/output.d.ts.map +1 -0
  38. package/dist/output.js +20 -0
  39. package/dist/output.js.map +1 -0
  40. package/dist/shell-memories.d.ts +2 -0
  41. package/dist/shell-memories.d.ts.map +1 -0
  42. package/dist/shell-memories.js +32 -0
  43. package/dist/shell-memories.js.map +1 -0
  44. package/dist/shell-thread.d.ts +2 -0
  45. package/dist/shell-thread.d.ts.map +1 -0
  46. package/dist/shell-thread.js +49 -0
  47. package/dist/shell-thread.js.map +1 -0
  48. package/dist/shell-toplevel-library.d.ts +2 -0
  49. package/dist/shell-toplevel-library.d.ts.map +1 -0
  50. package/dist/shell-toplevel-library.js +22 -0
  51. package/dist/shell-toplevel-library.js.map +1 -0
  52. package/dist/shell.d.ts +62 -0
  53. package/dist/shell.d.ts.map +1 -0
  54. package/dist/shell.js +135 -0
  55. package/dist/shell.js.map +1 -0
  56. package/dist/threads.d.ts +85 -0
  57. package/dist/threads.d.ts.map +1 -0
  58. package/dist/threads.js +145 -0
  59. package/dist/threads.js.map +1 -0
  60. package/package.json +46 -3
  61. package/src/aot.ts +239 -0
  62. package/src/args.ts +53 -0
  63. package/src/commands/compile.ts +286 -0
  64. package/src/commands/help.ts +60 -0
  65. package/src/commands/run.ts +131 -0
  66. package/src/files.ts +38 -0
  67. package/src/index.ts +25 -0
  68. package/src/main.ts +51 -0
  69. package/src/output.ts +23 -0
  70. package/src/shell-memories.ts +35 -0
  71. package/src/shell-thread.ts +54 -0
  72. package/src/shell-toplevel-library.ts +28 -0
  73. package/src/shell.ts +211 -0
  74. package/src/threads.ts +223 -0
@@ -0,0 +1,62 @@
1
+ import { type Codegen } from "@swf2es/codegen";
2
+ import type { Abc, CompileUnit, Runtime, RuntimeOptions, ShellFiles, ShellWorkerHost, ShellWorkerInit } from "@swf2es/runtime/avm2";
3
+ /** What the shell needs of a compiler: a Codegen, or a build of it for tests. */
4
+ export type ShellCompiler = Pick<Codegen, "reset" | "add" | "childDomain" | "found" | "compileModule">;
5
+ /** A module the compiler wrote, loaded: run with a runtime, it gives the ABC. */
6
+ export type ShellModule = (rt: Runtime) => Abc;
7
+ export interface ShellLibrary {
8
+ name: string;
9
+ abc: Uint8Array;
10
+ /** Its module, compiled before for the same libraries before it: linked again but not compiled. */
11
+ module?: ShellModule;
12
+ }
13
+ export interface ShellOptions {
14
+ compiler: ShellCompiler;
15
+ /** The runtime's createRuntime, or another build's. */
16
+ createRuntime: (options: RuntimeOptions) => Runtime;
17
+ /** Where trace and print write a line. */
18
+ print: (line: string) => void;
19
+ /** Where avmshell's File reads and writes; the runtime keeps them in memory by default. */
20
+ files?: ShellFiles;
21
+ /**
22
+ * Load a module the compiler has just written, `name` naming its script
23
+ * (which Runtime.codeDomain tells domains by); by default evaluated as a
24
+ * script of its own.
25
+ */
26
+ load?: (js: string, name: string) => ShellModule | Promise<ShellModule>;
27
+ /** What starts the background workers' threads (RuntimeOptions.workers), as nodeShellThreads does. */
28
+ workers?: ShellWorkerHost;
29
+ /** The background worker these ABCs run as, in the thread its host started (RuntimeOptions.worker). */
30
+ worker?: ShellWorkerInit;
31
+ /**
32
+ * The ABCs' API version, as avmshell's -api gives it, whose series is
33
+ * the run's: Flash Player's latest, 50, by default.
34
+ */
35
+ apiVersion?: number;
36
+ }
37
+ /** A module's source as a script of its own: its default export returned, `name` its sourceURL. */
38
+ export declare function evaluateModule(js: string, name: string): ShellModule;
39
+ /**
40
+ * The compiler for one runtime: the libraries and ABCs added to the root
41
+ * domain, and RuntimeOptions.compileAbc for those Domain.loadBytes loads.
42
+ */
43
+ export declare function shellDomain(compiler: ShellCompiler, apiVersion?: number): {
44
+ /** Add an ABC to the root domain, as avmshell loads its libraries and the ABCs it runs. */
45
+ add: (bytes: Uint8Array, builtin: boolean) => number;
46
+ /** The module of the ABC added last. */
47
+ compile: () => string;
48
+ /** RuntimeOptions.compileAbc: `bytes` compiled into the unit's domain, evaluated at once. */
49
+ compileAbc(bytes: Uint8Array, unit: CompileUnit): ShellModule | number;
50
+ };
51
+ /**
52
+ * Run `abcs` after `libraries` as avmshell runs them, printing what they
53
+ * trace: avmshell's exit status, 0, or 1 once an ABC is rejected, with
54
+ * its VerifyError, or throws an exception nothing catches, printed as its
55
+ * string; the ABCs after it do not run. A library's rejection throws a
56
+ * RejectedError, and an error of the host's, a JavaScript Error, is thrown.
57
+ */
58
+ export declare function runShell(libraries: ShellLibrary[], abcs: {
59
+ name: string;
60
+ abc: Uint8Array;
61
+ }[], options: ShellOptions): Promise<number>;
62
+ //# sourceMappingURL=shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAQA,OAAO,EAAe,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EACV,GAAG,EACH,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,eAAe,EACf,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAI9B,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,OAAO,EACP,OAAO,GAAG,KAAK,GAAG,aAAa,GAAG,OAAO,GAAG,eAAe,CAC5D,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,GAAG,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC;IAChB,mGAAmG;IACnG,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,aAAa,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC;IACpD,0CAA0C;IAC1C,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,2FAA2F;IAC3F,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxE,sGAAsG;IACtG,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,uGAAuG;IACvG,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAKpE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,UAAU,SAAc;IA0BzE,2FAA2F;IAC3F,GAAG,UAAU,UAAU,WAAW,OAAO,KAAG,MAAM;IAClD,wCAAwC;IACxC,OAAO,QAAM,MAAM;IACnB,6FAA6F;IAC7F,UAAU,QAAQ,UAAU,QAAQ,WAAW,GAAG,WAAW,GAAG,MAAM;EAgCzE;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,YAAY,EAAE,EACzB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,EAAE,EACzC,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,MAAM,CAAC,CAyDjB"}
package/dist/shell.js ADDED
@@ -0,0 +1,135 @@
1
+ // avmshell's way of running ABCs, in node: the libraries it loads (builtin
2
+ // and shell_toplevel), their scripts run on first use, then each ABC given,
3
+ // added to the same domain and its entry point run, until one throws. One
4
+ // compiler domain serves the one runtime, each ABC compiled in the
5
+ // application domain the runtime loads it into, so that an ABC
6
+ // Domain.loadBytes loads compiles against what its domain sees, a
7
+ // sibling's ABCs left out.
8
+ import { createHash } from "node:crypto";
9
+ import { API_VERSION } from "@swf2es/codegen";
10
+ import { floatLibrary, hasFloatLibrary } from "@swf2es/runtime/avm2";
11
+ import { RejectedError } from "./aot.js";
12
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
13
+ /** A module's source as a script of its own: its default export returned, `name` its sourceURL. */
14
+ export function evaluateModule(js, name) {
15
+ // Strict, as a module is: a sloppy function boxes a primitive `this`, such
16
+ // as the string a String method is called on.
17
+ const script = `"use strict";${js.replace(/^export default /, "return ")}//# sourceURL=${name}\n`;
18
+ return new Function(script)();
19
+ }
20
+ /**
21
+ * The compiler for one runtime: the libraries and ABCs added to the root
22
+ * domain, and RuntimeOptions.compileAbc for those Domain.loadBytes loads.
23
+ */
24
+ export function shellDomain(compiler, apiVersion = API_VERSION) {
25
+ // The compiler's number for each of the runtime's domains, and the
26
+ // compiler's index of each ABC loaded into one, in load order.
27
+ const domains = new Map([[0, 0]]);
28
+ const abcs = new Map([[0, []]]);
29
+ // The findings each domain has been told, reported once.
30
+ const reported = new Map();
31
+ // Every ABC's hash, in load order, as the compiler names a module's.
32
+ const hashes = [];
33
+ let added = 0;
34
+ let evaluated = 0;
35
+ compiler.reset(apiVersion);
36
+ /** Add an ABC to the runtime's domain `domain`: 0, or the VerifyError it was rejected with. */
37
+ const add = (bytes, builtin, domain = 0) => {
38
+ const error = compiler.add(bytes, builtin, domains.get(domain));
39
+ if (!error) {
40
+ abcs.get(domain)?.push(added++);
41
+ hashes.push(sha256(bytes));
42
+ }
43
+ return error;
44
+ };
45
+ return {
46
+ /** Add an ABC to the root domain, as avmshell loads its libraries and the ABCs it runs. */
47
+ add: (bytes, builtin) => add(bytes, builtin),
48
+ /** The module of the ABC added last. */
49
+ compile: () => compiler.compileModule(hashes),
50
+ /** RuntimeOptions.compileAbc: `bytes` compiled into the unit's domain, evaluated at once. */
51
+ compileAbc(bytes, unit) {
52
+ for (let i = unit.domains.length - 2; i >= 0; i--) {
53
+ const id = unit.domains[i];
54
+ if (!domains.has(id)) {
55
+ domains.set(id, compiler.childDomain(domains.get(unit.domains[i + 1]) ?? 0));
56
+ abcs.set(id, []);
57
+ }
58
+ }
59
+ const domain = unit.domains[0];
60
+ const at = domains.get(domain) ?? 0;
61
+ const told = reported.get(domain) ?? new Set();
62
+ reported.set(domain, told);
63
+ for (const f of unit.found) {
64
+ const key = JSON.stringify([f.asType, f.nsKind, f.uri, f.name, f.domain, f.index]);
65
+ const abc = abcs.get(f.domain)?.[f.index];
66
+ if (abc !== undefined && !told.has(key)) {
67
+ told.add(key);
68
+ const { nsKind, uri, name, asType } = f;
69
+ compiler.found({ domain: at, nsKind, uri, name, abc, asType });
70
+ }
71
+ }
72
+ const error = add(bytes, false, domain);
73
+ if (error) {
74
+ return error;
75
+ }
76
+ // A script of its own, by which Runtime.codeDomain finds its frames.
77
+ return evaluateModule(compiler.compileModule(hashes), `loaded-${evaluated++}.js`);
78
+ },
79
+ };
80
+ }
81
+ /**
82
+ * Run `abcs` after `libraries` as avmshell runs them, printing what they
83
+ * trace: avmshell's exit status, 0, or 1 once an ABC is rejected, with
84
+ * its VerifyError, or throws an exception nothing catches, printed as its
85
+ * string; the ABCs after it do not run. A library's rejection throws a
86
+ * RejectedError, and an error of the host's, a JavaScript Error, is thrown.
87
+ */
88
+ export async function runShell(libraries, abcs, options) {
89
+ if (abcs.some(({ abc }) => abc.length >= 4 && abc[2] === 47 && abc[3] === 0 && (abc[0] | (abc[1] << 8)) >= 16) &&
90
+ !hasFloatLibrary(libraries.map((lib) => lib.abc))) {
91
+ libraries = [...libraries, { name: "float", abc: floatLibrary }];
92
+ }
93
+ const { print } = options;
94
+ const load = options.load ?? evaluateModule;
95
+ const apiVersion = options.apiVersion ?? API_VERSION;
96
+ const domain = shellDomain(options.compiler, apiVersion);
97
+ const rt = options.createRuntime({
98
+ print,
99
+ apiVersion,
100
+ // Domain.loadBytes runs the ABC at once, so its module is evaluated, not imported.
101
+ compileAbc: (bytes, unit) => domain.compileAbc(bytes, unit),
102
+ ...(options.files ? { files: options.files } : {}),
103
+ ...(options.workers ? { workers: options.workers } : {}),
104
+ ...(options.worker ? { worker: options.worker } : {}),
105
+ });
106
+ for (const { name, abc, module } of libraries) {
107
+ const error = domain.add(abc, true);
108
+ if (error) {
109
+ throw new RejectedError(`library ${name}`, error, true);
110
+ }
111
+ // The libraries' scripts run on first use, as avmshell's builtins do.
112
+ (module ?? (await load(domain.compile(), `${name}.js`)))(rt);
113
+ }
114
+ for (const { name, abc } of abcs) {
115
+ const error = domain.add(abc, false);
116
+ if (error) {
117
+ print(`VerifyError: Error #${error}`);
118
+ return 1;
119
+ }
120
+ const loaded = (await load(domain.compile(), `${name}.js`))(rt);
121
+ try {
122
+ rt.run(loaded);
123
+ }
124
+ catch (e) {
125
+ // An AS3 exception nothing caught: avmshell prints it, as its string, and exits with 1.
126
+ if (e instanceof Error) {
127
+ throw e;
128
+ }
129
+ print(rt.toString(e));
130
+ return 1;
131
+ }
132
+ }
133
+ return 0;
134
+ }
135
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,mEAAmE;AACnE,+DAA+D;AAC/D,kEAAkE;AAClE,2BAA2B;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAgB,MAAM,iBAAiB,CAAC;AAW5D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA2CzC,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEvF,mGAAmG;AACnG,MAAM,UAAU,cAAc,CAAC,EAAU,EAAE,IAAY;IACrD,2EAA2E;IAC3E,8CAA8C;IAC9C,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,iBAAiB,IAAI,IAAI,CAAC;IAClG,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAuB,EAAE,UAAU,GAAG,WAAW;IAC3E,mEAAmE;IAC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AG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;YACtC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC;YACH,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,wFAAwF;YACxF,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,CAAC,CAAC;YACV,CAAC;YAED,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAU,CAAC,CAAC,CAAC;YAC/B,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { SharedBytesMemory, ShellWorkerHost, ShellWorkerInit } from "@swf2es/runtime/avm2";
2
+ export interface ShellThreadsOptions {
3
+ /** codegen.wasm, compiled: each thread instantiates it. */
4
+ codegen: WebAssembly.Module;
5
+ /** The libraries the primordial loaded, which each thread loads first. */
6
+ libraries: {
7
+ name: string;
8
+ abc: Uint8Array;
9
+ }[];
10
+ /** The primordial's ABCs, which createWorkerFromPrimordial runs. */
11
+ abcs: {
12
+ name: string;
13
+ abc: Uint8Array;
14
+ }[];
15
+ /**
16
+ * Where a thread's lines go, on this thread, once its event loop takes
17
+ * them; by default each thread writes its own to stdout as it prints
18
+ * them, as avmshell's threads do.
19
+ */
20
+ print?: (line: string) => void;
21
+ /** The primordial's threads' channel for shared memory, a background thread's parent's; by default a new one. */
22
+ group?: string;
23
+ /** The shared memory its parent had seen when the thread started. */
24
+ memories?: SharedBytesMemory[];
25
+ /** The API version the primordial's ABCs run at, which its workers' run at too (ShellOptions.apiVersion). */
26
+ apiVersion?: number;
27
+ }
28
+ /** What a thread is given, as workerData. */
29
+ export interface ShellThreadData {
30
+ codegen: WebAssembly.Module;
31
+ libraries: {
32
+ name: string;
33
+ abc: Uint8Array;
34
+ }[];
35
+ abcs: {
36
+ name: string;
37
+ abc: Uint8Array;
38
+ }[];
39
+ init: ShellWorkerInit;
40
+ /** Whether its lines are posted to the thread that started it, rather than written to stdout. */
41
+ post: boolean;
42
+ group: string;
43
+ memories: SharedBytesMemory[];
44
+ apiVersion?: number;
45
+ }
46
+ /** What the memory thread is given, as workerData. */
47
+ export interface MemoriesData {
48
+ group: string;
49
+ /** What the primordial shared before it started. */
50
+ memories: SharedBytesMemory[];
51
+ /** Set once it has subscribed to the group's channel. */
52
+ ready: Int32Array;
53
+ }
54
+ /** What the group's channel carries: a memory shared, and a question for the memory thread and its answer. */
55
+ export type MemoryMessage = {
56
+ type: "memory";
57
+ memory: SharedBytesMemory;
58
+ } | {
59
+ type: "ask";
60
+ id: number;
61
+ answered: Int32Array;
62
+ } | {
63
+ type: "answer";
64
+ id: number;
65
+ memory: SharedBytesMemory | null;
66
+ };
67
+ export interface ShellThreads {
68
+ host: ShellWorkerHost;
69
+ /** The primordial's threads' channel for shared memory, which a thread it starts is given. */
70
+ group: string;
71
+ /**
72
+ * Stop every thread still running, as avmshell interrupts its workers
73
+ * when the primordial ends, once what they printed so far has come.
74
+ */
75
+ close(): Promise<void>;
76
+ /**
77
+ * Wait for every thread to end by itself, those started meanwhile too:
78
+ * a worker whose code has ended leaves the workers it started running,
79
+ * as avmshell does, and its thread, which theirs belong to, waits for them.
80
+ */
81
+ ended(): Promise<void>;
82
+ }
83
+ /** Threads for the background workers of a primordial that runs `options.abcs`. */
84
+ export declare function nodeShellThreads(options: ShellThreadsOptions): ShellThreads;
85
+ //# sourceMappingURL=threads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../src/threads.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,iBAAiB,EAEjB,eAAe,EACf,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;IAC5B,0EAA0E;IAC1E,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;IAC/C,oEAAoE;IACpE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;IAC1C;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,iHAAiH;IACjH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B,6GAA6G;IAC7G,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;IAC5B,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;IAC/C,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;IAC1C,IAAI,EAAE,eAAe,CAAC;IACtB,iGAAiG;IACjG,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,yDAAyD;IACzD,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,8GAA8G;AAC9G,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE,CAAC;AAKrE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,eAAe,CAAC;IACtB,8FAA8F;IAC9F,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAgI3E"}
@@ -0,0 +1,145 @@
1
+ // avmshell's background workers on node's threads: each a worker_threads
2
+ // Worker running shell-thread.js, which compiles and runs its worker's
3
+ // ABCs after the same libraries, as runShell runs the primordial's.
4
+ //
5
+ // A shareable ByteArray's memory reaches the other threads on a
6
+ // BroadcastChannel of the primordial's threads, read synchronously
7
+ // (receiveMessageOnPort) when a shared property names memory a thread has
8
+ // not seen: its code never returns to the event loop to take messages.
9
+ // A thread started later is given what its parent has seen. A channel
10
+ // holds only what was posted once it was made, so a thread that was still
11
+ // starting when a memory was shared asks for it the primordial's memory
12
+ // thread (shell-memories.ts), which subscribed before any other thread
13
+ // started, and waits for its answer.
14
+ import { randomUUID } from "node:crypto";
15
+ import { writeSync } from "node:fs";
16
+ import { receiveMessageOnPort, Worker } from "node:worker_threads";
17
+ /** How long a thread waits for the memory thread's answer. */
18
+ const ANSWER_MS = 10_000;
19
+ /** Threads for the background workers of a primordial that runs `options.abcs`. */
20
+ export function nodeShellThreads(options) {
21
+ // Each thread running, with its exit.
22
+ const running = new Map();
23
+ // Only what a thread can be posted: a library's loaded module is not.
24
+ const libraries = options.libraries.map(({ name, abc }) => ({ name, abc }));
25
+ const abcs = options.abcs.map(({ name, abc }) => ({ name, abc }));
26
+ const group = options.group ?? `swf2es-shell-${randomUUID()}`;
27
+ const channel = new BroadcastChannel(group);
28
+ // Only read synchronously: it keeps no thread alive.
29
+ channel.unref();
30
+ const memories = new Map();
31
+ for (const memory of options.memories ?? []) {
32
+ memories.set(memory.id, memory);
33
+ }
34
+ // What the other threads shared since, and the memory thread's answers.
35
+ const receive = () => {
36
+ for (;;) {
37
+ const m = receiveMessageOnPort(channel);
38
+ if (!m) {
39
+ break;
40
+ }
41
+ const message = m.message;
42
+ if (message.type === "memory" || (message.type === "answer" && message.memory)) {
43
+ const memory = message.memory;
44
+ memories.set(memory.id, memory);
45
+ }
46
+ }
47
+ };
48
+ // The primordial's memory thread, started, and subscribed, before any
49
+ // other thread, or when the primordial first shares a memory.
50
+ let keeper = null;
51
+ const keep = () => {
52
+ if (keeper || options.group) {
53
+ return;
54
+ }
55
+ const ready = new Int32Array(new SharedArrayBuffer(4));
56
+ const data = { group, memories: [...memories.values()], ready };
57
+ keeper = new Worker(new URL("./shell-memories.js", import.meta.url), { workerData: data });
58
+ keeper.unref();
59
+ Atomics.wait(ready, 0, 0, ANSWER_MS);
60
+ };
61
+ const host = {
62
+ start(init) {
63
+ keep();
64
+ receive();
65
+ const data = {
66
+ codegen: options.codegen,
67
+ libraries,
68
+ abcs,
69
+ init,
70
+ post: options.print !== undefined,
71
+ group,
72
+ memories: [...memories.values()],
73
+ apiVersion: options.apiVersion,
74
+ };
75
+ const worker = new Worker(new URL("./shell-thread.js", import.meta.url), {
76
+ workerData: data,
77
+ stdout: false,
78
+ stderr: false,
79
+ });
80
+ running.set(worker, new Promise((resolve) => worker.once("exit", resolve)));
81
+ worker.on("message", (line) => {
82
+ if (options.print) {
83
+ options.print(line);
84
+ }
85
+ else {
86
+ writeSync(1, `${line}\n`);
87
+ }
88
+ });
89
+ worker.on("error", (e) => {
90
+ const line = `swf2es: a background worker failed: ${e.stack ?? e}`;
91
+ if (options.print) {
92
+ options.print(line);
93
+ }
94
+ else {
95
+ writeSync(2, `${line}\n`);
96
+ }
97
+ });
98
+ worker.on("exit", () => running.delete(worker));
99
+ return {
100
+ terminate() {
101
+ running.delete(worker);
102
+ return worker.terminate();
103
+ },
104
+ };
105
+ },
106
+ share(memory) {
107
+ keep();
108
+ if (!memories.has(memory.id)) {
109
+ memories.set(memory.id, memory);
110
+ channel.postMessage({ type: "memory", memory });
111
+ }
112
+ },
113
+ shared(id) {
114
+ if (!memories.has(id)) {
115
+ receive();
116
+ }
117
+ // Shared while this thread was starting: the memory thread has it.
118
+ if (!memories.has(id) && options.group) {
119
+ const answered = new Int32Array(new SharedArrayBuffer(4));
120
+ channel.postMessage({ type: "ask", id, answered });
121
+ Atomics.wait(answered, 0, 0, ANSWER_MS);
122
+ receive();
123
+ }
124
+ return memories.get(id);
125
+ },
126
+ };
127
+ return {
128
+ host,
129
+ group,
130
+ async close() {
131
+ await new Promise((resolve) => setImmediate(resolve));
132
+ await Promise.all([...running.keys()].map((w) => w.terminate()));
133
+ running.clear();
134
+ await keeper?.terminate();
135
+ channel.close();
136
+ memories.clear();
137
+ },
138
+ async ended() {
139
+ while (running.size) {
140
+ await Promise.all(running.values());
141
+ }
142
+ },
143
+ };
144
+ }
145
+ //# sourceMappingURL=threads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threads.js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,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;gBACxC,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;KACF,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,KAAK;QACL,KAAK,CAAC,KAAK;YACT,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YACtD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YACjE,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,MAAM,EAAE,SAAS,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QACD,KAAK,CAAC,KAAK;YACT,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;gBACpB,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@swf2es/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "swf2es command line: ahead-of-time compile SWF and ABC files, and run ABCs as avmshell does",
5
+ "keywords": [
6
+ "swf",
7
+ "flash",
8
+ "actionscript",
9
+ "as3",
10
+ "abc",
11
+ "avmshell",
12
+ "compiler",
13
+ "aot",
14
+ "cli"
15
+ ],
16
+ "homepage": "https://swf2es.github.io/swf2es/",
17
+ "bugs": "https://github.com/swf2es/swf2es/issues",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/swf2es/swf2es.git",
21
+ "directory": "packages/cli"
22
+ },
23
+ "license": "Apache-2.0 AND MPL-2.0",
24
+ "type": "module",
25
+ "engines": {
26
+ "node": ">=22.18"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "bin": {
35
+ "swf2es": "./dist/main.js"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "!dist/**/.tsbuildinfo",
40
+ "src",
41
+ "LICENSE.third-party"
42
+ ],
43
+ "dependencies": {
44
+ "@swf2es/format": "0.1.0",
45
+ "@swf2es/player": "0.1.0",
46
+ "@swf2es/runtime": "0.1.0",
47
+ "@swf2es/codegen": "0.1.0"
48
+ }
6
49
  }