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

79 lines · 2124 bytes Raw Blame History
1// Go caller for examples/deepinfer/flops_pairs.om. Every Omega declaration comes from the omeganative
2// package (omega_native.go, generated by tools/native); this file has no cgo of its own. Expected values:
3// evidence/deepinfer-flops-pairs/wolfram.md.
4package main
5
6import (
7 "fmt"
8 "os"
9
10 on "omegacaller/omeganative"
11)
12
13var fails int
14
15func check(name string, ok bool) {
16 if ok {
17 fmt.Println("PASS", name)
18 } else {
19 fmt.Println("FAIL", name)
20 fails++
21 }
22}
23
24type v struct {
25 f string
26 a []int64
27 status uint32
28 want int64
29}
30
31func call(x v, r *uint64) uint32 {
32 u := make([]uint64, len(x.a))
33 for i, a := range x.a {
34 u[i] = uint64(a)
35 }
36 switch x.f {
37 case "floor_prefix":
38 return on.Omega2_floor_prefix(r, u[0], u[1])
39 case "capped_prefix":
40 return on.Omega2_capped_prefix(r, u[0], u[1], u[2])
41 }
42 return on.Omega2_pairs(r, u[0], u[1], u[2], u[3])
43}
44
45func main() {
46 vs := []v{
47 {"floor_prefix", []int64{9, 2}, 0, 20},
48 {"capped_prefix", []int64{9, 2, 3}, 0, 18},
49 {"pairs", []int64{3, 9, 2, 3}, 0, 16},
50 {"pairs", []int64{3, 9, 2, 0}, 0, 18},
51 {"pairs", []int64{0, 4096, 1, 512}, 0, 1966336},
52 {"floor_prefix", []int64{3037000499, 1}, 0, 4611686016981624750},
53 {"capped_prefix", []int64{4611686018427387904, 1, 2}, 0, 9223372036854775807},
54 {"floor_prefix", []int64{3037000500, 1}, 1, 0},
55 {"capped_prefix", []int64{4611686018427387905, 1, 2}, 1, 0},
56 {"capped_prefix", []int64{0, 4294967296, 2147483648}, 1, 0},
57 {"floor_prefix", []int64{-1, 1}, 9, 0},
58 {"floor_prefix", []int64{5, 0}, 9, 0},
59 {"pairs", []int64{5, 3, 1, 0}, 9, 0},
60 {"pairs", []int64{0, 3, 1, -1}, 9, 0},
61 }
62 const sentinel = uint64(0x5a5a5a5a5a5a5a5a)
63 check("ident: library == binding", on.Omega2_ident_flops_pairs() == on.Omega2Ident_flops_pairs)
64 for _, x := range vs {
65 r := sentinel
66 st := call(x, &r)
67 ok := st == x.status
68 if st == on.OmegaOK {
69 ok = ok && int64(r) == x.want
70 } else {
71 ok = ok && r == sentinel
72 }
73 check(fmt.Sprintf("%s %v -> status %d", x.f, x.a, st), ok)
74 }
75 check("null result refused 32", on.Omega2_pairs(nil, 0, 3, 1, 0) == on.OmegaBadArg)
76 if fails != 0 {
77 os.Exit(1)
78 }
79}