[project @ 2002-11-06 13:10:46 by simonpj]
[ghc-hetmet.git] / ghc / compiler / hsSyn / Convert.lhs
index c8cca66..24d34f0 100644 (file)
@@ -26,14 +26,16 @@ import HsSyn as Hs
 
 import RdrName ( RdrName, mkRdrUnqual, mkRdrQual, mkOrig )
 import Module   ( mkModuleName )
-import RdrHsSyn        ( mkHsIntegral, mkClassDecl, mkTyData )
+import RdrHsSyn        ( mkHsIntegral, mkHsFractional, mkClassDecl, mkTyData )
 import OccName
 import SrcLoc  ( SrcLoc, generatedSrcLoc )
 import TyCon   ( DataConDetails(..) )
 import Type    ( Type )
 import BasicTypes( Boxity(..), RecFlag(Recursive), 
                   NewOrData(..), StrictnessMark(..) )
-import FastString( mkFastString )
+import ForeignCall ( Safety(..), CCallConv(..), CCallTarget(..) )
+import HsDecls ( CImportSpec(..), ForeignImport(..), ForeignDecl(..) )
+import FastString( mkFastString, nilFS )
 import Char    ( ord, isAlphaNum )
 import List    ( partition )
 import Outputable
@@ -79,6 +81,14 @@ cvt_top (Instance tys ty decs)
 
 cvt_top (Proto nm typ) = SigD (Sig (vName nm) (cvtType typ) loc0)
 
+cvt_top (Foreign (Import callconv safety from nm typ))
+ = ForD (ForeignImport (vName nm) (cvtType typ) fi False loc0)
+    where fi = CImport CCallConv (PlaySafe True) c_header nilFS cis
+          (c_header', c_func') = break (== ' ') from
+          c_header = mkFastString c_header'
+          c_func = tail c_func'
+          cis = CFunction (StaticTarget (mkFastString c_func))
+
 noContext      = []
 noExistentials = []
 noFunDeps      = []
@@ -107,7 +117,7 @@ cvt (Infix (Just x) s (Just y)) = OpApp (cvt x) (HsVar(vName s)) undefined (cvt
 cvt (Infix Nothing  s (Just y)) = SectionR (HsVar(vName s)) (cvt y)
 cvt (Infix (Just x) s Nothing ) = SectionL (cvt x) (HsVar(vName s))
 cvt (Infix Nothing  s Nothing ) = HsVar(vName s) -- Can I indicate this is an infix thing?
-
+cvt (SigExp e t)               = ExprWithTySig (cvt e) (cvtType t)
 
 cvtdecs :: [Meta.Dec] -> HsBinds RdrName
 cvtdecs [] = EmptyBinds
@@ -173,11 +183,14 @@ cvtpair (x,y) = GRHS [BindStmt truePat (cvt x) loc0,
                      ResultStmt (cvt y) loc0] loc0
 
 cvtOverLit :: Lit -> HsOverLit
-cvtOverLit (Int i) = mkHsIntegral (fromInt i)
+cvtOverLit (Int i)      = mkHsIntegral (fromInt i)
+cvtOverLit (Rational r) = mkHsFractional r
 -- An Int is like an an (overloaded) '3' in a Haskell source program
+-- Similarly 3.5 for fractionals
 
 cvtLit :: Lit -> HsLit
-cvtLit (Char c)              = HsChar (ord c)
+cvtLit (Char c)          = HsChar (ord c)
+cvtLit (String s) = HsString (mkFastString s)
 
 cvtp :: Meta.Pat -> Hs.Pat RdrName
 cvtp (Plit l)