diff options
Diffstat (limited to '')
| -rw-r--r-- | src/utility.rs | 16 |
1 files changed, 11 insertions, 5 deletions
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<Path>, tape: &mut [TapeInner]) -> Result<(), Error> { +pub fn execute_from_file<E: Engine>( + path: impl AsRef<Path>, + 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<Path>, tape: &mut [TapeInner]) -> Resu let mut data_pointer = 0; - Executor::execute(&instructions, tape, &mut data_pointer)?; + execute::<E>(&instructions, tape, &mut data_pointer)?; Ok(()) } @@ -34,14 +37,17 @@ pub fn execute_from_file(path: impl AsRef<Path>, 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<E: Engine<TapeInner = u8>>( + 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::<E>(&instructions, tape, &mut data_pointer)?; Ok(()) } |