Merge pull request 'fix: transpile() does not throw on <4 stack outputs (#584)' (#617) from fix/issue-584 into master

This commit is contained in:
johba 2026-03-12 16:16:45 +01:00
commit 66dcb2c2a2

View file

@ -391,10 +391,15 @@ export function transpile(program: Node): TranspileResult {
processItems(program.items, state);
// Pop 4 outputs: top → ci, then anchorShare, anchorWidth, discoveryDepth.
const ciVar = state.dStack.pop() ?? '0';
const anchorShareVar = state.dStack.pop() ?? '0';
const anchorWidthVar = state.dStack.pop() ?? '0';
const discoveryDepthVar = state.dStack.pop() ?? '0';
if (state.dStack.length !== 4) {
throw new Error(
`Program must leave exactly 4 values on the DYADIC stack; found ${state.dStack.length}`,
);
}
const ciVar = state.dStack.pop()!;
const anchorShareVar = state.dStack.pop()!;
const anchorWidthVar = state.dStack.pop()!;
const discoveryDepthVar = state.dStack.pop()!;
return { functionBody: state.lines, ciVar, anchorShareVar, anchorWidthVar, discoveryDepthVar };
}