Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What differentiates exception frames from other data on the return stack?

I'm trying to understand how exception frames are located on the return stack during a THROW.

The comments in "jonesforth.f.txt" assert that "When called, THROW walks up the return stack (the process is called 'unwinding') until it finds the exception stack frame." I'm unclear how the (EXCEPTION-MARKER) is differentiated from another other data on the return stack (return addresses, user values using >R, and indicies for do-loops).

In general, how do the various Forth's distinguish between exception frames and other data on the return stack?

like image 730
Raymond Hettinger Avatar asked Mar 09 '23 16:03

Raymond Hettinger


2 Answers

It seems Gforth doesn't use this 'unwinding' method.

Instead it stores the location of the active exception frame in a global variable, while saving the previously active frame's location within a new frame on the return stack. When an exception thrown, Gforth reads the last frame (most inner catch) location directly from the global variable.

Actually, across multiple other forths I've checked, I didn't see this implementation of the 'unwind' method. All those forths used the same idea of chaining frames in a linked list, with the head pointer stored in a global variable. This looks typical now for forths: http://lars.nocrew.org/dpans/dpansa9.htm

Maybe Jones Forth is relying on an assumption that the return stack should contain only return addresses at the moment of throwing. The marker address is unique, as it's a dictionary word. And typical loop indices don't reach that high to be confused with a return address.

like image 128
Vlad Avatar answered Apr 05 '23 23:04

Vlad


An explanation of how it can be made to work in a typical FORTH system is the paper by Milendorf

like image 39
vonbrand Avatar answered Apr 05 '23 22:04

vonbrand