Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!satisfied.apocalypse.org!news.mathworks.com!uunet!news.erinet.com!netcom.com!NewsWatcher!user
From: hbaker@netcom.com (Henry Baker)
Subject: Re: Hobbit4a (Scheme->C compiler for scm) now available
Message-ID: <hbaker-2903952238320001@192.0.2.1>
Sender: hbaker@netcom23.netcom.com
Organization: nil
References: <3kuhvn$jto@nyheter.chalmers.se> <3l7cth$hch@rtl.cygnus.com>
Date: Thu, 30 Mar 1995 06:34:25 GMT
Lines: 48

In article <3l7cth$hch@rtl.cygnus.com>, bothner@rtl.cygnus.com (Per
Bothner) wrote:

> In article <3kuhvn$jto@nyheter.chalmers.se>,
> Tanel Tammet <tammet@cs.chalmers.se> wrote:
> >(*) It does not fully conform to the requirement of being properly
> >tail-recursive: non-mutual tailrecursion is detected, but mutual
> >tailrecursion is not.
> 
> A good way to handle this may be to handle tail-call-elmination
> as an optimization in the C compiler. This would be useful for a
> number of things, not just Scheme.  (I considered adding this to
> gcc.  Part of my motivation is that the recommended way to 
> implement multiple inheritance in C++ is to use a "thunk" - which
> is a short stub function that tail-calls another function.)
> 
> One problem with tail-call elimination is that standard calling
> convention are not designed for it.  A tail-call involves:
> a) Evaluating the parameters,
> b) popping the current stack frame (including restoring registers), and
> c) jumping the the called procedure.
> In the worst case, the compiler may need to emit most of the
> function epilogue multiple times, so you use extra code space,
> though you save on stack space.
> 
> A calling convention better optimized for Scheme should make
> tail-call-elimination faster and easier to implement, and could
> also improve closures and continuations.  The C compiler would
> nned to be able to mix calling conventions - one idea would be
> to extend the 'extern "C"' convention of C++:
> 
>   extern "C" int foo(int); /* Using C linkage and calling conventions */
>   extern "C++" int bar(int); /* Using C++ conventions */
>   extern "Scheme" int foo(int); /* Using Scheme conventions */

In case you haven't seen it already, you might be interested in
the following paper on doing tail recursion (as well as precise GC) in C:

"CONS Should Not CONS its Arguments, Part II: Cheney on the MTA"

ftp://ftp.netcom.com/pub/hb/hbaker/CheneyMTA.html (also .ps.Z) and
ftp://ftp.netcom.com/pub/hb/hbaker/cboyer13.c

(The Boyer Benchmark writtin in this style of ANSI C.)

-- 
www/ftp directory:
ftp://ftp.netcom.com/pub/hb/hbaker/home.html
