wasm shell + destructuring

This commit is contained in:
agra
2026-03-03 13:21:54 +02:00
parent 6c5672c7df
commit 004aff5f67
18 changed files with 219 additions and 32 deletions

View File

@@ -296,6 +296,13 @@ Builder :: struct {
}
}
// Global variable for address-of test
g_smoke_val : s32 = 42;
write_to_ptr :: (p: *s32) {
p.* = 99;
}
main :: () {
// ========================================================
@@ -724,6 +731,10 @@ END;
print("str-suffix: {}\n", msg[6..]);
// --- Pointers ---
// Address-of global variable
write_to_ptr(@g_smoke_val);
print("global-addr-of: {}\n", g_smoke_val);
pv := Point.{ 10, 20 };
ptr := @pv;
print("deref: {}\n", ptr.*);
@@ -750,6 +761,13 @@ END;
print("ptr2==null: {}\n", np2 == null);
print("ptr2!=null: {}\n", np2 != null);
// Pointer to nested struct field
Inner3 :: struct { a: f32; b: f32; c: f32; }
Outer3 :: struct { key: s32; inner: Inner3; }
out3 := Outer3.{ key = 42, inner = Inner3.{ a = 1.0, b = 2.0, c = 3.0 } };
ip3 := @out3.inner;
print("ptr-nested-field: {} {} {}\n", ip3.a, ip3.b, ip3.c);
// --- Vectors ---
vc := vec3(1, 3, 2);
print("vec-construct: {}\n", vc);
@@ -1291,6 +1309,34 @@ END;
print("3-way: {} {} {}\n", ra, rb, rc);
}
// --- Tuple destructuring ---
print("--- destructure ---\n");
// Basic tuple destructuring
{
da, db := (10, 20);
print("basic: {} {}\n", da, db);
}
// Destructure from function return
{
dswap :: (a: s64, b: s64) -> (s64, s64) { (b, a); }
dx, dy := dswap(1, 2);
print("fn: {} {}\n", dx, dy);
}
// Discard with _
{
_, dsecond := (100, 200);
print("discard: {}\n", dsecond);
}
// Three elements
{
da3, db3, dc3 := (1, 2, 3);
print("triple: {} {} {}\n", da3, db3, dc3);
}
// ========================================================
// 15. FOREIGN FUNCTION BINDING
// ========================================================