Compare commits

..

No commits in common. "421a33c42c74f72b7d7834b090972d066de24f7d" and "6ac0628265ce8d614f7cd87e541c0a030d05639b" have entirely different histories.

10 changed files with 53 additions and 35 deletions

2
Cargo.lock generated
View File

@ -836,6 +836,8 @@ dependencies = [
"ena", "ena",
"failure", "failure",
"itertools", "itertools",
"lazy_static 1.4.0",
"maplit",
"radix_trie", "radix_trie",
"schala-lang-codegen", "schala-lang-codegen",
"schala-repl", "schala-repl",

View File

@ -8,6 +8,8 @@ resolver = "2"
[dependencies] [dependencies]
itertools = "0.10" itertools = "0.10"
take_mut = "0.2.2" take_mut = "0.2.2"
maplit = "1.0.1"
lazy_static = "1.3.0"
failure = "0.1.5" failure = "0.1.5"
ena = "0.11.0" ena = "0.11.0"
stopwatch = "0.0.7" stopwatch = "0.0.7"

View File

@ -6,6 +6,10 @@
//! It defines the `Schala` type, which contains the state for a Schala REPL, and implements //! It defines the `Schala` type, which contains the state for a Schala REPL, and implements
//! `ProgrammingLanguageInterface` and the chain of compiler passes for it. //! `ProgrammingLanguageInterface` and the chain of compiler passes for it.
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate maplit;
extern crate schala_repl; extern crate schala_repl;
#[macro_use] #[macro_use]
extern crate schala_lang_codegen; extern crate schala_lang_codegen;

View File

@ -2,6 +2,7 @@ use stopwatch::Stopwatch;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::collections::HashSet;
use schala_repl::{ProgrammingLanguageInterface, use schala_repl::{ProgrammingLanguageInterface,
ComputationRequest, ComputationResponse, ComputationRequest, ComputationResponse,
@ -57,13 +58,15 @@ impl Schala {
/// Schala code in the file `prelude.schala` /// Schala code in the file `prelude.schala`
pub fn new() -> Schala { pub fn new() -> Schala {
let prelude = include_str!("prelude.schala"); let prelude = include_str!("prelude.schala");
let mut env = Schala::new_blank_env(); let mut s = Schala::new_blank_env();
let response = env.run_pipeline(prelude); //TODO this shouldn't depend on schala-repl types
if let Err(msg) = response { let request = ComputationRequest { source: prelude, debug_requests: HashSet::default() };
let response = s.run_computation(request);
if let Err(msg) = response.main_output {
panic!("Error in prelude, panicking: {}", msg); panic!("Error in prelude, panicking: {}", msg);
} }
env s
} }
/// This is where the actual action of interpreting/compilation happens. /// This is where the actual action of interpreting/compilation happens.
@ -171,7 +174,7 @@ fn stage_names() -> Vec<&'static str> {
impl ProgrammingLanguageInterface for Schala { impl ProgrammingLanguageInterface for Schala {
type Config = (); type Options = ();
fn language_name() -> String { fn language_name() -> String {
"Schala".to_owned() "Schala".to_owned()
} }
@ -180,8 +183,8 @@ impl ProgrammingLanguageInterface for Schala {
"schala".to_owned() "schala".to_owned()
} }
fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse { fn run_computation(&mut self, request: ComputationRequest) -> ComputationResponse {
let ComputationRequest { source, debug_requests: _, config: _ } = request; let ComputationRequest { source, debug_requests: _ } = request;
self.source_reference.load_new_source(source); self.source_reference.load_new_source(source);
let sw = Stopwatch::start_new(); let sw = Stopwatch::start_new();

View File

@ -1,5 +1,8 @@
use itertools::Itertools; use itertools::Itertools;
use std::{iter::{Iterator, Peekable}, convert::TryFrom, rc::Rc, fmt}; use std::collections::HashMap;
use std::rc::Rc;
use std::iter::{Iterator, Peekable};
use std::fmt;
use crate::source_map::Location; use crate::source_map::Location;
@ -60,11 +63,9 @@ pub enum Kw {
Module, Import Module, Import
} }
impl TryFrom<&str> for Kw { lazy_static! {
type Error = (); static ref KEYWORDS: HashMap<&'static str, Kw> =
hashmap! {
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(match value {
"if" => Kw::If, "if" => Kw::If,
"then" => Kw::Then, "then" => Kw::Then,
"else" => Kw::Else, "else" => Kw::Else,
@ -87,9 +88,7 @@ impl TryFrom<&str> for Kw {
"false" => Kw::False, "false" => Kw::False,
"module" => Kw::Module, "module" => Kw::Module,
"import" => Kw::Import, "import" => Kw::Import,
_ => return Err(()), };
})
}
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -240,9 +239,9 @@ fn handle_alphabetic(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>
} }
} }
match Kw::try_from(buf.as_str()) { match KEYWORDS.get(buf.as_str()) {
Ok(kw) => TokenKind::Keyword(kw), Some(kw) => TokenKind::Keyword(*kw),
Err(()) => TokenKind::Identifier(Rc::new(buf)), None => TokenKind::Identifier(Rc::new(buf)),
} }
} }

View File

@ -11,8 +11,10 @@ pub enum DirectiveAction {
Help, Help,
QuitProgram, QuitProgram,
ListPasses, ListPasses,
TotalTime(bool), TotalTimeOff,
StageTime(bool), TotalTimeOn,
StageTimeOff,
StageTimeOn,
Doc, Doc,
} }
@ -48,12 +50,20 @@ impl DirectiveAction {
} }
Some(buf) Some(buf)
} }
TotalTime(value) => { TotalTimeOff => {
repl.options.show_total_time = *value; repl.options.show_total_time = false;
None None
} }
StageTime(value) => { TotalTimeOn => {
repl.options.show_stage_times = *value; repl.options.show_total_time = true;
None
}
StageTimeOff => {
repl.options.show_stage_times = false;
None
}
StageTimeOn => {
repl.options.show_stage_times = true;
None None
} }
Doc => doc(repl, arguments), Doc => doc(repl, arguments),

View File

@ -54,16 +54,16 @@ fn get_list(passes_directives: &[CommandTree], include_help: bool) -> Vec<Comman
"total-time", "total-time",
None, None,
vec![ vec![
CommandTree::terminal("on", None, vec![], TotalTime(true)), CommandTree::terminal("on", None, vec![], TotalTimeOn),
CommandTree::terminal("off", None, vec![], TotalTime(false)), CommandTree::terminal("off", None, vec![], TotalTimeOff),
], ],
), ),
CommandTree::nonterm( CommandTree::nonterm(
"stage-times", "stage-times",
Some("Computation time per-stage"), Some("Computation time per-stage"),
vec![ vec![
CommandTree::terminal("on", None, vec![], StageTime(true)), CommandTree::terminal("on", None, vec![], StageTimeOn),
CommandTree::terminal("off", None, vec![], StageTime(false)), CommandTree::terminal("off", None, vec![], StageTimeOff),
], ],
), ),
], ],

View File

@ -2,11 +2,11 @@ use std::collections::HashSet;
use std::time; use std::time;
pub trait ProgrammingLanguageInterface { pub trait ProgrammingLanguageInterface {
type Config: Default; type Options;
fn language_name() -> String; fn language_name() -> String;
fn source_file_suffix() -> String; fn source_file_suffix() -> String;
fn run_computation(&mut self, _request: ComputationRequest<Self::Config>) -> ComputationResponse; fn run_computation(&mut self, _request: ComputationRequest) -> ComputationResponse;
fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse { fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse {
LangMetaResponse::Custom { LangMetaResponse::Custom {
@ -23,9 +23,9 @@ struct Options<T> {
} }
*/ */
pub struct ComputationRequest<'a, T> { pub struct ComputationRequest<'a> {
pub source: &'a str, pub source: &'a str,
pub config: T, //pub options: Options<()>,
pub debug_requests: HashSet<DebugAsk>, pub debug_requests: HashSet<DebugAsk>,
} }

View File

@ -187,7 +187,6 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
let request = ComputationRequest { let request = ComputationRequest {
source: input, source: input,
config: Default::default(),
debug_requests, debug_requests,
}; };
let response = self.language_state.run_computation(request); let response = self.language_state.run_computation(request);

View File

@ -52,7 +52,6 @@ pub fn run_noninteractive<L: ProgrammingLanguageInterface>(filenames: Vec<PathBu
let request = ComputationRequest { let request = ComputationRequest {
source: &buffer, source: &buffer,
config: Default::default(),
debug_requests: HashSet::new(), debug_requests: HashSet::new(),
}; };