This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Simula front-end: Heap-allocated activation records


On 23-Feb-2001, Knut Aksel Røysland <knutroy@ifi.uio.no> wrote:
> The implementation I envision, will thus allocate activation records
> on heap upon entering routines.

That sounds like hard work.

A common technique used to implement coroutines is to allocate a
medium-sized region on the heap for each coroutine thread, to hold the
stack for that thread.  Then a little bit of assembler or other
platform-specific magic is needed when you create a coroutine, to set
the stack pointer to point to the start of that coroutine's stack
segment, and when you switch between one coroutine thread and another
(sometimes setjmp/longjmp can be abused for switching between
coroutine threads).  But there's no special magic needed for ordinary
function calls.

The major drawback of this technique is the need to determine the size
of the coroutine stacks in advance.  But if you can live with that,
the technique described above will be more efficient than allocating
each frame separately.  I think it will also be a lot easier to
implement: you don't need to mess with the gcc back-end, all you need
to do is to insert calls to a couple of routines in your runtime
system, for creating new coroutine threads, and for switching between
them.

I've seen library packages to do this implemented in C++, indeed I
believe the original Cfront came with such a package.  John Skaller
had one as well.  Hmm... let me see what google comes up with...
there's one in the Gardens Point Modula implementation
<http://www2.fit.qut.edu.au/CompSci/PLAS/GPM/>
<http://www2.fit.qut.edu.au/CompSci/PLAS/GPM/guide/node239.html>.
It even comes with source.  You can probably find lots of other
coroutine libraries around.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]