Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-bridge/blob/main/examples/deepinfer/callers/caller.rs # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-bridge / examples / deepinfer / callers / caller.rs` 54 lines ยท 2290 bytes Raw Blame History 1 // Rust caller for examples/deepinfer/flops_pairs.om (no crates). Every Omega declaration comes from the 2 // generated omega_native.rs; nothing is typed by hand here. Expected values: 3 // evidence/deepinfer-flops-pairs/wolfram.md. 4 mod omega_native; 5 use omega_native::*; 6 7 static mut FAILS: u32 = 0; 8 fn check(name: &str, ok: bool) { 9 println!("{} {}", if ok { "PASS" } else { "FAIL" }, name); 10 if !ok { 11 unsafe { FAILS += 1 }; 12 } 13 } 14 15 fn call(f: &str, a: &[i64], r: *mut u64) -> u32 { 16 let u: Vec = a.iter().map(|&v| v as u64).collect(); 17 unsafe { 18 match f { 19 "floor_prefix" => omega2_floor_prefix(r, u[0], u[1]), 20 "capped_prefix" => omega2_capped_prefix(r, u[0], u[1], u[2]), 21 _ => omega2_pairs(r, u[0], u[1], u[2], u[3]), 22 } 23 } 24 } 25 26 fn main() { 27 let vs: [(&str, &[i64], u32, i64); 14] = [ 28 ("floor_prefix", &[9, 2], 0, 20), 29 ("capped_prefix", &[9, 2, 3], 0, 18), 30 ("pairs", &[3, 9, 2, 3], 0, 16), 31 ("pairs", &[3, 9, 2, 0], 0, 18), 32 ("pairs", &[0, 4096, 1, 512], 0, `1966336`), 33 ("floor_prefix", &[`3037000499`, 1], 0, `4611686016981624750`), 34 ("capped_prefix", &[`4611686018427387904`, 1, 2], 0, `9223372036854775807`), 35 ("floor_prefix", &[`3037000500`, 1], 1, 0), 36 ("capped_prefix", &[`4611686018427387905`, 1, 2], 1, 0), 37 ("capped_prefix", &[0, `4294967296`, `2147483648`], 1, 0), 38 ("floor_prefix", &[-1, 1], 9, 0), 39 ("floor_prefix", &[5, 0], 9, 0), 40 ("pairs", &[5, 3, 1, 0], 9, 0), 41 ("pairs", &[0, 3, 1, -1], 9, 0), 42 ]; 43 const SENTINEL: u64 = 0x5a5a5a5a5a5a5a5a; 44 let id = unsafe { std::ffi::CStr::from_ptr(omega2_ident_flops_pairs() as *const std::ffi::c_char) }; 45 check("ident: library == binding", id.to_bytes() == OMEGA2_IDENT_flops_pairs.as_bytes()); 46 for (f, a, status, want) in vs.iter() { 47 let mut r: u64 = SENTINEL; 48 let st = call(f, a, &mut r); 49 let ok = st == *status && if st == OMEGA_OK { r as i64 == *want } else { r == SENTINEL }; 50 check(&format!("{} {:?} -> status {}", f, a, st), ok); 51 } 52 check("null result refused 32", unsafe { omega2_pairs(std::ptr::null_mut(), 0, 3, 1, 0) } == OMEGA_BAD_ARG); 53 std::process::exit(if unsafe { FAILS } == 0 { 0 } else { 1 }); 54 }