]> Repositorios git - scryer-prolog.git/commitdiff
Be conservative with visibility
authorbakaq <[email protected]>
Tue, 20 Aug 2024 02:19:09 +0000 (23:19 -0300)
committerbakaq <[email protected]>
Tue, 3 Sep 2024 04:02:01 +0000 (01:02 -0300)
benches/run_iai.rs
benches/setup.rs
src/bin/scryer-prolog.rs
src/lib.rs
src/machine/mod.rs
src/machine/parsed_results.rs
tests/scryer/helper.rs

index 4af8115a0e9490c09c515fa4069fc5e306fc3c72..c29645c2d0a4d5f13b0cc170d6f216e4511a0b27 100644 (file)
@@ -5,7 +5,7 @@ mod setup;
 mod iai {
     use iai_callgrind::{library_benchmark, library_benchmark_group, main};
 
-    use scryer_prolog::machine::parsed_results::QueryResolution;
+    use scryer_prolog::QueryResolution;
 
     use super::setup;
 
index ec9339c590c4d6e3fd496d7afd7a6552885c8047..6087be446f6ed449a92e8c524b33e359f2d6b529 100644 (file)
@@ -1,10 +1,7 @@
 use std::{collections::BTreeMap, fs, path::Path};
 
 use maplit::btreemap;
-use scryer_prolog::machine::{
-    parsed_results::{QueryResolution, Value},
-    Machine,
-};
+use scryer_prolog::{Machine, QueryResolution, Value};
 
 pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> {
     [
@@ -88,7 +85,7 @@ mod test {
     #[test]
     fn validate_benchmarks() {
         use super::prolog_benches;
-        use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution};
+        use scryer_prolog::{QueryMatch, QueryResolution};
         use std::{fmt::Write, fs};
 
         struct BenchResult {
index b1af916d3857b27aa080bffe136b778874158f8c..763314ec9709ac31b7435cf9a7060d54435d25dc 100644 (file)
@@ -1,27 +1,3 @@
 fn main() -> std::process::ExitCode {
-    use scryer_prolog::atom_table::Atom;
-    use scryer_prolog::*;
-
-    #[cfg(feature = "repl")]
-    ctrlc::set_handler(move || {
-        scryer_prolog::machine::INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
-    })
-    .unwrap();
-
-    #[cfg(target_arch = "wasm32")]
-    let runtime = tokio::runtime::Builder::new_current_thread()
-        .enable_all()
-        .build()
-        .unwrap();
-
-    #[cfg(not(target_arch = "wasm32"))]
-    let runtime = tokio::runtime::Builder::new_multi_thread()
-        .enable_all()
-        .build()
-        .unwrap();
-
-    runtime.block_on(async move {
-        let mut wam = machine::Machine::new(Default::default());
-        wam.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 0))
-    })
+    scryer_prolog::run_binary()
 }
index 90f498a30131703839e7a3fcb7975d64c3497dae..517935446e41a5305854442c798f1fe8d38eb9b6 100644 (file)
@@ -7,44 +7,50 @@ extern crate static_assertions;
 extern crate maplit;
 
 #[macro_use]
-pub mod macros;
+pub(crate) mod macros;
 #[macro_use]
-pub mod atom_table;
+pub(crate) mod atom_table;
 #[macro_use]
-pub mod arena;
+pub(crate) mod arena;
 #[macro_use]
-pub mod parser;
+pub(crate) mod parser;
 mod allocator;
 mod arithmetic;
-pub mod codegen;
+pub(crate) mod codegen;
 mod debray_allocator;
 #[cfg(feature = "ffi")]
 mod ffi;
 mod forms;
 mod heap_iter;
-pub mod heap_print;
+pub(crate) mod heap_print;
 #[cfg(feature = "http")]
 mod http;
 mod indexing;
 mod variable_records;
 #[macro_use]
-pub mod instructions {
+pub(crate) mod instructions {
     include!(concat!(env!("OUT_DIR"), "/instructions.rs"));
 }
 mod iterators;
-pub mod machine;
+pub(crate) mod machine;
 mod raw_block;
-pub mod read;
+pub(crate) mod read;
 #[cfg(feature = "repl")]
 mod repl_helper;
 mod targets;
-pub mod types;
+pub(crate) mod types;
 
 use instructions::instr;
 
 #[cfg(target_arch = "wasm32")]
 use wasm_bindgen::prelude::*;
 
+// Re-exports
+pub use machine::config::*;
+pub use machine::lib_machine::*;
+pub use machine::parsed_results::*;
+pub use machine::Machine;
+
 #[cfg(target_arch = "wasm32")]
 #[wasm_bindgen]
 pub fn eval_code(s: &str) -> String {
@@ -56,3 +62,31 @@ pub fn eval_code(s: &str) -> String {
     let bytes = wam.test_load_string(s);
     String::from_utf8_lossy(&bytes).to_string()
 }
+
+pub fn run_binary() -> std::process::ExitCode {
+    use crate::atom_table::Atom;
+    use crate::machine::{Machine, INTERRUPT};
+
+    #[cfg(feature = "repl")]
+    ctrlc::set_handler(move || {
+        INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
+    })
+    .unwrap();
+
+    #[cfg(target_arch = "wasm32")]
+    let runtime = tokio::runtime::Builder::new_current_thread()
+        .enable_all()
+        .build()
+        .unwrap();
+
+    #[cfg(not(target_arch = "wasm32"))]
+    let runtime = tokio::runtime::Builder::new_multi_thread()
+        .enable_all()
+        .build()
+        .unwrap();
+
+    runtime.block_on(async move {
+        let mut wam = Machine::new(Default::default());
+        wam.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 0))
+    })
+}
index cfba56662118175fa024f002cca6f7925e8d8038..cb89edc78c0171f946fd1675f2a6fc11dc18687d 100644 (file)
@@ -250,7 +250,7 @@ pub(crate) fn get_structure_index(value: HeapCellValue) -> Option<CodeIndex> {
 
 impl Machine {
     #[inline]
-    pub fn prelude_view_and_machine_st(&mut self) -> (MachinePreludeView, &mut MachineState) {
+    fn prelude_view_and_machine_st(&mut self) -> (MachinePreludeView, &mut MachineState) {
         (
             MachinePreludeView {
                 indices: &mut self.indices,
@@ -270,7 +270,7 @@ impl Machine {
             .unwrap()
     }
 
-    pub fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
+    fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
         let err = self.machine_st.session_error(err);
         let stub = functor_stub(key.0, key.1);
         let err = self.machine_st.error_form(err, stub);
@@ -278,7 +278,7 @@ impl Machine {
         self.machine_st.throw_exception(err);
     }
 
-    pub fn run_module_predicate(
+    pub(crate) fn run_module_predicate(
         &mut self,
         module_name: Atom,
         key: PredicateKey,
@@ -297,7 +297,7 @@ impl Machine {
         unreachable!();
     }
 
-    pub fn load_file(&mut self, path: &str, stream: Stream) {
+    fn load_file(&mut self, path: &str, stream: Stream) {
         self.machine_st.registers[1] = stream_as_cell!(stream);
         self.machine_st.registers[2] =
             atom_as_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, path));
@@ -357,11 +357,11 @@ impl Machine {
         }
     }
 
-    pub fn set_user_input(&mut self, input: String) {
+    fn set_user_input(&mut self, input: String) {
         self.user_input = Stream::from_owned_string(input, &mut self.machine_st.arena);
     }
 
-    pub fn get_user_output(&self) -> String {
+    fn get_user_output(&self) -> String {
         let output_bytes: Vec<_> = self.user_output.bytes().map(|b| b.unwrap()).collect();
         String::from_utf8(output_bytes).unwrap()
     }
index 05b0f7f1530b1051560ff516bece95914c3b86d6..b76239edd6c44d70a22b3c166e84497fbac24895 100644 (file)
@@ -24,7 +24,7 @@ pub enum QueryResolution {
     Matches(Vec<QueryMatch>),
 }
 
-pub fn write_prolog_value_as_json<W: Write>(
+fn write_prolog_value_as_json<W: Write>(
     writer: &mut W,
     value: &Value,
 ) -> Result<(), std::fmt::Error> {
index f4d54fb894b2a60f61e6898fdc7903887fb5dae7..696d2b12a0d9f47cbd737eeb90c218c935fd3df5 100644 (file)
@@ -26,7 +26,7 @@ impl Expectable for &[u8] {
 /// Tests whether the file can be successfully loaded
 /// and produces the expected output during it
 pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
-    use scryer_prolog::machine::mock_wam::*;
+    use scryer_prolog::Machine;
 
     let mut wam = Machine::with_test_streams();
     expected.assert_eq(wam.test_load_file(file).as_slice());