Skip to main content

arcis_interpreter_proc_macros/
lib.rs

1use arcis_interpreter::{arcis_type_macro, error_macro, library_macro, module_macro};
2use proc_macro::TokenStream;
3
4/// Tells our arcis compiler to create encrypted instructions that mimic the rust module you wrote.
5/// Use `#[instruction]` to mark the functions that will be the entry points.
6#[proc_macro_attribute]
7pub fn encrypted(_attr: TokenStream, item: TokenStream) -> TokenStream {
8    module_macro(item.into()).into()
9}
10
11/// Validates an arcis library, trying to find errors.
12/// Allows to build a library that can be used in `#[encrypted]` instructions.
13///
14/// Will transform
15/// ```
16/// mod arcis_library {
17///     /* content */
18/// }
19/// ```
20/// into
21/// ```
22/// /* content */
23/// ```
24/// if it does not detect any errors.
25#[proc_macro_attribute]
26pub fn encrypted_library(_attr: TokenStream, item: TokenStream) -> TokenStream {
27    library_macro(item.into()).into()
28}
29
30/// Derives `ArcisType`, a trait that helps to use the type in automated tests.
31#[doc(hidden)]
32#[proc_macro_derive(ArcisType)]
33pub fn derive_arcis_type(input: TokenStream) -> TokenStream {
34    arcis_type_macro(input.into()).into()
35}
36
37/// An `#[instruction]`. Should be inside an `#[encrypted]` module.
38#[proc_macro_attribute]
39pub fn instruction(_attr: TokenStream, item: TokenStream) -> TokenStream {
40    error_macro(
41        item.into(),
42        "`#[instruction]` can only be used inside `#[encrypted]`.",
43    )
44    .into()
45}
46#[doc(hidden)]
47#[proc_macro_attribute]
48pub fn arcis_circuit(_attr: TokenStream, item: TokenStream) -> TokenStream {
49    error_macro(
50        item.into(),
51        "`#[arcis_circuit = \"...\"]` can only be used inside `#[encrypted]`.",
52    )
53    .into()
54}