runtime-backends.ts (827B)
1 import type { GraphStats } from './graph.js'; 2 export type Backend = 'haskell-wasm'; 3 export type RuntimeStats = GraphStats | { backend: string; linearMemoryBytes: number }; 4 export const backends = { 5 'haskell-wasm': { label: 'Haskell', worker: './wasm-worker.js?backend=haskell-wasm' }, 6 } as const; 7 export function backend(value: string): Backend { 8 if (!Object.hasOwn(backends, value)) throw new Error('Unknown runtime backend'); 9 return value as Backend; 10 } 11 export function graphStats(stats: RuntimeStats): stats is GraphStats { return !('backend' in stats); } 12 export function runtimeStats(stats: RuntimeStats): string { 13 return graphStats(stats) ? `${stats.nodes.toLocaleString()} heap nodes ยท ${stats.work.toLocaleString()} work units` 14 : `${(stats.linearMemoryBytes / 1048576).toFixed(1)} MiB WASM linear memory`; 15 }