diff --git a/tools/calyx-ffi/src/prelude.rs b/tools/calyx-ffi/src/prelude.rs index d1f95663c..425a29c2e 100644 --- a/tools/calyx-ffi/src/prelude.rs +++ b/tools/calyx-ffi/src/prelude.rs @@ -11,8 +11,12 @@ macro_rules! declare_interface { ($name:ident($($input:ident: $input_width:literal),*) -> ($($output:ident: $output_width:literal),*) $(impl { + $(fn $fn2:ident(& $self2:ident $(, $arg2:ident: $argty2:ty)* $(,)?) $(-> $ret2:ty)? $body2:block)* + })? + $(mut impl { $(fn $fn:ident(&mut $self:ident $(, $arg:ident: $argty:ty)* $(,)?) $(-> $ret:ty)? $body:block)* - })? ) => { + })? + ) => { calyx_ffi::prelude::paste::paste! { pub trait $name: CalyxFFIComponent { $( @@ -25,6 +29,9 @@ macro_rules! declare_interface { fn $output(&self) -> u64; )* + $($( + fn $fn2(&$self2, $($arg2: $argty2),*) $(-> $ret2)* {$body2} + )*)* $($( fn $fn(&mut $self, $($arg: $argty),*) $(-> $ret)* {$body} )*)* diff --git a/tools/calyx-ffi/tests/fifo.rs b/tools/calyx-ffi/tests/fifo.rs index 76ffd1159..f1199f540 100644 --- a/tools/calyx-ffi/tests/fifo.rs +++ b/tools/calyx-ffi/tests/fifo.rs @@ -14,10 +14,10 @@ enum QueueStatus { calyx_ffi::declare_interface! { Queue(cmd: 1, value: 32) -> (ans: 32, err: 1) impl { - fn status(&mut self) -> QueueStatus { + fn status(&self) -> QueueStatus { if self.err() == 0 { QueueStatus::Ok } else { QueueStatus::Err } } - + } mut impl { fn assert_no_error(&mut self) { assert_eq!(QueueStatus::Ok, self.status(), "queue underflowed or overflowed"); } diff --git a/tools/calyx-ffi/tests/stack.rs b/tools/calyx-ffi/tests/stack.rs index 8009f5143..8e5b0d60a 100644 --- a/tools/calyx-ffi/tests/stack.rs +++ b/tools/calyx-ffi/tests/stack.rs @@ -9,8 +9,8 @@ enum StackCommand { const STACK_CAPACITY: u64 = 16; calyx_ffi::declare_interface! { - Stack(cmd: 1, value: 32) -> (out: 32, length: 4) impl { - fn push(&mut self, value: u32) { + Stack(cmd: 1, value: 32) -> (out: 32, length: 4) mut impl { + fn push(&mut self, value: u32,) { assert!(self.length() < STACK_CAPACITY, "tried to push when length={}", STACK_CAPACITY); println!("stack has length {} before push", self.length()); let old_length = self.length();