diff --git a/examples/triple_import_main.reid b/examples/triple_import_main.reid index e327efa..d2660d9 100644 --- a/examples/triple_import_main.reid +++ b/examples/triple_import_main.reid @@ -1,4 +1,4 @@ import triple_import_vec2::Vec2; import triple_import_ship::Ship; -fn main() -> i32 { return 0; } +fn main() -> i32 { return 0; } \ No newline at end of file diff --git a/examples/triple_import_ship.reid b/examples/triple_import_ship.reid index 49ade80..58c3fad 100644 --- a/examples/triple_import_ship.reid +++ b/examples/triple_import_ship.reid @@ -1,11 +1,3 @@ - import triple_import_vec2::Vec2; -struct Ship { position: Vec2 } -impl Ship { - pub fn new() -> Ship { - Ship { - position: Vec2 {x: 15, y: 16} - } - } -} \ No newline at end of file +struct Ship { position: Vec2 } \ No newline at end of file diff --git a/examples/triple_import_vec2.reid b/examples/triple_import_vec2.reid index 8cc75b3..9d430fb 100644 --- a/examples/triple_import_vec2.reid +++ b/examples/triple_import_vec2.reid @@ -1,2 +1,6 @@ -struct Vec2 { x: u32, y: u32 } \ No newline at end of file +struct Vec2 { x: f32, y: f32 } + +impl Vec2 { + pub fn zero() -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } +} diff --git a/reid/src/codegen/mod.rs b/reid/src/codegen/mod.rs index b00401c..1f4dd05 100644 --- a/reid/src/codegen/mod.rs +++ b/reid/src/codegen/mod.rs @@ -62,10 +62,12 @@ impl mir::Context { let mut modules = HashMap::new(); let mut modules_sorted = self.modules.iter().map(|(_, m)| m).collect::>(); modules_sorted.sort_by(|m1, m2| m2.module_id.cmp(&m1.module_id)); + for module in &modules_sorted { + modules.insert(module.module_id, *module); + } for module in &modules_sorted { let codegen = module.codegen(context, modules.clone())?; - modules.insert(module.module_id, codegen); } Ok(CodegenContext { context }) } @@ -128,7 +130,7 @@ impl mir::Module { fn codegen<'ctx>( &'ctx self, context: &'ctx Context, - modules: HashMap>, + modules: HashMap, ) -> Result, ErrorKind> { let mut module = context.module(&self.name, self.is_main); let tokens = &self.tokens; @@ -321,11 +323,12 @@ impl mir::Module { .collect(); let is_main = self.is_main && function.name == "main"; - let module_prefix = if let Some(module) = function.source { - if module == self.module_id { + let module_prefix = if let Some(module_id) = function.source { + if module_id == self.module_id { format!("reid.{}.", self.name) } else { - format!("reid.{}.", modules.get(&module).unwrap().name) + dbg!(self.module_id, module_id); + format!("reid.{}.", modules.get(&module_id).unwrap().name) } } else { format!("reid.intrinsic.") diff --git a/reid/src/codegen/scope.rs b/reid/src/codegen/scope.rs index 4e8fcd5..bc62913 100644 --- a/reid/src/codegen/scope.rs +++ b/reid/src/codegen/scope.rs @@ -11,6 +11,7 @@ use crate::{ codegen::intrinsics::LLVMIntrinsicKind, lexer::FullToken, mir::{ + self, pass::{AssociatedFunctionKey, BinopKey}, CustomTypeKey, FunctionParam, Metadata, SourceModuleId, TypeDefinition, TypeKind, }, @@ -20,7 +21,7 @@ use super::{allocator::Allocator, ErrorKind, IntrinsicFunction, ModuleCodegen}; pub struct Scope<'ctx, 'scope> { pub(super) context: &'ctx Context, - pub(super) modules: &'scope HashMap>, + pub(super) modules: &'scope HashMap, pub(super) tokens: &'ctx Vec, pub(super) module: &'ctx Module<'ctx>, pub(super) module_id: SourceModuleId, diff --git a/reid/src/codegen/util.rs b/reid/src/codegen/util.rs index 64b50f6..95b61da 100644 --- a/reid/src/codegen/util.rs +++ b/reid/src/codegen/util.rs @@ -124,7 +124,7 @@ impl TypeKind { type_map: &HashMap, local_mod: SourceModuleId, tokens: &Vec, - modules: &HashMap, + modules: &HashMap, ) -> DebugTypeValue { if let Some(ty) = debug_types.get(self) { return *ty;