Compare commits
No commits in common. "421a33c42c74f72b7d7834b090972d066de24f7d" and "6ac0628265ce8d614f7cd87e541c0a030d05639b" have entirely different histories.
421a33c42c
...
6ac0628265
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -836,6 +836,8 @@ dependencies = [
|
||||
"ena",
|
||||
"failure",
|
||||
"itertools",
|
||||
"lazy_static 1.4.0",
|
||||
"maplit",
|
||||
"radix_trie",
|
||||
"schala-lang-codegen",
|
||||
"schala-repl",
|
||||
|
@ -8,6 +8,8 @@ resolver = "2"
|
||||
[dependencies]
|
||||
itertools = "0.10"
|
||||
take_mut = "0.2.2"
|
||||
maplit = "1.0.1"
|
||||
lazy_static = "1.3.0"
|
||||
failure = "0.1.5"
|
||||
ena = "0.11.0"
|
||||
stopwatch = "0.0.7"
|
||||
|
@ -6,6 +6,10 @@
|
||||
//! It defines the `Schala` type, which contains the state for a Schala REPL, and implements
|
||||
//! `ProgrammingLanguageInterface` and the chain of compiler passes for it.
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
extern crate schala_repl;
|
||||
#[macro_use]
|
||||
extern crate schala_lang_codegen;
|
||||
|
@ -2,6 +2,7 @@ use stopwatch::Stopwatch;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use schala_repl::{ProgrammingLanguageInterface,
|
||||
ComputationRequest, ComputationResponse,
|
||||
@ -57,13 +58,15 @@ impl Schala {
|
||||
/// Schala code in the file `prelude.schala`
|
||||
pub fn new() -> 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);
|
||||
if let Err(msg) = response {
|
||||
//TODO this shouldn't depend on schala-repl types
|
||||
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);
|
||||
}
|
||||
env
|
||||
s
|
||||
}
|
||||
|
||||
/// This is where the actual action of interpreting/compilation happens.
|
||||
@ -171,7 +174,7 @@ fn stage_names() -> Vec<&'static str> {
|
||||
|
||||
|
||||
impl ProgrammingLanguageInterface for Schala {
|
||||
type Config = ();
|
||||
type Options = ();
|
||||
fn language_name() -> String {
|
||||
"Schala".to_owned()
|
||||
}
|
||||
@ -180,8 +183,8 @@ impl ProgrammingLanguageInterface for Schala {
|
||||
"schala".to_owned()
|
||||
}
|
||||
|
||||
fn run_computation(&mut self, request: ComputationRequest<Self::Config>) -> ComputationResponse {
|
||||
let ComputationRequest { source, debug_requests: _, config: _ } = request;
|
||||
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();
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
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;
|
||||
|
||||
@ -60,11 +63,9 @@ pub enum Kw {
|
||||
Module, Import
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Kw {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
Ok(match value {
|
||||
lazy_static! {
|
||||
static ref KEYWORDS: HashMap<&'static str, Kw> =
|
||||
hashmap! {
|
||||
"if" => Kw::If,
|
||||
"then" => Kw::Then,
|
||||
"else" => Kw::Else,
|
||||
@ -87,9 +88,7 @@ impl TryFrom<&str> for Kw {
|
||||
"false" => Kw::False,
|
||||
"module" => Kw::Module,
|
||||
"import" => Kw::Import,
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[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()) {
|
||||
Ok(kw) => TokenKind::Keyword(kw),
|
||||
Err(()) => TokenKind::Identifier(Rc::new(buf)),
|
||||
match KEYWORDS.get(buf.as_str()) {
|
||||
Some(kw) => TokenKind::Keyword(*kw),
|
||||
None => TokenKind::Identifier(Rc::new(buf)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,10 @@ pub enum DirectiveAction {
|
||||
Help,
|
||||
QuitProgram,
|
||||
ListPasses,
|
||||
TotalTime(bool),
|
||||
StageTime(bool),
|
||||
TotalTimeOff,
|
||||
TotalTimeOn,
|
||||
StageTimeOff,
|
||||
StageTimeOn,
|
||||
Doc,
|
||||
}
|
||||
|
||||
@ -48,12 +50,20 @@ impl DirectiveAction {
|
||||
}
|
||||
Some(buf)
|
||||
}
|
||||
TotalTime(value) => {
|
||||
repl.options.show_total_time = *value;
|
||||
TotalTimeOff => {
|
||||
repl.options.show_total_time = false;
|
||||
None
|
||||
}
|
||||
StageTime(value) => {
|
||||
repl.options.show_stage_times = *value;
|
||||
TotalTimeOn => {
|
||||
repl.options.show_total_time = true;
|
||||
None
|
||||
}
|
||||
StageTimeOff => {
|
||||
repl.options.show_stage_times = false;
|
||||
None
|
||||
}
|
||||
StageTimeOn => {
|
||||
repl.options.show_stage_times = true;
|
||||
None
|
||||
}
|
||||
Doc => doc(repl, arguments),
|
||||
|
@ -54,16 +54,16 @@ fn get_list(passes_directives: &[CommandTree], include_help: bool) -> Vec<Comman
|
||||
"total-time",
|
||||
None,
|
||||
vec![
|
||||
CommandTree::terminal("on", None, vec![], TotalTime(true)),
|
||||
CommandTree::terminal("off", None, vec![], TotalTime(false)),
|
||||
CommandTree::terminal("on", None, vec![], TotalTimeOn),
|
||||
CommandTree::terminal("off", None, vec![], TotalTimeOff),
|
||||
],
|
||||
),
|
||||
CommandTree::nonterm(
|
||||
"stage-times",
|
||||
Some("Computation time per-stage"),
|
||||
vec![
|
||||
CommandTree::terminal("on", None, vec![], StageTime(true)),
|
||||
CommandTree::terminal("off", None, vec![], StageTime(false)),
|
||||
CommandTree::terminal("on", None, vec![], StageTimeOn),
|
||||
CommandTree::terminal("off", None, vec![], StageTimeOff),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -2,11 +2,11 @@ use std::collections::HashSet;
|
||||
use std::time;
|
||||
|
||||
pub trait ProgrammingLanguageInterface {
|
||||
type Config: Default;
|
||||
type Options;
|
||||
fn language_name() -> 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 {
|
||||
LangMetaResponse::Custom {
|
||||
@ -23,9 +23,9 @@ struct Options<T> {
|
||||
}
|
||||
*/
|
||||
|
||||
pub struct ComputationRequest<'a, T> {
|
||||
pub struct ComputationRequest<'a> {
|
||||
pub source: &'a str,
|
||||
pub config: T,
|
||||
//pub options: Options<()>,
|
||||
pub debug_requests: HashSet<DebugAsk>,
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,6 @@ impl<L: ProgrammingLanguageInterface> Repl<L> {
|
||||
|
||||
let request = ComputationRequest {
|
||||
source: input,
|
||||
config: Default::default(),
|
||||
debug_requests,
|
||||
};
|
||||
let response = self.language_state.run_computation(request);
|
||||
|
@ -52,7 +52,6 @@ pub fn run_noninteractive<L: ProgrammingLanguageInterface>(filenames: Vec<PathBu
|
||||
|
||||
let request = ComputationRequest {
|
||||
source: &buffer,
|
||||
config: Default::default(),
|
||||
debug_requests: HashSet::new(),
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user