feat: infer complete ptrcast target types
This commit is contained in:
@@ -176,8 +176,8 @@
|
||||
- `Name :: opaque` is the incomplete nominal record spelling; bodyless `c_struct` is invalid
|
||||
- `anyopaque` is the erased object type used behind pointers for C `void*` and allocator contexts
|
||||
- C `void` function results remain `void`; C `void*` / `const void*` import and render as `?*mut anyopaque` / `?*anyopaque`
|
||||
- `ptrcast!(T, ptr)` preserves pointer shape and only changes the child type in v1
|
||||
- future direction: generalize toward Zig-style arbitrary pointer-result casts once casts have a broader result-type story
|
||||
- `ptrcast!(ptr)` infers its complete pointer result from context; `ptrcast!(P, ptr)` accepts an explicit complete pointer type
|
||||
- both forms change the child type, then permit only ordinary implicit pointer conversions to the requested target; broader pointer-shape changes remain deferred
|
||||
|
||||
12. `undefined` as inspired by zig (implemented):
|
||||
- allow mutable local and global declarations with `undefined`
|
||||
@@ -973,7 +973,7 @@ For casts that bypass safety checks, Honey provides builtin functions:
|
||||
| -- | -- | -- |
|
||||
| `truncate(x, T)` | Keep low bits, discard rest | Never |
|
||||
| `bitcast(x, T)` | Reinterpret bits, no cast | Sizes don't match (compile error) |
|
||||
| `ptrcast!(T, p)` | Change a pointer's child type while preserving its shape | Invalid child or non-pointer operand (compile error) |
|
||||
| `ptrcast!(p)` / `ptrcast!(P, p)` | Infer or explicitly supply a complete pointer target, changing the child before ordinary pointer coercion | Missing target context, invalid target, incompatible shape, or non-pointer operand (compile error) |
|
||||
| `constcast!(p)` | Restore pointer or slice mutability | Non-pointer/slice operand (compile error) |
|
||||
|
||||
```honey
|
||||
@@ -989,8 +989,10 @@ bits := bitcast(f, u32) # IEEE 754 representation
|
||||
|
||||
# pointer casts
|
||||
buf *u8 := get_buffer()
|
||||
ints *u32 := ptrcast!(u32, buf) # element type change, same pointer shape
|
||||
writable *mut u8 := constcast!(buf) # explicit unsafe mutability restoration
|
||||
ints *u32 := ptrcast!(buf) # target inferred from the declaration
|
||||
raw ?*mut anyopaque := get_raw_buffer()
|
||||
bytes := ptrcast!(?*mut u8, raw) # complete target supplied explicitly
|
||||
writable *mut u8 := constcast!(buf) # explicit unsafe mutability restoration
|
||||
```
|
||||
|
||||
## A word on multi-unwrap
|
||||
|
||||
Reference in New Issue
Block a user