instinct-cli 0.3.9

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
// generated by hxc 1.0.0-acgt-compiler from bench/capability/wasm_check.hlx -- do not edit by hand

#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
    let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
    if !ok {
        eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
    }
    ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    c
}

// hlx:2
#[path = "../../src/check/json.rs"]
// hlx:3
#[allow(dead_code)]
// hlx:4
mod json;
// hlx:5
#[path = "../../src/check/kernel.rs"]
// hlx:6
#[allow(dead_code)]
// hlx:7
mod kernel;
// hlx:8
#[path = "../../src/check/digest.rs"]
// hlx:9
#[allow(dead_code)]
// hlx:10
mod digest;
// hlx:11
#[path = "../../src/check/receipt.rs"]
// hlx:12
#[allow(dead_code)]
// hlx:13
mod receipt;
// hlx:14
use std::cell::RefCell;
// hlx:15
thread_local! { static OUTPUT: RefCell<Vec<u8>> = const { RefCell::new(Vec::new()) }; }
// hlx:16
#[no_mangle]
// hlx:17
pub extern "C" fn alloc(n: usize) -> *mut u8 {
    let mut b = Vec::<u8>::with_capacity(n.max(1));
    let p = b.as_mut_ptr();
    std::mem::forget(b);
    p
}
// hlx:18
#[no_mangle]
// hlx:19
pub unsafe extern "C" fn release(p: *mut u8, n: usize) {
    drop(Vec::from_raw_parts(p, 0, n.max(1)));
}
// hlx:20
#[no_mangle]
// hlx:21
pub unsafe extern "C" fn check(p: *const u8, n: usize, mode: u32) -> usize {
    // hlx:22
    let bytes = std::slice::from_raw_parts(p, n);
    // hlx:23
    let (out, _) = match mode {
        0 => kernel::evaluate(kernel::Mode::Run, bytes),
        1 => kernel::evaluate(kernel::Mode::Validate, bytes),
        2 => kernel::evaluate(kernel::Mode::Explain, bytes),
        3 => receipt::create(bytes),
        4 => receipt::replay(bytes),
        _ => return 0,
    };
    // hlx:24
    OUTPUT.with(|o| {
        *o.borrow_mut() = out.into_bytes();
        o.borrow().len()
    })
    // hlx:25
}
// hlx:26
#[no_mangle]
// hlx:27
pub extern "C" fn out_ptr() -> *const u8 {
    OUTPUT.with(|o| o.borrow().as_ptr())
}