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

@@ -62,7 +62,7 @@ NSLog :: (fmt: *void) #foreign;
ns_string :: (s: [*]u8) -> *void {
cls := objc_getClass("NSString".ptr);
sel := sel_registerName("stringWithUTF8String:".ptr);
fn_ptr : (*void, *void, [*]u8) -> *void = xx objc_msgSend;
fn_ptr : (*void, *void, [*]u8) -> *void callconv(.c) = xx objc_msgSend;
return fn_ptr(cls, sel, s);
}
@@ -70,6 +70,6 @@ ns_string :: (s: [*]u8) -> *void {
// tied to the NSString; don't free it.
c_string :: (ns: *void) -> [*]u8 {
sel := sel_registerName("UTF8String".ptr);
fn_ptr : (*void, *void) -> [*]u8 = xx objc_msgSend;
fn_ptr : (*void, *void) -> [*]u8 callconv(.c) = xx objc_msgSend;
return fn_ptr(ns, sel);
}

View File

@@ -59,6 +59,10 @@ __sx_block_descriptor : BlockDescriptor = .{
// Signature: `void (^)(void)` — no args, no return. The single most
// common Apple block shape (UIView animation bodies, dispatch_async, etc).
__block_invoke_void :: (block_self: *Block) callconv(.c) {
// `sx_fn` is the closure trampoline — an sx-side function with the
// implicit __sx_ctx at slot 0 and env at slot 1. We're a callconv(.c)
// entry, so the call site needs ctx prepended; the typed fn-pointer
// type stays default-conv to enable that.
typed_fn : (*void) -> void = xx block_self.sx_fn;
typed_fn(block_self.sx_env);
}