You can always hack the compiler/bytecode to be able to have gotos wherever you want, but I think Gotos is not allowed to jump into control structures because it is classed as "bad code structure". For ... Next also use hidden local variables to store things.
But I think gosubs can be implemented in the compiler and only having to do small changes to the interpreter, since using jumps/gotos to "return" into control structures is not a problem because the hidden local control variables can be guaranteed to be unchanged: The compiler must analyze all the calls to a gosub and see how many control structure variables that are occupied before entering it (the depth), so the Gosub doesn't overwrite them. One can use a control variable to store the return address of the Gosub, if they are only allowed as leaf functions. /Emil 2012/3/2 Jussi Lahtinen <jussi.lahti...@gmail.com> > I made quick effort to try to simulate gosub with goto, > and noticed that jumping back inside loops is not possible (as the > documentation says...). > > I understand that when it's For ... Next, but shouldn't that be possible > with Do ... Loop Until x? > > Anyway, I'm not sure my simulation does accurately compare speed of Sub to > Gosub... if it does, > then gosub would be 2 to 3 times faster. > > Jussi > > PS. Try to change last line "End" to "EndEnd" and then try to compile! > > > > > 2012/3/2 Benoît Minisini <gam...@users.sourceforge.net> > > > Le 25/02/2012 19:18, nando a écrit : > > > Benoit, > > > > > > I came across the need to call many different common small pieces of > > code multiple times. > > > Naturally, we tend to make a SUB just for all of them. > > > > > > I wondered if you'd consider resurrecting GOSUB {label} > > > which is in the same sub. > > > > > > It would be in the same scope, no parameters allowed and > > > acts just like a leaf subroutine with only return on the stack > > > and no formal stack frame. It's also part compromise to embedded SUBs > > > > > > Would overal execution run faster ? > > > > > > ?? > > > -Fernando > > > > > > > It may be a little bit faster. You can check that by simulate the GOSUB > > with some GOTOs and compare the speed with a similar function call. > > > > Anyway, there is a syntax problem. In Basic, GOSUB is ended by a RETURN > > instruction, but RETURN is already used to exit the all function. Or > > maybe RETURN will return from the function only if there is no pending > > GOSUB. > > > > Can you test if there is any speed gain I as said above? I don't have > > the time to do that now. If the speed gain is worth it, then I may > > implement GOSUB! > > > > Regards, > > > > -- > > Benoît Minisini > > > > > > > ------------------------------------------------------------------------------ > > Virtualization & Cloud Management Using Capacity Planning > > Cloud computing makes use of virtualization - but cloud computing > > also focuses on allowing computing to be delivered as a service. > > http://www.accelacomm.com/jaw/sfnl/114/51521223/ > > _______________________________________________ > > Gambas-user mailing list > > Gambas-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/gambas-user > > > > > ------------------------------------------------------------------------------ > Virtualization & Cloud Management Using Capacity Planning > Cloud computing makes use of virtualization - but cloud computing > also focuses on allowing computing to be delivered as a service. > http://www.accelacomm.com/jaw/sfnl/114/51521223/ > _______________________________________________ > Gambas-user mailing list > Gambas-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gambas-user > > ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user