|
From: | Marc Nieper-Wißkirchen |
Subject: | Re: [Lightning] Are tail calls possible in GNU lightning? |
Date: | Sat, 10 Jan 2015 08:23:12 +0100 |
2015-01-09 19:55 GMT-02:00 Marc Nieper-Wißkirchen <address@hidden>:
> P.S.: I have written a small example program that demonstrates what I want
> to achieve:
>
> #include <stdio.h>
> #include <lightning.h>
>
> static jit_state_t *_jit;
>
> jit_node_t *compile() {
> jit_state_t *_jit;
> _jit = jit_new_state();
> jit_prolog();
> jit_node_t *label = jit_indirect();
> jit_reti(42);
> jit_emit();
> jit_clear_state();
> return jit_address(label);
> }
This will leak a jit_state_t, but I presume it is only for example,
otherwise, need to jit_destroy_state it once no longer used.
> int main(int argc, char* argv[]) {
>
> int (*code)();
>
> jit_node_t *jump, *label, *ref;
>
> init_jit(argv[0]);
> _jit = jit_new_state();
>
> jit_prolog();
> jit_prepare();
> jit_finishi(compile);
This works because neither function receives (stack) arguments,
but if whatever "compile" returns needs more arguments than the
code calling it, it will corrupt the stack. Lightning could fix some
of the cases (same jit_context_t calling jit compiled functions),
> jit_retval(JIT_R0);
> jit_jmpr(JIT_R0);
This will not work on some backends, like ia64 or big endian
powerpc (function descriptors), or, mips or little endian powerpc
where the function pointer must be in a specific register, to
compute GOT, PIC, etc. hppa also needs some special
handling. Also, for the sake of simplicity/safety, lightning would
still need to spill/reload modified callee save registers.
[Prev in Thread] | Current Thread | [Next in Thread] |