]> Repositorios git - scryer-prolog.git/commitdiff
move the creation of the LIBRARIES IndexMap out of the generated file
authorBennet Bleßmann <[email protected]>
Thu, 25 Jul 2024 16:53:36 +0000 (18:53 +0200)
committerBennet Bleßmann <[email protected]>
Thu, 25 Jul 2024 16:53:36 +0000 (18:53 +0200)
- only leave the filling of the map in the generated code

build/main.rs
src/machine/mod.rs

index 1f026de37cc0f384e046e8ed47c9e874ce7f590a..a43b9e8650dcfdd4294182997077c62e1c757438 100644 (file)
@@ -58,28 +58,8 @@ fn main() {
     let mut libraries = File::create(dest_path).unwrap();
     let lib_path = Path::new("src").join("lib");
 
-    writeln!(
-        libraries,
-        "\
-use indexmap::IndexMap;
-\
-    "
-    )
-    .unwrap();
-
     let constants = find_prolog_files("", &lib_path);
 
-    writeln!(
-        libraries,
-        "\
-std::thread_local!{{
-    static LIBRARIES: IndexMap<&'static str, &'static str> = {{
-        let mut m = IndexMap::new();
-\
-        "
-    )
-    .unwrap();
-
     let out_dir = std::env::var("OUT_DIR").unwrap();
     let out_dir_path: &Path = out_dir.as_ref();
     let manifest_dir = &std::env::var("CARGO_MANIFEST_DIR").unwrap();
@@ -104,23 +84,12 @@ std::thread_local!{{
         manifest_dir_path.to_path_buf()
     };
 
+    writeln!(libraries, "{{").unwrap();
     for (name, lib_path) in constants {
         let path: PathBuf = prefix.join(lib_path);
-        writeln!(
-            libraries,
-            "        m.insert(\"{name}\", include_str!({path:?}));"
-        )
-        .unwrap();
+        writeln!(libraries, "m.insert(\"{name}\", include_str!({path:?}));").unwrap();
     }
-
-    writeln!(
-        libraries,
-        "
-        m
-    }};
-}}"
-    )
-    .unwrap();
+    writeln!(libraries, "}}").unwrap();
 
     let instructions_path = Path::new(&out_dir).join("instructions.rs");
     let mut instructions_file = File::create(&instructions_path).unwrap();
index 33199eddb5f3ba5ca8b2aeff393b5f0f142c0c24..12170e3993d2ade05a607456fa3bc03fbc91d22d 100644 (file)
@@ -119,7 +119,17 @@ fn current_dir() -> PathBuf {
 }
 
 mod libraries {
-    include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
+    use indexmap::IndexMap;
+
+    std::thread_local! {
+    static LIBRARIES: IndexMap<&'static str, &'static str> = {
+            let mut m = IndexMap::new();
+
+            include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
+
+            m
+        }
+    }
 
     pub(crate) fn contains(name: &str) -> bool {
         LIBRARIES.with(|libs| libs.contains_key(name))
@@ -128,16 +138,6 @@ mod libraries {
     pub(crate) fn get(name: &str) -> Option<&'static str> {
         LIBRARIES.with(|libs| libs.get(name).copied())
     }
-
-    #[cfg(test)]
-    std::thread_local! {
-        #[allow(dead_code)]
-        static LIBRARIES2 : IndexMap<&'static str, &'static str> = {
-            let mut  m = IndexMap::new();
-            m.insert("test", "test2");
-            m
-        };
-    }
 }
 
 pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;