Commit eec7d55
P1: fix Zig FFI to build and match the Idris2 ABI (#37)
## Summary
The Zig FFI (`src/interface/ffi/src/main.zig`) failed to compile under
**Zig 0.14.0**. This PR fixes the two compile errors with minimal,
behaviour-preserving changes. Only `src/interface/ffi/src/main.zig` is
touched; the **Idris2 ABI is the source of truth** and was left
untouched.
## Errors (from `zig test src/main.zig -lc`)
1. `src/main.zig:118` — `@bitCast size mismatch: destination type 'u64'
has 64 bits but source type 'i128' has 128 bits`. In `betlangiser_init`,
`std.time.nanoTimestamp()` returns `i128`, but it was `@bitCast`
directly into the `u64` PRNG seed.
2. `src/main.zig:558` — `name shadows primitive 'u1'`. In
`sampleDistribution` (Box-Muller normal sampling), the locals `u1`/`u2`
shadow the built-in primitive type `u1`, which is an error in Zig 0.14.
## Fixes
1. Reinterpret the `i128` timestamp as `u128`, then truncate to `u64`:
`@truncate(@as(u128, @bitcast(std.time.nanoTimestamp())))`.
2. Rename the Box-Muller locals `u1`/`u2` → `unif1`/`unif2`.
Net diff: 4 insertions, 4 deletions in one file.
## ABI fidelity (preserved)
No exported C symbol names, signatures, or integer encodings changed:
- All 26 `C:betlangiser_*` symbols in `Foreign.idr` still map to
matching `export fn`s.
- `Result` enum `ok=0 … sampling_failed=6` matches `Types.idr`
`resultToInt`.
- `TernaryBool` encoding `t_false=0, t_true=1, t_unknown=2` matches
`ternaryToInt`.
- `DistributionTag` encoding `normal=0 … custom=4` matches
`distributionTag`.
## Verification
- `cd src/interface/ffi && zig test src/main.zig -lc` → **all 9 tests
pass**, zero errors/warnings, exit 0.
- `cd src/interface/abi && idris2 --build betlangiser-abi.ipkg` → **exit
0** (build dir removed afterwards).
- Symbol-coverage check: every `C:<name>` in `Foreign.idr` has a
matching `export fn <name>` in `main.zig` (26/26 OK).
Note: any rust-ci / Hypatia / governance red checks are pre-existing
estate-infra issues unrelated to this Zig-only change.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH
---
_Generated by [Claude
Code](https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent bf59a6c commit eec7d55
1 file changed
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
558 | | - | |
559 | | - | |
560 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
| |||
0 commit comments