From 17b78f8cb127817b93f7e6ced7e55d8748806a80 Mon Sep 17 00:00:00 2001 From: Sophie Forrest Date: Fri, 30 Aug 2024 23:35:45 +1200 Subject: feat: bar engines behind features, optimise release and small profiles --- src/executor.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/executor.rs') diff --git a/src/executor.rs b/src/executor.rs index da7d676..c5fff93 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -25,13 +25,46 @@ pub struct U8; /// Struct for executor implementation, allows u16 Engine to be implemented. #[derive(Clone, Copy, Debug)] +#[cfg(feature = "engine-u16")] pub struct U16; /// Struct for executor implementation, allows u32 Engine to be implemented. #[derive(Clone, Copy, Debug)] +#[cfg(feature = "engine-u32")] pub struct U32; -/// Executes the provided instruction set, utilising the provided tape.. +/// Trait that must be implemented by all executors. +pub trait Executor { + /// Executes the provided instruction set, utilising the provided tape. + /// + /// # Errors + /// + /// This function will return an error if the Brainfuck code indexes out of + /// bounds of the tape, or if the executor cannot read an input byte from + /// stdin. + fn execute( + instructions: &[Instruction], + tape: &mut [E::TapeInner], + data_pointer: &mut usize, + ) -> Result<(), Error>; +} + +impl Executor for E +where + E: Engine, +{ + #[inline] + fn execute( + instructions: &[Instruction], + tape: &mut [::TapeInner], + data_pointer: &mut usize, + ) -> Result<(), Error> { + execute::(instructions, tape, data_pointer) + } +} + +/// Executes the provided instruction set, utilising the provided tape. This +/// function allows specifying the Brainfuck engine implementation per call. /// /// # Errors /// -- cgit 1.4.1