Target Language Compiler |
 |
Target Language Expressions
In any place throughout a target file, you can include an expression of the form %<
expression
>
. The Target Language Compiler replaces %<
expression
>
with a calculated replacement value based upon the type of the variables within the %<>
operator. Integer constant expressions are folded and replaced with the resultant value; string constants are concatenated (e.g., two strings in a row "a"
"b"
are replaced with "ab"
).
Within the context of an expression, each identifier must evaluate to an identifier or function argument currently in scope. You can use the %< >
directive on any line to perform textual substitution. To include the >
character within a replacement, you must escape it with a "\
" character as in
The Target Language Expressions table lists the operators that are allowed in expressions. In this table, expressions are listed in order from highest to lowest precedence. The horizontal lines distinguish the order of operations.
As in C expressions, conditional operators are short circuited. If the expression includes a function call with effects, the effects are noticed as if the entire expression was not fully evaluated. For example,
If the first term of the expression evaluates to a Boolean false (i.e., foo
does not exist), the second term (foo == 3
) will not be evaluated.
In the following table, note that "numeric" is one of the following:
Boolean
Number
Unsigned
Real
Real32
Complex
Complex32
Gaussian
UnsignedGaussian
Also, note that "integral" is one of the following:
See TLC Data Promotions for information on the promotions that result when the Target Language Compiler operates on mixed types of expressions.
Table 6-3: Target Language Expressions
Expression
|
Definition
|
constant
|
Any constant parameter value, including vectors and matrices
|
variable-name
|
Any valid in-scope variable name, including the local function scope, if any, and the global scope
|
::variable-name
|
Used within a function to indicate that the function scope is ignored when looking up the variable. This accesses the global scope.
|
expr[expr]
|
Index into an array parameter. Array indices range from 0 to N-1 . This syntax is used to index into vectors, matrices, and repeated scope variables.
|
expr([expr[,expr]...])
|
Function call or macro expansion. The expression outside of the parentheses is the function/macro name; the expressions inside are the arguments to the function or macro. Note: Since macros are text-based, they cannot be used within the same expression as other operators.
|
expr. expr
|
The first expression must have a valid scope; the second expression is a parameter name within that scope.
|
(expr)
|
Use () to override the precedence of operations.
|
!expr
|
Logical negation (always generates TLC_TRUE or TLC_FALSE ). The argument must be numeric or Boolean.
|
-expr
|
Unary minus negates the expression. The argument must be numeric.
|
+expr
|
No effect; the operand must be numeric.
|
~expr
|
Bitwise negation of the operand. The argument must be integral.
|
expr * expr
|
Multiply the two expressions together; the operands must be numeric.
|
expr / expr
|
Divide the two expressions; the operands must be numeric.
|
expr % expr
|
Take the integer modulo of the expressions; the operands must be integral.
|
expr + expr
|
Works on numeric types, strings, vectors, matrices, and records as follows: Numeric Types - Add the two expressions together; the operands must be numeric. Strings - The strings are concatenated. Vectors - If the first argument is a vector and the second is a scalar, it appends the scalar to the vector. Matrices - If the first argument is a matrix and the second is a vector of the same column-width as the matrix, it appends the vector as another row in the matrix. Records - If the first argument is a record, it adds the second argument as a parameter identifier (with its current value). Note, the addition operator is associative.
|
expr - expr
|
Subtracts the two expressions; the operands must be numeric.
|
expr << expr
|
Left shifts the left operand by an amount equal to the right operand; the arguments must be integral.
|
expr >> expr
|
Right shifts the left operand by an amount equal to the right operand; the arguments must be integral.
|
expr > expr
|
Tests if the first expression is greater than the second expression; the arguments must be numeric.
|
expr < expr
|
Tests if the first expression is less than the second expression; the arguments must be numeric.
|
expr >= expr
|
Tests if the first expression is greater than or equal to the second expression; the arguments must be numeric.
|
expr <= expr
|
Tests if the first expression is less than or equal to the second expression; the arguments must be numeric.
|
expr == expr
|
Tests if the two expressions are equal.
|
expr != expr
|
Tests if the two expression are not equal.
|
expr & expr
|
Performs the bitwise AND of the two arguments; the arguments must be integral.
|
expr ^ expr
|
Performs the bitwise XOR of the two arguments; the arguments must be integral.
|
expr | expr
|
Performs the bitwise OR of the two arguments; the arguments must be integral.
|
expr && expr
|
Performs the logical AND of the two arguments and returns TLC_TRUE or TLC_FALSE . This can be used on either numeric or Boolean arguments.
|
expr || expr
|
Performs the logical OR of the two arguments and returns TLC_TRUE or TLC_FALSE . This can be used on either numeric or Boolean arguments.
|
expr ? expr : expr
|
Tests the first expression for TLC_TRUE . If true, the first expression is returned; otherwise the second expression is returned.
|
expr , expr
|
Returns the value of the second expression.
|
Note
Relational operators ( <, =<, >, >=, !=, == ) can be used with nonfinite values.
|
Reminder It is not necessary to place expressions in the %< >
"eval" format when they appear on directive lines. Doing so causes a double evaluation.
TLC Data Promotions
When the Target Language Compiler operates on mixed types of expressions, it promotes the result to the common types indicated in the following table.
This table uses the following abbreviations:
B
|
Boolean
|
N
|
Number
|
U
|
Unsigned
|
F
|
Real32
|
D
|
Real
|
G
|
Gaussian
|
UG
|
UnsignedGaussian
|
C32
|
Complex32
|
C
|
Complex
|
The top row (in bold) and first column (in bold) show the types of expression used in the operation. The intersection of the row and column shows the resulting type of expression.
For example, if the operation involves a Boolean expression (B
) and an unsigned expression (U
), the result will be an unsigned expression (U
).
Table 6-4: Datatypes Resulting from Expressions of Mixed Type
|
B
|
N
|
U
|
F
|
D
|
G
|
UG
|
C32
|
C
|
B
|
B
|
N
|
U
|
F
|
D
|
G
|
UG
|
C32
|
C
|
N
|
N
|
N
|
U
|
F
|
D
|
G
|
UG
|
C32
|
C
|
U
|
U
|
U
|
U
|
F
|
D
|
UG
|
UG
|
C32
|
C
|
F
|
F
|
F
|
F
|
F
|
D
|
C32
|
C32
|
C32
|
C
|
D
|
D
|
D
|
D
|
D
|
D
|
C
|
C
|
C
|
C
|
G
|
G
|
G
|
UG
|
C32
|
C
|
G
|
UG
|
C32
|
C
|
UG
|
UG
|
UG
|
UG
|
C32
|
C
|
UG
|
UG
|
C32
|
C
|
C32
|
C32
|
C32
|
C32
|
C32
|
C
|
C32
|
C32
|
C32
|
C
|
C
|
C
|
C
|
C
|
C
|
C
|
C
|
C
|
C
|
C
|
| Target Language Values | | Formatting |  |