bitwise operations
This commit is contained in:
+31
-2
@@ -27,7 +27,7 @@ roadmap and milestone history.
|
||||
|
||||
- exact-width integers, concrete pointer-sized `isize` / `usize`, `f32`, `f64`, `bool`, `void`, and `anyopaque`; contextual `int` accepts the whole integer family, while `uint` accepts only unsigned native and target-classified C integers
|
||||
- target-dependent C scalar primitives from `c_char` through `c_longdouble`, kept semantically distinct from native scalars
|
||||
- contextual integer/float/character literals, backward type-demand inference through names and arithmetic, and compile-time folding for numeric constant expressions
|
||||
- contextual integer/float/character literals, backward type-demand inference through names and arithmetic/bitwise expressions, and typed compile-time evaluation for numeric constant expressions
|
||||
- strict numeric conversion by default, widening where valid, C scalar coercions at C boundaries, and explicit scalar keyword casts such as `i32(x)` / `c_float(x)`
|
||||
- compile-time `minval!(T)` and `maxval!(T)` bounds for concrete native and C integer scalar types
|
||||
- arrays `[N]T`, inferred-count arrays `[_]T`, sentinel arrays `[N;S]T`, compile-time expression array counts, slices `[]T` / `[;S]T`, single-item pointers `@T`, many-item pointers `*T`, and sentinel many-item pointers `[*;S]T`
|
||||
@@ -90,7 +90,8 @@ fields. `_` is not a keyword member name.
|
||||
### expressions and control flow
|
||||
|
||||
- checked integer `+ - *`, unary `-`, float-only `/`, IEEE float arithmetic, comparisons, `!`, `and`, and `or`
|
||||
- assignments and compound assignments `+= -= *= /=` with single evaluation of complex lvalues; `/=` is float-only
|
||||
- Zig-style integer bitwise complement `~`, binary `&`, `|`, `xor`, shifts `<<` / `>>`, and saturating left shift `<<|`; postfix `^` remains pointer dereference
|
||||
- assignments and compound assignments `+= -= *= /= &= |= xor= <<= >>= <<|=` with single evaluation of complex lvalues; `/=` is float-only and `xor=` is contiguous
|
||||
- field access through struct values and pointers, index/slice bounds contextually coerced to `usize`, and unsigned narrower index support
|
||||
- boolean `if` / `else if` / `else` and `for` loops with braceless single-statement bodies when the preceding expression is parenthesized or a function call
|
||||
- `while` loops with optional post-iteration update clauses
|
||||
@@ -103,6 +104,34 @@ fields. `_` is not a keyword member name.
|
||||
- fallible `try`, fallback `catch`, and `catch |e| { ... }` handler blocks
|
||||
- direct `return match ...` and `yield match ...` value-control-flow operands
|
||||
|
||||
#### bitwise operations
|
||||
|
||||
Bitwise operands must be concrete integers. `~` preserves its operand type. `&`, `xor`, and `|`
|
||||
use the ordinary common-integer widening rules; incompatible fixed integer families remain errors.
|
||||
Shifts preserve the left operand type and require a concrete unsigned count. `>>` is arithmetic for
|
||||
signed integers and logical for unsigned integers.
|
||||
|
||||
Ordinary `<<` and `>>` reject compile-time-known counts at least as large as the left type's bit
|
||||
width and trap for such runtime counts. `<<` discards shifted-out bits. Saturating `<<|` permits any
|
||||
unsigned count: zero remains zero, unsigned nonzero values clamp to the type maximum, and signed
|
||||
values clamp to the minimum or maximum according to their sign.
|
||||
|
||||
Binary precedence, from tightest to loosest, is:
|
||||
|
||||
```text
|
||||
* /
|
||||
+ -
|
||||
<< >> <<|
|
||||
& xor |
|
||||
== != < > <= >=
|
||||
and
|
||||
or
|
||||
```
|
||||
|
||||
Each level is left-associative. Because `|` also delimits `if` and `for` captures, a bitwise-OR
|
||||
header expression must be parenthesized before a capture list, for example
|
||||
`if (flags | mask) |value| { ... }`.
|
||||
|
||||
#### division
|
||||
|
||||
Compiler intrinsics use direct unqualified `name!(...)` syntax. The `!` marks the call as an
|
||||
|
||||
Reference in New Issue
Block a user