This commit is contained in:
agra
2026-02-18 05:31:54 +02:00
parent ae5e6cd507
commit 3c0912a936
4 changed files with 132 additions and 56 deletions

View File

@@ -1051,5 +1051,60 @@ END;
// Symbol rename: c_abs maps to C's abs()
print("foreign-rename: {}\n", c_abs(xx -42));
// ========================================================
// 16. COMPOUND ASSIGNMENT TYPE CONVERSION
// ========================================================
print("=== 16. Compound Assign ===\n");
{
ca_a : f64 = 10.0;
ca_b : f32 = 3.0;
ca_a += ca_b;
print("f64+=f32: {}\n", ca_a);
ca_c : s64 = 100;
ca_d : s32 = 7;
ca_c -= ca_d;
print("s64-=s32: {}\n", ca_c);
}
// ========================================================
// 17. SLICE/ARRAY .ptr ACCESS
// ========================================================
print("=== 17. Slice Ptr ===\n");
{
sarr : [5]s32 = .[10, 20, 30, 40, 50];
ssl := sarr[1..4];
sp := ssl.ptr;
print("sl-ptr[0]: {}\n", sp[0]);
print("sl-ptr[1]: {}\n", sp[1]);
}
// ========================================================
// 18. ARRAYS OF USER-DEFINED TYPES
// ========================================================
print("=== 18. Array of Structs ===\n");
{
spts : [2]Point = .[Point.{1, 2}, Point.{3, 4}];
spt2 := spts[1];
print("arr-struct-x: {}\n", spt2.x);
for spts: (it) {
print("for-struct: {}\n", it);
}
}
// ========================================================
// 19. LOCAL FUNCTION RETURNING STRUCT/ENUM
// ========================================================
print("=== 19. Local Fn Return ===\n");
{
local_pt :: () -> Point { Point.{42, 99}; }
lp := local_pt();
print("local-struct: {} {}\n", lp.x, lp.y);
local_sh :: () -> Shape { .circle(2.5); }
ls := local_sh();
print("local-enum: {}\n", ls);
}
print("=== DONE ===\n");
}