clm_rust_core/evaluator/dispatch/
mod.rs1pub mod catalog;
15pub mod catalog_ids;
16mod registry_core;
17mod registry_runtime;
18mod registry_infra;
19#[path = "registry_infra_testing.rs"]
21mod registry_testing;
22mod orchestrator_intercepts;
23mod orchestrator_invariants;
24mod orchestrator_pipeline;
25mod orchestrator;
26pub(crate) mod runtime;
27
28use std::fs;
29use std::path::Path;
30
31pub(crate) type InternalFn = fn(&str, &str) -> Result<(i32, String), String>;
34
35pub(super) fn get_clm_args(clm_file: &str) -> Result<Vec<String>, String> {
39 let content = fs::read_to_string(clm_file)
40 .map_err(|e| format!("Failed to read CLM file for args: {}", e))?;
41 let data: serde_yaml::Value = serde_yaml::from_str(&content)
42 .map_err(|e| format!("Failed to parse CLM YAML: {}", e))?;
43 let clm_data = data.get("clm").unwrap_or(&data);
44 let concrete_impl = clm_data.get("concrete_impl")
45 .ok_or_else(|| "No concrete_impl in CLM".to_string())?;
46 let process = concrete_impl.get("process")
47 .ok_or_else(|| "No process in concrete_impl".to_string())?;
48
49 if let Some(args_val) = process.get("args") {
50 if let Some(arr) = args_val.as_sequence() {
51 let mut result = Vec::new();
52 for item in arr {
53 if let Some(s) = item.as_str() {
54 result.push(s.to_string());
55 } else if let Some(i) = item.as_i64() {
56 result.push(i.to_string());
57 } else if let Some(b) = item.as_bool() {
58 result.push(b.to_string());
59 } else {
60 result.push("".to_string());
61 }
62 }
63 Ok(result)
64 } else {
65 Err("process.args is not a list/sequence".to_string())
66 }
67 } else {
68 Ok(Vec::new())
69 }
70}
71
72pub(super) fn resolve_json_ast_internal(json_or_file: &str, clm_root: &str) -> String {
74 let trimmed = json_or_file.trim();
75 if trimmed.starts_with('{') || trimmed.starts_with('[') {
76 trimmed.to_string()
77 } else {
78 let raw_path = Path::new(json_or_file);
79 let path = if raw_path.is_absolute() {
80 raw_path.to_path_buf()
81 } else {
82 Path::new(clm_root).join(json_or_file)
83 };
84 if path.exists() {
85 crate::yaml::parse_to_mcards(&path.to_string_lossy()).unwrap_or_else(|_| "null".to_string())
86 } else {
87 trimmed.to_string()
88 }
89 }
90}
91
92pub struct DispatchEntry {
96 pub module_path: &'static str,
97 pub func: InternalFn,
98}
99
100inventory::collect!(DispatchEntry);
101
102#[macro_export]
104macro_rules! register_clm_dispatch {
105 ($path:expr, $func:expr) => {
106 inventory::submit! {
107 $crate::evaluator::dispatch::DispatchEntry {
108 module_path: $path,
109 func: $func,
110 }
111 }
112 };
113}
114
115const TESTING_ROUTES: &[&str] = &["clm_rust_core::integration::", "clm_rust_core::test::", "clm_rust_core::prove::"];
119
120pub(crate) fn get_internal_registry(module_path: &str) -> Option<InternalFn> {
126 registry_core::dispatch(module_path)
127 .or_else(|| registry_runtime::dispatch(module_path))
128 .or_else(|| registry_infra::dispatch(module_path))
129 .or_else(|| testing_registry(module_path))
130}
131
132fn testing_registry(module_path: &str) -> Option<InternalFn> {
133 if !TESTING_ROUTES.iter().any(|prefix| module_path.starts_with(prefix)) {
134 return None;
135 }
136 static REGISTRY: std::sync::OnceLock<std::collections::HashMap<&'static str, InternalFn>> = std::sync::OnceLock::new();
137 let map = REGISTRY.get_or_init(|| {
138 let mut m = std::collections::HashMap::with_capacity(256);
139 for entry in inventory::iter::<DispatchEntry> {
140 m.insert(entry.module_path, entry.func);
141 }
142 m
143 });
144
145 map.get(module_path).copied().or_else(|| registry_testing::dispatch_testing_verification(module_path))
146}
147
148pub(crate) use orchestrator::try_internal_dispatch;
151#[allow(unused_imports)]
152pub(crate) use orchestrator::try_internal_dispatch_with_context;