// wasm/app/runner.js
// Tier runner — wraps the three loaders. Exposes a per-tier API so the
// SPA can iterate, time, and render a live elapsed-ms counter between
// the eval start and finish.

import { createPythonTier } from "./python/lumbda-py.js";
import { createCTier } from "./c/lumbda-c.loader.js";
import { createAsmTier } from "./asm/lumbda-asm.loader.js";

const cache = {};

export async function getTier(name, onLoad) {
    if (cache[name]) return cache[name];
    if (onLoad) onLoad(name);
    if (name === "python") cache[name] = await createPythonTier();
    else if (name === "c") cache[name] = await createCTier();
    else if (name === "asm") cache[name] = await createAsmTier();
    else throw new Error(`unknown tier: ${name}`);
    return cache[name];
}

export async function evalOnTier(name, src, onLoad) {
    const tier = await getTier(name, onLoad);
    return tier.evalLisp(src);
}
