schala.rs - clippy lints
This commit is contained in:
parent
a9b8fdcad6
commit
052a2feb23
@ -1,25 +1,19 @@
|
|||||||
use stopwatch::Stopwatch;
|
use stopwatch::Stopwatch;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use schala_repl::{ProgrammingLanguageInterface,
|
use schala_repl::{ProgrammingLanguageInterface,
|
||||||
ComputationRequest, ComputationResponse,
|
ComputationRequest, ComputationResponse,
|
||||||
LangMetaRequest, LangMetaResponse, GlobalOutputStats};
|
LangMetaRequest, LangMetaResponse, GlobalOutputStats};
|
||||||
use crate::{reduced_ast, tokenizing, parsing, eval, typechecking, symbol_table};
|
use crate::{reduced_ast, tokenizing, parsing, eval, typechecking, symbol_table};
|
||||||
use crate::error::SchalaError;
|
use crate::error::SchalaError;
|
||||||
|
|
||||||
pub type SymbolTableHandle = Rc<RefCell<symbol_table::SymbolTable>>;
|
|
||||||
|
|
||||||
/// All the state necessary to parse and execute a Schala program are stored in this struct.
|
/// All the state necessary to parse and execute a Schala program are stored in this struct.
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct Schala {
|
pub struct Schala {
|
||||||
/// Holds a reference to the original source code, parsed into line and character
|
/// Holds a reference to the original source code, parsed into line and character
|
||||||
source_reference: SourceReference,
|
source_reference: SourceReference,
|
||||||
/// Execution state for AST-walking interpreter
|
/// Execution state for AST-walking interpreter
|
||||||
state: eval::State<'static>,
|
state: eval::State<'static>,
|
||||||
/// Keeps track of symbols and scopes
|
/// Keeps track of symbols and scopes
|
||||||
symbol_table: SymbolTableHandle,
|
symbol_table: symbol_table::SymbolTable,
|
||||||
/// Contains information for type-checking
|
/// Contains information for type-checking
|
||||||
type_context: typechecking::TypeContext<'static>,
|
type_context: typechecking::TypeContext<'static>,
|
||||||
/// Schala Parser
|
/// Schala Parser
|
||||||
@ -40,10 +34,9 @@ impl Schala {
|
|||||||
impl Schala {
|
impl Schala {
|
||||||
/// Creates a new Schala environment *without* any prelude.
|
/// Creates a new Schala environment *without* any prelude.
|
||||||
fn new_blank_env() -> Schala {
|
fn new_blank_env() -> Schala {
|
||||||
let symbols = Rc::new(RefCell::new(symbol_table::SymbolTable::new()));
|
|
||||||
Schala {
|
Schala {
|
||||||
source_reference: SourceReference::new(),
|
source_reference: SourceReference::new(),
|
||||||
symbol_table: symbols.clone(),
|
symbol_table: symbol_table::SymbolTable::new(),
|
||||||
state: eval::State::new(),
|
state: eval::State::new(),
|
||||||
type_context: typechecking::TypeContext::new(),
|
type_context: typechecking::TypeContext::new(),
|
||||||
active_parser: parsing::Parser::new()
|
active_parser: parsing::Parser::new()
|
||||||
@ -52,6 +45,7 @@ impl Schala {
|
|||||||
|
|
||||||
/// Creates a new Schala environment with the standard prelude, which is defined as ordinary
|
/// Creates a new Schala environment with the standard prelude, which is defined as ordinary
|
||||||
/// Schala code in the file `prelude.schala`
|
/// Schala code in the file `prelude.schala`
|
||||||
|
#[allow(clippy::new_without_default)]
|
||||||
pub fn new() -> Schala {
|
pub fn new() -> Schala {
|
||||||
let prelude = include_str!("../source-files/prelude.schala");
|
let prelude = include_str!("../source-files/prelude.schala");
|
||||||
let mut env = Schala::new_blank_env();
|
let mut env = Schala::new_blank_env();
|
||||||
@ -80,8 +74,8 @@ impl Schala {
|
|||||||
.map_err(|err| SchalaError::from_parse_error(err, &self.source_reference))?;
|
.map_err(|err| SchalaError::from_parse_error(err, &self.source_reference))?;
|
||||||
|
|
||||||
//Perform all symbol table work
|
//Perform all symbol table work
|
||||||
self.symbol_table.borrow_mut().process_ast(&ast)
|
self.symbol_table.process_ast(&ast)
|
||||||
.map_err(|err| SchalaError::from_symbol_table(err))?;
|
.map_err(SchalaError::from_symbol_table)?;
|
||||||
|
|
||||||
// Typechecking
|
// Typechecking
|
||||||
// TODO typechecking not working
|
// TODO typechecking not working
|
||||||
@ -89,8 +83,7 @@ impl Schala {
|
|||||||
.map_err(SchalaError::from_type_error);
|
.map_err(SchalaError::from_type_error);
|
||||||
|
|
||||||
// Reduce AST - TODO this doesn't produce an error yet, but probably should
|
// Reduce AST - TODO this doesn't produce an error yet, but probably should
|
||||||
let symbol_table = self.symbol_table.borrow();
|
let reduced_ast = reduced_ast::reduce(&ast, &self.symbol_table);
|
||||||
let reduced_ast = reduced_ast::reduce(&ast, &symbol_table);
|
|
||||||
|
|
||||||
// Tree-walking evaluator. TODO fix this
|
// Tree-walking evaluator. TODO fix this
|
||||||
let evaluation_outputs = self.state.evaluate(reduced_ast, true);
|
let evaluation_outputs = self.state.evaluate(reduced_ast, true);
|
||||||
@ -124,7 +117,7 @@ impl SourceReference {
|
|||||||
self.lines = Some(source.lines().map(|s| s.to_string()).collect()); }
|
self.lines = Some(source.lines().map(|s| s.to_string()).collect()); }
|
||||||
|
|
||||||
pub fn get_line(&self, line: usize) -> String {
|
pub fn get_line(&self, line: usize) -> String {
|
||||||
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_else(|| "NO LINE FOUND".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +179,7 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
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()),
|
||||||
_ => LangMetaResponse::Custom { kind: format!("not-implemented"), value: format!("") }
|
_ => LangMetaResponse::Custom { kind: "not-implemented".to_string(), value: "".to_string() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user