@@ -538,9 +538,41 @@ function generate_opaque_closure(config::CompilerConfig, src::CodeInfo,
538
538
return OpaqueClosure {id, typeof(env), sig, rt} (env)
539
539
end
540
540
541
+ # generated function `ccall`, working around the restriction that ccall type
542
+ # tuples need to be literals. this relies on ccall internals...
543
+ @inline @generated function generated_ccall (f:: Ptr , _rettyp, _types, vals... )
544
+ ex = quote end
545
+
546
+ rettyp = _rettyp. parameters[1 ]
547
+ types = _types. parameters[1 ]. parameters
548
+ args = [:(vals[$ i]) for i in 1 : length (vals)]
549
+
550
+ # cconvert
551
+ cconverted = [Symbol (" cconverted_$i " ) for i in 1 : length (vals)]
552
+ for (dst, typ, src) in zip (cconverted, types, args)
553
+ append! (ex. args, (quote
554
+ $ dst = Base. cconvert ($ typ, $ src)
555
+ end ). args)
556
+ end
557
+
558
+ # unsafe_convert
559
+ unsafe_converted = [Symbol (" unsafe_converted_$i " ) for i in 1 : length (vals)]
560
+ for (dst, typ, src) in zip (unsafe_converted, types, cconverted)
561
+ append! (ex. args, (quote
562
+ $ dst = Base. unsafe_convert ($ typ, $ src)
563
+ end ). args)
564
+ end
565
+
566
+ call = Expr (:foreigncall , :f , rettyp, Core. svec (types... ), 0 ,
567
+ QuoteNode (:ccall ), unsafe_converted... , cconverted... )
568
+ push! (ex. args, call)
569
+ return ex
570
+ end
571
+
541
572
# device-side call to an opaque closure
542
- function (oc:: OpaqueClosure{F} )(a, b ) where F
573
+ function (oc:: OpaqueClosure{F,E,A,R } )(args ... ) where {F,E,A,R}
543
574
ptr = ccall (" extern deferred_codegen" , llvmcall, Ptr{Cvoid}, (Int,), F)
544
575
assume (ptr != C_NULL )
545
- return ccall (ptr, Int, (Int, Int), a, b)
576
+ # ccall(ptr, R, (A...), args...)
577
+ generated_ccall (ptr, R, A, args... )
546
578
end
0 commit comments