1#[macro_export]
5macro_rules! term {
6 ((!$precomp:literal, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
11 use $crate::algebra::dynamic_function::TypeShape;
12
13 Term::from(term!((!$precomp, $counter) > TypeShape::of::<$typ>()))
15 }};
16 (($agent:expr, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
17 use $crate::algebra::dynamic_function::TypeShape;
18 use $crate::algebra::Term;
19
20
21 Term::from(term!(($agent, $counter) > TypeShape::of::<$typ>()))
23 }};
24 ((!$precomp:literal, $counter:expr) $(>$req_type:expr)?) => {{
25 use $crate::algebra::signature::Signature;
26 use $crate::algebra::Term;
27 use $crate::trace::Source;
28
29 let var = Signature::new_var($($req_type)?, Some(Source::Label(Some($precomp.into()))), None, $counter); Term::from(DYTerm::Variable(var))
31 }};
32 (($agent:expr, $counter:expr) $(>$req_type:expr)?) => {{
33 use $crate::algebra::signature::Signature;
34 use $crate::algebra::{DYTerm,Term};
35 use $crate::trace::Source;
36
37 let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), None, $counter); Term::from(DYTerm::Variable(var))
39 }};
40
41 ((!$precomp:literal, $counter:expr) [$message_type:expr] / $typ:ty $(>$req_type:expr)?) => {{
45 use $crate::algebra::dynamic_function::TypeShape;
46
47 Term::from(term!((!$precomp, $counter) [$message_type] > TypeShape::of::<$typ>()))
49 }};
50 (($agent:expr, $counter:expr) [$message_type:expr] / $typ:ty $(>$req_type:expr)?) => {{
51 use $crate::algebra::dynamic_function::TypeShape;
52
53 Term::from(term!(($agent, $counter) [$message_type] > TypeShape::of::<$typ>()))
55 }};
56 ((!$precomp:literal, $counter:expr) [$message_type:expr] $(>$req_type:expr)?) => {{
58 use $crate::algebra::signature::Signature;
59 use $crate::algebra::Term;
60 use $crate::trace::Source;
61
62 let var = Signature::new_var($($req_type)?, Some(Source::Label(Some($precomp.into()))), $message_type, $counter);
63 Term::from(DYTerm::Variable(var))
64 }};
65 (($agent:expr, $counter:expr) [$message_type:expr] $(>$req_type:expr)?) => {{
66 use $crate::algebra::signature::Signature;
67 use $crate::algebra::{DYTerm,Term};
68 use $crate::trace::Source;
69
70 let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), $message_type, $counter);
71 Term::from(DYTerm::Variable(var))
72 }};
73
74 ($func:ident ( $( $arg:tt $( ( $($inner:tt)* ) )? ),* ) $(>$req_type:expr)?) => {{
77 use $crate::algebra::signature::Signature;
78 use $crate::algebra::{DYTerm,Term};
79
80 let func = Signature::new_function(&$func);
81 #[allow(unused_assignments, unused_variables, unused_mut)]
82 let mut i = 0;
83
84 #[allow(unused_assignments)]
85 #[allow(clippy::mixed_read_write_in_expression)]
86 let arguments = vec![$({
87 #[allow(unused)]
88 if let Some(argument) = func.shape().argument_types.get(i) {
89 i += 1;
90 Term::from($crate::term_arg!($arg $( ( $($inner)* ) )? > argument.clone()))
91 } else {
92 panic!("too many arguments specified for function {}", func)
93 }
94 }),*];
95
96 Term::from(DYTerm::Application(func, arguments))
97 }};
98 ($func:ident $(>$req_type:expr)?) => {{
100 use $crate::algebra::signature::Signature;
101 use $crate::algebra::{DYTerm,Term};
102
103
104 let func = Signature::new_function(&$func);
105 Term::from(DYTerm::Application(func, vec![]))
106 }};
107
108 (@$e:ident $(>$req_type:expr)?) => {{
112 use $crate::algebra::{DYTerm,Term};
113
114 let subterm: &Term<_> = &$e;
115 Term::from(subterm.clone())
116 }};
117}
118
119#[macro_export]
120macro_rules! term_arg {
121 ( ( $($e:tt)* ) $(>$req_type:expr)?) => {{
124 use $crate::algebra::{DYTerm,Term};
125
126 Term::from(term!($($e)* $(>$req_type)?))
127 }};
128 ( $f:ident ( $($inner:tt)* ) $(>$req_type:expr)?) => {{
130 use $crate::algebra::{DYTerm,Term};
131
132 Term::from(term!($f ( $($inner)* ) $(>$req_type)?))
133 }};
134 ($e:tt $(>$req_type:expr)?) => {{
136 Term::from(term!($e $(>$req_type)?))
137 }};
138}