Path: utzoo!attcan!uunet!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!MITCH.ENG.SUN.COM!wmb From: wmb@MITCH.ENG.SUN.COM Newsgroups: comp.lang.forth Subject: setjmp/longjmp vs. CATCH/THROW Message-ID: <9007062100.AA05671@ucbvax.Berkeley.EDU> Date: 6 Jul 90 14:30:43 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV Organization: The Internet Lines: 36 > You can push the jmp_buf on the return stack. You can do so if you happen to know how many return stack cells are necessary to hold the information in jmp_buf. Since the size of jmp_buf is not necessarily the same for all systems, the portable code for doing so looks like: #JMP_BUF BEGIN JMP_BUF OVER CELLS+ @ >R 1- DUP 0< UNTIL and the popping code which is required at the end is of similar ilk. And you can't build this code inside a colon definition because a standard program cannot make detailed assumptions about exactly what happens to the return stack when a colon definition is called. In particular, : FOO R> {push stuff on the return stack} >R ; isn't guaranteed to be portable. Note that you can't use a DO .. LOOP for the above code because you can't shove stuff on the return stack inside a DO .. LOOP . Which brings up the other obvious problem with using the return stack in this fashion; it "partitions" the return stack in the middle of a definition, so that anything that is placed on the return stack before the jmp_buf stuff is put there becomes inaccessible while the jmp_buf stuff is there. CATCH/THROW avoids this partitioning effect by making the return stack effects occur at a procedure boundary, where the return stack details are already hidden from a standard program. Specifying that the JMP_BUF information "must be" e.g. 2 cells worth of data would work in some systems, and would simplify the jmp_buf save code to JMP_BUF 2@ 2>R but the restriction to 2 cells is impractical, because many systems will need to save additional information, such as a floating point stack pointer or a local variable frame pointer. Mitch