-
Notifications
You must be signed in to change notification settings - Fork 17
bitwise expression
The bitwise “or”, “xor”, and “and” expressions are well-known expression forms, as are the various bit-shift expressions:
a & b
a | b
a ^ b
a << b
a >> b
a >>> b
The Ecstasy language places all of these operators together into a single precedence level, treating them all almost as if they were lower-precedence addition and subtraction operations. This choice reflects the number of parentheses necessary to do common operations in both Java/C# and C/C++ using these operators, and the potential for errors (and unreadability) that arises as a result.
Op | Default method name | Description |
---|---|---|
& |
and |
bitwise-and |
| |
or |
bitwise-or |
^ |
xor |
bitwise-exclusive-or |
<< |
shiftLeft |
bit-shift left |
>> |
shiftRight |
bit-shift right |
>>> |
shiftAllRight |
unsigned bit-shift right |
Despite appearing to be primitive-type operators, Ecstasy has no primitive type system, and the input and output types of these operators are defined entirely by the types against which the operators execute. Specifically, the type of the expression a
must have an unambiguously single best operator method (selected by the operator symbol and method name) that takes an argument of the type of expression b
. The implicit type of the expression is the return type of the operator method.
The execution of the expression is an invocation of the selected operator method, against a target reference yielded by the expression a
, passing one argument as yielded by the expression b
; the result of the expression is the return value from the operator method.
The expression short-circuits if either expression a
or b
short-circuits.
The expression uses the default left-to-right definite assignment rules:
- The VAS before
a
is the VAS before the expression. - The VAS before
b
is the VAS aftera
. - The VAS after the expression is the VAS after
b
.
These expressions group to the left, so for example, a | b | c
is treated as (a | b) | c
:
BitwiseExpression: AdditiveExpression BitwiseExpression & AdditiveExpression BitwiseExpression | AdditiveExpression BitwiseExpression ^ AdditiveExpression BitwiseExpression << AdditiveExpression BitwiseExpression >> AdditiveExpression BitwiseExpression >>> AdditiveExpression