feat: add method call support and analyzeFull
- Add analyzeFull() to return Sema context with method table - Improve method call desugaring: obj.method() → Type_method(obj) - Search methodTable by method name when type inference fails - Add methods.bux example demonstrating struct with extend blocks - Use analyzeFull in cli.nim for proper method resolution
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Methods - Struct with methods using extend
|
||||
extern func Std_Io_PrintLine(s: String);
|
||||
extern func Std_Io_PrintInt(n: int);
|
||||
|
||||
struct Rectangle {
|
||||
width: int;
|
||||
height: int;
|
||||
}
|
||||
|
||||
extend Rectangle {
|
||||
func Area(self: Rectangle) -> int {
|
||||
return self.width * self.height;
|
||||
}
|
||||
|
||||
func Perimeter(self: Rectangle) -> int {
|
||||
return 2 * (self.width + self.height);
|
||||
}
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
let rect: Rectangle = Rectangle { width: 10, height: 5 };
|
||||
|
||||
Std_Io_PrintLine("Rectangle:");
|
||||
Std_Io_PrintLine("Width = ");
|
||||
Std_Io_PrintInt(rect.width);
|
||||
Std_Io_PrintLine("");
|
||||
Std_Io_PrintLine("Height = ");
|
||||
Std_Io_PrintInt(rect.height);
|
||||
Std_Io_PrintLine("");
|
||||
Std_Io_PrintLine("Area = ");
|
||||
Std_Io_PrintInt(rect.Area());
|
||||
Std_Io_PrintLine("");
|
||||
Std_Io_PrintLine("Perimeter = ");
|
||||
Std_Io_PrintInt(rect.Perimeter());
|
||||
Std_Io_PrintLine("");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user