pub(crate) fn call_const_fn<S>(
        &mut self,
        spanned: S,
        meta: &CompileMeta,
        from: &CompileItem,
        query_const_fn: &QueryConstFn,
        args: &[(ast::Expr, Option<T![,]>)],
    ) -> Result<ConstValue, CompileError>
    where
        S: Copy + Spanned,
    {
        if query_const_fn.ir_fn.args.len() != args.len() {
            return Err(CompileError::new(
                spanned,
                CompileErrorKind::UnsupportedArgumentCount {
                    meta: meta.clone(),
                    expected: query_const_fn.ir_fn.args.len(),
                    actual: args.len(),
                },
            ));
        }

        let mut ir_query = self.query.as_ir_query();

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

        let mut compiled = Vec::new();

        // TODO: precompile these and fetch using opaque id?
        for ((a, _), name) in args.iter().zip(&query_const_fn.ir_fn.args) {
            compiled.push((compiler.compile(a)?, name));
        }

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

        for (ir, name) in compiled {
            let value = interpreter.eval_value(&ir, Used::Used)?;
            interpreter.scopes.decl(name, value, spanned)?;
        }

        interpreter.module = query_const_fn.item.module.clone();
        interpreter.item = query_const_fn.item.item.clone();
        let value = interpreter.eval_value(&query_const_fn.ir_fn.ir, Used::Used)?;
        Ok(value.into_const(spanned)?)
    }
/// Calling a constant function by id and return the resuling value.
Calling a constant function by id and return the resuling value.
Calling a constant function by id and return the resuling value .
pub(crate) fn call_const_fn<S>(
        &mut self,
        spanned: S,
        meta: &CompileMeta,
        from: &CompileItem,
        query_const_fn: &QueryConstFn,
        args: &[(ast::Expr, Option<T![,]>)],
    ) -> Result<ConstValue, CompileError>
    where
        S: Copy + Spanned,
    {
        if query_const_fn.ir_fn.args.len() != args.len() {
            return Err(CompileError::new(
                spanned,
                CompileErrorKind::UnsupportedArgumentCount {
                    meta: meta.clone(),
                    expected: query_const_fn.ir_fn.args.len(),
                    actual: args.len(),
                },
            ));
        }
        let mut ir_query = self.query.as_ir_query();
        let mut compiler = IrCompiler {
            storage: self.storage.clone(),
            source: self.source.clone(),
            query: &mut *ir_query,
        };
        let mut compiled = Vec::new();
        // TODO: precompile these and fetch using opaque id?
        for ((a, _), name) in args.iter().zip(&query_const_fn.ir_fn.args) {
            compiled.push((compiler.compile(a)?, name));
        }
        let mut interpreter = IrInterpreter {
            budget: IrBudget::new(1_000_000),
            scopes: Default::default(),
            module: from.module.clone(),
            item: from.item.clone(),
            consts: self.consts.clone(),
            query: &mut *ir_query,
        };
        for (ir, name) in compiled {
            let value = interpreter.eval_value(&ir, Used::Used)?;
            interpreter.scopes.decl(name, value, spanned)?;
        }
        interpreter.module = query_const_fn.item.module.clone();
        interpreter.item = query_const_fn.item.item.clone();
        let value = interpreter.eval_value(&query_const_fn.ir_fn.ir, Used::Used)?;
        Ok(value.into_const(spanned)?)
    }
pub ( crate ) fn call_const_fn < S > ( & mut self , spanned : S , meta : & CompileMeta , from : & CompileItem , query_const_fn : & QueryConstFn , args : & [ ( ast :: Expr , Option < T ! [ ] > ) ] , ) -> Result < ConstValue , CompileError > where S : Copy + Spanned , { if query_const_fn . ir_fn . args . len ( ) != args . len ( ) { return Err ( CompileError :: new ( spanned , CompileErrorKind :: UnsupportedArgumentCount { meta : meta . clone ( ) , expected : query_const_fn . ir_fn . args . len ( ) , actual : args . len ( ) , } , ) ) ; } let mut ir_query = self . query . as_ir_query ( ) ; let mut compiler = IrCompiler { storage : self . storage . clone ( ) , source : self . source . clone ( ) , query : & mut * ir_query , } ; let mut compiled = Vec :: new ( ) ; // TODO: precompile these and fetch using opaque id? for ( ( a , _ ) , name ) in args . iter ( ) . zip ( & query_const_fn . ir_fn . args ) { compiled . push ( ( compiler . compile ( a ) ? , name ) ) ; } let mut interpreter = IrInterpreter { budget : IrBudget :: new ( 1_000_000 ) , scopes : Default :: default ( ) , module : from . module . clone ( ) , item : from . item . clone ( ) , consts : self . consts . clone ( ) , query : & mut * ir_query , } ; for ( ir , name ) in compiled { let value = interpreter . eval_value ( & ir , Used :: Used ) ? ; interpreter . scopes . decl ( name , value , spanned ) ? ; } interpreter . module = query_const_fn . item . module . clone ( ) ; interpreter . item = query_const_fn . item . item . clone ( ) ; let value = interpreter . eval_value ( & query_const_fn . ir_fn . ir , Used :: Used ) ? ; Ok ( value . into_const ( spanned ) ? ) }
Calling a constant function by id and return the resuling value.
Calling a constant function by id and return the resuling value .
&mut self
spanned
S
meta
&CompileMeta
from
&CompileItem
query_const_fn
&QueryConstFn
args
&[(ast::Expr, Option<T![,]>)]
&mut self
spanned
S
meta
&CompileMeta
from
&CompileItem
query_const_fn
&QueryConstFn
args
&[(ast::Expr, Option<T![,]>)]