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