I'm developing a small language in Rust. To improve the performance, I'd like to use fastcall calling convention for x86. The "fastcall"
ABI is not supported for ARM.
For x86:
fn add_primitive(&mut self, name: &str, action: extern "fastcall" fn(&mut Self)) {
...
}
extern "fastcall" fn a_primitive(&mut self) {}
For ARM:
fn add_primitive(&mut self, name: &str, action: fn(&mut Self)) {
...
}
fn a_primitive(&mut self) {}
Using C I can define a macro
#ifdef x86
#define PRIMITIVE extern "fastcall" fn
#endif
#ifdef arm
#define PRIMITIVE fn
#endif
fn add_primitive(&mut self, name: &str, action: PRIMITIVE(&mut Self)) {
...
}
PRIMITIVE a_primitive(&mut self) {}
I do not know how to solve this problem using Rust's macro system.
EDIT:
I need two different macros. I know how to use target_arch to define different versions of functions but not macros.