From: Duncan Sands <baldrick@free.fr>
To: comp.lang.ada@ada-france.org
Cc: "Chad R. Meiners" <chad.rmeiners@gmail.com>
Subject: Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)
Date: Fri, 14 Jan 2005 09:32:36 +0100
Date: 2005-01-14T09:32:36+01:00 [thread overview]
Message-ID: <mailman.49.1105691581.527.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <1105653887.848989.268410@z14g2000cwz.googlegroups.com>
Hi Chad, first I commented out the Put in Fib:
begin
--Put(Int'Image(Next) & ", ");
Fib(Second,Next);
then I compiled this with gcc from CVS as follows:
> gnatmake -O2 tail
gcc -c -O2 tail.adb
tail.adb:12:01: warning: possible infinite recursion
tail.adb:12:01: warning: Storage_Error may be raised at run time
gnatbind -x tail.ali
gnatlink tail.ali
The disassembly is then:
> objdump -r -d tail.o
tail.o: file format elf32-i386
Disassembly of section .text:
00000000 <tail__fib.365>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: eb fe jmp 3 <tail__fib.365+0x3>
5: 8d 74 26 00 lea 0x0(%esi),%esi
9: 8d bc 27 00 00 00 00 lea 0x0(%edi),%edi
00000010 <_ada_tail>:
10: 55 push %ebp
11: b8 08 00 00 00 mov $0x8,%eax
12: R_386_32 .rodata
16: 89 e5 mov %esp,%ebp
18: ba 00 00 00 00 mov $0x0,%edx
19: R_386_32 .rodata
1d: 83 ec 08 sub $0x8,%esp
20: 89 04 24 mov %eax,(%esp)
23: 89 54 24 04 mov %edx,0x4(%esp)
27: e8 fc ff ff ff call 28 <_ada_tail+0x18>
28: R_386_PC32 ada__text_io__put__4
2c: 31 c0 xor %eax,%eax
2e: 89 e9 mov %ebp,%ecx
30: 89 44 24 04 mov %eax,0x4(%esp)
34: 31 d2 xor %edx,%edx
36: b8 01 00 00 00 mov $0x1,%eax
3b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
42: e8 b9 ff ff ff call 0 <tail__fib.365>
47: c9 leave
48: c3 ret
which is a bit too optimised!
Comments:
(1) I commented out the Put because I expected the "&" (string concatenation) to cause
trouble, since it uses the secondary stack.
(2) Maybe the fact that Fib is a local procedure causes problems for older gcc.
All the best,
Duncan.
next prev parent reply other threads:[~2005-01-14 8:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-13 22:04 Tail Recursion (Why it appears that Gnat 3.15p does support it) Chad R. Meiners
2005-01-14 8:32 ` Duncan Sands [this message]
2005-01-14 9:04 ` Jacob Sparre Andersen
2005-01-14 16:06 ` wojtek
2005-01-15 5:08 ` Brian May
2005-01-18 20:59 ` Chad R. Meiners
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox