leanfran-runtime 0.6.0

Runtime of the Rust code generated from Lean by leanfran
Documentation
//! Runtime of the Rust code generated from Lean IR by leanfran: the object model of `lean.h`
//! and the `lean_*` functions of the C runtime, under their C names.
//!
//! # Safety
//!
//! Every function follows the calling convention of its C counterpart: object arguments are
//! consumed unless the C declaration borrows them (`b_lean_obj_arg`, `@&` in Lean), results
//! are owned unless documented as borrowed, and every `Obj` must be a valid Lean value of the
//! type the function expects. Objects use single-threaded reference counts and must stay on
//! the thread that created them.

#![allow(clippy::missing_safety_doc, clippy::too_many_arguments, non_snake_case)]

pub mod array;
pub mod closure;
pub mod float;
pub mod fs;
pub mod int;
pub mod io;
pub mod io_error;
pub mod marshal;
pub mod model;
pub mod nat;
pub mod object;
pub mod panic;
pub mod process;
pub mod string;
pub mod thunk;
pub mod uint;

pub use array::*;
pub use closure::*;
pub use float::*;
pub use fs::*;
pub use int::*;
pub use io::*;
pub use io_error::*;
pub use marshal::*;
pub use model::*;
pub use nat::*;
pub use object::*;
pub use panic::*;
pub use process::*;
pub use string::*;
pub use thunk::*;
pub use uint::*;

/// `System.Platform.getNumBits`: the word size of the target.
pub unsafe fn lean_system_platform_nbits(_unit: Obj) -> Obj {
    lean_box(usize::BITS as usize)
}

/// `System.Platform.getIsWindows`.
pub unsafe fn lean_system_platform_windows(_unit: Obj) -> u8 {
    cfg!(windows) as u8
}

/// `System.Platform.getIsOSX`.
pub unsafe fn lean_system_platform_osx(_unit: Obj) -> u8 {
    cfg!(target_os = "macos") as u8
}

/// `System.Platform.getIsLinux`.
pub unsafe fn lean_system_platform_linux(_unit: Obj) -> u8 {
    cfg!(target_os = "linux") as u8
}

/// `System.Platform.getIsEmscripten`.
pub unsafe fn lean_system_platform_emscripten(_unit: Obj) -> u8 {
    cfg!(target_os = "emscripten") as u8
}

/// `System.Platform.getTarget`: the target triple the runtime was compiled for.
pub unsafe fn lean_system_platform_target(_unit: Obj) -> Obj {
    lean_mk_string(env!("LEANFRAN_TARGET"))
}

/// `System.Platform.Internal.getHardwareConcurrency`: the number of hardware threads, or 0.
pub unsafe fn lean_internal_get_hardware_concurrency(_unit: Obj) -> u32 {
    std::thread::available_parallelism().map_or(0, |n| n.get() as u32)
}

/// `ptrAddrUnsafe`.
pub unsafe fn lean_ptr_addr_unsafe(a: Obj) -> usize {
    lean_ptr_addr(a)
}

include!(concat!(env!("OUT_DIR"), "/externs.rs"));

/// The Lean source of `LeanRust/RuntimeExterns.lean`: [`EXTERNS`] as `runtimeExterns`.
#[doc(hidden)]
pub fn runtime_externs_lean() -> String {
    let mut s = String::from(
        "/-! C names of the functions the runtime `leanfran-runtime` provides. Generated by `make gen-externs`. -/\n\nnamespace LeanRust\n\ndef runtimeExterns : Array String := #[\n",
    );
    let items: Vec<String> = EXTERNS.iter().map(|n| format!("  \"{n}\"")).collect();
    s.push_str(&items.join(",\n"));
    s.push_str("\n]\n\nend LeanRust\n");
    s
}