Be conservative with visibility

This commit is contained in:
bakaq
2024-08-19 23:19:09 -03:00
parent 12a61cdff8
commit 806e980cca
7 changed files with 56 additions and 49 deletions

View File

@@ -5,7 +5,7 @@ mod setup;
mod iai { mod iai {
use iai_callgrind::{library_benchmark, library_benchmark_group, main}; use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use scryer_prolog::machine::parsed_results::QueryResolution; use scryer_prolog::QueryResolution;
use super::setup; use super::setup;

View File

@@ -1,10 +1,7 @@
use std::{collections::BTreeMap, fs, path::Path}; use std::{collections::BTreeMap, fs, path::Path};
use maplit::btreemap; use maplit::btreemap;
use scryer_prolog::machine::{ use scryer_prolog::{Machine, QueryResolution, Value};
parsed_results::{QueryResolution, Value},
Machine,
};
pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> { pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> {
[ [
@@ -88,7 +85,7 @@ mod test {
#[test] #[test]
fn validate_benchmarks() { fn validate_benchmarks() {
use super::prolog_benches; use super::prolog_benches;
use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution}; use scryer_prolog::{QueryMatch, QueryResolution};
use std::{fmt::Write, fs}; use std::{fmt::Write, fs};
struct BenchResult { struct BenchResult {

View File

@@ -1,27 +1,3 @@
fn main() -> std::process::ExitCode { fn main() -> std::process::ExitCode {
use scryer_prolog::atom_table::Atom; scryer_prolog::run_binary()
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))
})
} }

View File

@@ -7,44 +7,50 @@ extern crate static_assertions;
extern crate maplit; extern crate maplit;
#[macro_use] #[macro_use]
pub mod macros; pub(crate) mod macros;
#[macro_use] #[macro_use]
pub mod atom_table; pub(crate) mod atom_table;
#[macro_use] #[macro_use]
pub mod arena; pub(crate) mod arena;
#[macro_use] #[macro_use]
pub mod parser; pub(crate) mod parser;
mod allocator; mod allocator;
mod arithmetic; mod arithmetic;
pub mod codegen; pub(crate) mod codegen;
mod debray_allocator; mod debray_allocator;
#[cfg(feature = "ffi")] #[cfg(feature = "ffi")]
mod ffi; mod ffi;
mod forms; mod forms;
mod heap_iter; mod heap_iter;
pub mod heap_print; pub(crate) mod heap_print;
#[cfg(feature = "http")] #[cfg(feature = "http")]
mod http; mod http;
mod indexing; mod indexing;
mod variable_records; mod variable_records;
#[macro_use] #[macro_use]
pub mod instructions { pub(crate) mod instructions {
include!(concat!(env!("OUT_DIR"), "/instructions.rs")); include!(concat!(env!("OUT_DIR"), "/instructions.rs"));
} }
mod iterators; mod iterators;
pub mod machine; pub(crate) mod machine;
mod raw_block; mod raw_block;
pub mod read; pub(crate) mod read;
#[cfg(feature = "repl")] #[cfg(feature = "repl")]
mod repl_helper; mod repl_helper;
mod targets; mod targets;
pub mod types; pub(crate) mod types;
use instructions::instr; use instructions::instr;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*; 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")] #[cfg(target_arch = "wasm32")]
#[wasm_bindgen] #[wasm_bindgen]
pub fn eval_code(s: &str) -> String { 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); let bytes = wam.test_load_string(s);
String::from_utf8_lossy(&bytes).to_string() 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))
})
}

View File

@@ -250,7 +250,7 @@ pub(crate) fn get_structure_index(value: HeapCellValue) -> Option<CodeIndex> {
impl Machine { impl Machine {
#[inline] #[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 { MachinePreludeView {
indices: &mut self.indices, indices: &mut self.indices,
@@ -270,7 +270,7 @@ impl Machine {
.unwrap() .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 err = self.machine_st.session_error(err);
let stub = functor_stub(key.0, key.1); let stub = functor_stub(key.0, key.1);
let err = self.machine_st.error_form(err, stub); let err = self.machine_st.error_form(err, stub);
@@ -278,7 +278,7 @@ impl Machine {
self.machine_st.throw_exception(err); self.machine_st.throw_exception(err);
} }
pub fn run_module_predicate( pub(crate) fn run_module_predicate(
&mut self, &mut self,
module_name: Atom, module_name: Atom,
key: PredicateKey, key: PredicateKey,
@@ -297,7 +297,7 @@ impl Machine {
unreachable!(); 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[1] = stream_as_cell!(stream);
self.machine_st.registers[2] = self.machine_st.registers[2] =
atom_as_cell!(AtomTable::build_with(&self.machine_st.atom_tbl, path)); 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); 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(); let output_bytes: Vec<_> = self.user_output.bytes().map(|b| b.unwrap()).collect();
String::from_utf8(output_bytes).unwrap() String::from_utf8(output_bytes).unwrap()
} }

View File

@@ -24,7 +24,7 @@ pub enum QueryResolution {
Matches(Vec<QueryMatch>), Matches(Vec<QueryMatch>),
} }
pub fn write_prolog_value_as_json<W: Write>( fn write_prolog_value_as_json<W: Write>(
writer: &mut W, writer: &mut W,
value: &Value, value: &Value,
) -> Result<(), std::fmt::Error> { ) -> Result<(), std::fmt::Error> {

View File

@@ -26,7 +26,7 @@ impl Expectable for &[u8] {
/// Tests whether the file can be successfully loaded /// Tests whether the file can be successfully loaded
/// and produces the expected output during it /// and produces the expected output during it
pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) { 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(); let mut wam = Machine::with_test_streams();
expected.assert_eq(wam.test_load_file(file).as_slice()); expected.assert_eq(wam.test_load_file(file).as_slice());