1#![allow(ambiguous_glob_reexports)]
24
25#[cfg(target_arch = "wasm32")]
26extern crate self as snarkvm;
27
28#[cfg(target_arch = "wasm32")]
31mod snarkvm_wasm;
32#[cfg(target_arch = "wasm32")]
33#[doc(hidden)]
34pub use snarkvm_wasm::{console, prelude, synthesizer};
35
36mod errors;
37
38mod composite;
39pub use self::composite::*;
40
41pub mod common;
42pub use self::common::*;
43
44pub mod constructor;
45pub use self::constructor::*;
46
47mod expressions;
48pub use self::expressions::*;
49
50mod functions;
51pub use self::functions::*;
52
53mod interface;
54pub use self::interface::*;
55
56mod indent_display;
57use indent_display::*;
58
59pub mod const_eval;
60
61mod library;
62pub use self::library::*;
63
64mod mapping;
65pub use self::mapping::*;
66
67mod module;
68pub use self::module::*;
69
70mod passes;
71pub use self::passes::*;
72
73mod program;
74pub use self::program::*;
75
76mod statement;
77pub use self::statement::*;
78
79mod storage;
80pub use self::storage::*;
81
82mod types;
83pub use self::types::*;
84
85mod stub;
86pub use self::stub::*;
87
88pub use common::node::*;
89
90#[allow(clippy::large_enum_variant)]
96#[derive(Clone, Debug, Eq, PartialEq)]
97pub enum Ast {
98 Program(Program),
99 Library(Library),
100}
101
102impl std::fmt::Display for Ast {
103 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 match self {
105 Ast::Program(program) => write!(f, "{}", program),
106 Ast::Library(library) => write!(f, "{}", library),
107 }
108 }
109}
110
111impl Default for Ast {
114 fn default() -> Self {
115 Ast::Program(Program::default())
116 }
117}
118
119impl Ast {
120 pub fn map(self, program_fn: impl FnOnce(Program) -> Program, library_fn: impl FnOnce(Library) -> Library) -> Self {
121 match self {
122 Ast::Program(p) => Ast::Program(program_fn(p)),
123 Ast::Library(l) => Ast::Library(library_fn(l)),
124 }
125 }
126
127 pub fn try_map<E>(
128 self,
129 program_fn: impl FnOnce(Program) -> Result<Program, E>,
130 library_fn: impl FnOnce(Library) -> Result<Library, E>,
131 ) -> Result<Self, E> {
132 match self {
133 Ast::Program(p) => Ok(Ast::Program(program_fn(p)?)),
134 Ast::Library(l) => Ok(Ast::Library(library_fn(l)?)),
135 }
136 }
137
138 pub fn visit(&self, program_fn: impl FnOnce(&Program), library_fn: impl FnOnce(&Library)) {
139 match self {
140 Ast::Program(p) => program_fn(p),
141 Ast::Library(l) => library_fn(l),
142 }
143 }
144}