Commit e3ca6e3
committed
P1: implement real Zig FFI matching the Idris2 ABI
The Idris2 ABI is the source of truth. Its %foreign declarations live in
two places: Foreign.idr (18 symbols) and the `namespace Foreign` block in
Types.idr (3 symbols: eclexiaiser_measure_energy, eclexiaiser_query_carbon,
eclexiaiser_enforce_budget). The Zig FFI exported the 18 from Foreign.idr
but was missing all 3 from Types.idr, so those symbols would fail to link
when the ABI is compiled against libeclexiaiser.
This adds the three missing C-ABI exports with signatures matching their
%foreign types exactly:
eclexiaiser_measure_energy : Bits64 -> PrimIO Bits64
(handle: opaque ptr) -> u64 microjoules
eclexiaiser_query_carbon : Bits32 -> PrimIO Bits32
(zone_id: u32) -> u32 mgCO2/kWh (handle-free)
eclexiaiser_enforce_budget : Bits64 -> Bits64 -> PrimIO Bits32
(budget_uj, measured_uj: u64) -> Result (handle-free)
eclexiaiser_enforce_budget returns the Result enum, whose values already
match Types.idr resultToInt (Ok=0 .. CounterUnavailable=7); the handle-free
forms mirror the safe wrappers measureEnergy/queryCarbon/enforceBudget in
the Types.idr namespace Foreign block.
Adds three `test` blocks covering the new symbols: measure_energy main
path plus null-handle rejection, handle-free query_carbon, and
enforce_budget result codes (ok / budget_exceeded).
Verification:
- zig test src/main.zig -lc : 11/11 pass, no warnings
- idris2 --build eclexiaiser-abi.ipkg : exit 0, clean
- all 21 C:eclexiaiser_* ABI symbols now have a matching export fn
- Result enum values equal resultToInt
Only src/interface/ffi/ is touched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH1 parent 890972d commit e3ca6e3
1 file changed
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
250 | 272 | | |
251 | 273 | | |
252 | 274 | | |
| |||
280 | 302 | | |
281 | 303 | | |
282 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
283 | 313 | | |
284 | 314 | | |
285 | 315 | | |
| |||
317 | 347 | | |
318 | 348 | | |
319 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
320 | 363 | | |
321 | 364 | | |
322 | 365 | | |
| |||
639 | 682 | | |
640 | 683 | | |
641 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
0 commit comments