Port Schala to new framework
Evaluating a Schala function in the REPL works again with no debug info
This commit is contained in:
parent
70f715fbb2
commit
8610bd7a87
@ -23,7 +23,7 @@ use std::cell::RefCell;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use itertools::Itertools;
|
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 {
|
macro_rules! bx {
|
||||||
($e:expr) => { Box::new($e) }
|
($e:expr) => { Box::new($e) }
|
||||||
@ -43,12 +43,14 @@ mod reduced_ast;
|
|||||||
mod eval;
|
mod eval;
|
||||||
|
|
||||||
//trace_macros!(true);
|
//trace_macros!(true);
|
||||||
|
/*
|
||||||
#[derive(ProgrammingLanguageInterface)]
|
#[derive(ProgrammingLanguageInterface)]
|
||||||
#[LanguageName = "Schala"]
|
#[LanguageName = "Schala"]
|
||||||
#[SourceFileExtension = "schala"]
|
#[SourceFileExtension = "schala"]
|
||||||
#[PipelineSteps(load_source, tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)]
|
#[PipelineSteps(load_source, tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)]
|
||||||
#[DocMethod = "get_doc"]
|
#[DocMethod = "get_doc"]
|
||||||
#[HandleCustomInterpreterDirectives = "handle_custom_interpreter_directives"]
|
#[HandleCustomInterpreterDirectives = "handle_custom_interpreter_directives"]
|
||||||
|
*/
|
||||||
/// All bits of state necessary to parse and execute a Schala program are stored in this struct.
|
/// 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
|
/// `state` represents the execution state for the AST-walking interpreter, the other fields
|
||||||
/// should be self-explanatory.
|
/// 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"))
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,10 +8,10 @@ edition = "2018"
|
|||||||
llvm-sys = "70.0.2"
|
llvm-sys = "70.0.2"
|
||||||
take_mut = "0.2.2"
|
take_mut = "0.2.2"
|
||||||
itertools = "0.5.8"
|
itertools = "0.5.8"
|
||||||
getopts = "*"
|
getopts = "0.2.18"
|
||||||
lazy_static = "0.2.8"
|
lazy_static = "0.2.8"
|
||||||
maplit = "*"
|
maplit = "*"
|
||||||
colored = "1.5"
|
colored = "1.7"
|
||||||
serde = "1.0.15"
|
serde = "1.0.15"
|
||||||
serde_derive = "1.0.15"
|
serde_derive = "1.0.15"
|
||||||
serde_json = "1.0.3"
|
serde_json = "1.0.3"
|
||||||
|
@ -57,7 +57,7 @@ fn command_line_options() -> getopts::Options {
|
|||||||
/* --------------------------- */
|
/* --------------------------- */
|
||||||
|
|
||||||
pub use language::{ProgrammingLanguageInterface, EvalOptions,
|
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>;
|
pub type PLIGenerator = Box<Fn() -> Box<ProgrammingLanguageInterface> + Send + Sync>;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
|||||||
use colored::*;
|
use colored::*;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use crate::language::{ProgrammingLanguageInterface, EvalOptions,
|
use crate::language::{ProgrammingLanguageInterface, EvalOptions,
|
||||||
PassDebugOptionsDescriptor};
|
PassDebugOptionsDescriptor, ComputationRequest, ComputationResponse};
|
||||||
mod command_tree;
|
mod command_tree;
|
||||||
use self::command_tree::CommandTree;
|
use self::command_tree::CommandTree;
|
||||||
|
|
||||||
@ -96,11 +96,29 @@ impl NewRepl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_interpreter_directive(&mut self, input: &str) -> Option<String> {
|
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 {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user