Changeset 9050 for src/Pugs/CodeGen
- Timestamp:
- 02/18/06 17:03:32 (3 years ago)
- Files:
-
- 1 modified
-
src/Pugs/CodeGen/YAML.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/CodeGen/YAML.hs
r9009 r9050 8 8 import Pugs.PIL1 9 9 import DrIFT.YAML 10 import qualified Data.Map as Map 10 11 11 12 genParseYAML :: Eval Val 12 13 genParseYAML = do 13 glob <- asks envGlobal 14 glob <- asks envGlobal 15 MkPad pad <- liftSTM $ readTVar glob 16 pad' <- fmap (MkPad . Map.fromAscList . catMaybes) . mapM checkPrim $ Map.toAscList pad 17 -- munge the glob to filter out prim stuff in it 14 18 main <- asks envBody 15 yaml <- liftIO (showYaml (glob, main))19 yaml <- liftIO $ showYaml (pad', main) 16 20 return (VStr yaml) 21 22 checkPrim :: (String, PadEntry) -> Eval (Maybe (String, PadEntry)) 23 checkPrim ((':':'*':_), _) = return Nothing 24 checkPrim e@((_, MkEntry (_, tv))) = do 25 rv <- isPrim tv 26 return $ if rv then Nothing else Just e 27 checkPrim (key, MkEntryMulti xs) = do 28 xs' <- filterM (fmap not . isPrim . snd) xs 29 return $ if null xs' then Nothing else Just (key, MkEntryMulti xs') 30 31 isPrim :: TVar VRef -> Eval Bool 32 isPrim tv = do 33 vref <- liftSTM $ readTVar tv 34 case vref of 35 MkRef (ICode cv) -> fmap (isPrimVal . VCode) (code_fetch cv) 36 MkRef (IScalar sv) -> fmap isPrimVal (scalar_fetch sv) 37 _ -> return False 38 where 39 isPrimVal (VCode MkCode{ subBody = Prim _ }) = True 40 isPrimVal _ = False 17 41 18 42 genYAML :: Eval Val
