diff --git a/schala-repl/Cargo.toml b/schala-repl/Cargo.toml index 999510a..9dfc308 100644 --- a/schala-repl/Cargo.toml +++ b/schala-repl/Cargo.toml @@ -2,6 +2,7 @@ name = "schala-repl" version = "0.1.0" authors = ["greg "] +edition = "2018" [dependencies] llvm-sys = "70.0.2" diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index c6aa30f..37c5e94 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -25,14 +25,37 @@ mod repl; mod language; mod webapp; -pub fn start_repl() { +include!(concat!(env!("OUT_DIR"), "/static.rs")); +const VERSION_STRING: &'static str = "0.1.0"; + +pub fn start_repl(langs: Vec>) { + let command_line_options = command_line_options().parse(std::env::args()).unwrap_or_else(|e| { + println!("{:?}", e); + exit(1); + }); + + if command_line_options.opt_present("help") { + println!("{}", program_options().usage("Schala metainterpreter")); + exit(0); + } + let mut repl = repl::NewRepl::new(); + repl.run_repl(); } -const VERSION_STRING: &'static str = "0.1.0"; +fn command_line_options() -> getopts::Options { + let mut options = getopts::Options::new(); + options.optflag("h", + "help", + "Show help text"); + options.optflag("w", + "webapp", + "Start up web interpreter"); + options +} -include!(concat!(env!("OUT_DIR"), "/static.rs")); +/* --------------------------- */ pub use language::{ProgrammingLanguageInterface, EvalOptions, ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugOptionsDescriptor, PassDescriptor}; diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 7f9d0ad..0647765 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use colored::*; use itertools::Itertools; -use language::{ProgrammingLanguageInterface, EvalOptions, +use crate::language::{ProgrammingLanguageInterface, EvalOptions, PassDebugOptionsDescriptor}; mod command_tree; use self::command_tree::CommandTree; @@ -30,13 +30,16 @@ impl NewRepl { } pub fn run_repl(&mut self) { - println!("Schala MetaInterpreter version {}", ::VERSION_STRING); + self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(()); + + println!("Schala MetaInterpreter version {}", crate::VERSION_STRING); println!("Type {}help for help with the REPL", self.interpreter_directive_sigil); - self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(()); self.handle_repl_loop(); + self.line_reader.save_history(HISTORY_SAVE_FILE).unwrap_or(()); self.save_options(); + println!("Exiting..."); } @@ -50,8 +53,7 @@ impl NewRepl { println!("readline IO Error: {}", e); break; }, - Ok(Eof) => break, - Ok(Signal(_)) => break, + Ok(Eof) | Ok(Signal(_)) => break, Ok(Input(ref input)) => { self.line_reader.add_history_unique(input.to_string()); let output = match input.chars().nth(0) { @@ -158,7 +160,7 @@ impl Repl { pub fn run(&mut self) { use linefeed::ReadResult; - println!("Schala MetaInterpreter version {}", ::VERSION_STRING); + println!("Schala MetaInterpreter version {}", crate::VERSION_STRING); println!("Type {}help for help with the REPL", self.interpreter_directive_sigil); self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(()); diff --git a/schala-repl/src/webapp.rs b/schala-repl/src/webapp.rs index 6947019..a1b7869 100644 --- a/schala-repl/src/webapp.rs +++ b/schala-repl/src/webapp.rs @@ -3,9 +3,9 @@ use rocket::State; use rocket::response::Content; use rocket::http::ContentType; use rocket_contrib::json::Json; -use language::{ProgrammingLanguageInterface, EvalOptions}; -use WEBFILES; -use ::PLIGenerator; +use crate::language::{ProgrammingLanguageInterface, EvalOptions}; +use crate::WEBFILES; +use crate::PLIGenerator; #[get("/")] fn index() -> Content { diff --git a/src/main.rs b/src/main.rs index 0448f3f..dbefccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,18 +4,21 @@ extern crate maaru_lang; extern crate rukka_lang; extern crate robo_lang; extern crate schala_lang; -use schala_repl::{PLIGenerator, repl_main, start_repl}; +use schala_repl::{PLIGenerator, ProgrammingLanguageInterface, repl_main, start_repl}; extern { } fn main() { + /* let generators: Vec = vec![ Box::new(|| { Box::new(schala_lang::Schala::new())}), Box::new(|| { Box::new(maaru_lang::Maaru::new())}), Box::new(|| { Box::new(robo_lang::Robo::new())}), Box::new(|| { Box::new(rukka_lang::Rukka::new())}), ]; - //repl_main(generators); - start_repl(); + repl_main(generators); + */ + let langs: Vec> = vec![Box::new(schala_lang::Schala::new())]; + start_repl(langs); }