On Tue, 15 Jul 2008 07:45:04 +0200, Basile STARYNKEVITCH wrote:

> Ning Wang wrote:
>> Hi all,
>> 
>> I'm working on a project to compile C to C--.  My compiler can compile
>> c99 compliant code.  I want to regenerate C code from C-- code as a
>> means to test the complier.
>> If you have written a C-- to C translator, or are aware where I can
>> find one, could you please kindly let me know?
> 
> I believe it should not be possible in the general case, because C-- has
> some feature (like tailrecursion) missing in C.

There is a way of doing this.  Implement tail recursion by a regular 
procedure call, passing it a continuation, but never return -- just call 
the continuatino instead.

The stack will grow like mad.

Every now and then, when the stack gets uncomfortably big, do a longjump 
out of the whole stack of never-to-be-used activation records, and let 
the code at longjump target call your continuation for you.

If you want, you can also allocate heap storage on the stack, if you are 
careful to do a copying garbage collection before the longjump -- one 
that moves objects that are still alive to a longer-term heap.

-- hendrik

_______________________________________________
Cminusminus mailing list
[email protected]
https://cminusminus.org/mailman/listinfo/cminusminus

Reply via email to