refactor(ffi-linkage): Phase 7.4 — migrate straggler examples #foreign→extern
16 fn/global examples across categories (0415/0602/0603/1024/1025/1605/1607-1609/ 1611/1616/1619/1622/1628/1635/1636): bare '#foreign'→'extern'. All cls=0 (no class forms). Marker'd ones (1605/1609/1611 + the rest) corpus-validated; the 3 unmarked uikit importers (1607/1608/1616) verified byte-identical via 'sx ir' probes. Empty snapshot diff; suite green (647 corpus / 444 unit, 0 failed). LEFT comment-only/provenance #foreign (0716/0729 + issues/0030-extern-global + extern-test files 1223-1231/1332/1348/1349/1426) and the keep-list (identity ffi-foreign-* + foreign-asserting diagnostics 1172/1174/1219/1228/1620) for Phase 8.
This commit is contained in:
@@ -198,7 +198,7 @@ sm_first :: (a: i32, b: i32) -> (i32, !) {
|
||||
// --- Foreign function binding ---
|
||||
libc :: #library "c";
|
||||
|
||||
c_abs :: (n: i32) -> i32 #foreign libc "abs";
|
||||
c_abs :: (n: i32) -> i32 extern libc "abs";
|
||||
|
||||
// --- Protocol declarations (Phase 1: static dispatch only) ---
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#import "modules/build.sx";
|
||||
|
||||
libc :: #library "c";
|
||||
popen :: (cmd: [:0]u8, mode: [:0]u8) -> *void #foreign libc;
|
||||
puts :: (s: [:0]u8) -> i32 #foreign libc;
|
||||
popen :: (cmd: [:0]u8, mode: [:0]u8) -> *void extern libc;
|
||||
puts :: (s: [:0]u8) -> i32 extern libc;
|
||||
|
||||
R :: struct { x: i32; }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/build.sx";
|
||||
|
||||
puts :: (s: [:0]u8) -> i32 #foreign libc;
|
||||
puts :: (s: [:0]u8) -> i32 extern libc;
|
||||
|
||||
cb :: () -> bool {
|
||||
a := format("{}", "x");
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
// Internal runtime symbol (library/vendors/sx_trace_runtime/sx_trace.c).
|
||||
sx_trace_len :: () -> u32 #foreign;
|
||||
sx_trace_len :: () -> u32 extern;
|
||||
|
||||
E :: error { Bad }
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
trace :: #import "modules/std/trace.sx";
|
||||
|
||||
// Buffer length probe (the runtime symbol; public read API is the trace module).
|
||||
sx_trace_len :: () -> u32 #foreign;
|
||||
sx_trace_len :: () -> u32 extern;
|
||||
|
||||
E :: error { BadInput, Overflow }
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// `#framework "Name"` top-level directive registers an Apple framework for
|
||||
// linking; `#foreign` declarations can omit the library identifier (frameworks
|
||||
// linking; `extern` declarations can omit the library identifier (frameworks
|
||||
// resolve symbols by global namespace at link time).
|
||||
|
||||
#framework "CoreFoundation";
|
||||
|
||||
CFAbsoluteTimeGetCurrent :: () -> f64 #foreign;
|
||||
CFAbsoluteTimeGetCurrent :: () -> f64 extern;
|
||||
|
||||
main :: () -> i32 {
|
||||
t := CFAbsoluteTimeGetCurrent();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#framework "UIKit";
|
||||
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 #foreign;
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 extern;
|
||||
|
||||
// IMP for application:didFinishLaunchingWithOptions:
|
||||
// Obj-C: -(BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#framework "UIKit";
|
||||
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 #foreign;
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 extern;
|
||||
|
||||
g_window : *void = ---;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ configure_build :: () {
|
||||
}
|
||||
#run configure_build();
|
||||
|
||||
CFAbsoluteTimeGetCurrent :: () -> f64 #foreign;
|
||||
CFAbsoluteTimeGetCurrent :: () -> f64 extern;
|
||||
|
||||
main :: () -> i32 {
|
||||
t := CFAbsoluteTimeGetCurrent();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// runner is `runtime main`. The post-link path is exercised via
|
||||
// `sx build` separately.
|
||||
|
||||
puts :: (s: [:0]u8) -> i32 #foreign libc;
|
||||
puts :: (s: [:0]u8) -> i32 extern libc;
|
||||
|
||||
post_link :: () -> bool {
|
||||
puts("[post-link] callback fired");
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#framework "UIKit";
|
||||
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 #foreign;
|
||||
UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 extern;
|
||||
#import "modules/build.sx";
|
||||
#import "modules/platform/bundle.sx";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Pins the curated-bindings shape (PLAN-C C0.2): a `#source`-only unit
|
||||
// (no `#include`, so no auto-synthesized decls) paired with a
|
||||
// hand-written `#foreign` decl naming the unit. Works in JIT and AOT
|
||||
// hand-written `extern` decl naming the unit. Works in JIT and AOT
|
||||
// today — but see 1620: the unit ref is not yet validated or scoped,
|
||||
// so the symbol actually resolves globally, not through the unit.
|
||||
#import "modules/std.sx";
|
||||
@@ -9,7 +9,7 @@ only :: #import c {
|
||||
#source "1619-cimport-source-only/only.c";
|
||||
};
|
||||
|
||||
only_answer :: () -> i32 #foreign only "only_answer";
|
||||
only_answer :: () -> i32 extern only "only_answer";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("answer = {}\n", only_answer() + 1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// `#define`/`#flags` reach a unit whose ONLY consumer is hand-curated
|
||||
// `#foreign` decls (PLAN-C C3.3) — no `#include`, no auto-synthesis:
|
||||
// `extern` decls (PLAN-C C3.3) — no `#include`, no auto-synthesis:
|
||||
// the macro decides what the unit-bound decl answers.
|
||||
#import "modules/std.sx";
|
||||
|
||||
@@ -9,7 +9,7 @@ unit :: #import c {
|
||||
#source "1622-cimport-unit-bound-defines/unit.c";
|
||||
};
|
||||
|
||||
unit_answer :: () -> i32 #foreign unit "unit_answer";
|
||||
unit_answer :: () -> i32 extern unit "unit_answer";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("unit answer = {}\n", unit_answer());
|
||||
|
||||
@@ -12,7 +12,7 @@ ub :: #import c {
|
||||
#source "1628-cimport-duplicate-export/b.c";
|
||||
};
|
||||
|
||||
clash :: () -> i32 #foreign ua "clash";
|
||||
clash :: () -> i32 extern ua "clash";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("{}\n", clash());
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
clib :: #library "c";
|
||||
qsort :: (base: [*]u8, nel: usize, width: usize, compar: (*void, *void) -> i32 callconv(.c)) #foreign clib;
|
||||
qsort :: (base: [*]u8, nel: usize, width: usize, compar: (*void, *void) -> i32 callconv(.c)) extern clib;
|
||||
|
||||
cmp_i32 :: (a: *void, b: *void) -> i32 callconv(.c) {
|
||||
pa : *i32 = xx a;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
clib :: #library "c";
|
||||
pthread_create :: (thread: *usize, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 #foreign clib;
|
||||
pthread_join :: (thread: usize, retval: **void) -> i32 #foreign clib;
|
||||
pthread_create :: (thread: *usize, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 extern clib;
|
||||
pthread_join :: (thread: usize, retval: **void) -> i32 extern clib;
|
||||
|
||||
entry :: (arg: *void) -> *void callconv(.c) {
|
||||
p : *i64 = xx arg;
|
||||
|
||||
Reference in New Issue
Block a user