From: Frank Goenninger DG1SBG
Subject: Macrology: Macro for calling macro defcallback (OpenMCL)
Date: 
Message-ID: <m2pt30pn3q.fsf@pcsde001.de.goenninger.com>
Hi all:

I want to define a macro to call the defcallback macro in OpenMCL. 
I assume it's my basic knowledge of macrology and not a problem of
a specific implementation.

So, any hints on the following non-working source code is 
appreciated!

#1: Definition of the DEFCALLBACK macro in OpenMCL:

Macro  DEFCALLBACK 

Syntax:  defcallback name ({arg-type-specifier var}*   
                          &optional result-type-specifier)   
                          &body   body 

#2: Working example from OpenMCL's example source code

(ccl::defcallback reshape-cb (:int w :int h)
    (format t "reshape-cb: w=~D h=~D~%" w h))


#3: My macro:

(defmacro ff-defun-callable (call-convention result-type name args &body body)
  (declare (ignorable result-type))
  (declare (ignorable call-convention))
  `(ccl:defcallback ,name
	            ,(list args)
                    ,@body))

Problem/error I get is:

Unknown foreign type: (:VOID)
   [Condition of type SIMPLE-ERROR]

Backtrace:
  0: (CCL::%PARSE-FOREIGN-TYPE '((:VOID)))
  1: (CCL::PARSE-FOREIGN-TYPE '(:VOID))
  2: (CCL::FOREIGN-TYPE-TO-REPRESENTATION-TYPE '((:VOID)))
  3: (DEFINE-CALLBACK 'CL-OPENGL::MGWCLOSE '((:VOID)) '((PRINT "closing callback entered")) #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>)
      Locals:
        CCL::NAME = CL-OPENGL::MGWCLOSE
        CCL::ARGS = ((:VOID))
        CCL::BODY = ((PRINT "closing callback entered"))
        CCL::ENV = #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>
        CCL::STACK-WORD = #:G24663
        CCL::STACK-PTR = #:G24664
        CCL::RETURN-TYPE = #<VALUE-CELL (:VOID) #x69D259E>
        CCL::WOI = #<VALUE-CELL NIL #x69D2596>
        CCL::MONITOR = #<VALUE-CELL NIL #x69D258E>
        CCL::DYNAMIC-EXTENT-NAMES = #<VALUE-CELL NIL #x69D2586>
        CCL::ERROR-RETURN = #<VALUE-CELL NIL #x69D257E>
      [No catch-tags]

So, I know I have to get rid of the args being passed as a list - 
or that's what I assume, anyway. Is that true?

When passing ,args without being a list I get another error indicating that passing the args and the name of the callback got mixed up. So...?????

Thx for any help here! If I should provide more info pls tell me!

Frank

From: Barry Margolin
Subject: Re: Macrology: Macro for calling macro defcallback (OpenMCL)
Date: 
Message-ID: <barmar-AFE0BC.07433830102004@comcast.dca.giganews.com>
In article <··············@pcsde001.de.goenninger.com>,
 Frank Goenninger DG1SBG <················@t-online.de> wrote:

> Hi all:
> 
> I want to define a macro to call the defcallback macro in OpenMCL. 
> I assume it's my basic knowledge of macrology and not a problem of
> a specific implementation.
> 
> So, any hints on the following non-working source code is 
> appreciated!
> 
> #1: Definition of the DEFCALLBACK macro in OpenMCL:
> 
> Macro  DEFCALLBACK 
> 
> Syntax:  defcallback name ({arg-type-specifier var}*   
>                           &optional result-type-specifier)   
>                           &body   body 
> 
> #2: Working example from OpenMCL's example source code
> 
> (ccl::defcallback reshape-cb (:int w :int h)
>     (format t "reshape-cb: w=~D h=~D~%" w h))
> 
> 
> #3: My macro:
> 
> (defmacro ff-defun-callable (call-convention result-type name args &body 
> body)
>   (declare (ignorable result-type))
>   (declare (ignorable call-convention))
>   `(ccl:defcallback ,name
> 	            ,(list args)
>                     ,@body))
> 
> Problem/error I get is:
> 
> Unknown foreign type: (:VOID)
>    [Condition of type SIMPLE-ERROR]
> 
> Backtrace:
>   0: (CCL::%PARSE-FOREIGN-TYPE '((:VOID)))
>   1: (CCL::PARSE-FOREIGN-TYPE '(:VOID))
>   2: (CCL::FOREIGN-TYPE-TO-REPRESENTATION-TYPE '((:VOID)))
>   3: (DEFINE-CALLBACK 'CL-OPENGL::MGWCLOSE '((:VOID)) '((PRINT "closing 
>   callback entered")) #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>)
>       Locals:
>         CCL::NAME = CL-OPENGL::MGWCLOSE
>         CCL::ARGS = ((:VOID))
>         CCL::BODY = ((PRINT "closing callback entered"))
>         CCL::ENV = #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>
>         CCL::STACK-WORD = #:G24663
>         CCL::STACK-PTR = #:G24664
>         CCL::RETURN-TYPE = #<VALUE-CELL (:VOID) #x69D259E>
>         CCL::WOI = #<VALUE-CELL NIL #x69D2596>
>         CCL::MONITOR = #<VALUE-CELL NIL #x69D258E>
>         CCL::DYNAMIC-EXTENT-NAMES = #<VALUE-CELL NIL #x69D2586>
>         CCL::ERROR-RETURN = #<VALUE-CELL NIL #x69D257E>
>       [No catch-tags]
> 
> So, I know I have to get rid of the args being passed as a list - 
> or that's what I assume, anyway. Is that true?

Yes, that's the problem.  ARGS already contains a list, and you're 
wrapping it in another list when you use (list args).

> 
> When passing ,args without being a list I get another error indicating that 
> passing the args and the name of the callback got mixed up. So...?????

Not sure why this is happening.  Post the new version of your macro and 
the backtrace.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Frank Goenninger DG1SBG
Subject: Re: Macrology: Macro for calling macro defcallback (OpenMCL)
Date: 
Message-ID: <m2hdocpfmv.fsf@pcsde001.de.goenninger.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <··············@pcsde001.de.goenninger.com>,
>  Frank Goenninger DG1SBG <················@t-online.de> wrote:
>
>> Hi all:
>> 
>> I want to define a macro to call the defcallback macro in OpenMCL. 
>> I assume it's my basic knowledge of macrology and not a problem of
>> a specific implementation.
>> 
>> So, any hints on the following non-working source code is 
>> appreciated!
>> 
>> #1: Definition of the DEFCALLBACK macro in OpenMCL:
>> 
>> Macro  DEFCALLBACK 
>> 
>> Syntax:  defcallback name ({arg-type-specifier var}*   
>>                           &optional result-type-specifier)   
>>                           &body   body 
>> 
>> #2: Working example from OpenMCL's example source code
>> 
>> (ccl::defcallback reshape-cb (:int w :int h)
>>     (format t "reshape-cb: w=~D h=~D~%" w h))
>> 
>> 
>> #3: My macro:
>> 
>> (defmacro ff-defun-callable (call-convention result-type name args &body 
>> body)
>>   (declare (ignorable result-type))
>>   (declare (ignorable call-convention))
>>   `(ccl:defcallback ,name
>> 	            ,(list args)
>>                     ,@body))
>> 
>> Problem/error I get is:
>> 
>> Unknown foreign type: (:VOID)
>>    [Condition of type SIMPLE-ERROR]
>> 
>> Backtrace:
>>   0: (CCL::%PARSE-FOREIGN-TYPE '((:VOID)))
>>   1: (CCL::PARSE-FOREIGN-TYPE '(:VOID))
>>   2: (CCL::FOREIGN-TYPE-TO-REPRESENTATION-TYPE '((:VOID)))
>>   3: (DEFINE-CALLBACK 'CL-OPENGL::MGWCLOSE '((:VOID)) '((PRINT "closing 
>>   callback entered")) #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>)
>>       Locals:
>>         CCL::NAME = CL-OPENGL::MGWCLOSE
>>         CCL::ARGS = ((:VOID))
>>         CCL::BODY = ((PRINT "closing callback entered"))
>>         CCL::ENV = #<CCL::LEXICAL-ENVIRONMENT #x69C5BE6>
>>         CCL::STACK-WORD = #:G24663
>>         CCL::STACK-PTR = #:G24664
>>         CCL::RETURN-TYPE = #<VALUE-CELL (:VOID) #x69D259E>
>>         CCL::WOI = #<VALUE-CELL NIL #x69D2596>
>>         CCL::MONITOR = #<VALUE-CELL NIL #x69D258E>
>>         CCL::DYNAMIC-EXTENT-NAMES = #<VALUE-CELL NIL #x69D2586>
>>         CCL::ERROR-RETURN = #<VALUE-CELL NIL #x69D257E>
>>       [No catch-tags]
>> 
>> So, I know I have to get rid of the args being passed as a list - 
>> or that's what I assume, anyway. Is that true?
>
> Yes, that's the problem.  ARGS already contains a list, and you're 
> wrapping it in another list when you use (list args).
>
Well, seems as if I got it right then, in a sense ;-)

>> 
>> When passing ,args without being a list I get another error indicating that 
>> passing the args and the name of the callback got mixed up. So...?????
>
> Not sure why this is happening.  Post the new version of your macro and 
> the backtrace.
>
Here you go:

(defmacro ff-defun-callable (call-convention result-type name args &body body)
  (declare (ignorable result-type))
  (declare (ignorable call-convention))
  `(ccl:defcallback ,name
 	            ,args
                    ,@body)) 

And the new error and backtrace are (look at the locals CCL::NAME,
CCL::ARGS, and CCL::BODY ...):

value CL-OPENGL::MGWKEY is not of the expected type LIST.
   [Condition of type TYPE-ERROR]

Backtrace:
  0: (DEFINE-CALLBACK '(CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y) 'CL-OPENGL::MGWKEY '(((CL-OPENGL::K :INT) (CL-OPENGL::X :INT) (CL-OPENGL::Y :INT)) (PRINT 'CL-OPENGL::BINGO) (CL-OPENGL::MGWKEYI CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y)) #<CCL::LEXICAL-ENVIRONMENT #x69240F6>)
      Locals:
        CCL::NAME = (CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y)
        CCL::ARGS = CL-OPENGL::MGWKEY
        CCL::BODY = (((CL-OPENGL::K :INT) (CL-OPENGL::X :INT) (CL-OPENGL::Y :INT)) (PRINT 'CL-OPENGL::BINGO) (CL-OPENGL::MGWKEYI CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y))
        CCL::ENV = #<CCL::LEXICAL-ENVIRONMENT #x687D6F6>
        CCL::STACK-WORD = #:G26472
        CCL::STACK-PTR = #:G26473
        CCL::RETURN-TYPE = #<VALUE-CELL :VOID #x688060E>
        CCL::WOI = #<VALUE-CELL NIL #x6880606>
        CCL::MONITOR = #<VALUE-CELL NIL #x68805FE>
        CCL::DYNAMIC-EXTENT-NAMES = #<VALUE-CELL NIL #x68805F6>
        CCL::ERROR-RETURN = #<VALUE-CELL NIL #x68805EE>
      [No catch-tags]
  1: (DEFCALLBACK '(DEFCALLBACK (CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y) CL-OPENGL::MGWKEY ((CL-OPENGL::K :INT) (CL-OPENGL::X :INT) (CL-OPENGL::Y :INT)) (PRINT 'CL-OPENGL::BINGO) (CL-OPENGL::MGWKEYI CL-OPENGL::K CL-OPENGL::X CL-OPENGL::Y)) #<CCL::LEXICAL-ENVIRONMENT #x69240F6>)
  2: (FUNCALL #<Compiled-function DEFCALLBACK Macroexpander #x6256386>)
  3: (MACROEXPAND-1 'DEFCALLBACK #<CCL::LEXICAL-ENVIRONMENT #x69240F6>)

Oh, btw, the callback is defined as:

(ff-defun-callable :cdecl :void mgwclose (:void) ;frgo: CHANGED: :void inserted
  (print "closing callback entered"))

> -- 
> Barry Margolin, ······@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***

Thx, Barry!

Frank
From: Barry Margolin
Subject: Re: Macrology: Macro for calling macro defcallback (OpenMCL)
Date: 
Message-ID: <barmar-E196E0.13030030102004@comcast.dca.giganews.com>
In article <··············@pcsde001.de.goenninger.com>,
 Frank Goenninger DG1SBG <················@t-online.de> wrote:

> (defmacro ff-defun-callable (call-convention result-type name args &body body)
>   (declare (ignorable result-type))
>   (declare (ignorable call-convention))
>   `(ccl:defcallback ,name
>                ,args
>                     ,@body)) 
...
> Oh, btw, the callback is defined as:
> 
> (ff-defun-callable :cdecl :void mgwclose (:void) ;frgo: CHANGED: :void 
> inserted
>   (print "closing callback entered"))

The documentation of DEFCALLBACK said that the argument list is supposed 
to be an alternating sequence of types and variables, followed 
optionally by the result type.  So you have to supply an even-length 
list for the ARGS parameter to FF-DEFUN-CALLABLE.

Have you looked at the result of (macroexpand '(ff-defun-callable ...)) 
to see if it's producing a valid-looking DEFCALLBACK?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Kalle Olavi Niemitalo
Subject: Re: Macrology: Macro for calling macro defcallback (OpenMCL)
Date: 
Message-ID: <87is8s1b13.fsf@Astalo.kon.iki.fi>
Frank Goenninger DG1SBG <················@t-online.de> writes:

> Oh, btw, the callback is defined as:
>
> (ff-defun-callable :cdecl :void mgwclose (:void) ;frgo: CHANGED: :void inserted
>   (print "closing callback entered"))

Then why did the backtrace say MGWKEY, rather than MGWCLOSE?