schala.rs - clippy lints

This commit is contained in:
Greg Shuflin 2021-10-19 20:45:59 -07:00
parent a9b8fdcad6
commit 052a2feb23
1 changed files with 8 additions and 15 deletions

View File

@ -1,25 +1,19 @@
use stopwatch::Stopwatch;
use std::cell::RefCell;
use std::rc::Rc;
use schala_repl::{ProgrammingLanguageInterface,
ComputationRequest, ComputationResponse,
LangMetaRequest, LangMetaResponse, GlobalOutputStats};
use crate::{reduced_ast, tokenizing, parsing, eval, typechecking, symbol_table};
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.
#[allow(dead_code)]
pub struct Schala {
/// Holds a reference to the original source code, parsed into line and character
source_reference: SourceReference,
/// Execution state for AST-walking interpreter
state: eval::State<'static>,
/// Keeps track of symbols and scopes
symbol_table: SymbolTableHandle,
symbol_table: symbol_table::SymbolTable,
/// Contains information for type-checking
type_context: typechecking::TypeContext<'static>,
/// Schala Parser
@ -40,10 +34,9 @@ impl Schala {
impl Schala {
/// Creates a new Schala environment *without* any prelude.
fn new_blank_env() -> Schala {
let symbols = Rc::new(RefCell::new(symbol_table::SymbolTable::new()));
Schala {
source_reference: SourceReference::new(),
symbol_table: symbols.clone(),
symbol_table: symbol_table::SymbolTable::new(),
state: eval::State::new(),
type_context: typechecking::TypeContext::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
/// Schala code in the file `prelude.schala`
#[allow(clippy::new_without_default)]
pub fn new() -> Schala {
let prelude = include_str!("../source-files/prelude.schala");
let mut env = Schala::new_blank_env();
@ -80,8 +74,8 @@ impl Schala {
.map_err(|err| SchalaError::from_parse_error(err, &self.source_reference))?;
//Perform all symbol table work
self.symbol_table.borrow_mut().process_ast(&ast)
.map_err(|err| SchalaError::from_symbol_table(err))?;
self.symbol_table.process_ast(&ast)
.map_err(SchalaError::from_symbol_table)?;
// Typechecking
// TODO typechecking not working
@ -89,8 +83,7 @@ impl Schala {
.map_err(SchalaError::from_type_error);
// 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, &symbol_table);
let reduced_ast = reduced_ast::reduce(&ast, &self.symbol_table);
// Tree-walking evaluator. TODO fix this
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()); }
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 {
match request {
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() }
}
}
}