# 02. Types and Values ## 1. Primitive types Unsigned integers: ```text u8 u16 u32 u64 u128 usize ``` Signed integers: ```text i8 i16 i32 i64 i128 isize ``` Floating point: ```text f32 f64 ``` Other primitives: ```text bool byte void never ``` `byte` is an alias of `u8`. `usize` and `isize` match the target pointer width. ## 2. Integer semantics Normal arithmetic is checked. ```aji let c = a + b; ``` Overflow traps unless the compiler proves it impossible. Explicit alternatives: ```aji wrap_add(a, b) saturating_add(a, b) checked_add(a, b) // Option ``` Release/debug modes MUST NOT change these semantics. ### 2.1 Edge cases - Division and remainder truncate toward zero; the remainder has the sign of the dividend. - Division or remainder by zero traps (`T0004`). Signed `MIN / -1` and `MIN % -1` trap as overflow (`T0003`). - `shl` and `shr` take a shift amount of the same type as the shifted value. An amount that is negative or not less than the bit width traps (`T0005`). `shl` discards bits shifted out; `shr` is arithmetic for signed types and logical for unsigned types. - There are no implicit conversions. Explicit integer casts: - `widen`: only between types where every source value is representable in the target (unsigned to wider unsigned or wider signed, signed to wider signed); anything else is rejected statically (`E1002`). `usize` and `isize` are never valid `widen` operands or targets, so verification stays independent of the target; use `checked`. - `checked`: converts the numeric value; traps (`T0006`) if it is not representable in the target type. - `wrap`: takes the two's-complement bit pattern modulo 2^N of the target width. ## 3. Composite types ```aji [u8; 4096] slice slice_mut (u32, u64) Option Result ``` Structures: ```aji struct Header { len: u32, crc: u32, sequence: u64, } ``` Enums: ```aji enum State { Ready, Running, Failed(Error), } ``` ## 4. Nullability Safe references cannot be null. Nullable references use: ```text Option> Option> ``` Raw nullable addresses are unsafe-only. ## 5. Value ownership categories A value is one of: - copyable value; - move-only value; - linear resource; - borrow. Linear resources must be consumed exactly once. ## 6. Structural properties The compiler derives: - `Copy`: may be duplicated without changing semantics; - `Send`: may be moved to another concurrent execution context; - `Share`: may be observed concurrently through immutable access; - `Freeze`: can be converted to deeply immutable state; - `Local`: tied to its current execution context. These are semantic properties, not user-extensible traits in v0.1. Manual unsafe declarations MAY exist only for FFI/runtime wrappers and MUST state proof obligations. ## 7. Layout Default struct layout is implementation-defined and must not be used for external ABI assumptions. ABI-sensitive declarations use explicit representation attributes such as: ```aji @repr(C) struct PacketHeader { ... } ``` `@repr(packed)` and `@align(N)` MAY be supported. Packed fields do not yield normal aligned references unless alignment is established. ## 8. Endianness Serialization must be explicit: ```aji u32.from_le(...) u32.from_be(...) u32.to_le(...) u32.to_be(...) ```