Changeset 9050 for src/Pugs/CodeGen

Show
Ignore:
Timestamp:
02/18/06 17:03:32 (3 years ago)
Author:
audreyt
Message:

* Pugs.CodeGen?.YAML: "pugs -CParse-YAML" now omits the primitive

bindings for functions and types, just as "pugs -CPugs" used to do.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/CodeGen/YAML.hs

    r9009 r9050  
    88import Pugs.PIL1 
    99import DrIFT.YAML 
     10import qualified Data.Map as Map 
    1011 
    1112genParseYAML :: Eval Val 
    1213genParseYAML = 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 
    1418    main    <- asks envBody 
    15     yaml    <- liftIO (showYaml (glob, main)) 
     19    yaml    <- liftIO $ showYaml (pad', main) 
    1620    return (VStr yaml) 
     21 
     22checkPrim :: (String, PadEntry) -> Eval (Maybe (String, PadEntry)) 
     23checkPrim ((':':'*':_), _) = return Nothing 
     24checkPrim e@((_, MkEntry (_, tv))) = do 
     25    rv <- isPrim tv 
     26    return $ if rv then Nothing else Just e 
     27checkPrim (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 
     31isPrim :: TVar VRef -> Eval Bool 
     32isPrim 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 
    1741 
    1842genYAML :: Eval Val