extract new_toplevel

This commit is contained in:
numzero 2025-04-19 12:47:57 +03:00
parent 5077daf8f3
commit 6dbe397ebf

View File

@ -112,6 +112,13 @@ struct BuildContext<'a> {
}
impl BuildContext<'_> {
fn new_toplevel() -> Self {
BuildContext {
parent: None,
scope: RefCell::new(Scope::new_toplevel()),
}
}
fn request(&self, name: &ast::Ident) -> Option<Ident> {
if let Some(ident) = self.scope.borrow().lookup(name) {
return Some(ident);
@ -214,9 +221,5 @@ fn build_function(parent: &BuildContext<'_>, code: &ast::Function) -> Function {
}
pub fn build(code: &ast::Function) -> Function {
let mut root = BuildContext {
parent: None,
scope: RefCell::new(Scope::new_toplevel()),
};
build_function(&mut root, &code)
build_function(&BuildContext::new_toplevel(), &code)
}