raw foregin imports - new backend for jhc: ghc

Simon Peyton-Jones simonpj at microsoft.com
Fri Nov 17 12:12:23 EST 2006


John

Sorry for slow reply .  It's been a busy week.

| but I am still having a couple issues:
|
| I am having trouble with a couple foreign imports that I think
| should work:
|
| here is one:
|
| > type World__ = State# RealWorld
| >
| > main = IO $ \w -> case  getchar w of
| >     (# w', ch #) -> (# w', () #)
| >
| > foreign import ccall unsafe getchar :: World__ -> (# World__, Int# #)
|
| which produces a
|
| ghc-6.6: panic! (the 'impossible' happened)
|   (GHC version 6.6 for i386-unknown-linux):
|         resultWrapper
|     (# main:Main.World__{tc rpT}, base:GHC.Base.Int{(w) tc 3J} #)#

The crash is definitely a bug.  The user manual does not claim to allow unboxed tuples in the return type for a foreign call; so GHC should reject the program politely.

You might ask "well, couldn't the above program be accepted?".  Perhaps so... but why do you want it.  You should find that if you say
        foreign import ccall unsafe getchar :: IO Int
and then
        do { I# x <- getchar; ...}
then no boxing occurs.  So maybe this new feature isn't reqd.  Let us know

| the other is
|
| where 'global_argc' is a C symbol.
|
| > foreign import ccall "&global_argc" argc :: Addr#

What's the problem here?  Your mail looks garbled.

Concerning primitive types, Ian will respond in a few days.  We're not sure we understand what you want!

Simon


More information about the Glasgow-haskell-users mailing list