Accessing The Argument List

The statement format accepted by the macro preprocessor is more flexible than that accepted by the FHDL compiler, in that a text statement may have any number of arguments. In particular, a macro call may have an arbitrary number of arguments. For example, let us assume that when the "not.m" macro defined in section 3 is used, the outputs are all of the form <name>.bar where <name> is the name of the corresponding input. To save coding time, we could eliminate the need to specify the outputs, since the name of the output can be deduced from the name of the input. Again, to save coding time, we will allow the user to specify just the input list, without the parentheses. Thus the user would code the following statement.

not.m a,b,c

This statement would produce the following output.

not a,a.bar
not b,b.bar
not c,c.bar

The definition of "not.m" would be modified as illustrated below.

not.m: 'macro
'int 'i
'assign 'i,0
'while 'i'<'count('args)
not ''i,''i#".bar"
'assign 'i,'i+1
'endwhile
'endmacro

The built-in variable 'args is a list-type variable whose value is the entire argument list of the macro call. The individual arguments are accessed using variables of the form '0, '1, '2, and so forth. The value of the variable '0 is the text of the first argument in the argument list, the value of '1 is the text of the second argument, and so forth. The variables '0 and 'ilist are identical, as are '1 and 'olist. Although all argument variables are technically of type list, the coercion rules of the preprocessor will cause these variables to assume the type string or the type list, as appropriate to their value and usage.

.The operator ' is the indirection operator. When the indirection operator is applied to an expression, the value of the expression is used as a variable name and the value of the indirectly referenced variable is returned. The ' character is prepended to the value of the expression, so the expression must not include the leading ' character. Although this looks like multipass substitution, it is not.

Finally, the "#" operator is the concatenation operator. Unlike some macro processors, the FHDL macro processor does not provide automatic concatenation of consecutive expressions.