ruka_runtime/
lib.rs

1//! Runtime helpers used by emitted Rust and WASM outputs.
2
3/// Standard I/O runtime functions exposed to generated programs.
4pub mod io;
5/// Pointer storage used by generated Rust code.
6pub mod ptr;
7/// Generic string helpers exposed to generated programs.
8pub mod string;
9/// WASM runtime descriptors and ABI helpers.
10pub mod wasm_api;
11
12#[cfg(target_arch = "wasm32")]
13mod wasm_abi;
14
15/// Trap execution with one compiler-provided panic code.
16pub fn panic(code: i64) {
17    panic!("runtime panic with code {code}");
18}
19
20/// Build a static runtime descriptor slice with minimal duplication.
21#[macro_export]
22macro_rules! runtime_wasm_functions {
23    ($( $symbol:expr => $export:literal ( $( $param:ident ),* ) -> $result:tt ; )* ) => {
24        &[
25            $(
26                $crate::wasm_api::RuntimeFnDescriptor {
27                    symbol: $symbol,
28                    export_name: $export,
29                    params: &[$($crate::wasm_api::WasmValType::$param),*],
30                    result: $crate::runtime_wasm_result_ty!($result),
31                    lowering: $crate::wasm_api::LoweringMode::Direct,
32                },
33            )*
34        ]
35    };
36}
37
38/// Convert compact macro result syntax into runtime descriptor result metadata.
39#[macro_export]
40macro_rules! runtime_wasm_result_ty {
41    (()) => {
42        None
43    };
44    ($result:ident) => {
45        Some($crate::wasm_api::WasmValType::$result)
46    };
47}
48
49/// Runtime value used by tests and host-side helpers.
50#[derive(Debug, Clone, PartialEq)]
51pub enum Value {
52    /// Unit value.
53    Unit,
54    /// Integer value.
55    Int(i64),
56    /// Boolean value.
57    Bool(bool),
58    /// Slice value represented as runtime elements.
59    Slice(Vec<Value>),
60}
61
62/// Return the language-visible kind name for a runtime value.
63pub fn kind_name(value: &Value) -> &'static str {
64    match value {
65        Value::Unit => "Unit",
66        Value::Int(_) => "Int",
67        Value::Bool(_) => "Bool",
68        Value::Slice(_) => "Slice",
69    }
70}
71
72#[cfg(test)]
73mod tests;