schala/schala-repl/src/language.rs
2019-03-16 11:10:39 -07:00

85 lines
2.0 KiB
Rust

use std::collections::HashMap;
use colored::*;
use std::time;
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct EvalOptions {
pub execution_method: ExecutionMethod,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum ExecutionMethod {
Compile,
Interpret,
}
impl Default for ExecutionMethod {
fn default() -> ExecutionMethod {
ExecutionMethod::Interpret
}
}
pub trait ProgrammingLanguageInterface {
fn get_language_name(&self) -> String;
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 repl_request(&self, repl_request: String) -> String {
format!(">> No custom interpreter directives or help info specified <<")
}
}
//TODO source can probably be a &str
pub struct ComputationRequest {
pub source: String,
pub debug_requests: Vec<DebugRequest>,
}
pub struct ComputationResponse {
pub main_output: Result<String, String>,
pub global_output_stats: GlobalOutputStats,
pub debug_responses: Vec<DebugResponse>,
}
pub struct DebugRequest {
kind: String,
value: String
}
pub struct DebugResponse {
kind: String,
value: String
}
#[derive(Default, Debug)]
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
}
}
}
*/