[Implemented] #PB_Label
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
[Implemented] #PB_Label
Hi,
A little wish again...
An #PB_Label option for Defined would be very helpful.
Best regards
Wolf
A little wish again...
An #PB_Label option for Defined would be very helpful.
Best regards
Wolf
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Its not possible as labels can be used before they are declared, and PB is a one-pass compiler:
Code: Select all
CompilerIf Defined(mylabel, #PB_Label) ; how do we know there will be a "mylabel:" later ?
CompilerEndIf
; ...
mylabel:
quidquid Latine dictum sit altum videtur
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
I thought I understood the one-pass compiler concept until I realized one day that while I can't do this:
without having the procedure declared first, which makes perfect sense, why is it that I can do this:
when, due to the one-pass operation, the compiler seemingly shouldn't know where ?label is?
There must be something I'm missing, as this has puzzled me for quite a long time.
Code: Select all
DoIt()
Procedure DoIt()
; do something
EndProcedure
Code: Select all
CatchImage(0, ?label)
; lots of lines of code
DataSection
label: Includebinary "image.bmp"
EndDataSection
There must be something I'm missing, as this has puzzled me for quite a long time.
BERESHEIT
For procedures, the compiler has to know the parameters and returntype
to generate the right code and show correct error messages.
For labels all that isn't needed, thats why it is possible to simply assume the label exists
and fire an error at the very end if it isn't found.
[edit] must type faster...
to generate the right code and show correct error messages.
For labels all that isn't needed, thats why it is possible to simply assume the label exists
and fire an error at the very end if it isn't found.
[edit] must type faster...

quidquid Latine dictum sit altum videtur
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
ehh! look at this:nope, butyes.
So:should be nope, but:should be yes. Respected the one compilation pass 
Code: Select all
If Defined(var,#PB_Variable)
Debug "yes":Else:Debug "nope"
EndIf
var.l
Code: Select all
var.l
If Defined(var,#PB_Variable)
Debug "yes":Else:Debug "nope"
EndIf
So:
Code: Select all
If Defined(var,#PB_Label)
Debug "yes":Else:Debug "nope"
EndIf
var:
Code: Select all
var:
If Defined(var,#PB_Label)
Debug "yes":Else:Debug "nope"
EndIf

That would be very inconsistent:
As i said, labels are quite different from other things in PB.
Since a label can be accessed before it is defined, Defined() should also reflect this,
but this isn't possible.
Code: Select all
x = ?mylabel ; perfectly valid
Debug Defined(mylabel, #PB_Label) ; returns 0, even though mylabel is accessible !?
mylabel:
Since a label can be accessed before it is defined, Defined() should also reflect this,
but this isn't possible.
quidquid Latine dictum sit altum videtur
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
But... if compiler knows what is ?mylabel , why some like this couldn't work?
Code: Select all
x = ?mylabel ; perfectly valid
Debug Defined(?mylabel, #PB_Label)
mylabel:
wouldn't it be possible to let the fasm compiler handle this, like converting the Defined() command for this case to asm macro instructions
!if defined label
debug "label defined"
!else
debug "label undefined"
!end if
well.. would be the 'dirty' way but possible i think.. don't know atm how pb defines labels intern and can't check 'cause i'm at uni atm :p
!if defined label
debug "label defined"
!else
debug "label undefined"
!end if
well.. would be the 'dirty' way but possible i think.. don't know atm how pb defines labels intern and can't check 'cause i'm at uni atm :p