From 5916daaada5153a904029e48ec1f5119a15a1b56 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sun, 10 May 2026 04:01:54 +0200 Subject: [PATCH] Fixed class lifetimes --- mist-test/src/{core => }/app.mist | 0 mist-test/src/core/mod.mist | 5 --- mist-test/src/{core => }/event.mist | 0 mist-test/src/{core => }/logger.mist | 0 mist-test/src/main.mist | 8 +++- mist-test/src/{core => }/plugin.mist | 0 mist-test/src/{core => }/task.mist | 0 src/codegen.rs | 63 ++++++++++++++++++---------- 8 files changed, 47 insertions(+), 29 deletions(-) rename mist-test/src/{core => }/app.mist (100%) delete mode 100644 mist-test/src/core/mod.mist rename mist-test/src/{core => }/event.mist (100%) rename mist-test/src/{core => }/logger.mist (100%) rename mist-test/src/{core => }/plugin.mist (100%) rename mist-test/src/{core => }/task.mist (100%) diff --git a/mist-test/src/core/app.mist b/mist-test/src/app.mist similarity index 100% rename from mist-test/src/core/app.mist rename to mist-test/src/app.mist diff --git a/mist-test/src/core/mod.mist b/mist-test/src/core/mod.mist deleted file mode 100644 index 9de044b..0000000 --- a/mist-test/src/core/mod.mist +++ /dev/null @@ -1,5 +0,0 @@ -mod app; -mod task; -mod plugin; -mod logger; -mod event; \ No newline at end of file diff --git a/mist-test/src/core/event.mist b/mist-test/src/event.mist similarity index 100% rename from mist-test/src/core/event.mist rename to mist-test/src/event.mist diff --git a/mist-test/src/core/logger.mist b/mist-test/src/logger.mist similarity index 100% rename from mist-test/src/core/logger.mist rename to mist-test/src/logger.mist diff --git a/mist-test/src/main.mist b/mist-test/src/main.mist index 36a5934..688fbde 100644 --- a/mist-test/src/main.mist +++ b/mist-test/src/main.mist @@ -1,6 +1,10 @@ -mod core; +mod app; +mod task; +mod plugin; +mod logger; +mod event; -use ; +use ; // use ; // use ; diff --git a/mist-test/src/core/plugin.mist b/mist-test/src/plugin.mist similarity index 100% rename from mist-test/src/core/plugin.mist rename to mist-test/src/plugin.mist diff --git a/mist-test/src/core/task.mist b/mist-test/src/task.mist similarity index 100% rename from mist-test/src/core/task.mist rename to mist-test/src/task.mist diff --git a/src/codegen.rs b/src/codegen.rs index 532f069..437a99f 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -1,7 +1,7 @@ use parser::ast::{ - Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generics, Identifier, Literal, - Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind, TypeExpr, - TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility, + Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generic, Generics, Identifier, + Literal, Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind, + TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility, }; // --------------------------------------------------------------------------- @@ -383,7 +383,20 @@ impl ToRust for TopLevelKind { cg.addln("}\n"); // Constructor - cg.addln(&format!("impl {} {{", name.get_rust())); + cg.addln(&format!( + "impl{} {}{} {{", + generics.get_rust(), + name.get_rust(), + format!( + "<{}>", + generics + .0 + .iter() + .map(|v| (false, v).get_rust()) + .collect::>() + .join(", ") + ) + )); cg.indent += 1; let params_str = constructor @@ -725,24 +738,7 @@ impl GetRust for Generics { "<{}>", self.0 .iter() - .map(|generic| match generic { - parser::ast::Generic::Lifetime(name) => format!("'{}", name.get_rust()), - parser::ast::Generic::Type(name, requirements) => { - name.get_rust() - + &(if requirements.len() == 0 { - String::new() - } else { - format!( - ": {}", - requirements - .iter() - .map(TypeExpr::get_rust) - .collect::>() - .join("+") - ) - }) - } - }) + .map(|v| (true, v).get_rust()) .collect::>() .join(", ") ) @@ -750,6 +746,29 @@ impl GetRust for Generics { } } +impl GetRust for (bool, &Generic) { + fn get_rust(&self) -> String { + match &self.1 { + Generic::Lifetime(name) => format!("'{}", name.get_rust()), + Generic::Type(name, requirements) => { + name.get_rust() + + &(if !self.0 && requirements.len() == 0 { + String::new() + } else { + format!( + ": {}", + requirements + .iter() + .map(TypeExpr::get_rust) + .collect::>() + .join("+") + ) + }) + } + } + } +} + pub fn get_static_type_path(path: &Path) -> String { let rust_path = path.get_rust();