This commit is contained in:
agra
2026-02-18 13:08:35 +02:00
parent 3c0912a936
commit 2f5eb84259
4 changed files with 267 additions and 15 deletions

View File

@@ -17,7 +17,7 @@ main :: () -> s32 {
addr := SockAddr.{ sin_len = 16, sin_family = 2, sin_port = htons(PORT) };
if bind(fd, addr, 16) < 0 {
if bind(fd, @addr, 16) < 0 {
print("error: bind()\n");
return 1;
}

View File

@@ -78,6 +78,8 @@ vec3 :: (x: f32, y: f32, z: f32) -> Vector(3, f32) {
.[x, y, z];
}
point_sum :: (p: Point) -> s32 { p.x + p.y; }
// #run compile-time constants
CT_VAL :: #run add(10, 15);
CT_MUL :: #run mul(6, 7);
@@ -1106,5 +1108,81 @@ END;
print("local-enum: {}\n", ls);
}
// ========================================================
// 20. UFCS RETURN TYPE INFERENCE
// ========================================================
print("=== 20. UFCS Return Type ===\n");
{
p := Point.{3, 4};
print("direct: {}\n", point_sum(p));
print("ufcs: {}\n", p.point_sum());
}
// ========================================================
// 21. TYPE-NAMED VARIABLES (s2, u8, etc.)
// ========================================================
print("=== 21. Type-Named Vars ===\n");
{
s2 := 42;
print("s2: {}\n", s2);
s2 = s2 + 1;
print("s2+1: {}\n", s2);
}
// ========================================================
// 22. IF-EXPRESSION RETURNING STRUCT
// ========================================================
print("=== 22. If-Struct ===\n");
{
flag := true;
p := if flag { Point.{10, 20}; } else { Point.{30, 40}; };
print("if-struct: {} {}\n", p.x, p.y);
q := if !flag { Point.{10, 20}; } else { Point.{30, 40}; };
print("else-struct: {} {}\n", q.x, q.y);
}
// ========================================================
// 23. NESTED ARRAYS (2D)
// ========================================================
print("=== 23. Nested Arrays ===\n");
{
matrix : [2][3]s32 = .[ .[1, 2, 3], .[4, 5, 6] ];
print("m[0][0]: {}\n", matrix[0][0]);
print("m[0][2]: {}\n", matrix[0][2]);
print("m[1][0]: {}\n", matrix[1][0]);
print("m[1][2]: {}\n", matrix[1][2]);
}
// ========================================================
// 24. STRING COMPARISON
// ========================================================
print("=== 24. String Comparison ===\n");
{
a := "hello";
b := "hello";
c := "world";
print("str-eq: {}\n", a == b);
print("str-neq: {}\n", a != c);
print("str-diff: {}\n", a == c);
empty := "";
print("empty-eq: {}\n", empty == "");
}
// ========================================================
// 25. ARRAY LOOP MUTATION
// ========================================================
print("=== 25. Array Loop Mutation ===\n");
{
arr : [4]s32 = .[0, 0, 0, 0];
i := 0;
while i < 4 {
arr[i] = xx (i + 1);
i += 1;
}
print("loop-fill: {} {} {} {}\n", arr[0], arr[1], arr[2], arr[3]);
arr[2] += 10;
print("compound: {}\n", arr[2]);
}
print("=== DONE ===\n");
}