Changeset - f3ec8304a2a4
[Not reviewed]
! ! !
mh - 3 years ago 2022-02-08 15:03:20
contact@maxhenger.nl
Finish initial compiler binary, remove old testdata, add new testdata
114 files changed with 60 insertions and 1592 deletions:
0 comments (0 inline, 0 general)
bin-compiler/src/main.rs
Show inline comments
 
@@ -17,97 +17,98 @@ fn main() {
 
                .required(true)
 
                .takes_value(true)
 
                .multiple_occurrences(true)
 
        )
 
        .arg(
 
            Arg::new("threads")
 
                .long("threads")
 
                .short('t')
 
                .help("number of runtime threads")
 
                .default_value("1")
 
                .takes_value(true)
 
        );
 

	
 
    // Retrieve arguments and convert
 
    let app = app.get_matches();
 
    let input_files = app.values_of("input");
 
    if input_files.is_none() {
 
        println!("ERROR: Expected at least one input file");
 
        return;
 
    }
 

	
 
    let num_threads = app.value_of("threads").unwrap();
 
    let num_threads = match num_threads.parse::<i32>() {
 
        Ok(num_threads) => {
 
            if num_threads < 0 || num_threads > 255 {
 
                println!("ERROR: Number of threads must be a number between 0 and 256");
 
                return;
 
            }
 

	
 
            num_threads as u32
 
        },
 
        Err(err) => {
 
            println!("ERROR: Failed to parse number of threads\nbecause: {}", err);
 
            return;
 
        }
 
    };
 

	
 
    // 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();
 
    let mut file_buffer = Vec::with_capacity(4096);
 

	
 
    for input_file in input_files {
 
        print!("Adding file: {} ... ", input_file);
 
        let mut file = match File::open(input_file) {
 
            Ok(file) => file,
 
            Err(err) => {
 
                println!("FAILED (to open file)\nbecause:\n{}", err);
 
                return;
 
            }
 
        };
 

	
 
        file_buffer.clear();
 
        if let Err(err) = file.read_to_end(&mut file_buffer) {
 
            println!("FAILED (to read file)\nbecause:\n{}", err);
 
            return;
 
        }
 

	
 
        if let Err(err) = builder.add(input_file.to_string(), file_buffer.clone()) {
 
            println!("FAILED (to tokenize file)\nbecause:\n{}", err);
 
        }
 

	
 
        println!("Success");
 
    }
 

	
 
    // Compile the program
 
    print!("Compiling program ... ");
 
    let protocol_description = match builder.compile() {
 
        Ok(pd) => pd,
 
        Err(err) => {
 
            println!("FAILED\nbecause:\n{}", err);
 
            return;
 
        }
 
    };
 

	
 
    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, protocol_description);
 
    if let Err(err) = runtime.create_component(b"", b"main") {
 
        use rw::ComponentCreationError as CCE;
 
        let reason = match err {
 
            CCE::ModuleDoesntExist => "Input files did not contain a nameless module (that should contain the 'main' component)",
 
            CCE::DefinitionDoesntExist => "Input files did not contain a component called 'main'",
 
            CCE::DefinitionNotComponent => "Input file contained a 'main' function, but not a 'main' component",
 
            _ => "Unexpected error"
 
        };
 
        println!("FAILED\nbecause:\n{} (raw error: {:?})", reason, err);
 
        return;
 
    }
 

	
 
    println!("Success");
 
    println!("Now running until all components have exited");
 
    println!("--------------------------------------------\n\n");
 
}
 
\ No newline at end of file
testdata/basic-modules/consumer.pdl
Show inline comments
 
new file 100644
 
#module consumer
 

	
 
primitive consumer(in<u32> input) {
 
    sync {
 
        print("C: going to receive a value");
 
        auto v = get(input);
 
        print("C: I have received a value");
 
    }
 
    print("C: I am now exiting");
 
}
 
\ No newline at end of file
testdata/basic-modules/main.pdl
Show inline comments
 
new file 100644
 
import consumer as c;
 
import producer::producer;
 

	
 
composite main() {
 
    channel output -> input;
 
    new c::consumer(input);
 
    new producer(output);
 
}
 
\ No newline at end of file
testdata/basic-modules/producer.pdl
Show inline comments
 
new file 100644
 
#module producer
 

	
 
primitive producer(out<u32> output) {
 
    print("P: Going to send a value");
 
    sync {
 
        print("P: Going to send a value!");
 
        put(output, 1337);
 
        print("P: I just sent a value!");
 
    }
 
    print("P: I am exiting");
 
}
 
\ No newline at end of file
testdata/basic-modules/readme.txt
Show inline comments
 
new file 100644
 
Run as:
 

	
 
./bin-compiler -i ./testdata/basic-modules/consumer.pdl -i ./testdata/basic-modules/producer.pdl -i ./testdata/basic-modules/main.pdl
 
\ No newline at end of file
testdata/basic/readme.txt
Show inline comments
 
new file 100644
 
Run as:
 

	
 
./bin-compiler -i ./testdata/basic-modules/testing.pdl
 
\ No newline at end of file
testdata/basic/testing.pdl
Show inline comments
 
new file 100644
 
primitive consumer(in<u32> input) {
 
    sync {
 
        print("C: going to receive a value");
 
        auto v = get(input);
 
        print("C: I have received a value");
 
    }
 
    print("C: I am now exiting");
 
}
 

	
 
primitive producer(out<u32> output) {
 
    print("P: Going to send a value");
 
    sync {
 
        print("P: Going to send a value!");
 
        put(output, 1337);
 
        print("P: I just sent a value!");
 
    }
 
    print("P: I am exiting");
 
}
 

	
 
composite main() {
 
    channel output -> input;
 
    new consumer(input);
 
    new producer(output);
 
}
 
\ No newline at end of file
testdata/eval/positive/1.pdl
Show inline comments
 
deleted file
testdata/eval/positive/1.txt
Show inline comments
 
deleted file
testdata/eval/positive/10.pdl
Show inline comments
 
deleted file
testdata/eval/positive/10.txt
Show inline comments
 
deleted file
testdata/eval/positive/11.pdl
Show inline comments
 
deleted file
testdata/eval/positive/11.txt
Show inline comments
 
deleted file
testdata/eval/positive/2.pdl
Show inline comments
 
deleted file
testdata/eval/positive/2.txt
Show inline comments
 
deleted file
testdata/eval/positive/3.pdl
Show inline comments
 
deleted file
testdata/eval/positive/3.txt
Show inline comments
 
deleted file
testdata/eval/positive/4.pdl
Show inline comments
 
deleted file
testdata/eval/positive/4.txt
Show inline comments
 
deleted file
testdata/eval/positive/5.pdl
Show inline comments
 
deleted file
testdata/eval/positive/5.txt
Show inline comments
 
deleted file
testdata/eval/positive/6.pdl
Show inline comments
 
deleted file
testdata/eval/positive/6.txt
Show inline comments
 
deleted file
testdata/eval/positive/7.pdl
Show inline comments
 
deleted file
testdata/eval/positive/7.txt
Show inline comments
 
deleted file
testdata/eval/positive/8.pdl
Show inline comments
 
deleted file
testdata/eval/positive/8.txt
Show inline comments
 
deleted file
testdata/eval/positive/9.pdl
Show inline comments
 
deleted file
testdata/eval/positive/9.txt
Show inline comments
 
deleted file
testdata/parser/counterexamples/arity_checking.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/declaration_after_function_call.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/definition_order.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/empty_file_reporting.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/function_type_checks.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/import_bad_reporting.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/import_stmt.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/integer_specification.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/multiple_versions.pdl
Show inline comments
 
deleted file
testdata/parser/counterexamples/out_of_order_assignment.pdl
Show inline comments
 
deleted file
testdata/parser/negative/1.pdl
Show inline comments
 
deleted file
testdata/parser/negative/1.txt
Show inline comments
 
deleted file
testdata/parser/negative/10.pdl
Show inline comments
 
deleted file
testdata/parser/negative/10.txt
Show inline comments
 
deleted file
testdata/parser/negative/12.pdl
Show inline comments
 
deleted file
testdata/parser/negative/12.txt
Show inline comments
 
deleted file
testdata/parser/negative/13.pdl
Show inline comments
 
deleted file
testdata/parser/negative/13.txt
Show inline comments
 
deleted file
testdata/parser/negative/14.pdl
Show inline comments
 
deleted file
testdata/parser/negative/14.txt
Show inline comments
 
deleted file
testdata/parser/negative/17.pdl
Show inline comments
 
deleted file
testdata/parser/negative/17.txt
Show inline comments
 
deleted file
testdata/parser/negative/18.pdl
Show inline comments
 
deleted file
testdata/parser/negative/18.txt
Show inline comments
 
deleted file
testdata/parser/negative/19.pdl
Show inline comments
 
deleted file
testdata/parser/negative/19.txt
Show inline comments
 
deleted file
testdata/parser/negative/2.pdl
Show inline comments
 
deleted file
testdata/parser/negative/2.txt
Show inline comments
 
deleted file
testdata/parser/negative/22.pdl
Show inline comments
 
deleted file
testdata/parser/negative/22.txt
Show inline comments
 
deleted file
testdata/parser/negative/23.pdl
Show inline comments
 
deleted file
testdata/parser/negative/23.txt
Show inline comments
 
deleted file
testdata/parser/negative/24.pdl
Show inline comments
 
deleted file
testdata/parser/negative/24.txt
Show inline comments
 
deleted file
testdata/parser/negative/25.pdl
Show inline comments
 
deleted file
testdata/parser/negative/25.txt
Show inline comments
 
deleted file
testdata/parser/negative/26.pdl
Show inline comments
 
deleted file
testdata/parser/negative/26.txt
Show inline comments
 
deleted file
testdata/parser/negative/27.pdl
Show inline comments
 
deleted file
testdata/parser/negative/27.txt
Show inline comments
 
deleted file
testdata/parser/negative/28.pdl
Show inline comments
 
deleted file
testdata/parser/negative/28.txt
Show inline comments
 
deleted file
testdata/parser/negative/29.pdl
Show inline comments
 
deleted file
testdata/parser/negative/29.txt
Show inline comments
 
deleted file
testdata/parser/negative/3.pdl
Show inline comments
 
deleted file
testdata/parser/negative/3.txt
Show inline comments
 
deleted file
testdata/parser/negative/30.pdl
Show inline comments
 
deleted file
testdata/parser/negative/30.txt
Show inline comments
 
deleted file
testdata/parser/negative/31.pdl
Show inline comments
 
deleted file
testdata/parser/negative/31.txt
Show inline comments
 
deleted file
testdata/parser/negative/32.pdl
Show inline comments
 
deleted file
testdata/parser/negative/32.txt
Show inline comments
 
deleted file
testdata/parser/negative/4.pdl
Show inline comments
 
deleted file
testdata/parser/negative/4.txt
Show inline comments
 
deleted file
testdata/parser/negative/5.pdl
Show inline comments
 
deleted file
testdata/parser/negative/5.txt
Show inline comments
 
deleted file
testdata/parser/negative/6.pdl
Show inline comments
 
deleted file
testdata/parser/negative/6.txt
Show inline comments
 
deleted file
testdata/parser/negative/7.pdl
Show inline comments
 
deleted file
testdata/parser/negative/7.txt
Show inline comments
 
deleted file
testdata/parser/negative/8.pdl
Show inline comments
 
deleted file
testdata/parser/negative/8.txt
Show inline comments
 
deleted file
testdata/parser/negative/9.pdl
Show inline comments
 
deleted file
testdata/parser/negative/9.txt
Show inline comments
 
deleted file
testdata/parser/positive/1.pdl
Show inline comments
 
deleted file
testdata/parser/positive/10.pdl
Show inline comments
 
deleted file
testdata/parser/positive/11.pdl
Show inline comments
 
deleted file
testdata/parser/positive/12.pdl
Show inline comments
 
deleted file
testdata/parser/positive/13.pdl
Show inline comments
 
deleted file
testdata/parser/positive/14.pdl
Show inline comments
 
deleted file
testdata/parser/positive/15.pdl
Show inline comments
 
deleted file
testdata/parser/positive/16.pdl
Show inline comments
 
deleted file
testdata/parser/positive/17.pdl
Show inline comments
 
deleted file
testdata/parser/positive/18.pdl
Show inline comments
 
deleted file
testdata/parser/positive/19.pdl
Show inline comments
 
deleted file
testdata/parser/positive/2.pdl
Show inline comments
 
deleted file
testdata/parser/positive/20.pdl
Show inline comments
 
deleted file
testdata/parser/positive/3.pdl
Show inline comments
 
deleted file
testdata/parser/positive/4.pdl
Show inline comments
 
deleted file
testdata/parser/positive/5.pdl
Show inline comments
 
deleted file
testdata/parser/positive/6.pdl
Show inline comments
 
deleted file
testdata/parser/positive/7.pdl
Show inline comments
 
deleted file
testdata/parser/positive/8.pdl
Show inline comments
 
deleted file
testdata/parser/positive/9.pdl
Show inline comments
 
deleted file
testdata/parser/positive/tarry.pdl
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)