Re: [Flashforth-devel] jumping without a return
Brought to you by:
oh2aun
From: Christopher H. <chr...@li...> - 2021-04-22 13:51:49
|
The goal is to make a call to the function /without/ growing the return stack. An example would be tail call optimization in a language like scheme. In that specific example, you would be calling the same function recursively, but the optimization would prevent you from growing the return stack. It would also be helpful for things like mutual recursion. E.g., in gforth: : foo 124 emit s" bar" evaluate ; : bar 43 emit s" foo" evaluate ; This does not work however, because the return stack quickly overflows. However, if I had another version of execute, which worked exactly like execute normally does, but does not place a return value on the stack, then it would work. : foo 124 emit s" ' bar myexecute" evaluate ; : bar 43 emit s" ' foo myexecute" evaluate ; I have not seen that forth has a built-in word for this, but thought maybe you knew how it could be done with other ff5-specific words. -- Christopher Howard blog: https://librehacker.com social: https://gnusocial.club/librehacker On Thu, 2021-04-22 at 14:36 +0300, Mikael Nordman wrote: > I am not sure what you are after, but the Forth way is to use > EXECUTE. If you give an address to EXECUTE > on the parameter stack, the code execution will continue at that > address. > > 12 ok<$,ram> 12 > 2+ ok<$,ram> 14 > ' 2+ ok<$,ram> 14 15b8 > execute ok<$,ram> 16 > > Any other solution must revert to ATmega assembler to compile a jmp > or ijmp. > > In order to not break the Forth there must by a return address on the > stack. That gets you back to after the address where EXECUTE was > executed. > > What do you want to achieve ? > > On 2021-04-22 04:06, Christopher Howard wrote: > > > Hi, I was wondering if in FlashForth there was some trick to > > execute a word without throwing anything on the return stack? Kind > > of like you would with a tail call recursion, but in any arbitrary > > place? It looks like there are some jumping instructions in ff5 > > reference but I don't understand how to use them. I'm thinking in > > avr context if that makes a difference. > > > > Christopher Howard > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |