Files
dimgigov 92c5cd59f5 refactor: migrate examples to import Std::Io instead of raw extern func
- Create stdlib/Std/Io.bux with extern func declarations
- Rename C shim functions to short names (PrintLine, PrintInt, etc.)
- Update all 9 examples to use import Std::Io::{PrintLine, PrintInt};
- Remove manual extern func Std_Io_* declarations from examples
2026-05-31 02:01:28 +03:00

39 lines
792 B
Plaintext

// Methods - Struct with methods using extend
import Std::Io::{PrintLine, PrintInt};
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 };
PrintLine("Rectangle:");
PrintLine("Width = ");
PrintInt(rect.width);
PrintLine("");
PrintLine("Height = ");
PrintInt(rect.height);
PrintLine("");
PrintLine("Area = ");
PrintInt(rect.Area());
PrintLine("");
PrintLine("Perimeter = ");
PrintInt(rect.Perimeter());
PrintLine("");
return 0;
}