libjuno 0.1.3

Library for JunoLang
use std::collections::HashMap;

use super::*;
impl<'a> MetaIRGen<'a> {
    pub fn push_scope(&mut self) {
        self.locals.push(HashMap::new());
    }

    pub fn pop_scope(&mut self) {
        self.locals.pop();
    }

    pub fn insert_local(&mut self, id: SymbolId, ty: MetaType) {
        self.locals.last_mut().unwrap().insert(id, ty);
    }

    pub fn lookup_local(&self, id: SymbolId) -> MetaType {
        for scope in self.locals.iter().rev() {
            if let Some(ty) = scope.get(&id) {
                return ty.clone();
            }
        }

        panic!("unknown variable {}", id);
    }
    pub fn lookup_local_type(&self, id: SymbolId) -> MetaType {
        for scope in self.locals.iter().rev() {
            if let Some(ty) = scope.get(&id) {
                return ty.clone();
            }
        }
        let binding = format!("<noname:{:#08x}>", id).to_string();
        let name = &self.symbol_list.get(id as usize).unwrap_or(&binding);
        panic!("unknown local variable '{}'", name);
    }
    
}