MachineConfig, PrologTerm,
};
+/// An iterator though the leaf answers of a query.
pub struct QueryState<'a> {
machine: &'a mut Machine,
term: TermWriteResult,
}
impl Machine {
+ /// Creates a new [`Machine`] configured for use as a library.
pub fn new_lib() -> Self {
Machine::new(MachineConfig::default().with_streams(StreamConfig::in_memory()))
}
- pub fn load_module_string(&mut self, module_name: &str, program: String) {
- let stream = Stream::from_owned_string(program, &mut self.machine_st.arena);
+ /// Loads a module into the [`Machine`] from a string.
+ pub fn load_module_string(&mut self, module_name: &str, program: impl Into<String>) {
+ let stream = Stream::from_owned_string(program.into(), &mut self.machine_st.arena);
self.load_file(module_name, stream);
}
- pub fn consult_module_string(&mut self, module_name: &str, program: String) {
- let stream = Stream::from_owned_string(program, &mut self.machine_st.arena);
+ /// Consults a module into the [`Machine`] from a string.
+ pub fn consult_module_string(&mut self, module_name: &str, program: impl Into<String>) {
+ let stream = Stream::from_owned_string(program.into(), &mut self.machine_st.arena);
self.machine_st.registers[1] = stream_as_cell!(stream);
self.machine_st.registers[2] = atom_as_cell!(&atom_table::AtomTable::build_with(
&self.machine_st.atom_tbl,
self.machine_st.block = stub_b;
}
- pub fn run_query(&mut self, query: String) -> QueryState {
+ /// Runs a query.
+ pub fn run_query(&mut self, query: impl Into<String>) -> QueryState {
let mut parser = Parser::new(
- Stream::from_owned_string(query, &mut self.machine_st.arena),
+ Stream::from_owned_string(query.into(), &mut self.machine_st.arena),
&mut self.machine_st,
);
let op_dir = CompositeOpDir::new(&self.indices.op_dir, None);
pub static ref INTERRUPT: AtomicBool = AtomicBool::new(false);
}
+/// An instance of Scryer Prolog.
#[derive(Debug)]
pub struct Machine {
pub(super) machine_st: MachineState,
)
}
+ /// Gets the current inference count.
pub fn get_inference_count(&mut self) -> u64 {
self.machine_st
.cwil
}
}
+ /// Creates a new [`Machine`] from a [`MachineConfig`].
#[allow(clippy::new_without_default)]
pub fn new(config: MachineConfig) -> Self {
let args = MachineArgs::new();