import type { Block, GoalId, ProofTree, RootBlock, StepId } from "../ir.ts"; export function buildBlocks(tree: ProofTree): RootBlock[] { const buildFrom = (entry: GoalId): Block => { const steps: StepId[] = []; let cur = entry; let into: Block[] = []; for (;;) { const close = tree.closes.get(cur); if (!close) break; steps.push(close.step); if (close.opens.length === 0) break; if (close.opens.length === 1) { cur = close.opens[0]; continue; } into = close.opens.map((childGoal) => buildFrom(childGoal)); break; } return { entry, steps, inlined: new Map(), errorLabel: undefined, last: cur, into, marks: new Set(), }; }; return tree.roots.map((root) => ({ root, block: buildFrom(root.goal), })); }