Conditional Macros .



The  #If  Keywords


All Conditional Statements begin with a '#' Char:


#If....

    ; Do this

#Else_If....

    ; Do that

#Else

    ; Do in other cases

#End_If


These '#If' Statements can be nested, and the cases of unpairings raise an error Message.



The Conditions


You can test the Macros Evocations Parameters, on Types and Sizes, the Internal Strings on Contents, the Number of Parameters in the Evocation, and the Internal Counters on Contents.



Testing the Types&Sizes


The Types are:    reg, mem, imm, str, sym


... standing for:   register, memory, immediate, string, symbol.


The str (string) Condition, for example, that is:


Else_If  #1=str


... addresses the cases of direct Strings, in the form of:


MyMacro  'My String'


Notice that all Conditions are to be given without any spaces inside. That is, for example:


#1=reg


... never:


#1 = reg



The Sizes are the usual ones, as found in the Sizes Markers List:


B, W, D, Q, F, R, X


Example:


#If  #1=reg

    #If  #1=D

        ; Do this with a dWord Register

    #Else

        ; Do that with other Sizes Registers

    #End_If

#End_If



Testing the Number of Parameters


The 'N' Condition tests the Number of Parameters, in the Evocation. Example:


#If  #N=0

      push 0

#Else

      push #1

#End_If



Testing the Internal Strings


Let us recall that the Internal Strings (the &1,.... &99 thingies), are implemented, in the normal Macros Engine, for storing strings. That is, when you say, for example:


... | &5=12345 | ... &7=#2 |...


... what is stored in the Internal Strings are nothing but the ''12345'' String or the ''Parameter_2'' String.


So, what you can test, with the Conditional Macros, is the content of an Internal String, to know if the room is free or not:


#If  &55=0


or


#If  &55<>0


Notice that you cannot, both at the same time, inside the same Macro Declaration, set up some Internal String and test its content. If  the Internal String was empty before the Macro Evocation, it will still be empty when the Conditional Macro parser considers the content.



Testing the Internal Counters


The only tests actually implemented are for 'empty' / 'not empty' state:


#If &&55=0


#If &&60<>0


For more, see Internal_Counters.



The #Error Statement


Inside Conditional Macros, you can make use of User Defined Error Messages, assuming your own cases of misusage in your own Macros.


Example:


[MyConditionalMacro

; ...

#If  #1=reg

    ; Do this

#Else

    #Error  'MyConditionalMacro works only with Registers'

#End_If

...

#+1]



The #ErrorPos Statement


The Internal Counter also accepts (normal Macros engine) a Statement saying:


... | &&2=Pos | ...


What is then stored, inside the Internal String is the Source Position, at the Macros Job time. This feature is useful for forcing the RosAsm Error Manager (the Compile Time Error Manager), to point to a Source Location that you have defined that way, when stating:


#If &&2<>48

    #ErrorPos &&2,  'Unpaired use of the While Macro'

#End_If


(48 stands for Ascii '0')


In this example of ''While // End_While'' Macros usage, you can make an unpairing error. If you test the content of an internal Counter, - that you use for defining the ''W0 to W9'' Local Label -, at the very first ''While'', and find it to not be ''W0'', this means that an unpairing error has been committed previously. So, this feature offers you to define where, in your Source, the error should be pointed out: not on the actual first ''While'', but on the previous ''While'', that can be, as well, several pages above, in your Source.



General Usage


You can, of course make use of the usual Macro Loop, for testing the Parameters, say, one by one, with the usual '#+1'.


~~~~~~~