refactor(ffi-linkage): Phase 9.3 — purge 'foreign' from comments (src caps + examples + docs)

src/: ~21 capital-Foreign comments the case-sensitive verify grep missed
(Foreign-class→Runtime-class, Foreign path→Runtime path, Foreign decls→Extern decls,
FOREIGN function→extern function) across calls/inst/ffi_objc/jni_descriptor/emit_llvm/
c_import/lower.*/ops. src 'foreign' now = ONLY the hash_foreign token + 4 rejection
messages (9.0-delete targets). examples/*.sx comments → extern/runtime-class (1219
stdout regen; KEPT 1176). docs/inline-asm-design + debugger purged. Comments only —
no build impact. 9.0 ratified: DELETE hash_foreign token next.
This commit is contained in:
agra
2026-06-15 10:52:56 +03:00
parent dc51c4b5bf
commit 811a280517
57 changed files with 198 additions and 125 deletions

View File

@@ -301,8 +301,8 @@ traces and DWARF can never disagree:
declared lazily by `getTraceFids()` (which sets `needs_trace_runtime`).
3. **Interpreter** (`interp.zig`, same op): pack `(current_func_id,
span.start)` into a `u64` and return it as the op's value. The separate
`sx_trace_push` call op is then executed by the interp as a foreign call
(`callForeign` → `host_ffi.lookupSymbol`/dlsym, the same path as any
`sx_trace_push` call op is then executed by the interp as an extern call
(`callExtern` → `host_ffi.lookupSymbol`/dlsym, the same path as any
extern), storing the packed value in the buffer. The comptime
`.trace_resolve` resolver later turns each packed value back into
`file:line:col` via the IR/source tables.

View File

@@ -445,26 +445,20 @@ q, r := divmod(17, 5); // q = 3, r = 2
ATT,
};
my_func :: (a: i32, b: i32) -> i32 #foreign; // extern, no library — valid sx today
my_func :: (a: i32, b: i32) -> i32 extern; // extern, no library — valid sx today
```
Only the `comptime {}` wrapper is dropped; lowers to `LLVMAppendModuleInlineAsm`.
**Calling the asm symbol reuses the C-FFI *import* path** (no new mechanism for
v1) — but note `#foreign` is **not** a general `extern`. A lib-less `#foreign`
(its library is optional: `src/parser.zig:319-325`; used in 50+ stdlib sites,
e.g. `chdir :: (path: [*]u8) -> i32 #foreign;`) emits exactly the artifact needed
to *call into* the asm symbol — an external-linkage, **C-calling-convention**,
raw-named (`emit_llvm.zig:1279`), link-time-resolved declaration — the same thing
Zig's `extern fn` produces (Zig's `extern fn` is also C-callconv). At the IR level
`is_extern` is set straight from `is_foreign` (`decl.zig:1123`) and `#foreign`
forces the C ABI (`decl.zig:2110`). The two real differences from a general
`extern`: (1) `#foreign` is **import-only** — sx has no `#export`/linkname, so the
reverse direction (asm calling *back into* an sx function) is unsupported; (2) it
carries C-ABI marshaling and reads as "a foreign C function," a category-borrow
for a symbol your own module defines. It is the right *mechanism* but an imperfect
*spelling*; a dedicated `#extern`/linkname is an open question (§II.10).
(`specs.md:1209` was corrected to drop the false "library mandatory" claim.)
v1). A lib-less `extern` fn declaration (its library is optional; used in 50+
stdlib sites, e.g. `chdir :: (path: [*]u8) -> i32 extern;`) emits exactly the
artifact needed to *call into* the asm symbol — an external-linkage,
**C-calling-convention**, raw-named, link-time-resolved declaration — the same
thing Zig's `extern fn` produces (also C-callconv). The reverse direction (asm
calling *back into* an sx function) is handled by `export`, the define-and-expose
dual of `extern`. (The legacy prefix `#foreign` spelling that originally provided
the import path has since been replaced by the postfix `extern`/`export` keywords.)
Everything *semantic* — comptime-known template, register/memory constraints
verbatim to LLVM, clobber meaning, "no-output ⇒ must be volatile," AT&T default,
@@ -475,14 +469,14 @@ verbatim to LLVM, clobber meaning, "no-output ⇒ must be volatile," AT&T defaul
sx's AST is a pointer-based tagged union (`Data = union(enum)` at
`src/ast.zig:13`, nodes built via `Parser.createNode`), much simpler than Zig's
SoA `extra_data` scheme — so we can store slices directly. Add one arm next to
`foreign_expr` (`src/ast.zig:85`):
SoA `extra_data` scheme — so we can store slices directly. Add one arm to the
`Node.Data` union (`src/ast.zig:13`):
```zig
// in Node.Data union(enum):
asm_expr: AsmExpr,
// new, near ForeignExpr (src/ast.zig:721):
// new node struct, alongside the other expression node defs:
pub const AsmExpr = struct {
template: *Node, // string-literal / #string node (comptime string)
is_volatile: bool = false,