comptime compiler-API: Phase 1 foundation + Phase 2.1 weld plan
Introduce the welded comptime `compiler` library (`#library "compiler"` +
`abi(.zig) extern compiler`), per design/comptime-compiler-api.md, and unify
`callconv(...)` into the new `abi(...)` annotation.
abi(...) replaces callconv(...):
- New ABI enum { default, c, zig, pure }; `abi(.c|.zig|.pure)` parses in the
postfix slot before extern/export (and standalone). `kw_callconv` -> `kw_abi`.
- Migrated 52 sx files, the call-convention-mismatch diagnostic, and docs
(readme/specs) from `callconv(.c)` to `abi(.c)`.
Phase 1 — welded compiler library (parse -> registry -> validation -> bridge):
- `abi(.zig) extern compiler` parses on fn decls (carries abi/extern_lib) and
struct decls (StructDecl.abi/extern_lib).
- `#library "compiler"` is the comptime-only internal surface — never dlopen'd.
- src/ir/compiler_lib.zig: the binding registry (the safety boundary). `Field`
welded to StructInfo.Field with layout baked from the real Zig type
(@offsetOf/@sizeOf); `findType`/`findFn`. Welded structs are layout-validated
at registration (field set + total size) as a header checked against the impl.
- Host-call bridge: a `fn abi(.zig) extern compiler` dispatches under the
comptime interp to its registered Zig handler (intern/text_of round-trip),
never dlsym. IR Function.compiler_welded; validated in declareFunction.
- Comptime-only enforcement: a runtime call to a welded fn is a clean
build-gating error (emitCall), not an undefined-symbol link failure.
Phase 2.1 — byte-layout weld foundation:
- Decision: full byte-layout weld (sx struct laid out byte-identically to the
bound Zig type). Registered StructInfo (first non-natural / Zig-reordered
layout). `computeWeldPlan` — pure offset-ordered element plan + padding +
sx-field->LLVM-element remap; unit-tested. Emit/interp wiring is the next
sub-step (2.2+, see current/CHECKPOINT-COMPILER-API.md).
Examples: 0625/0626 (welded struct + fn round-trip), 1183/1184/1185
(layout-mismatch, unexported-fn, runtime-call diagnostics).
This commit is contained in:
@@ -85,7 +85,7 @@ ANativeWindow_setBuffersGeometry :: (w: *void, width: i32, height: i32, fmt: i32
|
||||
AAssetManager_fromJava :: (env: *void, mgr: *void) -> *void extern;
|
||||
|
||||
// pthread (link libpthread is built into bionic).
|
||||
pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 extern;
|
||||
pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void abi(.c), arg: *void) -> i32 extern;
|
||||
pthread_mutex_init :: (m: *void, attr: *void) -> i32 extern;
|
||||
pthread_mutex_lock :: (m: *void) -> i32 extern;
|
||||
pthread_mutex_unlock :: (m: *void) -> i32 extern;
|
||||
@@ -254,7 +254,7 @@ sx_android_start_render_thread :: (plat: *AndroidPlatform, entry_fn: () -> void)
|
||||
plat.render_thread_started = true;
|
||||
}
|
||||
|
||||
sx_android_render_thread_entry :: (arg: *void) -> *void callconv(.c) {
|
||||
sx_android_render_thread_entry :: (arg: *void) -> *void abi(.c) {
|
||||
plat : *AndroidPlatform = xx arg;
|
||||
while plat.app_window == null and !plat.should_stop {
|
||||
usleep(1000);
|
||||
|
||||
@@ -229,7 +229,7 @@ impl Platform for SdlPlatform {
|
||||
// SDL fires the watch synchronously when events are added — including during
|
||||
// macOS's modal resize-drag, when SDL_PollEvent can't run. Re-invoking the
|
||||
// frame closure here keeps content rendering at the new size during the drag.
|
||||
sdl_event_watch :: (userdata: *void, event: *SDL_Event) -> bool callconv(.c) {
|
||||
sdl_event_watch :: (userdata: *void, event: *SDL_Event) -> bool abi(.c) {
|
||||
plat : *SdlPlatform = xx userdata;
|
||||
if event.* == {
|
||||
case .window_resized: (data) {
|
||||
@@ -245,7 +245,7 @@ sdl_event_watch :: (userdata: *void, event: *SDL_Event) -> bool callconv(.c) {
|
||||
true
|
||||
}
|
||||
|
||||
sdl_wasm_tick :: () callconv(.c) {
|
||||
sdl_wasm_tick :: () abi(.c) {
|
||||
if g_sdl_plat == null { return; }
|
||||
if !g_sdl_plat.has_frame_closure { return; }
|
||||
fn := g_sdl_plat.frame_closure;
|
||||
|
||||
@@ -790,8 +790,8 @@ impl Platform for UIKitPlatform {
|
||||
}
|
||||
|
||||
// dlsym(RTLD_DEFAULT, name) — Apple platforms. RTLD_DEFAULT is (void*)-2.
|
||||
// callconv(.c) so this is callable from `load_gl`'s C-conv proc-loader slot.
|
||||
ios_gl_proc :: (name: [*]u8) -> *void callconv(.c) {
|
||||
// abi(.c) so this is callable from `load_gl`'s C-conv proc-loader slot.
|
||||
ios_gl_proc :: (name: [*]u8) -> *void abi(.c) {
|
||||
rtld_default : *void = xx (0 - 2);
|
||||
dlsym(rtld_default, name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user