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/utility.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/utility.rs') diff --git a/src/utility.rs b/src/utility.rs index 58ac3e2..4eba853 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -2,7 +2,7 @@ use std::path::Path; -use crate::{constants::TapeInner, lex, parse, Error, Executor}; +use crate::{engine::Engine, executor::execute, lex, parse, Error}; /// Utility function to execute a Brainfuck file. Lexes, parses and executes the /// input file. @@ -12,7 +12,10 @@ use crate::{constants::TapeInner, lex, parse, Error, Executor}; /// This function will return an error if reading the input file, parsing or /// execution fails. See documentation for [`crate::parser::parse`] and /// [`crate::executor::execute`]. -pub fn execute_from_file(path: impl AsRef, tape: &mut [TapeInner]) -> Result<(), Error> { +pub fn execute_from_file( + path: impl AsRef, + tape: &mut [E::TapeInner], +) -> Result<(), Error> { let input = fs_err::read_to_string(path.as_ref())?; let operator_codes = lex(&input); @@ -21,7 +24,7 @@ pub fn execute_from_file(path: impl AsRef, tape: &mut [TapeInner]) -> Resu let mut data_pointer = 0; - Executor::execute(&instructions, tape, &mut data_pointer)?; + execute::(&instructions, tape, &mut data_pointer)?; Ok(()) } @@ -34,14 +37,17 @@ pub fn execute_from_file(path: impl AsRef, tape: &mut [TapeInner]) -> Resu /// This function will return an error if parsing or /// execution fails. See documentation for [`crate::parser::parse`] and /// [`crate::executor::execute`]. -pub fn execute_from_str(input: &str, tape: &mut [TapeInner]) -> Result<(), Error> { +pub fn execute_from_str>( + input: &str, + tape: &mut [E::TapeInner], +) -> Result<(), Error> { let operator_codes = lex(input); let instructions = parse(input, &operator_codes)?; let mut data_pointer = 0; - Executor::execute(&instructions, tape, &mut data_pointer)?; + execute::(&instructions, tape, &mut data_pointer)?; Ok(()) } -- cgit 1.4.1