[Implemented] Labels local to procedures

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

[Implemented] Labels local to procedures

Post by luis »

WHAT:

Labels local to procedures.

WHY:

Useful for example to name an exit point LBL_ERROR: and jump to it using GOTO.

This will permit to use LBL_ERROR in any proc without the need to append something to the name to make it unique.

And it will take care of errors while cutting/pasting some code from a proc to another leaving a goto to a label inside another procedure if you forget to update it to the local label.


SEE:
Fred wrote: I will change label's scope to be local to procedure to avoid such syntax.
http://www.purebasic.fr/english/viewtop ... 88#p320088

ATM not available in PB 4.50.

Thanks!
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Labels local to procedures

Post by luis »

For now I'm trying to use FASM's anonymous labels (@@) in my (fake) TRY/CATCH constructs.

Unfortunately the use of FASM's local labels like someone proposed in some other thread (a label preceded by a dot like .label) is not feasible because the ASM code generated by PB uses global labels and:
FASM manual wrote: The label whose name begins with dot is treated as local label, and its name
is attached to the name of last global label (with name beginning with
anything but dot) to make the full name of this label. So you can use the
short name (beginning with dot) of this label anywhere before the next global
label is defined
, and in the other places you have to use the full name.
For what I saw PB doesn't use anonymous labels and so this method should work.

Obviously this way one can have only one CATCH point but you can treat different error codes there (the equivalent of real exceptions) with some if/select.

All of this could be avoided if it would possible to generate a unique (and so local-like) label using #PB_Compiler_Procedure as the base for the name but for what I know it's not possible. Right ?
Last edited by luis on Mon Nov 05, 2012 9:10 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Labels local to procedures

Post by luis »

Fred, can you say if we'll have local labels in the foreseeable future ?

I would like to not depend too extensively on the trick above as I'm doing.

Thanks.
"Have you tried turning it off and on again ?"
A little PureBasic review
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Labels local to procedures

Post by Fred »

I had done some work on it for 4.60, but it wasn't finished in time. Could be in a next version, but as always, no promises.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Labels local to procedures

Post by luis »

Thank you for the answer (and naturally for working on it) :wink:
"Have you tried turning it off and on again ?"
A little PureBasic review
ColeopterusMaximus
User
User
Posts: 66
Joined: Fri Oct 29, 2010 11:29 am

Re: Labels local to procedures

Post by ColeopterusMaximus »

Fred wrote:I had done some work on it for 4.60, but it wasn't finished in time. Could be in a next version, but as always, no promises.
God bless you.

Please Fred tell me that you're fixing the on error goto jumps too... please please please.
Post Reply