WIP thing
This commit is contained in:
parent
d01d280452
commit
c3131a6d5e
@ -152,11 +152,10 @@ impl Expression {
|
|||||||
Expression { id, kind, type_anno: None }
|
Expression { id, kind, type_anno: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - commented out because unused
|
#[cfg(test)]
|
||||||
pub fn with_anno(id: ItemId, kind: ExpressionKind, type_anno: TypeIdentifier) -> Expression {
|
pub fn with_anno(id: ItemId, kind: ExpressionKind, type_anno: TypeIdentifier) -> Expression {
|
||||||
Expression { id, kind, type_anno: Some(type_anno) }
|
Expression { id, kind, type_anno: Some(type_anno) }
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use stopwatch::Stopwatch;
|
use stopwatch::Stopwatch;
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -30,11 +29,14 @@ pub struct Schala {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Schala {
|
impl Schala {
|
||||||
|
//TODO implement documentation for language items
|
||||||
|
/*
|
||||||
fn handle_docs(&self, source: String) -> LangMetaResponse {
|
fn handle_docs(&self, source: String) -> LangMetaResponse {
|
||||||
LangMetaResponse::Docs {
|
LangMetaResponse::Docs {
|
||||||
doc_string: format!("Schala item `{}` : <<Schala-lang documentation not yet implemented>>", source)
|
doc_string: format!("Schala item `{}` : <<Schala-lang documentation not yet implemented>>", source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Schala {
|
impl Schala {
|
||||||
@ -60,6 +62,7 @@ impl Schala {
|
|||||||
let prelude = include_str!("prelude.schala");
|
let prelude = include_str!("prelude.schala");
|
||||||
let mut s = Schala::new_blank_env();
|
let mut s = Schala::new_blank_env();
|
||||||
|
|
||||||
|
//TODO this shouldn't depend on schala-repl types
|
||||||
let request = ComputationRequest { source: prelude, debug_requests: HashSet::default() };
|
let request = ComputationRequest { source: prelude, debug_requests: HashSet::default() };
|
||||||
let response = s.run_computation(request);
|
let response = s.run_computation(request);
|
||||||
if let Err(msg) = response.main_output {
|
if let Err(msg) = response.main_output {
|
||||||
@ -68,41 +71,51 @@ impl Schala {
|
|||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_debug_immediate(&self, request: DebugAsk) -> DebugResponse {
|
/// This is where the actual action of interpreting/compilation happens.
|
||||||
use DebugAsk::*;
|
/// Note: this should eventually use a query-based system for parallelization, cf.
|
||||||
match request {
|
/// https://rustc-dev-guide.rust-lang.org/overview.html
|
||||||
Timing => DebugResponse { ask: Timing, value: format!("Invalid") },
|
fn run_pipeline(&mut self, source: &str) -> Result<String, String> {
|
||||||
ByStage { stage_name, token } => match &stage_name[..] {
|
//TODO `run_pipeline` should return a formatted error struct
|
||||||
"symbol-table" => {
|
|
||||||
let value = self.symbol_table.borrow().debug_symbol_table();
|
//TODO every stage should have a common error-format that gets turned into a repl-appropriate
|
||||||
DebugResponse {
|
//string in `run_computation`
|
||||||
ask: ByStage { stage_name: format!("symbol-table"), token },
|
// 1st stage - tokenization
|
||||||
value
|
// TODO tokenize should return its own error type
|
||||||
}
|
let tokens = tokenizing::tokenize(source);
|
||||||
},
|
let token_errors: Vec<String> = tokens.iter().filter_map(|t| t.get_error()).collect();
|
||||||
s => {
|
if token_errors.len() > 0 {
|
||||||
DebugResponse {
|
return Err(format!("{:?}", token_errors));
|
||||||
ask: ByStage { stage_name: s.to_string(), token: None },
|
|
||||||
value: format!("Not-implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<Vec<tokenizing::Token>, String> {
|
//2nd stage - parsing
|
||||||
let tokens = tokenizing::tokenize(input);
|
self.active_parser.add_new_tokens(tokens);
|
||||||
comp.map(|comp| {
|
let mut ast = self.active_parser.parse()
|
||||||
let token_string = tokens.iter().map(|t| t.to_string_with_metadata()).join(", ");
|
.map_err(|err| format_parse_error(err, &self.source_reference))?;
|
||||||
comp.add_artifact(token_string);
|
|
||||||
});
|
|
||||||
|
|
||||||
let errors: Vec<String> = tokens.iter().filter_map(|t| t.get_error()).collect();
|
// Symbol table
|
||||||
if errors.len() == 0 {
|
self.symbol_table.borrow_mut().add_top_level_symbols(&ast)?;
|
||||||
Ok(tokens)
|
|
||||||
} else {
|
// Scope resolution - requires mutating AST
|
||||||
Err(format!("{:?}", errors))
|
self.resolver.resolve(&mut ast)?;
|
||||||
|
|
||||||
|
// Typechecking
|
||||||
|
let overall_type = self.type_context.typecheck(&ast)
|
||||||
|
.map_err(|err| format!("Type error: {}", err.msg))?;
|
||||||
|
|
||||||
|
// Reduce AST - this doesn't produce an error yet, but probably should
|
||||||
|
let symbol_table = self.symbol_table.borrow();
|
||||||
|
let reduced_ast = reduced_ast::reduce(&ast, &symbol_table);
|
||||||
|
|
||||||
|
// Tree-walking evaluator. TODO fix this
|
||||||
|
let evaluation_outputs = self.state.evaluate(reduced_ast, true);
|
||||||
|
let text_output: Result<Vec<String>, String> = evaluation_outputs
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let eval_output: String = text_output
|
||||||
|
.map(|v| { Iterator::intersperse(v.into_iter(), "\n".to_owned()).collect() })?;
|
||||||
|
|
||||||
|
Ok(eval_output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,6 +272,27 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
"schala".to_owned()
|
"schala".to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
|
||||||
|
let ComputationRequest { source, debug_requests } = request;
|
||||||
|
self.source_reference.load_new_source(source);
|
||||||
|
let sw = Stopwatch::start_new();
|
||||||
|
|
||||||
|
let main_output = self.run_pipeline(source);
|
||||||
|
|
||||||
|
let global_output_stats = GlobalOutputStats {
|
||||||
|
total_duration: sw.elapsed(),
|
||||||
|
stage_durations: vec![]
|
||||||
|
};
|
||||||
|
|
||||||
|
ComputationResponse {
|
||||||
|
main_output,
|
||||||
|
global_output_stats,
|
||||||
|
debug_responses: vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// n.b. - old-style, overcomplicated `run_computation`. need to revamp the entire metadata system
|
||||||
|
/*
|
||||||
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
|
fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
|
||||||
struct PassToken<'a> {
|
struct PassToken<'a> {
|
||||||
schala: &'a mut Schala,
|
schala: &'a mut Schala,
|
||||||
@ -331,14 +365,12 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
debug_responses,
|
debug_responses,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
|
fn request_meta(&mut self, request: LangMetaRequest) -> LangMetaResponse {
|
||||||
match request {
|
match request {
|
||||||
LangMetaRequest::StageNames => LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()),
|
LangMetaRequest::StageNames => LangMetaResponse::StageNames(stage_names().iter().map(|s| s.to_string()).collect()),
|
||||||
LangMetaRequest::Docs { source } => self.handle_docs(source),
|
_ => LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") }
|
||||||
LangMetaRequest::ImmediateDebug(debug_request) =>
|
|
||||||
LangMetaResponse::ImmediateDebug(self.handle_debug_immediate(debug_request)),
|
|
||||||
LangMetaRequest::Custom { .. } => LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user