| 2 | import type { ConsoleLine, TestResult } from "./types"; |
| 3 | |
| 4 | function formatStackError(err: Error): Error | null { |
| 5 | const match = err.message.match( |
| 6 | /Compiling function #\d+:"([^"]+)" failed: expected (\d+) elements on the stack for fallthru(?:, found (\d+))?/, |
| 7 | ); |
| 8 | if (!match) return null; |
| 9 | |
| 10 | const [, funcName, expected, found] = match; |
| 11 | const detail = |
| 12 | found === undefined || found === "0" |
| 13 | ? `it should return ${expected} value(s) but returns nothing. Add the required WebAssembly instructions to produce the return value.` |
| 14 | : `expected ${expected} value(s) on the stack but found ${found}. Check that your instructions produce the correct number of values.`; |
| 15 | return new Error( |
| 16 | `Function "${funcName}" ${found === undefined || found === "0" ? "is incomplete" : "has a stack mismatch"}: ${detail}`, |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | async function instantiate( |
| 21 | buffer: Uint8Array, |