diff --git a/src/ast/environment.rs b/src/ast/environment.rs index 4fb1d1a..aef2aa8 100644 --- a/src/ast/environment.rs +++ b/src/ast/environment.rs @@ -537,11 +537,12 @@ impl Environment { // 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); + + let global_idx = GlobalIdx(*slot_count); root_scopes[0].locals.insert( Symbol::from(name), crate::ast::compiler::binder::LocalInfo { - addr: Address::Global(GlobalIdx(slot.0)), + addr: Address::Global(global_idx), identity, _ty: ty.clone(), purity: func.purity, @@ -549,17 +550,9 @@ impl Environment { ); *slot_count += 1; - // Ensure arrays are large enough - let idx = slot.0 as usize; - if idx >= values.len() { - values.resize(idx + 1, Value::Void); - types.resize(idx + 1, StaticType::Any); - purity.resize(idx + 1, Purity::Impure); - } - - types[idx] = ty; - purity[idx] = func.purity; - values[idx] = Value::Function(func); + types.push(ty); + purity.push(func.purity); + values.push(Value::Function(func)); } pub fn register_native_fn( @@ -589,11 +582,12 @@ impl Environment { // 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); + + let global_idx = GlobalIdx(*slot_count); root_scopes[0].locals.insert( Symbol::from(name), crate::ast::compiler::binder::LocalInfo { - addr: Address::Global(GlobalIdx(slot.0)), + addr: Address::Global(global_idx), identity, _ty: ty.clone(), purity: Purity::Pure, @@ -601,16 +595,9 @@ impl Environment { ); *slot_count += 1; - let idx = slot.0 as usize; - if idx >= values.len() { - values.resize(idx + 1, Value::Void); - types.resize(idx + 1, StaticType::Any); - purity.resize(idx + 1, Purity::Impure); - } - - types[idx] = ty; - purity[idx] = Purity::Pure; - values[idx] = val; + types.push(ty); + purity.push(Purity::Pure); + values.push(val); }