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:
@@ -0,0 +1,45 @@
|
||||
// Phase 1.1 — the compiler-internal heap-copy that backs `xx <rvalue>`
|
||||
// protocol erasure must dispatch through `context.allocator`, not call
|
||||
// libc malloc directly. So when a `push Context.{ allocator = tracer }`
|
||||
// block is active, a `xx StructLiteral.{}` inside it MUST be allocated
|
||||
// by the tracker.
|
||||
//
|
||||
// Note: `xx` only heap-copies for RVALUES (struct literals, call results).
|
||||
// `xx <lvalue>` (an identifier, field access, index, or deref) borrows
|
||||
// the operand's storage, so it never allocates and never reaches this
|
||||
// path. See specs.md §3 — Protocol value ownership and lifetime.
|
||||
#import "modules/std.sx";
|
||||
#import "modules/std/mem.sx"; // `Allocator` is non-transitive: name it, import it.
|
||||
|
||||
Tracer :: struct {
|
||||
count: i64;
|
||||
|
||||
init :: () -> *Tracer {
|
||||
t : *Tracer = xx libc_malloc(size_of(Tracer));
|
||||
t.count = 0;
|
||||
t
|
||||
}
|
||||
}
|
||||
|
||||
impl Allocator for Tracer {
|
||||
alloc_bytes :: (self: *Tracer, size: i64) -> *void {
|
||||
self.count += 1;
|
||||
return libc_malloc(size);
|
||||
}
|
||||
dealloc_bytes :: (self: *Tracer, ptr: *void) {
|
||||
libc_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
ByValue :: struct { x: i64; y: i64; }
|
||||
|
||||
main :: () -> i32 {
|
||||
tracer := Tracer.init();
|
||||
push Context.{ allocator = xx tracer, data = null } {
|
||||
// Struct-literal operand: rvalue → heap-copy through context.allocator.
|
||||
ignore : Allocator = xx ByValue.{ x = 1, y = 2 };
|
||||
_ = ignore;
|
||||
}
|
||||
print("Tracer.count = {}\n", tracer.count);
|
||||
0
|
||||
}
|
||||
Reference in New Issue
Block a user