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.cpp

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