schala/schala-repl/src/language.rs

94 lines
2.0 KiB
Rust
Raw Normal View History

use std::time;
2017-09-08 03:47:04 -07:00
2017-08-30 19:09:22 -07:00
pub trait ProgrammingLanguageInterface {
fn get_language_name(&self) -> String;
2017-10-02 23:07:05 -07:00
fn get_source_file_suffix(&self) -> String;
fn run_computation(&mut self, _request: ComputationRequest) -> ComputationResponse {
ComputationResponse {
main_output: Err(format!("Computation pipeline not implemented")),
global_output_stats: GlobalOutputStats::default(),
debug_responses: vec![],
}
}
fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse {
LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") }
}
}
2019-03-19 19:01:04 -07:00
pub struct ComputationRequest<'a> {
pub source: &'a str,
pub debug_requests: Vec<DebugRequest>,
}
2019-03-13 10:10:42 -07:00
pub struct ComputationResponse {
pub main_output: Result<String, String>,
pub global_output_stats: GlobalOutputStats,
pub debug_responses: Vec<DebugResponse>,
2017-08-30 19:09:22 -07:00
}
2019-03-12 00:01:30 -07:00
2019-03-13 10:10:42 -07:00
pub struct DebugRequest {
pub ask: DebugAsk,
}
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum DebugAsk {
Timing,
ByStage { stage_name: String },
}
2019-03-12 00:01:30 -07:00
2019-03-13 10:10:42 -07:00
pub struct DebugResponse {
pub ask: DebugAsk,
2019-03-27 02:20:43 -07:00
pub value: String
}
pub enum LangMetaRequest {
StageNames,
2019-03-19 19:26:05 -07:00
Docs {
source: String,
},
Custom {
kind: String,
value: String
2019-03-27 02:20:43 -07:00
},
ImmediateDebug(DebugRequest),
}
pub enum LangMetaResponse {
StageNames(Vec<String>),
2019-03-19 19:26:05 -07:00
Docs {
doc_string: String,
},
Custom {
kind: String,
value: String
2019-03-27 02:20:43 -07:00
},
ImmediateDebug(DebugResponse),
}
#[derive(Default, Debug)]
2019-03-13 10:10:42 -07:00
pub struct GlobalOutputStats {
total_duration: Option<time::Duration>,
stage_durations: Option<Vec<(String, time::Duration)>>
}
/*
impl GlobalOutputStats {
fn get_timing(&self) -> Option<String> {
if self.durations.len() != 0 {
let mut buf = String::new();
write!(&mut buf, "Timing: ").unwrap();
for duration in self.durations.iter() {
let timing = (duration.as_secs() as f64) + (duration.subsec_nanos() as f64 * 1e-9);
write!(&mut buf, "{}s, ", timing).unwrap()
}
write!(&mut buf, "\n").unwrap();
Some(buf)
} else {
None
}
}
}
*/