Changeset 16627
- Timestamp:
- 06/04/07 10:08:30 (18 months ago)
- Location:
- src
- Files:
-
- 12 modified
-
Pugs.hs (modified) (1 diff)
-
Pugs/AST/Internals.hs (modified) (2 diffs)
-
Pugs/AST/Internals/Instances.hs (modified) (1 diff)
-
Pugs/CodeGen.hs (modified) (3 diffs)
-
Pugs/CodeGen/JSON.hs (modified) (1 diff)
-
Pugs/CodeGen/PIL1.hs (modified) (1 diff)
-
Pugs/CodeGen/PIR.hs (modified) (1 diff)
-
Pugs/CodeGen/Perl5.hs (modified) (1 diff)
-
Pugs/CodeGen/YAML.hs (modified) (1 diff)
-
Pugs/Compile/Pugs.hs (modified) (2 diffs)
-
Pugs/Prim/Eval.hs (modified) (1 diff)
-
Pugs/Run.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs.hs
r16610 r16627 194 194 195 195 doCompile :: String -> FilePath -> String -> IO String 196 doCompile backend = doParseWith $ \env _-> do196 doCompile backend = doParseWith $ \env file -> do 197 197 globRef <- stm $ do 198 198 glob <- readMPad $ envGlobal env 199 199 newMPad $ filterUserDefinedPad glob 200 codeGen backend env{ envGlobal = globRef }200 codeGen backend file env{ envGlobal = globRef } 201 201 202 202 initCompile :: IO () -
src/Pugs/AST/Internals.hs
r16610 r16627 1547 1547 -} 1548 1548 data CompUnit = MkCompUnit 1549 { ver :: Int -- a version number, currently 11550 --, desc :: String -- e.g., the name of the contained module1549 { ver :: Int -- a version number, see compUnitVersion 1550 , desc :: String -- e.g., the name of the contained module 1551 1551 , pad :: Pad -- pad for unit Env 1552 1552 , ast :: Exp -- AST of unit … … 1554 1554 1555 1555 mkCompUnit :: String -> Pad -> Exp -> CompUnit 1556 mkCompUnit _ pad ast = MkCompUnit compUnitVersion pad ast1556 mkCompUnit = MkCompUnit compUnitVersion 1557 1557 1558 1558 {-# NOINLINE compUnitVersion #-} 1559 1559 compUnitVersion :: Int 1560 compUnitVersion = 1 71560 compUnitVersion = 18 1561 1561 1562 1562 {-| -
src/Pugs/AST/Internals/Instances.hs
r16413 r16627 710 710 fromYAML MkNode{n_tag=Just t, n_elem=e} | 't':'a':'g':':':'h':'s':':':tag <- unpackBuf t = case tag of 711 711 "MkCompUnit" -> do 712 let ESeq [aa, ab, ac ] = e713 liftM 3 MkCompUnit (fromYAML aa) (fromYAML ab) (fromYAML ac)712 let ESeq [aa, ab, ac, ad] = e 713 liftM4 MkCompUnit (fromYAML aa) (fromYAML ab) (fromYAML ac) (fromYAML ad) 714 714 _ -> fail $ "unhandled tag: " ++ show t ++ ", expecting " ++ show ["MkCompUnit"] ++ " in node " ++ show e 715 715 fromYAML e = fail $ "no tag found: expecting " ++ show ["MkCompUnit"] ++ " in node " ++ show e 716 asYAML (MkCompUnit aa ab ac ) = asYAMLseq "MkCompUnit"717 [asYAML aa, asYAML ab, asYAML ac ]716 asYAML (MkCompUnit aa ab ac ad) = asYAMLseq "MkCompUnit" 717 [asYAML aa, asYAML ab, asYAML ac, asYAML ad] 718 718 719 719 instance YAML VMultiCode where -
src/Pugs/CodeGen.hs
r15297 r16627 25 25 import qualified Data.Map as Map 26 26 27 type Generator = Eval Val27 type Generator = FilePath -> Eval Val 28 28 29 29 generators :: Map String Generator … … 43 43 , ("Parse-YAML", genParseYAML) 44 44 , ("Parse-HsYAML",genParseHsYAML) 45 , ("Parse-Pretty", fmap (VStr . (++"\n") . pretty) (asks envBody))45 , ("Parse-Pretty",const $ fmap (VStr . (++"\n") . pretty) (asks envBody)) 46 46 -- , ("XML", genXML) 47 47 ] … … 85 85 key -> Map.lookup key generators 86 86 87 codeGen :: String -> Env -> IO String88 codeGen s env = do87 codeGen :: String -> FilePath -> Env -> IO String 88 codeGen s file env = do 89 89 gen <- catchIO (doLookup s) . const $ do 90 fail $ "Cannot generate code for " ++ s 91 rv <- runEvalIO env gen90 fail $ "Cannot generate code for " ++ s ++ ": " ++ file 91 rv <- runEvalIO env (gen file) 92 92 case rv of 93 93 VStr str -> return str -
src/Pugs/CodeGen/JSON.hs
r15297 r16627 8 8 import DrIFT.JSON 9 9 10 genJSON :: Eval Val 11 genJSON = do 10 -- XXX: do something useful with the filename arg 11 genJSON :: FilePath -> Eval Val 12 genJSON _ = do 12 13 penv <- compile () :: Eval PIL_Environment 13 14 return . VStr . unlines $ [showJSON penv] -
src/Pugs/CodeGen/PIL1.hs
r15297 r16627 7 7 import Pugs.Compile 8 8 9 genPIL1 :: Eval Val10 genPIL1 = do9 genPIL1 :: FilePath -> Eval Val 10 genPIL1 _ = do 11 11 penv <- compile () 12 12 return . VStr . unlines $ -
src/Pugs/CodeGen/PIR.hs
r15651 r16627 370 370 varInit x = internalError $ "Invalid name: " ++ x 371 371 372 genPIR_YAML :: Eval Val 373 genPIR_YAML = genPIRWith $ \globPIR mainPIR _ -> do 372 -- XXX: do something useful with the filename arg 373 genPIR_YAML :: FilePath -> Eval Val 374 genPIR_YAML _ = genPIRWith $ \globPIR mainPIR _ -> do 374 375 yaml <- io (showYaml (mainPIR, globPIR)) 375 376 return (VStr yaml) 376 377 377 378 {-| Compiles the current environment to PIR code. -} 378 genPIR :: Eval Val379 genPIR = genPIRWith $ \globPIR mainPIR penv -> do379 genPIR :: FilePath -> Eval Val 380 genPIR file = genPIRWith $ \globPIR mainPIR penv -> do 380 381 libs <- io $ getLibs 381 382 return . VStr . unlines $ 382 383 [ "#!/usr/bin/env parrot" 384 , "# " ++ file 383 385 , renderStyle (Style PageMode 0 0) $ preludePIR $+$ vcat 384 386 -- Namespaces have bugs in both pugs and parrot. -
src/Pugs/CodeGen/Perl5.hs
r15297 r16627 8 8 import DrIFT.Perl5 9 9 10 genPerl5 :: Eval Val 11 genPerl5 = do 10 -- XXX: do something useful with the filename arg 11 genPerl5 :: FilePath -> Eval Val 12 genPerl5 _ = do 12 13 penv <- compile () :: Eval PIL_Environment 13 14 return . VStr . unlines $ [showPerl5 penv] -
src/Pugs/CodeGen/YAML.hs
r15753 r16627 9 9 import DrIFT.YAML 10 10 11 genParseHsYAML, genParseYAML :: Eval Val12 genParseHsYAML = doGenParseYAML(fmap show . toYamlNode)13 genParseYAML = doGenParseYAMLshowYamlCompressed11 genParseHsYAML, genParseYAML :: FilePath -> Eval Val 12 genParseHsYAML file = doGenParseYAML file (fmap show . toYamlNode) 13 genParseYAML file = doGenParseYAML file showYamlCompressed 14 14 15 doGenParseYAML :: (CompUnit -> IO String) -> Eval Val16 doGenParseYAML f = do15 doGenParseYAML :: FilePath -> (CompUnit -> IO String) -> Eval Val 16 doGenParseYAML file f = do 17 17 pad <- filterPrim =<< asks envGlobal 18 18 main <- asks envBody 19 yaml <- io $ f $ mkCompUnit "<unused>"pad main19 yaml <- io $ f $ mkCompUnit file pad main 20 20 return $ VStr yaml 21 21 22 genYAML :: Eval Val 23 genYAML = do 22 -- XXX: do something useful with the filename arg 23 genYAML :: FilePath -> Eval Val 24 genYAML _ = do 24 25 penv <- compile () :: Eval PIL_Environment 25 26 yaml <- io (showYamlCompressed penv) -
src/Pugs/Compile/Pugs.hs
r16340 r16627 198 198 -} 199 199 200 genPugs :: Eval Val201 genPugs = do200 genPugs :: FilePath -> Eval Val 201 genPugs file = do 202 202 exp <- asks envBody 203 203 glob <- askGlobal … … 214 214 , "import qualified Data.Set as Set" 215 215 , "" 216 , "-- compiled from " ++ file ++ " with -CPugs" 217 , "" 216 218 , "main = do" 217 219 , " glob <- globC" -
src/Pugs/Prim/Eval.hs
r16626 r16627 150 150 Right yml' -> do 151 151 globTVar <- asks envGlobal 152 MkCompUnit _ glob ast <- io $ fromYAML yml'152 MkCompUnit _ _ glob ast <- io $ fromYAML yml' 153 153 tryT $ do 154 154 -- Inject the global bindings -
src/Pugs/Run.hs
r16433 r16627 276 276 --(glob, ast) <- fromYAML yml 277 277 -- cleanSeen 278 MkCompUnit _ glob ast <- io $ fromYAML yml278 MkCompUnit _ _ glob ast <- io $ fromYAML yml 279 279 -- print "Loading done!" 280 280 -- z <- stm $ join (findSym (cast "&*__fail") glob)
