Changeset 4986
- Timestamp:
- 06/26/05 10:01:46 (4 years ago)
- svk:copy_cache_prev:
- 6771
- Location:
- src/Pugs
- Files:
-
- 2 modified
-
Prim.hs (modified) (3 diffs)
-
Prim/Match.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r4943 r4986 25 25 import Pugs.Internals 26 26 import Pugs.Junc 27 import Pugs.Context28 27 import Pugs.AST 29 28 import Pugs.Types … … 567 566 (return . VList $ vals) 568 567 569 pkgParents :: VStr -> Eval [VStr]570 pkgParents pkg = do571 ref <- readVar (':':'*':pkg)572 if ref == undef then return [] else do573 meta <- readRef =<< fromVal ref574 fetch <- doHash meta hash_fetchVal575 attrs <- fromVal =<< fetch "traits"576 pkgs <- mapM pkgParents attrs577 return $ nub (pkg:concat pkgs)578 579 568 op1WalkAllNoArgs :: ([VStr] -> [VStr]) -> VStr -> Val -> Eval Val 580 569 op1WalkAllNoArgs f meth v = do … … 813 802 op2 "does" = op2 "isa" -- XXX not correct 814 803 op2 "isa" = \x y -> do 815 typX <- fromVal =<< op1 "ref" x816 804 typY <- case y of 817 805 VStr str -> return $ mkType str 818 806 _ -> fromVal y 819 cls <- asks envClasses 820 return . VBool $ isaType cls (showType typY) typX 807 op2Match x (VType typY) 821 808 op2 "delete" = \x y -> do 822 809 ref <- fromVal x -
src/Pugs/Prim/Match.hs
r4922 r4986 3 3 4 4 module Pugs.Prim.Match ( 5 op2Match, rxSplit, rxSplit_n, matchFromMR 5 op2Match, rxSplit, rxSplit_n, matchFromMR, pkgParents 6 6 ) where 7 7 import Pugs.Internals … … 9 9 import Pugs.AST 10 10 import Pugs.Types 11 import Pugs.Context12 11 import Pugs.Config 13 12 import qualified RRegex.PCRE as PCRE … … 74 73 -- XXX - need to generalise this 75 74 op2Match :: Val -> Val -> Eval Val 75 76 op2Match x (VRef (MkRef (IScalar sv))) | scalar_iType sv == mkType "Scalar::Const" = do 77 y' <- scalar_fetch' sv 78 op2Match x y' 79 76 80 op2Match x (VRef y) = do 77 81 y' <- readRef y 78 82 op2Match x y' 83 84 op2Match x y@(VObject MkObject{ objType = MkType "Class" } ) = do 85 fetch <- doHash y hash_fetchVal 86 name <- fromVal =<< fetch "name" 87 op2Match x (VType (MkType name)) 79 88 80 89 op2Match x (VSubst (rx, subst)) | rxGlobal rx = do … … 147 156 148 157 op2Match (VType typ) (VType t) = do 149 cls <- asks envClasses150 return $ VBool (isaType cls (showType t) typ)158 typs <- pkgParents (showType typ) 159 return . VBool $ showType t `elem` typs 151 160 152 161 op2Match x y@(VType _) = do … … 154 163 op2Match (VType typ) y 155 164 156 op2Match x y = op2Cmp (fromVal :: Val -> Eval VStr) (==) x y 165 op2Match x y = do 166 op2Cmp (fromVal :: Val -> Eval VStr) (==) x y 157 167 158 168 op2Cmp :: (a -> Eval b) -> (b -> b -> VBool) -> a -> a -> Eval Val … … 195 205 rest <- rxSplit_n rx after (n-1) 196 206 return $ (VStr before:matchSubPos match) ++ rest 207 208 pkgParents :: VStr -> Eval [VStr] 209 pkgParents pkg = do 210 ref <- readVar (':':'*':pkg) 211 if ref == undef then return [] else do 212 meta <- readRef =<< fromVal ref 213 fetch <- doHash meta hash_fetchVal 214 attrs <- fromVal =<< fetch "traits" 215 pkgs <- mapM pkgParents attrs 216 return $ nub (pkg:concat pkgs) 217
