test: group examples into per-category folders

Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
This commit is contained in:
agra
2026-06-21 14:41:34 +03:00
parent 6d1409bc1f
commit 66bdc70bf1
3357 changed files with 456 additions and 363 deletions

View File

@@ -0,0 +1,26 @@
// PLAN-HTTPZ C2: an sx `abi(.c)` function passes by name as a
// typed C function pointer — libc qsort drives an sx comparator.
#import "modules/std.sx";
clib :: #library "c";
qsort :: (base: [*]u8, nel: usize, width: usize, compar: (*void, *void) -> i32 abi(.c)) extern clib;
cmp_i32 :: (a: *void, b: *void) -> i32 abi(.c) {
pa : *i32 = xx a;
pb : *i32 = xx b;
if pa.* < pb.* { return -1; }
if pa.* > pb.* { return 1; }
return 0;
}
main :: () -> i32 {
arr : [5]i32 = .[ 4, 1, 5, 2, 3 ];
qsort(xx @arr[0], 5, 4, cmp_i32);
i := 0;
while i < 5 {
if arr[i] != cast(i32)(i + 1) { print("not sorted at {}\n", i); return 1; }
i += 1;
}
print("qsort via sx comparator ok\n");
return 0;
}

View File

@@ -0,0 +1,29 @@
// PLAN-HTTPZ C2: the C->sx re-entry contract. A real OS thread enters
// sx through a `abi(.c)` entry (which has NO implicit context),
// fabricates its own Context via `push Context.{ allocator = xx gpa }`,
// and calls default-conv sx code that allocates through it.
#import "modules/std.sx";
clib :: #library "c";
pthread_create :: (thread: *usize, attr: *void, start: (*void) -> *void abi(.c), arg: *void) -> i32 extern clib;
pthread_join :: (thread: usize, retval: **void) -> i32 extern clib;
entry :: (arg: *void) -> *void abi(.c) {
p : *i64 = xx arg;
gpa := GPA.init();
push Context.{ allocator = xx gpa } {
s := concat("th", "read"); // allocate through the thread's OWN context
if s.len == 6 { p.* = p.* * 2; }
}
return null;
}
main :: () -> i32 {
v : i64 = 21;
th : usize = 0;
if pthread_create(@th, null, entry, xx @v) != 0 { print("create failed\n"); return 1; }
pthread_join(th, null);
if v != 42 { print("wrong result: {}\n", v); return 1; }
print("pthread into sx ok: {}\n", v);
return 0;
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@
qsort via sx comparator ok

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@
pthread into sx ok: 42