Parameterize compiler Config type
This commit is contained in:
parent
2d72f560ed
commit
61e2acc338
@ -2,7 +2,6 @@ use stopwatch::Stopwatch;
|
|||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use schala_repl::{ProgrammingLanguageInterface,
|
use schala_repl::{ProgrammingLanguageInterface,
|
||||||
ComputationRequest, ComputationResponse,
|
ComputationRequest, ComputationResponse,
|
||||||
@ -58,15 +57,13 @@ impl Schala {
|
|||||||
/// Schala code in the file `prelude.schala`
|
/// Schala code in the file `prelude.schala`
|
||||||
pub fn new() -> Schala {
|
pub fn new() -> Schala {
|
||||||
let prelude = include_str!("prelude.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 response = env.run_pipeline(prelude);
|
||||||
let request = ComputationRequest { source: prelude, debug_requests: HashSet::default() };
|
if let Err(msg) = response {
|
||||||
let response = s.run_computation(request);
|
|
||||||
if let Err(msg) = response.main_output {
|
|
||||||
panic!("Error in prelude, panicking: {}", msg);
|
panic!("Error in prelude, panicking: {}", msg);
|
||||||
}
|
}
|
||||||
s
|
env
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is where the actual action of interpreting/compilation happens.
|
/// This is where the actual action of interpreting/compilation happens.
|
||||||
@ -174,7 +171,7 @@ fn stage_names() -> Vec<&'static str> {
|
|||||||
|
|
||||||
|
|
||||||
impl ProgrammingLanguageInterface for Schala {
|
impl ProgrammingLanguageInterface for Schala {
|
||||||
type Options = ();
|
type Config = ();
|
||||||
fn language_name() -> String {
|
fn language_name() -> String {
|
||||||
"Schala".to_owned()
|
"Schala".to_owned()
|
||||||
}
|
}
|
||||||
@ -183,8 +180,8 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
"schala".to_owned()
|
"schala".to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
|
fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse {
|
||||||
let ComputationRequest { source, debug_requests: _ } = request;
|
let ComputationRequest { source, debug_requests: _, config: _ } = request;
|
||||||
self.source_reference.load_new_source(source);
|
self.source_reference.load_new_source(source);
|
||||||
let sw = Stopwatch::start_new();
|
let sw = Stopwatch::start_new();
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@ use std::collections::HashSet;
|
|||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
pub trait ProgrammingLanguageInterface {
|
pub trait ProgrammingLanguageInterface {
|
||||||
type Options;
|
type Config: Default;
|
||||||
fn language_name() -> String;
|
fn language_name() -> String;
|
||||||
fn source_file_suffix() -> 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 {
|
fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse {
|
||||||
LangMetaResponse::Custom {
|
LangMetaResponse::Custom {
|
||||||
@ -23,9 +23,9 @@ struct Options<T> {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub struct ComputationRequest<'a> {
|
pub struct ComputationRequest<'a, T> {
|
||||||
pub source: &'a str,
|
pub source: &'a str,
|
||||||
//pub options: Options<()>,
|
pub config: T,
|
||||||
pub debug_requests: HashSet<DebugAsk>,
|
pub debug_requests: HashSet<DebugAsk>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +187,7 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
|
|||||||
|
|
||||||
let request = ComputationRequest {
|
let request = ComputationRequest {
|
||||||
source: input,
|
source: input,
|
||||||
|
config: Default::default(),
|
||||||
debug_requests,
|
debug_requests,
|
||||||
};
|
};
|
||||||
let response = self.language_state.run_computation(request);
|
let response = self.language_state.run_computation(request);
|
||||||
|
@ -52,6 +52,7 @@ pub fn run_noninteractive<L: ProgrammingLanguageInterface>(filenames: Vec<PathBu
|
|||||||
|
|
||||||
let request = ComputationRequest {
|
let request = ComputationRequest {
|
||||||
source: &buffer,
|
source: &buffer,
|
||||||
|
config: Default::default(),
|
||||||
debug_requests: HashSet::new(),
|
debug_requests: HashSet::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user