> On Feb 22, 2017, at 12:03 PM, Stefan Israelsson Tampe
> <[email protected]> wrote:
> With this we should be able to actually compile guile scheme via the vm ops
> to C and then gcc to position independent machine code. The main obstacles to
> use this is that a) C calls are not tail calls and b) it is difficult to
> manage the stack as we do in guile and have native code interoperate with vm
> code.
In your dev process are you looking at intermediate stages of .c -> .o to see
if gcc is generating tail-calls? I’m guessing it will (w/ -O2) in many cases.
mwette$ cat sum.c
#include <stdio.h>
int sum(int total, int top) {
if (top == 1) return total+top;
else sum(total+top, top-1);
}
int main() { printf("%d\n", sum(0, 5)); }
mwette$ cat sum.s. # where gcc -O2 [-S] produces tail call in sum()
_sum:
LFB1:
jmp L10
.align 4,0x90
L7:
addl %esi, %edi
subl $1, %esi
L10:
cmpl $1, %esi
jne L7
leal 1(%rdi), %eax
ret
Matt