diff --git a/crates/codegen/src/class_decl.rs b/crates/codegen/src/class_decl.rs index 587e91a..6977125 100644 --- a/crates/codegen/src/class_decl.rs +++ b/crates/codegen/src/class_decl.rs @@ -16,7 +16,7 @@ pub struct ClassProcessedData { items: Vec, methods: Vec>, v_table: Vec, - override_v_table: HashMap>>, + override_v_table: HashMap>>, } impl ClassProcessedData { @@ -64,7 +64,7 @@ impl ClassProcessedData { item: Vec::new(), }) .item - .push(method.item.name.clone()); + .push((method.item.name.clone(), method.item.is_virtual)); } } } @@ -191,13 +191,13 @@ impl ClassProcessedData { .as_ref() .unwrap_or(self.inherits.as_ref().unwrap()) .get_rust(); - for method_ident in &overriden_method_idents.item { + for (method_ident, is_virtual) in &overriden_method_idents.item { cg.add_indentedln(&format!( - "table[{}::__FN_{}] = {}::__m_{} as *const std::ffi::c_void;", + "table[{}::__FN_{}] = {}::{} as *const std::ffi::c_void;", base_class_path, method_ident.0.to_uppercase(), self.self_path.get_rust(), - method_ident.get_rust() + get_virtual_name(method_ident, *is_virtual) )); } } @@ -618,3 +618,11 @@ pub fn get_type_from_path(path: &ExprPath) -> TypeExpr { path.0.last().unwrap().generics.clone(), ) } + +pub fn get_virtual_name(name: &Identifier, is_virtual: bool) -> String { + if is_virtual { + format!("__m_{}", name.get_rust()) + } else { + name.get_rust() + } +} diff --git a/mist-test/src/items/class_test.mist b/mist-test/src/items/class_test.mist index e169947..de58af4 100644 --- a/mist-test/src/items/class_test.mist +++ b/mist-test/src/items/class_test.mist @@ -45,7 +45,7 @@ pub class Dog : Mammal super = Super::new(); } - pub virtual String speak(&self) override(Animal) + pub String speak(&self) override(Animal) { "Woof!".to_string() }