-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
The Forth translator's control flow stack (cfStack and loopStack) lacks defensive validation when popping entries. Mismatched control flow words like IF REPEAT, THEN without IF, or BEGIN THEN will either crash on pop_back_val() (empty stack) or silently produce garbage IR (wrong tag).
Currently only LOOP checks loopStack.empty() before popping.
Expected behavior
Clear error diagnostics for malformed input, e.g.:
THENwithoutIF→"THEN without matching IF"REPEATwithoutWHILE→"REPEAT without matching WHILE"UNTILwithoutBEGIN→"UNTIL without matching BEGIN"ELSEwithoutIF→"ELSE without matching IF"LOOPwithoutDO→ already handled
Suggested fix
- Add empty-stack guards before every
cfStack.pop_back_val()call (similar to the existingLOOPcheck) - Validate the popped tag matches expectations:
THEN/ELSEexpectCFTag::Orig(fromIF)UNTILexpectsCFTag::Dest(fromBEGIN)WHILEexpectsCFTag::Dest(fromBEGIN)REPEATexpectsCFTag::DestthenCFTag::Orig(fromWHILE)
- Add negative tests for each case in
test/Translation/Forth/
Context
Introduced in #20 (refactor: lower control flow to cf dialect instead of scf). The cf-stack approach is correct but the validation was deferred.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working