-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: call interface macros cleanup
- Loading branch information
Showing
6 changed files
with
415 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
noir-projects/aztec-nr/aztec/src/macros/functions/abi_export.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::meta::type_of; | ||
|
||
pub(crate) comptime fn create_fn_abi_export(f: FunctionDefinition) -> Quoted { | ||
let name = f.name(); | ||
let mut parameters = | ||
f.parameters().map(|(name, typ): (Quoted, Type)| quote { pub $name: $typ }).join(quote {,}); | ||
|
||
let parameters_struct_name = f"{name}_parameters".quoted_contents(); | ||
let parameters = quote { | ||
pub struct $parameters_struct_name { | ||
$parameters | ||
} | ||
}; | ||
|
||
let return_value_type = f.return_type(); | ||
let return_type = if return_value_type != type_of(()) { | ||
quote { return_type: $return_value_type } | ||
} else { | ||
quote {} | ||
}; | ||
|
||
let abi_struct_name = f"{name}_abi".quoted_contents(); | ||
|
||
let result = quote { | ||
|
||
$parameters | ||
|
||
#[abi(functions)] | ||
pub struct $abi_struct_name { | ||
parameters: $parameters_struct_name, | ||
$return_type | ||
} | ||
}; | ||
result | ||
} |
Oops, something went wrong.