From f5f789540ad7d3f7f4f855c9db69d65cfc190ee0 Mon Sep 17 00:00:00 2001 From: Sophie Forrest Date: Fri, 30 Aug 2024 23:35:45 +1200 Subject: feat(engine): allow choosing engine per executor call --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'src/lib.rs') 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 = vec![0; 1024]; + let mut tape: Vec = vec![0; 1024]; - utility::execute_from_file("./test_programs/hello_world.bf", &mut tape)?; + utility::execute_from_file::("./test_programs/hello_world.bf", &mut tape)?; + + Ok(()) + } + + #[test] + fn hello_world_u16() -> Result<(), Error> { + let mut tape: Vec = vec![0; 1024]; + + utility::execute_from_file::("./test_programs/hello_world.bf", &mut tape)?; + + Ok(()) + } + + #[test] + fn hello_world_from_hell() -> Result<(), Error> { + let mut tape: Vec = vec![0; 1024]; + + utility::execute_from_file::( + "./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 = vec![0; 1024]; + let mut tape: Vec = vec![0; 1024]; #[allow(clippy::expect_used)] - utility::execute_from_file("./test_programs/hello_world.bf", &mut tape) + utility::execute_from_file::("./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 = vec![0; 1024]; + + #[allow(clippy::expect_used)] + utility::execute_from_file::( + "./test_programs/hello_world.bf", + &mut tape, + ) + .expect("failed to run"); + }); + } + #[test] fn hello_world_short() -> Result<(), Error> { - let mut tape: Vec = vec![0; 1024]; + let mut tape: Vec = vec![0; 1024]; - utility::execute_from_str( + utility::execute_from_str::( "--[+++++++<---->>-->+>+>+<<<<]<.>++++[-<++++>>->--<<]>>-.>--..>+.<<<.<<-.>>+>->>.\ +++[.<]", &mut tape, -- cgit 1.4.1