More misc changes including edition 2018

This commit is contained in:
greg 2019-03-12 02:39:25 -07:00
parent 981d4f88bf
commit 8d8d7d8bf8
5 changed files with 44 additions and 15 deletions

View File

@ -2,6 +2,7 @@
name = "schala-repl" name = "schala-repl"
version = "0.1.0" version = "0.1.0"
authors = ["greg <greg.shuflin@protonmail.com>"] authors = ["greg <greg.shuflin@protonmail.com>"]
edition = "2018"
[dependencies] [dependencies]
llvm-sys = "70.0.2" llvm-sys = "70.0.2"

View File

@ -25,14 +25,37 @@ mod repl;
mod language; mod language;
mod webapp; 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<Box<dyn ProgrammingLanguageInterface>>) {
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(); let mut repl = repl::NewRepl::new();
repl.run_repl(); 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, pub use language::{ProgrammingLanguageInterface, EvalOptions,
ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugOptionsDescriptor, PassDescriptor}; ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugOptionsDescriptor, PassDescriptor};

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use colored::*; use colored::*;
use itertools::Itertools; use itertools::Itertools;
use language::{ProgrammingLanguageInterface, EvalOptions, use crate::language::{ProgrammingLanguageInterface, EvalOptions,
PassDebugOptionsDescriptor}; PassDebugOptionsDescriptor};
mod command_tree; mod command_tree;
use self::command_tree::CommandTree; use self::command_tree::CommandTree;
@ -30,13 +30,16 @@ impl NewRepl {
} }
pub fn run_repl(&mut self) { 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); 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.handle_repl_loop();
self.line_reader.save_history(HISTORY_SAVE_FILE).unwrap_or(()); self.line_reader.save_history(HISTORY_SAVE_FILE).unwrap_or(());
self.save_options(); self.save_options();
println!("Exiting..."); println!("Exiting...");
} }
@ -50,8 +53,7 @@ impl NewRepl {
println!("readline IO Error: {}", e); println!("readline IO Error: {}", e);
break; break;
}, },
Ok(Eof) => break, Ok(Eof) | Ok(Signal(_)) => break,
Ok(Signal(_)) => break,
Ok(Input(ref input)) => { Ok(Input(ref input)) => {
self.line_reader.add_history_unique(input.to_string()); self.line_reader.add_history_unique(input.to_string());
let output = match input.chars().nth(0) { let output = match input.chars().nth(0) {
@ -158,7 +160,7 @@ impl Repl {
pub fn run(&mut self) { pub fn run(&mut self) {
use linefeed::ReadResult; 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); println!("Type {}help for help with the REPL", self.interpreter_directive_sigil);
self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(()); self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(());

View File

@ -3,9 +3,9 @@ use rocket::State;
use rocket::response::Content; use rocket::response::Content;
use rocket::http::ContentType; use rocket::http::ContentType;
use rocket_contrib::json::Json; use rocket_contrib::json::Json;
use language::{ProgrammingLanguageInterface, EvalOptions}; use crate::language::{ProgrammingLanguageInterface, EvalOptions};
use WEBFILES; use crate::WEBFILES;
use ::PLIGenerator; use crate::PLIGenerator;
#[get("/")] #[get("/")]
fn index() -> Content<String> { fn index() -> Content<String> {

View File

@ -4,18 +4,21 @@ extern crate maaru_lang;
extern crate rukka_lang; extern crate rukka_lang;
extern crate robo_lang; extern crate robo_lang;
extern crate schala_lang; extern crate schala_lang;
use schala_repl::{PLIGenerator, repl_main, start_repl}; use schala_repl::{PLIGenerator, ProgrammingLanguageInterface, repl_main, start_repl};
extern { } extern { }
fn main() { fn main() {
/*
let generators: Vec<PLIGenerator> = vec![ let generators: Vec<PLIGenerator> = vec![
Box::new(|| { Box::new(schala_lang::Schala::new())}), Box::new(|| { Box::new(schala_lang::Schala::new())}),
Box::new(|| { Box::new(maaru_lang::Maaru::new())}), Box::new(|| { Box::new(maaru_lang::Maaru::new())}),
Box::new(|| { Box::new(robo_lang::Robo::new())}), Box::new(|| { Box::new(robo_lang::Robo::new())}),
Box::new(|| { Box::new(rukka_lang::Rukka::new())}), Box::new(|| { Box::new(rukka_lang::Rukka::new())}),
]; ];
//repl_main(generators); repl_main(generators);
start_repl(); */
let langs: Vec<Box<ProgrammingLanguageInterface>> = vec![Box::new(schala_lang::Schala::new())];
start_repl(langs);
} }