pforth icon indicating copy to clipboard operation
pforth copied to clipboard

CATCH restores stack state incorrectly

Open alexshpilkin opened this issue 6 years ago • 2 comments

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.

alexshpilkin avatar Feb 14 '19 16:02 alexshpilkin

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.

philburk avatar Dec 05 '22 16:12 philburk

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.

philburk avatar Dec 12 '22 00:12 philburk