Continues the implicit-Context refactor. Bare-fn trampolines, lambda trampolines, and protocol thunks now carry __sx_ctx at slot 0; call sites for closures, fn-pointer variables, and method dispatch prepend the caller's current ctx. - emit_llvm.zig:1687 call_indirect treats `fp_ctx_slots` leading args as opaque ptr (the implicit ctx) when the fn-pointer is default-conv under has_implicit_ctx. - lower.zig:fnPtrTypeWantsCtx predicate gates the prepend at both scope-local and global fn-pointer call sites. - lower.zig:fixupMethodReceiver skips __sx_ctx when probing the receiver param's type. - lower.zig:lowerLambda builds closure type from user-visible params only (skip ctx + env). - lower.zig:closure(bare_fn) builds closure type from user-visible params only. - module.zig: Module.has_implicit_ctx flag mirrors Lowering's switch so emit_llvm can read it without a back-pointer. Tests updated: - 5 ObjC-block/runtime tests get `callconv(.c)` on fn-ptr types cast from `objc_msgSend` / Block.invoke (C-side calls into sx). - ffi-06-callback gets `callconv(.c)` on double_it/add_with_ctx — the registered C-side callbacks. - 08-types snapshot regen (undefined-init drift from layout shift). - 11 JNI/ObjC .ir snapshots regen for the ctx-prepended thunk signatures. 151/152 example tests pass. Remaining failure (05-run) is the comptime/interp path that requires Step 7 (callWithDefaultContext).
20 lines
495 B
Plaintext
20 lines
495 B
Plaintext
// `xx <closure>` passed as a `*Block` fn argument auto-allocates the
|
|
// Block instance and passes its address — no named temp required.
|
|
// Matches the ergonomics of ObjC's `^{...}` literal at the call site.
|
|
|
|
#import "modules/std.sx";
|
|
#import "modules/std/objc_block.sx";
|
|
|
|
invoke_once :: (b: *Block) {
|
|
invoke_fn : (*Block) -> void callconv(.c) = xx b.invoke;
|
|
invoke_fn(b);
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
x : s64 = 7;
|
|
invoke_once(xx () => {
|
|
print("inline block, x = {}\n", x);
|
|
});
|
|
0;
|
|
}
|