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:
agra
2026-06-17 13:31:11 +03:00
parent 3a9b508502
commit cd5b958d19
100 changed files with 1490 additions and 298 deletions

View File

@@ -53,7 +53,7 @@ objc_msgSend :: (recv: *void, sel: *void) -> *void extern objc;
//
// IMPs (method implementations) are function pointers with the implicit
// Obj-C method shape: `(self: *void, _cmd: *void, ...args) -> ret` with
// `callconv(.c)` so they land args in the standard C registers.
// `abi(.c)` so they land args in the standard C registers.
//
// Method type encoding strings follow Apple's runtime DSL:
// v = void c = char/BOOL i = int l = long f = float d = double
@@ -120,7 +120,7 @@ impl Into(*NSString) for string {
convert :: (self: string) -> *NSString {
cls := objc_getClass("NSString".ptr);
sel := sel_registerName("stringWithUTF8String:".ptr);
msg : (*void, *void, [*]u8) -> *void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, [*]u8) -> *void abi(.c) = xx objc_msgSend;
return xx msg(cls, sel, self.ptr);
}
}

View File

@@ -63,7 +63,7 @@ __sx_block_descriptor : BlockDescriptor = .{
// `$args` is the bound pack of arg types and `$R` is the bound
// return type. The `#insert` evaluates `build_block_convert` at
// comptime and substitutes the resulting source — a nested
// `callconv(.c)` trampoline + the Block literal that points its
// `abi(.c)` trampoline + the Block literal that points its
// `invoke` slot at it. One impl in stdlib replaces every per-
// signature hand-rolled `__block_invoke_*` + `Into(Block)` pair.
impl Into(Block) for Closure(..$args) -> $R {
@@ -77,7 +77,7 @@ impl Into(Block) for Closure(..$args) -> $R {
// (`args`, a comptime `[]Type`) and the closure's return type
// (`$ret`), emits source that:
//
// 1. Declares a nested `__invoke` `callconv(.c)` trampoline whose
// 1. Declares a nested `__invoke` `abi(.c)` trampoline whose
// signature matches the per-shape Apple Block ABI: first arg is
// `block_self: *Block`, then the pack types verbatim. The body
// reconstructs a typed fn-pointer from `block_self.sx_fn`,
@@ -105,7 +105,7 @@ build_block_convert :: (args: []Type, $ret: Type) -> string {
}
code = concat(code, ") -> ");
code = concat(code, ret_name);
code = concat(code, " callconv(.c) { typed_fn : (*void");
code = concat(code, " abi(.c) { typed_fn : (*void");
i = 0;
while i < args.len {
code = concat(code, ", ");

View File

@@ -25,39 +25,39 @@ GL_LINE :u32: 0x1B01;
GL_FILL :u32: 0x1B02;
// Function pointer variables (mutable, loaded at runtime)
glClearColor : (f32, f32, f32, f32) -> void callconv(.c) = ---;
glClear : (u32) -> void callconv(.c) = ---;
glEnable : (u32) -> void callconv(.c) = ---;
glDisable : (u32) -> void callconv(.c) = ---;
glViewport : (i32, i32, i32, i32) -> void callconv(.c) = ---;
glFlush : () -> void callconv(.c) = ---;
glDrawArrays : (u32, i32, i32) -> void callconv(.c) = ---;
glPolygonMode : (u32, u32) -> void callconv(.c) = ---;
glLineWidth : (f32) -> void callconv(.c) = ---;
glCreateShader : (u32) -> u32 callconv(.c) = ---;
glShaderSource : (u32, i32, *[:0]u8, *i32) -> void callconv(.c) = ---;
glCompileShader : (u32) -> void callconv(.c) = ---;
glGetShaderiv : (u32, u32, *i32) -> void callconv(.c) = ---;
glGetShaderInfoLog : (u32, i32, *i32, [*]u8) -> void callconv(.c) = ---;
glCreateProgram : () -> u32 callconv(.c) = ---;
glAttachShader : (u32, u32) -> void callconv(.c) = ---;
glLinkProgram : (u32) -> void callconv(.c) = ---;
glGetProgramiv : (u32, u32, *i32) -> void callconv(.c) = ---;
glGetProgramInfoLog : (u32, i32, *i32, [*]u8) -> void callconv(.c) = ---;
glUseProgram : (u32) -> void callconv(.c) = ---;
glDeleteShader : (u32) -> void callconv(.c) = ---;
glGenVertexArrays : (i32, *u32) -> void callconv(.c) = ---;
glGenBuffers : (i32, *u32) -> void callconv(.c) = ---;
glBindVertexArray : (u32) -> void callconv(.c) = ---;
glBindBuffer : (u32, u32) -> void callconv(.c) = ---;
glBufferData : (u32, isize, *void, u32) -> void callconv(.c) = ---;
glVertexAttribPointer : (u32, i32, u32, u8, i32, *void) -> void callconv(.c) = ---;
glEnableVertexAttribArray : (u32) -> void callconv(.c) = ---;
glGetUniformLocation : (u32, [*]u8) -> i32 callconv(.c) = ---;
glUniformMatrix4fv : (i32, i32, u8, [*]f32) -> void callconv(.c) = ---;
glUniform3f : (i32, f32, f32, f32) -> void callconv(.c) = ---;
glDepthFunc : (u32) -> void callconv(.c) = ---;
glUniform1f : (i32, f32) -> void callconv(.c) = ---;
glClearColor : (f32, f32, f32, f32) -> void abi(.c) = ---;
glClear : (u32) -> void abi(.c) = ---;
glEnable : (u32) -> void abi(.c) = ---;
glDisable : (u32) -> void abi(.c) = ---;
glViewport : (i32, i32, i32, i32) -> void abi(.c) = ---;
glFlush : () -> void abi(.c) = ---;
glDrawArrays : (u32, i32, i32) -> void abi(.c) = ---;
glPolygonMode : (u32, u32) -> void abi(.c) = ---;
glLineWidth : (f32) -> void abi(.c) = ---;
glCreateShader : (u32) -> u32 abi(.c) = ---;
glShaderSource : (u32, i32, *[:0]u8, *i32) -> void abi(.c) = ---;
glCompileShader : (u32) -> void abi(.c) = ---;
glGetShaderiv : (u32, u32, *i32) -> void abi(.c) = ---;
glGetShaderInfoLog : (u32, i32, *i32, [*]u8) -> void abi(.c) = ---;
glCreateProgram : () -> u32 abi(.c) = ---;
glAttachShader : (u32, u32) -> void abi(.c) = ---;
glLinkProgram : (u32) -> void abi(.c) = ---;
glGetProgramiv : (u32, u32, *i32) -> void abi(.c) = ---;
glGetProgramInfoLog : (u32, i32, *i32, [*]u8) -> void abi(.c) = ---;
glUseProgram : (u32) -> void abi(.c) = ---;
glDeleteShader : (u32) -> void abi(.c) = ---;
glGenVertexArrays : (i32, *u32) -> void abi(.c) = ---;
glGenBuffers : (i32, *u32) -> void abi(.c) = ---;
glBindVertexArray : (u32) -> void abi(.c) = ---;
glBindBuffer : (u32, u32) -> void abi(.c) = ---;
glBufferData : (u32, isize, *void, u32) -> void abi(.c) = ---;
glVertexAttribPointer : (u32, i32, u32, u8, i32, *void) -> void abi(.c) = ---;
glEnableVertexAttribArray : (u32) -> void abi(.c) = ---;
glGetUniformLocation : (u32, [*]u8) -> i32 abi(.c) = ---;
glUniformMatrix4fv : (i32, i32, u8, [*]f32) -> void abi(.c) = ---;
glUniform3f : (i32, f32, f32, f32) -> void abi(.c) = ---;
glDepthFunc : (u32) -> void abi(.c) = ---;
glUniform1f : (i32, f32) -> void abi(.c) = ---;
GL_LESS :u32: 0x0201;
GL_LEQUAL :u32: 0x0203;
GL_SCISSOR_TEST :u32: 0x0C11;
@@ -76,27 +76,27 @@ GL_RED :u32: 0x1903;
GL_R8 :u32: 0x8229;
GL_UNPACK_ALIGNMENT :u32: 0x0CF5;
glScissor : (i32, i32, i32, i32) -> void callconv(.c) = ---;
glBufferSubData : (u32, isize, isize, *void) -> void callconv(.c) = ---;
glGenTextures : (i32, *u32) -> void callconv(.c) = ---;
glBindTexture : (u32, u32) -> void callconv(.c) = ---;
glTexImage2D : (u32, i32, i32, i32, i32, i32, u32, u32, *void) -> void callconv(.c) = ---;
glTexParameteri : (u32, u32, i32) -> void callconv(.c) = ---;
glBlendFunc : (u32, u32) -> void callconv(.c) = ---;
glReadPixels : (i32, i32, i32, i32, u32, u32, *void) -> void callconv(.c) = ---;
glActiveTexture : (u32) -> void callconv(.c) = ---;
glUniform1i : (i32, i32) -> void callconv(.c) = ---;
glPixelStorei : (u32, i32) -> void callconv(.c) = ---;
glTexSubImage2D : (u32, i32, i32, i32, i32, i32, u32, u32, *void) -> void callconv(.c) = ---;
glDeleteTextures : (i32, *u32) -> void callconv(.c) = ---;
glScissor : (i32, i32, i32, i32) -> void abi(.c) = ---;
glBufferSubData : (u32, isize, isize, *void) -> void abi(.c) = ---;
glGenTextures : (i32, *u32) -> void abi(.c) = ---;
glBindTexture : (u32, u32) -> void abi(.c) = ---;
glTexImage2D : (u32, i32, i32, i32, i32, i32, u32, u32, *void) -> void abi(.c) = ---;
glTexParameteri : (u32, u32, i32) -> void abi(.c) = ---;
glBlendFunc : (u32, u32) -> void abi(.c) = ---;
glReadPixels : (i32, i32, i32, i32, u32, u32, *void) -> void abi(.c) = ---;
glActiveTexture : (u32) -> void abi(.c) = ---;
glUniform1i : (i32, i32) -> void abi(.c) = ---;
glPixelStorei : (u32, i32) -> void abi(.c) = ---;
glTexSubImage2D : (u32, i32, i32, i32, i32, i32, u32, u32, *void) -> void abi(.c) = ---;
glDeleteTextures : (i32, *u32) -> void abi(.c) = ---;
glGenFramebuffers : (i32, *u32) -> void callconv(.c) = ---;
glGenRenderbuffers : (i32, *u32) -> void callconv(.c) = ---;
glBindFramebuffer : (u32, u32) -> void callconv(.c) = ---;
glBindRenderbuffer : (u32, u32) -> void callconv(.c) = ---;
glFramebufferRenderbuffer : (u32, u32, u32, u32) -> void callconv(.c) = ---;
glGetRenderbufferParameteriv : (u32, u32, *i32) -> void callconv(.c) = ---;
glCheckFramebufferStatus : (u32) -> u32 callconv(.c) = ---;
glGenFramebuffers : (i32, *u32) -> void abi(.c) = ---;
glGenRenderbuffers : (i32, *u32) -> void abi(.c) = ---;
glBindFramebuffer : (u32, u32) -> void abi(.c) = ---;
glBindRenderbuffer : (u32, u32) -> void abi(.c) = ---;
glFramebufferRenderbuffer : (u32, u32, u32, u32) -> void abi(.c) = ---;
glGetRenderbufferParameteriv : (u32, u32, *i32) -> void abi(.c) = ---;
glCheckFramebufferStatus : (u32) -> u32 abi(.c) = ---;
GL_TEXTURE_WRAP_S :u32: 0x2802;
GL_TEXTURE_WRAP_T :u32: 0x2803;
@@ -104,7 +104,7 @@ GL_CLAMP_TO_EDGE :u32: 0x812F;
// Loader: call once after creating GL context
// Pass in a proc loader (e.g. SDL_GL_GetProcAddress)
load_gl :: (get_proc: ([*]u8) -> *void callconv(.c)) {
load_gl :: (get_proc: ([*]u8) -> *void abi(.c)) {
glClearColor = xx get_proc("glClearColor");
glClear = xx get_proc("glClear");
glEnable = xx get_proc("glEnable");

View File

@@ -58,7 +58,7 @@ MTLClearColor :: struct {
// MTLRegion is 48 bytes and MTLScissorRect is 32 bytes; both are passed
// by value to the Obj-C runtime, which the compiler marshals as
// `ptr byval(<T>)` via the C-ABI byval coercion. The fn-pointer cast
// must spell `callconv(.c)` so the indirect call applies that coercion.
// must spell `abi(.c)` so the indirect call applies that coercion.
MTLOrigin :: struct { x: u64; y: u64; z: u64; }
MTLSize :: struct { width: u64; height: u64; depth: u64; }
MTLRegion :: struct { origin: MTLOrigin; size: MTLSize; }
@@ -257,11 +257,11 @@ metal_init_ios :: (self: *MetalGPU) -> bool {
if self.device == null { return false; }
}
msg_oo : (*void, *void, *void) -> void callconv(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg_ob : (*void, *void, u8) -> void callconv(.c) = xx objc_msgSend;
msg_osize : (*void, *void, CGSize) -> void callconv(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void abi(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg_ob : (*void, *void, u8) -> void abi(.c) = xx objc_msgSend;
msg_osize : (*void, *void, CGSize) -> void abi(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void abi(.c) = xx objc_msgSend;
if self.queue == null {
self.queue = msg_o(self.device, sel_registerName("newCommandQueue".ptr));
@@ -290,7 +290,7 @@ metal_resize_ios :: (self: *MetalGPU) {
inline if OS != .ios { return; }
if self.layer == null { return; }
msg_osize : (*void, *void, CGSize) -> void callconv(.c) = xx objc_msgSend;
msg_osize : (*void, *void, CGSize) -> void abi(.c) = xx objc_msgSend;
size := CGSize.{ width = xx self.pixel_w, height = xx self.pixel_h };
msg_osize(self.layer, sel_registerName("setDrawableSize:".ptr), size);
}
@@ -301,12 +301,12 @@ metal_begin_frame_ios :: (self: *MetalGPU, clear: ClearColor) -> bool {
if self.queue == null { return false; }
if self.pixel_w <= 0 or self.pixel_h <= 0 { return false; }
msg_o : (*void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void callconv(.c) = xx objc_msgSend;
msg_oo_ret : (*void, *void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg_ouret : (*void, *void, u64) -> *void callconv(.c) = xx objc_msgSend;
msg_oclear : (*void, *void, MTLClearColor) -> void callconv(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void abi(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void abi(.c) = xx objc_msgSend;
msg_oo_ret : (*void, *void, *void) -> *void abi(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg_ouret : (*void, *void, u64) -> *void abi(.c) = xx objc_msgSend;
msg_oclear : (*void, *void, MTLClearColor) -> void abi(.c) = xx objc_msgSend;
// drawable = [layer nextDrawable]
self.drawable = msg_o(self.layer, sel_registerName("nextDrawable".ptr));
@@ -353,9 +353,9 @@ metal_end_frame_ios :: (self: *MetalGPU, target_time: f64) {
if self.cmd_buffer == null { return; }
if self.drawable == null { return; }
msg_v : (*void, *void) -> void callconv(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void callconv(.c) = xx objc_msgSend;
msg_ood : (*void, *void, *void, f64) -> void callconv(.c) = xx objc_msgSend;
msg_v : (*void, *void) -> void abi(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void abi(.c) = xx objc_msgSend;
msg_ood : (*void, *void, *void, f64) -> void abi(.c) = xx objc_msgSend;
msg_v(self.encoder, sel_registerName("endEncoding".ptr));
@@ -386,15 +386,15 @@ metal_create_shader_ios :: (self: *MetalGPU, src: string) -> u32 {
inline if OS != .ios { return 0; }
if self.device == null { return 0; }
msg_o : (*void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void callconv(.c) = xx objc_msgSend;
msg_oo_r : (*void, *void, *NSString) -> *void callconv(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg_ouret: (*void, *void, u64) -> *void callconv(.c) = xx objc_msgSend;
msg_ob : (*void, *void, u8) -> void callconv(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void abi(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> void abi(.c) = xx objc_msgSend;
msg_oo_r : (*void, *void, *NSString) -> *void abi(.c) = xx objc_msgSend;
msg_ou : (*void, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg_ouret: (*void, *void, u64) -> *void abi(.c) = xx objc_msgSend;
msg_ob : (*void, *void, u8) -> void abi(.c) = xx objc_msgSend;
// [device newLibraryWithSource:src options:nil error:&err]
msg_lib : (*void, *void, *NSString, *void, **void) -> *void callconv(.c) = xx objc_msgSend;
msg_lib : (*void, *void, *NSString, *void, **void) -> *void abi(.c) = xx objc_msgSend;
err : *void = null;
library := msg_lib(self.device,
sel_registerName("newLibraryWithSource:options:error:".ptr),
@@ -428,7 +428,7 @@ metal_create_shader_ios :: (self: *MetalGPU, src: string) -> u32 {
msg_ou(att0, sel_registerName("setSourceAlphaBlendFactor:".ptr), MTL_BLEND_FACTOR_SRC_ALPHA);
msg_ou(att0, sel_registerName("setDestinationAlphaBlendFactor:".ptr), MTL_BLEND_FACTOR_ONE_MINUS_SRC_A);
msg_pipe : (*void, *void, *void, **void) -> *void callconv(.c) = xx objc_msgSend;
msg_pipe : (*void, *void, *void, **void) -> *void abi(.c) = xx objc_msgSend;
err2 : *void = null;
state := msg_pipe(self.device,
sel_registerName("newRenderPipelineStateWithDescriptor:error:".ptr),
@@ -452,7 +452,7 @@ metal_create_buffer_ios :: (self: *MetalGPU, size_bytes: i64) -> u32 {
if size_bytes <= 0 { return 0; }
// MTLResourceStorageModeShared is the default (option value 0).
msg_buf : (*void, *void, u64, u64) -> *void callconv(.c) = xx objc_msgSend;
msg_buf : (*void, *void, u64, u64) -> *void abi(.c) = xx objc_msgSend;
buf := msg_buf(self.device,
sel_registerName("newBufferWithLength:options:".ptr),
xx size_bytes, 0);
@@ -469,7 +469,7 @@ metal_update_buffer_ios :: (self: *MetalGPU, handle: u32, data: *void, size_byte
if data == null { return; }
if size_bytes <= 0 { return; }
msg_o : (*void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void abi(.c) = xx objc_msgSend;
dst := msg_o(buf, sel_registerName("contents".ptr));
if dst == null { return; }
memcpy(dst, data, size_bytes);
@@ -483,7 +483,7 @@ metal_update_buffer_at_ios :: (self: *MetalGPU, handle: u32, data: *void, size_b
if size_bytes <= 0 { return; }
if byte_offset < 0 { return; }
msg_o : (*void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_o : (*void, *void) -> *void abi(.c) = xx objc_msgSend;
base := msg_o(buf, sel_registerName("contents".ptr));
if base == null { return; }
// Add byte_offset via integer arithmetic — `@dst[i]` on `[*]u8`
@@ -530,7 +530,7 @@ metal_create_texture_ios :: (self: *MetalGPU, w: i32, h: i32, format: TextureFor
// [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:width:height:mipmapped:]
MTLTextureDescriptor := objc_getClass("MTLTextureDescriptor".ptr);
msg_desc : (*void, *void, u64, u64, u64, u8) -> *void callconv(.c) = xx objc_msgSend;
msg_desc : (*void, *void, u64, u64, u64, u8) -> *void abi(.c) = xx objc_msgSend;
desc := msg_desc(MTLTextureDescriptor,
sel_registerName("texture2DDescriptorWithPixelFormat:width:height:mipmapped:".ptr),
pixel_format, xx w, xx h, 0);
@@ -539,10 +539,10 @@ metal_create_texture_ios :: (self: *MetalGPU, w: i32, h: i32, format: TextureFor
// Force shared storage so the CPU can keep writing pixels (atlas updates,
// sprite uploads). On iOS-sim under Apple Silicon the convenience class
// method's default storage isn't reliably shared for every format.
msg_ou_void : (*void, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg_ou_void : (*void, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg_ou_void(desc, sel_registerName("setStorageMode:".ptr), MTL_STORAGE_MODE_SHARED);
msg_oo : (*void, *void, *void) -> *void callconv(.c) = xx objc_msgSend;
msg_oo : (*void, *void, *void) -> *void abi(.c) = xx objc_msgSend;
tex := msg_oo(self.device, sel_registerName("newTextureWithDescriptor:".ptr), desc);
if tex == null { return 0; }
@@ -575,7 +575,7 @@ metal_update_texture_region_ios :: (self: *MetalGPU, handle: u32, x: i32, y: i32
bytes_per_row : u64 = xx (slot.bytes_per_pixel * cast(u32) w);
// [tex replaceRegion:region mipmapLevel:0 withBytes:pixels bytesPerRow:bytes_per_row]
msg_replace : (*void, *void, MTLRegion, u64, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg_replace : (*void, *void, MTLRegion, u64, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg_replace(slot.tex,
sel_registerName("replaceRegion:mipmapLevel:withBytes:bytesPerRow:".ptr),
region, 0, pixels, bytes_per_row);
@@ -596,7 +596,7 @@ metal_destroy_shader_ios :: (self: *MetalGPU, handle: u32) {
if h64 > self.shaders.len { return; }
obj := self.shaders.items[handle - 1];
if obj == null { return; }
msg : (*void, *void) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void) -> void abi(.c) = xx objc_msgSend;
msg(obj, sel_registerName("release".ptr));
self.shaders.items[handle - 1] = null;
}
@@ -608,7 +608,7 @@ metal_destroy_buffer_ios :: (self: *MetalGPU, handle: u32) {
if h64 > self.buffers.len { return; }
obj := self.buffers.items[handle - 1];
if obj == null { return; }
msg : (*void, *void) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void) -> void abi(.c) = xx objc_msgSend;
msg(obj, sel_registerName("release".ptr));
self.buffers.items[handle - 1] = null;
}
@@ -620,7 +620,7 @@ metal_destroy_texture_ios :: (self: *MetalGPU, handle: u32) {
if h64 > self.textures.len { return; }
obj := self.textures.items[handle - 1].tex;
if obj == null { return; }
msg : (*void, *void) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void) -> void abi(.c) = xx objc_msgSend;
msg(obj, sel_registerName("release".ptr));
self.textures.items[handle - 1].tex = null;
self.textures.items[handle - 1].bytes_per_pixel = 0;
@@ -633,7 +633,7 @@ metal_set_shader_ios :: (self: *MetalGPU, sh: u32) {
if self.encoder == null { return; }
state := metal_lookup_shader(self, sh);
if state == null { return; }
msg : (*void, *void, *void) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, *void) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setRenderPipelineState:".ptr), state);
}
@@ -643,7 +643,7 @@ metal_set_vertex_buffer_ios :: (self: *MetalGPU, h: u32) {
buf := metal_lookup_buffer(self, h);
if buf == null { return; }
// [encoder setVertexBuffer:buf offset:0 atIndex:0]
msg : (*void, *void, *void, u64, u64) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, *void, u64, u64) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setVertexBuffer:offset:atIndex:".ptr), buf, 0, 0);
}
@@ -656,7 +656,7 @@ metal_set_texture_ios :: (self: *MetalGPU, slot: u32, h: u32) {
tex := self.textures.items[h - 1].tex;
if tex == null { return; }
// [encoder setFragmentTexture:tex atIndex:slot]
msg : (*void, *void, *void, u64) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, *void, u64) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setFragmentTexture:atIndex:".ptr), tex, xx slot);
}
@@ -666,7 +666,7 @@ metal_set_vertex_constants_ios :: (self: *MetalGPU, slot: u32, data: *void, size
if data == null { return; }
if size_bytes <= 0 { return; }
// [encoder setVertexBytes:data length:size_bytes atIndex:slot]
msg : (*void, *void, *void, u64, u64) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, *void, u64, u64) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setVertexBytes:length:atIndex:".ptr),
data, xx size_bytes, xx slot);
}
@@ -676,7 +676,7 @@ metal_set_scissor_ios :: (self: *MetalGPU, x: i32, y: i32, w: i32, h: i32) {
if self.encoder == null { return; }
rect : MTLScissorRect = .{ x = xx x, y = xx y, width = xx w, height = xx h };
// [encoder setScissorRect:rect] (MTLScissorRect is 32 bytes → ptr byval)
msg : (*void, *void, MTLScissorRect) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, MTLScissorRect) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setScissorRect:".ptr), rect);
}
@@ -686,7 +686,7 @@ metal_disable_scissor_ios :: (self: *MetalGPU) {
// Metal has no "disable scissor" — set the rect to cover the full
// drawable so subsequent draws aren't clipped.
rect : MTLScissorRect = .{ x = 0, y = 0, width = xx self.pixel_w, height = xx self.pixel_h };
msg : (*void, *void, MTLScissorRect) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, MTLScissorRect) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("setScissorRect:".ptr), rect);
}
@@ -695,7 +695,7 @@ metal_draw_triangles_ios :: (self: *MetalGPU, vertex_offset: i32, vertex_count:
if self.encoder == null { return; }
if vertex_count <= 0 { return; }
// [encoder drawPrimitives:.triangle vertexStart:offset vertexCount:count]
msg : (*void, *void, u64, u64, u64) -> void callconv(.c) = xx objc_msgSend;
msg : (*void, *void, u64, u64, u64) -> void abi(.c) = xx objc_msgSend;
msg(self.encoder, sel_registerName("drawPrimitives:vertexStart:vertexCount:".ptr),
MTL_PRIMITIVE_TYPE_TRIANGLE, xx vertex_offset, xx vertex_count);
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)
}

View File

@@ -2,7 +2,7 @@
// pthreads (PLAN-HTTPZ S6).
//
// THE RE-ENTRY CONTRACT (pinned by examples/1636): a thread entry is a
// `callconv(.c)` function — it has NO implicit context — and enters
// `abi(.c)` function — it has NO implicit context — and enters
// the sx world by fabricating one: `push Context.{ allocator = xx gpa }`
// around the default-conv code it runs. Pool workers do exactly that,
// each with its own malloc-backed GPA, so tasks allocate freely and
@@ -26,7 +26,7 @@
tlib :: #library "c";
pthread_create :: (thread: *usize, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 extern tlib;
pthread_create :: (thread: *usize, attr: *void, start: (*void) -> *void abi(.c), arg: *void) -> i32 extern tlib;
pthread_join :: (thread: usize, retval: **void) -> i32 extern tlib;
pthread_detach :: (thread: usize) -> i32 extern tlib;
@@ -104,9 +104,9 @@ Cond :: struct {
Thread :: struct {
handle: usize = 0;
// `entry` is the C->sx boundary: callconv(.c), fabricates its own
// `entry` is the C->sx boundary: abi(.c), fabricates its own
// Context before touching default-conv sx code (examples/1636).
spawn :: (entry: (*void) -> *void callconv(.c), arg: *void) -> (Thread, !ThreadErr) {
spawn :: (entry: (*void) -> *void abi(.c), arg: *void) -> (Thread, !ThreadErr) {
t : Thread = .{};
if pthread_create(@t.handle, null, entry, arg) != 0 { raise error.Spawn; }
return t;
@@ -200,7 +200,7 @@ Pool :: struct {
// The worker loop: C entry, own fabricated Context, then
// pop-task/run-task until stop with an empty queue.
pool_worker :: (arg: *void) -> *void callconv(.c) {
pool_worker :: (arg: *void) -> *void abi(.c) {
p : *Pool = xx arg;
gpa := GPA.init();
push Context.{ allocator = xx gpa } {