Page 1 of 1
[Implemented] #PB_Label
Posted: Tue Nov 20, 2007 3:17 am
by Hroudtwolf
Hi,
A little wish again...
An #PB_Label option for Defined would be very helpful.
Best regards
Wolf
Posted: Tue Nov 20, 2007 4:03 pm
by Psychophanta
I Second it

Posted: Tue Nov 20, 2007 5:04 pm
by freak
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:
Posted: Tue Nov 20, 2007 5:25 pm
by netmaestro
I thought I understood the one-pass compiler concept until I realized one day that while I can't do this:
Code: Select all
DoIt()
Procedure DoIt()
; do something
EndProcedure
without having the procedure declared first, which makes perfect sense, why is it that I can do this:
Code: Select all
CatchImage(0, ?label)
; lots of lines of code
DataSection
label: Includebinary "image.bmp"
EndDataSection
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.
Posted: Tue Nov 20, 2007 5:28 pm
by Fred
Actually, "?" operand only work with a label, so we "pre-declare" the label (and check for real declaration at the very end of the program). That's a little exception, that's true.
Posted: Tue Nov 20, 2007 5:30 pm
by freak
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...

Posted: Tue Nov 20, 2007 7:03 pm
by Hroudtwolf
It's a great pity.

But, thanks for the explanations.
Posted: Tue Nov 20, 2007 7:56 pm
by Psychophanta
I believed that labels just was treated as simple long type variables (pointers) internally.
Maybe if there was like that, things would be easier.

Posted: Tue Nov 20, 2007 8:03 pm
by Psychophanta
ehh! look at this:
Code: Select all
If Defined(var,#PB_Variable)
Debug "yes":Else:Debug "nope"
EndIf
var.l
nope, but
Code: Select all
var.l
If Defined(var,#PB_Variable)
Debug "yes":Else:Debug "nope"
EndIf
yes.
So:
Code: Select all
If Defined(var,#PB_Label)
Debug "yes":Else:Debug "nope"
EndIf
var:
should be nope, but:
Code: Select all
var:
If Defined(var,#PB_Label)
Debug "yes":Else:Debug "nope"
EndIf
should be yes. Respected the one compilation pass

Posted: Tue Nov 20, 2007 8:11 pm
by freak
That would be very inconsistent:
Code: Select all
x = ?mylabel ; perfectly valid
Debug Defined(mylabel, #PB_Label) ; returns 0, even though mylabel is accessible !?
mylabel:
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.
Posted: Tue Nov 20, 2007 8:45 pm
by Psychophanta
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:
Posted: Tue Nov 20, 2007 9:11 pm
by freak
read the full post please. Fred and I explained it... :roll:
Posted: Fri Nov 30, 2007 1:40 pm
by pcfreak
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