Add purity to LocalInfo and initialize in binder
The `LocalInfo` struct now includes a `purity` field to track the purity of local variables and function arguments. This is initialized to `Purity::Impure` for local variables and arguments within functions and when registering native functions. Additionally, the `Environment` struct is updated to include `root_scopes` and `root_slot_count` to support parallel mode compilation by populating the root scope with initial function and native function information.
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::ast::compiler::bound_nodes::{
|
|||||||
};
|
};
|
||||||
use crate::ast::diagnostics::Diagnostics;
|
use crate::ast::diagnostics::Diagnostics;
|
||||||
use crate::ast::nodes::{Node, Symbol, UntypedKind};
|
use crate::ast::nodes::{Node, Symbol, UntypedKind};
|
||||||
use crate::ast::types::{Identity, StaticType};
|
use crate::ast::types::{Identity, StaticType, Purity};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -13,6 +13,7 @@ pub struct LocalInfo {
|
|||||||
pub addr: Address,
|
pub addr: Address,
|
||||||
pub identity: Identity,
|
pub identity: Identity,
|
||||||
pub _ty: StaticType,
|
pub _ty: StaticType,
|
||||||
|
pub purity: Purity,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -69,6 +70,7 @@ impl FunctionCompiler {
|
|||||||
addr: Address::Local(slot),
|
addr: Address::Local(slot),
|
||||||
identity,
|
identity,
|
||||||
_ty: StaticType::Any,
|
_ty: StaticType::Any,
|
||||||
|
purity: Purity::Impure,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.slot_count += 1;
|
self.slot_count += 1;
|
||||||
@@ -191,6 +193,7 @@ impl Binder {
|
|||||||
addr,
|
addr,
|
||||||
identity,
|
identity,
|
||||||
_ty: StaticType::Any,
|
_ty: StaticType::Any,
|
||||||
|
purity: Purity::Impure,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return Some(addr);
|
return Some(addr);
|
||||||
|
|||||||
+39
-5
@@ -76,6 +76,8 @@ pub struct Environment {
|
|||||||
pub global_purity: Rc<RefCell<HashMap<GlobalIdx, Purity>>>,
|
pub global_purity: Rc<RefCell<HashMap<GlobalIdx, Purity>>>,
|
||||||
pub global_values: Rc<RefCell<Vec<Value>>>,
|
pub global_values: Rc<RefCell<Vec<Value>>>,
|
||||||
pub fixed_scope_idx: i32,
|
pub fixed_scope_idx: i32,
|
||||||
|
pub root_scopes: Rc<RefCell<Vec<crate::ast::compiler::binder::CompilerScope>>>,
|
||||||
|
pub root_slot_count: Rc<RefCell<u32>>,
|
||||||
pub function_registry: Rc<RefCell<GlobalFunctionRegistry>>,
|
pub function_registry: Rc<RefCell<GlobalFunctionRegistry>>,
|
||||||
pub typed_function_registry: Rc<RefCell<GlobalAnalyzedRegistry>>,
|
pub typed_function_registry: Rc<RefCell<GlobalAnalyzedRegistry>>,
|
||||||
pub monomorph_cache: Rc<RefCell<MonoCache>>,
|
pub monomorph_cache: Rc<RefCell<MonoCache>>,
|
||||||
@@ -164,6 +166,8 @@ impl Environment {
|
|||||||
global_purity: Rc::new(RefCell::new(HashMap::new())),
|
global_purity: Rc::new(RefCell::new(HashMap::new())),
|
||||||
global_values: Rc::new(RefCell::new(Vec::new())),
|
global_values: Rc::new(RefCell::new(Vec::new())),
|
||||||
fixed_scope_idx: -1,
|
fixed_scope_idx: -1,
|
||||||
|
root_scopes: Rc::new(RefCell::new(vec![crate::ast::compiler::binder::CompilerScope::new()])),
|
||||||
|
root_slot_count: Rc::new(RefCell::new(0)),
|
||||||
function_registry: Rc::new(RefCell::new(HashMap::new())),
|
function_registry: Rc::new(RefCell::new(HashMap::new())),
|
||||||
typed_function_registry: Rc::new(RefCell::new(HashMap::new())),
|
typed_function_registry: Rc::new(RefCell::new(HashMap::new())),
|
||||||
monomorph_cache: Rc::new(RefCell::new(HashMap::new())),
|
monomorph_cache: Rc::new(RefCell::new(HashMap::new())),
|
||||||
@@ -504,10 +508,25 @@ impl Environment {
|
|||||||
|
|
||||||
let idx = GlobalIdx(values.len() as u32);
|
let idx = GlobalIdx(values.len() as u32);
|
||||||
let identity = NodeIdentity::new(SourceLocation { line: 0, col: 0 });
|
let identity = NodeIdentity::new(SourceLocation { line: 0, col: 0 });
|
||||||
names.insert(Symbol::from(name), (idx, identity));
|
names.insert(Symbol::from(name), (idx, identity.clone()));
|
||||||
types.insert(idx, ty);
|
types.insert(idx, ty.clone());
|
||||||
purity.insert(idx, func.purity);
|
purity.insert(idx, func.purity);
|
||||||
values.push(Value::Function(func));
|
values.push(Value::Function(func.clone()));
|
||||||
|
|
||||||
|
// Parallel mode: populate root_scopes[0]
|
||||||
|
let mut root_scopes = self.root_scopes.borrow_mut();
|
||||||
|
let mut slot_count = self.root_slot_count.borrow_mut();
|
||||||
|
let slot = crate::ast::compiler::bound_nodes::LocalSlot(*slot_count);
|
||||||
|
root_scopes[0].locals.insert(
|
||||||
|
Symbol::from(name),
|
||||||
|
crate::ast::compiler::binder::LocalInfo {
|
||||||
|
addr: Address::Local(slot),
|
||||||
|
identity,
|
||||||
|
_ty: ty,
|
||||||
|
purity: func.purity,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
*slot_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_native_fn(
|
pub fn register_native_fn(
|
||||||
@@ -535,10 +554,25 @@ impl Environment {
|
|||||||
|
|
||||||
let idx = GlobalIdx(values.len() as u32);
|
let idx = GlobalIdx(values.len() as u32);
|
||||||
let identity = NodeIdentity::new(SourceLocation { line: 0, col: 0 });
|
let identity = NodeIdentity::new(SourceLocation { line: 0, col: 0 });
|
||||||
names.insert(Symbol::from(name), (idx, identity));
|
names.insert(Symbol::from(name), (idx, identity.clone()));
|
||||||
types.insert(idx, ty);
|
types.insert(idx, ty.clone());
|
||||||
purity.insert(idx, Purity::Pure);
|
purity.insert(idx, Purity::Pure);
|
||||||
values.push(val);
|
values.push(val);
|
||||||
|
|
||||||
|
// Parallel mode: populate root_scopes[0]
|
||||||
|
let mut root_scopes = self.root_scopes.borrow_mut();
|
||||||
|
let mut slot_count = self.root_slot_count.borrow_mut();
|
||||||
|
let slot = crate::ast::compiler::bound_nodes::LocalSlot(*slot_count);
|
||||||
|
root_scopes[0].locals.insert(
|
||||||
|
Symbol::from(name),
|
||||||
|
crate::ast::compiler::binder::LocalInfo {
|
||||||
|
addr: Address::Local(slot),
|
||||||
|
identity,
|
||||||
|
_ty: ty,
|
||||||
|
purity: Purity::Pure,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
*slot_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user