inlean-runtime 0.1.0

Runtime support for Rust code generated from Lean by inlean
Documentation
//! Primitives that belong to no data type.

use crate::object::{box_, Obj};

/// The number of bits in a word of the target, as a `Nat`. Takes Lean's `Unit`.
pub fn system_platform_nbits(_unit: Obj) -> Obj {
    box_(usize::BITS as usize)
}

/// Lean's `panic!`. Lean's own runtime prints the message and continues with a default
/// value; here the Rust program panics, so that a violated assumption cannot go unnoticed.
pub unsafe fn panic_fn(_default: Obj, message: Obj) -> Obj {
    panic!("{}", crate::string::text(message))
}

/// [`panic_fn`] for a default value the caller keeps.
pub unsafe fn panic_fn_borrowed(default: Obj, message: Obj) -> Obj {
    panic_fn(default, message)
}

/// The constructor index of a value, as a `Nat`.
pub unsafe fn obj_tag_nat(o: Obj) -> Obj {
    box_(crate::object::obj_tag(o) as usize)
}

/// Combines two hash values.
pub fn uint64_mix_hash(mut h: u64, mut k: u64) -> u64 {
    const M: u64 = 0xc6a4a7935bd1e995;
    const R: u32 = 47;
    k = k.wrapping_mul(M);
    k ^= k >> R;
    k ^= M;
    h ^= k;
    h = h.wrapping_mul(M);
    h
}

/// The functions of this module that generated code may call, named as in `lean.h` without
/// the `lean_` prefix.
pub(crate) const OPS: &[&str] = &["system_platform_nbits", "panic_fn", "panic_fn_borrowed", "uint64_mix_hash", "obj_tag_nat"];