Add Machine::set_user_input(&mut self, input: String) and get_user_output() -> String. Make read_term_from_user_input() handle Stream::Byte.

This commit is contained in:
Nicolas Luck
2023-07-11 14:22:27 +02:00
parent eb9d865635
commit 95b31146b5
2 changed files with 14 additions and 0 deletions

View 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 {