@@ -47,14 +47,14 @@ Print a formatted string in device context on the host standard output.
4747macro mtlprintf (fmt:: String , args... )
4848 fmt_val = Val (Symbol (fmt))
4949
50- quote
50+ return quote
5151 _mtlprintf ($ fmt_val, $ (map (arg -> :(promote_c_argument ($ arg)), esc .(args))... ))
5252 end
5353end
5454
5555@generated function _mtlprintf (:: Val{fmt} , argspec... ) where {fmt}
56- @dispose ctx= Context () begin
57- arg_exprs = [:( argspec[$ i] ) for i in 1 : length (argspec)]
56+ return @dispose ctx = Context () begin
57+ arg_exprs = [:(argspec[$ i]) for i in 1 : length (argspec)]
5858 arg_types = [argspec... ]
5959
6060 T_void = LLVM. VoidType ()
6868 wrapper_f, wrapper_ft = create_function (T_void, param_types)
6969 mod = LLVM. parent (wrapper_f)
7070
71- llvm_ft = LLVM. FunctionType (T_void, LLVMType[]; vararg= true )
71+ llvm_ft = LLVM. FunctionType (T_void, LLVMType[]; vararg = true )
7272 llvm_f = LLVM. Function (mod, " metal_os_log" , llvm_ft)
7373 push! (function_attributes (llvm_f), EnumAttribute (" alwaysinline" , 0 ))
7474
7575 # generate IR
76- @dispose builder= IRBuilder () begin
76+ @dispose builder = IRBuilder () begin
7777 entry = BasicBlock (llvm_f, " entry" )
7878 position! (builder, entry)
7979
80- str = globalstring_ptr! (builder, String (fmt), addrspace= 2 )
81- subsystem_str = globalstring_ptr! (builder, MTLLOG_SUBSYSTEM, addrspace= 2 )
82- category_str = globalstring_ptr! (builder, MTLLOG_CATEGORY, addrspace= 2 )
80+ str = globalstring_ptr! (builder, String (fmt), addrspace = 2 )
81+ subsystem_str = globalstring_ptr! (builder, MTLLOG_SUBSYSTEM, addrspace = 2 )
82+ category_str = globalstring_ptr! (builder, MTLLOG_CATEGORY, addrspace = 2 )
8383 log_type = LLVM. ConstantInt (T_int32, __METAL_OS_LOG_TYPE_DEBUG__)
8484
8585 # compute argsize
115115 ret! (builder)
116116 end
117117
118- @dispose builder= IRBuilder () begin
118+ @dispose builder = IRBuilder () begin
119119 entry = BasicBlock (wrapper_f, " entry" )
120120 position! (builder, entry)
121121
@@ -137,29 +137,29 @@ export @mtlprint, @mtlprintln
137137# simple conversions, defining an expression and the resulting argument type. nothing fancy,
138138# `@mtlprint` pretty directly maps to `@mtlprintf`; we should just support `write(::IO)`.
139139const mtlprint_conversions = [
140- Float32 => (x-> :(Float64 ($ x)), Float64),
141- Ptr{<: Any } => (x-> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
142- LLVMPtr{<: Any } => (x-> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
143- Bool => (x-> :(Int32 ($ x)), Int32),
140+ Float32 => (x -> :(Float64 ($ x)), Float64),
141+ Ptr{<: Any } => (x -> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
142+ LLVMPtr{<: Any } => (x -> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
143+ Bool => (x -> :(Int32 ($ x)), Int32),
144144]
145145
146146# format specifiers
147147const mtlprint_specifiers = Dict (
148148 # integers
149- Int16 => " %hd" ,
150- Int32 => " %d" ,
151- Int64 => " %ld" ,
152- UInt16 => " %hu" ,
153- UInt32 => " %u" ,
154- UInt64 => " %lu" ,
149+ Int16 => " %hd" ,
150+ Int32 => " %d" ,
151+ Int64 => " %ld" ,
152+ UInt16 => " %hu" ,
153+ UInt32 => " %u" ,
154+ UInt64 => " %lu" ,
155155
156156 # floating-point
157- Float32 => " %f" ,
157+ Float32 => " %f" ,
158158
159159 # other
160- Cchar => " %c" ,
161- Ptr{Cvoid} => " %p" ,
162- Cstring => " %s" ,
160+ Cchar => " %c" ,
161+ Ptr{Cvoid} => " %p" ,
162+ Cstring => " %s" ,
163163)
164164
165165@inline @generated function _mtlprint (parts... )
@@ -217,7 +217,7 @@ const mtlprint_specifiers = Dict(
217217 end
218218 end
219219
220- quote
220+ return quote
221221 @mtlprintf ($ fmt, $ (args... ))
222222 end
223223end
@@ -240,7 +240,7 @@ Limited string interpolation is also possible:
240240```
241241"""
242242macro mtlprint (parts... )
243- args = Union{Val,Expr,Symbol}[]
243+ args = Union{Val, Expr, Symbol}[]
244244
245245 parts = [parts... ]
246246 while true
@@ -266,16 +266,18 @@ macro mtlprint(parts...)
266266 end
267267 end
268268
269- quote
269+ return quote
270270 _mtlprint ($ (map (esc, args)... ))
271271 end
272272end
273273
274274@doc (@doc @mtlprint ) ->
275275macro mtlprintln (parts... )
276- esc (quote
277- Metal. @mtlprint ($ (parts... ), " \n " )
278- end )
276+ return esc (
277+ quote
278+ Metal. @mtlprint ($ (parts... ), " \n " )
279+ end
280+ )
279281end
280282
281283export @mtlshow
@@ -292,9 +294,17 @@ GPU analog of `Base.@show`. It comes with the same type restrictions as [`@mtlpr
292294macro mtlshow (exs... )
293295 blk = Expr (:block )
294296 for ex in exs
295- push! (blk. args, :(Metal. @mtlprintln ($ (sprint (Base. show_unquoted,ex)* " = " ),
296- begin local value = $ (esc (ex)) end )))
297+ push! (
298+ blk. args, :(
299+ Metal. @mtlprintln (
300+ $ (sprint (Base. show_unquoted, ex) * " = " ),
301+ begin
302+ local value = $ (esc (ex))
303+ end
304+ )
305+ )
306+ )
297307 end
298308 isempty (exs) || push! (blk. args, :value )
299- blk
309+ return blk
300310end
0 commit comments