diff --git a/bin-compiler/src/main.rs b/bin-compiler/src/main.rs index 9ab3e1d1bce01f4594b1f0452e1c7c71935b75c2..1482ae752710211bac6dcaab87745d6bbad57d16 100644 --- a/bin-compiler/src/main.rs +++ b/bin-compiler/src/main.rs @@ -31,6 +31,13 @@ fn main() { .long("debug") .short('d') .help("enable debug logging") + ) + .arg( + Arg::new("stdlib") + .long("stdlib") + .short('s') + .help("standard library directory (overrides default)") + .takes_value(true) ); // Retrieve arguments and convert @@ -59,11 +66,15 @@ fn main() { let debug_enabled = app.is_present("debug"); + let standard_library_dir = app.value_of("stdlib") + .map(|v| v.to_string()); + // Add input files to file buffer let input_files = input_files.unwrap(); assert!(input_files.len() > 0); // because arg is required - let mut builder = rw::ProtocolDescriptionBuilder::new().expect("create protocol description builder"); + let mut builder = rw::ProtocolDescriptionBuilder::new(standard_library_dir) + .expect("create protocol description builder"); let mut file_buffer = Vec::with_capacity(4096); for input_file in input_files { @@ -101,9 +112,17 @@ fn main() { println!("Success"); + // Start runtime + print!("Startup of runtime ... "); + let runtime = rw::runtime2::Runtime::new(num_threads, debug_enabled, protocol_description); + if let Err(err) = &runtime { + println!("FAILED\nbecause:\n{}", err); + } + println!("Success"); + // Make sure there is a nameless module with a main component print!("Creating main component ... "); - let runtime = rw::runtime2::Runtime::new(num_threads, debug_enabled, protocol_description); + let runtime = runtime.unwrap(); if let Err(err) = runtime.create_component(b"", b"main") { use rw::ComponentCreationError as CCE; let reason = match err { diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 993e4e64f949e0ff8efe028d9ccc4231b21c7d8d..d0dd2453c06c9f49d1cce7f935c3c0f092dba0ce 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -52,7 +52,7 @@ pub enum ComponentCreationError { impl ProtocolDescription { pub fn parse(buffer: &[u8]) -> Result { let source = InputSource::new(String::new(), Vec::from(buffer)); - let mut parser = Parser::new()?; + let mut parser = Parser::new(None)?; parser.feed(source).expect("failed to feed source"); if let Err(err) = parser.parse() { @@ -253,10 +253,9 @@ pub struct ProtocolDescriptionBuilder { } impl ProtocolDescriptionBuilder { - pub fn new() -> Result { - return Ok(Self{ - parser: Parser::new()?, - }) + pub fn new(std_lib_dir: Option) -> Result { + let mut parser = Parser::new(std_lib_dir)?; + return Ok(Self{ parser }) } pub fn add(&mut self, filename: String, buffer: Vec) -> Result<(), ParseError> { diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index 1d2eee5bc1b2683818d37d490b6d745636b034f2..8f1500639951df5c37527325b710f7e2f3e88097 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -136,11 +136,12 @@ pub struct Parser { // Compiler options pub write_tokens_to: Option, pub write_ast_to: Option, + pub std_lib_dir: Option, pub(crate) arch: TargetArch, } impl Parser { - pub fn new() -> Result { + pub fn new(std_lib_dir: Option) -> Result { let mut parser = Parser{ heap: Heap::new(), string_pool: StringPool::new(), @@ -158,6 +159,7 @@ impl Parser { pass_stack_size: PassStackSize::new(), write_tokens_to: None, write_ast_to: None, + std_lib_dir, arch: TargetArch::new(), }; @@ -309,9 +311,16 @@ impl Parser { // Path variable is set (path, true) } else { - let mut path = String::with_capacity(REOWOLF_PATH_DIR.len() + 2); - path.push_str("./"); - path.push_str(REOWOLF_PATH_DIR); + let path = match self.std_lib_dir.take() { + Some(path) => path, + None => { + let mut path = String::with_capacity(REOWOLF_PATH_DIR.len() + 2); + path.push_str("./"); + path.push_str(REOWOLF_PATH_DIR); + path + } + }; + (path, false) }; diff --git a/src/protocol/tests/utils.rs b/src/protocol/tests/utils.rs index 0fc4005a2dc6edf5c69523ee351d28dace6724a1..8ee104fec54e1c6076614eabee40a92c987b1f5d 100644 --- a/src/protocol/tests/utils.rs +++ b/src/protocol/tests/utils.rs @@ -59,7 +59,7 @@ impl Tester { } pub(crate) fn compile(self) -> AstTesterResult { - let mut parser = Parser::new().unwrap(); + let mut parser = Parser::new(None).unwrap(); for source in self.sources.into_iter() { let source = source.into_bytes();