rename intrinsics

This commit is contained in:
2026-07-14 19:22:20 +02:00
parent 471896b48a
commit 5157cf3bcc
26 changed files with 107640 additions and 106418 deletions
+15 -14
View File
@@ -173,7 +173,7 @@
- `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`
- `ptr_cast(T, ptr)` preserves pointer shape and only changes the child type in v1
- `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
12. `undefined` as inspired by zig (implemented):
@@ -464,7 +464,7 @@
active/field `integer`) is sufficient. **no HIR/IR/lowering change** (like 18/19/20); the delta
is parser + types layout + one checker validation + three LLVM emit sites
- runtime layout `{tag, payload-carrier}`: tag at offset 0, payload carrier at
`payload_offset = round_up(sizeof(tag), payload_align)` (`types.union_payload_offset`, shared by
`payload_offset = round_up(sizeof!(tag), payload_align)` (`types.union_payload_offset`, shared by
`size` and the emitter). field access uses byte-offset GEPs, so offsets stay self-consistent
- construction `T{ variant = value }` reuses the union-literal path and additionally stores the
derived tag; payload read `x.variant` reuses field access, reading at the payload offset
@@ -794,19 +794,19 @@
32. explicit division family (implemented)
- `/` and `/=` are float-only; every integer use is rejected with guidance toward explicit
division, including literals, comptime execution, array counts, and compound assignment
- direct unqualified calls reserve `div_trunc`, `div_floor`, `div_exact`, `div_ceil`, `rem`, and
`mod`; qualified names remain ordinary package functions
- direct bang calls use `divtrunc!`, `divfloor!`, `divexact!`, `divceil!`, `rem!`, and `mod!`;
bare and qualified names remain ordinary functions
- the builtins accept compatible concrete integer or float scalars, reuse existing literal and
widening rules, and return the common operand type (integral-valued floats for quotients)
- all builtins diagnose zero denominators at comptime and trap at runtime; quotient operations
also trap on signed `min_value(T) / -1`, while `rem` and `mod` return zero for that pair
- `div_exact` checks the reconstructed dividend in the operand type; `rem` pairs with truncation
and follows the numerator sign, while `mod` pairs with floor and follows the denominator sign
also trap on signed `minval!(T) / -1`, while `rem!` and `mod!` return zero for that pair
- `divexact!` checks the reconstructed dividend in the operand type; `rem!` pairs with truncation
and follows the numerator sign, while `mod!` pairs with floor and follows the denominator sign
- HIR/IR use compact semantic enum tags; integer floor, ceil, and exact lowering reconstructs the
remainder from one quotient so each produces only one hardware-division candidate
- float lowering uses the typed LLVM trunc/floor/ceil intrinsics, `frem`, and ordered equality;
ordinary float `/` remains the unchecked IEEE infinity/NaN escape hatch
- migrated `std/mem`, `std/arraylist`, and the compound-assignment example to `div_trunc`
- migrated `std/mem`, `std/arraylist`, and the compound-assignment example to `divtrunc!`
33. explicit I/O provider (implemented)
- `main` may take one canonical `@std/io Io`; parameterless entry points remain valid
@@ -834,7 +834,8 @@
- add `debug.print` function making use of `std/io` to print values to the console
- this may either require native variadic arguments or a tuple value to like zig's approach (consider pros and cons)
38. consider renaming `ptr_cast` to `ptrcast`
38. place every intrinsic behind direct unqualified `name!(...)` syntax, freeing the bare names for
user functions (implemented)
## A word on unchecked casts
@@ -844,7 +845,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(p, T)` | Change pointer type | Gaining mutability (compile error) |
| `ptrcast!(p, T)` | Change pointer type | Gaining mutability (compile error) |
```honey
# truncation
@@ -859,10 +860,10 @@ bits := bitcast(f, u32) # IEEE 754 representation
# pointer casts (element type, many ↔ single, pointer ↔ usize)
buf: *u8 = get_buffer()
ints := ptrcast(buf, *u32) # element type change
single := ptrcast(buf, @u8) # many → single (restricting)
addr := ptrcast(buf, usize) # pointer to integer
ptr := ptrcast(addr, @u8) # integer to pointer
ints := ptrcast!(buf, *u32) # element type change
single := ptrcast!(buf, @u8) # many → single (restricting)
addr := ptrcast!(buf, usize) # pointer to integer
ptr := ptrcast!(addr, @u8) # integer to pointer
```
## A word on multi-unwrap