Skip to content

Commit

Permalink
Be conservative with visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaq committed Sep 3, 2024
1 parent 12a61cd commit e06ea4c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 50 deletions.
2 changes: 1 addition & 1 deletion benches/run_iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 2 additions & 5 deletions benches/setup.rs
Original file line number Diff line number Diff line change
@@ -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> {
[
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 1 addition & 25 deletions src/bin/scryer-prolog.rs
Original file line number Diff line number Diff line change
@@ -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()
}
54 changes: 44 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
})
}
2 changes: 1 addition & 1 deletion src/machine/mock_wam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Machine {
self.user_output.bytes().map(|b| b.unwrap()).collect()
}

pub fn test_load_string(&mut self, code: &str) -> Vec<u8> {
fn test_load_string(&mut self, code: &str) -> Vec<u8> {
let stream = Stream::from_owned_string(code.to_owned(), &mut self.machine_st.arena);

self.load_file("<stdin>", stream);
Expand Down
12 changes: 6 additions & 6 deletions src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -270,15 +270,15 @@ 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);

self.machine_st.throw_exception(err);
}

pub fn run_module_predicate(
pub(crate) fn run_module_predicate(
&mut self,
module_name: Atom,
key: PredicateKey,
Expand All @@ -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));
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/machine/parsed_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion tests/scryer/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e06ea4c

Please sign in to comment.