Sven Panne writes:
> In my obviously never-ending adventure of porting the Binary
> lib to GHC, two nasty bugs in the latest GC version hit me:
>
> -------------------------------------------------------
> import StdDIS
> -------------------------------------------------------
> newtype Baz a = BC Int
> %dis baz bp = declare {unsigned int} bp in (BC (int bp))
>
> %fun foo :: IO (Baz a)
> %code r = c_foo();
> %result (baz r)
> -------------------------------------------------------
> newtype Blah = B Int
> %dis blah x = B x
>
> %fun bar :: Blah -> IO ()
> %call (blah x)
> %code c_bar( x );
> -------------------------------------------------------
>
> The following code is generated from the above spec:
>
> -------------------------------------------------------
> import StdDIS
> -------------------------------------------------------
> newtype Baz a = BC Int
>
> foo :: IO (Baz a)
> foo =
> _casm_ ``do {unsigned int r; int r;
> do { r = c_foo();
>
> %r = (int)(r);} while(0);} while(0);''
> >>= \ r ->
> (return ((BC r)))
> -------------------------------------------------------
> newtype Blah = B Int
>
> bar :: Blah -> IO ()
> bar gc_arg1 =
> case gc_arg1 of { (B x) ->
> _casm_ ``do {do { c_bar( x );
> } while(0);} while(0);''}
> -------------------------------------------------------
>
> r is declared *two* times in the first _casm_ and
> x is neither declared or passed to the second one.
>
First one is a bug, the second uses an un-cool DIS - how can Green
Card infer the type of 'x' in the blah DIS? (Green Card should really
catch this..) Try instead doing
%dis blah x = B (int x)
New GC snapshot available from the ftp server which fixes the above
bug.
--Sigbjorn