From 52608d5601d266ad30855adb99734d98f936e6dc Mon Sep 17 00:00:00 2001 From: dimgigov Date: Sat, 30 May 2026 23:11:03 +0300 Subject: [PATCH] feat: add enum path expression support in codegen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Support ekPath in lowerExpr for enum variants (Color::Red → Color_Red) - Support module paths (Std::Io::PrintLine → Std_Io_PrintLine) - Add enums.bux example demonstrating enum usage - Enums now compile and run correctly --- examples/enums.bux | 34 ++++++++++++++++++++++++++++++++++ src/hir_lower.nim | 6 ++++++ 2 files changed, 40 insertions(+) create mode 100644 examples/enums.bux diff --git a/examples/enums.bux b/examples/enums.bux new file mode 100644 index 0000000..fd62ac4 --- /dev/null +++ b/examples/enums.bux @@ -0,0 +1,34 @@ +// Enums - Enumeration types +extern func Std_Io_PrintLine(s: String); +extern func Std_Io_PrintInt(n: int); + +enum Color { + Red, + Green, + Blue +} + +func ColorName(c: Color) -> String { + if c == Color::Red { + return "Red"; + } + if c == Color::Green { + return "Green"; + } + if c == Color::Blue { + return "Blue"; + } + return "Unknown"; +} + +func Main() -> int { + let myColor: Color = Color::Green; + + Std_Io_PrintLine("My color is:"); + Std_Io_PrintLine(ColorName(myColor)); + Std_Io_PrintLine("Color value:"); + Std_Io_PrintInt(myColor as int); + Std_Io_PrintLine(""); + + return 0; +} diff --git a/src/hir_lower.nim b/src/hir_lower.nim index 2b26852..0b0a42a 100644 --- a/src/hir_lower.nim +++ b/src/hir_lower.nim @@ -127,6 +127,12 @@ proc lowerExpr(ctx: var LowerCtx, expr: Expr): HirNode = of ekIdent: return hirVar(expr.exprIdent, typ, loc) + of ekPath: + # Handle enum variants: Color::Red → Color_Red + # or module paths: Std::Io::PrintLine → Std_Io_PrintLine + let mangledName = expr.exprPath.join("_") + return hirVar(mangledName, typ, loc) + of ekSelf: return hirSelf(typ, loc)