This commit is contained in:
2020-05-16 00:30:09 +08:00
parent b527f30870
commit 2d346a5312

View File

@@ -5,16 +5,14 @@ mod compiler;
mod context; mod context;
mod vm; mod vm;
use std::{ use std::{ env, fs::read_to_string, };
env,
fs::read_to_string,
};
use err::*; use err::*;
use parser::*; use parser::*;
use compiler::*; use compiler::*;
use context::*; use context::*;
use vm::*; use vm::*;
const VERSION: &str = env!("CARGO_PKG_VERSION");
// https://playsecurity.org/rawfile/grass_mud_horse_language_specification.md // https://playsecurity.org/rawfile/grass_mud_horse_language_specification.md
// https://p.rogram.me/grassmudhorse.js/grassmudhorse.js // https://p.rogram.me/grassmudhorse.js/grassmudhorse.js
@@ -24,8 +22,16 @@ fn main() {
let is_compile = env::args().any(|a| a == "-c" || a == "--compile"); let is_compile = env::args().any(|a| a == "-c" || a == "--compile");
let arg_file = env::args().filter(|a| !a.starts_with("-")).nth(1); let arg_file = env::args().filter(|a| !a.starts_with("-")).nth(1);
if is_debug {
println!("[DEBUG] Run in debug mode");
}
if is_help { if is_help {
println!("grassmudhorse.rs v0.1"); println!("GrassMudHorse in Rust v{}\n", VERSION);
println!("grassmudhorse [OPTIONS] file_name");
println!(" -h, --help print this message");
println!(" -d, --debug run in debug mode");
println!(" -c, --compile compile grassmudhorse source code");
return; return;
} }
@@ -51,14 +57,14 @@ fn main() {
if is_compile { if is_compile {
match compile_lang(&input) { match compile_lang(&input) {
Ok(compiled) => println!("{}", compiled), Ok(compiled) => println!("{}", compiled),
Err(err) => println!("Compile error: {}", err), Err(err) => println!("[ERROR] Compile error: {}", err),
} }
return; return;
} }
let instructions = match parse_lang(&input) { let instructions = match parse_lang(&input) {
Ok(i) => i, Err(err) => { Ok(i) => i, Err(err) => {
println!("Parse error: {}", err); println!("[ERROR] Parse error: {}", err);
return; return;
}, },
}; };
@@ -77,7 +83,7 @@ fn main() {
match vm.execute(&mut context) { match vm.execute(&mut context) {
Err(RuntimeError::EndVm) => (), Err(RuntimeError::EndVm) => (),
Err(err) => println!("Vm error: {}", err), Err(err) => println!("[ERROR] Vm error: {}", err),
Ok(_) => (), Ok(_) => (),
} }