ir
This commit is contained in:
24
examples/test_proto.sx
Normal file
24
examples/test_proto.sx
Normal file
@@ -0,0 +1,24 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
Point :: struct { x: s32; y: s32; }
|
||||
|
||||
Eq :: protocol {
|
||||
eq :: (other: Self) -> bool;
|
||||
}
|
||||
|
||||
impl Eq for Point {
|
||||
eq :: (self: *Point, other: Point) -> bool {
|
||||
self.x == other.x and self.y == other.y;
|
||||
}
|
||||
}
|
||||
|
||||
are_equal :: ($T: Type/Eq, a: T, b: T) -> bool {
|
||||
a.eq(b);
|
||||
}
|
||||
|
||||
main :: () {
|
||||
p1 := Point.{ x = 1, y = 2 };
|
||||
p2 := Point.{ x = 1, y = 2 };
|
||||
p3 := Point.{ x = 3, y = 4 };
|
||||
print("P6.1: {} {}\n", are_equal(p1, p2), are_equal(p1, p3));
|
||||
}
|
||||
Reference in New Issue
Block a user