tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

runtime-backends.ts (917B)


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