1use std::sync::{
2 Arc,
3 atomic::{AtomicU64, Ordering},
4};
5
6pub mod ast;
7pub mod builtins;
8pub mod error;
9pub mod expr;
10pub mod format;
11pub mod gen_uplc;
12pub mod levenshtein;
13pub mod line_numbers;
14pub mod parser;
15pub mod plutus_version;
16pub mod pretty;
17pub mod test_framework;
18pub mod tipo;
19pub mod utils;
20pub mod version;
21
22#[derive(Debug, Default, Clone)]
23pub struct IdGenerator {
24 id: Arc<AtomicU64>,
25}
26
27impl IdGenerator {
28 pub fn new() -> Self {
29 Self::default()
30 }
31
32 pub fn next(&self) -> u64 {
33 self.id.fetch_add(1, Ordering::Relaxed)
34 }
35}
36
37#[macro_export]
38macro_rules! aiken_fn {
39 ($module_types:expr, $id_gen:expr, $src:expr) => {{
40 let (untyped_module, _) = $crate::parser::module($src, $crate::ast::ModuleKind::Lib)
41 .expect("failed to parse module.");
42
43 let module_name = "";
44
45 let mut warnings = vec![];
46
47 let typed_module = untyped_module
48 .infer(
49 $id_gen,
50 $crate::ast::ModuleKind::Lib,
51 module_name,
52 $module_types,
53 $crate::ast::Tracing::silent(),
54 &mut warnings,
55 None,
56 )
57 .unwrap();
58
59 if let Some($crate::ast::Definition::Fn(typed_fn)) =
60 typed_module.definitions.into_iter().last()
61 {
62 typed_fn
63 } else {
64 unreachable!()
65 }
66 }};
67}
68
69#[cfg(test)]
70mod tests;