Skip to main content

runmat_runtime/builtins/common/
mod.rs

1//! Shared helpers for builtin implementations.
2//!
3//! This module hosts small utility subsystems that builtins
4//! can depend on.
5
6pub mod arg_tokens;
7pub mod broadcast;
8pub mod env;
9pub mod format;
10pub mod fs;
11pub mod gpu_helpers;
12pub mod linalg;
13pub mod path_search;
14pub mod path_state;
15pub mod random;
16pub mod random_args;
17pub mod residency;
18pub mod shape;
19pub mod spec;
20pub mod tensor;
21
22#[cfg(test)]
23pub mod test_support;
24
25pub(crate) fn map_control_flow_with_builtin(
26    mut err: crate::RuntimeError,
27    builtin: &str,
28) -> crate::RuntimeError {
29    if err.context.builtin.is_none() {
30        err.context = err.context.with_builtin(builtin);
31    }
32    if err.identifier.is_none() {
33        let segment = builtin
34            .chars()
35            .map(|ch| {
36                if ch.is_ascii_alphanumeric() || ch == '_' {
37                    ch
38                } else {
39                    '_'
40                }
41            })
42            .collect::<String>();
43        err.identifier = Some(format!("RunMat:{segment}:Error"));
44    }
45    err
46}