1use crate::types::Effect;
11use std::collections::HashMap;
12use std::sync::LazyLock;
13
14mod adt;
15mod arith;
16mod callable;
17mod concurrency;
18mod diagnostics;
19mod float;
20mod fs;
21mod io;
22mod list;
23mod macros;
24mod map;
25mod os;
26mod stack;
27mod tcp;
28mod text;
29mod udp;
30
31#[cfg(test)]
32mod tests;
33
34type AddSigsFn = fn(&mut HashMap<String, Effect>);
35type AddDocsFn = fn(&mut HashMap<&'static str, &'static str>);
36
37const CATEGORIES: &[(&str, AddSigsFn, AddDocsFn)] = &[
43 ("io", io::add_signatures, io::add_docs),
44 ("fs", fs::add_signatures, fs::add_docs),
45 ("arith", arith::add_signatures, arith::add_docs),
46 ("stack", stack::add_signatures, stack::add_docs),
47 (
48 "concurrency",
49 concurrency::add_signatures,
50 concurrency::add_docs,
51 ),
52 ("callable", callable::add_signatures, callable::add_docs),
53 ("tcp", tcp::add_signatures, tcp::add_docs),
54 ("udp", udp::add_signatures, udp::add_docs),
55 ("os", os::add_signatures, os::add_docs),
56 ("text", text::add_signatures, text::add_docs),
57 ("adt", adt::add_signatures, adt::add_docs),
58 ("list", list::add_signatures, list::add_docs),
59 ("map", map::add_signatures, map::add_docs),
60 ("float", float::add_signatures, float::add_docs),
61 (
62 "diagnostics",
63 diagnostics::add_signatures,
64 diagnostics::add_docs,
65 ),
66];
67
68pub fn builtin_signature(name: &str) -> Option<Effect> {
70 BUILTIN_SIGNATURES.get(name).cloned()
71}
72
73pub fn builtin_signatures() -> HashMap<String, Effect> {
78 BUILTIN_SIGNATURES.clone()
79}
80
81static BUILTIN_SIGNATURES: LazyLock<HashMap<String, Effect>> = LazyLock::new(|| {
82 let mut sigs = HashMap::new();
83 for (_, add_sigs, _) in CATEGORIES {
84 add_sigs(&mut sigs);
85 }
86 sigs
87});
88
89pub fn builtin_doc(name: &str) -> Option<&'static str> {
91 BUILTIN_DOCS.get(name).copied()
92}
93
94pub fn builtin_categories() -> Vec<(&'static str, Vec<String>)> {
99 CATEGORIES
100 .iter()
101 .map(|(name, add_sigs, _)| {
102 let mut sigs = HashMap::new();
103 add_sigs(&mut sigs);
104 let mut words: Vec<String> = sigs.into_keys().collect();
105 words.sort();
106 (*name, words)
107 })
108 .collect()
109}
110
111pub fn builtin_docs() -> &'static HashMap<&'static str, &'static str> {
113 &BUILTIN_DOCS
114}
115
116static BUILTIN_DOCS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
117 let mut docs = HashMap::new();
118 for (_, _, add_docs) in CATEGORIES {
119 add_docs(&mut docs);
120 }
121 docs
122});