1use std::collections::HashMap;
2use std::sync::OnceLock;
3
4pub fn base_lib() -> LibraryDefinition {
6 def::fift()
7}
8
9pub fn all() -> &'static HashMap<&'static str, &'static str> {
11 static MAP: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
12 MAP.get_or_init(|| {
13 let mut libraries = HashMap::with_capacity(LIBRARIES.len());
14 for LibraryDefinition { name, content } in LIBRARIES {
15 libraries.insert(*name, *content);
16 }
17 libraries
18 })
19}
20
21pub struct LibraryDefinition {
22 pub name: &'static str,
23 pub content: &'static str,
24}
25
26macro_rules! define_libs {
27 ($prefix:literal, [
28 $($name:ident => $file:literal),*$(,)?
29 ]) => {
30 pub mod def {
32 $(#[doc = $file]
34 pub const fn $name() -> crate::LibraryDefinition {
36 crate::LibraryDefinition {
37 name: $file,
38 content: include_str!(concat!($prefix, $file)),
39 }
40 })*
41 }
42
43 const LIBRARIES: &[LibraryDefinition] = &[
44 $(def::$name()),*
45 ];
46 };
47}
48
49define_libs!(
50 "./",
51 [
52 asm => "Asm.fif",
53 disasm => "Disasm.fif",
54 color => "Color.fif",
55 fift => "Fift.fif",
56 fift_ext => "FiftExt.fif",
57 lisp => "Lisp.fif",
58 lists => "Lists.fif",
59 stack => "Stack.fif",
60 ton_util => "TonUtil.fif",
61 get_opt => "GetOpt.fif",
62 ]
63);