[project @ 2000-03-23 17:45:17 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / ParseIface.y
index 9dacbee..40cc451 100644 (file)
@@ -7,35 +7,38 @@ import HsSyn          -- quite a bit of stuff
 import RdrHsSyn                -- oodles of synonyms
 import HsTypes         ( mkHsForAllTy, mkHsUsForAllTy )
 import HsCore
-import Const           ( Literal(..), mkMachInt_safe )
+import Literal         ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
 import BasicTypes      ( Fixity(..), FixityDirection(..), 
                          NewOrData(..), Version
                        )
 import CostCentre       ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
+import CallConv         ( cCallConv )
 import HsPragmas       ( noDataPragmas, noClassPragmas )
 import Type            ( Kind, mkArrowKind, boxedTypeKind, openTypeKind, UsageAnn(..) )
 import IdInfo           ( ArityInfo, exactArity, CprInfo(..), InlinePragInfo(..) )
+import PrimOp           ( CCall(..), CCallTarget(..) )
 import Lex             
 
 import RnMonad         ( ImportVersion, LocalVersion, ParsedIface(..), WhatsImported(..),
-                         RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..), WhetherHasOrphans
+                         RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..), 
+                          WhetherHasOrphans, IsBootInterface
                        ) 
 import Bag             ( emptyBag, unitBag, snocBag )
 import FiniteMap       ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
-import RdrName          ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual )
+import RdrName          ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual, mkRdrNameWkr )
 import Name            ( OccName, Provenance )
 import OccName          ( mkSysOccFS,
                          tcName, varName, ipName, dataName, clsName, tvName, uvName,
                          EncodedFS 
                        )
 import Module           ( ModuleName, mkSysModuleFS )                  
-import PrelMods         ( mkTupNameStr, mkUbxTupNameStr )
 import PrelInfo         ( mkTupConRdrName, mkUbxTupConRdrName )
 import SrcLoc          ( SrcLoc )
 import Maybes
 import Outputable
 
 import GlaExts
+import FastString      ( tailFS )
 
 #if __HASKELL1__ > 4
 import Ratio ( (%) )
@@ -93,6 +96,9 @@ import Ratio ( (%) )
  '__bot'       { ITbottom }
  '__integer'   { ITinteger_lit }
  '__float'     { ITfloat_lit }
+ '__word'      { ITword_lit }
+ '__int64'     { ITint64_lit }
+ '__word64'    { ITword64_lit }
  '__rational'  { ITrational_lit }
  '__addr'      { ITaddr_lit }
  '__litlit'    { ITlit_lit }
@@ -110,8 +116,8 @@ import Ratio ( (%) )
  '__U'         { ITunfold $$ }
  '__S'         { ITstrict $$ }
  '__R'         { ITrules }
+ '__M'         { ITcprinfo }
  '__D'         { ITdeprecated }
- '__M'         { ITcprinfo $$ }
 
  '..'          { ITdotdot }                    -- reserved symbols
  '::'          { ITdcolon }
@@ -200,16 +206,21 @@ import_part :                                               { [] }
            |  import_part import_decl                    { $2 : $1 }
            
 import_decl :: { ImportVersion OccName }
-import_decl : 'import' mod_fs INTEGER orphans whats_imported ';'
-                       { (mkSysModuleFS $2, fromInteger $3, $4, $5) }
+import_decl : 'import' mod_fs INTEGER orphans is_boot whats_imported ';'
+                       { (mkSysModuleFS $2, fromInteger $3, $4, $5, $6) }
        -- import Foo 3 :: a 1 b 3 c 7 ;        means import a,b,c from Foo
        -- import Foo 3 ;                       means import all of Foo
-       -- import Foo 3 ! :: ...stuff... ;      the ! means that Foo contains orphans
+       -- import Foo 3 ! @ :: ...stuff... ;    the ! means that Foo contains orphans
+        --                                      and @ that Foo is a boot interface
 
 orphans                    :: { WhetherHasOrphans }
 orphans                    :                                           { False }
                    | '!'                                       { True }
 
+is_boot                    :: { IsBootInterface }
+is_boot                    :                                           { False }
+                   | '@'                                       { True }
+
 whats_imported      :: { WhatsImported OccName }
 whats_imported      :                                           { Everything }
                     | '::' name_version_pairs                  { Specifically $2 }
@@ -370,12 +381,13 @@ deprecs           : {- empty -}           { [] }
                | deprecs deprec ';'    { $2 : $1 }
 
 deprec         :: { RdrNameDeprecation }
-deprec         : STRING                { DeprecMod     $1 }
-               | deprec_name STRING    { DeprecName $1 $2 }
+deprec         : STRING                { Deprecation (IEModuleContents undefined) $1 }
+               | deprec_name STRING    { Deprecation $1 $2 }
 
-deprec_name    :: { RdrName }
-               : var_name              { $1 }
-               | tc_name               { $1 }
+-- SUP: TEMPORARY HACK
+deprec_name    :: { RdrNameIE }
+               : var_name              { IEVar      $1 }
+               | data_name             { IEThingAbs $1 }
 
 -----------------------------------------------------------------------------
 
@@ -397,15 +409,15 @@ constrs1  :  constr               { [$1] }
                |  constr '|' constrs1  { $1 : $3 }
 
 constr         :: { RdrNameConDecl }
-constr         :  src_loc ex_stuff data_name batypes           { mkConDecl $3 $2 (VanillaCon $4) $1 }
-               |  src_loc ex_stuff data_name '{' fields1 '}'   { mkConDecl $3 $2 (RecCon $5)     $1 }
+constr         :  src_loc ex_stuff data_name batypes           { mk_con_decl $3 $2 (VanillaCon $4) $1 }
+               |  src_loc ex_stuff data_name '{' fields1 '}'   { mk_con_decl $3 $2 (RecCon $5)     $1 }
                 -- We use "data_fs" so as to include ()
 
 newtype_constr :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
 newtype_constr :                                       { [] }
-               | src_loc '=' ex_stuff data_name atype  { [mkConDecl $4 $3 (NewCon $5 Nothing) $1] }
+               | src_loc '=' ex_stuff data_name atype  { [mk_con_decl $4 $3 (NewCon $5 Nothing) $1] }
                | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
-                                                       { [mkConDecl $4 $3 (NewCon $8 (Just $6)) $1] }
+                                                       { [mk_con_decl $4 $3 (NewCon $8 (Just $6)) $1] }
 
 ex_stuff :: { ([HsTyVar RdrName], RdrNameContext) }
 ex_stuff       :                                       { ([],[]) }
@@ -453,7 +465,7 @@ context_list1       : class                                 { [$1] }
 
 class          :: { HsPred RdrName }
 class          :  qcls_name atypes                     { (HsPClass $1 $2) }
-               |  IPVARID '::' type                    { (HsPIParam (mkSysUnqual ipName $1) $3) }
+               |  ipvar_name '::' type                 { (HsPIParam $1 $3) }
 
 types0         :: { [RdrNameHsType]                    {- Zero or more -}  }   
 types0         :  {- empty -}                          { [ ] }
@@ -481,7 +493,7 @@ atype               :  qtc_name                             { MonoTyVar $1 }
                |  '(#' types0 '#)'                     { MonoTupleTy $2 False{-unboxed-} }
                |  '[' type ']'                         { MonoListTy  $2 }
                |  '{' qcls_name atypes '}'             { MonoDictTy $2 $3 }
-               |  '{' IPVARID '::' type '}'            { MonoIParamTy (mkSysUnqual ipName $2) $4 }
+               |  '{' ipvar_name '::' type '}'         { MonoIParamTy $2 $4 }
                |  '(' type ')'                         { $2 }
 
 -- This one is dealt with via qtc_name
@@ -527,6 +539,9 @@ qvar_name   :: { RdrName }
 qvar_name      :  var_name             { $1 }
                |  qvar_fs              { mkSysQual varName $1 }
 
+ipvar_name     :: { RdrName }
+               :  IPVARID              { mkSysUnqual ipName (tailFS $1) }
+
 var_names      :: { [RdrName] }
 var_names      :                       { [] }
                | var_name var_names    { $1 : $2 }
@@ -651,7 +666,7 @@ id_info             :: { [HsIdInfo RdrName] }
 id_info_item   :: { HsIdInfo RdrName }
                : '__A' INTEGER                 { HsArity (exactArity (fromInteger $2)) }
                | '__U' inline_prag core_expr   { HsUnfold $2 $3 }
-               | '__M'                         { HsCprInfo $1 }
+               | '__M'                         { HsCprInfo }
                | '__S'                         { HsStrictness (HsStrictnessInfo $1) }
                | '__C'                         { HsNoCafRefs }
                | '__P' qvar_name               { HsWorker $2 }
@@ -672,8 +687,7 @@ core_expr   : '\\' core_bndrs '->' core_expr        { foldr UfLam $4 $2 }
                | '__letrec' '{' rec_binds '}'          
                  'in' core_expr                        { UfLet (UfRec $3) $6 }
 
-               | con_or_primop '{' core_args '}'       { UfCon $1 $3 }
-                | '__litlit' STRING atype               { UfCon (UfLitLitCon $2 $3) [] }
+                | '__litlit' STRING atype               { UfLitLit $2 $3 }
 
                 | '__inline_me' core_expr               { UfNote UfInlineMe $2 }
                 | '__inline_call' core_expr             { UfNote UfInlineCall $2 }
@@ -695,7 +709,6 @@ core_args   :: { [UfExpr RdrName] }
 
 core_aexpr      :: { UfExpr RdrName }              -- Atomic expressions
 core_aexpr      : qvar_name                                    { UfVar $1 }
-
                 | qdata_name                                    { UfVar $1 }
                        -- This one means that e.g. "True" will parse as 
                        -- (UfVar True_Id) rather than (UfCon True_Con []).
@@ -706,14 +719,30 @@ core_aexpr      : qvar_name                                       { UfVar $1 }
                        -- If you want to get a UfCon, then use the
                        -- curly-bracket notation (True {}).
 
-               | core_lit               { UfCon (UfLitCon $1) [] }
-               | '(' core_expr ')'      { $2 }
-               | '(' comma_exprs2 ')'   { UfTuple (mkTupConRdrName (length $2)) $2 }
-               | '(#' comma_exprs0 '#)' { UfTuple (mkUbxTupConRdrName (length $2)) $2 }
-
 -- This one is dealt with by qdata_name: see above comments
 --             | '('  ')'               { UfTuple (mkTupConRdrName 0) [] }
 
+               | core_lit               { UfLit $1 }
+               | '(' core_expr ')'      { $2 }
+
+                       -- Tuple construtors are for the *worker* of the tuple
+                       -- Going direct saves needless messing about 
+               | '(' comma_exprs2 ')'   { UfTuple (mkRdrNameWkr (mkTupConRdrName (length $2))) $2 }
+               | '(#' comma_exprs0 '#)' { UfTuple (mkRdrNameWkr (mkUbxTupConRdrName (length $2))) $2 }
+
+                | '{' '__ccall' ccall_string type '}'       
+                           { let
+                                 (is_dyn, is_casm, may_gc) = $2
+
+                                target | is_dyn    = DynamicTarget (error "CCall dyn target bogus unique")
+                                       | otherwise = StaticTarget $3
+
+                                ccall = CCall target is_casm may_gc cCallConv
+                            in
+                            UfCCall ccall $4
+                          }
+
+
 comma_exprs0    :: { [UfExpr RdrName] }        -- Zero or more
 comma_exprs0   : {- empty -}                   { [ ] }
                | core_expr                     { [ $1 ] }
@@ -723,15 +752,6 @@ comma_exprs2       :: { [UfExpr RdrName] } -- Two or more
 comma_exprs2   : core_expr ',' core_expr                       { [$1,$3] }
                | core_expr ',' comma_exprs2                    { $1 : $3 }
 
-con_or_primop   :: { UfCon RdrName }
-con_or_primop   : qdata_name                    { UfDataCon $1 }
-                | qvar_name                    { UfPrimOp $1 }
-                | '__ccall' ccall_string      { let
-                                               (is_dyn, is_casm, may_gc) = $1
-                                               in
-                                               UfCCallOp $2 is_dyn is_casm may_gc
-                                               }
-
 rec_binds      :: { [(UfBinder RdrName, UfExpr RdrName)] }
                :                                               { [] }
                | core_val_bndr '=' core_expr ';' rec_binds     { ($1,$3) : $5 }
@@ -743,12 +763,12 @@ core_alts :: { [UfAlt RdrName] }
 core_alt        :: { UfAlt RdrName }
 core_alt       : core_pat '->' core_expr       { (fst $1, snd $1, $3) }
 
-core_pat       :: { (UfCon RdrName, [RdrName]) }
-core_pat       : core_lit                      { (UfLitCon  $1, []) }
-               | '__litlit' STRING atype       { (UfLitLitCon $2 $3, []) }
-               | qdata_name core_pat_names     { (UfDataCon $1, $2) }
-               | '(' comma_var_names1 ')'      { (UfDataCon (mkTupConRdrName (length $2)), $2) }
-               | '(#' comma_var_names1 '#)'    { (UfDataCon (mkUbxTupConRdrName (length $2)), $2) }
+core_pat       :: { (UfConAlt RdrName, [RdrName]) }
+core_pat       : core_lit                      { (UfLitAlt  $1, []) }
+               | '__litlit' STRING atype       { (UfLitLitAlt $2 $3, []) }
+               | qdata_name core_pat_names     { (UfDataAlt $1, $2) }
+               | '(' comma_var_names1 ')'      { (UfDataAlt (mkTupConRdrName (length $2)), $2) }
+               | '(#' comma_var_names1 '#)'    { (UfDataAlt (mkUbxTupConRdrName (length $2)), $2) }
                | '__DEFAULT'                   { (UfDefault, []) }
                | '(' core_pat ')'              { $2 }
 
@@ -769,22 +789,14 @@ comma_var_names1 : var_name                                       { [$1] }
                 | var_name ',' comma_var_names1                { $1 : $3 }
 
 core_lit       :: { Literal }
-core_lit       : integer                       { mkMachInt_safe $1 }
+core_lit       : integer                       { mkMachInt $1 }
                | CHAR                          { MachChar $1 }
                | STRING                        { MachStr $1 }
-               | '__string' STRING             { NoRepStr $2 (panic "NoRepStr type") }
                | rational                      { MachDouble $1 }
+               | '__word' integer              { mkMachWord $2 }
+               | '__word64' integer            { mkMachWord64 $2 }
+               | '__int64' integer             { mkMachInt64 $2 }
                | '__float' rational            { MachFloat $2 }
-
-               | '__integer' integer           { NoRepInteger  $2 (panic "NoRepInteger type") 
-                                                       -- The type checker will add the types
-                                               }
-
-               | '__rational' integer integer  { NoRepRational ($2 % $3) 
-                                                  (panic "NoRepRational type")
-                                                       -- The type checker will add the type
-                                               }
-
                | '__addr' integer              { MachAddr $2 }
 
 integer                :: { Integer }
@@ -818,10 +830,10 @@ ccall_string      :: { FAST_STRING }
 
 ------------------------------------------------------------------------
 scc     :: { CostCentre }
-        :  '__sccC' '{' mod_name STRING '}'                      { AllCafsCC $3 $4 }
-        |  '__scc' '{' cc_name mod_name STRING cc_dup cc_caf '}'
-                             { NormalCC { cc_name = $3, cc_mod = $4, cc_grp = $5,
-                                          cc_is_dupd = $6, cc_is_caf = $7 } }
+        :  '__sccC' '{' mod_name '}'                      { AllCafsCC $3 }
+        |  '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
+                             { NormalCC { cc_name = $3, cc_mod = $4,
+                                          cc_is_dupd = $5, cc_is_caf = $6 } }
 
 cc_name :: { EncodedFS }
         : CONID                 { $1 }
@@ -857,5 +869,5 @@ data IfaceStuff = PIface    EncodedFS{-.hi module name-} ParsedIface
                | PRules        [RdrNameRuleDecl]
                | PDeprecs      [RdrNameDeprecation]
 
-mkConDecl name (ex_tvs, ex_ctxt) details loc = ConDecl name ex_tvs ex_ctxt details loc
+mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc
 }