interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / examples / deepinfer / callers / caller.c

63 lines · 2290 bytes Raw Blame History
1/* C caller for examples/deepinfer/flops_pairs.om (run.sh builds it plain and with BTI enforced).
2 * Every Omega declaration comes from the generated omega_native.h; nothing is typed by hand here.
3 * Expected values: evidence/deepinfer-flops-pairs/wolfram.md. */
4#include <stdint.h>
5#include <stdio.h>
6#include <string.h>
7
8#include "omega_native.h"
9
10static int fails;
11static void check(const char *name, int ok) {
12 printf("%s %s\n", ok ? "PASS" : "FAIL", name);
13 if (!ok) fails++;
14}
15
16enum { FP, CP, PR };
17struct v {
18 int fn;
19 int64_t a[4];
20 uint32_t status;
21 int64_t want;
22};
23
24static const struct v vs[] = {
25 {FP, {9, 2}, 0, 20},
26 {CP, {9, 2, 3}, 0, 18},
27 {PR, {3, 9, 2, 3}, 0, 16},
28 {PR, {3, 9, 2, 0}, 0, 18},
29 {PR, {0, 4096, 1, 512}, 0, 1966336},
30 {FP, {3037000499, 1}, 0, 4611686016981624750},
31 {CP, {4611686018427387904, 1, 2}, 0, 9223372036854775807},
32 {FP, {3037000500, 1}, 1, 0},
33 {CP, {4611686018427387905, 1, 2}, 1, 0},
34 {CP, {0, 4294967296, 2147483648}, 1, 0},
35 {FP, {-1, 1}, 9, 0},
36 {FP, {5, 0}, 9, 0},
37 {PR, {5, 3, 1, 0}, 9, 0},
38 {PR, {0, 3, 1, -1}, 9, 0},
39};
40
41static uint32_t call(const struct v *x, uint64_t *r) {
42 const uint64_t *u = (const uint64_t *)x->a;
43 if (x->fn == FP) return omega2_floor_prefix(r, u[0], u[1]);
44 if (x->fn == CP) return omega2_capped_prefix(r, u[0], u[1], u[2]);
45 return omega2_pairs(r, u[0], u[1], u[2], u[3]);
46}
47
48int main(void) {
49 static const char *names[] = {"floor_prefix", "capped_prefix", "pairs"};
50 const uint64_t sentinel = 0x5a5a5a5a5a5a5a5aull;
51 check("ident: library == header", strcmp(omega2_ident_flops_pairs(), OMEGA2_IDENT_flops_pairs) == 0);
52 for (size_t i = 0; i < sizeof vs / sizeof vs[0]; i++) {
53 uint64_t r = sentinel;
54 const uint32_t st = call(&vs[i], &r);
55 const int ok = st == vs[i].status && (st == 0 ? (int64_t)r == vs[i].want : r == sentinel);
56 char name[160];
57 snprintf(name, sizeof name, "%s %lld %lld %lld %lld -> status %u", names[vs[i].fn], (long long)vs[i].a[0],
58 (long long)vs[i].a[1], (long long)vs[i].a[2], (long long)vs[i].a[3], st);
59 check(name, ok);
60 }
61 check("null result refused 32", omega2_pairs(NULL, 0, 3, 1, 0) == OMEGA_BAD_ARG);
62 return fails ? 1 : 0;
63}