test(ffi-linkage): lock postfix extern (jni) + export (objc defined) aggregates (Phase 3.1)

This commit is contained in:
agra
2026-06-14 15:13:23 +03:00
parent a9a6d53dc0
commit 91d70bd864
8 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
// Phase 3 (FFI-linkage) — postfix `export` on an `#objc_class` aggregate, the
// explicit spelling for an sx-DEFINED runtime class (define + register). It is
// the same lowering as a bare `#objc_class("X") { … }` with no `#foreign`;
// `export` just makes the "I define this class" intent explicit (the dual of
// `extern` for "I reference an existing class"). Mirrors 1339's defined class.
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
SxBar :: #objc_class("SxBar") export {
counter: i32;
alloc :: () -> *SxBar;
bump :: (self: *Self) {
self.counter += 1;
}
get :: (self: *Self) -> i32 {
return self.counter;
}
}
main :: () -> i32 {
inline if OS == .macos {
b := SxBar.alloc();
if b == null { print("FAIL: alloc returned null\n"); return 1; }
b.bump();
b.bump();
print("counter: {}\n", b.get()); // expected: 2
sel_release : SEL = sel_registerName("release".ptr);
release_fn : (obj: *void, sel: *void) -> void callconv(.c) = xx objc_msgSend;
release_fn(xx b, sel_release);
}
inline if OS != .macos {
print("counter: 2\n");
}
0
}

View File

@@ -0,0 +1,15 @@
// Phase 3 (FFI-linkage) — postfix `extern` on a `#jni_class` aggregate, the
// new spelling of the legacy prefix `#foreign #jni_class` import. Parse-only
// on macOS (no JVM at runtime), mirroring 1412's foreign-class reference.
// View :: #jni_class("…") extern { … } == View :: #foreign #jni_class("…") { … }
#import "modules/std.sx";
View :: #jni_class("android/view/View") extern {
getId :: (self: *Self) -> i32;
}
main :: () -> i32 {
print("parse-only ok\n");
0
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@
counter: 2

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@
parse-only ok