pub fn eval<T>(&self, target: &T) -> Result<<T::Output as IrEval>::Output, IrError>
    where
        T: Spanned + IrCompile,
        T::Output: IrEval,
    {
        let mut ir_query = self.query.as_ir_query();

        let mut ir_compiler = IrCompiler {
            storage: self.storage.clone(),
            source: self.source.clone(),
            query: &mut *ir_query,
        };

        let output = ir_compiler.compile(target)?;

        let mut ir_interpreter = IrInterpreter {
            budget: IrBudget::new(1_000_000),
            scopes: Default::default(),
            module: self.item.module.clone(),
            item: self.item.item.clone(),
            consts: self.consts.clone(),
            query: &mut *ir_query,
        };

        match ir_interpreter.eval(&output, Used::Used) {
            Ok(value) => Ok(value),
            Err(e) => match e {
                IrEvalOutcome::Error(error) => Err(error),
                IrEvalOutcome::NotConst(span) => Err(IrError::new(span, IrErrorKind::NotConst)),
                IrEvalOutcome::Break(span, _) => {
                    Err(IrError::new(span, IrErrorKind::BreakOutsideOfLoop))
                }
            },
        }
    }
/// Evaluate the given ast as a constant expression.
Evaluate the given ast as a constant expression.
Evaluate the given ast as a constant expression .
pub fn eval<T>(&self, target: &T) -> Result<<T::Output as IrEval>::Output, IrError>
    where
        T: Spanned + IrCompile,
        T::Output: IrEval,
    {
        let mut ir_query = self.query.as_ir_query();
        let mut ir_compiler = IrCompiler {
            storage: self.storage.clone(),
            source: self.source.clone(),
            query: &mut *ir_query,
        };
        let output = ir_compiler.compile(target)?;
        let mut ir_interpreter = IrInterpreter {
            budget: IrBudget::new(1_000_000),
            scopes: Default::default(),
            module: self.item.module.clone(),
            item: self.item.item.clone(),
            consts: self.consts.clone(),
            query: &mut *ir_query,
        };
        match ir_interpreter.eval(&output, Used::Used) {
            Ok(value) => Ok(value),
            Err(e) => match e {
                IrEvalOutcome::Error(error) => Err(error),
                IrEvalOutcome::NotConst(span) => Err(IrError::new(span, IrErrorKind::NotConst)),
                IrEvalOutcome::Break(span, _) => {
                    Err(IrError::new(span, IrErrorKind::BreakOutsideOfLoop))
                }
            },
        }
    }
pub fn eval < T > ( & self , target : & T ) -> Result < < T :: Output as IrEval > :: Output , IrError > where T : Spanned + IrCompile , T :: Output : IrEval , { let mut ir_query = self . query . as_ir_query ( ) ; let mut ir_compiler = IrCompiler { storage : self . storage . clone ( ) , source : self . source . clone ( ) , query : & mut * ir_query , } ; let output = ir_compiler . compile ( target ) ? ; let mut ir_interpreter = IrInterpreter { budget : IrBudget :: new ( 1_000_000 ) , scopes : Default :: default ( ) , module : self . item . module . clone ( ) , item : self . item . item . clone ( ) , consts : self . consts . clone ( ) , query : & mut * ir_query , } ; match ir_interpreter . eval ( & output , Used :: Used ) { Ok ( value ) => Ok ( value ) , Err ( e ) => match e { IrEvalOutcome :: Error ( error ) => Err ( error ) , IrEvalOutcome :: NotConst ( span ) => Err ( IrError :: new ( span , IrErrorKind :: NotConst ) ) , IrEvalOutcome :: Break ( span , _ ) => { Err ( IrError :: new ( span , IrErrorKind :: BreakOutsideOfLoop ) ) } } , } }
Evaluate the given ast as a constant expression.
Evaluate the given ast as a constant expression .
&self
target
&T
&self
target
&T