@@ -13,36 +13,36 @@ pub fn msgSend(comptime ReturnType: type, target: anytype, selector: SEL, args:
1313 const FnType = blk : {
1414 {
1515 // TODO(hazeycode): replace this hack with the more generalised code above once it doens't crash the compiler
16- break :blk switch (args_meta .len ) {
16+ break :blk * const switch (args_meta .len ) {
1717 0 = > fn (@TypeOf (target ), SEL ) callconv (.C ) ReturnType ,
18- 1 = > fn (@TypeOf (target ), SEL , args_meta [0 ].field_type ) callconv (.C ) ReturnType ,
19- 2 = > fn (@TypeOf (target ), SEL , args_meta [0 ].field_type , args_meta [1 ].field_type ) callconv (.C ) ReturnType ,
20- 3 = > fn (@TypeOf (target ), SEL , args_meta [0 ].field_type , args_meta [1 ].field_type , args_meta [2 ].field_type ) callconv (.C ) ReturnType ,
21- 4 = > fn (@TypeOf (target ), SEL , args_meta [0 ].field_type , args_meta [1 ].field_type , args_meta [2 ].field_type , args_meta [3 ].field_type ) callconv (.C ) ReturnType ,
22- 5 = > fn (@TypeOf (target ), SEL , args_meta [0 ].field_type , args_meta [1 ].field_type , args_meta [2 ].field_type , args_meta [3 ].field_type , args_meta [4 ].field_type ) callconv (.C ) ReturnType ,
18+ 1 = > fn (@TypeOf (target ), SEL , args_meta [0 ].type ) callconv (.C ) ReturnType ,
19+ 2 = > fn (@TypeOf (target ), SEL , args_meta [0 ].type , args_meta [1 ].type ) callconv (.C ) ReturnType ,
20+ 3 = > fn (@TypeOf (target ), SEL , args_meta [0 ].type , args_meta [1 ].type , args_meta [2 ].type ) callconv (.C ) ReturnType ,
21+ 4 = > fn (@TypeOf (target ), SEL , args_meta [0 ].type , args_meta [1 ].type , args_meta [2 ].type , args_meta [3 ].type ) callconv (.C ) ReturnType ,
22+ 5 = > fn (@TypeOf (target ), SEL , args_meta [0 ].type , args_meta [1 ].type , args_meta [2 ].type , args_meta [3 ].type , args_meta [4 ].type ) callconv (.C ) ReturnType ,
2323 else = > @compileError ("Unsupported number of args: add more variants in zig-objcrt/src/message.zig" ),
2424 };
2525 }
2626 };
2727 // NOTE: func is a var because making it const causes a compile error which I believe is a compiler bug
28- var func = @as (FnType , @ptrCast (c .objc_msgSend ));
29- return @call (.{} , func , .{ target , selector } ++ args );
28+ var func = @as (FnType , @ptrCast (& c .objc_msgSend ));
29+ return @call (.auto , func , .{ target , selector } ++ args );
3030 } else {
3131 const FnType = blk : {
3232 {
3333 // TODO(hazeycode): replace this hack with the more generalised code above once it doens't crash the compiler
34- break :blk switch (args_meta .len ) {
34+ break :blk * const switch (args_meta .len ) {
3535 0 = > fn (* ReturnType , @TypeOf (target ), SEL ) callconv (.C ) void ,
36- 1 = > fn (* ReturnType , @TypeOf (target ), SEL , args_meta [0 ].field_type ) callconv (.C ) void ,
37- 2 = > fn (* ReturnType , @TypeOf (target ), SEL , args_meta [0 ].field_type , args_meta [1 ].field_type ) callconv (.C ) void ,
36+ 1 = > fn (* ReturnType , @TypeOf (target ), SEL , args_meta [0 ].type ) callconv (.C ) void ,
37+ 2 = > fn (* ReturnType , @TypeOf (target ), SEL , args_meta [0 ].type , args_meta [1 ].type ) callconv (.C ) void ,
3838 else = > @compileError ("Unsupported number of args: add more variants in zig-objcrt/src/message.zig" ),
3939 };
4040 }
4141 };
4242 // NOTE: func is a var because making it const causes a compile error which I believe is a compiler bug
43- var func = @as (FnType , @ptrCast (c .objc_msgSend_stret ));
43+ var func = @as (FnType , @ptrCast (& c .objc_msgSend_stret ));
4444 var stret : ReturnType = undefined ;
45- _ = @call (.{} , func , .{ & stret , target , selector } ++ args );
45+ _ = @call (.auto , func , .{ & stret , target , selector } ++ args );
4646 return stret ;
4747 }
4848}
@@ -143,20 +143,13 @@ pub fn getClass(class_name: [:0]const u8) Error!Class {
143143 return c .objc_getClass (class_name ) orelse Error .ClassNotRegisteredWithRuntime ;
144144}
145145
146- pub const CGFloat = switch (@import ("builtin" ).cpu . arch .ptrBitWidth ()) {
146+ pub const CGFloat = switch (@import ("builtin" ).target .ptrBitWidth ()) {
147147 64 = > f64 ,
148148 32 = > f32 ,
149149 else = > unreachable ,
150150};
151151
152152pub const NSRect = CGRect ;
153- pub const NSRectMake = CGRectMake ;
154- pub fn CGRectMake (x : CGFloat , y : CGFloat , width : CGFloat , height : CGFloat ) CGRect {
155- return CGRect {
156- .origin = .{ .x = x , .y = y },
157- .size = .{ .width = width , .height = height },
158- };
159- }
160153
161154pub const CGPoint = extern struct {
162155 x : CGFloat ,
@@ -171,4 +164,11 @@ pub const CGSize = extern struct {
171164pub const CGRect = extern struct {
172165 origin : CGPoint ,
173166 size : CGSize ,
167+
168+ pub fn make (x : CGFloat , y : CGFloat , w : CGFloat , h : CGFloat ) CGRect {
169+ return .{
170+ .origin = .{ .x = x , .y = y },
171+ .size = .{ .width = w , .height = h },
172+ };
173+ }
174174};
0 commit comments