Skip to content

Commit 7276b82

Browse files
committed
feat: cleaned nodes to use global scope
1 parent d1eb351 commit 7276b82

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

compiler/astoir_hir/src/nodes.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::collections::HashMap;
44

55
use compiler_typing::{
6-
enums::RawEnumTypeContainer, raw::RawType, references::TypeReference,
6+
TypedGlobalScopeEntry, enums::RawEnumTypeContainer, raw::RawType, references::TypeReference,
77
structs::RawStructTypeContainer, transmutation::array::can_transmute_inner, tree::Type,
88
};
99
use compiler_utils::{
@@ -13,7 +13,7 @@ use compiler_utils::{
1313
};
1414
use diagnostics::{
1515
DiagnosticSpanOrigin,
16-
builders::{make_diff_type, make_diff_type_val},
16+
builders::{make_diff_type, make_diff_type_val, make_expected_simple_error_originless},
1717
diagnostic::{Diagnostic, Span, SpanKind, SpanPosition},
1818
unsure_panic,
1919
};
@@ -416,7 +416,9 @@ impl HIRNode {
416416
match &self.kind {
417417
HIRNodeKind::VariableReference { index, is_static } => {
418418
if *is_static {
419-
return Some(context.static_variables.vals[*index].clone());
419+
return Some(
420+
context.global_scope.scope.entries[*index].as_static_variable_unsafe(),
421+
);
420422
}
421423

422424
return Some(curr_ctx.variables[*index].variable_type.clone());
@@ -490,9 +492,30 @@ impl HIRNode {
490492
func_name,
491493
arguments: _,
492494
} => {
493-
let f = context.functions.vals[*func_name].0.clone();
495+
//let f = context.functions.vals[*func_name].0.clone();
496+
let ind = match &context.global_scope.scope.entries[*func_name].entry_type {
497+
TypedGlobalScopeEntry::Function {
498+
descriptor_ind,
499+
impl_ind: _,
500+
} => descriptor_ind,
501+
TypedGlobalScopeEntry::ImplLessFunction(ind) => ind,
502+
TypedGlobalScopeEntry::StructFunction {
503+
descriptor_ind,
504+
impl_ind: _,
505+
struct_type: _,
506+
} => descriptor_ind,
507+
508+
_ => {
509+
make_expected_simple_error_originless(
510+
&"function".to_string(),
511+
&context.global_scope.scope.entries[*func_name].entry_type,
512+
);
513+
514+
return None;
515+
}
516+
};
494517

495-
return f;
518+
return context.global_scope.descriptors[*ind].clone().0;
496519
}
497520

498521
_ => return None,

compiler/diagnostics/src/builders.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ pub fn make_expected_simple_error<K: DiagnosticSpanOrigin, E: Display, G: Displa
3131
)
3232
}
3333

34+
pub fn make_expected_simple_error_originless<E: Display, G: Display>(
35+
expected: &E,
36+
got: &G,
37+
) -> Diagnostic {
38+
let main_span = Span::make_primary(get_current_diagnostic_pos(), None);
39+
40+
Diagnostic::new_base(
41+
Level::Error,
42+
EXPECTED_TOKEN.0,
43+
format!("expected {} but got {}", expected, got),
44+
main_span,
45+
vec![],
46+
vec![],
47+
vec![],
48+
)
49+
}
50+
3451
pub fn make_unexpected_simple_error<K: DiagnosticSpanOrigin, E: Display>(
3552
origin: &K,
3653
got: &E,

0 commit comments

Comments
 (0)