The first one is not a severe bug, but nevertheless: When using
declare, Green Card omits a C type cast. Consider the following
(silly) GC spec:

--------------------------------------------------
module Cast where

import StdDIS

newtype Foo = B Word32
%dis foo b = B (declare {FILE*} b in (word32 b))

%fun bar :: Foo -> IO Char
%call (foo b)
%code r = fgetc(b);
%result (char r)
--------------------------------------------------

This is converted to:

--------------------------------------------------
module Cast where

import StdDIS

newtype Foo = B Word32

bar :: Foo -> IO Char
bar gc_arg1 =
  case gc_arg1 of { (B b) ->
  _casm_ ``do {FILE* b;char r;
               b = %0;
               do { r = fgetc(b);
                   
                   %r = (char)(r);} while(0);} while(0);'' b
  >>= \  r  ->
  (return (r))}
--------------------------------------------------

The "b = %0;" should be "b = (FILE*)%0;", otherwise gcc complains
about making a pointer from an integer without a cast. That this
should be correct has already been stated in the DIS.

Another point is user-defined marshalling with more than one argument.
The Green Card from York seems to interpret this as implicit tupling,
so (I guess) the following should be fine:

--------------------------------------------------
module Strange where

import StdDIS

data Foo = F Int Char
%dis foo x y = <fromFoo/toFoo> (int x) (char y)

fromFoo (F i c) = (i,c)
toFoo   (i,c)   = F i c

%fun bar :: Foo -> IO ()
%call (foo a b)
%code baz(a, b);
--------------------------------------------------

But, alas, it isn't:

--------------------------------------------------
module Strange where

import StdDIS

data Foo = F Int Char

fromFoo (F i c) = (i,c)
toFoo   (i,c)   = F i c

bar :: Foo -> IO ()
bar gc_arg1 =
  case (fromFoo gc_arg1) of { a ->
  _casm_ ``do {int a;
               a = %0;
               do { baz(a, b);
                   } while(0);} while(0);'' a}
--------------------------------------------------

Somehow the b disappeared...   :-(
Bug, feature, or an uncool DIS again?   ;-)

[ BTW, the GHC port of the Binary lib is up and running, but it
  needs a little bit of testing before I dare to release it... ]

-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne

Reply via email to