schala/schala-repl/src/language.rs

77 lines
1.9 KiB
Rust
Raw Normal View History

2019-05-26 04:16:40 -07:00
use std::collections::HashSet;
2021-10-07 01:19:35 -07:00
use std::time;
2017-09-08 03:47:04 -07:00
2017-08-30 19:09:22 -07:00
pub trait ProgrammingLanguageInterface {
2021-10-07 01:19:35 -07:00
fn get_language_name(&self) -> String;
fn get_source_file_suffix(&self) -> String;
2021-10-07 01:19:35 -07:00
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![],
}
}
2021-10-07 01:19:35 -07:00
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> {
2021-10-07 01:19:35 -07:00
pub source: &'a str,
pub debug_requests: HashSet<DebugAsk>,
}
2019-03-13 10:10:42 -07:00
pub struct ComputationResponse {
2021-10-07 01:19:35 -07:00
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-05-21 02:06:34 -07:00
#[derive(Default, Debug)]
pub struct GlobalOutputStats {
2021-10-07 01:19:35 -07:00
pub total_duration: time::Duration,
pub stage_durations: Vec<(String, time::Duration)>,
2019-05-21 02:06:34 -07:00
}
2019-05-14 00:40:38 -07:00
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize, Serialize)]
pub enum DebugAsk {
2021-10-07 01:19:35 -07:00
Timing,
ByStage {
stage_name: String,
token: Option<String>,
},
}
2019-03-12 00:01:30 -07:00
2019-06-22 12:13:43 -07:00
impl DebugAsk {
2021-10-07 01:19:35 -07:00
pub fn is_for_stage(&self, name: &str) -> bool {
match self {
DebugAsk::ByStage { stage_name, .. } if stage_name == name => true,
_ => false,
}
2019-06-22 12:13:43 -07:00
}
}
2019-03-13 10:10:42 -07:00
pub struct DebugResponse {
2021-10-07 01:19:35 -07:00
pub ask: DebugAsk,
pub value: String,
}
pub enum LangMetaRequest {
2021-10-07 01:19:35 -07:00
StageNames,
Docs { source: String },
Custom { kind: String, value: String },
ImmediateDebug(DebugAsk),
}
pub enum LangMetaResponse {
2021-10-07 01:19:35 -07:00
StageNames(Vec<String>),
Docs { doc_string: String },
Custom { kind: String, value: String },
ImmediateDebug(DebugResponse),
}