diff options
| author | Sophie Forrest <git@sophieforrest.com> | 2024-08-30 23:35:45 +1200 |
|---|---|---|
| committer | Sophie Forrest <git@sophieforrest.com> | 2024-08-30 23:35:45 +1200 |
| commit | f5f789540ad7d3f7f4f855c9db69d65cfc190ee0 (patch) | |
| tree | f532988e9a35a0d2c58efbad9daf6e66288f4a1f /src/lib.rs | |
| parent | c9ab8d38765c7c80f2ea9083ce8d326f407110ac (diff) | |
feat(engine): allow choosing engine per executor call
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs index 4a7950a..b806b4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,6 @@ #[cfg(test)] extern crate test; -mod constants; mod engine; pub mod executor; pub mod lexer; @@ -90,7 +89,6 @@ pub mod parser; #[cfg(feature = "utilities")] pub mod utility; -pub use executor::Executor; pub use lexer::{lex, OperatorCode}; use miette::Diagnostic; pub use parser::{parse, Instruction}; @@ -118,33 +116,67 @@ mod tests { use test::Bencher; use super::*; - use crate::constants::TapeInner; #[test] fn hello_world() -> Result<(), Error> { - let mut tape: Vec<TapeInner> = vec![0; 1024]; + let mut tape: Vec<u8> = vec![0; 1024]; - utility::execute_from_file("./test_programs/hello_world.bf", &mut tape)?; + utility::execute_from_file::<executor::U8>("./test_programs/hello_world.bf", &mut tape)?; + + Ok(()) + } + + #[test] + fn hello_world_u16() -> Result<(), Error> { + let mut tape: Vec<u16> = vec![0; 1024]; + + utility::execute_from_file::<executor::U16>("./test_programs/hello_world.bf", &mut tape)?; + + Ok(()) + } + + #[test] + fn hello_world_from_hell() -> Result<(), Error> { + let mut tape: Vec<u16> = vec![0; 1024]; + + utility::execute_from_file::<executor::U16>( + "./test_programs/hello_world_from_hell.bf", + &mut tape, + )?; Ok(()) } #[bench] - fn hello_world_from_hell(b: &mut Bencher) { + fn hello_world_from_hell_bench_u8(b: &mut Bencher) { b.iter(|| { - let mut tape: Vec<TapeInner> = vec![0; 1024]; + let mut tape: Vec<u8> = vec![0; 1024]; #[allow(clippy::expect_used)] - utility::execute_from_file("./test_programs/hello_world.bf", &mut tape) + utility::execute_from_file::<executor::U8>("./test_programs/hello_world.bf", &mut tape) .expect("failed to run"); }); } + #[bench] + fn hello_world_from_hell_bench_u16(b: &mut Bencher) { + b.iter(|| { + let mut tape: Vec<u16> = vec![0; 1024]; + + #[allow(clippy::expect_used)] + utility::execute_from_file::<executor::U16>( + "./test_programs/hello_world.bf", + &mut tape, + ) + .expect("failed to run"); + }); + } + #[test] fn hello_world_short() -> Result<(), Error> { - let mut tape: Vec<TapeInner> = vec![0; 1024]; + let mut tape: Vec<u8> = vec![0; 1024]; - utility::execute_from_str( + utility::execute_from_str::<executor::U8>( "--[+++++++<---->>-->+>+>+<<<<]<.>++++[-<++++>>->--<<]>>-.>--..>+.<<<.<<-.>>+>->>.\ +++[.<]", &mut tape, |