Files
sx/examples/1315-ffi-objc-self-class-accessor.sx
agra d8076b9333 lang: rename signed integer types sN -> iN
Surface rename of the signed integer family: s1..s64 become i1..i64
(u1..u64, usize, isize unchanged). 'string' keeps the s-prefix arm in
name classification; width parsing moves to the i-prefix arm next to
isize.

Internal TypeId tags follow the surface (.s8/.s16/.s32/.s64 ->
.i8/.i16/.i32/.i64), as do mono-key mangle fragments (ptr_i64,
tu_i64_bool) and all display/diagnostic formatting (i{d}).

Migrated in the same sweep: stdlib + examples + issue repros + FFI C
companions (shared symbol names like ffi_id_i64), expected
stdout/stderr/ir snapshots, specs.md, readme.md, CLAUDE.md/AGENTS.md,
implementation_plan.md, docs/, issue writeups. Vendored stb_image and
historical flow state left untouched.

zig build test: 426/426; examples suite: 595/595.
2026-06-12 09:31:53 +03:00

49 lines
1.5 KiB
Plaintext

// M1.3 — `obj.class` accessor on Obj-C pointers.
//
// Any Obj-C-class pointer (foreign or sx-defined) can be probed
// for its runtime class object via `obj.class`. Lowers to
// `object_getClass(obj)`. Returns `Class` (alias for *void —
// parameterized `Class(T)` covariance is M1.1.b).
//
// Verifies both shapes:
// 1. (*SxFoo).class — sx-defined class. Returns the SxFoo Class.
// 2. (*NSObject).class — foreign class via stdlib. Returns NSObject's
// Class.
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
NSObjectFwd :: #foreign #objc_class("NSObject") {
alloc :: () -> *NSObjectFwd;
init :: (self: *NSObjectFwd) -> *NSObjectFwd;
}
SxFoo :: #objc_class("SxFoo") {
counter: i32;
alloc :: () -> *SxFoo;
bump :: (self: *Self) { self.counter += 1; }
}
main :: () -> i32 {
inline if OS == .macos {
// sx-defined class round-trip.
f := SxFoo.alloc();
cls_f : Class = f.class;
expected_f : Class = objc_getClass("SxFoo".ptr);
if cls_f != expected_f { print("FAIL: SxFoo.class mismatch\n"); return 1; }
// foreign class round-trip.
nso := NSObjectFwd.alloc().init();
cls_n : Class = nso.class;
expected_n : Class = objc_getClass("NSObject".ptr);
if cls_n != expected_n { print("FAIL: NSObject.class mismatch\n"); return 1; }
print("class accessor: ok\n");
}
inline if OS != .macos {
print("class accessor: ok\n");
}
0
}