fix: transpile() does not throw on <4 stack outputs (#584)
Replace silent ?? '0' fallbacks with an explicit length check that throws when the DYADIC stack holds fewer than 4 values at program termination. isValid() in the evolution pipeline now correctly rejects underflow programs instead of silently scoring them as valid with zeroed outputs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
685a0e488e
commit
e770191e56
1 changed files with 9 additions and 4 deletions
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue