Changeset - e3cd0bb27952
[Not reviewed]
0 4 0
mh - 3 years ago 2022-04-13 14:01:14
contact@maxhenger.nl
Add stdlib dir option to bin-compiler args
4 files changed with 39 insertions and 12 deletions:
0 comments (0 inline, 0 general)
bin-compiler/src/main.rs
Show inline comments
 
@@ -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 {
src/protocol/mod.rs
Show inline comments
 
@@ -52,7 +52,7 @@ pub enum ComponentCreationError {
 
impl ProtocolDescription {
 
    pub fn parse(buffer: &[u8]) -> Result<Self, String> {
 
        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<Self, String> {
 
        return Ok(Self{
 
            parser: Parser::new()?,
 
        })
 
    pub fn new(std_lib_dir: Option<String>) -> Result<Self, String> {
 
        let mut parser = Parser::new(std_lib_dir)?;
 
        return Ok(Self{ parser })
 
    }
 

	
 
    pub fn add(&mut self, filename: String, buffer: Vec<u8>) -> Result<(), ParseError> {
src/protocol/parser/mod.rs
Show inline comments
 
@@ -136,11 +136,12 @@ pub struct Parser {
 
    // Compiler options
 
    pub write_tokens_to: Option<String>,
 
    pub write_ast_to: Option<String>,
 
    pub std_lib_dir: Option<String>,
 
    pub(crate) arch: TargetArch,
 
}
 

	
 
impl Parser {
 
    pub fn new() -> Result<Self, String> {
 
    pub fn new(std_lib_dir: Option<String>) -> Result<Self, String> {
 
        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)
 
        };
 

	
src/protocol/tests/utils.rs
Show inline comments
 
@@ -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();
0 comments (0 inline, 0 general)