diff --git a/examples/ptr.reid b/examples/ptr.reid index d694349..ef9f616 100644 --- a/examples/ptr.reid +++ b/examples/ptr.reid @@ -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; diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index 4bebf42..8ebd252 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -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); } diff --git a/reid/src/mir/fmt.rs b/reid/src/mir/fmt.rs index 9cbba3b..53e5417 100644 --- a/reid/src/mir/fmt.rs +++ b/reid/src/mir/fmt.rs @@ -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) diff --git a/reid/src/mir/linker.rs b/reid/src/mir/linker.rs index 14e5e13..5252432 100644 --- a/reid/src/mir/linker.rs +++ b/reid/src/mir/linker.rs @@ -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, }); } } diff --git a/reid/src/mir/mod.rs b/reid/src/mir/mod.rs index 99fea98..1372bbd 100644 --- a/reid/src/mir/mod.rs +++ b/reid/src/mir/mod.rs @@ -293,6 +293,7 @@ pub struct FunctionDefinition { pub return_type: TypeKind, pub parameters: Vec<(String, TypeKind)>, pub kind: FunctionDefinitionKind, + pub source: SourceModuleId, } #[derive(Debug)] diff --git a/reid/src/mir/pass.rs b/reid/src/mir/pass.rs index db63202..5409d80 100644 --- a/reid/src/mir/pass.rs +++ b/reid/src/mir/pass.rs @@ -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(); diff --git a/reid/src/mir/typeinference.rs b/reid/src/mir/typeinference.rs index 35bf42f..4b729b8 100644 --- a/reid/src/mir/typeinference.rs +++ b/reid/src/mir/typeinference.rs @@ -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