From 801896bcc62e1ada61ca215a3da9c3cf62fdc9b4 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 23 Jul 2017 02:12:05 -0700 Subject: [PATCH] Starting to add code for vm --- src/main.rs | 24 +++++++++++++++++++++++- src/virtual_machine/mod.rs | 9 +++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/virtual_machine/mod.rs diff --git a/src/main.rs b/src/main.rs index a701231..43dba4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,9 @@ use language::{ProgrammingLanguage, LanguageInterface, LLVMCodeString, Evaluatio mod llvm_wrap; +mod virtual_machine; +use virtual_machine::{run_vm, run_assembler}; + fn main() { let languages: Vec> = vec![ @@ -44,7 +47,19 @@ fn main() { if option_matches.opt_present("h") { println!("{}", program_options().usage("Schala metainterpreter")); - std::process::exit(1); + std::process::exit(0); + } + + if option_matches.opt_present("m") { + let file_name = option_matches.free.get(1); + run_vm(file_name); + std::process::exit(0); + } + + if option_matches.opt_present("a") { + let file_name = option_matches.free.get(1); + run_assembler(file_name); + std::process::exit(0); } let language_names: Vec = languages.iter().map(|lang| {lang.get_language_name()}).collect(); @@ -91,9 +106,16 @@ fn program_options() -> getopts::Options { options.optflag("h", "help", "Show help text"); + options.optflag("m", + "virtual-machine", + "Start up a virtual machine instead of an interpreter"); + options.optflag("a", + "assembler", + "Assemble file into bytecode"); options } + fn run_noninteractive<'a, T: ProgrammingLanguage>(filename: &str, _language: &T, trace_evaluation: bool, compile: bool) { let mut source_file = File::open(&Path::new(filename)).unwrap(); let mut buffer = String::new(); diff --git a/src/virtual_machine/mod.rs b/src/virtual_machine/mod.rs new file mode 100644 index 0000000..a200750 --- /dev/null +++ b/src/virtual_machine/mod.rs @@ -0,0 +1,9 @@ +pub fn run_vm(file_name: Option<&String>) { + println!("Running in VM mode"); + println!("yy: {:?}", file_name); +} + +pub fn run_assembler(file_name: Option<&String>) { + println!("Assembling file"); + println!("yy: {:?}", file_name); +}