@bytecodealliance/jco 1.13.0 → 1.13.1-rc.4

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/obj/wasm-tools.js CHANGED
@@ -75,10 +75,580 @@ function rscTableRemove (table, handle) {
75
75
 
76
76
  let curResourceBorrows = [];
77
77
 
78
+ let NEXT_TASK_ID = 0n;
79
+ function startCurrentTask(componentIdx, isAsync, entryFnName) {
80
+ _debugLog('[startCurrentTask()] args', { componentIdx, isAsync });
81
+ if (componentIdx === undefined || componentIdx === null) {
82
+ throw new Error('missing/invalid component instance index while starting task');
83
+ }
84
+ const tasks = ASYNC_TASKS_BY_COMPONENT_IDX.get(componentIdx);
85
+
86
+ const nextId = ++NEXT_TASK_ID;
87
+ const newTask = new AsyncTask({ id: nextId, componentIdx, isAsync, entryFnName });
88
+ const newTaskMeta = { id: nextId, componentIdx, task: newTask };
89
+
90
+ ASYNC_CURRENT_TASK_ID = nextId;
91
+ ASYNC_CURRENT_COMPONENT_IDX = componentIdx;
92
+
93
+ if (!tasks) {
94
+ ASYNC_TASKS_BY_COMPONENT_IDX.set(componentIdx, [newTaskMeta]);
95
+ return nextId;
96
+ } else {
97
+ tasks.push(newTaskMeta);
98
+ }
99
+
100
+ return nextId;
101
+ }
102
+
103
+ function endCurrentTask(componentIdx, taskId) {
104
+ _debugLog('[endCurrentTask()] args', { componentIdx });
105
+ if (componentIdx === undefined || componentIdx === null) {
106
+ throw new Error('missing/invalid component instance index while ending current task');
107
+ }
108
+ const tasks = ASYNC_TASKS_BY_COMPONENT_IDX.get(componentIdx);
109
+ if (!tasks || !Array.isArray(tasks)) {
110
+ throw new Error('missing/invalid tasks for component instance while ending task');
111
+ }
112
+ if (tasks.length == 0) {
113
+ throw new Error('no current task(s) for component instance while ending task');
114
+ }
115
+
116
+ if (taskId) {
117
+ const last = tasks[tasks.length - 1];
118
+ if (last.id !== taskId) {
119
+ throw new Error('current task does not match expected task ID');
120
+ }
121
+ }
122
+
123
+ ASYNC_CURRENT_TASK_ID = null;
124
+ ASYNC_CURRENT_COMPONENT_IDX = null;
125
+
126
+ return tasks.pop();
127
+ }
128
+ const ASYNC_TASKS_BY_COMPONENT_IDX = new Map();
129
+ let ASYNC_CURRENT_TASK_ID = null;
130
+ let ASYNC_CURRENT_COMPONENT_IDX = null;
131
+
132
+ class AsyncTask {
133
+ static State = {
134
+ INITIAL: 'initial',
135
+ CANCELLED: 'cancelled',
136
+ CANCEL_PENDING: 'cancel-pending',
137
+ CANCEL_DELIVERED: 'cancel-delivered',
138
+ RESOLVED: 'resolved',
139
+ }
140
+
141
+ static BlockResult = {
142
+ CANCELLED: 'block.cancelled',
143
+ NOT_CANCELLED: 'block.not-cancelled',
144
+ }
145
+
146
+ #id;
147
+ #componentIdx;
148
+ #state;
149
+ #isAsync;
150
+ #onResolve = null;
151
+ #returnedResults = null;
152
+ #entryFnName = null;
153
+
154
+ cancelled = false;
155
+ requested = false;
156
+ alwaysTaskReturn = false;
157
+
158
+ returnCalls = 0;
159
+ storage = [0, 0];
160
+ borrowedHandles = {};
161
+
162
+ awaitableResume = null;
163
+ awaitableCancel = null;
164
+
165
+ constructor(opts) {
166
+ if (opts?.id === undefined) { throw new TypeError('missing task ID during task creation'); }
167
+ this.#id = opts.id;
168
+ if (opts?.componentIdx === undefined) {
169
+ throw new TypeError('missing component id during task creation');
170
+ }
171
+ this.#componentIdx = opts.componentIdx;
172
+ this.#state = AsyncTask.State.INITIAL;
173
+ this.#isAsync = opts?.isAsync ?? false;
174
+ this.#entryFnName = opts.entryFnName;
175
+
176
+ this.#onResolve = (results) => {
177
+ this.#returnedResults = results;
178
+ }
179
+ }
180
+
181
+ taskState() { return this.#state.slice(); }
182
+ id() { return this.#id; }
183
+ componentIdx() { return this.#componentIdx; }
184
+ isAsync() { return this.#isAsync; }
185
+ getEntryFnName() { return this.#entryFnName; }
186
+
187
+ takeResults() {
188
+ const results = this.#returnedResults;
189
+ this.#returnedResults = null;
190
+ return results;
191
+ }
192
+
193
+ mayEnter(task) {
194
+ const cstate = getOrCreateAsyncState(this.#componentIdx);
195
+ if (!cstate.backpressure) {
196
+ _debugLog('[AsyncTask#mayEnter()] disallowed due to backpressure', { taskID: this.#id });
197
+ return false;
198
+ }
199
+ if (!cstate.callingSyncImport()) {
200
+ _debugLog('[AsyncTask#mayEnter()] disallowed due to sync import call', { taskID: this.#id });
201
+ return false;
202
+ }
203
+ const callingSyncExportWithSyncPending = cstate.callingSyncExport && !task.isAsync;
204
+ if (!callingSyncExportWithSyncPending) {
205
+ _debugLog('[AsyncTask#mayEnter()] disallowed due to sync export w/ sync pending', { taskID: this.#id });
206
+ return false;
207
+ }
208
+ return true;
209
+ }
210
+
211
+ async enter() {
212
+ _debugLog('[AsyncTask#enter()] args', { taskID: this.#id });
213
+
214
+ // TODO: assert scheduler locked
215
+ // TODO: trap if on the stack
216
+
217
+ const cstate = getOrCreateAsyncState(this.#componentIdx);
218
+
219
+ let mayNotEnter = !this.mayEnter(this);
220
+ const componentHasPendingTasks = cstate.pendingTasks > 0;
221
+ if (mayNotEnter || componentHasPendingTasks) {
222
+
223
+ throw new Error('in enter()'); // TODO: remove
224
+ cstate.pendingTasks.set(this.#id, new Awaitable(new Promise()));
225
+
226
+ const blockResult = await this.onBlock(awaitable);
227
+ if (blockResult) {
228
+ // TODO: find this pending task in the component
229
+ const pendingTask = cstate.pendingTasks.get(this.#id);
230
+ if (!pendingTask) {
231
+ throw new Error('pending task [' + this.#id + '] not found for component instance');
232
+ }
233
+ cstate.pendingTasks.remove(this.#id);
234
+ this.#onResolve([]);
235
+ return false;
236
+ }
237
+
238
+ mayNotEnter = !this.mayEnter(this);
239
+ if (!mayNotEnter || !cstate.startPendingTask) {
240
+ throw new Error('invalid component entrance/pending task resolution');
241
+ }
242
+ cstate.startPendingTask = false;
243
+ }
244
+
245
+ if (!this.isAsync) { cstate.callingSyncExport = true; }
246
+
247
+ return true;
248
+ }
249
+
250
+ async waitForEvent(opts) {
251
+ const { waitableSetRep, isAsync } = opts;
252
+ _debugLog('[AsyncTask#waitForEvent()] args', { taskID: this.#id, waitableSetRep, isAsync });
253
+
254
+ if (this.#isAsync !== isAsync) {
255
+ throw new Error('async waitForEvent called on non-async task');
256
+ }
257
+
258
+ if (this.status === AsyncTask.State.CANCEL_PENDING) {
259
+ this.#state = AsyncTask.State.CANCEL_DELIVERED;
260
+ return {
261
+ code: ASYNC_EVENT_CODE.TASK_CANCELLED,
262
+ something: 0,
263
+ something: 0,
264
+ };
265
+ }
266
+
267
+ const state = getOrCreateAsyncState(this.#componentIdx);
268
+ const waitableSet = state.waitableSets.get(waitableSetRep);
269
+ if (!waitableSet) { throw new Error('missing/invalid waitable set'); }
270
+
271
+ waitableSet.numWaiting += 1;
272
+ let event = null;
273
+
274
+ while (event == null) {
275
+ const awaitable = new Awaitable(waitableSet.getPendingEvent());
276
+ const waited = await this.blockOn({ awaitable, isAsync, isCancellable: true });
277
+ if (waited) {
278
+ if (this.#state !== AsyncTask.State.INITIAL) {
279
+ throw new Error('task should be in initial state found [' + this.#state + ']');
280
+ }
281
+ this.#state = AsyncTask.State.CANCELLED;
282
+ return {
283
+ code: ASYNC_EVENT_CODE.TASK_CANCELLED,
284
+ something: 0,
285
+ something: 0,
286
+ };
287
+ }
288
+
289
+ event = waitableSet.poll();
290
+ }
291
+
292
+ waitableSet.numWaiting -= 1;
293
+ return event;
294
+ }
295
+
296
+ waitForEventSync(opts) {
297
+ throw new Error('AsyncTask#yieldSync() not implemented')
298
+ }
299
+
300
+ async pollForEvent(opts) {
301
+ const { waitableSetRep, isAsync } = opts;
302
+ _debugLog('[AsyncTask#pollForEvent()] args', { taskID: this.#id, waitableSetRep, isAsync });
303
+
304
+ if (this.#isAsync !== isAsync) {
305
+ throw new Error('async pollForEvent called on non-async task');
306
+ }
307
+
308
+ throw new Error('AsyncTask#pollForEvent() not implemented');
309
+ }
310
+
311
+ pollForEventSync(opts) {
312
+ throw new Error('AsyncTask#yieldSync() not implemented')
313
+ }
314
+
315
+ async blockOn(opts) {
316
+ const { awaitable, isCancellable, forCallback } = opts;
317
+ _debugLog('[AsyncTask#blockOn()] args', { taskID: this.#id, awaitable, isCancellable, forCallback });
318
+
319
+ if (awaitable.resolved() && !ASYNC_DETERMINISM && _coinFlip()) {
320
+ return AsyncTask.BlockResult.NOT_CANCELLED;
321
+ }
322
+
323
+ const cstate = getOrCreateAsyncState(this.#componentIdx);
324
+ if (forCallback) { cstate.exclusiveRelease(); }
325
+
326
+ let cancelled = await this.onBlock(awaitable);
327
+ if (cancelled === AsyncTask.BlockResult.CANCELLED && !isCancellable) {
328
+ const secondCancel = await this.onBlock(awaitable);
329
+ if (secondCancel !== AsyncTask.BlockResult.NOT_CANCELLED) {
330
+ throw new Error('uncancellable task was canceled despite second onBlock()');
331
+ }
332
+ }
333
+
334
+ if (forCallback) {
335
+ const acquired = new Awaitable(cstate.exclusiveLock());
336
+ cancelled = await this.onBlock(acquired);
337
+ if (cancelled === AsyncTask.BlockResult.CANCELLED) {
338
+ const secondCancel = await this.onBlock(acquired);
339
+ if (secondCancel !== AsyncTask.BlockResult.NOT_CANCELLED) {
340
+ throw new Error('uncancellable callback task was canceled despite second onBlock()');
341
+ }
342
+ }
343
+ }
344
+
345
+ if (cancelled === AsyncTask.BlockResult.CANCELLED) {
346
+ if (this.#state !== AsyncTask.State.INITIAL) {
347
+ throw new Error('cancelled task is not at initial state');
348
+ }
349
+ if (isCancellable) {
350
+ this.#state = AsyncTask.State.CANCELLED;
351
+ return AsyncTask.BlockResult.CANCELLED;
352
+ } else {
353
+ this.#state = AsyncTask.State.CANCEL_PENDING;
354
+ return AsyncTask.BlockResult.NOT_CANCELLED;
355
+ }
356
+ }
357
+
358
+ return AsyncTask.BlockResult.NOT_CANCELLED;
359
+ }
360
+
361
+ async onBlock(awaitable) {
362
+ _debugLog('[AsyncTask#onBlock()] args', { taskID: this.#id, awaitable });
363
+ if (!(awaitable instanceof Awaitable)) {
364
+ throw new Error('invalid awaitable during onBlock');
365
+ }
366
+
367
+ // Build a promise that this task can await on which resolves when it is awoken
368
+ const { promise, resolve, reject } = Promise.withResolvers();
369
+ this.awaitableResume = () => {
370
+ _debugLog('[AsyncTask] resuming after onBlock', { taskID: this.#id });
371
+ resolve();
372
+ };
373
+ this.awaitableCancel = (err) => {
374
+ _debugLog('[AsyncTask] rejecting after onBlock', { taskID: this.#id, err });
375
+ reject(err);
376
+ };
377
+
378
+ // Park this task/execution to be handled later
379
+ const state = getOrCreateAsyncState(this.#componentIdx);
380
+ state.parkTaskOnAwaitable({ awaitable, task: this });
381
+
382
+ try {
383
+ await promise;
384
+ return AsyncTask.BlockResult.NOT_CANCELLED;
385
+ } catch (err) {
386
+ // rejection means task cancellation
387
+ return AsyncTask.BlockResult.CANCELLED;
388
+ }
389
+ }
390
+
391
+ // NOTE: this should likely be moved to a SubTask class
392
+ async asyncOnBlock(awaitable) {
393
+ _debugLog('[AsyncTask#asyncOnBlock()] args', { taskID: this.#id, awaitable });
394
+ if (!(awaitable instanceof Awaitable)) {
395
+ throw new Error('invalid awaitable during onBlock');
396
+ }
397
+ // TODO: watch for waitable AND cancellation
398
+ // TODO: if it WAS cancelled:
399
+ // - return true
400
+ // - only once per subtask
401
+ // - do not wait on the scheduler
402
+ // - control flow should go to the subtask (only once)
403
+ // - Once subtask blocks/resolves, reqlinquishControl() will tehn resolve request_cancel_end (without scheduler lock release)
404
+ // - control flow goes back to request_cancel
405
+ //
406
+ // Subtask cancellation should work similarly to an async import call -- runs sync up until
407
+ // the subtask blocks or resolves
408
+ //
409
+ throw new Error('AsyncTask#asyncOnBlock() not yet implemented');
410
+ }
411
+
412
+ async yield(opts) {
413
+ const { isCancellable, forCallback } = opts;
414
+ _debugLog('[AsyncTask#yield()] args', { taskID: this.#id, isCancellable, forCallback });
415
+
416
+ if (isCancellable && this.status === AsyncTask.State.CANCEL_PENDING) {
417
+ this.#state = AsyncTask.State.CANCELLED;
418
+ return {
419
+ code: ASYNC_EVENT_CODE.TASK_CANCELLED,
420
+ payload: [0, 0],
421
+ };
422
+ }
423
+
424
+ // TODO: Awaitables need to *always* trigger the parking mechanism when they're done...?
425
+ // TODO: Component async state should remember which awaitables are done and work to clear tasks waiting
426
+
427
+ const blockResult = await this.blockOn({
428
+ awaitable: new Awaitable(new Promise(resolve => setTimeout(resolve, 0))),
429
+ isCancellable,
430
+ forCallback,
431
+ });
432
+
433
+ if (blockResult === AsyncTask.BlockResult.CANCELLED) {
434
+ if (this.#state !== AsyncTask.State.INITIAL) {
435
+ throw new Error('task should be in initial state found [' + this.#state + ']');
436
+ }
437
+ this.#state = AsyncTask.State.CANCELLED;
438
+ return {
439
+ code: ASYNC_EVENT_CODE.TASK_CANCELLED,
440
+ payload: [0, 0],
441
+ };
442
+ }
443
+
444
+ return {
445
+ code: ASYNC_EVENT_CODE.NONE,
446
+ payload: [0, 0],
447
+ };
448
+ }
449
+
450
+ yieldSync(opts) {
451
+ throw new Error('AsyncTask#yieldSync() not implemented')
452
+ }
453
+
454
+ cancel() {
455
+ _debugLog('[AsyncTask#cancel()] args', { });
456
+ if (!this.taskState() !== AsyncTask.State.CANCEL_DELIVERED) {
457
+ throw new Error('invalid task state for cancellation');
458
+ }
459
+ if (this.borrowedHandles.length > 0) { throw new Error('task still has borrow handles'); }
460
+
461
+ this.#onResolve([]);
462
+ this.#state = AsyncTask.State.RESOLVED;
463
+ }
464
+
465
+ resolve(result) {
466
+ if (this.#state === AsyncTask.State.RESOLVED) {
467
+ throw new Error('task is already resolved');
468
+ }
469
+ if (this.borrowedHandles.length > 0) { throw new Error('task still has borrow handles'); }
470
+ this.#onResolve(result);
471
+ this.#state = AsyncTask.State.RESOLVED;
472
+ }
473
+
474
+ exit() {
475
+ // TODO: ensure there is only one task at a time (scheduler.lock() functionality)
476
+ if (this.#state !== AsyncTask.State.RESOLVED) {
477
+ throw new Error('task exited without resolution');
478
+ }
479
+ if (this.borrowedHandles > 0) {
480
+ throw new Error('task exited without clearing borrowed handles');
481
+ }
482
+
483
+ const state = getOrCreateAsyncState(this.#componentIdx);
484
+ if (!state) { throw new Error('missing async state for component [' + this.#componentIdx + ']'); }
485
+ if (!this.#isAsync && !state.inSyncExportCall) {
486
+ throw new Error('sync task must be run from components known to be in a sync export call');
487
+ }
488
+ state.inSyncExportCall = false;
489
+
490
+ this.startPendingTask();
491
+ }
492
+
493
+ startPendingTask(opts) {
494
+ // TODO: implement
495
+ }
496
+
497
+ }
498
+
499
+ function unpackCallbackResult(result) {
500
+ _debugLog('[unpackCallbackResult()] args', { result });
501
+ if (!(_typeCheckValidI32(result))) { throw new Error('invalid callback return value [' + result + '], not a valid i32'); }
502
+ const eventCode = result & 0xF;
503
+ if (eventCode < 0 || eventCode > 3) {
504
+ throw new Error('invalid async return value [' + eventCode + '], outside callback code range');
505
+ }
506
+ if (result < 0 || result >= 2**32) { throw new Error('invalid callback result'); }
507
+ // TODO: table max length check?
508
+ const waitableSetIdx = result >> 4;
509
+ return [eventCode, waitableSetIdx];
510
+ }
511
+ const ASYNC_STATE = new Map();
512
+
513
+ function getOrCreateAsyncState(componentIdx, init) {
514
+ if (!ASYNC_STATE.has(componentIdx)) {
515
+ ASYNC_STATE.set(componentIdx, new ComponentAsyncState());
516
+ }
517
+ return ASYNC_STATE.get(componentIdx);
518
+ }
519
+
520
+ class ComponentAsyncState {
521
+ #callingAsyncImport = false;
522
+ #syncImportWait = Promise.withResolvers();
523
+ #lock = null;
524
+
525
+ mayLeave = false;
526
+ waitableSets = new RepTable();
527
+ waitables = new RepTable();
528
+
529
+ #parkedTasks = new Map();
530
+
531
+ callingSyncImport(val) {
532
+ if (val === undefined) { return this.#callingAsyncImport; }
533
+ if (typeof val !== 'boolean') { throw new TypeError('invalid setting for async import'); }
534
+ const prev = this.#callingAsyncImport;
535
+ this.#callingAsyncImport = val;
536
+ if (prev === true && this.#callingAsyncImport === false) {
537
+ this.#notifySyncImportEnd();
538
+ }
539
+ }
540
+
541
+ #notifySyncImportEnd() {
542
+ const existing = this.#syncImportWait;
543
+ this.#syncImportWait = Promise.withResolvers();
544
+ existing.resolve();
545
+ }
546
+
547
+ async waitForSyncImportCallEnd() {
548
+ await this.#syncImportWait.promise;
549
+ }
550
+
551
+ parkTaskOnAwaitable(args) {
552
+ if (!args.awaitable) { throw new TypeError('missing awaitable when trying to park'); }
553
+ if (!args.task) { throw new TypeError('missing task when trying to park'); }
554
+ const { awaitable, task } = args;
555
+
556
+ let taskList = this.#parkedTasks.get(awaitable.id());
557
+ if (!taskList) {
558
+ taskList = [];
559
+ this.#parkedTasks.set(awaitable.id(), taskList);
560
+ }
561
+ taskList.push(task);
562
+
563
+ this.wakeNextTaskForAwaitable(awaitable);
564
+ }
565
+
566
+ wakeNextTaskForAwaitable(awaitable) {
567
+ if (!awaitable) { throw new TypeError('missing awaitable when waking next task'); }
568
+ const awaitableID = awaitable.id();
569
+
570
+ const taskList = this.#parkedTasks.get(awaitableID);
571
+ if (!taskList || taskList.length === 0) {
572
+ _debugLog('[ComponentAsyncState] no tasks waiting for awaitable', { awaitableID: awaitable.id() });
573
+ return;
574
+ }
575
+
576
+ let task = taskList.shift(); // todo(perf)
577
+ if (!task) { throw new Error('no task in parked list despite previous check'); }
578
+
579
+ if (!task.awaitableResume) {
580
+ throw new Error('task ready due to awaitable is missing resume', { taskID: task.id(), awaitableID });
581
+ }
582
+ task.awaitableResume();
583
+ }
584
+
585
+ async exclusiveLock() { // TODO: use atomics
586
+ if (this.#lock === null) {
587
+ this.#lock = { ticket: 0n };
588
+ }
589
+
590
+ // Take a ticket for the next valid usage
591
+ const ticket = ++this.#lock.ticket;
592
+
593
+ _debugLog('[ComponentAsyncState#exclusiveLock()] locking', {
594
+ currentTicket: ticket - 1n,
595
+ ticket
596
+ });
597
+
598
+ // If there is an active promise, then wait for it
599
+ while (this.#lock.promise) {
600
+ const finishedTicket = await this.#lock.promise;
601
+ finishedTicket = await this.#lock.promise;
602
+ if (finishedTicket === ticket - 1n) { break; }
603
+ }
604
+
605
+ const { promise, resolve } = Promise.withResolvers();
606
+ this.#lock = {
607
+ ticket,
608
+ promise,
609
+ resolve,
610
+ };
611
+
612
+ return this.#lock.promise;
613
+ }
614
+
615
+ exclusiveRelease() {
616
+ _debugLog('[ComponentAsyncState#exclusiveRelease()] releasing', {
617
+ currentTicket: this.#lock === null ? 'none' : this.#lock.ticket,
618
+ });
619
+
620
+ if (this.#lock === null) { return; }
621
+
622
+ const existingLock = this.#lock;
623
+ this.#lock = null;
624
+ existingLock.resolve(existingLock.ticket);
625
+ }
626
+
627
+ isExclusivelyLocked() { return this.#lock !== null; }
628
+
629
+ }
630
+
631
+ if (!Promise.withResolvers) {
632
+ Promise.withResolvers = () => {
633
+ let resolve;
634
+ let reject;
635
+ const promise = new Promise((res, rej) => {
636
+ resolve = res;
637
+ reject = rej;
638
+ });
639
+ return { promise, resolve, reject };
640
+ };
641
+ }
642
+
78
643
  const _debugLog = (...args) => {
79
644
  if (!globalThis?.process?.env?.JCO_DEBUG) { return; }
80
645
  console.debug(...args);
81
646
  }
647
+ const ASYNC_DETERMINISM = 'random';
648
+ const _coinFlip = () => { return Math.random() > 0.5; };
649
+ const I32_MAX = 2_147_483_647;
650
+ const I32_MIN = -2_147_483_648;
651
+ const _typeCheckValidI32 = (n) => typeof n === 'number' && n >= I32_MIN && n <= I32_MAX;
82
652
 
83
653
  const base64Compile = str => WebAssembly.compile(typeof Buffer !== 'undefined' ? Buffer.from(str, 'base64') : Uint8Array.from(atob(str), b => b.charCodeAt(0)));
84
654
 
@@ -116,6 +686,54 @@ function getErrorPayload(e) {
116
686
  return e;
117
687
  }
118
688
 
689
+ class RepTable {
690
+ #data = [0, null];
691
+
692
+ insert(val) {
693
+ _debugLog('[RepTable#insert()] args', { val });
694
+ const freeIdx = this.#data[0];
695
+ if (freeIdx === 0) {
696
+ this.#data.push(val);
697
+ this.#data.push(null);
698
+ return (this.#data.length >> 1) - 1;
699
+ }
700
+ this.#data[0] = this.#data[freeIdx];
701
+ const newFreeIdx = freeIdx << 1;
702
+ this.#data[newFreeIdx] = val;
703
+ this.#data[newFreeIdx + 1] = null;
704
+ return free;
705
+ }
706
+
707
+ get(rep) {
708
+ _debugLog('[RepTable#insert()] args', { rep });
709
+ const baseIdx = idx << 1;
710
+ const val = this.#data[baseIdx];
711
+ return val;
712
+ }
713
+
714
+ contains(rep) {
715
+ _debugLog('[RepTable#insert()] args', { rep });
716
+ const baseIdx = idx << 1;
717
+ return !!this.#data[baseIdx];
718
+ }
719
+
720
+ remove(rep) {
721
+ _debugLog('[RepTable#insert()] args', { idx });
722
+ if (this.#data.length === 2) { throw new Error('invalid'); }
723
+
724
+ const baseIdx = idx << 1;
725
+ const val = this.#data[baseIdx];
726
+ if (val === 0) { throw new Error('invalid resource rep (cannot be 0)'); }
727
+ this.#data[baseIdx] = this.#data[0];
728
+ this.#data[0] = idx;
729
+ return val;
730
+ }
731
+
732
+ clear() {
733
+ this.#data = [0, null];
734
+ }
735
+ }
736
+
119
737
  function throwUninitialized() {
120
738
  throw new TypeError('Wasm uninitialized use `await $init` first');
121
739
  }
@@ -133,7 +751,10 @@ let captureCnt2 = 0;
133
751
  handleTables[2] = handleTable2;
134
752
 
135
753
  function trampoline5() {
754
+ _debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"] [Instruction::CallInterface] (async? sync, @ enter)');
755
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stderr');
136
756
  const ret = getStderr();
757
+ _debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"] [Instruction::CallInterface] (sync, @ post-call)');
137
758
  if (!(ret instanceof OutputStream)) {
138
759
  throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
139
760
  }
@@ -143,6 +764,11 @@ function trampoline5() {
143
764
  captureTable2.set(rep, ret);
144
765
  handle0 = rscTableCreateOwn(handleTable2, rep);
145
766
  }
767
+ _debugLog('[iface="wasi:cli/stderr@0.2.3", function="get-stderr"][Instruction::Return]', {
768
+ funcName: 'get-stderr',
769
+ paramCount: 1,
770
+ postReturn: false
771
+ });
146
772
  return handle0;
147
773
  }
148
774
 
@@ -152,7 +778,10 @@ let captureCnt1 = 0;
152
778
  handleTables[1] = handleTable1;
153
779
 
154
780
  function trampoline8() {
781
+ _debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"] [Instruction::CallInterface] (async? sync, @ enter)');
782
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stdin');
155
783
  const ret = getStdin();
784
+ _debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"] [Instruction::CallInterface] (sync, @ post-call)');
156
785
  if (!(ret instanceof InputStream)) {
157
786
  throw new TypeError('Resource error: Not a valid "InputStream" resource.');
158
787
  }
@@ -162,12 +791,20 @@ function trampoline8() {
162
791
  captureTable1.set(rep, ret);
163
792
  handle0 = rscTableCreateOwn(handleTable1, rep);
164
793
  }
794
+ _debugLog('[iface="wasi:cli/stdin@0.2.3", function="get-stdin"][Instruction::Return]', {
795
+ funcName: 'get-stdin',
796
+ paramCount: 1,
797
+ postReturn: false
798
+ });
165
799
  return handle0;
166
800
  }
167
801
 
168
802
 
169
803
  function trampoline9() {
804
+ _debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"] [Instruction::CallInterface] (async? sync, @ enter)');
805
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-stdout');
170
806
  const ret = getStdout();
807
+ _debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"] [Instruction::CallInterface] (sync, @ post-call)');
171
808
  if (!(ret instanceof OutputStream)) {
172
809
  throw new TypeError('Resource error: Not a valid "OutputStream" resource.');
173
810
  }
@@ -177,6 +814,11 @@ function trampoline9() {
177
814
  captureTable2.set(rep, ret);
178
815
  handle0 = rscTableCreateOwn(handleTable2, rep);
179
816
  }
817
+ _debugLog('[iface="wasi:cli/stdout@0.2.3", function="get-stdout"][Instruction::Return]', {
818
+ funcName: 'get-stdout',
819
+ paramCount: 1,
820
+ postReturn: false
821
+ });
180
822
  return handle0;
181
823
  }
182
824
 
@@ -202,7 +844,15 @@ function trampoline10(arg0) {
202
844
  throw new TypeError('invalid variant discriminant for expected');
203
845
  }
204
846
  }
847
+ _debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"] [Instruction::CallInterface] (async? sync, @ enter)');
848
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'exit');
205
849
  exit(variant0);
850
+ _debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"] [Instruction::CallInterface] (sync, @ post-call)');
851
+ _debugLog('[iface="wasi:cli/exit@0.2.3", function="exit"][Instruction::Return]', {
852
+ funcName: 'exit',
853
+ paramCount: 0,
854
+ postReturn: false
855
+ });
206
856
  }
207
857
 
208
858
  let exports2;
@@ -210,7 +860,10 @@ let memory0;
210
860
  let realloc0;
211
861
 
212
862
  function trampoline11(arg0) {
863
+ _debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"] [Instruction::CallInterface] (async? sync, @ enter)');
864
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-environment');
213
865
  const ret = getEnvironment();
866
+ _debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"] [Instruction::CallInterface] (sync, @ post-call)');
214
867
  var vec3 = ret;
215
868
  var len3 = vec3.length;
216
869
  var result3 = realloc0(0, 0, 4, len3 * 16);
@@ -228,6 +881,11 @@ function trampoline11(arg0) {
228
881
  }
229
882
  dataView(memory0).setInt32(arg0 + 4, len3, true);
230
883
  dataView(memory0).setInt32(arg0 + 0, result3, true);
884
+ _debugLog('[iface="wasi:cli/environment@0.2.3", function="get-environment"][Instruction::Return]', {
885
+ funcName: 'get-environment',
886
+ paramCount: 0,
887
+ postReturn: false
888
+ });
231
889
  }
232
890
 
233
891
  const handleTable6 = [T_FLAG, 0];
@@ -245,12 +903,15 @@ function trampoline12(arg0, arg1) {
245
903
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
246
904
  }
247
905
  curResourceBorrows.push(rsc0);
906
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"] [Instruction::CallInterface] (async? sync, @ enter)');
907
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.get-type');
248
908
  let ret;
249
909
  try {
250
910
  ret = { tag: 'ok', val: rsc0.getType()};
251
911
  } catch (e) {
252
912
  ret = { tag: 'err', val: getErrorPayload(e) };
253
913
  }
914
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"] [Instruction::CallInterface] (sync, @ post-call)');
254
915
  for (const rsc of curResourceBorrows) {
255
916
  rsc[symbolRscHandle] = undefined;
256
917
  }
@@ -475,6 +1136,11 @@ function trampoline12(arg0, arg1) {
475
1136
  throw new TypeError('invalid variant specified for result');
476
1137
  }
477
1138
  }
1139
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.get-type"][Instruction::Return]', {
1140
+ funcName: '[method]descriptor.get-type',
1141
+ paramCount: 0,
1142
+ postReturn: false
1143
+ });
478
1144
  }
479
1145
 
480
1146
 
@@ -488,12 +1154,15 @@ function trampoline13(arg0, arg1) {
488
1154
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
489
1155
  }
490
1156
  curResourceBorrows.push(rsc0);
1157
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash"] [Instruction::CallInterface] (async? sync, @ enter)');
1158
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.metadata-hash');
491
1159
  let ret;
492
1160
  try {
493
1161
  ret = { tag: 'ok', val: rsc0.metadataHash()};
494
1162
  } catch (e) {
495
1163
  ret = { tag: 'err', val: getErrorPayload(e) };
496
1164
  }
1165
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash"] [Instruction::CallInterface] (sync, @ post-call)');
497
1166
  for (const rsc of curResourceBorrows) {
498
1167
  rsc[symbolRscHandle] = undefined;
499
1168
  }
@@ -677,6 +1346,11 @@ function trampoline13(arg0, arg1) {
677
1346
  throw new TypeError('invalid variant specified for result');
678
1347
  }
679
1348
  }
1349
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash"][Instruction::Return]', {
1350
+ funcName: '[method]descriptor.metadata-hash',
1351
+ paramCount: 0,
1352
+ postReturn: false
1353
+ });
680
1354
  }
681
1355
 
682
1356
  const handleTable0 = [T_FLAG, 0];
@@ -694,7 +1368,10 @@ function trampoline14(arg0, arg1) {
694
1368
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
695
1369
  }
696
1370
  curResourceBorrows.push(rsc0);
1371
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"] [Instruction::CallInterface] (async? sync, @ enter)');
1372
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'filesystem-error-code');
697
1373
  const ret = filesystemErrorCode(rsc0);
1374
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"] [Instruction::CallInterface] (sync, @ post-call)');
698
1375
  for (const rsc of curResourceBorrows) {
699
1376
  rsc[symbolRscHandle] = undefined;
700
1377
  }
@@ -866,6 +1543,11 @@ function trampoline14(arg0, arg1) {
866
1543
  }
867
1544
  dataView(memory0).setInt8(arg1 + 1, enum3, true);
868
1545
  }
1546
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="filesystem-error-code"][Instruction::Return]', {
1547
+ funcName: 'filesystem-error-code',
1548
+ paramCount: 0,
1549
+ postReturn: false
1550
+ });
869
1551
  }
870
1552
 
871
1553
 
@@ -888,12 +1570,15 @@ function trampoline15(arg0, arg1, arg2, arg3, arg4) {
888
1570
  var ptr4 = arg2;
889
1571
  var len4 = arg3;
890
1572
  var result4 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr4, len4));
1573
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash-at"] [Instruction::CallInterface] (async? sync, @ enter)');
1574
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.metadata-hash-at');
891
1575
  let ret;
892
1576
  try {
893
1577
  ret = { tag: 'ok', val: rsc0.metadataHashAt(flags3, result4)};
894
1578
  } catch (e) {
895
1579
  ret = { tag: 'err', val: getErrorPayload(e) };
896
1580
  }
1581
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash-at"] [Instruction::CallInterface] (sync, @ post-call)');
897
1582
  for (const rsc of curResourceBorrows) {
898
1583
  rsc[symbolRscHandle] = undefined;
899
1584
  }
@@ -1077,6 +1762,11 @@ function trampoline15(arg0, arg1, arg2, arg3, arg4) {
1077
1762
  throw new TypeError('invalid variant specified for result');
1078
1763
  }
1079
1764
  }
1765
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.metadata-hash-at"][Instruction::Return]', {
1766
+ funcName: '[method]descriptor.metadata-hash-at',
1767
+ paramCount: 0,
1768
+ postReturn: false
1769
+ });
1080
1770
  }
1081
1771
 
1082
1772
 
@@ -1090,12 +1780,15 @@ function trampoline16(arg0, arg1, arg2) {
1090
1780
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
1091
1781
  }
1092
1782
  curResourceBorrows.push(rsc0);
1783
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-via-stream"] [Instruction::CallInterface] (async? sync, @ enter)');
1784
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.read-via-stream');
1093
1785
  let ret;
1094
1786
  try {
1095
1787
  ret = { tag: 'ok', val: rsc0.readViaStream(BigInt.asUintN(64, arg1))};
1096
1788
  } catch (e) {
1097
1789
  ret = { tag: 'err', val: getErrorPayload(e) };
1098
1790
  }
1791
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-via-stream"] [Instruction::CallInterface] (sync, @ post-call)');
1099
1792
  for (const rsc of curResourceBorrows) {
1100
1793
  rsc[symbolRscHandle] = undefined;
1101
1794
  }
@@ -1286,6 +1979,11 @@ function trampoline16(arg0, arg1, arg2) {
1286
1979
  throw new TypeError('invalid variant specified for result');
1287
1980
  }
1288
1981
  }
1982
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-via-stream"][Instruction::Return]', {
1983
+ funcName: '[method]descriptor.read-via-stream',
1984
+ paramCount: 0,
1985
+ postReturn: false
1986
+ });
1289
1987
  }
1290
1988
 
1291
1989
 
@@ -1299,12 +1997,15 @@ function trampoline17(arg0, arg1, arg2) {
1299
1997
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
1300
1998
  }
1301
1999
  curResourceBorrows.push(rsc0);
2000
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"] [Instruction::CallInterface] (async? sync, @ enter)');
2001
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.write-via-stream');
1302
2002
  let ret;
1303
2003
  try {
1304
2004
  ret = { tag: 'ok', val: rsc0.writeViaStream(BigInt.asUintN(64, arg1))};
1305
2005
  } catch (e) {
1306
2006
  ret = { tag: 'err', val: getErrorPayload(e) };
1307
2007
  }
2008
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"] [Instruction::CallInterface] (sync, @ post-call)');
1308
2009
  for (const rsc of curResourceBorrows) {
1309
2010
  rsc[symbolRscHandle] = undefined;
1310
2011
  }
@@ -1495,6 +2196,11 @@ function trampoline17(arg0, arg1, arg2) {
1495
2196
  throw new TypeError('invalid variant specified for result');
1496
2197
  }
1497
2198
  }
2199
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.write-via-stream"][Instruction::Return]', {
2200
+ funcName: '[method]descriptor.write-via-stream',
2201
+ paramCount: 0,
2202
+ postReturn: false
2203
+ });
1498
2204
  }
1499
2205
 
1500
2206
 
@@ -1508,12 +2214,15 @@ function trampoline18(arg0, arg1) {
1508
2214
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
1509
2215
  }
1510
2216
  curResourceBorrows.push(rsc0);
2217
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"] [Instruction::CallInterface] (async? sync, @ enter)');
2218
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.append-via-stream');
1511
2219
  let ret;
1512
2220
  try {
1513
2221
  ret = { tag: 'ok', val: rsc0.appendViaStream()};
1514
2222
  } catch (e) {
1515
2223
  ret = { tag: 'err', val: getErrorPayload(e) };
1516
2224
  }
2225
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"] [Instruction::CallInterface] (sync, @ post-call)');
1517
2226
  for (const rsc of curResourceBorrows) {
1518
2227
  rsc[symbolRscHandle] = undefined;
1519
2228
  }
@@ -1704,6 +2413,11 @@ function trampoline18(arg0, arg1) {
1704
2413
  throw new TypeError('invalid variant specified for result');
1705
2414
  }
1706
2415
  }
2416
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.append-via-stream"][Instruction::Return]', {
2417
+ funcName: '[method]descriptor.append-via-stream',
2418
+ paramCount: 0,
2419
+ postReturn: false
2420
+ });
1707
2421
  }
1708
2422
 
1709
2423
  const handleTable5 = [T_FLAG, 0];
@@ -1721,12 +2435,15 @@ function trampoline19(arg0, arg1) {
1721
2435
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
1722
2436
  }
1723
2437
  curResourceBorrows.push(rsc0);
2438
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-directory"] [Instruction::CallInterface] (async? sync, @ enter)');
2439
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.read-directory');
1724
2440
  let ret;
1725
2441
  try {
1726
2442
  ret = { tag: 'ok', val: rsc0.readDirectory()};
1727
2443
  } catch (e) {
1728
2444
  ret = { tag: 'err', val: getErrorPayload(e) };
1729
2445
  }
2446
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-directory"] [Instruction::CallInterface] (sync, @ post-call)');
1730
2447
  for (const rsc of curResourceBorrows) {
1731
2448
  rsc[symbolRscHandle] = undefined;
1732
2449
  }
@@ -1917,6 +2634,11 @@ function trampoline19(arg0, arg1) {
1917
2634
  throw new TypeError('invalid variant specified for result');
1918
2635
  }
1919
2636
  }
2637
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.read-directory"][Instruction::Return]', {
2638
+ funcName: '[method]descriptor.read-directory',
2639
+ paramCount: 0,
2640
+ postReturn: false
2641
+ });
1920
2642
  }
1921
2643
 
1922
2644
 
@@ -1930,12 +2652,15 @@ function trampoline20(arg0, arg1) {
1930
2652
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
1931
2653
  }
1932
2654
  curResourceBorrows.push(rsc0);
2655
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"] [Instruction::CallInterface] (async? sync, @ enter)');
2656
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.stat');
1933
2657
  let ret;
1934
2658
  try {
1935
2659
  ret = { tag: 'ok', val: rsc0.stat()};
1936
2660
  } catch (e) {
1937
2661
  ret = { tag: 'err', val: getErrorPayload(e) };
1938
2662
  }
2663
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"] [Instruction::CallInterface] (sync, @ post-call)');
1939
2664
  for (const rsc of curResourceBorrows) {
1940
2665
  rsc[symbolRscHandle] = undefined;
1941
2666
  }
@@ -2193,6 +2918,11 @@ function trampoline20(arg0, arg1) {
2193
2918
  throw new TypeError('invalid variant specified for result');
2194
2919
  }
2195
2920
  }
2921
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat"][Instruction::Return]', {
2922
+ funcName: '[method]descriptor.stat',
2923
+ paramCount: 0,
2924
+ postReturn: false
2925
+ });
2196
2926
  }
2197
2927
 
2198
2928
 
@@ -2215,12 +2945,15 @@ function trampoline21(arg0, arg1, arg2, arg3, arg4) {
2215
2945
  var ptr4 = arg2;
2216
2946
  var len4 = arg3;
2217
2947
  var result4 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr4, len4));
2948
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat-at"] [Instruction::CallInterface] (async? sync, @ enter)');
2949
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.stat-at');
2218
2950
  let ret;
2219
2951
  try {
2220
2952
  ret = { tag: 'ok', val: rsc0.statAt(flags3, result4)};
2221
2953
  } catch (e) {
2222
2954
  ret = { tag: 'err', val: getErrorPayload(e) };
2223
2955
  }
2956
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat-at"] [Instruction::CallInterface] (sync, @ post-call)');
2224
2957
  for (const rsc of curResourceBorrows) {
2225
2958
  rsc[symbolRscHandle] = undefined;
2226
2959
  }
@@ -2478,6 +3211,11 @@ function trampoline21(arg0, arg1, arg2, arg3, arg4) {
2478
3211
  throw new TypeError('invalid variant specified for result');
2479
3212
  }
2480
3213
  }
3214
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.stat-at"][Instruction::Return]', {
3215
+ funcName: '[method]descriptor.stat-at',
3216
+ paramCount: 0,
3217
+ postReturn: false
3218
+ });
2481
3219
  }
2482
3220
 
2483
3221
 
@@ -2520,12 +3258,15 @@ function trampoline22(arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
2520
3258
  requestedWriteSync: Boolean(arg5 & 16),
2521
3259
  mutateDirectory: Boolean(arg5 & 32),
2522
3260
  };
3261
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.open-at"] [Instruction::CallInterface] (async? sync, @ enter)');
3262
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]descriptor.open-at');
2523
3263
  let ret;
2524
3264
  try {
2525
3265
  ret = { tag: 'ok', val: rsc0.openAt(flags3, result4, flags5, flags6)};
2526
3266
  } catch (e) {
2527
3267
  ret = { tag: 'err', val: getErrorPayload(e) };
2528
3268
  }
3269
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.open-at"] [Instruction::CallInterface] (sync, @ post-call)');
2529
3270
  for (const rsc of curResourceBorrows) {
2530
3271
  rsc[symbolRscHandle] = undefined;
2531
3272
  }
@@ -2716,6 +3457,11 @@ function trampoline22(arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
2716
3457
  throw new TypeError('invalid variant specified for result');
2717
3458
  }
2718
3459
  }
3460
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]descriptor.open-at"][Instruction::Return]', {
3461
+ funcName: '[method]descriptor.open-at',
3462
+ paramCount: 0,
3463
+ postReturn: false
3464
+ });
2719
3465
  }
2720
3466
 
2721
3467
 
@@ -2729,12 +3475,15 @@ function trampoline23(arg0, arg1) {
2729
3475
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
2730
3476
  }
2731
3477
  curResourceBorrows.push(rsc0);
3478
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]directory-entry-stream.read-directory-entry"] [Instruction::CallInterface] (async? sync, @ enter)');
3479
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]directory-entry-stream.read-directory-entry');
2732
3480
  let ret;
2733
3481
  try {
2734
3482
  ret = { tag: 'ok', val: rsc0.readDirectoryEntry()};
2735
3483
  } catch (e) {
2736
3484
  ret = { tag: 'err', val: getErrorPayload(e) };
2737
3485
  }
3486
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]directory-entry-stream.read-directory-entry"] [Instruction::CallInterface] (sync, @ post-call)');
2738
3487
  for (const rsc of curResourceBorrows) {
2739
3488
  rsc[symbolRscHandle] = undefined;
2740
3489
  }
@@ -2971,6 +3720,11 @@ function trampoline23(arg0, arg1) {
2971
3720
  throw new TypeError('invalid variant specified for result');
2972
3721
  }
2973
3722
  }
3723
+ _debugLog('[iface="wasi:filesystem/types@0.2.3", function="[method]directory-entry-stream.read-directory-entry"][Instruction::Return]', {
3724
+ funcName: '[method]directory-entry-stream.read-directory-entry',
3725
+ paramCount: 0,
3726
+ postReturn: false
3727
+ });
2974
3728
  }
2975
3729
 
2976
3730
 
@@ -2984,12 +3738,15 @@ function trampoline24(arg0, arg1, arg2) {
2984
3738
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
2985
3739
  }
2986
3740
  curResourceBorrows.push(rsc0);
3741
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.read"] [Instruction::CallInterface] (async? sync, @ enter)');
3742
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]input-stream.read');
2987
3743
  let ret;
2988
3744
  try {
2989
3745
  ret = { tag: 'ok', val: rsc0.read(BigInt.asUintN(64, arg1))};
2990
3746
  } catch (e) {
2991
3747
  ret = { tag: 'err', val: getErrorPayload(e) };
2992
3748
  }
3749
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.read"] [Instruction::CallInterface] (sync, @ post-call)');
2993
3750
  for (const rsc of curResourceBorrows) {
2994
3751
  rsc[symbolRscHandle] = undefined;
2995
3752
  }
@@ -3042,6 +3799,11 @@ function trampoline24(arg0, arg1, arg2) {
3042
3799
  throw new TypeError('invalid variant specified for result');
3043
3800
  }
3044
3801
  }
3802
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.read"][Instruction::Return]', {
3803
+ funcName: '[method]input-stream.read',
3804
+ paramCount: 0,
3805
+ postReturn: false
3806
+ });
3045
3807
  }
3046
3808
 
3047
3809
 
@@ -3055,12 +3817,15 @@ function trampoline25(arg0, arg1, arg2) {
3055
3817
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
3056
3818
  }
3057
3819
  curResourceBorrows.push(rsc0);
3820
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.blocking-read"] [Instruction::CallInterface] (async? sync, @ enter)');
3821
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]input-stream.blocking-read');
3058
3822
  let ret;
3059
3823
  try {
3060
3824
  ret = { tag: 'ok', val: rsc0.blockingRead(BigInt.asUintN(64, arg1))};
3061
3825
  } catch (e) {
3062
3826
  ret = { tag: 'err', val: getErrorPayload(e) };
3063
3827
  }
3828
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.blocking-read"] [Instruction::CallInterface] (sync, @ post-call)');
3064
3829
  for (const rsc of curResourceBorrows) {
3065
3830
  rsc[symbolRscHandle] = undefined;
3066
3831
  }
@@ -3113,6 +3878,11 @@ function trampoline25(arg0, arg1, arg2) {
3113
3878
  throw new TypeError('invalid variant specified for result');
3114
3879
  }
3115
3880
  }
3881
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]input-stream.blocking-read"][Instruction::Return]', {
3882
+ funcName: '[method]input-stream.blocking-read',
3883
+ paramCount: 0,
3884
+ postReturn: false
3885
+ });
3116
3886
  }
3117
3887
 
3118
3888
 
@@ -3126,12 +3896,15 @@ function trampoline26(arg0, arg1) {
3126
3896
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
3127
3897
  }
3128
3898
  curResourceBorrows.push(rsc0);
3899
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"] [Instruction::CallInterface] (async? sync, @ enter)');
3900
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.check-write');
3129
3901
  let ret;
3130
3902
  try {
3131
3903
  ret = { tag: 'ok', val: rsc0.checkWrite()};
3132
3904
  } catch (e) {
3133
3905
  ret = { tag: 'err', val: getErrorPayload(e) };
3134
3906
  }
3907
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"] [Instruction::CallInterface] (sync, @ post-call)');
3135
3908
  for (const rsc of curResourceBorrows) {
3136
3909
  rsc[symbolRscHandle] = undefined;
3137
3910
  }
@@ -3178,6 +3951,11 @@ function trampoline26(arg0, arg1) {
3178
3951
  throw new TypeError('invalid variant specified for result');
3179
3952
  }
3180
3953
  }
3954
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.check-write"][Instruction::Return]', {
3955
+ funcName: '[method]output-stream.check-write',
3956
+ paramCount: 0,
3957
+ postReturn: false
3958
+ });
3181
3959
  }
3182
3960
 
3183
3961
 
@@ -3194,12 +3972,15 @@ function trampoline27(arg0, arg1, arg2, arg3) {
3194
3972
  var ptr3 = arg1;
3195
3973
  var len3 = arg2;
3196
3974
  var result3 = new Uint8Array(memory0.buffer.slice(ptr3, ptr3 + len3 * 1));
3975
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"] [Instruction::CallInterface] (async? sync, @ enter)');
3976
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.write');
3197
3977
  let ret;
3198
3978
  try {
3199
3979
  ret = { tag: 'ok', val: rsc0.write(result3)};
3200
3980
  } catch (e) {
3201
3981
  ret = { tag: 'err', val: getErrorPayload(e) };
3202
3982
  }
3983
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"] [Instruction::CallInterface] (sync, @ post-call)');
3203
3984
  for (const rsc of curResourceBorrows) {
3204
3985
  rsc[symbolRscHandle] = undefined;
3205
3986
  }
@@ -3245,6 +4026,11 @@ function trampoline27(arg0, arg1, arg2, arg3) {
3245
4026
  throw new TypeError('invalid variant specified for result');
3246
4027
  }
3247
4028
  }
4029
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.write"][Instruction::Return]', {
4030
+ funcName: '[method]output-stream.write',
4031
+ paramCount: 0,
4032
+ postReturn: false
4033
+ });
3248
4034
  }
3249
4035
 
3250
4036
 
@@ -3261,12 +4047,15 @@ function trampoline28(arg0, arg1, arg2, arg3) {
3261
4047
  var ptr3 = arg1;
3262
4048
  var len3 = arg2;
3263
4049
  var result3 = new Uint8Array(memory0.buffer.slice(ptr3, ptr3 + len3 * 1));
4050
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"] [Instruction::CallInterface] (async? sync, @ enter)');
4051
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.blocking-write-and-flush');
3264
4052
  let ret;
3265
4053
  try {
3266
4054
  ret = { tag: 'ok', val: rsc0.blockingWriteAndFlush(result3)};
3267
4055
  } catch (e) {
3268
4056
  ret = { tag: 'err', val: getErrorPayload(e) };
3269
4057
  }
4058
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"] [Instruction::CallInterface] (sync, @ post-call)');
3270
4059
  for (const rsc of curResourceBorrows) {
3271
4060
  rsc[symbolRscHandle] = undefined;
3272
4061
  }
@@ -3312,6 +4101,11 @@ function trampoline28(arg0, arg1, arg2, arg3) {
3312
4101
  throw new TypeError('invalid variant specified for result');
3313
4102
  }
3314
4103
  }
4104
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-write-and-flush"][Instruction::Return]', {
4105
+ funcName: '[method]output-stream.blocking-write-and-flush',
4106
+ paramCount: 0,
4107
+ postReturn: false
4108
+ });
3315
4109
  }
3316
4110
 
3317
4111
 
@@ -3325,12 +4119,15 @@ function trampoline29(arg0, arg1) {
3325
4119
  Object.defineProperty(rsc0, symbolRscRep, { writable: true, value: rep2});
3326
4120
  }
3327
4121
  curResourceBorrows.push(rsc0);
4122
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"] [Instruction::CallInterface] (async? sync, @ enter)');
4123
+ const _interface_call_currentTaskID = startCurrentTask(0, false, '[method]output-stream.blocking-flush');
3328
4124
  let ret;
3329
4125
  try {
3330
4126
  ret = { tag: 'ok', val: rsc0.blockingFlush()};
3331
4127
  } catch (e) {
3332
4128
  ret = { tag: 'err', val: getErrorPayload(e) };
3333
4129
  }
4130
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"] [Instruction::CallInterface] (sync, @ post-call)');
3334
4131
  for (const rsc of curResourceBorrows) {
3335
4132
  rsc[symbolRscHandle] = undefined;
3336
4133
  }
@@ -3376,11 +4173,19 @@ function trampoline29(arg0, arg1) {
3376
4173
  throw new TypeError('invalid variant specified for result');
3377
4174
  }
3378
4175
  }
4176
+ _debugLog('[iface="wasi:io/streams@0.2.3", function="[method]output-stream.blocking-flush"][Instruction::Return]', {
4177
+ funcName: '[method]output-stream.blocking-flush',
4178
+ paramCount: 0,
4179
+ postReturn: false
4180
+ });
3379
4181
  }
3380
4182
 
3381
4183
 
3382
4184
  function trampoline30(arg0, arg1) {
4185
+ _debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"] [Instruction::CallInterface] (async? sync, @ enter)');
4186
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-random-bytes');
3383
4187
  const ret = getRandomBytes(BigInt.asUintN(64, arg0));
4188
+ _debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"] [Instruction::CallInterface] (sync, @ post-call)');
3384
4189
  var val0 = ret;
3385
4190
  var len0 = val0.byteLength;
3386
4191
  var ptr0 = realloc0(0, 0, 1, len0 * 1);
@@ -3388,11 +4193,19 @@ function trampoline30(arg0, arg1) {
3388
4193
  (new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
3389
4194
  dataView(memory0).setInt32(arg1 + 4, len0, true);
3390
4195
  dataView(memory0).setInt32(arg1 + 0, ptr0, true);
4196
+ _debugLog('[iface="wasi:random/random@0.2.3", function="get-random-bytes"][Instruction::Return]', {
4197
+ funcName: 'get-random-bytes',
4198
+ paramCount: 0,
4199
+ postReturn: false
4200
+ });
3391
4201
  }
3392
4202
 
3393
4203
 
3394
4204
  function trampoline31(arg0) {
4205
+ _debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"] [Instruction::CallInterface] (async? sync, @ enter)');
4206
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-directories');
3395
4207
  const ret = getDirectories();
4208
+ _debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"] [Instruction::CallInterface] (sync, @ post-call)');
3396
4209
  var vec3 = ret;
3397
4210
  var len3 = vec3.length;
3398
4211
  var result3 = realloc0(0, 0, 4, len3 * 12);
@@ -3416,6 +4229,11 @@ function trampoline31(arg0) {
3416
4229
  }
3417
4230
  dataView(memory0).setInt32(arg0 + 4, len3, true);
3418
4231
  dataView(memory0).setInt32(arg0 + 0, result3, true);
4232
+ _debugLog('[iface="wasi:filesystem/preopens@0.2.3", function="get-directories"][Instruction::Return]', {
4233
+ funcName: 'get-directories',
4234
+ paramCount: 0,
4235
+ postReturn: false
4236
+ });
3419
4237
  }
3420
4238
 
3421
4239
  const handleTable3 = [T_FLAG, 0];
@@ -3424,7 +4242,10 @@ let captureCnt3 = 0;
3424
4242
  handleTables[3] = handleTable3;
3425
4243
 
3426
4244
  function trampoline32(arg0) {
4245
+ _debugLog('[iface="wasi:cli/terminal-stdin@0.2.3", function="get-terminal-stdin"] [Instruction::CallInterface] (async? sync, @ enter)');
4246
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-terminal-stdin');
3427
4247
  const ret = getTerminalStdin();
4248
+ _debugLog('[iface="wasi:cli/terminal-stdin@0.2.3", function="get-terminal-stdin"] [Instruction::CallInterface] (sync, @ post-call)');
3428
4249
  var variant1 = ret;
3429
4250
  if (variant1 === null || variant1=== undefined) {
3430
4251
  dataView(memory0).setInt8(arg0 + 0, 0, true);
@@ -3442,6 +4263,11 @@ function trampoline32(arg0) {
3442
4263
  }
3443
4264
  dataView(memory0).setInt32(arg0 + 4, handle0, true);
3444
4265
  }
4266
+ _debugLog('[iface="wasi:cli/terminal-stdin@0.2.3", function="get-terminal-stdin"][Instruction::Return]', {
4267
+ funcName: 'get-terminal-stdin',
4268
+ paramCount: 0,
4269
+ postReturn: false
4270
+ });
3445
4271
  }
3446
4272
 
3447
4273
  const handleTable4 = [T_FLAG, 0];
@@ -3450,7 +4276,10 @@ let captureCnt4 = 0;
3450
4276
  handleTables[4] = handleTable4;
3451
4277
 
3452
4278
  function trampoline33(arg0) {
4279
+ _debugLog('[iface="wasi:cli/terminal-stdout@0.2.3", function="get-terminal-stdout"] [Instruction::CallInterface] (async? sync, @ enter)');
4280
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-terminal-stdout');
3453
4281
  const ret = getTerminalStdout();
4282
+ _debugLog('[iface="wasi:cli/terminal-stdout@0.2.3", function="get-terminal-stdout"] [Instruction::CallInterface] (sync, @ post-call)');
3454
4283
  var variant1 = ret;
3455
4284
  if (variant1 === null || variant1=== undefined) {
3456
4285
  dataView(memory0).setInt8(arg0 + 0, 0, true);
@@ -3468,11 +4297,19 @@ function trampoline33(arg0) {
3468
4297
  }
3469
4298
  dataView(memory0).setInt32(arg0 + 4, handle0, true);
3470
4299
  }
4300
+ _debugLog('[iface="wasi:cli/terminal-stdout@0.2.3", function="get-terminal-stdout"][Instruction::Return]', {
4301
+ funcName: 'get-terminal-stdout',
4302
+ paramCount: 0,
4303
+ postReturn: false
4304
+ });
3471
4305
  }
3472
4306
 
3473
4307
 
3474
4308
  function trampoline34(arg0) {
4309
+ _debugLog('[iface="wasi:cli/terminal-stderr@0.2.3", function="get-terminal-stderr"] [Instruction::CallInterface] (async? sync, @ enter)');
4310
+ const _interface_call_currentTaskID = startCurrentTask(0, false, 'get-terminal-stderr');
3475
4311
  const ret = getTerminalStderr();
4312
+ _debugLog('[iface="wasi:cli/terminal-stderr@0.2.3", function="get-terminal-stderr"] [Instruction::CallInterface] (sync, @ post-call)');
3476
4313
  var variant1 = ret;
3477
4314
  if (variant1 === null || variant1=== undefined) {
3478
4315
  dataView(memory0).setInt8(arg0 + 0, 0, true);
@@ -3490,6 +4327,11 @@ function trampoline34(arg0) {
3490
4327
  }
3491
4328
  dataView(memory0).setInt32(arg0 + 4, handle0, true);
3492
4329
  }
4330
+ _debugLog('[iface="wasi:cli/terminal-stderr@0.2.3", function="get-terminal-stderr"][Instruction::Return]', {
4331
+ funcName: 'get-terminal-stderr',
4332
+ paramCount: 0,
4333
+ postReturn: false
4334
+ });
3493
4335
  }
3494
4336
 
3495
4337
  let exports3;
@@ -3593,7 +4435,10 @@ function parse(arg0) {
3593
4435
  if (!_initialized) throwUninitialized();
3594
4436
  var ptr0 = utf8Encode(arg0, realloc1, memory0);
3595
4437
  var len0 = utf8EncodedLen;
4438
+ _debugLog('[iface="local:wasm-tools/tools", function="parse"] [Instruction::CallWasm] (async? false, @ enter)');
4439
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsParse');
3596
4440
  const ret = toolsParse(ptr0, len0);
4441
+ endCurrentTask(0);
3597
4442
  let variant3;
3598
4443
  switch (dataView(memory0).getUint8(ret + 0, true)) {
3599
4444
  case 0: {
@@ -3620,12 +4465,25 @@ function parse(arg0) {
3620
4465
  throw new TypeError('invalid variant discriminant for expected');
3621
4466
  }
3622
4467
  }
3623
- const retVal = variant3;
4468
+ _debugLog('[iface="local:wasm-tools/tools", function="parse"][Instruction::Return]', {
4469
+ funcName: 'parse',
4470
+ paramCount: 1,
4471
+ postReturn: true
4472
+ });
4473
+ const retCopy = variant3;
4474
+
4475
+ let cstate = getOrCreateAsyncState(0);
4476
+ cstate.mayLeave = false;
3624
4477
  postReturn0(ret);
3625
- if (typeof retVal === 'object' && retVal.tag === 'err') {
3626
- throw new ComponentError(retVal.val);
4478
+ cstate.mayLeave = true;
4479
+
4480
+
4481
+
4482
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
4483
+ throw new ComponentError(retCopy.val);
3627
4484
  }
3628
- return retVal.val;
4485
+ return retCopy.val;
4486
+
3629
4487
  }
3630
4488
  let toolsPrint;
3631
4489
 
@@ -3636,7 +4494,10 @@ function print(arg0) {
3636
4494
  var ptr0 = realloc1(0, 0, 1, len0 * 1);
3637
4495
  var src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
3638
4496
  (new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
4497
+ _debugLog('[iface="local:wasm-tools/tools", function="print"] [Instruction::CallWasm] (async? false, @ enter)');
4498
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsPrint');
3639
4499
  const ret = toolsPrint(ptr0, len0);
4500
+ endCurrentTask(0);
3640
4501
  let variant3;
3641
4502
  switch (dataView(memory0).getUint8(ret + 0, true)) {
3642
4503
  case 0: {
@@ -3663,12 +4524,25 @@ function print(arg0) {
3663
4524
  throw new TypeError('invalid variant discriminant for expected');
3664
4525
  }
3665
4526
  }
3666
- const retVal = variant3;
4527
+ _debugLog('[iface="local:wasm-tools/tools", function="print"][Instruction::Return]', {
4528
+ funcName: 'print',
4529
+ paramCount: 1,
4530
+ postReturn: true
4531
+ });
4532
+ const retCopy = variant3;
4533
+
4534
+ let cstate = getOrCreateAsyncState(0);
4535
+ cstate.mayLeave = false;
3667
4536
  postReturn0(ret);
3668
- if (typeof retVal === 'object' && retVal.tag === 'err') {
3669
- throw new ComponentError(retVal.val);
4537
+ cstate.mayLeave = true;
4538
+
4539
+
4540
+
4541
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
4542
+ throw new ComponentError(retCopy.val);
3670
4543
  }
3671
- return retVal.val;
4544
+ return retCopy.val;
4545
+
3672
4546
  }
3673
4547
  let toolsComponentNew;
3674
4548
 
@@ -3711,7 +4585,10 @@ function componentNew(arg0, arg1) {
3711
4585
  variant5_1 = result4;
3712
4586
  variant5_2 = len4;
3713
4587
  }
4588
+ _debugLog('[iface="local:wasm-tools/tools", function="component-new"] [Instruction::CallWasm] (async? false, @ enter)');
4589
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsComponentNew');
3714
4590
  const ret = toolsComponentNew(ptr0, len0, variant5_0, variant5_1, variant5_2);
4591
+ endCurrentTask(0);
3715
4592
  let variant8;
3716
4593
  switch (dataView(memory0).getUint8(ret + 0, true)) {
3717
4594
  case 0: {
@@ -3738,12 +4615,25 @@ function componentNew(arg0, arg1) {
3738
4615
  throw new TypeError('invalid variant discriminant for expected');
3739
4616
  }
3740
4617
  }
3741
- const retVal = variant8;
4618
+ _debugLog('[iface="local:wasm-tools/tools", function="component-new"][Instruction::Return]', {
4619
+ funcName: 'component-new',
4620
+ paramCount: 1,
4621
+ postReturn: true
4622
+ });
4623
+ const retCopy = variant8;
4624
+
4625
+ let cstate = getOrCreateAsyncState(0);
4626
+ cstate.mayLeave = false;
3742
4627
  postReturn0(ret);
3743
- if (typeof retVal === 'object' && retVal.tag === 'err') {
3744
- throw new ComponentError(retVal.val);
4628
+ cstate.mayLeave = true;
4629
+
4630
+
4631
+
4632
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
4633
+ throw new ComponentError(retCopy.val);
3745
4634
  }
3746
- return retVal.val;
4635
+ return retCopy.val;
4636
+
3747
4637
  }
3748
4638
  let toolsComponentWit;
3749
4639
 
@@ -3754,7 +4644,10 @@ function componentWit(arg0) {
3754
4644
  var ptr0 = realloc1(0, 0, 1, len0 * 1);
3755
4645
  var src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
3756
4646
  (new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
4647
+ _debugLog('[iface="local:wasm-tools/tools", function="component-wit"] [Instruction::CallWasm] (async? false, @ enter)');
4648
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsComponentWit');
3757
4649
  const ret = toolsComponentWit(ptr0, len0);
4650
+ endCurrentTask(0);
3758
4651
  let variant3;
3759
4652
  switch (dataView(memory0).getUint8(ret + 0, true)) {
3760
4653
  case 0: {
@@ -3781,12 +4674,25 @@ function componentWit(arg0) {
3781
4674
  throw new TypeError('invalid variant discriminant for expected');
3782
4675
  }
3783
4676
  }
3784
- const retVal = variant3;
4677
+ _debugLog('[iface="local:wasm-tools/tools", function="component-wit"][Instruction::Return]', {
4678
+ funcName: 'component-wit',
4679
+ paramCount: 1,
4680
+ postReturn: true
4681
+ });
4682
+ const retCopy = variant3;
4683
+
4684
+ let cstate = getOrCreateAsyncState(0);
4685
+ cstate.mayLeave = false;
3785
4686
  postReturn0(ret);
3786
- if (typeof retVal === 'object' && retVal.tag === 'err') {
3787
- throw new ComponentError(retVal.val);
4687
+ cstate.mayLeave = true;
4688
+
4689
+
4690
+
4691
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
4692
+ throw new ComponentError(retCopy.val);
3788
4693
  }
3789
- return retVal.val;
4694
+ return retCopy.val;
4695
+
3790
4696
  }
3791
4697
  let toolsComponentEmbed;
3792
4698
 
@@ -3951,7 +4857,10 @@ function componentEmbed(arg0) {
3951
4857
  }
3952
4858
  }
3953
4859
  }
4860
+ _debugLog('[iface="local:wasm-tools/tools", function="component-embed"] [Instruction::CallWasm] (async? false, @ enter)');
4861
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsComponentEmbed');
3954
4862
  const ret = toolsComponentEmbed(ptr0);
4863
+ endCurrentTask(0);
3955
4864
  let variant27;
3956
4865
  switch (dataView(memory0).getUint8(ret + 0, true)) {
3957
4866
  case 0: {
@@ -3978,12 +4887,25 @@ function componentEmbed(arg0) {
3978
4887
  throw new TypeError('invalid variant discriminant for expected');
3979
4888
  }
3980
4889
  }
3981
- const retVal = variant27;
4890
+ _debugLog('[iface="local:wasm-tools/tools", function="component-embed"][Instruction::Return]', {
4891
+ funcName: 'component-embed',
4892
+ paramCount: 1,
4893
+ postReturn: true
4894
+ });
4895
+ const retCopy = variant27;
4896
+
4897
+ let cstate = getOrCreateAsyncState(0);
4898
+ cstate.mayLeave = false;
3982
4899
  postReturn0(ret);
3983
- if (typeof retVal === 'object' && retVal.tag === 'err') {
3984
- throw new ComponentError(retVal.val);
4900
+ cstate.mayLeave = true;
4901
+
4902
+
4903
+
4904
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
4905
+ throw new ComponentError(retCopy.val);
3985
4906
  }
3986
- return retVal.val;
4907
+ return retCopy.val;
4908
+
3987
4909
  }
3988
4910
  let toolsMetadataShow;
3989
4911
 
@@ -3994,7 +4916,10 @@ function metadataShow(arg0) {
3994
4916
  var ptr0 = realloc1(0, 0, 1, len0 * 1);
3995
4917
  var src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
3996
4918
  (new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
4919
+ _debugLog('[iface="local:wasm-tools/tools", function="metadata-show"] [Instruction::CallWasm] (async? false, @ enter)');
4920
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsMetadataShow');
3997
4921
  const ret = toolsMetadataShow(ptr0, len0);
4922
+ endCurrentTask(0);
3998
4923
  let variant12;
3999
4924
  switch (dataView(memory0).getUint8(ret + 0, true)) {
4000
4925
  case 0: {
@@ -4104,12 +5029,25 @@ function metadataShow(arg0) {
4104
5029
  throw new TypeError('invalid variant discriminant for expected');
4105
5030
  }
4106
5031
  }
4107
- const retVal = variant12;
5032
+ _debugLog('[iface="local:wasm-tools/tools", function="metadata-show"][Instruction::Return]', {
5033
+ funcName: 'metadata-show',
5034
+ paramCount: 1,
5035
+ postReturn: true
5036
+ });
5037
+ const retCopy = variant12;
5038
+
5039
+ let cstate = getOrCreateAsyncState(0);
5040
+ cstate.mayLeave = false;
4108
5041
  postReturn1(ret);
4109
- if (typeof retVal === 'object' && retVal.tag === 'err') {
4110
- throw new ComponentError(retVal.val);
5042
+ cstate.mayLeave = true;
5043
+
5044
+
5045
+
5046
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
5047
+ throw new ComponentError(retCopy.val);
4111
5048
  }
4112
- return retVal.val;
5049
+ return retCopy.val;
5050
+
4113
5051
  }
4114
5052
  let toolsMetadataAdd;
4115
5053
 
@@ -4148,7 +5086,10 @@ function metadataAdd(arg0, arg1) {
4148
5086
  dataView(memory0).setInt32(base + 12, len6, true);
4149
5087
  dataView(memory0).setInt32(base + 8, result6, true);
4150
5088
  }
5089
+ _debugLog('[iface="local:wasm-tools/tools", function="metadata-add"] [Instruction::CallWasm] (async? false, @ enter)');
5090
+ const _wasm_call_currentTaskID = startCurrentTask(0, false, 'toolsMetadataAdd');
4151
5091
  const ret = toolsMetadataAdd(ptr0, len0, result7, len7);
5092
+ endCurrentTask(0);
4152
5093
  let variant10;
4153
5094
  switch (dataView(memory0).getUint8(ret + 0, true)) {
4154
5095
  case 0: {
@@ -4175,12 +5116,25 @@ function metadataAdd(arg0, arg1) {
4175
5116
  throw new TypeError('invalid variant discriminant for expected');
4176
5117
  }
4177
5118
  }
4178
- const retVal = variant10;
5119
+ _debugLog('[iface="local:wasm-tools/tools", function="metadata-add"][Instruction::Return]', {
5120
+ funcName: 'metadata-add',
5121
+ paramCount: 1,
5122
+ postReturn: true
5123
+ });
5124
+ const retCopy = variant10;
5125
+
5126
+ let cstate = getOrCreateAsyncState(0);
5127
+ cstate.mayLeave = false;
4179
5128
  postReturn0(ret);
4180
- if (typeof retVal === 'object' && retVal.tag === 'err') {
4181
- throw new ComponentError(retVal.val);
5129
+ cstate.mayLeave = true;
5130
+
5131
+
5132
+
5133
+ if (typeof retCopy === 'object' && retCopy.tag === 'err') {
5134
+ throw new ComponentError(retCopy.val);
4182
5135
  }
4183
- return retVal.val;
5136
+ return retCopy.val;
5137
+
4184
5138
  }
4185
5139
 
4186
5140
  let _initialized = false;
@@ -4188,8 +5142,8 @@ export const $init = (() => {
4188
5142
  let gen = (function* init () {
4189
5143
  const module0 = fetchCompile(new URL('./wasm-tools.core.wasm', import.meta.url));
4190
5144
  const module1 = fetchCompile(new URL('./wasm-tools.core2.wasm', import.meta.url));
4191
- const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUHCAkCAgQEAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+QMlGQAgACABIAIgAyAEIAUgBiAHIAhBABEHAAsRACAAIAEgAiADIARBAREIAAsRACAAIAEgAiADIARBAhEJAAsLACAAIAFBAxECAAsLACAAIAFBBBECAAsPACAAIAEgAiADQQURBAALDwAgACABIAIgA0EGEQQACwsAIAAgAUEHEQIACwsAIAAgAUEIEQIACwkAIABBCREKAAsLACAAIAFBChECAAsNACAAIAEgAkELEQsACwkAIABBDBEBAAsJACAAQQ0RAQALCwAgACABQQ4RAAALCwAgACABQQ8RAAALCwAgACABQRARAAALEQAgACABIAIgAyAEQRERBQALDQAgACABIAJBEhEDAAsNACAAIAEgAkETEQMACwsAIAAgAUEUEQAACwsAIAAgAUEVEQAACwsAIAAgAUEWEQAACxEAIAAgASACIAMgBEEXEQUACxUAIAAgASACIAMgBCAFIAZBGBEMAAsLACAAIAFBGREAAAsNACAAIAEgAkEaEQMACw0AIAAgASACQRsRAwALCwAgACABQRwRAAALDwAgACABIAIgA0EdEQYACw8AIAAgASACIANBHhEGAAsLACAAIAFBHxEAAAsLACAAIAFBIBENAAsJACAAQSERAQALCQAgAEEiEQEACwkAIABBIxEBAAsJACAAQSQRAQALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yMzAuMA');
4192
- const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwAC5AEmAAEwAAcAATEACAABMgAJAAEzAAIAATQAAgABNQAEAAE2AAQAATcAAgABOAACAAE5AAoAAjEwAAIAAjExAAsAAjEyAAEAAjEzAAEAAjE0AAAAAjE1AAAAAjE2AAAAAjE3AAUAAjE4AAMAAjE5AAMAAjIwAAAAAjIxAAAAAjIyAAAAAjIzAAUAAjI0AAwAAjI1AAAAAjI2AAMAAjI3AAMAAjI4AAAAAjI5AAYAAjMwAAYAAjMxAAAAAjMyAA0AAjMzAAEAAjM0AAEAAjM1AAEAAjM2AAEACCRpbXBvcnRzAXABJSUJKwEAQQALJQABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIzMC4w');
5145
+ const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUHCAkCAgQEAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+QMlGQAgACABIAIgAyAEIAUgBiAHIAhBABEHAAsRACAAIAEgAiADIARBAREIAAsRACAAIAEgAiADIARBAhEJAAsLACAAIAFBAxECAAsLACAAIAFBBBECAAsPACAAIAEgAiADQQURBAALDwAgACABIAIgA0EGEQQACwsAIAAgAUEHEQIACwsAIAAgAUEIEQIACwkAIABBCREKAAsLACAAIAFBChECAAsNACAAIAEgAkELEQsACwkAIABBDBEBAAsJACAAQQ0RAQALCwAgACABQQ4RAAALCwAgACABQQ8RAAALCwAgACABQRARAAALEQAgACABIAIgAyAEQRERBQALDQAgACABIAJBEhEDAAsNACAAIAEgAkETEQMACwsAIAAgAUEUEQAACwsAIAAgAUEVEQAACwsAIAAgAUEWEQAACxEAIAAgASACIAMgBEEXEQUACxUAIAAgASACIAMgBCAFIAZBGBEMAAsLACAAIAFBGREAAAsNACAAIAEgAkEaEQMACw0AIAAgASACQRsRAwALCwAgACABQRwRAAALDwAgACABIAIgA0EdEQYACw8AIAAgASACIANBHhEGAAsLACAAIAFBHxEAAAsLACAAIAFBIBENAAsJACAAQSERAQALCQAgAEEiEQEACwkAIABBIxEBAAsJACAAQSQRAQALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yMzUuMA');
5146
+ const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwAC5AEmAAEwAAcAATEACAABMgAJAAEzAAIAATQAAgABNQAEAAE2AAQAATcAAgABOAACAAE5AAoAAjEwAAIAAjExAAsAAjEyAAEAAjEzAAEAAjE0AAAAAjE1AAAAAjE2AAAAAjE3AAUAAjE4AAMAAjE5AAMAAjIwAAAAAjIxAAAAAjIyAAAAAjIzAAUAAjI0AAwAAjI1AAAAAjI2AAMAAjI3AAMAAjI4AAAAAjI5AAYAAjMwAAYAAjMxAAAAAjMyAA0AAjMzAAEAAjM0AAEAAjM1AAEAAjM2AAEACCRpbXBvcnRzAXABJSUJKwEAQQALJQABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIzNS4w');
4193
5147
  ({ exports: exports0 } = yield instantiateCore(yield module2));
4194
5148
  ({ exports: exports1 } = yield instantiateCore(yield module0, {
4195
5149
  wasi_snapshot_preview1: {