Parameterize compiler Config type

This commit is contained in:
Greg Shuflin 2021-10-14 02:24:42 -07:00
parent 2d72f560ed
commit 61e2acc338
4 changed files with 13 additions and 14 deletions

View File

@ -2,7 +2,6 @@ use stopwatch::Stopwatch;
use std::cell::RefCell;
use std::rc::Rc;
use std::collections::HashSet;
use schala_repl::{ProgrammingLanguageInterface,
ComputationRequest, ComputationResponse,
@ -58,15 +57,13 @@ impl Schala {
/// Schala code in the file `prelude.schala`
pub fn new() -> Schala {
let prelude = include_str!("prelude.schala");
let mut s = Schala::new_blank_env();
let mut env = Schala::new_blank_env();
//TODO this shouldn't depend on schala-repl types
let request = ComputationRequest { source: prelude, debug_requests: HashSet::default() };
let response = s.run_computation(request);
if let Err(msg) = response.main_output {
let response = env.run_pipeline(prelude);
if let Err(msg) = response {
panic!("Error in prelude, panicking: {}", msg);
}
s
env
}
/// This is where the actual action of interpreting/compilation happens.
@ -174,7 +171,7 @@ fn stage_names() -> Vec<&'static str> {
impl ProgrammingLanguageInterface for Schala {
type Options = ();
type Config = ();
fn language_name() -> String {
"Schala".to_owned()
}
@ -183,8 +180,8 @@ impl ProgrammingLanguageInterface for Schala {
"schala".to_owned()
}
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
let ComputationRequest { source, debug_requests: _ } = request;
fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse {
let ComputationRequest { source, debug_requests: _, config: _ } = request;
self.source_reference.load_new_source(source);
let sw = Stopwatch::start_new();

View File

@ -2,11 +2,11 @@ use std::collections::HashSet;
use std::time;
pub trait ProgrammingLanguageInterface {
type Options;
type Config: Default;
fn language_name() -> String;
fn source_file_suffix() -> String;
fn run_computation(&mut self, _request: ComputationRequest) -> ComputationResponse;
fn run_computation(&mut self, _request: ComputationRequest<Self::Config>) -> ComputationResponse;
fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse {
LangMetaResponse::Custom {
@ -23,9 +23,9 @@ struct Options<T> {
}
*/
pub struct ComputationRequest<'a> {
pub struct ComputationRequest<'a, T> {
pub source: &'a str,
//pub options: Options<()>,
pub config: T,
pub debug_requests: HashSet<DebugAsk>,
}

View File

@ -187,6 +187,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
let request = ComputationRequest {
source: input,
config: Default::default(),
debug_requests,
};
let response = self.language_state.run_computation(request);

View File

@ -52,6 +52,7 @@ pub fn run_noninteractive<L: ProgrammingLanguageInterface>(filenames: Vec<PathBu
let request = ComputationRequest {
source: &buffer,
config: Default::default(),
debug_requests: HashSet::new(),
};