b59e852330
- 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
39 lines
921 B
Plaintext
39 lines
921 B
Plaintext
// 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;
|
|
}
|