Or is it that once the lambda is compiled, it replaces the version with
generate-gl-function in it? Does that mean that the wrapper functions are
compiled on first call?


On 16 October 2013 13:42, Chris Bagley <chris.bag...@gmail.com> wrote:

> It seems to be compiling a new lambda on every call. I'll walk through my
> logic below:
>
> So I am looking at how (gen-buffers) is implemented.
>
> (defun gen-buffers (count)
>   (with-foreign-object (buffer-array '%gl:uint count)
>     (%gl:gen-buffers count buffer-array)
>     (loop for i below count
>           collecting (mem-aref buffer-array '%gl:uint i))))
>
> %gl:gen-buffers is deifned as
> (defglextfun ("glGenBuffers" gen-buffers) :void
>   (n sizei)
>   (buffers (:pointer uint)))
>
> which expands to:
> (progn
>  (declaim (notinline gen-buffers))
>  (defun gen-buffers (n buffers)
>    (generate-gl-function "glgenbuffers" 'gen-buffers ':void
>                          '((n sizei) (buffers (:pointer uint))) n buffers))
>  (setf (get 'gen-buffers 'proc-address-dummy) #'gen-buffers)
>  'gen-buffers)
>
> and generate-gl-function
> (defun generate-gl-function (foreign-name lisp-name result-type body &rest
> args)
>   (let ((address (gl-get-proc-address foreign-name))
>         (arg-list (mapcar #'first body)))
>     (when (or (not (pointerp address)) (null-pointer-p address))
>       (error "Couldn't find function ~A" foreign-name))
>     (compile lisp-name
>              `(lambda ,arg-list
>                 (multiple-value-prog1
>                     (foreign-funcall-pointer
>                      ,address
>                      (:library opengl)
>                      ,@(loop for i in body
>                           collect (second i)
>                           collect (first i))
>                      ,result-type)
>                   #-cl-opengl-no-check-error
>                   (check-error ',lisp-name))))
>     (apply lisp-name args)))
>
> What is going on here? I don't believe that it is recompiling the wrapper
> function on every call, but I'm having issues working out how else this
> works.
> Hope someone can help me out here.
> Cheers
> Baggers
>
>

Reply via email to