Thread SchalaConfig for repl/non-repl in runner

This commit is contained in:
Greg Shuflin
2021-10-31 03:30:45 -07:00
parent d084deac80
commit 76f7524fdb
6 changed files with 30 additions and 20 deletions

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::time;
pub trait ProgrammingLanguageInterface {
type Config: Default;
type Config: Default + Clone;
fn language_name() -> String;
fn source_file_suffix() -> String;

View File

@@ -66,14 +66,14 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
}
}
pub fn run_repl(&mut self) {
pub fn run_repl(&mut self, config: L::Config) {
println!("Schala meta-interpeter version {}", VERSION_STRING);
println!(
"Type {} for help with the REPL",
format!("{}help", self.sigil).bright_green().bold()
);
self.load_options();
self.handle_repl_loop();
self.handle_repl_loop(config);
self.save_before_exit();
println!("Exiting...");
}
@@ -90,7 +90,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
}
}
fn handle_repl_loop(&mut self) {
fn handle_repl_loop(&mut self, config: L::Config) {
use linefeed::ReadResult::*;
'main: loop {
@@ -128,7 +128,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
buf.push('\n');
}
}
self.handle_input(&buf)
self.handle_input(&buf, &config)
} else {
if let Some(output) = self.handle_interpreter_directive(input.get(1..).unwrap()) {
println!("{}", output);
@@ -136,7 +136,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
continue;
}
}
_ => self.handle_input(input),
_ => self.handle_input(input, &config),
};
for repl_response in repl_responses.iter() {
@@ -179,7 +179,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
directives.perform(self, &arguments)
}
fn handle_input(&mut self, input: &str) -> Vec<ReplResponse> {
fn handle_input(&mut self, input: &str, config: &L::Config) -> Vec<ReplResponse> {
let mut debug_requests = HashSet::new();
for ask in self.options.debug_asks.iter() {
debug_requests.insert(ask.clone());
@@ -187,7 +187,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
let request = ComputationRequest {
source: input,
config: Default::default(),
config: config.clone(),
debug_requests,
};
let response = self.language_state.run_computation(request);