 : ?delete-at ( key assoc -- old/key ? )
     2dup delete-at* [ 2nip t ] [ 2drop f ] if ; inline
 
-: cuda-int ( function offset value -- )
-    cuParamSeti cuda-error ; inline
-
-: cuda-float ( function offset value -- )
-    cuParamSetf cuda-error ; inline
+: cuda-param-size ( function n -- )
+    cuParamSetSize cuda-error ; inline
 
 : cuda-vector ( function offset ptr n -- )
     cuParamSetv cuda-error ; inline
-
-: param-size ( function n -- )
-    cuParamSetSize cuda-error ; inline
 
 : launch-function-grid ( function width height -- )
     cuLaunchGrid cuda-error ; inline

! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.data alien.parser arrays
assocs combinators cuda cuda.ffi fry io.backend kernel macros
math namespaces sequences words ;
QUALIFIED-WITH: alien.c-types c
IN: cuda.libraries


        ]
    } 2cleave ;

<PRIVATE
: make-param-buffer ( function size -- buffer size )
    [ cuda-param-size ] [ (byte-array) ] [ ] tri ; inline

: fill-param-buffer ( values... buffer quots... n -- )
    [ cleave-curry ] [ spread* ] bi ; inline

: >argument-type ( c-type -- c-type' )
    dup { [ c:void* = ] [ c:pointer? ] } 1|| [ drop CUdeviceptr ] when ;

: >argument-struct-slot ( type -- slot )
    "cuda-arg" swap >argument-type { } <struct-slot-spec> ;

: [cuda-arguments] ( c-types -- quot )
    [ >argument-struct-slot ] map
    [ compute-struct-offsets ]
    [ [ '[ _ write-struct-slot ] ] [ ] map-as ]
    [ length ] tri
    '[
        [ _ make-param-buffer [ drop @ _ fill-param-buffer ] 2keep ]
        [ '[ _ 0 ] 2dip cuda-vector ] bi
    ] ;
PRIVATE>

MACRO: cuda-arguments ( c-types -- quot: ( args... function -- ) )
    [ [ 0 cuda-param-size ] ] [ [cuda-arguments] ] if-empty ;

: get-function-ptr ( module string -- function )
    [ CUfunction <c-object> ] 2dip
