Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!oddjob!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.lang.fortran
Subject: Re: Assigned GOTO
Message-ID: <12362@mimsy.UUCP>
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: 39

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