🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #1022

Re: PL/1 non-local goto versus setjmp/longjmp

#1022
From: Peter da Silva
Date: Tue, 18 Aug 1992 14:54
100 lines
3191 bytes
In article <mwm.1jk3@contessa.palo-alto.ca.us> mwm@contessa.palo-alto.ca.us (Mike Meyer) writes:
> In <id.VJBS.0DK@ferranti.com>, peter@ferranti.com (Peter da Silva) wrote:
> > Personally, I'd prefer if C had no goto at all, but an organized system of
> > contexts, so you could perform setjmp/longjmp operations within a routine.

> I'm not quite sure what you mean by "organized system of contexts"? If
> this mechanism would allows multilevel loop breaks. If not, I'd like
> more details on it.

Basically, imagine integrating setjmp/longjmp with the language to a greater
extent. Instead of writing:

	retry:
		insert amazing mass of nested loops here {
			goto retry;
		}
		and put in some more code here
		if something horrible happens {
			goto fail;
		}
		and still more code
	fail:

You use a formal setup like so:

	context foo: {
		insert amazing mass of nested loops here {
			continue foo;
		}
		and put some more code here
		if something horrible happens {
			break foo;
		}
		and still more code
	}

Now, to generalize:

	context foo;

	...

	context foo: {
		yadda yadda yadda
		bar(foo);
	}

void bar(foo)
context foo;
{
	blah blah blah;
	if something horrible happens {
		break foo;
	}
}

But putting it directly in the language, you allow for more optimizations.
By replacing goto, you clean up a messy part of the language without losing
any general capability (switches with good optimization and this context
can replace every use of goto).

As a further elaboration (my long-term fantasy, real coroutine support in C):

	context other, self;
	stack_t otherstack[MIN_STACK + 20*STACK_FRAME + 20*30*sizeof(int)];
	extern void token(context, context);

	bind other: otherstack, token, (self);
	bind self;

	while((t = pause(other, 1)) != EOF) {
		handle_token(t);
		if we need to bail out
			(void)pause(other, 0);
	}


token(other)
context other;
{
	char buf[whatever];

	while(gets(buf)) {
		parse tokens here;
		if it looks like a foo
			if(!pause(other, foo))
				break;
		...
	}
}

Yes, you can build subroutine libraries that do this, but they're inherently
non-portable. This sort of thing should be part of the language, and is much
more important to me than expanding the type structure with object-oriented
stuff.
-- 
Peter da Silva                                               `-_-'
$ EDIT/TECO LOVE                                              'U` 
%TECO-W-OLDJOKE Not war?                        Have you hugged your wolf today?
Ferranti Intl. Ctls. Corp.      Sugar Land, TX  77487-5012       +1 713 274 5180
Technical Details
Message-ID: <id.KTGS.0N5@ferranti.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!Sirius.dfn.de!darwin.sura.net!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!ficc!peter
References: <1992Aug12.073130.1@zodiac.rutgers.edu> <id.VJBS.0DK@ferranti.com> <mwm.1jk3@contessa.palo-alto.ca.us>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!Sirius.dfn.de!darwin.sura.net!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!ficc!peter
From: peter@ferranti.com (Peter da Silva)
Subject: Re: PL/1 non-local goto versus setjmp/longjmp
Message-ID: <id.KTGS.0N5@ferranti.com>
Organization: Xenix Support, FICC
References: <1992Aug12.073130.1@zodiac.rutgers.edu> <id.VJBS.0DK@ferranti.com> <mwm.1jk3@contessa.palo-alto.ca.us>
Date: Tue, 18 Aug 1992 14:54:47 GMT
Lines: 100