@@ -361,9 +361,41 @@ function generate_opaque_closure(config::CompilerConfig, src::CodeInfo,
361
361
return OpaqueClosure {id, typeof(env), sig, rt} (env)
362
362
end
363
363
364
+ # generated function `ccall`, working around the restriction that ccall type
365
+ # tuples need to be literals. this relies on ccall internals...
366
+ @inline @generated function generated_ccall (f:: Ptr , _rettyp, _types, vals... )
367
+ ex = quote end
368
+
369
+ rettyp = _rettyp. parameters[1 ]
370
+ types = _types. parameters[1 ]. parameters
371
+ args = [:(vals[$ i]) for i in 1 : length (vals)]
372
+
373
+ # cconvert
374
+ cconverted = [Symbol (" cconverted_$i " ) for i in 1 : length (vals)]
375
+ for (dst, typ, src) in zip (cconverted, types, args)
376
+ append! (ex. args, (quote
377
+ $ dst = Base. cconvert ($ typ, $ src)
378
+ end ). args)
379
+ end
380
+
381
+ # unsafe_convert
382
+ unsafe_converted = [Symbol (" unsafe_converted_$i " ) for i in 1 : length (vals)]
383
+ for (dst, typ, src) in zip (unsafe_converted, types, cconverted)
384
+ append! (ex. args, (quote
385
+ $ dst = Base. unsafe_convert ($ typ, $ src)
386
+ end ). args)
387
+ end
388
+
389
+ call = Expr (:foreigncall , :f , rettyp, Core. svec (types... ), 0 ,
390
+ QuoteNode (:ccall ), unsafe_converted... , cconverted... )
391
+ push! (ex. args, call)
392
+ return ex
393
+ end
394
+
364
395
# device-side call to an opaque closure
365
- function (oc:: OpaqueClosure{F} )(a, b ) where F
396
+ function (oc:: OpaqueClosure{F,E,A,R } )(args ... ) where {F,E,A,R}
366
397
ptr = ccall (" extern deferred_codegen" , llvmcall, Ptr{Cvoid}, (Int,), F)
367
398
assume (ptr != C_NULL )
368
- return ccall (ptr, Int, (Int, Int), a, b)
399
+ # ccall(ptr, R, (A...), args...)
400
+ generated_ccall (ptr, R, A, args... )
369
401
end
0 commit comments