@arborium/php 0.3.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.
- package/grammar.core.wasm +0 -0
- package/grammar.d.ts +63 -0
- package/grammar.js +2953 -0
- package/interfaces/arborium-grammar-plugin.d.ts +15 -0
- package/interfaces/arborium-grammar-types.d.ts +30 -0
- package/interfaces/wasi-cli-environment.d.ts +2 -0
- package/interfaces/wasi-cli-exit.d.ts +3 -0
- package/interfaces/wasi-cli-stderr.d.ts +3 -0
- package/interfaces/wasi-cli-stdin.d.ts +3 -0
- package/interfaces/wasi-cli-stdout.d.ts +3 -0
- package/interfaces/wasi-clocks-wall-clock.d.ts +5 -0
- package/interfaces/wasi-filesystem-preopens.d.ts +3 -0
- package/interfaces/wasi-filesystem-types.d.ts +124 -0
- package/interfaces/wasi-io-error.d.ts +8 -0
- package/interfaces/wasi-io-streams.d.ts +28 -0
- package/interfaces/wasi-random-random.d.ts +2 -0
- package/package.json +43 -0
package/grammar.js
ADDED
|
@@ -0,0 +1,2953 @@
|
|
|
1
|
+
export function instantiate(getCoreModule, imports, instantiateCore = WebAssembly.instantiate) {
|
|
2
|
+
|
|
3
|
+
let dv = new DataView(new ArrayBuffer());
|
|
4
|
+
const dataView = mem => dv.buffer === mem.buffer ? dv : dv = new DataView(mem.buffer);
|
|
5
|
+
|
|
6
|
+
const toUint64 = val => BigInt.asUintN(64, BigInt(val));
|
|
7
|
+
|
|
8
|
+
function toUint32(val) {
|
|
9
|
+
return val >>> 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const utf8Decoder = new TextDecoder();
|
|
13
|
+
|
|
14
|
+
const utf8Encoder = new TextEncoder();
|
|
15
|
+
let utf8EncodedLen = 0;
|
|
16
|
+
function utf8Encode(s, realloc, memory) {
|
|
17
|
+
if (typeof s !== 'string') throw new TypeError('expected a string');
|
|
18
|
+
if (s.length === 0) {
|
|
19
|
+
utf8EncodedLen = 0;
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
let buf = utf8Encoder.encode(s);
|
|
23
|
+
let ptr = realloc(0, 0, 1, buf.length);
|
|
24
|
+
new Uint8Array(memory.buffer).set(buf, ptr);
|
|
25
|
+
utf8EncodedLen = buf.length;
|
|
26
|
+
return ptr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const T_FLAG = 1 << 30;
|
|
30
|
+
|
|
31
|
+
function rscTableCreateOwn (table, rep) {
|
|
32
|
+
const free = table[0] & ~T_FLAG;
|
|
33
|
+
if (free === 0) {
|
|
34
|
+
table.push(0);
|
|
35
|
+
table.push(rep | T_FLAG);
|
|
36
|
+
return (table.length >> 1) - 1;
|
|
37
|
+
}
|
|
38
|
+
table[0] = table[free << 1];
|
|
39
|
+
table[free << 1] = 0;
|
|
40
|
+
table[(free << 1) + 1] = rep | T_FLAG;
|
|
41
|
+
return free;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function rscTableRemove (table, handle) {
|
|
45
|
+
const scope = table[handle << 1];
|
|
46
|
+
const val = table[(handle << 1) + 1];
|
|
47
|
+
const own = (val & T_FLAG) !== 0;
|
|
48
|
+
const rep = val & ~T_FLAG;
|
|
49
|
+
if (val === 0 || (scope & T_FLAG) !== 0) throw new TypeError('Invalid handle');
|
|
50
|
+
table[handle << 1] = table[0] | T_FLAG;
|
|
51
|
+
table[0] = handle | T_FLAG;
|
|
52
|
+
return { rep, scope, own };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let curResourceBorrows = [];
|
|
56
|
+
|
|
57
|
+
let NEXT_TASK_ID = 0n;
|
|
58
|
+
function startCurrentTask(componentIdx, isAsync, entryFnName) {
|
|
59
|
+
_debugLog('[startCurrentTask()] args', { componentIdx, isAsync });
|
|
60
|
+
if (componentIdx === undefined || componentIdx === null) {
|
|
61
|
+
throw new Error('missing/invalid component instance index while starting task');
|
|
62
|
+
}
|
|
63
|
+
const tasks = ASYNC_TASKS_BY_COMPONENT_IDX.get(componentIdx);
|
|
64
|
+
|
|
65
|
+
const nextId = ++NEXT_TASK_ID;
|
|
66
|
+
const newTask = new AsyncTask({ id: nextId, componentIdx, isAsync, entryFnName });
|
|
67
|
+
const newTaskMeta = { id: nextId, componentIdx, task: newTask };
|
|
68
|
+
|
|
69
|
+
ASYNC_CURRENT_TASK_IDS.push(nextId);
|
|
70
|
+
ASYNC_CURRENT_COMPONENT_IDXS.push(componentIdx);
|
|
71
|
+
|
|
72
|
+
if (!tasks) {
|
|
73
|
+
ASYNC_TASKS_BY_COMPONENT_IDX.set(componentIdx, [newTaskMeta]);
|
|
74
|
+
return nextId;
|
|
75
|
+
} else {
|
|
76
|
+
tasks.push(newTaskMeta);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return nextId;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function endCurrentTask(componentIdx, taskId) {
|
|
83
|
+
_debugLog('[endCurrentTask()] args', { componentIdx });
|
|
84
|
+
componentIdx ??= ASYNC_CURRENT_COMPONENT_IDXS.at(-1);
|
|
85
|
+
taskId ??= ASYNC_CURRENT_TASK_IDS.at(-1);
|
|
86
|
+
if (componentIdx === undefined || componentIdx === null) {
|
|
87
|
+
throw new Error('missing/invalid component instance index while ending current task');
|
|
88
|
+
}
|
|
89
|
+
const tasks = ASYNC_TASKS_BY_COMPONENT_IDX.get(componentIdx);
|
|
90
|
+
if (!tasks || !Array.isArray(tasks)) {
|
|
91
|
+
throw new Error('missing/invalid tasks for component instance while ending task');
|
|
92
|
+
}
|
|
93
|
+
if (tasks.length == 0) {
|
|
94
|
+
throw new Error('no current task(s) for component instance while ending task');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (taskId) {
|
|
98
|
+
const last = tasks[tasks.length - 1];
|
|
99
|
+
if (last.id !== taskId) {
|
|
100
|
+
throw new Error('current task does not match expected task ID');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
ASYNC_CURRENT_TASK_IDS.pop();
|
|
105
|
+
ASYNC_CURRENT_COMPONENT_IDXS.pop();
|
|
106
|
+
|
|
107
|
+
return tasks.pop();
|
|
108
|
+
}
|
|
109
|
+
const ASYNC_TASKS_BY_COMPONENT_IDX = new Map();
|
|
110
|
+
const ASYNC_CURRENT_TASK_IDS = [];
|
|
111
|
+
const ASYNC_CURRENT_COMPONENT_IDXS = [];
|
|
112
|
+
|
|
113
|
+
class AsyncTask {
|
|
114
|
+
static State = {
|
|
115
|
+
INITIAL: 'initial',
|
|
116
|
+
CANCELLED: 'cancelled',
|
|
117
|
+
CANCEL_PENDING: 'cancel-pending',
|
|
118
|
+
CANCEL_DELIVERED: 'cancel-delivered',
|
|
119
|
+
RESOLVED: 'resolved',
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static BlockResult = {
|
|
123
|
+
CANCELLED: 'block.cancelled',
|
|
124
|
+
NOT_CANCELLED: 'block.not-cancelled',
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#id;
|
|
128
|
+
#componentIdx;
|
|
129
|
+
#state;
|
|
130
|
+
#isAsync;
|
|
131
|
+
#onResolve = null;
|
|
132
|
+
#entryFnName = null;
|
|
133
|
+
#subtasks = [];
|
|
134
|
+
#completionPromise = null;
|
|
135
|
+
|
|
136
|
+
cancelled = false;
|
|
137
|
+
requested = false;
|
|
138
|
+
alwaysTaskReturn = false;
|
|
139
|
+
|
|
140
|
+
returnCalls = 0;
|
|
141
|
+
storage = [0, 0];
|
|
142
|
+
borrowedHandles = {};
|
|
143
|
+
|
|
144
|
+
awaitableResume = null;
|
|
145
|
+
awaitableCancel = null;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
constructor(opts) {
|
|
149
|
+
if (opts?.id === undefined) { throw new TypeError('missing task ID during task creation'); }
|
|
150
|
+
this.#id = opts.id;
|
|
151
|
+
if (opts?.componentIdx === undefined) {
|
|
152
|
+
throw new TypeError('missing component id during task creation');
|
|
153
|
+
}
|
|
154
|
+
this.#componentIdx = opts.componentIdx;
|
|
155
|
+
this.#state = AsyncTask.State.INITIAL;
|
|
156
|
+
this.#isAsync = opts?.isAsync ?? false;
|
|
157
|
+
this.#entryFnName = opts.entryFnName;
|
|
158
|
+
|
|
159
|
+
const {
|
|
160
|
+
promise: completionPromise,
|
|
161
|
+
resolve: resolveCompletionPromise,
|
|
162
|
+
reject: rejectCompletionPromise,
|
|
163
|
+
} = Promise.withResolvers();
|
|
164
|
+
this.#completionPromise = completionPromise;
|
|
165
|
+
|
|
166
|
+
this.#onResolve = (results) => {
|
|
167
|
+
// TODO: handle external facing cancellation (should likely be a rejection)
|
|
168
|
+
resolveCompletionPromise(results);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
taskState() { return this.#state.slice(); }
|
|
173
|
+
id() { return this.#id; }
|
|
174
|
+
componentIdx() { return this.#componentIdx; }
|
|
175
|
+
isAsync() { return this.#isAsync; }
|
|
176
|
+
entryFnName() { return this.#entryFnName; }
|
|
177
|
+
completionPromise() { return this.#completionPromise; }
|
|
178
|
+
|
|
179
|
+
mayEnter(task) {
|
|
180
|
+
const cstate = getOrCreateAsyncState(this.#componentIdx);
|
|
181
|
+
if (!cstate.backpressure) {
|
|
182
|
+
_debugLog('[AsyncTask#mayEnter()] disallowed due to backpressure', { taskID: this.#id });
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
if (!cstate.callingSyncImport()) {
|
|
186
|
+
_debugLog('[AsyncTask#mayEnter()] disallowed due to sync import call', { taskID: this.#id });
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const callingSyncExportWithSyncPending = cstate.callingSyncExport && !task.isAsync;
|
|
190
|
+
if (!callingSyncExportWithSyncPending) {
|
|
191
|
+
_debugLog('[AsyncTask#mayEnter()] disallowed due to sync export w/ sync pending', { taskID: this.#id });
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async enter() {
|
|
198
|
+
_debugLog('[AsyncTask#enter()] args', { taskID: this.#id });
|
|
199
|
+
|
|
200
|
+
// TODO: assert scheduler locked
|
|
201
|
+
// TODO: trap if on the stack
|
|
202
|
+
|
|
203
|
+
const cstate = getOrCreateAsyncState(this.#componentIdx);
|
|
204
|
+
|
|
205
|
+
let mayNotEnter = !this.mayEnter(this);
|
|
206
|
+
const componentHasPendingTasks = cstate.pendingTasks > 0;
|
|
207
|
+
if (mayNotEnter || componentHasPendingTasks) {
|
|
208
|
+
throw new Error('in enter()'); // TODO: remove
|
|
209
|
+
cstate.pendingTasks.set(this.#id, new Awaitable(new Promise()));
|
|
210
|
+
|
|
211
|
+
const blockResult = await this.onBlock(awaitable);
|
|
212
|
+
if (blockResult) {
|
|
213
|
+
// TODO: find this pending task in the component
|
|
214
|
+
const pendingTask = cstate.pendingTasks.get(this.#id);
|
|
215
|
+
if (!pendingTask) {
|
|
216
|
+
throw new Error('pending task [' + this.#id + '] not found for component instance');
|
|
217
|
+
}
|
|
218
|
+
cstate.pendingTasks.remove(this.#id);
|
|
219
|
+
this.#onResolve(new Error('failed enter'));
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
mayNotEnter = !this.mayEnter(this);
|
|
224
|
+
if (!mayNotEnter || !cstate.startPendingTask) {
|
|
225
|
+
throw new Error('invalid component entrance/pending task resolution');
|
|
226
|
+
}
|
|
227
|
+
cstate.startPendingTask = false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!this.isAsync) { cstate.callingSyncExport = true; }
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async waitForEvent(opts) {
|
|
236
|
+
const { waitableSetRep, isAsync } = opts;
|
|
237
|
+
_debugLog('[AsyncTask#waitForEvent()] args', { taskID: this.#id, waitableSetRep, isAsync });
|
|
238
|
+
|
|
239
|
+
if (this.#isAsync !== isAsync) {
|
|
240
|
+
throw new Error('async waitForEvent called on non-async task');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (this.status === AsyncTask.State.CANCEL_PENDING) {
|
|
244
|
+
this.#state = AsyncTask.State.CANCEL_DELIVERED;
|
|
245
|
+
return {
|
|
246
|
+
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const state = getOrCreateAsyncState(this.#componentIdx);
|
|
251
|
+
const waitableSet = state.waitableSets.get(waitableSetRep);
|
|
252
|
+
if (!waitableSet) { throw new Error('missing/invalid waitable set'); }
|
|
253
|
+
|
|
254
|
+
waitableSet.numWaiting += 1;
|
|
255
|
+
let event = null;
|
|
256
|
+
|
|
257
|
+
while (event == null) {
|
|
258
|
+
const awaitable = new Awaitable(waitableSet.getPendingEvent());
|
|
259
|
+
const waited = await this.blockOn({ awaitable, isAsync, isCancellable: true });
|
|
260
|
+
if (waited) {
|
|
261
|
+
if (this.#state !== AsyncTask.State.INITIAL) {
|
|
262
|
+
throw new Error('task should be in initial state found [' + this.#state + ']');
|
|
263
|
+
}
|
|
264
|
+
this.#state = AsyncTask.State.CANCELLED;
|
|
265
|
+
return {
|
|
266
|
+
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
event = waitableSet.poll();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
waitableSet.numWaiting -= 1;
|
|
274
|
+
return event;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
waitForEventSync(opts) {
|
|
278
|
+
throw new Error('AsyncTask#yieldSync() not implemented')
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async pollForEvent(opts) {
|
|
282
|
+
const { waitableSetRep, isAsync } = opts;
|
|
283
|
+
_debugLog('[AsyncTask#pollForEvent()] args', { taskID: this.#id, waitableSetRep, isAsync });
|
|
284
|
+
|
|
285
|
+
if (this.#isAsync !== isAsync) {
|
|
286
|
+
throw new Error('async pollForEvent called on non-async task');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
throw new Error('AsyncTask#pollForEvent() not implemented');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
pollForEventSync(opts) {
|
|
293
|
+
throw new Error('AsyncTask#yieldSync() not implemented')
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async blockOn(opts) {
|
|
297
|
+
const { awaitable, isCancellable, forCallback } = opts;
|
|
298
|
+
_debugLog('[AsyncTask#blockOn()] args', { taskID: this.#id, awaitable, isCancellable, forCallback });
|
|
299
|
+
|
|
300
|
+
if (awaitable.resolved() && !ASYNC_DETERMINISM && _coinFlip()) {
|
|
301
|
+
return AsyncTask.BlockResult.NOT_CANCELLED;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const cstate = getOrCreateAsyncState(this.#componentIdx);
|
|
305
|
+
if (forCallback) { cstate.exclusiveRelease(); }
|
|
306
|
+
|
|
307
|
+
let cancelled = await this.onBlock(awaitable);
|
|
308
|
+
if (cancelled === AsyncTask.BlockResult.CANCELLED && !isCancellable) {
|
|
309
|
+
const secondCancel = await this.onBlock(awaitable);
|
|
310
|
+
if (secondCancel !== AsyncTask.BlockResult.NOT_CANCELLED) {
|
|
311
|
+
throw new Error('uncancellable task was canceled despite second onBlock()');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (forCallback) {
|
|
316
|
+
const acquired = new Awaitable(cstate.exclusiveLock());
|
|
317
|
+
cancelled = await this.onBlock(acquired);
|
|
318
|
+
if (cancelled === AsyncTask.BlockResult.CANCELLED) {
|
|
319
|
+
const secondCancel = await this.onBlock(acquired);
|
|
320
|
+
if (secondCancel !== AsyncTask.BlockResult.NOT_CANCELLED) {
|
|
321
|
+
throw new Error('uncancellable callback task was canceled despite second onBlock()');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (cancelled === AsyncTask.BlockResult.CANCELLED) {
|
|
327
|
+
if (this.#state !== AsyncTask.State.INITIAL) {
|
|
328
|
+
throw new Error('cancelled task is not at initial state');
|
|
329
|
+
}
|
|
330
|
+
if (isCancellable) {
|
|
331
|
+
this.#state = AsyncTask.State.CANCELLED;
|
|
332
|
+
return AsyncTask.BlockResult.CANCELLED;
|
|
333
|
+
} else {
|
|
334
|
+
this.#state = AsyncTask.State.CANCEL_PENDING;
|
|
335
|
+
return AsyncTask.BlockResult.NOT_CANCELLED;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return AsyncTask.BlockResult.NOT_CANCELLED;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async onBlock(awaitable) {
|
|
343
|
+
_debugLog('[AsyncTask#onBlock()] args', { taskID: this.#id, awaitable });
|
|
344
|
+
if (!(awaitable instanceof Awaitable)) {
|
|
345
|
+
throw new Error('invalid awaitable during onBlock');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Build a promise that this task can await on which resolves when it is awoken
|
|
349
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
350
|
+
this.awaitableResume = () => {
|
|
351
|
+
_debugLog('[AsyncTask] resuming after onBlock', { taskID: this.#id });
|
|
352
|
+
resolve();
|
|
353
|
+
};
|
|
354
|
+
this.awaitableCancel = (err) => {
|
|
355
|
+
_debugLog('[AsyncTask] rejecting after onBlock', { taskID: this.#id, err });
|
|
356
|
+
reject(err);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// Park this task/execution to be handled later
|
|
360
|
+
const state = getOrCreateAsyncState(this.#componentIdx);
|
|
361
|
+
state.parkTaskOnAwaitable({ awaitable, task: this });
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
await promise;
|
|
365
|
+
return AsyncTask.BlockResult.NOT_CANCELLED;
|
|
366
|
+
} catch (err) {
|
|
367
|
+
// rejection means task cancellation
|
|
368
|
+
return AsyncTask.BlockResult.CANCELLED;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async asyncOnBlock(awaitable) {
|
|
373
|
+
_debugLog('[AsyncTask#asyncOnBlock()] args', { taskID: this.#id, awaitable });
|
|
374
|
+
if (!(awaitable instanceof Awaitable)) {
|
|
375
|
+
throw new Error('invalid awaitable during onBlock');
|
|
376
|
+
}
|
|
377
|
+
// TODO: watch for waitable AND cancellation
|
|
378
|
+
// TODO: if it WAS cancelled:
|
|
379
|
+
// - return true
|
|
380
|
+
// - only once per subtask
|
|
381
|
+
// - do not wait on the scheduler
|
|
382
|
+
// - control flow should go to the subtask (only once)
|
|
383
|
+
// - Once subtask blocks/resolves, reqlinquishControl() will tehn resolve request_cancel_end (without scheduler lock release)
|
|
384
|
+
// - control flow goes back to request_cancel
|
|
385
|
+
//
|
|
386
|
+
// Subtask cancellation should work similarly to an async import call -- runs sync up until
|
|
387
|
+
// the subtask blocks or resolves
|
|
388
|
+
//
|
|
389
|
+
throw new Error('AsyncTask#asyncOnBlock() not yet implemented');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async yield(opts) {
|
|
393
|
+
const { isCancellable, forCallback } = opts;
|
|
394
|
+
_debugLog('[AsyncTask#yield()] args', { taskID: this.#id, isCancellable, forCallback });
|
|
395
|
+
|
|
396
|
+
if (isCancellable && this.status === AsyncTask.State.CANCEL_PENDING) {
|
|
397
|
+
this.#state = AsyncTask.State.CANCELLED;
|
|
398
|
+
return {
|
|
399
|
+
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
400
|
+
payload: [0, 0],
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// TODO: Awaitables need to *always* trigger the parking mechanism when they're done...?
|
|
405
|
+
// TODO: Component async state should remember which awaitables are done and work to clear tasks waiting
|
|
406
|
+
|
|
407
|
+
const blockResult = await this.blockOn({
|
|
408
|
+
awaitable: new Awaitable(new Promise(resolve => setTimeout(resolve, 0))),
|
|
409
|
+
isCancellable,
|
|
410
|
+
forCallback,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
if (blockResult === AsyncTask.BlockResult.CANCELLED) {
|
|
414
|
+
if (this.#state !== AsyncTask.State.INITIAL) {
|
|
415
|
+
throw new Error('task should be in initial state found [' + this.#state + ']');
|
|
416
|
+
}
|
|
417
|
+
this.#state = AsyncTask.State.CANCELLED;
|
|
418
|
+
return {
|
|
419
|
+
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
420
|
+
payload: [0, 0],
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
code: ASYNC_EVENT_CODE.NONE,
|
|
426
|
+
payload: [0, 0],
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
yieldSync(opts) {
|
|
431
|
+
throw new Error('AsyncTask#yieldSync() not implemented')
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
cancel() {
|
|
435
|
+
_debugLog('[AsyncTask#cancel()] args', { });
|
|
436
|
+
if (!this.taskState() !== AsyncTask.State.CANCEL_DELIVERED) {
|
|
437
|
+
throw new Error('invalid task state for cancellation');
|
|
438
|
+
}
|
|
439
|
+
if (this.borrowedHandles.length > 0) { throw new Error('task still has borrow handles'); }
|
|
440
|
+
|
|
441
|
+
this.#onResolve(new Error('cancelled'));
|
|
442
|
+
this.#state = AsyncTask.State.RESOLVED;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
resolve(results) {
|
|
446
|
+
_debugLog('[AsyncTask#resolve()] args', { results });
|
|
447
|
+
if (this.#state === AsyncTask.State.RESOLVED) {
|
|
448
|
+
throw new Error('task is already resolved');
|
|
449
|
+
}
|
|
450
|
+
if (this.borrowedHandles.length > 0) { throw new Error('task still has borrow handles'); }
|
|
451
|
+
this.#onResolve(results.length === 1 ? results[0] : results);
|
|
452
|
+
this.#state = AsyncTask.State.RESOLVED;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
exit() {
|
|
456
|
+
_debugLog('[AsyncTask#exit()] args', { });
|
|
457
|
+
|
|
458
|
+
// TODO: ensure there is only one task at a time (scheduler.lock() functionality)
|
|
459
|
+
if (this.#state !== AsyncTask.State.RESOLVED) {
|
|
460
|
+
throw new Error('task exited without resolution');
|
|
461
|
+
}
|
|
462
|
+
if (this.borrowedHandles > 0) {
|
|
463
|
+
throw new Error('task exited without clearing borrowed handles');
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const state = getOrCreateAsyncState(this.#componentIdx);
|
|
467
|
+
if (!state) { throw new Error('missing async state for component [' + this.#componentIdx + ']'); }
|
|
468
|
+
if (!this.#isAsync && !state.inSyncExportCall) {
|
|
469
|
+
throw new Error('sync task must be run from components known to be in a sync export call');
|
|
470
|
+
}
|
|
471
|
+
state.inSyncExportCall = false;
|
|
472
|
+
|
|
473
|
+
this.startPendingTask();
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
startPendingTask(args) {
|
|
477
|
+
_debugLog('[AsyncTask#startPendingTask()] args', args);
|
|
478
|
+
throw new Error('AsyncTask#startPendingTask() not implemented');
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
createSubtask(args) {
|
|
482
|
+
_debugLog('[AsyncTask#createSubtask()] args', args);
|
|
483
|
+
const newSubtask = new AsyncSubtask({
|
|
484
|
+
componentIdx: this.componentIdx(),
|
|
485
|
+
taskID: this.id(),
|
|
486
|
+
memoryIdx: args?.memoryIdx,
|
|
487
|
+
});
|
|
488
|
+
this.#subtasks.push(newSubtask);
|
|
489
|
+
return newSubtask;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
currentSubtask() {
|
|
493
|
+
_debugLog('[AsyncTask#currentSubtask()]');
|
|
494
|
+
if (this.#subtasks.length === 0) { throw new Error('no current subtask'); }
|
|
495
|
+
return this.#subtasks.at(-1);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
endCurrentSubtask() {
|
|
499
|
+
_debugLog('[AsyncTask#endCurrentSubtask()]');
|
|
500
|
+
if (this.#subtasks.length === 0) { throw new Error('cannot end current subtask: no current subtask'); }
|
|
501
|
+
const subtask = this.#subtasks.pop();
|
|
502
|
+
subtask.drop();
|
|
503
|
+
return subtask;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function unpackCallbackResult(result) {
|
|
508
|
+
_debugLog('[unpackCallbackResult()] args', { result });
|
|
509
|
+
if (!(_typeCheckValidI32(result))) { throw new Error('invalid callback return value [' + result + '], not a valid i32'); }
|
|
510
|
+
const eventCode = result & 0xF;
|
|
511
|
+
if (eventCode < 0 || eventCode > 3) {
|
|
512
|
+
throw new Error('invalid async return value [' + eventCode + '], outside callback code range');
|
|
513
|
+
}
|
|
514
|
+
if (result < 0 || result >= 2**32) { throw new Error('invalid callback result'); }
|
|
515
|
+
// TODO: table max length check?
|
|
516
|
+
const waitableSetIdx = result >> 4;
|
|
517
|
+
return [eventCode, waitableSetIdx];
|
|
518
|
+
}
|
|
519
|
+
const ASYNC_STATE = new Map();
|
|
520
|
+
|
|
521
|
+
function getOrCreateAsyncState(componentIdx, init) {
|
|
522
|
+
if (!ASYNC_STATE.has(componentIdx)) {
|
|
523
|
+
ASYNC_STATE.set(componentIdx, new ComponentAsyncState());
|
|
524
|
+
}
|
|
525
|
+
return ASYNC_STATE.get(componentIdx);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
class ComponentAsyncState {
|
|
529
|
+
#callingAsyncImport = false;
|
|
530
|
+
#syncImportWait = Promise.withResolvers();
|
|
531
|
+
#lock = null;
|
|
532
|
+
|
|
533
|
+
mayLeave = true;
|
|
534
|
+
waitableSets = new RepTable();
|
|
535
|
+
waitables = new RepTable();
|
|
536
|
+
|
|
537
|
+
#parkedTasks = new Map();
|
|
538
|
+
|
|
539
|
+
callingSyncImport(val) {
|
|
540
|
+
if (val === undefined) { return this.#callingAsyncImport; }
|
|
541
|
+
if (typeof val !== 'boolean') { throw new TypeError('invalid setting for async import'); }
|
|
542
|
+
const prev = this.#callingAsyncImport;
|
|
543
|
+
this.#callingAsyncImport = val;
|
|
544
|
+
if (prev === true && this.#callingAsyncImport === false) {
|
|
545
|
+
this.#notifySyncImportEnd();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
#notifySyncImportEnd() {
|
|
550
|
+
const existing = this.#syncImportWait;
|
|
551
|
+
this.#syncImportWait = Promise.withResolvers();
|
|
552
|
+
existing.resolve();
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
async waitForSyncImportCallEnd() {
|
|
556
|
+
await this.#syncImportWait.promise;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
parkTaskOnAwaitable(args) {
|
|
560
|
+
if (!args.awaitable) { throw new TypeError('missing awaitable when trying to park'); }
|
|
561
|
+
if (!args.task) { throw new TypeError('missing task when trying to park'); }
|
|
562
|
+
const { awaitable, task } = args;
|
|
563
|
+
|
|
564
|
+
let taskList = this.#parkedTasks.get(awaitable.id());
|
|
565
|
+
if (!taskList) {
|
|
566
|
+
taskList = [];
|
|
567
|
+
this.#parkedTasks.set(awaitable.id(), taskList);
|
|
568
|
+
}
|
|
569
|
+
taskList.push(task);
|
|
570
|
+
|
|
571
|
+
this.wakeNextTaskForAwaitable(awaitable);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
wakeNextTaskForAwaitable(awaitable) {
|
|
575
|
+
if (!awaitable) { throw new TypeError('missing awaitable when waking next task'); }
|
|
576
|
+
const awaitableID = awaitable.id();
|
|
577
|
+
|
|
578
|
+
const taskList = this.#parkedTasks.get(awaitableID);
|
|
579
|
+
if (!taskList || taskList.length === 0) {
|
|
580
|
+
_debugLog('[ComponentAsyncState] no tasks waiting for awaitable', { awaitableID: awaitable.id() });
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
let task = taskList.shift(); // todo(perf)
|
|
585
|
+
if (!task) { throw new Error('no task in parked list despite previous check'); }
|
|
586
|
+
|
|
587
|
+
if (!task.awaitableResume) {
|
|
588
|
+
throw new Error('task ready due to awaitable is missing resume', { taskID: task.id(), awaitableID });
|
|
589
|
+
}
|
|
590
|
+
task.awaitableResume();
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async exclusiveLock() { // TODO: use atomics
|
|
594
|
+
if (this.#lock === null) {
|
|
595
|
+
this.#lock = { ticket: 0n };
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Take a ticket for the next valid usage
|
|
599
|
+
const ticket = ++this.#lock.ticket;
|
|
600
|
+
|
|
601
|
+
_debugLog('[ComponentAsyncState#exclusiveLock()] locking', {
|
|
602
|
+
currentTicket: ticket - 1n,
|
|
603
|
+
ticket
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
// If there is an active promise, then wait for it
|
|
607
|
+
let finishedTicket;
|
|
608
|
+
while (this.#lock.promise) {
|
|
609
|
+
finishedTicket = await this.#lock.promise;
|
|
610
|
+
if (finishedTicket === ticket - 1n) { break; }
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
614
|
+
this.#lock = {
|
|
615
|
+
ticket,
|
|
616
|
+
promise,
|
|
617
|
+
resolve,
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
return this.#lock.promise;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
exclusiveRelease() {
|
|
624
|
+
_debugLog('[ComponentAsyncState#exclusiveRelease()] releasing', {
|
|
625
|
+
currentTicket: this.#lock === null ? 'none' : this.#lock.ticket,
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
if (this.#lock === null) { return; }
|
|
629
|
+
|
|
630
|
+
const existingLock = this.#lock;
|
|
631
|
+
this.#lock = null;
|
|
632
|
+
existingLock.resolve(existingLock.ticket);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
isExclusivelyLocked() { return this.#lock !== null; }
|
|
636
|
+
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function prepareCall(memoryIdx) {
|
|
640
|
+
_debugLog('[prepareCall()] args', { memoryIdx });
|
|
641
|
+
|
|
642
|
+
const taskMeta = getCurrentTask(ASYNC_CURRENT_COMPONENT_IDXS.at(-1), ASYNC_CURRENT_TASK_IDS.at(-1));
|
|
643
|
+
if (!taskMeta) { throw new Error('invalid/missing current async task meta during prepare call'); }
|
|
644
|
+
|
|
645
|
+
const task = taskMeta.task;
|
|
646
|
+
if (!task) { throw new Error('unexpectedly missing task in task meta during prepare call'); }
|
|
647
|
+
|
|
648
|
+
const state = getOrCreateAsyncState(task.componentIdx());
|
|
649
|
+
if (!state) {
|
|
650
|
+
throw new Error('invalid/missing async state for component instance [' + componentInstanceID + ']');
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const subtask = task.createSubtask({
|
|
654
|
+
memoryIdx,
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function asyncStartCall(callbackIdx, postReturnIdx) {
|
|
660
|
+
_debugLog('[asyncStartCall()] args', { callbackIdx, postReturnIdx });
|
|
661
|
+
|
|
662
|
+
const taskMeta = getCurrentTask(ASYNC_CURRENT_COMPONENT_IDXS.at(-1), ASYNC_CURRENT_TASK_IDS.at(-1));
|
|
663
|
+
if (!taskMeta) { throw new Error('invalid/missing current async task meta during prepare call'); }
|
|
664
|
+
|
|
665
|
+
const task = taskMeta.task;
|
|
666
|
+
if (!task) { throw new Error('unexpectedly missing task in task meta during prepare call'); }
|
|
667
|
+
|
|
668
|
+
const subtask = task.currentSubtask();
|
|
669
|
+
if (!subtask) { throw new Error('invalid/missing subtask during async start call'); }
|
|
670
|
+
|
|
671
|
+
return Number(subtask.waitableRep()) << 4 | subtask.getStateNumber();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function syncStartCall(callbackIdx) {
|
|
675
|
+
_debugLog('[syncStartCall()] args', { callbackIdx });
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (!Promise.withResolvers) {
|
|
679
|
+
Promise.withResolvers = () => {
|
|
680
|
+
let resolve;
|
|
681
|
+
let reject;
|
|
682
|
+
const promise = new Promise((res, rej) => {
|
|
683
|
+
resolve = res;
|
|
684
|
+
reject = rej;
|
|
685
|
+
});
|
|
686
|
+
return { promise, resolve, reject };
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const _debugLog = (...args) => {
|
|
691
|
+
if (!globalThis?.process?.env?.JCO_DEBUG) { return; }
|
|
692
|
+
console.debug(...args);
|
|
693
|
+
}
|
|
694
|
+
const ASYNC_DETERMINISM = 'random';
|
|
695
|
+
const _coinFlip = () => { return Math.random() > 0.5; };
|
|
696
|
+
const I32_MAX = 2_147_483_647;
|
|
697
|
+
const I32_MIN = -2_147_483_648;
|
|
698
|
+
const _typeCheckValidI32 = (n) => typeof n === 'number' && n >= I32_MIN && n <= I32_MAX;
|
|
699
|
+
|
|
700
|
+
const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
|
|
701
|
+
let _fs;
|
|
702
|
+
async function fetchCompile (url) {
|
|
703
|
+
if (isNode) {
|
|
704
|
+
_fs = _fs || await import('node:fs/promises');
|
|
705
|
+
return WebAssembly.compile(await _fs.readFile(url));
|
|
706
|
+
}
|
|
707
|
+
return fetch(url).then(WebAssembly.compileStreaming);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const symbolCabiDispose = Symbol.for('cabiDispose');
|
|
711
|
+
|
|
712
|
+
const symbolRscHandle = Symbol('handle');
|
|
713
|
+
|
|
714
|
+
const symbolRscRep = Symbol.for('cabiRep');
|
|
715
|
+
|
|
716
|
+
const symbolDispose = Symbol.dispose || Symbol.for('dispose');
|
|
717
|
+
|
|
718
|
+
const handleTables = [];
|
|
719
|
+
|
|
720
|
+
class ComponentError extends Error {
|
|
721
|
+
constructor (value) {
|
|
722
|
+
const enumerable = typeof value !== 'string';
|
|
723
|
+
super(enumerable ? `${String(value)} (see error.payload)` : value);
|
|
724
|
+
Object.defineProperty(this, 'payload', { value, enumerable });
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function getErrorPayload(e) {
|
|
729
|
+
if (e && hasOwnProperty.call(e, 'payload')) return e.payload;
|
|
730
|
+
if (e instanceof Error) throw e;
|
|
731
|
+
return e;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
class RepTable {
|
|
735
|
+
#data = [0, null];
|
|
736
|
+
|
|
737
|
+
insert(val) {
|
|
738
|
+
_debugLog('[RepTable#insert()] args', { val });
|
|
739
|
+
const freeIdx = this.#data[0];
|
|
740
|
+
if (freeIdx === 0) {
|
|
741
|
+
this.#data.push(val);
|
|
742
|
+
this.#data.push(null);
|
|
743
|
+
return (this.#data.length >> 1) - 1;
|
|
744
|
+
}
|
|
745
|
+
this.#data[0] = this.#data[freeIdx << 1];
|
|
746
|
+
const placementIdx = freeIdx << 1;
|
|
747
|
+
this.#data[placementIdx] = val;
|
|
748
|
+
this.#data[placementIdx + 1] = null;
|
|
749
|
+
return freeIdx;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
get(rep) {
|
|
753
|
+
_debugLog('[RepTable#get()] args', { rep });
|
|
754
|
+
const baseIdx = rep << 1;
|
|
755
|
+
const val = this.#data[baseIdx];
|
|
756
|
+
return val;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
contains(rep) {
|
|
760
|
+
_debugLog('[RepTable#contains()] args', { rep });
|
|
761
|
+
const baseIdx = rep << 1;
|
|
762
|
+
return !!this.#data[baseIdx];
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
remove(rep) {
|
|
766
|
+
_debugLog('[RepTable#remove()] args', { rep });
|
|
767
|
+
if (this.#data.length === 2) { throw new Error('invalid'); }
|
|
768
|
+
|
|
769
|
+
const baseIdx = rep << 1;
|
|
770
|
+
const val = this.#data[baseIdx];
|
|
771
|
+
if (val === 0) { throw new Error('invalid resource rep (cannot be 0)'); }
|
|
772
|
+
|
|
773
|
+
this.#data[baseIdx] = this.#data[0];
|
|
774
|
+
this.#data[0] = rep;
|
|
775
|
+
|
|
776
|
+
return val;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
clear() {
|
|
780
|
+
_debugLog('[RepTable#clear()] args', { rep });
|
|
781
|
+
this.#data = [0, null];
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function throwInvalidBool() {
|
|
786
|
+
throw new TypeError('invalid variant discriminant for bool');
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
if (!getCoreModule) getCoreModule = (name) => fetchCompile(new URL(`./${name}`, import.meta.url));
|
|
793
|
+
const module0 = getCoreModule('grammar.core.wasm');
|
|
794
|
+
const module1 = getCoreModule('grammar.core2.wasm');
|
|
795
|
+
const module2 = getCoreModule('grammar.core3.wasm');
|
|
796
|
+
const module3 = getCoreModule('grammar.core4.wasm');
|
|
797
|
+
|
|
798
|
+
const { getEnvironment } = imports['wasi:cli/environment'];
|
|
799
|
+
const { exit } = imports['wasi:cli/exit'];
|
|
800
|
+
const { getStderr } = imports['wasi:cli/stderr'];
|
|
801
|
+
const { getStdin } = imports['wasi:cli/stdin'];
|
|
802
|
+
const { getStdout } = imports['wasi:cli/stdout'];
|
|
803
|
+
const { getDirectories } = imports['wasi:filesystem/preopens'];
|
|
804
|
+
const { Descriptor, filesystemErrorCode } = imports['wasi:filesystem/types'];
|
|
805
|
+
const { Error: Error$1 } = imports['wasi:io/error'];
|
|
806
|
+
const { InputStream, OutputStream } = imports['wasi:io/streams'];
|
|
807
|
+
const { getRandomBytes } = imports['wasi:random/random'];
|
|
808
|
+
let gen = (function* _initGenerator () {
|
|
809
|
+
let exports0;
|
|
810
|
+
let exports1;
|
|
811
|
+
const handleTable1 = [T_FLAG, 0];
|
|
812
|
+
const captureTable1= new Map();
|
|
813
|
+
let captureCnt1 = 0;
|
|
814
|
+
handleTables[1] = handleTable1;
|
|
815
|
+
|
|
816
|
+
function trampoline4() {
|
|
817
|
+
_debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
818
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stderr');
|
|
819
|
+
const ret = getStderr();
|
|
820
|
+
_debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
821
|
+
endCurrentTask(0);
|
|
822
|
+
if (!(ret instanceof OutputStream)) {
|
|
823
|
+
throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
|
|
824
|
+
}
|
|
825
|
+
var handle0 = ret[symbolRscHandle];
|
|
826
|
+
if (!handle0) {
|
|
827
|
+
const rep = ret[symbolRscRep] || ++captureCnt1;
|
|
828
|
+
captureTable1.set(rep, ret);
|
|
829
|
+
handle0 = rscTableCreateOwn(handleTable1, rep);
|
|
830
|
+
}
|
|
831
|
+
_debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"][Instruction::Return]', {
|
|
832
|
+
funcName: 'get-stderr',
|
|
833
|
+
paramCount: 1,
|
|
834
|
+
async: false,
|
|
835
|
+
postReturn: false
|
|
836
|
+
});
|
|
837
|
+
return handle0;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
const handleTable2 = [T_FLAG, 0];
|
|
841
|
+
const captureTable2= new Map();
|
|
842
|
+
let captureCnt2 = 0;
|
|
843
|
+
handleTables[2] = handleTable2;
|
|
844
|
+
|
|
845
|
+
function trampoline5() {
|
|
846
|
+
_debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
847
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stdin');
|
|
848
|
+
const ret = getStdin();
|
|
849
|
+
_debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
850
|
+
endCurrentTask(0);
|
|
851
|
+
if (!(ret instanceof InputStream)) {
|
|
852
|
+
throw new TypeError('Resource error: Not a valid "InputStream" resource.');
|
|
853
|
+
}
|
|
854
|
+
var handle0 = ret[symbolRscHandle];
|
|
855
|
+
if (!handle0) {
|
|
856
|
+
const rep = ret[symbolRscRep] || ++captureCnt2;
|
|
857
|
+
captureTable2.set(rep, ret);
|
|
858
|
+
handle0 = rscTableCreateOwn(handleTable2, rep);
|
|
859
|
+
}
|
|
860
|
+
_debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"][Instruction::Return]', {
|
|
861
|
+
funcName: 'get-stdin',
|
|
862
|
+
paramCount: 1,
|
|
863
|
+
async: false,
|
|
864
|
+
postReturn: false
|
|
865
|
+
});
|
|
866
|
+
return handle0;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
function trampoline6() {
|
|
871
|
+
_debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
872
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stdout');
|
|
873
|
+
const ret = getStdout();
|
|
874
|
+
_debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
875
|
+
endCurrentTask(0);
|
|
876
|
+
if (!(ret instanceof OutputStream)) {
|
|
877
|
+
throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
|
|
878
|
+
}
|
|
879
|
+
var handle0 = ret[symbolRscHandle];
|
|
880
|
+
if (!handle0) {
|
|
881
|
+
const rep = ret[symbolRscRep] || ++captureCnt1;
|
|
882
|
+
captureTable1.set(rep, ret);
|
|
883
|
+
handle0 = rscTableCreateOwn(handleTable1, rep);
|
|
884
|
+
}
|
|
885
|
+
_debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"][Instruction::Return]', {
|
|
886
|
+
funcName: 'get-stdout',
|
|
887
|
+
paramCount: 1,
|
|
888
|
+
async: false,
|
|
889
|
+
postReturn: false
|
|
890
|
+
});
|
|
891
|
+
return handle0;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
function trampoline7(arg0) {
|
|
896
|
+
let variant0;
|
|
897
|
+
switch (arg0) {
|
|
898
|
+
case 0: {
|
|
899
|
+
variant0= {
|
|
900
|
+
tag: 'ok',
|
|
901
|
+
val: undefined
|
|
902
|
+
};
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
case 1: {
|
|
906
|
+
variant0= {
|
|
907
|
+
tag: 'err',
|
|
908
|
+
val: undefined
|
|
909
|
+
};
|
|
910
|
+
break;
|
|
911
|
+
}
|
|
912
|
+
default: {
|
|
913
|
+
throw new TypeError('invalid variant discriminant for expected');
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
_debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
917
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'exit');
|
|
918
|
+
exit(variant0);
|
|
919
|
+
_debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
920
|
+
endCurrentTask(0);
|
|
921
|
+
_debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"][Instruction::Return]', {
|
|
922
|
+
funcName: 'exit',
|
|
923
|
+
paramCount: 0,
|
|
924
|
+
async: false,
|
|
925
|
+
postReturn: false
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
let exports2;
|
|
930
|
+
let memory0;
|
|
931
|
+
let realloc0;
|
|
932
|
+
|
|
933
|
+
function trampoline8(arg0) {
|
|
934
|
+
_debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
935
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-environment');
|
|
936
|
+
const ret = getEnvironment();
|
|
937
|
+
_debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
938
|
+
endCurrentTask(0);
|
|
939
|
+
var vec3 = ret;
|
|
940
|
+
var len3 = vec3.length;
|
|
941
|
+
var result3 = realloc0(0, 0, 4, len3 * 16);
|
|
942
|
+
for (let i = 0; i < vec3.length; i++) {
|
|
943
|
+
const e = vec3[i];
|
|
944
|
+
const base = result3 + i * 16;var [tuple0_0, tuple0_1] = e;
|
|
945
|
+
var ptr1 = utf8Encode(tuple0_0, realloc0, memory0);
|
|
946
|
+
var len1 = utf8EncodedLen;
|
|
947
|
+
dataView(memory0).setUint32(base + 4, len1, true);
|
|
948
|
+
dataView(memory0).setUint32(base + 0, ptr1, true);
|
|
949
|
+
var ptr2 = utf8Encode(tuple0_1, realloc0, memory0);
|
|
950
|
+
var len2 = utf8EncodedLen;
|
|
951
|
+
dataView(memory0).setUint32(base + 12, len2, true);
|
|
952
|
+
dataView(memory0).setUint32(base + 8, ptr2, true);
|
|
953
|
+
}
|
|
954
|
+
dataView(memory0).setUint32(arg0 + 4, len3, true);
|
|
955
|
+
dataView(memory0).setUint32(arg0 + 0, result3, true);
|
|
956
|
+
_debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"][Instruction::Return]', {
|
|
957
|
+
funcName: 'get-environment',
|
|
958
|
+
paramCount: 0,
|
|
959
|
+
async: false,
|
|
960
|
+
postReturn: false
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
const handleTable0 = [T_FLAG, 0];
|
|
965
|
+
const captureTable0= new Map();
|
|
966
|
+
let captureCnt0 = 0;
|
|
967
|
+
handleTables[0] = handleTable0;
|
|
968
|
+
|
|
969
|
+
function trampoline9(arg0, arg1) {
|
|
970
|
+
var handle1 = arg0;
|
|
971
|
+
var rep2 = handleTable0[(handle1 << 1) + 1] & ~T_FLAG;
|
|
972
|
+
var rsc0 = captureTable0.get(rep2);
|
|
973
|
+
if (!rsc0) {
|
|
974
|
+
rsc0 = Object.create(Error$1.prototype);
|
|
975
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
976
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
977
|
+
}
|
|
978
|
+
curResourceBorrows.push(rsc0);
|
|
979
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
980
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'filesystem-error-code');
|
|
981
|
+
const ret = filesystemErrorCode(rsc0);
|
|
982
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
983
|
+
for (const rsc of curResourceBorrows) {
|
|
984
|
+
rsc[symbolRscHandle] = undefined;
|
|
985
|
+
}
|
|
986
|
+
curResourceBorrows = [];
|
|
987
|
+
endCurrentTask(0);
|
|
988
|
+
var variant4 = ret;
|
|
989
|
+
if (variant4 === null || variant4=== undefined) {
|
|
990
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
991
|
+
} else {
|
|
992
|
+
const e = variant4;
|
|
993
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
994
|
+
var val3 = e;
|
|
995
|
+
let enum3;
|
|
996
|
+
switch (val3) {
|
|
997
|
+
case 'access': {
|
|
998
|
+
enum3 = 0;
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
case 'would-block': {
|
|
1002
|
+
enum3 = 1;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
case 'already': {
|
|
1006
|
+
enum3 = 2;
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case 'bad-descriptor': {
|
|
1010
|
+
enum3 = 3;
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
case 'busy': {
|
|
1014
|
+
enum3 = 4;
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
case 'deadlock': {
|
|
1018
|
+
enum3 = 5;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
case 'quota': {
|
|
1022
|
+
enum3 = 6;
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
case 'exist': {
|
|
1026
|
+
enum3 = 7;
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
case 'file-too-large': {
|
|
1030
|
+
enum3 = 8;
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
case 'illegal-byte-sequence': {
|
|
1034
|
+
enum3 = 9;
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
case 'in-progress': {
|
|
1038
|
+
enum3 = 10;
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
case 'interrupted': {
|
|
1042
|
+
enum3 = 11;
|
|
1043
|
+
break;
|
|
1044
|
+
}
|
|
1045
|
+
case 'invalid': {
|
|
1046
|
+
enum3 = 12;
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
case 'io': {
|
|
1050
|
+
enum3 = 13;
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
case 'is-directory': {
|
|
1054
|
+
enum3 = 14;
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
case 'loop': {
|
|
1058
|
+
enum3 = 15;
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
case 'too-many-links': {
|
|
1062
|
+
enum3 = 16;
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
case 'message-size': {
|
|
1066
|
+
enum3 = 17;
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
case 'name-too-long': {
|
|
1070
|
+
enum3 = 18;
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
case 'no-device': {
|
|
1074
|
+
enum3 = 19;
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
case 'no-entry': {
|
|
1078
|
+
enum3 = 20;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
case 'no-lock': {
|
|
1082
|
+
enum3 = 21;
|
|
1083
|
+
break;
|
|
1084
|
+
}
|
|
1085
|
+
case 'insufficient-memory': {
|
|
1086
|
+
enum3 = 22;
|
|
1087
|
+
break;
|
|
1088
|
+
}
|
|
1089
|
+
case 'insufficient-space': {
|
|
1090
|
+
enum3 = 23;
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1093
|
+
case 'not-directory': {
|
|
1094
|
+
enum3 = 24;
|
|
1095
|
+
break;
|
|
1096
|
+
}
|
|
1097
|
+
case 'not-empty': {
|
|
1098
|
+
enum3 = 25;
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
case 'not-recoverable': {
|
|
1102
|
+
enum3 = 26;
|
|
1103
|
+
break;
|
|
1104
|
+
}
|
|
1105
|
+
case 'unsupported': {
|
|
1106
|
+
enum3 = 27;
|
|
1107
|
+
break;
|
|
1108
|
+
}
|
|
1109
|
+
case 'no-tty': {
|
|
1110
|
+
enum3 = 28;
|
|
1111
|
+
break;
|
|
1112
|
+
}
|
|
1113
|
+
case 'no-such-device': {
|
|
1114
|
+
enum3 = 29;
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
case 'overflow': {
|
|
1118
|
+
enum3 = 30;
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
case 'not-permitted': {
|
|
1122
|
+
enum3 = 31;
|
|
1123
|
+
break;
|
|
1124
|
+
}
|
|
1125
|
+
case 'pipe': {
|
|
1126
|
+
enum3 = 32;
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
case 'read-only': {
|
|
1130
|
+
enum3 = 33;
|
|
1131
|
+
break;
|
|
1132
|
+
}
|
|
1133
|
+
case 'invalid-seek': {
|
|
1134
|
+
enum3 = 34;
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
case 'text-file-busy': {
|
|
1138
|
+
enum3 = 35;
|
|
1139
|
+
break;
|
|
1140
|
+
}
|
|
1141
|
+
case 'cross-device': {
|
|
1142
|
+
enum3 = 36;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
default: {
|
|
1146
|
+
if ((e) instanceof Error) {
|
|
1147
|
+
console.error(e);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
throw new TypeError(`"${val3}" is not one of the cases of error-code`);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
dataView(memory0).setInt8(arg1 + 1, enum3, true);
|
|
1154
|
+
}
|
|
1155
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"][Instruction::Return]', {
|
|
1156
|
+
funcName: 'filesystem-error-code',
|
|
1157
|
+
paramCount: 0,
|
|
1158
|
+
async: false,
|
|
1159
|
+
postReturn: false
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
const handleTable3 = [T_FLAG, 0];
|
|
1164
|
+
const captureTable3= new Map();
|
|
1165
|
+
let captureCnt3 = 0;
|
|
1166
|
+
handleTables[3] = handleTable3;
|
|
1167
|
+
|
|
1168
|
+
function trampoline10(arg0, arg1, arg2) {
|
|
1169
|
+
var handle1 = arg0;
|
|
1170
|
+
var rep2 = handleTable3[(handle1 << 1) + 1] & ~T_FLAG;
|
|
1171
|
+
var rsc0 = captureTable3.get(rep2);
|
|
1172
|
+
if (!rsc0) {
|
|
1173
|
+
rsc0 = Object.create(Descriptor.prototype);
|
|
1174
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
1175
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
1176
|
+
}
|
|
1177
|
+
curResourceBorrows.push(rsc0);
|
|
1178
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
1179
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.write-via-stream');
|
|
1180
|
+
let ret;
|
|
1181
|
+
try {
|
|
1182
|
+
ret = { tag: 'ok', val: rsc0.writeViaStream(BigInt.asUintN(64, arg1))};
|
|
1183
|
+
} catch (e) {
|
|
1184
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
1185
|
+
}
|
|
1186
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
1187
|
+
for (const rsc of curResourceBorrows) {
|
|
1188
|
+
rsc[symbolRscHandle] = undefined;
|
|
1189
|
+
}
|
|
1190
|
+
curResourceBorrows = [];
|
|
1191
|
+
endCurrentTask(0);
|
|
1192
|
+
var variant5 = ret;
|
|
1193
|
+
switch (variant5.tag) {
|
|
1194
|
+
case 'ok': {
|
|
1195
|
+
const e = variant5.val;
|
|
1196
|
+
dataView(memory0).setInt8(arg2 + 0, 0, true);
|
|
1197
|
+
if (!(e instanceof OutputStream)) {
|
|
1198
|
+
throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
|
|
1199
|
+
}
|
|
1200
|
+
var handle3 = e[symbolRscHandle];
|
|
1201
|
+
if (!handle3) {
|
|
1202
|
+
const rep = e[symbolRscRep] || ++captureCnt1;
|
|
1203
|
+
captureTable1.set(rep, e);
|
|
1204
|
+
handle3 = rscTableCreateOwn(handleTable1, rep);
|
|
1205
|
+
}
|
|
1206
|
+
dataView(memory0).setInt32(arg2 + 4, handle3, true);
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
case 'err': {
|
|
1210
|
+
const e = variant5.val;
|
|
1211
|
+
dataView(memory0).setInt8(arg2 + 0, 1, true);
|
|
1212
|
+
var val4 = e;
|
|
1213
|
+
let enum4;
|
|
1214
|
+
switch (val4) {
|
|
1215
|
+
case 'access': {
|
|
1216
|
+
enum4 = 0;
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
case 'would-block': {
|
|
1220
|
+
enum4 = 1;
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
case 'already': {
|
|
1224
|
+
enum4 = 2;
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
case 'bad-descriptor': {
|
|
1228
|
+
enum4 = 3;
|
|
1229
|
+
break;
|
|
1230
|
+
}
|
|
1231
|
+
case 'busy': {
|
|
1232
|
+
enum4 = 4;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
case 'deadlock': {
|
|
1236
|
+
enum4 = 5;
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1239
|
+
case 'quota': {
|
|
1240
|
+
enum4 = 6;
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
case 'exist': {
|
|
1244
|
+
enum4 = 7;
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
case 'file-too-large': {
|
|
1248
|
+
enum4 = 8;
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1251
|
+
case 'illegal-byte-sequence': {
|
|
1252
|
+
enum4 = 9;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
case 'in-progress': {
|
|
1256
|
+
enum4 = 10;
|
|
1257
|
+
break;
|
|
1258
|
+
}
|
|
1259
|
+
case 'interrupted': {
|
|
1260
|
+
enum4 = 11;
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
case 'invalid': {
|
|
1264
|
+
enum4 = 12;
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
case 'io': {
|
|
1268
|
+
enum4 = 13;
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
case 'is-directory': {
|
|
1272
|
+
enum4 = 14;
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
case 'loop': {
|
|
1276
|
+
enum4 = 15;
|
|
1277
|
+
break;
|
|
1278
|
+
}
|
|
1279
|
+
case 'too-many-links': {
|
|
1280
|
+
enum4 = 16;
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
case 'message-size': {
|
|
1284
|
+
enum4 = 17;
|
|
1285
|
+
break;
|
|
1286
|
+
}
|
|
1287
|
+
case 'name-too-long': {
|
|
1288
|
+
enum4 = 18;
|
|
1289
|
+
break;
|
|
1290
|
+
}
|
|
1291
|
+
case 'no-device': {
|
|
1292
|
+
enum4 = 19;
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
case 'no-entry': {
|
|
1296
|
+
enum4 = 20;
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
case 'no-lock': {
|
|
1300
|
+
enum4 = 21;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
case 'insufficient-memory': {
|
|
1304
|
+
enum4 = 22;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
case 'insufficient-space': {
|
|
1308
|
+
enum4 = 23;
|
|
1309
|
+
break;
|
|
1310
|
+
}
|
|
1311
|
+
case 'not-directory': {
|
|
1312
|
+
enum4 = 24;
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
case 'not-empty': {
|
|
1316
|
+
enum4 = 25;
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
case 'not-recoverable': {
|
|
1320
|
+
enum4 = 26;
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
case 'unsupported': {
|
|
1324
|
+
enum4 = 27;
|
|
1325
|
+
break;
|
|
1326
|
+
}
|
|
1327
|
+
case 'no-tty': {
|
|
1328
|
+
enum4 = 28;
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
case 'no-such-device': {
|
|
1332
|
+
enum4 = 29;
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
case 'overflow': {
|
|
1336
|
+
enum4 = 30;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
case 'not-permitted': {
|
|
1340
|
+
enum4 = 31;
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
case 'pipe': {
|
|
1344
|
+
enum4 = 32;
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
case 'read-only': {
|
|
1348
|
+
enum4 = 33;
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
case 'invalid-seek': {
|
|
1352
|
+
enum4 = 34;
|
|
1353
|
+
break;
|
|
1354
|
+
}
|
|
1355
|
+
case 'text-file-busy': {
|
|
1356
|
+
enum4 = 35;
|
|
1357
|
+
break;
|
|
1358
|
+
}
|
|
1359
|
+
case 'cross-device': {
|
|
1360
|
+
enum4 = 36;
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
default: {
|
|
1364
|
+
if ((e) instanceof Error) {
|
|
1365
|
+
console.error(e);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
throw new TypeError(`"${val4}" is not one of the cases of error-code`);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
dataView(memory0).setInt8(arg2 + 4, enum4, true);
|
|
1372
|
+
break;
|
|
1373
|
+
}
|
|
1374
|
+
default: {
|
|
1375
|
+
throw new TypeError('invalid variant specified for result');
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"][Instruction::Return]', {
|
|
1379
|
+
funcName: '[method]descriptor.write-via-stream',
|
|
1380
|
+
paramCount: 0,
|
|
1381
|
+
async: false,
|
|
1382
|
+
postReturn: false
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
function trampoline11(arg0, arg1) {
|
|
1388
|
+
var handle1 = arg0;
|
|
1389
|
+
var rep2 = handleTable3[(handle1 << 1) + 1] & ~T_FLAG;
|
|
1390
|
+
var rsc0 = captureTable3.get(rep2);
|
|
1391
|
+
if (!rsc0) {
|
|
1392
|
+
rsc0 = Object.create(Descriptor.prototype);
|
|
1393
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
1394
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
1395
|
+
}
|
|
1396
|
+
curResourceBorrows.push(rsc0);
|
|
1397
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
1398
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.append-via-stream');
|
|
1399
|
+
let ret;
|
|
1400
|
+
try {
|
|
1401
|
+
ret = { tag: 'ok', val: rsc0.appendViaStream()};
|
|
1402
|
+
} catch (e) {
|
|
1403
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
1404
|
+
}
|
|
1405
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
1406
|
+
for (const rsc of curResourceBorrows) {
|
|
1407
|
+
rsc[symbolRscHandle] = undefined;
|
|
1408
|
+
}
|
|
1409
|
+
curResourceBorrows = [];
|
|
1410
|
+
endCurrentTask(0);
|
|
1411
|
+
var variant5 = ret;
|
|
1412
|
+
switch (variant5.tag) {
|
|
1413
|
+
case 'ok': {
|
|
1414
|
+
const e = variant5.val;
|
|
1415
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
1416
|
+
if (!(e instanceof OutputStream)) {
|
|
1417
|
+
throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
|
|
1418
|
+
}
|
|
1419
|
+
var handle3 = e[symbolRscHandle];
|
|
1420
|
+
if (!handle3) {
|
|
1421
|
+
const rep = e[symbolRscRep] || ++captureCnt1;
|
|
1422
|
+
captureTable1.set(rep, e);
|
|
1423
|
+
handle3 = rscTableCreateOwn(handleTable1, rep);
|
|
1424
|
+
}
|
|
1425
|
+
dataView(memory0).setInt32(arg1 + 4, handle3, true);
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
case 'err': {
|
|
1429
|
+
const e = variant5.val;
|
|
1430
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
1431
|
+
var val4 = e;
|
|
1432
|
+
let enum4;
|
|
1433
|
+
switch (val4) {
|
|
1434
|
+
case 'access': {
|
|
1435
|
+
enum4 = 0;
|
|
1436
|
+
break;
|
|
1437
|
+
}
|
|
1438
|
+
case 'would-block': {
|
|
1439
|
+
enum4 = 1;
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1442
|
+
case 'already': {
|
|
1443
|
+
enum4 = 2;
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
case 'bad-descriptor': {
|
|
1447
|
+
enum4 = 3;
|
|
1448
|
+
break;
|
|
1449
|
+
}
|
|
1450
|
+
case 'busy': {
|
|
1451
|
+
enum4 = 4;
|
|
1452
|
+
break;
|
|
1453
|
+
}
|
|
1454
|
+
case 'deadlock': {
|
|
1455
|
+
enum4 = 5;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
case 'quota': {
|
|
1459
|
+
enum4 = 6;
|
|
1460
|
+
break;
|
|
1461
|
+
}
|
|
1462
|
+
case 'exist': {
|
|
1463
|
+
enum4 = 7;
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
case 'file-too-large': {
|
|
1467
|
+
enum4 = 8;
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
case 'illegal-byte-sequence': {
|
|
1471
|
+
enum4 = 9;
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
case 'in-progress': {
|
|
1475
|
+
enum4 = 10;
|
|
1476
|
+
break;
|
|
1477
|
+
}
|
|
1478
|
+
case 'interrupted': {
|
|
1479
|
+
enum4 = 11;
|
|
1480
|
+
break;
|
|
1481
|
+
}
|
|
1482
|
+
case 'invalid': {
|
|
1483
|
+
enum4 = 12;
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
case 'io': {
|
|
1487
|
+
enum4 = 13;
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
case 'is-directory': {
|
|
1491
|
+
enum4 = 14;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
case 'loop': {
|
|
1495
|
+
enum4 = 15;
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
case 'too-many-links': {
|
|
1499
|
+
enum4 = 16;
|
|
1500
|
+
break;
|
|
1501
|
+
}
|
|
1502
|
+
case 'message-size': {
|
|
1503
|
+
enum4 = 17;
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
case 'name-too-long': {
|
|
1507
|
+
enum4 = 18;
|
|
1508
|
+
break;
|
|
1509
|
+
}
|
|
1510
|
+
case 'no-device': {
|
|
1511
|
+
enum4 = 19;
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
case 'no-entry': {
|
|
1515
|
+
enum4 = 20;
|
|
1516
|
+
break;
|
|
1517
|
+
}
|
|
1518
|
+
case 'no-lock': {
|
|
1519
|
+
enum4 = 21;
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
case 'insufficient-memory': {
|
|
1523
|
+
enum4 = 22;
|
|
1524
|
+
break;
|
|
1525
|
+
}
|
|
1526
|
+
case 'insufficient-space': {
|
|
1527
|
+
enum4 = 23;
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
case 'not-directory': {
|
|
1531
|
+
enum4 = 24;
|
|
1532
|
+
break;
|
|
1533
|
+
}
|
|
1534
|
+
case 'not-empty': {
|
|
1535
|
+
enum4 = 25;
|
|
1536
|
+
break;
|
|
1537
|
+
}
|
|
1538
|
+
case 'not-recoverable': {
|
|
1539
|
+
enum4 = 26;
|
|
1540
|
+
break;
|
|
1541
|
+
}
|
|
1542
|
+
case 'unsupported': {
|
|
1543
|
+
enum4 = 27;
|
|
1544
|
+
break;
|
|
1545
|
+
}
|
|
1546
|
+
case 'no-tty': {
|
|
1547
|
+
enum4 = 28;
|
|
1548
|
+
break;
|
|
1549
|
+
}
|
|
1550
|
+
case 'no-such-device': {
|
|
1551
|
+
enum4 = 29;
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
case 'overflow': {
|
|
1555
|
+
enum4 = 30;
|
|
1556
|
+
break;
|
|
1557
|
+
}
|
|
1558
|
+
case 'not-permitted': {
|
|
1559
|
+
enum4 = 31;
|
|
1560
|
+
break;
|
|
1561
|
+
}
|
|
1562
|
+
case 'pipe': {
|
|
1563
|
+
enum4 = 32;
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
case 'read-only': {
|
|
1567
|
+
enum4 = 33;
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
case 'invalid-seek': {
|
|
1571
|
+
enum4 = 34;
|
|
1572
|
+
break;
|
|
1573
|
+
}
|
|
1574
|
+
case 'text-file-busy': {
|
|
1575
|
+
enum4 = 35;
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
case 'cross-device': {
|
|
1579
|
+
enum4 = 36;
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
default: {
|
|
1583
|
+
if ((e) instanceof Error) {
|
|
1584
|
+
console.error(e);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
throw new TypeError(`"${val4}" is not one of the cases of error-code`);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
dataView(memory0).setInt8(arg1 + 4, enum4, true);
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
default: {
|
|
1594
|
+
throw new TypeError('invalid variant specified for result');
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"][Instruction::Return]', {
|
|
1598
|
+
funcName: '[method]descriptor.append-via-stream',
|
|
1599
|
+
paramCount: 0,
|
|
1600
|
+
async: false,
|
|
1601
|
+
postReturn: false
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
function trampoline12(arg0, arg1) {
|
|
1607
|
+
var handle1 = arg0;
|
|
1608
|
+
var rep2 = handleTable3[(handle1 << 1) + 1] & ~T_FLAG;
|
|
1609
|
+
var rsc0 = captureTable3.get(rep2);
|
|
1610
|
+
if (!rsc0) {
|
|
1611
|
+
rsc0 = Object.create(Descriptor.prototype);
|
|
1612
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
1613
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
1614
|
+
}
|
|
1615
|
+
curResourceBorrows.push(rsc0);
|
|
1616
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
1617
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.get-type');
|
|
1618
|
+
let ret;
|
|
1619
|
+
try {
|
|
1620
|
+
ret = { tag: 'ok', val: rsc0.getType()};
|
|
1621
|
+
} catch (e) {
|
|
1622
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
1623
|
+
}
|
|
1624
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
1625
|
+
for (const rsc of curResourceBorrows) {
|
|
1626
|
+
rsc[symbolRscHandle] = undefined;
|
|
1627
|
+
}
|
|
1628
|
+
curResourceBorrows = [];
|
|
1629
|
+
endCurrentTask(0);
|
|
1630
|
+
var variant5 = ret;
|
|
1631
|
+
switch (variant5.tag) {
|
|
1632
|
+
case 'ok': {
|
|
1633
|
+
const e = variant5.val;
|
|
1634
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
1635
|
+
var val3 = e;
|
|
1636
|
+
let enum3;
|
|
1637
|
+
switch (val3) {
|
|
1638
|
+
case 'unknown': {
|
|
1639
|
+
enum3 = 0;
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
case 'block-device': {
|
|
1643
|
+
enum3 = 1;
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1646
|
+
case 'character-device': {
|
|
1647
|
+
enum3 = 2;
|
|
1648
|
+
break;
|
|
1649
|
+
}
|
|
1650
|
+
case 'directory': {
|
|
1651
|
+
enum3 = 3;
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
case 'fifo': {
|
|
1655
|
+
enum3 = 4;
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
case 'symbolic-link': {
|
|
1659
|
+
enum3 = 5;
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
case 'regular-file': {
|
|
1663
|
+
enum3 = 6;
|
|
1664
|
+
break;
|
|
1665
|
+
}
|
|
1666
|
+
case 'socket': {
|
|
1667
|
+
enum3 = 7;
|
|
1668
|
+
break;
|
|
1669
|
+
}
|
|
1670
|
+
default: {
|
|
1671
|
+
if ((e) instanceof Error) {
|
|
1672
|
+
console.error(e);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
throw new TypeError(`"${val3}" is not one of the cases of descriptor-type`);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
dataView(memory0).setInt8(arg1 + 1, enum3, true);
|
|
1679
|
+
break;
|
|
1680
|
+
}
|
|
1681
|
+
case 'err': {
|
|
1682
|
+
const e = variant5.val;
|
|
1683
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
1684
|
+
var val4 = e;
|
|
1685
|
+
let enum4;
|
|
1686
|
+
switch (val4) {
|
|
1687
|
+
case 'access': {
|
|
1688
|
+
enum4 = 0;
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
case 'would-block': {
|
|
1692
|
+
enum4 = 1;
|
|
1693
|
+
break;
|
|
1694
|
+
}
|
|
1695
|
+
case 'already': {
|
|
1696
|
+
enum4 = 2;
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
case 'bad-descriptor': {
|
|
1700
|
+
enum4 = 3;
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1703
|
+
case 'busy': {
|
|
1704
|
+
enum4 = 4;
|
|
1705
|
+
break;
|
|
1706
|
+
}
|
|
1707
|
+
case 'deadlock': {
|
|
1708
|
+
enum4 = 5;
|
|
1709
|
+
break;
|
|
1710
|
+
}
|
|
1711
|
+
case 'quota': {
|
|
1712
|
+
enum4 = 6;
|
|
1713
|
+
break;
|
|
1714
|
+
}
|
|
1715
|
+
case 'exist': {
|
|
1716
|
+
enum4 = 7;
|
|
1717
|
+
break;
|
|
1718
|
+
}
|
|
1719
|
+
case 'file-too-large': {
|
|
1720
|
+
enum4 = 8;
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
case 'illegal-byte-sequence': {
|
|
1724
|
+
enum4 = 9;
|
|
1725
|
+
break;
|
|
1726
|
+
}
|
|
1727
|
+
case 'in-progress': {
|
|
1728
|
+
enum4 = 10;
|
|
1729
|
+
break;
|
|
1730
|
+
}
|
|
1731
|
+
case 'interrupted': {
|
|
1732
|
+
enum4 = 11;
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
case 'invalid': {
|
|
1736
|
+
enum4 = 12;
|
|
1737
|
+
break;
|
|
1738
|
+
}
|
|
1739
|
+
case 'io': {
|
|
1740
|
+
enum4 = 13;
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
1743
|
+
case 'is-directory': {
|
|
1744
|
+
enum4 = 14;
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
case 'loop': {
|
|
1748
|
+
enum4 = 15;
|
|
1749
|
+
break;
|
|
1750
|
+
}
|
|
1751
|
+
case 'too-many-links': {
|
|
1752
|
+
enum4 = 16;
|
|
1753
|
+
break;
|
|
1754
|
+
}
|
|
1755
|
+
case 'message-size': {
|
|
1756
|
+
enum4 = 17;
|
|
1757
|
+
break;
|
|
1758
|
+
}
|
|
1759
|
+
case 'name-too-long': {
|
|
1760
|
+
enum4 = 18;
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
case 'no-device': {
|
|
1764
|
+
enum4 = 19;
|
|
1765
|
+
break;
|
|
1766
|
+
}
|
|
1767
|
+
case 'no-entry': {
|
|
1768
|
+
enum4 = 20;
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
case 'no-lock': {
|
|
1772
|
+
enum4 = 21;
|
|
1773
|
+
break;
|
|
1774
|
+
}
|
|
1775
|
+
case 'insufficient-memory': {
|
|
1776
|
+
enum4 = 22;
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
case 'insufficient-space': {
|
|
1780
|
+
enum4 = 23;
|
|
1781
|
+
break;
|
|
1782
|
+
}
|
|
1783
|
+
case 'not-directory': {
|
|
1784
|
+
enum4 = 24;
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
case 'not-empty': {
|
|
1788
|
+
enum4 = 25;
|
|
1789
|
+
break;
|
|
1790
|
+
}
|
|
1791
|
+
case 'not-recoverable': {
|
|
1792
|
+
enum4 = 26;
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
case 'unsupported': {
|
|
1796
|
+
enum4 = 27;
|
|
1797
|
+
break;
|
|
1798
|
+
}
|
|
1799
|
+
case 'no-tty': {
|
|
1800
|
+
enum4 = 28;
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
case 'no-such-device': {
|
|
1804
|
+
enum4 = 29;
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
case 'overflow': {
|
|
1808
|
+
enum4 = 30;
|
|
1809
|
+
break;
|
|
1810
|
+
}
|
|
1811
|
+
case 'not-permitted': {
|
|
1812
|
+
enum4 = 31;
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
case 'pipe': {
|
|
1816
|
+
enum4 = 32;
|
|
1817
|
+
break;
|
|
1818
|
+
}
|
|
1819
|
+
case 'read-only': {
|
|
1820
|
+
enum4 = 33;
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
case 'invalid-seek': {
|
|
1824
|
+
enum4 = 34;
|
|
1825
|
+
break;
|
|
1826
|
+
}
|
|
1827
|
+
case 'text-file-busy': {
|
|
1828
|
+
enum4 = 35;
|
|
1829
|
+
break;
|
|
1830
|
+
}
|
|
1831
|
+
case 'cross-device': {
|
|
1832
|
+
enum4 = 36;
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
default: {
|
|
1836
|
+
if ((e) instanceof Error) {
|
|
1837
|
+
console.error(e);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
throw new TypeError(`"${val4}" is not one of the cases of error-code`);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
dataView(memory0).setInt8(arg1 + 1, enum4, true);
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
default: {
|
|
1847
|
+
throw new TypeError('invalid variant specified for result');
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"][Instruction::Return]', {
|
|
1851
|
+
funcName: '[method]descriptor.get-type',
|
|
1852
|
+
paramCount: 0,
|
|
1853
|
+
async: false,
|
|
1854
|
+
postReturn: false
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
function trampoline13(arg0, arg1) {
|
|
1860
|
+
var handle1 = arg0;
|
|
1861
|
+
var rep2 = handleTable3[(handle1 << 1) + 1] & ~T_FLAG;
|
|
1862
|
+
var rsc0 = captureTable3.get(rep2);
|
|
1863
|
+
if (!rsc0) {
|
|
1864
|
+
rsc0 = Object.create(Descriptor.prototype);
|
|
1865
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
1866
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
1867
|
+
}
|
|
1868
|
+
curResourceBorrows.push(rsc0);
|
|
1869
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
1870
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.stat');
|
|
1871
|
+
let ret;
|
|
1872
|
+
try {
|
|
1873
|
+
ret = { tag: 'ok', val: rsc0.stat()};
|
|
1874
|
+
} catch (e) {
|
|
1875
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
1876
|
+
}
|
|
1877
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
1878
|
+
for (const rsc of curResourceBorrows) {
|
|
1879
|
+
rsc[symbolRscHandle] = undefined;
|
|
1880
|
+
}
|
|
1881
|
+
curResourceBorrows = [];
|
|
1882
|
+
endCurrentTask(0);
|
|
1883
|
+
var variant12 = ret;
|
|
1884
|
+
switch (variant12.tag) {
|
|
1885
|
+
case 'ok': {
|
|
1886
|
+
const e = variant12.val;
|
|
1887
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
1888
|
+
var {type: v3_0, linkCount: v3_1, size: v3_2, dataAccessTimestamp: v3_3, dataModificationTimestamp: v3_4, statusChangeTimestamp: v3_5 } = e;
|
|
1889
|
+
var val4 = v3_0;
|
|
1890
|
+
let enum4;
|
|
1891
|
+
switch (val4) {
|
|
1892
|
+
case 'unknown': {
|
|
1893
|
+
enum4 = 0;
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
case 'block-device': {
|
|
1897
|
+
enum4 = 1;
|
|
1898
|
+
break;
|
|
1899
|
+
}
|
|
1900
|
+
case 'character-device': {
|
|
1901
|
+
enum4 = 2;
|
|
1902
|
+
break;
|
|
1903
|
+
}
|
|
1904
|
+
case 'directory': {
|
|
1905
|
+
enum4 = 3;
|
|
1906
|
+
break;
|
|
1907
|
+
}
|
|
1908
|
+
case 'fifo': {
|
|
1909
|
+
enum4 = 4;
|
|
1910
|
+
break;
|
|
1911
|
+
}
|
|
1912
|
+
case 'symbolic-link': {
|
|
1913
|
+
enum4 = 5;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
case 'regular-file': {
|
|
1917
|
+
enum4 = 6;
|
|
1918
|
+
break;
|
|
1919
|
+
}
|
|
1920
|
+
case 'socket': {
|
|
1921
|
+
enum4 = 7;
|
|
1922
|
+
break;
|
|
1923
|
+
}
|
|
1924
|
+
default: {
|
|
1925
|
+
if ((v3_0) instanceof Error) {
|
|
1926
|
+
console.error(v3_0);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
throw new TypeError(`"${val4}" is not one of the cases of descriptor-type`);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
dataView(memory0).setInt8(arg1 + 8, enum4, true);
|
|
1933
|
+
dataView(memory0).setBigInt64(arg1 + 16, toUint64(v3_1), true);
|
|
1934
|
+
dataView(memory0).setBigInt64(arg1 + 24, toUint64(v3_2), true);
|
|
1935
|
+
var variant6 = v3_3;
|
|
1936
|
+
if (variant6 === null || variant6=== undefined) {
|
|
1937
|
+
dataView(memory0).setInt8(arg1 + 32, 0, true);
|
|
1938
|
+
} else {
|
|
1939
|
+
const e = variant6;
|
|
1940
|
+
dataView(memory0).setInt8(arg1 + 32, 1, true);
|
|
1941
|
+
var {seconds: v5_0, nanoseconds: v5_1 } = e;
|
|
1942
|
+
dataView(memory0).setBigInt64(arg1 + 40, toUint64(v5_0), true);
|
|
1943
|
+
dataView(memory0).setInt32(arg1 + 48, toUint32(v5_1), true);
|
|
1944
|
+
}
|
|
1945
|
+
var variant8 = v3_4;
|
|
1946
|
+
if (variant8 === null || variant8=== undefined) {
|
|
1947
|
+
dataView(memory0).setInt8(arg1 + 56, 0, true);
|
|
1948
|
+
} else {
|
|
1949
|
+
const e = variant8;
|
|
1950
|
+
dataView(memory0).setInt8(arg1 + 56, 1, true);
|
|
1951
|
+
var {seconds: v7_0, nanoseconds: v7_1 } = e;
|
|
1952
|
+
dataView(memory0).setBigInt64(arg1 + 64, toUint64(v7_0), true);
|
|
1953
|
+
dataView(memory0).setInt32(arg1 + 72, toUint32(v7_1), true);
|
|
1954
|
+
}
|
|
1955
|
+
var variant10 = v3_5;
|
|
1956
|
+
if (variant10 === null || variant10=== undefined) {
|
|
1957
|
+
dataView(memory0).setInt8(arg1 + 80, 0, true);
|
|
1958
|
+
} else {
|
|
1959
|
+
const e = variant10;
|
|
1960
|
+
dataView(memory0).setInt8(arg1 + 80, 1, true);
|
|
1961
|
+
var {seconds: v9_0, nanoseconds: v9_1 } = e;
|
|
1962
|
+
dataView(memory0).setBigInt64(arg1 + 88, toUint64(v9_0), true);
|
|
1963
|
+
dataView(memory0).setInt32(arg1 + 96, toUint32(v9_1), true);
|
|
1964
|
+
}
|
|
1965
|
+
break;
|
|
1966
|
+
}
|
|
1967
|
+
case 'err': {
|
|
1968
|
+
const e = variant12.val;
|
|
1969
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
1970
|
+
var val11 = e;
|
|
1971
|
+
let enum11;
|
|
1972
|
+
switch (val11) {
|
|
1973
|
+
case 'access': {
|
|
1974
|
+
enum11 = 0;
|
|
1975
|
+
break;
|
|
1976
|
+
}
|
|
1977
|
+
case 'would-block': {
|
|
1978
|
+
enum11 = 1;
|
|
1979
|
+
break;
|
|
1980
|
+
}
|
|
1981
|
+
case 'already': {
|
|
1982
|
+
enum11 = 2;
|
|
1983
|
+
break;
|
|
1984
|
+
}
|
|
1985
|
+
case 'bad-descriptor': {
|
|
1986
|
+
enum11 = 3;
|
|
1987
|
+
break;
|
|
1988
|
+
}
|
|
1989
|
+
case 'busy': {
|
|
1990
|
+
enum11 = 4;
|
|
1991
|
+
break;
|
|
1992
|
+
}
|
|
1993
|
+
case 'deadlock': {
|
|
1994
|
+
enum11 = 5;
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
case 'quota': {
|
|
1998
|
+
enum11 = 6;
|
|
1999
|
+
break;
|
|
2000
|
+
}
|
|
2001
|
+
case 'exist': {
|
|
2002
|
+
enum11 = 7;
|
|
2003
|
+
break;
|
|
2004
|
+
}
|
|
2005
|
+
case 'file-too-large': {
|
|
2006
|
+
enum11 = 8;
|
|
2007
|
+
break;
|
|
2008
|
+
}
|
|
2009
|
+
case 'illegal-byte-sequence': {
|
|
2010
|
+
enum11 = 9;
|
|
2011
|
+
break;
|
|
2012
|
+
}
|
|
2013
|
+
case 'in-progress': {
|
|
2014
|
+
enum11 = 10;
|
|
2015
|
+
break;
|
|
2016
|
+
}
|
|
2017
|
+
case 'interrupted': {
|
|
2018
|
+
enum11 = 11;
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
case 'invalid': {
|
|
2022
|
+
enum11 = 12;
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
case 'io': {
|
|
2026
|
+
enum11 = 13;
|
|
2027
|
+
break;
|
|
2028
|
+
}
|
|
2029
|
+
case 'is-directory': {
|
|
2030
|
+
enum11 = 14;
|
|
2031
|
+
break;
|
|
2032
|
+
}
|
|
2033
|
+
case 'loop': {
|
|
2034
|
+
enum11 = 15;
|
|
2035
|
+
break;
|
|
2036
|
+
}
|
|
2037
|
+
case 'too-many-links': {
|
|
2038
|
+
enum11 = 16;
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
case 'message-size': {
|
|
2042
|
+
enum11 = 17;
|
|
2043
|
+
break;
|
|
2044
|
+
}
|
|
2045
|
+
case 'name-too-long': {
|
|
2046
|
+
enum11 = 18;
|
|
2047
|
+
break;
|
|
2048
|
+
}
|
|
2049
|
+
case 'no-device': {
|
|
2050
|
+
enum11 = 19;
|
|
2051
|
+
break;
|
|
2052
|
+
}
|
|
2053
|
+
case 'no-entry': {
|
|
2054
|
+
enum11 = 20;
|
|
2055
|
+
break;
|
|
2056
|
+
}
|
|
2057
|
+
case 'no-lock': {
|
|
2058
|
+
enum11 = 21;
|
|
2059
|
+
break;
|
|
2060
|
+
}
|
|
2061
|
+
case 'insufficient-memory': {
|
|
2062
|
+
enum11 = 22;
|
|
2063
|
+
break;
|
|
2064
|
+
}
|
|
2065
|
+
case 'insufficient-space': {
|
|
2066
|
+
enum11 = 23;
|
|
2067
|
+
break;
|
|
2068
|
+
}
|
|
2069
|
+
case 'not-directory': {
|
|
2070
|
+
enum11 = 24;
|
|
2071
|
+
break;
|
|
2072
|
+
}
|
|
2073
|
+
case 'not-empty': {
|
|
2074
|
+
enum11 = 25;
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
case 'not-recoverable': {
|
|
2078
|
+
enum11 = 26;
|
|
2079
|
+
break;
|
|
2080
|
+
}
|
|
2081
|
+
case 'unsupported': {
|
|
2082
|
+
enum11 = 27;
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
case 'no-tty': {
|
|
2086
|
+
enum11 = 28;
|
|
2087
|
+
break;
|
|
2088
|
+
}
|
|
2089
|
+
case 'no-such-device': {
|
|
2090
|
+
enum11 = 29;
|
|
2091
|
+
break;
|
|
2092
|
+
}
|
|
2093
|
+
case 'overflow': {
|
|
2094
|
+
enum11 = 30;
|
|
2095
|
+
break;
|
|
2096
|
+
}
|
|
2097
|
+
case 'not-permitted': {
|
|
2098
|
+
enum11 = 31;
|
|
2099
|
+
break;
|
|
2100
|
+
}
|
|
2101
|
+
case 'pipe': {
|
|
2102
|
+
enum11 = 32;
|
|
2103
|
+
break;
|
|
2104
|
+
}
|
|
2105
|
+
case 'read-only': {
|
|
2106
|
+
enum11 = 33;
|
|
2107
|
+
break;
|
|
2108
|
+
}
|
|
2109
|
+
case 'invalid-seek': {
|
|
2110
|
+
enum11 = 34;
|
|
2111
|
+
break;
|
|
2112
|
+
}
|
|
2113
|
+
case 'text-file-busy': {
|
|
2114
|
+
enum11 = 35;
|
|
2115
|
+
break;
|
|
2116
|
+
}
|
|
2117
|
+
case 'cross-device': {
|
|
2118
|
+
enum11 = 36;
|
|
2119
|
+
break;
|
|
2120
|
+
}
|
|
2121
|
+
default: {
|
|
2122
|
+
if ((e) instanceof Error) {
|
|
2123
|
+
console.error(e);
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
throw new TypeError(`"${val11}" is not one of the cases of error-code`);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
dataView(memory0).setInt8(arg1 + 8, enum11, true);
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
2132
|
+
default: {
|
|
2133
|
+
throw new TypeError('invalid variant specified for result');
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
_debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"][Instruction::Return]', {
|
|
2137
|
+
funcName: '[method]descriptor.stat',
|
|
2138
|
+
paramCount: 0,
|
|
2139
|
+
async: false,
|
|
2140
|
+
postReturn: false
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
function trampoline14(arg0, arg1) {
|
|
2146
|
+
var handle1 = arg0;
|
|
2147
|
+
var rep2 = handleTable1[(handle1 << 1) + 1] & ~T_FLAG;
|
|
2148
|
+
var rsc0 = captureTable1.get(rep2);
|
|
2149
|
+
if (!rsc0) {
|
|
2150
|
+
rsc0 = Object.create(OutputStream.prototype);
|
|
2151
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
2152
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
2153
|
+
}
|
|
2154
|
+
curResourceBorrows.push(rsc0);
|
|
2155
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2156
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.check-write');
|
|
2157
|
+
let ret;
|
|
2158
|
+
try {
|
|
2159
|
+
ret = { tag: 'ok', val: rsc0.checkWrite()};
|
|
2160
|
+
} catch (e) {
|
|
2161
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
2162
|
+
}
|
|
2163
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2164
|
+
for (const rsc of curResourceBorrows) {
|
|
2165
|
+
rsc[symbolRscHandle] = undefined;
|
|
2166
|
+
}
|
|
2167
|
+
curResourceBorrows = [];
|
|
2168
|
+
endCurrentTask(0);
|
|
2169
|
+
var variant5 = ret;
|
|
2170
|
+
switch (variant5.tag) {
|
|
2171
|
+
case 'ok': {
|
|
2172
|
+
const e = variant5.val;
|
|
2173
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
2174
|
+
dataView(memory0).setBigInt64(arg1 + 8, toUint64(e), true);
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
case 'err': {
|
|
2178
|
+
const e = variant5.val;
|
|
2179
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
2180
|
+
var variant4 = e;
|
|
2181
|
+
switch (variant4.tag) {
|
|
2182
|
+
case 'last-operation-failed': {
|
|
2183
|
+
const e = variant4.val;
|
|
2184
|
+
dataView(memory0).setInt8(arg1 + 8, 0, true);
|
|
2185
|
+
if (!(e instanceof Error$1)) {
|
|
2186
|
+
throw new TypeError('Resource error: Not a valid "Error" resource.');
|
|
2187
|
+
}
|
|
2188
|
+
var handle3 = e[symbolRscHandle];
|
|
2189
|
+
if (!handle3) {
|
|
2190
|
+
const rep = e[symbolRscRep] || ++captureCnt0;
|
|
2191
|
+
captureTable0.set(rep, e);
|
|
2192
|
+
handle3 = rscTableCreateOwn(handleTable0, rep);
|
|
2193
|
+
}
|
|
2194
|
+
dataView(memory0).setInt32(arg1 + 12, handle3, true);
|
|
2195
|
+
break;
|
|
2196
|
+
}
|
|
2197
|
+
case 'closed': {
|
|
2198
|
+
dataView(memory0).setInt8(arg1 + 8, 1, true);
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
default: {
|
|
2202
|
+
throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant4.tag)}\` (received \`${variant4}\`) specified for \`StreamError\``);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
break;
|
|
2206
|
+
}
|
|
2207
|
+
default: {
|
|
2208
|
+
throw new TypeError('invalid variant specified for result');
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"][Instruction::Return]', {
|
|
2212
|
+
funcName: '[method]output-stream.check-write',
|
|
2213
|
+
paramCount: 0,
|
|
2214
|
+
async: false,
|
|
2215
|
+
postReturn: false
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
|
|
2220
|
+
function trampoline15(arg0, arg1, arg2, arg3) {
|
|
2221
|
+
var handle1 = arg0;
|
|
2222
|
+
var rep2 = handleTable1[(handle1 << 1) + 1] & ~T_FLAG;
|
|
2223
|
+
var rsc0 = captureTable1.get(rep2);
|
|
2224
|
+
if (!rsc0) {
|
|
2225
|
+
rsc0 = Object.create(OutputStream.prototype);
|
|
2226
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
2227
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
2228
|
+
}
|
|
2229
|
+
curResourceBorrows.push(rsc0);
|
|
2230
|
+
var ptr3 = arg1;
|
|
2231
|
+
var len3 = arg2;
|
|
2232
|
+
var result3 = new Uint8Array(memory0.buffer.slice(ptr3, ptr3 + len3 * 1));
|
|
2233
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2234
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.write');
|
|
2235
|
+
let ret;
|
|
2236
|
+
try {
|
|
2237
|
+
ret = { tag: 'ok', val: rsc0.write(result3)};
|
|
2238
|
+
} catch (e) {
|
|
2239
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
2240
|
+
}
|
|
2241
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2242
|
+
for (const rsc of curResourceBorrows) {
|
|
2243
|
+
rsc[symbolRscHandle] = undefined;
|
|
2244
|
+
}
|
|
2245
|
+
curResourceBorrows = [];
|
|
2246
|
+
endCurrentTask(0);
|
|
2247
|
+
var variant6 = ret;
|
|
2248
|
+
switch (variant6.tag) {
|
|
2249
|
+
case 'ok': {
|
|
2250
|
+
const e = variant6.val;
|
|
2251
|
+
dataView(memory0).setInt8(arg3 + 0, 0, true);
|
|
2252
|
+
break;
|
|
2253
|
+
}
|
|
2254
|
+
case 'err': {
|
|
2255
|
+
const e = variant6.val;
|
|
2256
|
+
dataView(memory0).setInt8(arg3 + 0, 1, true);
|
|
2257
|
+
var variant5 = e;
|
|
2258
|
+
switch (variant5.tag) {
|
|
2259
|
+
case 'last-operation-failed': {
|
|
2260
|
+
const e = variant5.val;
|
|
2261
|
+
dataView(memory0).setInt8(arg3 + 4, 0, true);
|
|
2262
|
+
if (!(e instanceof Error$1)) {
|
|
2263
|
+
throw new TypeError('Resource error: Not a valid "Error" resource.');
|
|
2264
|
+
}
|
|
2265
|
+
var handle4 = e[symbolRscHandle];
|
|
2266
|
+
if (!handle4) {
|
|
2267
|
+
const rep = e[symbolRscRep] || ++captureCnt0;
|
|
2268
|
+
captureTable0.set(rep, e);
|
|
2269
|
+
handle4 = rscTableCreateOwn(handleTable0, rep);
|
|
2270
|
+
}
|
|
2271
|
+
dataView(memory0).setInt32(arg3 + 8, handle4, true);
|
|
2272
|
+
break;
|
|
2273
|
+
}
|
|
2274
|
+
case 'closed': {
|
|
2275
|
+
dataView(memory0).setInt8(arg3 + 4, 1, true);
|
|
2276
|
+
break;
|
|
2277
|
+
}
|
|
2278
|
+
default: {
|
|
2279
|
+
throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant5.tag)}\` (received \`${variant5}\`) specified for \`StreamError\``);
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
break;
|
|
2283
|
+
}
|
|
2284
|
+
default: {
|
|
2285
|
+
throw new TypeError('invalid variant specified for result');
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"][Instruction::Return]', {
|
|
2289
|
+
funcName: '[method]output-stream.write',
|
|
2290
|
+
paramCount: 0,
|
|
2291
|
+
async: false,
|
|
2292
|
+
postReturn: false
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
function trampoline16(arg0, arg1) {
|
|
2298
|
+
var handle1 = arg0;
|
|
2299
|
+
var rep2 = handleTable1[(handle1 << 1) + 1] & ~T_FLAG;
|
|
2300
|
+
var rsc0 = captureTable1.get(rep2);
|
|
2301
|
+
if (!rsc0) {
|
|
2302
|
+
rsc0 = Object.create(OutputStream.prototype);
|
|
2303
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
2304
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
2305
|
+
}
|
|
2306
|
+
curResourceBorrows.push(rsc0);
|
|
2307
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2308
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.blocking-flush');
|
|
2309
|
+
let ret;
|
|
2310
|
+
try {
|
|
2311
|
+
ret = { tag: 'ok', val: rsc0.blockingFlush()};
|
|
2312
|
+
} catch (e) {
|
|
2313
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
2314
|
+
}
|
|
2315
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2316
|
+
for (const rsc of curResourceBorrows) {
|
|
2317
|
+
rsc[symbolRscHandle] = undefined;
|
|
2318
|
+
}
|
|
2319
|
+
curResourceBorrows = [];
|
|
2320
|
+
endCurrentTask(0);
|
|
2321
|
+
var variant5 = ret;
|
|
2322
|
+
switch (variant5.tag) {
|
|
2323
|
+
case 'ok': {
|
|
2324
|
+
const e = variant5.val;
|
|
2325
|
+
dataView(memory0).setInt8(arg1 + 0, 0, true);
|
|
2326
|
+
break;
|
|
2327
|
+
}
|
|
2328
|
+
case 'err': {
|
|
2329
|
+
const e = variant5.val;
|
|
2330
|
+
dataView(memory0).setInt8(arg1 + 0, 1, true);
|
|
2331
|
+
var variant4 = e;
|
|
2332
|
+
switch (variant4.tag) {
|
|
2333
|
+
case 'last-operation-failed': {
|
|
2334
|
+
const e = variant4.val;
|
|
2335
|
+
dataView(memory0).setInt8(arg1 + 4, 0, true);
|
|
2336
|
+
if (!(e instanceof Error$1)) {
|
|
2337
|
+
throw new TypeError('Resource error: Not a valid "Error" resource.');
|
|
2338
|
+
}
|
|
2339
|
+
var handle3 = e[symbolRscHandle];
|
|
2340
|
+
if (!handle3) {
|
|
2341
|
+
const rep = e[symbolRscRep] || ++captureCnt0;
|
|
2342
|
+
captureTable0.set(rep, e);
|
|
2343
|
+
handle3 = rscTableCreateOwn(handleTable0, rep);
|
|
2344
|
+
}
|
|
2345
|
+
dataView(memory0).setInt32(arg1 + 8, handle3, true);
|
|
2346
|
+
break;
|
|
2347
|
+
}
|
|
2348
|
+
case 'closed': {
|
|
2349
|
+
dataView(memory0).setInt8(arg1 + 4, 1, true);
|
|
2350
|
+
break;
|
|
2351
|
+
}
|
|
2352
|
+
default: {
|
|
2353
|
+
throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant4.tag)}\` (received \`${variant4}\`) specified for \`StreamError\``);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
break;
|
|
2357
|
+
}
|
|
2358
|
+
default: {
|
|
2359
|
+
throw new TypeError('invalid variant specified for result');
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"][Instruction::Return]', {
|
|
2363
|
+
funcName: '[method]output-stream.blocking-flush',
|
|
2364
|
+
paramCount: 0,
|
|
2365
|
+
async: false,
|
|
2366
|
+
postReturn: false
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
function trampoline17(arg0, arg1, arg2, arg3) {
|
|
2372
|
+
var handle1 = arg0;
|
|
2373
|
+
var rep2 = handleTable1[(handle1 << 1) + 1] & ~T_FLAG;
|
|
2374
|
+
var rsc0 = captureTable1.get(rep2);
|
|
2375
|
+
if (!rsc0) {
|
|
2376
|
+
rsc0 = Object.create(OutputStream.prototype);
|
|
2377
|
+
Object.defineProperty(rsc0, symbolRscHandle, { writable: true, value: handle1});
|
|
2378
|
+
Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
|
|
2379
|
+
}
|
|
2380
|
+
curResourceBorrows.push(rsc0);
|
|
2381
|
+
var ptr3 = arg1;
|
|
2382
|
+
var len3 = arg2;
|
|
2383
|
+
var result3 = new Uint8Array(memory0.buffer.slice(ptr3, ptr3 + len3 * 1));
|
|
2384
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2385
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.blocking-write-and-flush');
|
|
2386
|
+
let ret;
|
|
2387
|
+
try {
|
|
2388
|
+
ret = { tag: 'ok', val: rsc0.blockingWriteAndFlush(result3)};
|
|
2389
|
+
} catch (e) {
|
|
2390
|
+
ret = { tag: 'err', val: getErrorPayload(e) };
|
|
2391
|
+
}
|
|
2392
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2393
|
+
for (const rsc of curResourceBorrows) {
|
|
2394
|
+
rsc[symbolRscHandle] = undefined;
|
|
2395
|
+
}
|
|
2396
|
+
curResourceBorrows = [];
|
|
2397
|
+
endCurrentTask(0);
|
|
2398
|
+
var variant6 = ret;
|
|
2399
|
+
switch (variant6.tag) {
|
|
2400
|
+
case 'ok': {
|
|
2401
|
+
const e = variant6.val;
|
|
2402
|
+
dataView(memory0).setInt8(arg3 + 0, 0, true);
|
|
2403
|
+
break;
|
|
2404
|
+
}
|
|
2405
|
+
case 'err': {
|
|
2406
|
+
const e = variant6.val;
|
|
2407
|
+
dataView(memory0).setInt8(arg3 + 0, 1, true);
|
|
2408
|
+
var variant5 = e;
|
|
2409
|
+
switch (variant5.tag) {
|
|
2410
|
+
case 'last-operation-failed': {
|
|
2411
|
+
const e = variant5.val;
|
|
2412
|
+
dataView(memory0).setInt8(arg3 + 4, 0, true);
|
|
2413
|
+
if (!(e instanceof Error$1)) {
|
|
2414
|
+
throw new TypeError('Resource error: Not a valid "Error" resource.');
|
|
2415
|
+
}
|
|
2416
|
+
var handle4 = e[symbolRscHandle];
|
|
2417
|
+
if (!handle4) {
|
|
2418
|
+
const rep = e[symbolRscRep] || ++captureCnt0;
|
|
2419
|
+
captureTable0.set(rep, e);
|
|
2420
|
+
handle4 = rscTableCreateOwn(handleTable0, rep);
|
|
2421
|
+
}
|
|
2422
|
+
dataView(memory0).setInt32(arg3 + 8, handle4, true);
|
|
2423
|
+
break;
|
|
2424
|
+
}
|
|
2425
|
+
case 'closed': {
|
|
2426
|
+
dataView(memory0).setInt8(arg3 + 4, 1, true);
|
|
2427
|
+
break;
|
|
2428
|
+
}
|
|
2429
|
+
default: {
|
|
2430
|
+
throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant5.tag)}\` (received \`${variant5}\`) specified for \`StreamError\``);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
break;
|
|
2434
|
+
}
|
|
2435
|
+
default: {
|
|
2436
|
+
throw new TypeError('invalid variant specified for result');
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
_debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"][Instruction::Return]', {
|
|
2440
|
+
funcName: '[method]output-stream.blocking-write-and-flush',
|
|
2441
|
+
paramCount: 0,
|
|
2442
|
+
async: false,
|
|
2443
|
+
postReturn: false
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
function trampoline18(arg0, arg1) {
|
|
2449
|
+
_debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2450
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-random-bytes');
|
|
2451
|
+
const ret = getRandomBytes(BigInt.asUintN(64, arg0));
|
|
2452
|
+
_debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2453
|
+
endCurrentTask(0);
|
|
2454
|
+
var val0 = ret;
|
|
2455
|
+
var len0 = val0.byteLength;
|
|
2456
|
+
var ptr0 = realloc0(0, 0, 1, len0 * 1);
|
|
2457
|
+
var src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
|
|
2458
|
+
(new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
|
|
2459
|
+
dataView(memory0).setUint32(arg1 + 4, len0, true);
|
|
2460
|
+
dataView(memory0).setUint32(arg1 + 0, ptr0, true);
|
|
2461
|
+
_debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"][Instruction::Return]', {
|
|
2462
|
+
funcName: 'get-random-bytes',
|
|
2463
|
+
paramCount: 0,
|
|
2464
|
+
async: false,
|
|
2465
|
+
postReturn: false
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
function trampoline19(arg0) {
|
|
2471
|
+
_debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"] [Instruction::CallInterface] (async? sync, @ enter)');
|
|
2472
|
+
const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-directories');
|
|
2473
|
+
const ret = getDirectories();
|
|
2474
|
+
_debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"] [Instruction::CallInterface] (sync, @ post-call)');
|
|
2475
|
+
endCurrentTask(0);
|
|
2476
|
+
var vec3 = ret;
|
|
2477
|
+
var len3 = vec3.length;
|
|
2478
|
+
var result3 = realloc0(0, 0, 4, len3 * 12);
|
|
2479
|
+
for (let i = 0; i < vec3.length; i++) {
|
|
2480
|
+
const e = vec3[i];
|
|
2481
|
+
const base = result3 + i * 12;var [tuple0_0, tuple0_1] = e;
|
|
2482
|
+
if (!(tuple0_0 instanceof Descriptor)) {
|
|
2483
|
+
throw new TypeError('Resource error: Not a valid "Descriptor" resource.');
|
|
2484
|
+
}
|
|
2485
|
+
var handle1 = tuple0_0[symbolRscHandle];
|
|
2486
|
+
if (!handle1) {
|
|
2487
|
+
const rep = tuple0_0[symbolRscRep] || ++captureCnt3;
|
|
2488
|
+
captureTable3.set(rep, tuple0_0);
|
|
2489
|
+
handle1 = rscTableCreateOwn(handleTable3, rep);
|
|
2490
|
+
}
|
|
2491
|
+
dataView(memory0).setInt32(base + 0, handle1, true);
|
|
2492
|
+
var ptr2 = utf8Encode(tuple0_1, realloc0, memory0);
|
|
2493
|
+
var len2 = utf8EncodedLen;
|
|
2494
|
+
dataView(memory0).setUint32(base + 8, len2, true);
|
|
2495
|
+
dataView(memory0).setUint32(base + 4, ptr2, true);
|
|
2496
|
+
}
|
|
2497
|
+
dataView(memory0).setUint32(arg0 + 4, len3, true);
|
|
2498
|
+
dataView(memory0).setUint32(arg0 + 0, result3, true);
|
|
2499
|
+
_debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"][Instruction::Return]', {
|
|
2500
|
+
funcName: 'get-directories',
|
|
2501
|
+
paramCount: 0,
|
|
2502
|
+
async: false,
|
|
2503
|
+
postReturn: false
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
let exports3;
|
|
2508
|
+
let postReturn0;
|
|
2509
|
+
let postReturn1;
|
|
2510
|
+
let realloc1;
|
|
2511
|
+
let postReturn2;
|
|
2512
|
+
function trampoline0(handle) {
|
|
2513
|
+
const handleEntry = rscTableRemove(handleTable3, handle);
|
|
2514
|
+
if (handleEntry.own) {
|
|
2515
|
+
|
|
2516
|
+
const rsc = captureTable3.get(handleEntry.rep);
|
|
2517
|
+
if (rsc) {
|
|
2518
|
+
if (rsc[symbolDispose]) rsc[symbolDispose]();
|
|
2519
|
+
captureTable3.delete(handleEntry.rep);
|
|
2520
|
+
} else if (Descriptor[symbolCabiDispose]) {
|
|
2521
|
+
Descriptor[symbolCabiDispose](handleEntry.rep);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
function trampoline1(handle) {
|
|
2526
|
+
const handleEntry = rscTableRemove(handleTable1, handle);
|
|
2527
|
+
if (handleEntry.own) {
|
|
2528
|
+
|
|
2529
|
+
const rsc = captureTable1.get(handleEntry.rep);
|
|
2530
|
+
if (rsc) {
|
|
2531
|
+
if (rsc[symbolDispose]) rsc[symbolDispose]();
|
|
2532
|
+
captureTable1.delete(handleEntry.rep);
|
|
2533
|
+
} else if (OutputStream[symbolCabiDispose]) {
|
|
2534
|
+
OutputStream[symbolCabiDispose](handleEntry.rep);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function trampoline2(handle) {
|
|
2539
|
+
const handleEntry = rscTableRemove(handleTable0, handle);
|
|
2540
|
+
if (handleEntry.own) {
|
|
2541
|
+
|
|
2542
|
+
const rsc = captureTable0.get(handleEntry.rep);
|
|
2543
|
+
if (rsc) {
|
|
2544
|
+
if (rsc[symbolDispose]) rsc[symbolDispose]();
|
|
2545
|
+
captureTable0.delete(handleEntry.rep);
|
|
2546
|
+
} else if (Error$1[symbolCabiDispose]) {
|
|
2547
|
+
Error$1[symbolCabiDispose](handleEntry.rep);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
function trampoline3(handle) {
|
|
2552
|
+
const handleEntry = rscTableRemove(handleTable2, handle);
|
|
2553
|
+
if (handleEntry.own) {
|
|
2554
|
+
|
|
2555
|
+
const rsc = captureTable2.get(handleEntry.rep);
|
|
2556
|
+
if (rsc) {
|
|
2557
|
+
if (rsc[symbolDispose]) rsc[symbolDispose]();
|
|
2558
|
+
captureTable2.delete(handleEntry.rep);
|
|
2559
|
+
} else if (InputStream[symbolCabiDispose]) {
|
|
2560
|
+
InputStream[symbolCabiDispose](handleEntry.rep);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
Promise.all([module0, module1, module2, module3]).catch(() => {});
|
|
2565
|
+
({ exports: exports0 } = yield instantiateCore(yield module2));
|
|
2566
|
+
({ exports: exports1 } = yield instantiateCore(yield module0, {
|
|
2567
|
+
wasi_snapshot_preview1: {
|
|
2568
|
+
environ_get: exports0['2'],
|
|
2569
|
+
environ_sizes_get: exports0['3'],
|
|
2570
|
+
fd_write: exports0['1'],
|
|
2571
|
+
proc_exit: exports0['4'],
|
|
2572
|
+
random_get: exports0['0'],
|
|
2573
|
+
},
|
|
2574
|
+
}));
|
|
2575
|
+
({ exports: exports2 } = yield instantiateCore(yield module1, {
|
|
2576
|
+
__main_module__: {
|
|
2577
|
+
cabi_realloc: exports1.cabi_realloc,
|
|
2578
|
+
},
|
|
2579
|
+
env: {
|
|
2580
|
+
memory: exports1.memory,
|
|
2581
|
+
},
|
|
2582
|
+
'wasi:cli/environment@0.2.3': {
|
|
2583
|
+
'get-environment': exports0['5'],
|
|
2584
|
+
},
|
|
2585
|
+
'wasi:cli/exit@0.2.3': {
|
|
2586
|
+
exit: trampoline7,
|
|
2587
|
+
},
|
|
2588
|
+
'wasi:cli/stderr@0.2.3': {
|
|
2589
|
+
'get-stderr': trampoline4,
|
|
2590
|
+
},
|
|
2591
|
+
'wasi:cli/stdin@0.2.3': {
|
|
2592
|
+
'get-stdin': trampoline5,
|
|
2593
|
+
},
|
|
2594
|
+
'wasi:cli/stdout@0.2.3': {
|
|
2595
|
+
'get-stdout': trampoline6,
|
|
2596
|
+
},
|
|
2597
|
+
'wasi:filesystem/preopens@0.2.2': {
|
|
2598
|
+
'get-directories': exports0['16'],
|
|
2599
|
+
},
|
|
2600
|
+
'wasi:filesystem/types@0.2.3': {
|
|
2601
|
+
'[method]descriptor.append-via-stream': exports0['8'],
|
|
2602
|
+
'[method]descriptor.get-type': exports0['9'],
|
|
2603
|
+
'[method]descriptor.stat': exports0['10'],
|
|
2604
|
+
'[method]descriptor.write-via-stream': exports0['7'],
|
|
2605
|
+
'[resource-drop]descriptor': trampoline0,
|
|
2606
|
+
'filesystem-error-code': exports0['6'],
|
|
2607
|
+
},
|
|
2608
|
+
'wasi:io/error@0.2.3': {
|
|
2609
|
+
'[resource-drop]error': trampoline2,
|
|
2610
|
+
},
|
|
2611
|
+
'wasi:io/streams@0.2.3': {
|
|
2612
|
+
'[method]output-stream.blocking-flush': exports0['13'],
|
|
2613
|
+
'[method]output-stream.blocking-write-and-flush': exports0['14'],
|
|
2614
|
+
'[method]output-stream.check-write': exports0['11'],
|
|
2615
|
+
'[method]output-stream.write': exports0['12'],
|
|
2616
|
+
'[resource-drop]input-stream': trampoline3,
|
|
2617
|
+
'[resource-drop]output-stream': trampoline1,
|
|
2618
|
+
},
|
|
2619
|
+
'wasi:random/random@0.2.3': {
|
|
2620
|
+
'get-random-bytes': exports0['15'],
|
|
2621
|
+
},
|
|
2622
|
+
}));
|
|
2623
|
+
memory0 = exports1.memory;
|
|
2624
|
+
realloc0 = exports2.cabi_import_realloc;
|
|
2625
|
+
({ exports: exports3 } = yield instantiateCore(yield module3, {
|
|
2626
|
+
'': {
|
|
2627
|
+
$imports: exports0.$imports,
|
|
2628
|
+
'0': exports2.random_get,
|
|
2629
|
+
'1': exports2.fd_write,
|
|
2630
|
+
'10': trampoline13,
|
|
2631
|
+
'11': trampoline14,
|
|
2632
|
+
'12': trampoline15,
|
|
2633
|
+
'13': trampoline16,
|
|
2634
|
+
'14': trampoline17,
|
|
2635
|
+
'15': trampoline18,
|
|
2636
|
+
'16': trampoline19,
|
|
2637
|
+
'2': exports2.environ_get,
|
|
2638
|
+
'3': exports2.environ_sizes_get,
|
|
2639
|
+
'4': exports2.proc_exit,
|
|
2640
|
+
'5': trampoline8,
|
|
2641
|
+
'6': trampoline9,
|
|
2642
|
+
'7': trampoline10,
|
|
2643
|
+
'8': trampoline11,
|
|
2644
|
+
'9': trampoline12,
|
|
2645
|
+
},
|
|
2646
|
+
}));
|
|
2647
|
+
postReturn0 = exports1['cabi_post_arborium:grammar/plugin@0.1.0#language-id'];
|
|
2648
|
+
postReturn1 = exports1['cabi_post_arborium:grammar/plugin@0.1.0#injection-languages'];
|
|
2649
|
+
realloc1 = exports1.cabi_realloc;
|
|
2650
|
+
postReturn2 = exports1['cabi_post_arborium:grammar/plugin@0.1.0#parse'];
|
|
2651
|
+
let plugin010LanguageId;
|
|
2652
|
+
|
|
2653
|
+
function languageId() {
|
|
2654
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="language-id"][Instruction::CallWasm] enter', {
|
|
2655
|
+
funcName: 'language-id',
|
|
2656
|
+
paramCount: 0,
|
|
2657
|
+
async: false,
|
|
2658
|
+
postReturn: true,
|
|
2659
|
+
});
|
|
2660
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010LanguageId');
|
|
2661
|
+
const ret = plugin010LanguageId();
|
|
2662
|
+
endCurrentTask(0);
|
|
2663
|
+
var ptr0 = dataView(memory0).getUint32(ret + 0, true);
|
|
2664
|
+
var len0 = dataView(memory0).getUint32(ret + 4, true);
|
|
2665
|
+
var result0 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr0, len0));
|
|
2666
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="language-id"][Instruction::Return]', {
|
|
2667
|
+
funcName: 'language-id',
|
|
2668
|
+
paramCount: 1,
|
|
2669
|
+
async: false,
|
|
2670
|
+
postReturn: true
|
|
2671
|
+
});
|
|
2672
|
+
const retCopy = result0;
|
|
2673
|
+
|
|
2674
|
+
let cstate = getOrCreateAsyncState(0);
|
|
2675
|
+
cstate.mayLeave = false;
|
|
2676
|
+
postReturn0(ret);
|
|
2677
|
+
cstate.mayLeave = true;
|
|
2678
|
+
return retCopy;
|
|
2679
|
+
|
|
2680
|
+
}
|
|
2681
|
+
let plugin010InjectionLanguages;
|
|
2682
|
+
|
|
2683
|
+
function injectionLanguages() {
|
|
2684
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="injection-languages"][Instruction::CallWasm] enter', {
|
|
2685
|
+
funcName: 'injection-languages',
|
|
2686
|
+
paramCount: 0,
|
|
2687
|
+
async: false,
|
|
2688
|
+
postReturn: true,
|
|
2689
|
+
});
|
|
2690
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010InjectionLanguages');
|
|
2691
|
+
const ret = plugin010InjectionLanguages();
|
|
2692
|
+
endCurrentTask(0);
|
|
2693
|
+
var len1 = dataView(memory0).getUint32(ret + 4, true);
|
|
2694
|
+
var base1 = dataView(memory0).getUint32(ret + 0, true);
|
|
2695
|
+
var result1 = [];
|
|
2696
|
+
for (let i = 0; i < len1; i++) {
|
|
2697
|
+
const base = base1 + i * 8;
|
|
2698
|
+
var ptr0 = dataView(memory0).getUint32(base + 0, true);
|
|
2699
|
+
var len0 = dataView(memory0).getUint32(base + 4, true);
|
|
2700
|
+
var result0 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr0, len0));
|
|
2701
|
+
result1.push(result0);
|
|
2702
|
+
}
|
|
2703
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="injection-languages"][Instruction::Return]', {
|
|
2704
|
+
funcName: 'injection-languages',
|
|
2705
|
+
paramCount: 1,
|
|
2706
|
+
async: false,
|
|
2707
|
+
postReturn: true
|
|
2708
|
+
});
|
|
2709
|
+
const retCopy = result1;
|
|
2710
|
+
|
|
2711
|
+
let cstate = getOrCreateAsyncState(0);
|
|
2712
|
+
cstate.mayLeave = false;
|
|
2713
|
+
postReturn1(ret);
|
|
2714
|
+
cstate.mayLeave = true;
|
|
2715
|
+
return retCopy;
|
|
2716
|
+
|
|
2717
|
+
}
|
|
2718
|
+
let plugin010CreateSession;
|
|
2719
|
+
|
|
2720
|
+
function createSession() {
|
|
2721
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="create-session"][Instruction::CallWasm] enter', {
|
|
2722
|
+
funcName: 'create-session',
|
|
2723
|
+
paramCount: 0,
|
|
2724
|
+
async: false,
|
|
2725
|
+
postReturn: false,
|
|
2726
|
+
});
|
|
2727
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010CreateSession');
|
|
2728
|
+
const ret = plugin010CreateSession();
|
|
2729
|
+
endCurrentTask(0);
|
|
2730
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="create-session"][Instruction::Return]', {
|
|
2731
|
+
funcName: 'create-session',
|
|
2732
|
+
paramCount: 1,
|
|
2733
|
+
async: false,
|
|
2734
|
+
postReturn: false
|
|
2735
|
+
});
|
|
2736
|
+
return ret >>> 0;
|
|
2737
|
+
}
|
|
2738
|
+
let plugin010FreeSession;
|
|
2739
|
+
|
|
2740
|
+
function freeSession(arg0) {
|
|
2741
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="free-session"][Instruction::CallWasm] enter', {
|
|
2742
|
+
funcName: 'free-session',
|
|
2743
|
+
paramCount: 1,
|
|
2744
|
+
async: false,
|
|
2745
|
+
postReturn: false,
|
|
2746
|
+
});
|
|
2747
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010FreeSession');
|
|
2748
|
+
plugin010FreeSession(toUint32(arg0));
|
|
2749
|
+
endCurrentTask(0);
|
|
2750
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="free-session"][Instruction::Return]', {
|
|
2751
|
+
funcName: 'free-session',
|
|
2752
|
+
paramCount: 0,
|
|
2753
|
+
async: false,
|
|
2754
|
+
postReturn: false
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
let plugin010SetText;
|
|
2758
|
+
|
|
2759
|
+
function setText(arg0, arg1) {
|
|
2760
|
+
var ptr0 = utf8Encode(arg1, realloc1, memory0);
|
|
2761
|
+
var len0 = utf8EncodedLen;
|
|
2762
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="set-text"][Instruction::CallWasm] enter', {
|
|
2763
|
+
funcName: 'set-text',
|
|
2764
|
+
paramCount: 3,
|
|
2765
|
+
async: false,
|
|
2766
|
+
postReturn: false,
|
|
2767
|
+
});
|
|
2768
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010SetText');
|
|
2769
|
+
plugin010SetText(toUint32(arg0), ptr0, len0);
|
|
2770
|
+
endCurrentTask(0);
|
|
2771
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="set-text"][Instruction::Return]', {
|
|
2772
|
+
funcName: 'set-text',
|
|
2773
|
+
paramCount: 0,
|
|
2774
|
+
async: false,
|
|
2775
|
+
postReturn: false
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
let plugin010ApplyEdit;
|
|
2779
|
+
|
|
2780
|
+
function applyEdit(arg0, arg1, arg2) {
|
|
2781
|
+
var ptr0 = utf8Encode(arg1, realloc1, memory0);
|
|
2782
|
+
var len0 = utf8EncodedLen;
|
|
2783
|
+
var {startByte: v1_0, oldEndByte: v1_1, newEndByte: v1_2, startRow: v1_3, startCol: v1_4, oldEndRow: v1_5, oldEndCol: v1_6, newEndRow: v1_7, newEndCol: v1_8 } = arg2;
|
|
2784
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="apply-edit"][Instruction::CallWasm] enter', {
|
|
2785
|
+
funcName: 'apply-edit',
|
|
2786
|
+
paramCount: 12,
|
|
2787
|
+
async: false,
|
|
2788
|
+
postReturn: false,
|
|
2789
|
+
});
|
|
2790
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010ApplyEdit');
|
|
2791
|
+
plugin010ApplyEdit(toUint32(arg0), ptr0, len0, toUint32(v1_0), toUint32(v1_1), toUint32(v1_2), toUint32(v1_3), toUint32(v1_4), toUint32(v1_5), toUint32(v1_6), toUint32(v1_7), toUint32(v1_8));
|
|
2792
|
+
endCurrentTask(0);
|
|
2793
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="apply-edit"][Instruction::Return]', {
|
|
2794
|
+
funcName: 'apply-edit',
|
|
2795
|
+
paramCount: 0,
|
|
2796
|
+
async: false,
|
|
2797
|
+
postReturn: false
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
let plugin010Parse;
|
|
2801
|
+
|
|
2802
|
+
function parse(arg0) {
|
|
2803
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="parse"][Instruction::CallWasm] enter', {
|
|
2804
|
+
funcName: 'parse',
|
|
2805
|
+
paramCount: 1,
|
|
2806
|
+
async: false,
|
|
2807
|
+
postReturn: true,
|
|
2808
|
+
});
|
|
2809
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010Parse');
|
|
2810
|
+
const ret = plugin010Parse(toUint32(arg0));
|
|
2811
|
+
endCurrentTask(0);
|
|
2812
|
+
let variant6;
|
|
2813
|
+
switch (dataView(memory0).getUint8(ret + 0, true)) {
|
|
2814
|
+
case 0: {
|
|
2815
|
+
var len1 = dataView(memory0).getUint32(ret + 8, true);
|
|
2816
|
+
var base1 = dataView(memory0).getUint32(ret + 4, true);
|
|
2817
|
+
var result1 = [];
|
|
2818
|
+
for (let i = 0; i < len1; i++) {
|
|
2819
|
+
const base = base1 + i * 16;
|
|
2820
|
+
var ptr0 = dataView(memory0).getUint32(base + 8, true);
|
|
2821
|
+
var len0 = dataView(memory0).getUint32(base + 12, true);
|
|
2822
|
+
var result0 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr0, len0));
|
|
2823
|
+
result1.push({
|
|
2824
|
+
start: dataView(memory0).getInt32(base + 0, true) >>> 0,
|
|
2825
|
+
end: dataView(memory0).getInt32(base + 4, true) >>> 0,
|
|
2826
|
+
capture: result0,
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
2829
|
+
var len4 = dataView(memory0).getUint32(ret + 16, true);
|
|
2830
|
+
var base4 = dataView(memory0).getUint32(ret + 12, true);
|
|
2831
|
+
var result4 = [];
|
|
2832
|
+
for (let i = 0; i < len4; i++) {
|
|
2833
|
+
const base = base4 + i * 20;
|
|
2834
|
+
var ptr2 = dataView(memory0).getUint32(base + 8, true);
|
|
2835
|
+
var len2 = dataView(memory0).getUint32(base + 12, true);
|
|
2836
|
+
var result2 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr2, len2));
|
|
2837
|
+
var bool3 = dataView(memory0).getUint8(base + 16, true);
|
|
2838
|
+
result4.push({
|
|
2839
|
+
start: dataView(memory0).getInt32(base + 0, true) >>> 0,
|
|
2840
|
+
end: dataView(memory0).getInt32(base + 4, true) >>> 0,
|
|
2841
|
+
language: result2,
|
|
2842
|
+
includeChildren: bool3 == 0 ? false : (bool3 == 1 ? true : throwInvalidBool()),
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
variant6= {
|
|
2846
|
+
tag: 'ok',
|
|
2847
|
+
val: {
|
|
2848
|
+
spans: result1,
|
|
2849
|
+
injections: result4,
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
break;
|
|
2853
|
+
}
|
|
2854
|
+
case 1: {
|
|
2855
|
+
var ptr5 = dataView(memory0).getUint32(ret + 4, true);
|
|
2856
|
+
var len5 = dataView(memory0).getUint32(ret + 8, true);
|
|
2857
|
+
var result5 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr5, len5));
|
|
2858
|
+
variant6= {
|
|
2859
|
+
tag: 'err',
|
|
2860
|
+
val: {
|
|
2861
|
+
message: result5,
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
break;
|
|
2865
|
+
}
|
|
2866
|
+
default: {
|
|
2867
|
+
throw new TypeError('invalid variant discriminant for expected');
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="parse"][Instruction::Return]', {
|
|
2871
|
+
funcName: 'parse',
|
|
2872
|
+
paramCount: 1,
|
|
2873
|
+
async: false,
|
|
2874
|
+
postReturn: true
|
|
2875
|
+
});
|
|
2876
|
+
const retCopy = variant6;
|
|
2877
|
+
|
|
2878
|
+
let cstate = getOrCreateAsyncState(0);
|
|
2879
|
+
cstate.mayLeave = false;
|
|
2880
|
+
postReturn2(ret);
|
|
2881
|
+
cstate.mayLeave = true;
|
|
2882
|
+
|
|
2883
|
+
|
|
2884
|
+
|
|
2885
|
+
if (typeof retCopy === 'object' && retCopy.tag === 'err') {
|
|
2886
|
+
throw new ComponentError(retCopy.val);
|
|
2887
|
+
}
|
|
2888
|
+
return retCopy.val;
|
|
2889
|
+
|
|
2890
|
+
}
|
|
2891
|
+
let plugin010Cancel;
|
|
2892
|
+
|
|
2893
|
+
function cancel(arg0) {
|
|
2894
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="cancel"][Instruction::CallWasm] enter', {
|
|
2895
|
+
funcName: 'cancel',
|
|
2896
|
+
paramCount: 1,
|
|
2897
|
+
async: false,
|
|
2898
|
+
postReturn: false,
|
|
2899
|
+
});
|
|
2900
|
+
const _wasm_call_currentTaskID = startCurrentTask(0, false, 'plugin010Cancel');
|
|
2901
|
+
plugin010Cancel(toUint32(arg0));
|
|
2902
|
+
endCurrentTask(0);
|
|
2903
|
+
_debugLog('[iface="arborium:grammar/plugin@0.1.0", function="cancel"][Instruction::Return]', {
|
|
2904
|
+
funcName: 'cancel',
|
|
2905
|
+
paramCount: 0,
|
|
2906
|
+
async: false,
|
|
2907
|
+
postReturn: false
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
plugin010LanguageId = exports1['arborium:grammar/plugin@0.1.0#language-id'];
|
|
2911
|
+
plugin010InjectionLanguages = exports1['arborium:grammar/plugin@0.1.0#injection-languages'];
|
|
2912
|
+
plugin010CreateSession = exports1['arborium:grammar/plugin@0.1.0#create-session'];
|
|
2913
|
+
plugin010FreeSession = exports1['arborium:grammar/plugin@0.1.0#free-session'];
|
|
2914
|
+
plugin010SetText = exports1['arborium:grammar/plugin@0.1.0#set-text'];
|
|
2915
|
+
plugin010ApplyEdit = exports1['arborium:grammar/plugin@0.1.0#apply-edit'];
|
|
2916
|
+
plugin010Parse = exports1['arborium:grammar/plugin@0.1.0#parse'];
|
|
2917
|
+
plugin010Cancel = exports1['arborium:grammar/plugin@0.1.0#cancel'];
|
|
2918
|
+
const plugin010 = {
|
|
2919
|
+
applyEdit: applyEdit,
|
|
2920
|
+
cancel: cancel,
|
|
2921
|
+
createSession: createSession,
|
|
2922
|
+
freeSession: freeSession,
|
|
2923
|
+
injectionLanguages: injectionLanguages,
|
|
2924
|
+
languageId: languageId,
|
|
2925
|
+
parse: parse,
|
|
2926
|
+
setText: setText,
|
|
2927
|
+
|
|
2928
|
+
};
|
|
2929
|
+
|
|
2930
|
+
return { plugin: plugin010, 'arborium:grammar/plugin@0.1.0': plugin010, };
|
|
2931
|
+
})();
|
|
2932
|
+
let promise, resolve, reject;
|
|
2933
|
+
function runNext (value) {
|
|
2934
|
+
try {
|
|
2935
|
+
let done;
|
|
2936
|
+
do {
|
|
2937
|
+
({ value, done } = gen.next(value));
|
|
2938
|
+
} while (!(value instanceof Promise) && !done);
|
|
2939
|
+
if (done) {
|
|
2940
|
+
if (resolve) return resolve(value);
|
|
2941
|
+
else return value;
|
|
2942
|
+
}
|
|
2943
|
+
if (!promise) promise = new Promise((_resolve, _reject) => (resolve = _resolve, reject = _reject));
|
|
2944
|
+
value.then(nextVal => done ? resolve() : runNext(nextVal), reject);
|
|
2945
|
+
}
|
|
2946
|
+
catch (e) {
|
|
2947
|
+
if (reject) reject(e);
|
|
2948
|
+
else throw e;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
const maybeSyncReturn = runNext(null);
|
|
2952
|
+
return promise || maybeSyncReturn;
|
|
2953
|
+
}
|