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