1use leo_errors::{InterpreterHalt, Result};
18use leo_span::{Span, Symbol};
19
20use snarkvm::prelude::{Identifier, TestnetV0};
21
22#[macro_export]
23macro_rules! tc_fail {
24 () => {
25 panic!("type checker failure")
26 };
27}
28
29#[macro_export]
30macro_rules! halt_no_span {
31 ($($x:tt)*) => {
32 return Err(InterpreterHalt::new(format!($($x)*)).into())
33 }
34}
35
36#[macro_export]
37macro_rules! halt {
38 ($span: expr) => {
39 return Err(InterpreterHalt::new_spanned(String::new(), $span).into())
40
41 };
42
43 ($span: expr, $($x:tt)*) => {
44 return Err(InterpreterHalt::new_spanned(format!($($x)*), $span).into())
45 };
46}
47
48pub trait ExpectTc {
49 type T;
50 fn expect_tc(self, span: Span) -> Result<Self::T>;
51}
52
53impl<T> ExpectTc for Option<T> {
54 type T = T;
55
56 fn expect_tc(self, span: Span) -> Result<Self::T> {
57 match self {
58 Some(t) => Ok(t),
59 None => Err(InterpreterHalt::new_spanned("type failure".into(), span).into()),
60 }
61 }
62}
63
64impl<T, U: std::fmt::Debug> ExpectTc for Result<T, U> {
65 type T = T;
66
67 fn expect_tc(self, span: Span) -> Result<Self::T> {
68 self.map_err(|_e| InterpreterHalt::new_spanned("type failure".into(), span).into())
69 }
70}
71
72pub fn snarkvm_identifier_to_symbol(id: &Identifier<TestnetV0>) -> Symbol {
73 let s = id.to_string();
74 Symbol::intern(&s)
75}