This is the mail archive of the guile@cygnus.com mailing list for the guile project.


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

Re: finite state machines in guile



> There's a C compiler that optimizes tail calls? Where? There is no
> requirement in any standard that C prorams should be able to tail-call in
> constant space, and I'm not sure if it's even possible with all ABIs..

OK, after experimenting with egcs-1.1b, I'll back off a little. It WILL
optimise tail recursion (i.e. the function tail-chaining to itself)
but WON'T optimise tail calls (the function tail-chaining to some
other function). It won't properly optimise a mutually recursive pair
either, even when they are both defined in the same file.

Strangely, it won't optimise a tail recursion for
a function returning void (this surely has to be a bug because the
conditions for a void recursion should be more relaxed than for a
return value recursion -- should this go to egcs-bug@cygnus.com,
I have the example code still)

> And definitely not possible with debugging, you need to have the stack
> frames in store. I wouldn't want to lose gdb backtraces 150 calls deep
> anyway. :)

OK, this is one of the oldest sources of confusion when using gcc.
Basically, as soon as you turn the optimiser on, you get no guarantees
about code being debuggable. In my opinion, you shouldn't be debugging
optimised code unless you just want to take a quick peek at something.

Unless you allow the optimiser to break the debugger, you don't have
sufficient freedom to optimise.

> And this is of course just another point to prove that C can't be used
> well as a portable assembler.. :(

The point of this comment is completely lost on me. Your purpose when
compiling a program is to produce binary code that has the same behaviour as
you have described with your C code. You have no business trying to
specify to the compiler exactly where you want each jump -- so long as
the behaviour is guaranteed consistent.

Naturally, if you want to debug, you want to be able to turn optimisation
on and off, or turn on/off special optimisation features like
``-fomit-frame-pointer''. It's also important to be able to audit the
compiler's results to see that it functions as you might expect.

	- Tel