pforth
pforth copied to clipboard
CATCH restores stack state incorrectly
The code
: TEST-T 1 THROW ;
: TEST 3 ['] TEST-T CATCH ;
TEST . . DEPTH . CR
prints 1 3 0
on latest Gforth and VFX, but 1 1 0
on latest pForth git. I can’t point to a particular sentence in the standard, but I’d expect that if the code inside the CATCH
didn’t touch an item on the stack, that item would be unaffected by the THROW
.
The THROW docs at: https://forth-standard.org/standard/exception/THROW are pretty clear about all the stacks being restored to their depth when catch was called. So pForth has a bug.
I need to check to make sure the float stack is also handled properly.
I have tried twice to fix this and it is not easy. PForth does not implement CATCH THROW like a normal Forth. CATCH actually calls the inner interpreter, this is pfCatch(). Fixing this would require some major refactoring, That is too risky for the 2.0.0 release. So I am punting this to a later version.