]> Repositorios git - scryer-prolog.git/commitdiff
Docs for Machine and QueryState
authorbakaq <[email protected]>
Mon, 30 Sep 2024 02:30:57 +0000 (23:30 -0300)
committerbakaq <[email protected]>
Sun, 8 Dec 2024 23:18:06 +0000 (20:18 -0300)
src/machine/lib_machine.rs
src/machine/mod.rs

index 4137a9855ff322e06b56c87b2f89e40f5300815e..5f0f4213505eb8693ff55605663470ead24faa56 100644 (file)
@@ -14,6 +14,7 @@ use super::{
     MachineConfig, PrologTerm,
 };
 
+/// An iterator though the leaf answers of a query.
 pub struct QueryState<'a> {
     machine: &'a mut Machine,
     term: TermWriteResult,
@@ -146,17 +147,20 @@ impl Iterator for QueryState<'_> {
 }
 
 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,
@@ -190,9 +194,10 @@ impl Machine {
         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);
index 94f2842f804a9aeb6e766f6f84ed22820a15f892..448734e4080e1115fc6294f07a6b47a03e165ef6 100644 (file)
@@ -70,6 +70,7 @@ lazy_static! {
     pub static ref INTERRUPT: AtomicBool = AtomicBool::new(false);
 }
 
+/// An instance of Scryer Prolog.
 #[derive(Debug)]
 pub struct Machine {
     pub(super) machine_st: MachineState,
@@ -262,6 +263,7 @@ impl Machine {
         )
     }
 
+    /// Gets the current inference count.
     pub fn get_inference_count(&mut self) -> u64 {
         self.machine_st
             .cwil
@@ -480,6 +482,7 @@ impl Machine {
         }
     }
 
+    /// Creates a new [`Machine`] from a [`MachineConfig`].
     #[allow(clippy::new_without_default)]
     pub fn new(config: MachineConfig) -> Self {
         let args = MachineArgs::new();