[Gambas-user] Gambas has Gosub now!

Benoît Minisini gambas at ...1...
Mon Mar 5 00:46:43 CET 2012


Le 04/03/2012 10:16, Benoît Minisini a écrit :
> Le 04/03/2012 02:23, Benoît Minisini a écrit :
>>
>> You are right, I didn't think about that. So the current design does not
>> work, and I don't have another one.
>>
>> I will remove GOSUB if it cannot be implemented in a right way. :-/
>>
>> Regards,
>>
>
> Here is the only solution I found in revision #4531:
>
> * Now I use a dedicated control variable set for each GOSUB subroutine.
>
> * GOSUB labels now must be at top-level, and must be declared *after*
> the GOSUB call. Consequently, recursion is not possible anymore.
>
> I hope that GOSUB is still useful!
>

Here is a new implementation of GOSUB in revision #4534.

GOSUB can be used on any top-level label now.

GOSUB can be recursive now, because control variables are saved and 
restored on the RETURN instruction.

GOSUB is still faster than calling a true method, and far faster when 
using recursion. Stack allocation is heavier, and slower and slower as 
far as the recursion level grows (dunno why). GOSUB does not have that 
problem.

Enjoy it!

-- 
Benoît Minisini




More information about the User mailing list