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 concatenation;
9pub mod deal;
10pub mod elementwise;
11pub mod env;
12pub mod format;
13pub mod fs;
14pub mod gpu_helpers;
15pub mod indexing;
16pub mod linalg;
17pub mod matrix;
18pub mod path_search;
19pub mod path_state;
20pub mod random;
21pub mod random_args;
22pub mod residency;
23pub mod shape;
24pub mod spec;
25pub mod tensor;
26
27#[cfg(test)]
28pub mod test_support;
29
30pub(crate) fn map_control_flow_with_builtin(
31    mut err: crate::RuntimeError,
32    builtin: &str,
33) -> crate::RuntimeError {
34    if err.context.builtin.is_none() {
35        err.context = err.context.with_builtin(builtin);
36    }
37    if err.identifier.is_none() {
38        let segment = builtin
39            .chars()
40            .map(|ch| {
41                if ch.is_ascii_alphanumeric() || ch == '_' {
42                    ch
43                } else {
44                    '_'
45                }
46            })
47            .collect::<String>();
48        err.identifier = Some(format!("RunMat:{segment}:Error"));
49    }
50    err
51}