[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lightning] Are tail calls possible in GNU lightning?
From: |
Paulo César Pereira de Andrade |
Subject: |
Re: [Lightning] Are tail calls possible in GNU lightning? |
Date: |
Sat, 10 Jan 2015 10:55:02 -0200 |
2015-01-10 5:23 GMT-02:00 Marc Nieper-Wißkirchen <address@hidden>:
>> > 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);
>> > }
> For my purposes (using a virtual stack), I will never have to do a real
> C-style function call (except when doing FFI calls). Instead there will be
> (indirect) jumps everywhere and the real stack will not be touched. Thus the
> assumption that all generated functions take the same number of parameters
> (namely 0) would be fine for me.
>
>>
>> > 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.
>>
>
> How to do indirect jumps then? In the manual to GNU lightning, the code
> jit_jmpr(R0) is used in several examples. How can I use an indirect label
> then?
It is useful for computed gotos, e.g. something like C
switch/case or choosing what virtual method to call in
a vm that has a stack in the heap.
Your specific example would be better done using
jit_frame and jit_tramp. These calls are not in a
released lightning version, but were added for
GNU Smalltalk. Examples:
http://git.savannah.gnu.org/cgit/lightning.git/tree/check/tramp.tst
http://git.savannah.gnu.org/cgit/lightning.git/tree/check/ctramp.c
Basically, "jit_frame(int size)" creates a stack frame
saving all callee save registers, and allocates at
least "size" bytes, that have as a good value, 8*
maximum number of arguments used in a C call.
After that, trampolines, but work as tail call in the
way you need it, created with "jit_tramp(int size)"
are like a normal function body, just that while it
needs calling jit_prolog and jit_epilog, it does not
generate any code, so, it is very "light" and allow
jumping from code generated by one jit_context_t
to another.
I suggest you test it. Lightning 2.0.6 should be
released shortly, and will have the feature described
above.
I will also make some experiments with "true" tail
call. For a vm that could use the real stack, and
would need to pass arguments in the proper call
sequence, the feature would be very useful, and
if available, would be used...
> Marc
Thanks,
Paulo
- [Lightning] Are tail calls possible in GNU lightning?, Marc Nieper-Wißkirchen, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Paulo César Pereira de Andrade, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Marc Nieper-Wißkirchen, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Marc Nieper-Wißkirchen, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Alex Gilding, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Paulo César Pereira de Andrade, 2015/01/09
- Re: [Lightning] Are tail calls possible in GNU lightning?, Marc Nieper-Wißkirchen, 2015/01/10
- Re: [Lightning] Are tail calls possible in GNU lightning?,
Paulo César Pereira de Andrade <=
- Re: [Lightning] Are tail calls possible in GNU lightning?, Marc Nieper-Wißkirchen, 2015/01/10
- Re: [Lightning] Are tail calls possible in GNU lightning?, Paulo César Pereira de Andrade, 2015/01/15