Changeset 15420 for src/Pugs/Eval.hs

Show
Ignore:
Timestamp:
03/03/07 14:57:49 (21 months ago)
Author:
audreyt
Message:

* Pugs.Eval: Chase Feed/Capture changes. (We switched

from a lazy [Val] into a parallel-friendly strict [:Val:].)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r15297 r15420  
    1 {-# OPTIONS_GHC -fglasgow-exts -cpp -fno-warn-deprecations -fallow-overlapping-instances #-} 
     1{-# OPTIONS_GHC -fglasgow-exts -cpp -fno-warn-deprecations -fallow-overlapping-instances -fparr #-} 
    22 
    33{-| 
     
    4040import Pugs.Eval.Var 
    4141import DrIFT.YAML () 
     42import GHC.PArr 
    4243import qualified Data.ByteString.Char8 as Buf 
    4344 
     
    10291030                   } 
    10301031        vcap <- case args of 
    1031             []      -> return (CaptSub { c_feeds = [] }) 
     1032            []      -> return (CaptSub { c_feeds = [::] }) 
    10321033            (x:_)   -> castVal =<< fromVal =<< enterRValue (enterEvalContext (cxtItem "Capture") x) 
    10331034        local callerEnv $ applyCapture sub vcap 
     
    10391040    , "&infix:=>"   ... reduceSyn "=>" 
    10401041    , "&circumfix:\\( )" ... \invs args -> do 
    1041         feeds <- argsFeed [] Nothing [args] 
     1042        feeds <- argsFeed [::] Nothing [args] 
    10421043        case invs of 
    10431044            Just i' -> do 
    10441045                invVal  <- reduce i' 
    10451046                vv      <- fromVal invVal 
    1046                 return $ VV $ val $ CaptMeth{ c_invocant = vv, c_feeds = feeds } 
     1047                return . VV . mkVal $ CaptMeth{ c_invocant = vv, c_feeds = feeds } 
    10471048            Nothing -> do 
    1048                 return $ VV $ val $ CaptSub{ c_feeds = feeds } 
     1049                return . VV . mkVal $ CaptSub{ c_feeds = feeds } 
    10491050    , "&prefix:|<<" ... reduceSyn "," -- XXX this is wrong as well - should handle at args level 
    10501051    ] 
     
    10801081 
    10811082applyCapture :: VCode -> ValCapt -> Eval Val 
    1082 applyCapture sub capt = apply sub inv (argsPos ++ argsNam) 
    1083     where 
    1084     argsPos = map (Val . castV) (f_positionals feed) 
    1085     argsNam = [Syn "named" [Val (VStr (cast k)), Val (castV (last vs))] | (k, vs@(_:_)) <- Map.toList $ f_nameds feed ] 
    1086     feed = mconcat (c_feeds capt) 
     1083applyCapture sub capt = apply sub inv (fromP argsPos ++ argsNam) 
     1084    where 
     1085    argsPos = mapP (Val . castV) (f_positionals feed) 
     1086    argsNam = [ Syn "named" [Val (VStr (cast k)), Val (castV (vs !: lst))] | (k, vs) <- Map.toList (f_nameds feed), let lst = length vs - 1, lst >= 0 ] 
     1087    feed = concatFeeds (c_feeds capt) 
    10871088    inv  = case capt of  
    10881089        CaptMeth { c_invocant = val }   -> Just (Val (castV val)) 
    10891090        _                               -> Nothing 
    10901091 
    1091 argsFeed :: [ValFeed] -> Maybe ValFeed -> [[Exp]] -> Eval [ValFeed] 
    1092 argsFeed fAcc aAcc [] = return $ fAcc ++ maybeToList aAcc 
    1093 argsFeed fAcc aAcc [[]] = return $ fAcc ++ maybeToList aAcc 
     1092argsFeed :: [:ValFeed:] -> Maybe ValFeed -> [[Exp]] -> Eval [:ValFeed:] 
     1093argsFeed fAcc Nothing [] =   return fAcc 
     1094argsFeed fAcc Nothing [[]]  = return fAcc 
     1095argsFeed fAcc (Just x) []   = return $ fAcc +:+ [:x:] 
     1096argsFeed fAcc (Just x) [[]] = return $ fAcc +:+ [:x:] 
    10941097argsFeed fAcc aAcc (argl:als) = do 
    10951098    acc <- af aAcc argl 
     
    11061109        | Syn "|" (capExp:_) <- unwrapN = do 
    11071110            cap <- castVal =<< fromVal =<< enterRValue (enterEvalContext (cxtItem "Capture") capExp) 
    1108             af (Just (mconcat (resFeed:c_feeds cap))) args 
     1111            af (Just (mconcat (resFeed:fromP (c_feeds cap)))) args 
    11091112        | App (Var var) Nothing capExps <- unwrapN 
    11101113        , var == cast "&prefix:|<<" = do 
    11111114            caps    <- mapM castVal =<< fromVals =<< (enterRValue $ enterEvalContext (cxtSlurpy "Capture") (Syn "," capExps)) 
    1112             af (Just (mconcat (resFeed:concatMap c_feeds caps))) args 
     1115            af (Just (mconcat (resFeed:concatMap (fromP . c_feeds) caps))) args 
    11131116        | otherwise = do 
    11141117            argVal  <- fromVal =<< reduce n 
    1115             af (Just resFeed{ f_positionals = (f_positionals resFeed) ++ [argVal] }) args 
     1118            af (Just resFeed{ f_positionals = (f_positionals resFeed) +:+ [:argVal:] }) args 
    11161119        where 
    11171120        unwrapN = unwrap n 
    11181121        resFeed = feed res 
    11191122    feed res = maybe emptyFeed id res 
    1120     addNamed :: (Map ID [a]) -> VStr -> a -> Map ID [a] 
     1123    addNamed :: (Map ID [:a:]) -> VStr -> a -> Map ID [:a:] 
    11211124    addNamed mp k v = 
    11221125        let id = cast k in 
    1123         Map.insertWith (flip (++)) id [v] mp 
     1126        Map.insertWith (flip (+:+)) id [:v:] mp 
    11241127 
    11251128dummyVar :: Var 
     
    11721175    (k, v) <- pair_fetch pv 
    11731176    return [ Syn "named" [Val k, Val v] ] 
    1174 interpolateVal (VV vv) | Just (CaptSub{ c_feeds = feeds } :: ValCapt) <- castVal vv = return $ 
    1175     [ Val (castV v) | v <- concatMap f_positionals feeds ] 
    1176     ++ [ Syn "named" [Val (VStr $ cast k), Val (concatNamed v)] | (k, v) <- concatMap (Map.toList . f_nameds) feeds ] 
    1177     where 
    1178     concatNamed [x] = castV x 
    1179     concatNamed xs  = VList (map castV xs) 
     1177interpolateVal (VV vv) | Just (CaptSub{ c_feeds = feeds } :: ValCapt) <- castVal vv = return . fromP $ 
     1178    [: Val (castV v) | v <- concatMapP f_positionals feeds :] 
     1179    +:+ [: Syn "named" [Val (VStr $ cast k), Val (concatNamed v)] | (k, v) <- concatMapP (toP . Map.toList . f_nameds) feeds :] 
     1180    where 
     1181    concatNamed [:x:] = castV x 
     1182    concatNamed xs    = VList (fromP (mapP castV xs)) 
    11801183interpolateVal val = return [Val val] 
    11811184