test(ffi-linkage): lock postfix extern (jni) + export (objc defined) aggregates (Phase 3.1)
This commit is contained in:
41
examples/1349-ffi-objc-export-class.sx
Normal file
41
examples/1349-ffi-objc-export-class.sx
Normal 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
|
||||||
|
}
|
||||||
15
examples/1426-ffi-jni-extern-class.sx
Normal file
15
examples/1426-ffi-jni-extern-class.sx
Normal 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
|
||||||
|
}
|
||||||
1
examples/expected/1349-ffi-objc-export-class.exit
Normal file
1
examples/expected/1349-ffi-objc-export-class.exit
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
0
examples/expected/1349-ffi-objc-export-class.stderr
Normal file
0
examples/expected/1349-ffi-objc-export-class.stderr
Normal file
1
examples/expected/1349-ffi-objc-export-class.stdout
Normal file
1
examples/expected/1349-ffi-objc-export-class.stdout
Normal file
@@ -0,0 +1 @@
|
|||||||
|
counter: 2
|
||||||
1
examples/expected/1426-ffi-jni-extern-class.exit
Normal file
1
examples/expected/1426-ffi-jni-extern-class.exit
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
0
examples/expected/1426-ffi-jni-extern-class.stderr
Normal file
0
examples/expected/1426-ffi-jni-extern-class.stderr
Normal file
1
examples/expected/1426-ffi-jni-extern-class.stdout
Normal file
1
examples/expected/1426-ffi-jni-extern-class.stdout
Normal file
@@ -0,0 +1 @@
|
|||||||
|
parse-only ok
|
||||||
Reference in New Issue
Block a user