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/tests/native/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 / tests / native / caller.rs` 55 lines ยท 3057 bytes Raw Blame History 1 // Rust caller for the omega-bridge native call ABI v1 test library (no crates). 2 mod omega_native; // every Omega declaration: generated by tools/native, nothing typed by hand 3 use omega_native::*; 4 5 fn main() { 6 const SENTINEL: u64 = `6148914691236517205`; 7 let mut fails = 0; 8 let mut check = |name: &str, ok: bool| { 9 println!("{} {}", if ok { "PASS" } else { "FAIL" }, name); 10 if !ok { 11 fails += 1; 12 } 13 }; 14 let mut r: u64 = 0; 15 unsafe { 16 check("madd 3*5+7 = 22", omega_madd(&mut r, 3, 5, 7) == 0 && r == 22); 17 check("madd wraps = 3", omega_madd(&mut r, u64::MAX, 2, 5) == 0 && r == 3); 18 check("madd large", omega_madd(&mut r, `1311768467463790320`, `18364758544493064720`, `1085102592571150095`) == 0 19 && r == `3637949782307626511`); 20 check("madd signed bits = -13", omega_madd(&mut r, (-3i64) as u64, 5, 2) == 0 && r as i64 == -13); 21 r = SENTINEL; 22 check("smadd overflow traps 1, result unchanged", omega_smadd(&mut r, 1u64 << 62, 4, 0) == 1 && r == SENTINEL); 23 let mut buf = [0u64; 4]; 24 check("fill k=1 traps 3, result unchanged", omega_fill(&mut r, buf.as_mut_ptr(), 4, 1) == 3 && r == SENTINEL); 25 check("writes before the trap stay visible", buf == [11, 22, 0, 0]); 26 check("fill k=0 = 3", omega_fill(&mut r, buf.as_mut_ptr(), 4, 0) == 0 && r == 3 && buf == [11, 22, 33, 0]); 27 check("null result refused 32", omega_madd(std::ptr::null_mut(), 3, 5, 7) == 32); 28 // mix: six parameters (ulong, long, view uchar 3, edit uchar 2, view ulong 2, ulong), no result. 29 // 5 + 20 + 7 = 32 (calc:`08302bc4`); 5 + 20 + 300 is 70 over 255 (calc:`a6a8bb76`), so the conversion traps 5. 30 let cb = [1u8, 2, 3]; 31 let mut db = [0u8; 2]; 32 let eb = [10u64, 20]; 33 r = SENTINEL; 34 check("mix six parameters, void result writes 0", 35 omega_mix(&mut r, 5, 1, cb.as_ptr(), 3, db.as_mut_ptr(), 2, eb.as_ptr(), 2, 7) == 0 && r == 0 && db == [3, 32]); 36 db = [0, 0]; 37 r = SENTINEL; 38 check("mix negative long traps 9 after both writes, result unchanged", 39 omega_mix(&mut r, 5, (-1i64) as u64, cb.as_ptr(), 3, db.as_mut_ptr(), 2, eb.as_ptr(), 2, 7) == 9 40 && r == SENTINEL && db == [3, 32]); 41 db = [0, 0]; 42 check("mix uchar conversion 325 traps 5, first write visible", 43 omega_mix(&mut r, 5, 1, cb.as_ptr(), 3, db.as_mut_ptr(), 2, eb.as_ptr(), 2, 300) == 5 && r == SENTINEL && db == [3, 0]); 44 } 45 // A std::thread has a 2 MiB stack by default; the 4,000,000-byte local array runs on the binding's own stack. 46 // (7 + 1) + 7 = 15 (calc:`e44bce3f`). 47 let t = std::thread::spawn(|| { 48 let mut r: u64 = 0; 49 let s = unsafe { omega_big(&mut r, 7) }; 50 (s, r) 51 }); 52 check("big local array on a default std::thread = 15", t.join().map_or(false, |v| v == (0, 15))); 53 println!("{} {} failure(s)", if fails > 0 { "FAIL" } else { "PASS" }, fails); 54 std::process::exit(if fails > 0 { 1 } else { 0 }); 55 }