Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!bbn!uwmcsd1!ig!agate!helios.ee.lbl.gov!nosc!ucsd!ucsdhub!esosun!jackson From: jackson@esosun.UUCP (Jerry Jackson) Newsgroups: comp.lang.fortran Subject: Re: Assigned GOTO Message-ID: <224@esosun.UUCP> Date: 8 Jul 88 16:19:28 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <222@esosun.UUCP> <12362@mimsy.UUCP> Organization: SAIC, San Diego Lines: 72 In-reply-to: chris@mimsy.UUCP's message of 8 Jul 88 04:38:27 GMT In article <12362@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: Path: esosun!seismo!uunet!lll-winken!lll-tis!ames!ncar!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.fortran Date: 8 Jul 88 04:38:27 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <222@esosun.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 38 In article <222@esosun.UUCP> jackson@esosun.UUCP (Jerry Jackson) writes: >Someone asked for uses for the assigned goto. ... >I wrote a Scheme interpreter in 'C'. One of the properties of Scheme >is that procedure calls MUST be tail recursive -- hence, the 'C' >function calling mechanism was not applicable to Scheme function >calls. What I had to do was simulate a procedure call/return >sequence. To do this right, you have to be able to push return >addresses (i.e. labels) on an explicit stack, then pop them and goto >the result. C does not allow you to 'goto' the value of a variable -- >If it did, I could have written a much more efficient interpreter. On the other hand, FORTRAN does not allow this either: not the way you want it. The GOTO is only allowed to transfer control within the current module (program, subroutine, or function). It sometimes works to jump outside the function, but it is by no means required to work. You can almost do this with setjmp and longjmp in C. A better way is to do it in assembly: extern void foo(); ... bar() { ... jump_to(foo); } # jump_to, for vax: .globl _jump_to _jump_to:.word 0 movl 4(ap),12(fp) # stash new return pc ret # and away we go This version is somewhat simplistic; it assumes that bar() and foo() have the same register save mask, for instance. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris I don't know if this really requires a follow-up but, actually, the ability to jump to a label stored in a variable within the current function would have been enough to do what I wanted... Only Scheme special forms (mostly) would have required the goto's (primitive functions that do not call the evaluator need not be tail-recursive -- they will always return before evaluation continues anyway). The code for each of the special forms would just have to have been included in the main function for the interpreter. So, I would have had a large main function, but it would have been fast!!!! +-----------------------------------------------------------------------------+ | Jerry Jackson UUCP: seismo!esosun!jackson | | Geophysics Division, MS/22 ARPA: esosun!jackson@seismo.css.gov | | SAIC SOUND: (619)458-4924 | | 10210 Campus Point Drive | | San Diego, CA 92121 | +-----------------------------------------------------------------------------+