mem: implicit-Context platform fixes — chess green on macOS/iOS/Android

Verify-step uncovered three categories of regressions where sx code
calls into the platform's C ABI through fn-pointer types or as a
registered callback. Every site now declares the right convention.

C-side calls INTO sx → callconv(.c) on the sx function:
- platform/android.sx: sx_android_render_thread_entry is the start
  routine pthread_create invokes — pthread treats it as a C function.
  Also annotate the pthread_create signature so the start-routine fn-
  pointer field rejects mismatching sx fns at compile time.

sx code calling typed fn-pointers cast from C symbols → callconv(.c)
on the fn-pointer type:
- opengl.sx: 55 GL fn-ptr globals + load_gl's proc-loader param. GL
  trampolines are macOS/iOS/Android system code.
- std/objc.sx: the two typed `objc_msgSend` casts.
- gpu/metal.sx: ~40 typed `objc_msgSend` casts across Metal command
  encoder / device / pipeline construction.

The block invoke trampolines (objc_block.sx) call back INTO sx (the
closure trampoline). The typed fn-ptr there stays default-conv so
ctx prepends correctly. Compiler change: a callconv(.c) sx function
now binds `current_ctx_ref` to `&__sx_default_context` at entry (used
to be gated by `isExportedEntryName`). C-callable sx callbacks like
the block invokes don't get their own __sx_ctx param but their bodies
still need a real Context to forward to the closure they delegate to.

Tests: 152/152 example suite + chess green on all 3 platforms.
Screenshots at /tmp/sx-game-{macos,iossim,android}.png.
This commit is contained in:
agra
2026-05-25 09:35:15 +03:00
parent a8fb1233e3
commit d4a342d0c1
6 changed files with 109 additions and 100 deletions

View File

@@ -85,7 +85,7 @@ ANativeWindow_setBuffersGeometry :: (w: *void, width: s32, height: s32, fmt: s32
AAssetManager_fromJava :: (env: *void, mgr: *void) -> *void #foreign;
// pthread (link libpthread is built into bionic).
pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void, arg: *void) -> s32 #foreign;
pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> s32 #foreign;
pthread_mutex_init :: (m: *void, attr: *void) -> s32 #foreign;
pthread_mutex_lock :: (m: *void) -> s32 #foreign;
pthread_mutex_unlock :: (m: *void) -> s32 #foreign;
@@ -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 {
sx_android_render_thread_entry :: (arg: *void) -> *void callconv(.c) {
plat : *AndroidPlatform = xx arg;
while plat.app_window == null and !plat.should_stop {
usleep(1000);