refactor(ffi-linkage): Phase 9.3 — rename *-foreign* example files → extern/runtime names
git-mv the 10 foreign-named example families to extern/runtime-class names + update every #import/#include/#source ref, stale comment ref, and the 1172 stderr snapshot (path + 'extern symbol' message). Renames: 0729…-foreign→…-extern, 1172-diagnostics- foreign-symbol-conflict→…-extern-symbol-conflict, 1205/1207 ffi-foreign-global→ ffi-extern-global, 1216/1217 ffi-…-foreign-(in-method|result-chain)→…-extern-…, 1219-ffi-foreign→1219-ffi-extern, 1306 objc-foreign-class-chained→objc-runtime-class- chained, 1318 objc-property-foreign→objc-property-extern-class. DEDUP: deleted 1218-ffi-foreign-cvariadic (identical to 1229-ffi-extern-cvariadic; updated 1229's twin ref) + the orphaned 1620 dir. Also purged editors/vscode tmLanguage (#foreign dropped from the directive highlighter) + 1220.h/issues-0030.sx comment refs. Suite green (644 corpus / 443 unit, 0 failed).
This commit is contained in:
@@ -179,7 +179,7 @@
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.other.directive.sx",
|
||||
"match": "#(?:run|import|insert|builtin|foreign|library)\\b"
|
||||
"match": "#(?:run|import|insert|builtin|library)\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// dispatch binds the call. A same-name extern collision therefore compiles and
|
||||
// runs (master behavior), it does NOT error as ambiguous.
|
||||
#import "modules/std.sx";
|
||||
#import "0729-modules-flat-same-name-foreign/a.sx";
|
||||
#import "0729-modules-flat-same-name-foreign/b.sx";
|
||||
#import "0729-modules-flat-same-name-extern/a.sx";
|
||||
#import "0729-modules-flat-same-name-extern/b.sx";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("absval = {}\n", absval(-7));
|
||||
@@ -1,4 +1,4 @@
|
||||
// Companion module for examples/94-foreign-global.sx (PLAN-FFI 0.10).
|
||||
// Companion module for examples/1205-ffi-extern-global.sx (PLAN-FFI 0.10).
|
||||
// Declares the same `extern` extern global as the main file; the
|
||||
// linker should treat both decls as one symbol. We deliberately don't
|
||||
// READ `@__stdinp` from inside a helper fn body — that path is busted
|
||||
@@ -4,7 +4,7 @@
|
||||
// `<fn> :: (...) -> ... extern;` form on the function side.
|
||||
//
|
||||
// Cross-file dimension (PLAN-FFI step 0.10): the helper companion
|
||||
// `94-foreign-global-helper.sx` ALSO declares `__stdinp : *void extern;`.
|
||||
// `1205-ffi-extern-global-helper.sx` ALSO declares `__stdinp : *void extern;`.
|
||||
// Both files referencing the same extern symbol must link cleanly —
|
||||
// LLVM dedupes the named global, the C linker resolves both refs to
|
||||
// the one libSystem symbol.
|
||||
@@ -15,7 +15,7 @@
|
||||
// the equality check here.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "1205-ffi-foreign-global-helper.sx";
|
||||
#import "1205-ffi-extern-global-helper.sx";
|
||||
|
||||
__stdinp : *void extern;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#include "1216-ffi-08-foreign-in-method.h"
|
||||
#include "1216-ffi-08-extern-in-method.h"
|
||||
|
||||
int ffi_method_helper(int x) { return x * 10; }
|
||||
@@ -12,8 +12,8 @@
|
||||
#import "modules/build.sx";
|
||||
|
||||
#import c {
|
||||
#include "1216-ffi-08-foreign-in-method.h";
|
||||
#source "1216-ffi-08-foreign-in-method.c";
|
||||
#include "1216-ffi-08-extern-in-method.h";
|
||||
#source "1216-ffi-08-extern-in-method.c";
|
||||
};
|
||||
|
||||
// ── 1. Struct method calling a #extern fn ───────────────────────────
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "1217-ffi-09-foreign-result-chain.h"
|
||||
#include "1217-ffi-09-extern-result-chain.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void *ffi_chain_make(int seed) {
|
||||
@@ -12,8 +12,8 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
#import c {
|
||||
#include "1217-ffi-09-foreign-result-chain.h";
|
||||
#source "1217-ffi-09-foreign-result-chain.c";
|
||||
#include "1217-ffi-09-extern-result-chain.h";
|
||||
#source "1217-ffi-09-extern-result-chain.c";
|
||||
};
|
||||
|
||||
// Struct field hosts an FFI-returned handle.
|
||||
@@ -1,30 +0,0 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
long long sx_ffi_sum_ints(int n, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, n);
|
||||
long long total = 0;
|
||||
for (int i = 0; i < n; i++) total += va_arg(ap, int);
|
||||
va_end(ap);
|
||||
return total;
|
||||
}
|
||||
|
||||
double sx_ffi_avg_doubles(int n, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, n);
|
||||
double total = 0.0;
|
||||
for (int i = 0; i < n; i++) total += va_arg(ap, double);
|
||||
va_end(ap);
|
||||
if (n == 0) return 0.0;
|
||||
return total / n;
|
||||
}
|
||||
|
||||
int sx_ffi_count_args(const char *tag, ...) {
|
||||
(void) tag;
|
||||
va_list ap;
|
||||
va_start(ap, tag);
|
||||
int count = 0;
|
||||
while (va_arg(ap, const char *) != 0) count++;
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// `extern` C-variadic tail: trailing `..args: []T` on a extern fn maps
|
||||
// to the C calling convention's `...`. Extras at the call site are
|
||||
// passed via the variadic slot with the standard default argument
|
||||
// promotion (i8/i16/bool → i32, f32 → f64) applied implicitly.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
#import c {
|
||||
#source "1218-ffi-foreign-cvariadic.c";
|
||||
};
|
||||
|
||||
sx_ffi_sum_ints :: (n: i32, ..args: []i32) -> i64 extern;
|
||||
sx_ffi_avg_doubles :: (n: i32, ..args: []f64) -> f64 extern;
|
||||
sx_ffi_count_args :: (tag: *u8, ..args: []*u8) -> i32 extern;
|
||||
|
||||
main :: () -> i32 {
|
||||
print("sum_ints(3, 10, 20, 30) = {}\n", sx_ffi_sum_ints(3, 10, 20, 30));
|
||||
print("sum_ints(0) = {}\n", sx_ffi_sum_ints(0));
|
||||
print("avg_doubles(2) = {}\n", sx_ffi_avg_doubles(2, 1.5, 2.5));
|
||||
print("avg_doubles(3) = {}\n", sx_ffi_avg_doubles(3, 1.0, 2.0, 3.0));
|
||||
|
||||
a := "alpha".ptr;
|
||||
b := "beta".ptr;
|
||||
g := "gamma".ptr;
|
||||
sentinel : *u8 = null;
|
||||
print("count_args(3 strs) = {}\n", sx_ffi_count_args("tag".ptr, a, b, g, sentinel));
|
||||
0
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Foreign C declarations whose names collide with sx's reserved type spellings.
|
||||
/* Extern C declarations whose names collide with sx's reserved type spellings.
|
||||
The `#import c` exemption must accept these generated names unedited, both as
|
||||
parameter names (`i1`, `i2`) and as a FUNCTION name (`i2`) — and a foreign
|
||||
parameter names (`i1`, `i2`) and as a FUNCTION name (`i2`) — and an extern
|
||||
reserved-name function must be bare-callable (issue 0089). */
|
||||
int ffi_pick(int i1, int i2, int which);
|
||||
int ffi_sum(int i1, int i2);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// `extern` C-variadic tail: a trailing `..args: []T` on an `extern` fn
|
||||
// maps to the C calling convention's `...`, exactly like its `extern`
|
||||
// twin (example 1218). Extras at the call site pass through the variadic
|
||||
// maps to the C calling convention's `...`. Extras at the call site pass through the variadic
|
||||
// slot with standard default argument promotion (i8/i16/bool → i32,
|
||||
// f32 → f64), NOT packed into an sx slice.
|
||||
//
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
int ref_answer(void) { return 7; }
|
||||
@@ -1,5 +1,5 @@
|
||||
error: extern symbol 'getenv' is already bound with a different signature; two views of one C symbol must declare identical types
|
||||
--> examples/1172-diagnostics-foreign-symbol-conflict.sx:9:61
|
||||
--> examples/1172-diagnostics-extern-symbol-conflict.sx:9:61
|
||||
|
|
||||
9 | getenv_opt :: (name: [:0]u8) -> ?[:0]u8 extern libc "getenv";
|
||||
| ^
|
||||
@@ -1,5 +0,0 @@
|
||||
sum_ints(3, 10, 20, 30) = 60
|
||||
sum_ints(0) = 0
|
||||
avg_doubles(2) = 2.000000
|
||||
avg_doubles(3) = 2.000000
|
||||
count_args(3 strs) = 3
|
||||
@@ -1 +0,0 @@
|
||||
0
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Repro for issue 0030 (OPEN feature request): cross-file sx `extern` globals.
|
||||
// Want: `extern G : T;` declares a reference to a global defined in another sx
|
||||
// file (resolved at link time), mirroring `#foreign` functions. Today this is a
|
||||
// parse error — the form doesn't exist. Distinct from `name : T #foreign;`
|
||||
// (an external C data symbol; see examples/1205-ffi-foreign-global.sx).
|
||||
// file (resolved at link time), mirroring `extern` functions. Today this is a
|
||||
// parse error — the form doesn't exist. Distinct from `name : T extern;`
|
||||
// (an external C data symbol; see examples/1205-ffi-extern-global.sx).
|
||||
//
|
||||
// Expected (once implemented): parses; `g_x` resolves to a global defined
|
||||
// elsewhere. Actual: error "expected '::', ':=', or ':' after identifier".
|
||||
|
||||
Reference in New Issue
Block a user