Skip to content

Commit d1eb351

Browse files
committed
feat: cleaned HIR Context out of global scope contained elements
1 parent 52e7053 commit d1eb351

2 files changed

Lines changed: 12 additions & 35 deletions

File tree

compiler/astoir_hir/src/ctx.rs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
33
use std::collections::{HashMap, HashSet};
44

5+
use compiler_global_scope::key::EntryKey;
56
use compiler_typing::tree::Type;
6-
use compiler_utils::{hash::SelfHash, utils::indexed::IndexStorage};
7+
use compiler_utils::hash::SelfHash;
78
use diagnostics::{
89
DiagnosticResult, DiagnosticSpanOrigin,
9-
builders::{make_cannot_find_func, make_cannot_find_var, make_doesnt_exist_in_era},
10+
builders::{make_cannot_find_var, make_doesnt_exist_in_era},
1011
};
1112

12-
use crate::{nodes::HIRNode, scope::HIRGlobalScopeStorage, structs::HIRStructContainer};
13+
use crate::{nodes::HIRNode, scope::HIRGlobalScopeStorage};
1314

1415
pub type HIRFunction = (Option<Type>, Vec<(u64, Type)>, String);
1516
pub type HIRFunctionImpl = (HIRBranchedContext, Box<HIRNode>);
@@ -274,11 +275,6 @@ pub struct HIRBranchedVariable {
274275

275276
#[derive(Debug)]
276277
pub struct HIRContext {
277-
pub functions: IndexStorage<HIRFunction>,
278-
pub function_declarations: Vec<Option<Box<HIRNode>>>,
279-
pub function_contexts: Vec<Option<HIRBranchedContext>>,
280-
pub static_variables: IndexStorage<Type>,
281-
pub struct_func_impls: HashMap<usize, HIRStructContainer>,
282278
pub global_scope: HIRGlobalScopeStorage,
283279
}
284280

@@ -291,25 +287,9 @@ pub enum VariableKind {
291287
impl HIRContext {
292288
pub fn new() -> Self {
293289
return HIRContext {
294-
functions: IndexStorage::new(),
295-
static_variables: IndexStorage::new(),
296-
function_contexts: vec![],
297-
function_declarations: vec![],
298-
struct_func_impls: HashMap::new(),
299290
global_scope: HIRGlobalScopeStorage::new(),
300291
};
301292
}
302-
303-
pub fn translate_function<K: DiagnosticSpanOrigin>(
304-
&self,
305-
func_hash: u64,
306-
origin: &K,
307-
) -> DiagnosticResult<usize> {
308-
return match self.functions.get_index(func_hash) {
309-
Some(v) => Ok(v),
310-
None => return Err(make_cannot_find_func(origin, &func_hash).into()),
311-
};
312-
}
313293
}
314294

315295
pub fn get_variable<K: DiagnosticSpanOrigin>(
@@ -328,15 +308,12 @@ pub fn get_variable<K: DiagnosticSpanOrigin>(
328308
));
329309
}
330310

331-
match context.static_variables.get_index(hash) {
332-
Some(v) => {
333-
return Ok((
334-
VariableKind::STATIC,
335-
context.static_variables.vals[v].clone(),
336-
v,
337-
));
338-
}
311+
let name = EntryKey { name_hash: hash };
312+
313+
let ind = context.global_scope.scope.value_to_ind
314+
[&context.global_scope.get_base(name.clone(), origin)?];
315+
316+
let t = context.global_scope.get_static_variable(name, origin)?;
339317

340-
None => return Err(make_cannot_find_var(origin, &hash).into()),
341-
};
318+
Ok((VariableKind::STATIC, t, ind))
342319
}

compiler/compiler_global_scope/src/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::hash::Hash;
22

33
/// Represents a key to a global storage entry. Potentially allows for namespaces later on
4-
#[derive(Debug)]
4+
#[derive(Debug, Clone)]
55
pub struct EntryKey {
66
pub name_hash: u64,
77
}

0 commit comments

Comments
 (0)