@bgforge/mls-server 3.13.2 → 3.15.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.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Runs the WebAssembly SSL compiler in the directory it was actually started in.
3
+ *
4
+ * The compiler package ships its own command-line wrapper, which derives the directory to compile in as
5
+ * `join(parse(cwd).dir, parse(cwd).name)`. That reads whatever follows the last dot of the final segment as
6
+ * a file extension and drops it, so a mod directory named for its version - `mymod.v2` - becomes `mymod`,
7
+ * the compiler changes into a directory that does not exist, and the run dies with a bare
8
+ * `ErrnoError undefined undefined` naming neither the cause nor the path. The working directory cannot
9
+ * simply be moved somewhere without a dot: the compiler resolves `#include` against it.
10
+ *
11
+ * So this stands in for that wrapper, differing only in changing into the working directory as given. It
12
+ * is forked rather than imported: a compile is a fresh process, which is what keeps a compiler crash away
13
+ * from the language server. Output is collected and written once at the end rather than streamed, so what
14
+ * the parent parses is shaped exactly as the package's own wrapper shaped it.
15
+ *
16
+ * Not a TypeScript file, unlike the rest of this directory: it is executed as-is rather than bundled, and
17
+ * the module it loads is an Emscripten build that ships no types. The build copies it beside the server
18
+ * bundle, where the same relative path from ssl_compiler.ts resolves as it does here in the source tree.
19
+ */
20
+
21
+ // Named lowercase because it is a factory, not a constructor: the Emscripten build exports it
22
+ // capitalised, and calling it that way reads as a missing `new`.
23
+ import createCompiler from "sslc-emscripten-noderawfs";
24
+
25
+ const stdout = [];
26
+ const stderr = [];
27
+
28
+ let returnCode;
29
+ try {
30
+ const instance = await createCompiler({
31
+ print: (text) => stdout.push(text),
32
+ printErr: (text) => stderr.push(text),
33
+ noInitialRun: true,
34
+ });
35
+
36
+ // The whole point of this file. `process.cwd()` is where the parent asked for the compile to happen.
37
+ instance.FS.chdir(process.cwd());
38
+ returnCode = instance.callMain(process.argv.slice(2));
39
+ instance.FS.chdir("/");
40
+ } catch (error) {
41
+ returnCode = 1;
42
+ stderr.push(`ERROR: ${error.name} ${error.message} ${error.stack}`);
43
+ }
44
+
45
+ console.log(stdout.join("\n"));
46
+ if (stderr.length > 0) console.error(stderr.join("\n"));
47
+ process.exit(returnCode);
@@ -28,6 +28,22 @@ interface Action {
28
28
 
29
29
  // --- IElib sync surface end ---
30
30
 
31
+ /**
32
+ * A dialogue state: a nullary function whose `say`/`reply`/`goTo` calls describe one state.
33
+ *
34
+ * Deliberately a call signature and not a brand, unlike `StrRef` and `Action` above. Those name values
35
+ * the runtime itself produces, so a brand costs their callers nothing; a state is written by the author
36
+ * with the `function` keyword (`function greeting() { ... }; begin("DLG", [greeting])`), and a branded
37
+ * type would reject every one of them.
38
+ *
39
+ * What this buys over `Function`, exactly: a function REQUIRING arguments is now rejected at the call
40
+ * site (`begin("DLG", [f])` where `f(a: string)` - "Target signature provides too few arguments").
41
+ * It is not airtight - anything callable with zero arguments still passes, `Math.max` included, since a
42
+ * rest parameter satisfies a nullary signature and every return type is assignable to `void`. Tightening
43
+ * further would need a brand, which the paragraph above rules out.
44
+ */
45
+ type StateFn = () => void;
46
+
31
47
  // ---------------------------------------------------------------------------
32
48
  // State-level functions (called inside state functions)
33
49
  // ---------------------------------------------------------------------------
@@ -69,7 +85,7 @@ interface TransitionBuilder<Self> {
69
85
  /** Set transition feature flags directly using the binary DLG format. */
70
86
  flags(n: number): Self;
71
87
  /** Continue dialogue at the given state label in the same DLG file. */
72
- goTo(target: string | number | Function): void;
88
+ goTo(target: string | number | StateFn): void;
73
89
  /** End the conversation. */
74
90
  exit(): void;
75
91
  /** Continue dialogue at the given state in another DLG file. */
@@ -100,7 +116,7 @@ declare function reply(text: StrRef): AfterReply;
100
116
  declare function action(...actions: Action[]): AfterAction;
101
117
 
102
118
  /** Continue dialogue at the given state label in the same DLG file. Synonym for GOTO. */
103
- declare function goTo(target: string | number | Function): void;
119
+ declare function goTo(target: string | number | StateFn): void;
104
120
 
105
121
  /** End the conversation. */
106
122
  declare function exit(): void;
@@ -139,26 +155,26 @@ declare function unsolvedJournal(text: StrRef): void;
139
155
  * Use inside begin(), append(), appendEarly() argument lists.
140
156
  * @example begin("DLG", [state("greeting", () => { say(tra(1)); exit(); })]);
141
157
  */
142
- declare function state(label: string, body: () => void): Function;
158
+ declare function state(label: string, body: StateFn): StateFn;
143
159
 
144
160
  /**
145
161
  * Create a new DLG file from scratch. Any existing DLG file with the same name
146
162
  * will be overwritten. The new DLG file contains exactly the states in the list.
147
163
  */
148
- declare function begin(dialog: string, states: (Function | string)[]): void;
149
- declare function begin(dialog: string, ...states: Function[]): void;
164
+ declare function begin(dialog: string, states: (StateFn | string)[]): void;
165
+ declare function begin(dialog: string, ...states: StateFn[]): void;
150
166
 
151
167
  /**
152
168
  * Add states to the end of an already-existing dialogue file.
153
169
  */
154
- declare function append(dialog: string, states: Function[]): void;
155
- declare function append(dialog: string, ...states: Function[]): void;
170
+ declare function append(dialog: string, states: StateFn[]): void;
171
+ declare function append(dialog: string, ...states: StateFn[]): void;
156
172
 
157
173
  /**
158
174
  * Like `append`, but the states are added early in the compilation timeline
159
175
  * (just after BEGIN is processed). They can be targets for INTERJECT_COPY_TRANS.
160
176
  */
161
- declare function appendEarly(dialog: string, ...states: Function[]): void;
177
+ declare function appendEarly(dialog: string, ...states: StateFn[]): void;
162
178
 
163
179
  /**
164
180
  * Load the given dialog and replace the state at the given numeric index
@@ -169,15 +185,15 @@ declare function replaceState(dialog: string, state: number, body: () => void):
169
185
  /**
170
186
  * Add transitions to the top of the transition list for the specified state.
171
187
  */
172
- declare function extendTop(dialog: string, state: string | number | Function, callback: () => void): void;
188
+ declare function extendTop(dialog: string, state: string | number | StateFn, callback: () => void): void;
173
189
 
174
190
  /**
175
191
  * Add transitions to the bottom of the transition list for the specified state.
176
192
  */
177
- declare function extendBottom(dialog: string, state: string | number | Function, callback: () => void): void;
193
+ declare function extendBottom(dialog: string, state: string | number | StateFn, callback: () => void): void;
178
194
  declare function extendBottom(
179
195
  dialog: string,
180
- state: string | number | Function,
196
+ state: string | number | StateFn,
181
197
  options: { position?: number },
182
198
  callback: () => void,
183
199
  ): void;
@@ -191,8 +207,8 @@ declare function extendBottom(
191
207
  * Useful when NPCs talk among themselves. CHAIN only appends to existing
192
208
  * dialogues; it cannot create a new DLG.
193
209
  */
194
- declare function chain(callback: Function): void;
195
- declare function chain(entryTrigger: boolean, callback: Function): void;
210
+ declare function chain(callback: () => void): void;
211
+ declare function chain(entryTrigger: boolean, callback: () => void): void;
196
212
  declare function chain(dialog: string, label: string, body: () => void): void;
197
213
  declare function chain(entryTrigger: boolean, dialog: string, label: string, body: () => void): void;
198
214
 
@@ -215,7 +231,7 @@ declare function interject(
215
231
  entryDialog: string,
216
232
  entryState: string,
217
233
  globalVar: string,
218
- callback: Function,
234
+ callback: () => void,
219
235
  exitDialog?: string,
220
236
  exitState?: string,
221
237
  ): void;
@@ -229,7 +245,7 @@ declare function interjectCopyTrans(
229
245
  entryDialog: string,
230
246
  entryState: string,
231
247
  globalVar: string,
232
- callback: Function,
248
+ callback: () => void,
233
249
  exitDialog?: string,
234
250
  exitState?: string,
235
251
  ): void;
@@ -242,7 +258,7 @@ declare function interjectCopyTrans2(
242
258
  entryDialog: string,
243
259
  entryState: string,
244
260
  globalVar: string,
245
- callback: Function,
261
+ callback: () => void,
246
262
  ): void;
247
263
 
248
264
  /**
@@ -253,7 +269,7 @@ declare function interjectCopyTrans3(
253
269
  entryDialog: string,
254
270
  entryState: string,
255
271
  globalVar: string,
256
- callback: Function,
272
+ callback: () => void,
257
273
  ): void;
258
274
 
259
275
  /**
@@ -264,7 +280,7 @@ declare function interjectCopyTrans4(
264
280
  entryDialog: string,
265
281
  entryState: string,
266
282
  globalVar: string,
267
- callback: Function,
283
+ callback: () => void,
268
284
  ): void;
269
285
 
270
286
  // ---------------------------------------------------------------------------
@@ -311,7 +327,7 @@ declare function addTransAction(dialog: string, states: (string | number)[], tra
311
327
  */
312
328
  declare function replaceTransTrigger(
313
329
  dialog: string,
314
- states: (string | number | Function)[],
330
+ states: (string | number | StateFn)[],
315
331
  trans: number[],
316
332
  from: string,
317
333
  to: string,
@@ -323,7 +339,7 @@ declare function replaceTransTrigger(
323
339
  */
324
340
  declare function replaceTransAction(
325
341
  dialog: string,
326
- states: (string | number | Function)[],
342
+ states: (string | number | StateFn)[],
327
343
  trans: number[],
328
344
  from: string,
329
345
  to: string,
Binary file
Binary file
Binary file