Port Schala to new framework

Evaluating a Schala function in the REPL works again with no debug info
This commit is contained in:
greg 2019-03-13 22:43:44 -07:00
parent 70f715fbb2
commit 8610bd7a87
4 changed files with 54 additions and 7 deletions

View File

@ -23,7 +23,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use itertools::Itertools;
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, UnfinishedComputation, FinishedComputation};
use schala_repl::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, UnfinishedComputation, FinishedComputation, ComputationRequest, ComputationResponse, GlobalOutputStats};
macro_rules! bx {
($e:expr) => { Box::new($e) }
@ -43,12 +43,14 @@ mod reduced_ast;
mod eval;
//trace_macros!(true);
/*
#[derive(ProgrammingLanguageInterface)]
#[LanguageName = "Schala"]
#[SourceFileExtension = "schala"]
#[PipelineSteps(load_source, tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)]
#[DocMethod = "get_doc"]
#[HandleCustomInterpreterDirectives = "handle_custom_interpreter_directives"]
*/
/// All bits of state necessary to parse and execute a Schala program are stored in this struct.
/// `state` represents the execution state for the AST-walking interpreter, the other fields
/// should be self-explanatory.
@ -218,3 +220,30 @@ impl SourceReference {
self.lines.as_ref().and_then(|x| x.get(line).map(|s| s.to_string())).unwrap_or(format!("NO LINE FOUND"))
}
}
impl ProgrammingLanguageInterface for Schala {
fn get_language_name(&self) -> String { format!("Schala") }
fn get_source_file_suffix(&self) -> String { format!("schala") }
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
let ComputationRequest { source, debug_requests } = request;
load_source(&source, self, None);
let main_output: Result<String, String> = tokenizing(&source, self, None)
.and_then(|tokens| parsing(tokens, self, None))
.and_then(|ast| symbol_table(ast, self, None))
.and_then(|ast| typechecking(ast, self, None))
.and_then(|ast| ast_reducing(ast, self, None))
.and_then(|reduced_ast| eval(reduced_ast, self, None));
ComputationResponse {
main_output,
global_output_stats: GlobalOutputStats::default(),
debug_responses: vec![],
}
}
fn repl_request(&self, repl_request: String) -> String {
format!("Schala: can't understand {}", repl_request)
}
}

View File

@ -8,10 +8,10 @@ edition = "2018"
llvm-sys = "70.0.2"
take_mut = "0.2.2"
itertools = "0.5.8"
getopts = "*"
getopts = "0.2.18"
lazy_static = "0.2.8"
maplit = "*"
colored = "1.5"
colored = "1.7"
serde = "1.0.15"
serde_derive = "1.0.15"
serde_json = "1.0.3"

View File

@ -57,7 +57,7 @@ fn command_line_options() -> getopts::Options {
/* --------------------------- */
pub use language::{ProgrammingLanguageInterface, EvalOptions,
ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugOptionsDescriptor, PassDescriptor};
ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugOptionsDescriptor, PassDescriptor, ComputationRequest, ComputationResponse, GlobalOutputStats};
pub type PLIGenerator = Box<Fn() -> Box<ProgrammingLanguageInterface> + Send + Sync>;

View File

@ -6,7 +6,7 @@ use std::sync::Arc;
use colored::*;
use itertools::Itertools;
use crate::language::{ProgrammingLanguageInterface, EvalOptions,
PassDebugOptionsDescriptor};
PassDebugOptionsDescriptor, ComputationRequest, ComputationResponse};
mod command_tree;
use self::command_tree::CommandTree;
@ -96,11 +96,29 @@ impl NewRepl {
}
fn handle_interpreter_directive(&mut self, input: &str) -> Option<String> {
None
Some(format!("you typed {}, which is unsupported", input))
}
fn get_cur_language_state(&mut self) -> &mut Box<ProgrammingLanguageInterface> {
//TODO this is obviously not complete
&mut self.language_states[0]
}
fn handle_input(&mut self, input: &str) -> String {
format!("")
let ref mut language_state = self.get_cur_language_state();
let request = ComputationRequest {
source: input.to_string(),
debug_requests: vec![],
};
let ComputationResponse { main_output, global_output_stats, debug_responses }
= language_state.run_computation(request);
match main_output {
Ok(s) => s,
Err(e) => format!("{} {}", "Error".red(), e)
}
}
}