From: Luke Crook
Subject: Lispworks foreign-parser and #defines
Date: 
Message-ID: <1123172197.993073.271590@f14g2000cwb.googlegroups.com>
The Lispworks FFI parser seems to skip all #defines in my C header
files. Even ones as simple as #define A_DEFINE 100 . Is there an option
I am not setting or do I need to manually create bindings for #defines?

-Luke

From: Edi Weitz
Subject: Re: Lispworks foreign-parser and #defines
Date: 
Message-ID: <ud5ot7irg.fsf@agharta.de>
On 4 Aug 2005 09:16:38 -0700, "Luke Crook" <····@balooga.com> wrote:

> The Lispworks FFI parser seems to skip all #defines in my C header
> files.

  ···@vmware:/tmp$ cat foo.c
  #define FOO_TYPE float

  FOO_TYPE frob (FOO_TYPE x) {
    return 2 * x;
  }
  ···@vmware:/tmp$ lw
  LispWorks(R): The Common Lisp Programming Environment
  Copyright (C) 1987-2005 LispWorks Ltd.  All rights reserved.
  Version 4.4.5
  Saved by edi as lw-console, at 26 Apr 2005 11:21
  User edi on vmware
  ; Loading text file /usr/local/lib/LispWorks/lib/4-4-0-0/config/siteinit.lisp
  ;  Loading text file /usr/local/lib/LispWorks/lib/4-4-0-0/private-patches/load.lisp
  ; Loading text file /home/edi/.lispworks

  CL-USER 1 > (require "foreign-parser")
  ; Loading fasl file /usr/local/lib/LispWorks/lib/4-4-0-0/load-on-demand/pcl/concat/foreign-parser.ufsl
  ;  Loading fasl file /usr/local/lib/LispWorks/lib/4-4-0-0/load-on-demand/pcl/concat/foreign-preprocessor.ufsl
  ;; C++ grammar - Portions Copyright (c) 1989, 1990 James A. Roskind
  ;  Loading fasl file /usr/local/lib/LispWorks/lib/4-4-0-0/load-on-demand/pcl/concat/parser-runtime.ufsl
  T

  CL-USER 2 > (foreign-parser:process-foreign-file "foo.c" :case-sensitive nil)
  ;;;    Output dff file #P"foo-dff.lisp"
  ;;;    Parsing source file "foo.c"

  ;;; Process-foreign-file : Preprocessing file

  ;;; Process-foreign-file : Level 1 parsing

  ;;; Process-foreign-file : Selecting foreign forms
  NIL

  CL-USER 3 > (quit)
  ···@vmware:/tmp$ cat foo-dff.lisp 
  #| DATE           : 4 Aug 2005 
   | USER           : edi 
   | PROCESSED FILE : foo.c
   |#

  (in-package "COMMON-LISP-USER")

  ;;; Derived from file : "/tmp/foo.c"

  (fli:define-foreign-function (frob "frob" :source)
                               ((x :float))
                               :result-type
                               :float
                               :language
                               :ansi-c)

Looks to me as if the #define wasn't skipped.  I'm pretty sure the
file is fed to the C preprocessor before it's parsed so the #define is
used but LispWorks doesn't see it.

> Even ones as simple as #define A_DEFINE 100 . Is there an option I
> am not setting or do I need to manually create bindings for
> #defines?

What do you expect the result of #define A_DEFINE 100 to be on the
Lisp side?  A DEFCONSTANT?

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Luke Crook
Subject: Re: Lispworks foreign-parser and #defines
Date: 
Message-ID: <1123177257.427210.306700@g14g2000cwa.googlegroups.com>
Edi Weitz wrote:

> What do you expect the result of #define A_DEFINE 100 to be on the
> Lisp side?  A DEFCONSTANT?


Edi, thanks for your detailed response. Yes, I would need the #define
to be converted into a defconstant as these defines need to be passed
from the Lisp code to the C library. For example;


#define SDL_INIT_VIDEO 10
#define SDL_INIT_AUDIO 20


(SDL-Init (logior sdl:SDL-INIT-VIDEO sdl:SDL-INIT-AUDIO))
From: Edi Weitz
Subject: Re: Lispworks foreign-parser and #defines
Date: 
Message-ID: <u8xzh7ddy.fsf@agharta.de>
On 4 Aug 2005 10:40:57 -0700, "Luke Crook" <····@balooga.com> wrote:

> Yes, I would need the #define to be converted into a defconstant as
> these defines need to be passed from the Lisp code to the C
> library. For example;
>
> #define SDL_INIT_VIDEO 10
> #define SDL_INIT_AUDIO 20
>
> (SDL-Init (logior sdl:SDL-INIT-VIDEO sdl:SDL-INIT-AUDIO))

Hmm, looks like you have to do that yourself.  Can other foreign
parsers do it automatically?  Corman's for example?  How do they
handle a #define with parameters?  How do they know the #define is
really meant to be a run-time constant and not something else like the
type in my earlier example?

Cheers,
Edi.


-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Luke J Crook
Subject: Re: Lispworks foreign-parser and #defines
Date: 
Message-ID: <_5adndvNNO61gG7fRVn-rA@giganews.com>
Edi Weitz wrote:
> On 4 Aug 2005 10:40:57 -0700, "Luke Crook" <····@balooga.com> wrote:
> Can other foreign
> parsers do it automatically?  Corman's for example?  How do they
> handle a #define with parameters?  How do they know the #define is
> really meant to be a run-time constant and not something else like the
> type in my earlier example?

In Corman, a #define with arguments is not allowed. It will attempt to 
convert a #define to a defconstant. Something like your example would 
have to be rewritten as:

typedef float FOO_TYPE;
FOO_TYPE frob (FOO_TYPE x);


-Luke