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 | 3c163eabc78ddbd26bb250ef5ad6da28cd61adc6 (patch) | |
| tree | 58e17534e1db18813554d4fb6e67020f898b655d /src/utility.rs | |
| parent | 17b78f8cb127817b93f7e6ced7e55d8748806a80 (diff) | |
feat: split engine into crates
Diffstat (limited to 'src/utility.rs')
| -rw-r--r-- | src/utility.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/utility.rs b/src/utility.rs deleted file mode 100644 index 514343c..0000000 --- a/src/utility.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Utility functions for working with the Brainfuck interpreter. - -use std::path::Path; - -use crate::{engine::Engine, executor::execute, lex, parse, Error}; - -/// Utility function to execute a Brainfuck file. Lexes, parses and executes the -/// input file. -/// -/// # Errors -/// -/// 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<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); - - let instructions = parse(&input, &operator_codes)?; - - let mut data_pointer = 0; - - execute::<E>(&instructions, tape, &mut data_pointer)?; - - Ok(()) -} - -/// Utility function to execute Brainfuck code. Lexes, parses and executes the -/// input. -/// -/// # Errors -/// -/// 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<E: Engine>(input: &str, tape: &mut [E::TapeInner]) -> Result<(), Error> { - let operator_codes = lex(input); - - let instructions = parse(input, &operator_codes)?; - - let mut data_pointer = 0; - - execute::<E>(&instructions, tape, &mut data_pointer)?; - - Ok(()) -} |