mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-16 01:25:07 +01:00
more
This commit is contained in:
parent
4abbd3ca76
commit
1407eb299a
2 changed files with 67 additions and 18 deletions
|
|
@ -1,12 +1,50 @@
|
|||
use parser::{ast, Span};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::hir::{self, Symbol};
|
||||
use crate::hir::{self, DefId, Symbol};
|
||||
|
||||
pub struct LowerCtx<'hir> {
|
||||
hir_symbol_intern: lasso::Rodeo,
|
||||
hir_arena: &'hir bumpalo::Bump,
|
||||
global_symbols: FxHashMap<Symbol, &'hir hir::ExternalDecl>,
|
||||
scope: Scope,
|
||||
}
|
||||
|
||||
struct Scope {
|
||||
parent: Option<Box<Scope>>,
|
||||
variables: FxHashMap<Symbol, DefId>,
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
parent: None,
|
||||
variables: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn insert(&mut self, symbol: Symbol, def_id: DefId) {
|
||||
self.variables.insert(symbol, def_id);
|
||||
}
|
||||
|
||||
fn enter_new(&mut self) {
|
||||
let new = Self::new();
|
||||
let this = std::mem::replace(self, new);
|
||||
self.parent = Some(Box::new(this));
|
||||
}
|
||||
|
||||
fn leave(&mut self) {
|
||||
let old = std::mem::replace(self, Self::new());
|
||||
let parent = old.parent.expect("parent not found when leaving scope");
|
||||
*self = *parent;
|
||||
}
|
||||
|
||||
fn lookup(&self, sym: Symbol) -> Option<DefId> {
|
||||
self.variables
|
||||
.get(&sym)
|
||||
.copied()
|
||||
.or_else(|| self.parent.as_ref().and_then(|parent| parent.lookup(sym)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> LowerCtx<'hir> {
|
||||
|
|
@ -16,10 +54,13 @@ impl<'hir> LowerCtx<'hir> {
|
|||
todo!()
|
||||
}
|
||||
|
||||
fn lower_decl(&mut self, decl: &ast::ExternalDecl, _span: Span) -> hir::ExternalDecl {
|
||||
fn lower_decl(&mut self, decl: &ast::ExternalDecl, span: Span) -> hir::ExternalDecl {
|
||||
match decl {
|
||||
ast::ExternalDecl::Decl(_) => todo!(),
|
||||
ast::ExternalDecl::FunctionDef(_func) => todo!(),
|
||||
ast::ExternalDecl::FunctionDef(def) => {
|
||||
let _fn_def = self.lower_function_def(def, span);
|
||||
hir::ExternalDecl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,11 +76,9 @@ impl<'hir> LowerCtx<'hir> {
|
|||
|
||||
let name_sym = self.hir_symbol_intern.get_or_intern(name_ident);
|
||||
|
||||
|
||||
if self.global_symbols.contains_key(&name_sym) {
|
||||
panic!("function declarated twice! return this error properly! lol!")
|
||||
}
|
||||
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue