Fix typedefinition in scope

This commit is contained in:
Sofia 2025-07-23 15:34:01 +03:00
parent 82758ae333
commit 8b79959288
7 changed files with 10 additions and 4 deletions

View File

@ -1,8 +1,9 @@
// Arithmetic, function calls and imports!
import std::allocate;
fn main() -> u8 {
let mut ptr = malloc(4);
let mut ptr = allocate(4);
ptr[0] = 5;

View File

@ -50,6 +50,7 @@ impl ast::Module {
block.into_mir(module_id),
(*range).as_meta(module_id),
),
source: module_id,
};
functions.push(def);
}
@ -70,6 +71,7 @@ impl ast::Module {
.map(|p| (p.0, p.1 .0.into_mir(module_id)))
.collect(),
kind: mir::FunctionDefinitionKind::Extern(false),
source: module_id,
};
functions.push(def);
}

View File

@ -326,7 +326,7 @@ impl Display for Metadata {
impl Display for SourceModuleId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Mod {}", self.0)
write!(f, "{}", self.0)
}
}
@ -364,7 +364,7 @@ impl Display for TypeKind {
Display::fmt(len, f)?;
f.write_char(']')
}
TypeKind::CustomType(CustomTypeKey(name, mod_id)) => write!(f, "{}:{}", mod_id, name),
TypeKind::CustomType(CustomTypeKey(name, mod_id)) => write!(f, "{}@{}", name, mod_id),
TypeKind::Borrow(type_kind, false) => {
write!(f, "&")?;
Display::fmt(type_kind, f)

View File

@ -320,6 +320,7 @@ impl<'map> Pass for LinkerPass<'map> {
return_type: return_type,
parameters: param_tys,
kind: super::FunctionDefinitionKind::Extern(true),
source: imported_mod_id,
});
}
}

View File

@ -293,6 +293,7 @@ pub struct FunctionDefinition {
pub return_type: TypeKind,
pub parameters: Vec<(String, TypeKind)>,
pub kind: FunctionDefinitionKind,
pub source: SourceModuleId,
}
#[derive(Debug)]

View File

@ -295,7 +295,7 @@ impl Module {
scope
.types
.set(
CustomTypeKey(typedef.name.clone(), self.module_id),
CustomTypeKey(typedef.name.clone(), typedef.source_module),
typedef.clone(),
)
.ok();

View File

@ -322,6 +322,7 @@ impl Expression {
// Check that the resolved type is at least a struct, no
// need for further resolution.
let kind = expr_ty.resolve_weak().unwrap();
dbg!(&state.scope);
match kind {
CustomType(key) => {
let struct_ty = state