Changeset 6248
- Timestamp:
- 08/14/05 17:32:14 (3 years ago)
- svk:copy_cache_prev:
- 8452
- Files:
-
- 1 added
- 12 modified
-
src/DrIFT/Binary.hs (modified) (7 diffs)
-
src/DrIFT/Perl5.hs (modified) (2 diffs)
-
src/Pugs/CodeGen.hs (modified) (2 diffs)
-
src/Pugs/CodeGen/Binary.hs (added)
-
src/Pugs/CodeGen/PIL.hs (modified) (1 diff)
-
src/Pugs/CodeGen/PIR.hs (modified) (3 diffs)
-
src/Pugs/CodeGen/Perl5.hs (modified) (1 diff)
-
src/Pugs/CodeGen/XML.hs (modified) (1 diff)
-
src/Pugs/Compile.hs (modified) (9 diffs)
-
src/Pugs/Embed/Parrot.hsc (modified) (1 diff)
-
src/Pugs/PIL1.hs (modified) (17 diffs)
-
src/Pugs/PIL1.hs-drift (modified) (4 diffs)
-
util/drift.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/DrIFT/Binary.hs
r6243 r6248 1 {-# OPTIONS -fallow-overlapping-instances#-}1 {-# OPTIONS_GHC -fglasgow-exts -w #-} 2 2 -- 3 3 -- (c) The University of Glasgow 2002 … … 42 42 ByteArray(..), 43 43 getByteArray, 44 putByteArray 44 putByteArray, 45 45 46 46 --getBinFileWithDict, -- :: Binary a => FilePath -> IO a … … 49 49 ) where 50 50 51 52 --import FastString53 import FastMutInt54 51 55 52 import Data.Array.IO … … 60 57 import Data.IORef 61 58 import Data.Char ( ord, chr ) 62 import Data.Array.Base ( unsafeRead, unsafeWrite )63 59 import Control.Monad ( when ) 64 60 import Control.Exception ( throwDyn ) … … 71 67 import GHC.Word ( Word8(..) ) 72 68 import System.IO ( openBinaryFile ) 73 import PackedString69 import UTF8.PackedString 74 70 --import Atom 75 71 import Time … … 77 73 import Data.Array.IArray 78 74 import Data.Array.Base 75 import Foreign.Storable 76 import Control.Concurrent.STM 79 77 80 78 … … 711 709 put_ bh a = put_ bh (toPackedString a) 712 710 -} 711 712 sSIZEOF_HSINT = sizeOf (undefined :: Int) 713 714 data FastMutInt = FastMutInt (MutableByteArray# RealWorld) 715 716 newFastMutInt :: IO FastMutInt 717 newFastMutInt = IO $ \s -> 718 case newByteArray# size s of { (# s, arr #) -> 719 (# s, FastMutInt arr #) } 720 where I# size = sSIZEOF_HSINT 721 722 {-# INLINE readFastMutInt #-} 723 readFastMutInt :: FastMutInt -> IO Int 724 readFastMutInt (FastMutInt arr) = IO $ \s -> 725 case readIntArray# arr 0# s of { (# s, i #) -> 726 (# s, I# i #) } 727 728 {-# INLINE writeFastMutInt #-} 729 writeFastMutInt :: FastMutInt -> Int -> IO () 730 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s -> 731 case writeIntArray# arr 0# i s of { s -> 732 (# s, () #) } 733 734 ---------------------------------------------------------------------------- 735 -- Pugs Additions 736 737 instance Binary Double where 738 put_ bh n = put_ bh (decodeFloat n) 739 get bh = fmap (uncurry encodeFloat) (get bh) 740 741 instance Binary a => Binary (TVar a) where 742 put_ bh v = put_ bh =<< (atomically $ readTVar v) 743 get bh = atomically . newTVar =<< get bh 744 745 instance Binary a => Binary (IORef a) where 746 put_ bh v = put_ bh =<< readIORef v 747 get bh = newIORef =<< get bh 748 -
src/DrIFT/Perl5.hs
r6240 r6248 1 {-# OPTIONS_GHC -fglasgow-exts -funbox-strict-fields -fallow-overlapping-instances #-}1 {-# OPTIONS_GHC -fglasgow-exts -funbox-strict-fields -fallow-overlapping-instances -fallow-undecidable-instances #-} 2 2 3 3 module DrIFT.Perl5 where 4 4 import Data.Ratio 5 5 import Data.List (intersperse) 6 import Control.Concurrent.STM 6 7 7 8 type Perl5Class = String … … 68 69 showPerl5 (x, y, z) = showP5Array [showPerl5 x, showPerl5 y, showPerl5 z] 69 70 71 instance (Show (TVar a)) => Perl5 (TVar a) where 72 showPerl5 _ = "(warn '<ref>')" -
src/Pugs/CodeGen.hs
r6240 r6248 16 16 import Pugs.CodeGen.PIR (genPIR) 17 17 import Pugs.CodeGen.Perl5 (genPerl5) 18 import Pugs.CodeGen.Binary (genBinary) 18 19 import Pugs.Compile.Pugs (genPugs) 19 20 import Pugs.Compile.Haskell (genGHC) … … 33 34 , ("Perl5", genPerl5) 34 35 , ("Pugs", genPugs) 36 , ("Binary", genBinary) 35 37 -- , ("Xml", genXML) 36 38 ] -
src/Pugs/CodeGen/PIL.hs
r6229 r6248 5 5 import Pugs.Internals 6 6 import Pugs.AST 7 import Pugs.PIL1 7 8 import Pugs.Compile 8 9 9 10 genPIL :: Eval Val 10 11 genPIL = do 11 glob <- askGlobal 12 main <- asks envBody 13 globPIL <- compile glob :: Eval [PIL_Decl] 14 mainPIL <- compile main :: Eval PIL_Stmts 12 penv <- compile () 15 13 return . VStr . unlines $ 16 14 [ "PIL_Environment" 17 , " { pilMain = (" ++ show mainPIL++ ")"18 , " , pilGlob = (" ++ show globPIL++ ")"15 , " { pilMain = (" ++ show (pilMain penv) ++ ")" 16 , " , pilGlob = (" ++ show (pilGlob penv) ++ ")" 19 17 , " }" 20 18 ] -
src/Pugs/CodeGen/PIR.hs
r6229 r6248 19 19 import Pugs.Types 20 20 import Pugs.Eval.Var 21 import Pugs.PIL1 21 22 import Emit.PIR 22 23 import Pugs.Pretty … … 338 339 local (\env -> env{ envDebug = Nothing }) $ do 339 340 opEval style "<prelude-pir>" preludeStr 340 glob <- askGlobal 341 main <- asks envBody 342 globPIL <- compile glob 343 mainPIL <- compile main 344 globPIR <- runCodeGenGlob tenv globPIL 345 mainPIR <- runCodeGenMain tenv mainPIL 341 penv <- compile () 342 globPIR <- runCodeGenGlob tenv (pilGlob penv) 343 mainPIR <- runCodeGenMain tenv (pilMain penv) 346 344 libs <- liftIO $ getLibs 347 345 return . VStr . unlines $ … … 385 383 , InsNew tempPMC PerlScalar 386 384 , "store_global" .- [lit "$_", tempPMC] 387 ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ <- globPIL] ++385 ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ <- pilGlob penv ] ++ 388 386 [ StmtRaw (text "main()") 389 387 , StmtIns $ tempPMC <-- "find_global" $ [lit "Perl6::Internals", lit "&exit"] -
src/Pugs/CodeGen/Perl5.hs
r6236 r6248 6 6 import Pugs.AST 7 7 import Pugs.Compile 8 import Pugs.PIL1 8 9 import DrIFT.Perl5 9 10 10 11 genPerl5 :: Eval Val 11 12 genPerl5 = do 12 glob <- askGlobal 13 main <- asks envBody 14 globPIL <- compile glob :: Eval [PIL_Decl] 15 mainPIL <- compile main :: Eval PIL_Stmts 13 penv <- compile () 16 14 return . VStr . unlines $ 17 15 [ "bless({" 18 , " pilMain => " ++ showPerl5 mainPIL++ ","19 , " pilGlob => " ++ showPerl5 globPIL16 , " pilMain => " ++ showPerl5 (pilMain penv) ++ "," 17 , " pilGlob => " ++ showPerl5 (pilGlob penv) 20 18 , "} => 'PIL::Environment')" 21 19 ] -
src/Pugs/CodeGen/XML.hs
r6239 r6248 11 11 genXML :: Eval Val 12 12 genXML = do 13 glob <- askGlobal 14 main <- asks envBody 15 globPIL <- compile glob :: Eval [PIL_Decl] 16 mainPIL <- compile main :: Eval PIL_Stmts 17 return . VStr . showXml $ PIL_Environment globPIL mainPIL 13 penv <- compile () :: Eval PIL_Environment 14 return $ VStr (showXml penv) -
src/Pugs/Compile.hs
r6230 r6248 49 49 50 50 -- Compile instances 51 instance Compile (Var, [(TVar Bool, TVar VRef)]) (PIL_Decl) where 51 instance Compile () PIL_Environment where 52 compile _ = do 53 glob <- askGlobal 54 main <- asks envBody 55 globPIL <- compile glob 56 mainPIL <- compile main 57 return $ PIL_Environment globPIL mainPIL 58 59 instance Compile (Var, [(TVar Bool, TVar VRef)]) PIL_Decl where 52 60 compile = compError 53 61 … … 126 134 return [PSub name (subType vsub) paramsC bodyC] 127 135 128 instance Compile (String, [(TVar Bool, TVar VRef)]) (PIL_Expr)where136 instance Compile (String, [(TVar Bool, TVar VRef)]) PIL_Expr where 129 137 compile (name, _) = return $ PRawName name 130 138 131 instance Compile Exp (PIL_Stmts)where139 instance Compile Exp PIL_Stmts where 132 140 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 133 141 compile (Cxt cxt rest) = enter cxt $ compile rest … … 149 157 enter cxt = local (\e -> e{ envContext = cxt }) 150 158 151 compileStmts :: Exp -> Comp (PIL_Stmts)159 compileStmts :: Exp -> Comp PIL_Stmts 152 160 compileStmts exp = case exp of 153 161 Stmts this Noop -> do … … 170 178 _ -> compile (Stmts exp Noop) 171 179 172 instance Compile Val (PIL_Stmt)where180 instance Compile Val PIL_Stmt where 173 181 compile = fmap PStmt . compile . Val 174 182 175 instance Compile Val (PIL_Expr)where183 instance Compile Val PIL_Expr where 176 184 compile = compile . Val 177 185 178 instance Compile Exp (PIL_Stmt)where186 instance Compile Exp PIL_Stmt where 179 187 compile (Pos pos rest) = fmap (PPos pos rest) $ compile rest 180 188 compile (Cxt cxt rest) = enter cxt $ compile rest … … 250 258 compile x = compError x 251 259 252 instance Compile Exp (PIL_LValue)where260 instance Compile Exp PIL_LValue where 253 261 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 254 262 compile (Cxt cxt rest) = enter cxt $ compile rest … … 311 319 compile exp = compError exp 312 320 313 compLoop :: Exp -> Comp (PIL_Stmt)321 compLoop :: Exp -> Comp PIL_Stmt 314 322 compLoop (Syn name [cond, body]) = do 315 323 cxt <- askTCxt … … 323 331 appropriate function call (@&statement_control:if@ or 324 332 @&statement_control:unless@). -} 325 compConditional :: Exp -> Comp (PIL_LValue)333 compConditional :: Exp -> Comp PIL_LValue 326 334 compConditional (Syn name exps) = do 327 335 [condC, trueC, falseC] <- compile exps … … 332 340 333 341 {-| Compiles various 'Exp's to 'PIL_Expr's. -} 334 instance Compile Exp (PIL_Expr)where342 instance Compile Exp PIL_Expr where 335 343 compile (Pos _ rest) = compile rest -- fmap (PPos pos rest) $ compile rest 336 344 compile (Cxt cxt rest) = enter cxt $ compile rest … … 363 371 364 372 {-| Compiles a 'Val' to a 'PIL_Literal'. -} 365 instance Compile Val (PIL_Literal)where373 instance Compile Val PIL_Literal where 366 374 compile val = return $ PVal val 367 375 -
src/Pugs/Embed/Parrot.hsc
r5963 r6248 49 49 evalParrot str = do 50 50 tmp <- getTemporaryDirectory 51 (file, fh) <- openTempFile tmp "pugs. imc"51 (file, fh) <- openTempFile tmp "pugs.pir" 52 52 hPutStr fh str 53 53 hClose fh -
src/Pugs/PIL1.hs
r6240 r6248 1 {-# OPTIONS_GHC -fglasgow-exts -funbox-strict-fields -fallow-overlapping-instances -fno-warn-orphans #-}1 {-# OPTIONS_GHC -fglasgow-exts -funbox-strict-fields -fallow-overlapping-instances -fno-warn-orphans -fno-warn-incomplete-patterns #-} 2 2 3 3 module Pugs.PIL1 ( … … 8 8 ) where 9 9 import Pugs.AST hiding (Prim) 10 import Pugs.Internals 10 import Pugs.Internals hiding (get, put) 11 11 import Pugs.Types 12 12 import Emit.PIR 13 13 import DrIFT.Perl5 14 import DrIFT.Binary 14 15 15 16 -- import DrIFT.XML 16 17 -- {-! global : Haskell2Xml !-} 17 18 18 {-! global : Perl5 !-} 19 20 instance (Typeable a) => Perl5 (TVar a) where 21 showPerl5 _ = "(warn '<ref>')" 22 instance Perl5 Exp where 23 showPerl5 _ = "(undef)" 19 {-! global : GhcBinary, Perl5 !-} 24 20 25 21 {-| … … 30 26 31 27 data PIL_Environment = PIL_Environment 32 { pil Main:: [PIL_Decl]33 , pil Glob:: PIL_Stmts28 { pilGlob :: [PIL_Decl] 29 , pilMain :: PIL_Stmts 34 30 } 35 31 deriving (Show, Eq, Ord, Typeable) … … 116 112 ------------------------------------------------------------------------ 117 113 114 instance Binary Exp where 115 put_ _ _ = return () 116 get _ = return Noop 117 instance Perl5 Exp where 118 showPerl5 _ = "(undef)" 119 118 120 {-* Generated by DrIFT : Look, but Don't Touch. *-} 121 instance Binary PIL_Environment where 122 put_ bh (PIL_Environment aa ab) = do 123 put_ bh aa 124 put_ bh ab 125 get bh = do 126 aa <- get bh 127 ab <- get bh 128 return (PIL_Environment aa ab) 129 119 130 instance Perl5 PIL_Environment where 120 131 showPerl5 (PIL_Environment aa ab) = 121 132 showP5HashObj "PIL::Environment" 122 [("pilMain", showPerl5 aa) , ("pilGlob", showPerl5 ab)] 133 [("pilGlob", showPerl5 aa) , ("pilMain", showPerl5 ab)] 134 135 instance Binary PIL_Stmts where 136 put_ bh PNil = do 137 putByte bh 0 138 put_ bh (PStmts aa ab) = do 139 putByte bh 1 140 put_ bh aa 141 put_ bh ab 142 put_ bh (PPad ac ad ae) = do 143 putByte bh 2 144 put_ bh ac 145 put_ bh ad 146 put_ bh ae 147 get bh = do 148 h <- getByte bh 149 case h of 150 0 -> do 151 return PNil 152 1 -> do 153 aa <- get bh 154 ab <- get bh 155 return (PStmts aa ab) 156 2 -> do 157 ac <- get bh 158 ad <- get bh 159 ae <- get bh 160 return (PPad ac ad ae) 123 161 124 162 instance Perl5 PIL_Stmts where … … 130 168 ("pStmts", showPerl5 ac)] 131 169 170 instance Binary PIL_Stmt where 171 put_ bh PNoop = do 172 putByte bh 0 173 put_ bh (PStmt aa) = do 174 putByte bh 1 175 put_ bh aa 176 put_ bh (PPos ab ac ad) = do 177 putByte bh 2 178 put_ bh ab 179 put_ bh ac 180 put_ bh ad 181 get bh = do 182 h <- getByte bh 183 case h of 184 0 -> do 185 return PNoop 186 1 -> do 187 aa <- get bh 188 return (PStmt aa) 189 2 -> do 190 ab <- get bh 191 ac <- get bh 192 ad <- get bh 193 return (PPos ab ac ad) 194 132 195 instance Perl5 PIL_Stmt where 133 196 showPerl5 (PNoop) = showP5Class "PNoop" … … 137 200 [("pPos", showPerl5 aa) , ("pExp", showPerl5 ab) , 138 201 ("pNode", showPerl5 ac)] 202 203 instance Binary PIL_Expr where 204 put_ bh (PRawName aa) = do 205 putByte bh 0 206 put_ bh aa 207 put_ bh (PExp ab) = do 208 putByte bh 1 209 put_ bh ab 210 put_ bh (PLit ac) = do 211 putByte bh 2 212 put_ bh ac 213 put_ bh (PThunk ad) = do 214 putByte bh 3 215 put_ bh ad 216 put_ bh (PCode ae af ag) = do 217 putByte bh 4 218 put_ bh ae 219 put_ bh af 220 put_ bh ag 221 get bh = do 222 h <- getByte bh 223 case h of 224 0 -> do 225 aa <- get bh 226 return (PRawName aa) 227 1 -> do 228 ab <- get bh 229 return (PExp ab) 230 2 -> do 231 ac <- get bh 232 return (PLit ac) 233 3 -> do 234 ad <- get bh 235 return (PThunk ad) 236 4 -> do 237 ae <- get bh 238 af <- get bh 239 ag <- get bh 240 return (PCode ae af ag) 139 241 140 242 instance Perl5 PIL_Expr where … … 149 251 ("pBody", showPerl5 ac)] 150 252 253 instance Binary PIL_Decl where 254 put_ bh (PSub aa ab ac ad) = do 255 put_ bh aa 256 put_ bh ab 257 put_ bh ac 258 put_ bh ad 259 get bh = do 260 aa <- get bh 261 ab <- get bh 262 ac <- get bh 263 ad <- get bh 264 return (PSub aa ab ac ad) 265 151 266 instance Perl5 PIL_Decl where 152 267 showPerl5 (PSub aa ab ac ad) = showP5HashObj "PSub" … … 154 269 ("pSubParams", showPerl5 ac) , ("pSubBody", showPerl5 ad)] 155 270 271 instance Binary PIL_Literal where 272 put_ bh (PVal aa) = do 273 put_ bh aa 274 get bh = do 275 aa <- get bh 276 return (PVal aa) 277 156 278 instance Perl5 PIL_Literal where 157 279 showPerl5 (PVal aa) = showP5HashObj "PVal" [("pVal", showPerl5 aa)] 280 281 instance Binary PIL_LValue where 282 put_ bh (PVar aa) = do 283 putByte bh 0 284 put_ bh aa 285 put_ bh (PApp ab ac ad ae) = do 286 putByte bh 1 287 put_ bh ab 288 put_ bh ac 289 put_ bh ad 290 put_ bh ae 291 put_ bh (PAssign af ag) = do 292 putByte bh 2 293 put_ bh af 294 put_ bh ag 295 put_ bh (PBind ah ai) = do 296 putByte bh 3 297 put_ bh ah 298 put_ bh ai 299 get bh = do 300 h <- getByte bh 301 case h of 302 0 -> do 303 aa <- get bh 304 return (PVar aa) 305 1 -> do 306 ab <- get bh 307 ac <- get bh 308 ad <- get bh 309 ae <- get bh 310 return (PApp ab ac ad ae) 311 2 -> do 312 af <- get bh 313 ag <- get bh 314 return (PAssign af ag) 315 3 -> do 316 ah <- get bh 317 ai <- get bh 318 return (PBind ah ai) 158 319 159 320 instance Perl5 PIL_LValue where … … 168 329 [("pLHS", showPerl5 aa) , ("pRHS", showPerl5 ab)] 169 330 331 instance Binary TParam where 332 put_ bh (MkTParam aa ab) = do 333 put_ bh aa 334 put_ bh ab 335 get bh = do 336 aa <- get bh 337 ab <- get bh 338 return (MkTParam aa ab) 339 170 340 instance Perl5 TParam where 171 341 showPerl5 (MkTParam aa ab) = showP5HashObj "MkTParam" 172 342 [("tpParam", showPerl5 aa) , ("tpDefault", showPerl5 ab)] 343 344 instance Binary TCxt where 345 put_ bh TCxtVoid = do 346 putByte bh 0 347 put_ bh (TCxtLValue aa) = do 348 putByte bh 1 349 put_ bh aa 350 put_ bh (TCxtItem ab) = do 351 putByte bh 2 352 put_ bh ab 353 put_ bh (TCxtSlurpy ac) = do 354 putByte bh 3 355 put_ bh ac 356 put_ bh (TTailCall ad) = do 357 putByte bh 4 358 put_ bh ad 359 get bh = do 360 h <- getByte bh 361 case h of 362 0 -> do 363 return TCxtVoid 364 1 -> do 365 aa <- get bh 366 return (TCxtLValue aa) 367 2 -> do 368 ab <- get bh 369 return (TCxtItem ab) 370 3 -> do 371 ac <- get bh 372 return (TCxtSlurpy ac) 373 4 -> do 374 ad <- get bh 375 return (TTailCall ad) 173 376 174 377 instance Perl5 TCxt where … … 182 385 [showPerl5 aa] 183 386 387 instance Binary TEnv where 388 put_ bh (MkTEnv aa ab ac ad ae) = do 389 put_ bh aa 390 put_ bh ab 391 put_ bh ac 392 put_ bh ad 393 put_ bh ae 394 get bh = do 395 aa <- get bh 396 ab <- get bh 397 ac <- get bh 398 ad <- get bh 399 ae <- get bh 400 return (MkTEnv aa ab ac ad ae) 401 184 402 instance Perl5 TEnv where 185 403 showPerl5 (MkTEnv aa ab ac ad ae) = showP5HashObj "MkTEnv" … … 187 405 ("tCxt", showPerl5 ac) , ("tReg", showPerl5 ad) , 188 406 ("tLabel", showPerl5 ae)] 407 408 instance Binary Scope where 409 put_ bh SState = do 410 putByte bh 0 411 put_ bh SMy = do 412 putByte bh 1 413 put_ bh SOur = do 414 putByte bh 2 415 put_ bh SLet = do 416 putByte bh 3 417 put_ bh STemp = do 418 putByte bh 4 419 put_ bh SGlobal = do 420 putByte bh 5 421 get bh = do 422 h <- getByte bh 423 case h of 424 0 -> do 425 return SState 426 1 -> do 427 return SMy 428 2 -> do 429 return SOur 430 3 -> do 431 return SLet 432 4 -> do 433 return STemp 434 5 -> do 435 return SGlobal 189 436
