]> Repositorios git - scryer-prolog.git/commitdiff
Add Machine::set_user_input(&mut self, input: String) and get_user_output() -> String...
authorNicolas Luck <[email protected]>
Tue, 11 Jul 2023 12:22:27 +0000 (14:22 +0200)
committerNicolas Luck <[email protected]>
Tue, 11 Jul 2023 12:22:27 +0000 (14:22 +0200)
src/machine/machine_state.rs
src/machine/mod.rs

index 6aa5191674f0344bb9c8706a23e7316d079a01eb..50431a8aa24d5e01de514a39603ae5ac55ef0bdc 100644 (file)
@@ -495,6 +495,10 @@ impl MachineState {
             }
         }
 
+        if let Stream::Byte(_) = stream {
+            return self.read_term(stream, indices)
+        }
+
         unreachable!("Stream must be a Stream::Readline(_)")
     }
 
index 4cd1fce83d84abdc2194699a28900a2a95ad9895..f7beecd3bd417722cae1cc5157c726e3efaa2d90 100644 (file)
@@ -47,6 +47,7 @@ use ordered_float::OrderedFloat;
 
 use std::cmp::Ordering;
 use std::env;
+use std::io::Read;
 use std::path::PathBuf;
 use std::sync::atomic::AtomicBool;
 use tokio::runtime::Runtime;
@@ -306,6 +307,15 @@ impl Machine {
         self.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 1));
     }
 
+    pub 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(&mut self) -> String {
+        let output_bytes: Vec<_> = self.user_output.bytes().map(|b| b.unwrap()).collect();
+        String::from_utf8(output_bytes).unwrap()
+    }
+
     pub(crate) fn configure_modules(&mut self) {
         fn update_call_n_indices(loader: &Module, target_code_dir: &mut CodeDir, arena: &mut Arena) {
             for arity in 1..66 {