From: bakaq Date: Tue, 20 Aug 2024 02:19:09 +0000 (-0300) Subject: Be conservative with visibility X-Git-Tag: v0.10.0~112^2~3 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=806e980cca91b0d944619f7fee98cc54109f4a9e;p=scryer-prolog.git Be conservative with visibility --- diff --git a/benches/run_iai.rs b/benches/run_iai.rs index 4af8115a..c29645c2 100644 --- a/benches/run_iai.rs +++ b/benches/run_iai.rs @@ -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; diff --git a/benches/setup.rs b/benches/setup.rs index ec9339c5..6087be44 100644 --- a/benches/setup.rs +++ b/benches/setup.rs @@ -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 { diff --git a/src/bin/scryer-prolog.rs b/src/bin/scryer-prolog.rs index b1af916d..763314ec 100644 --- a/src/bin/scryer-prolog.rs +++ b/src/bin/scryer-prolog.rs @@ -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() } diff --git a/src/lib.rs b/src/lib.rs index 90f498a3..51793544 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)) + }) +} diff --git a/src/machine/mod.rs b/src/machine/mod.rs index cfba5666..cb89edc7 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -250,7 +250,7 @@ pub(crate) fn get_structure_index(value: HeapCellValue) -> Option { 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() } diff --git a/src/machine/parsed_results.rs b/src/machine/parsed_results.rs index 05b0f7f1..b76239ed 100644 --- a/src/machine/parsed_results.rs +++ b/src/machine/parsed_results.rs @@ -24,7 +24,7 @@ pub enum QueryResolution { Matches(Vec), } -pub fn write_prolog_value_as_json( +fn write_prolog_value_as_json( writer: &mut W, value: &Value, ) -> Result<(), std::fmt::Error> { diff --git a/tests/scryer/helper.rs b/tests/scryer/helper.rs index f4d54fb8..696d2b12 100644 --- a/tests/scryer/helper.rs +++ b/tests/scryer/helper.rs @@ -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(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());