/// Resolve the given constant value from the block scope.
///
/// This looks up `const <ident> = <expr>` and evaluates them while caching
/// their result.
Resolve the given constant value from the block scope.
This looks up `const  = ` and evaluates them while caching
their result.
Resolve the given constant value from the block scope . This looks up ` const = ` and evaluates them while caching their result .
pub(crate) fn resolve_var(
        &mut self,
        spanned: Span,
        name: &str,
        used: Used,
    ) -> Result<IrValue, IrError> {
        if let Some(ir_value) = self.scopes.try_get(name) {
            return Ok(ir_value.clone());
        }
        let mut base = self.item.clone();
        loop {
            let item = base.extended(name);
            if let Some(const_value) = self.consts.get(&item) {
                return Ok(IrValue::from_const(const_value));
            }
            if let Some(meta) = self.query.query_meta(spanned, &item, used)? {
                match &meta.kind {
                    CompileMetaKind::Const { const_value, .. } => {
                        return Ok(IrValue::from_const(const_value.clone()));
                    }
                    _ => {
                        return Err(IrError::new(spanned, IrErrorKind::UnsupportedMeta { meta }));
                    }
                }
            }
            if base.is_empty() {
                break;
            }
            base.pop();
        }
        if name.starts_with(char::is_lowercase) {
            Err(IrError::new(
                spanned,
                IrErrorKind::MissingLocal { name: name.into() },
            ))
        } else {
            Err(IrError::new(
                spanned,
                IrErrorKind::MissingConst { name: name.into() },
            ))
        }
    }
pub ( crate ) fn resolve_var ( & mut self , spanned : Span , name : & str , used : Used , ) -> Result < IrValue , IrError > { if let Some ( ir_value ) = self . scopes . try_get ( name ) { return Ok ( ir_value . clone ( ) ) ; } let mut base = self . item . clone ( ) ; loop { let item = base . extended ( name ) ; if let Some ( const_value ) = self . consts . get ( & item ) { return Ok ( IrValue :: from_const ( const_value ) ) ; } if let Some ( meta ) = self . query . query_meta ( spanned , & item , used ) ? { match & meta . kind { CompileMetaKind :: Const { const_value , .. } => { return Ok ( IrValue :: from_const ( const_value . clone ( ) ) ) ; } _ => { return Err ( IrError :: new ( spanned , IrErrorKind :: UnsupportedMeta { meta } ) ) ; } } } if base . is_empty ( ) { break ; } base . pop ( ) ; } if name . starts_with ( char :: is_lowercase ) { Err ( IrError :: new ( spanned , IrErrorKind :: MissingLocal { name : name . into ( ) } , ) ) } else { Err ( IrError :: new ( spanned , IrErrorKind :: MissingConst { name : name . into ( ) } , ) ) } }
Resolve the given constant value from the block scope.
Resolve the given constant value from the block scope .
&mut self
spanned
Span
name
&str
used
Used