SirWumpus / post4

Post4 is an indirect threaded Forth dialect written in C.
BSD 2-Clause "Simplified" License
4 stars 1 forks source link

Add over/under guard regions around each stack. #9

Closed SirWumpus closed 2 months ago

SirWumpus commented 2 months ago

Typically, systems check for this only in the Forth text interpreter loop, after the lexeme has been translated.

To avoid damage due to a small overflow/underflow, some amount of cells can be reserved in both sides of the stack (say, 8 or 16).

Originally posted by @ruv in https://github.com/SirWumpus/post4/issues/7#issuecomment-2271622514

SirWumpus commented 2 months ago

Added guard over/under flow regions around each stack that can be safely stepped.

SirWumpus commented 2 months ago

Not enough to add the guard regions, should check them too (dah).

This should replace stack size checking, which given the current implementation is way less efficient and eats CPU in a paranoid attempt to catch over and under flows as soon as possible.

Update

Will probably keep the old code, but default it to disabled.