Changeset 15420 for src/Pugs/Eval.hs
- Timestamp:
- 03/03/07 14:57:49 (21 months ago)
- Files:
-
- 1 modified
-
src/Pugs/Eval.hs (modified) (7 diffs)
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 #-} 2 2 3 3 {-| … … 40 40 import Pugs.Eval.Var 41 41 import DrIFT.YAML () 42 import GHC.PArr 42 43 import qualified Data.ByteString.Char8 as Buf 43 44 … … 1029 1030 } 1030 1031 vcap <- case args of 1031 [] -> return (CaptSub { c_feeds = [ ] })1032 [] -> return (CaptSub { c_feeds = [::] }) 1032 1033 (x:_) -> castVal =<< fromVal =<< enterRValue (enterEvalContext (cxtItem "Capture") x) 1033 1034 local callerEnv $ applyCapture sub vcap … … 1039 1040 , "&infix:=>" ... reduceSyn "=>" 1040 1041 , "&circumfix:\\( )" ... \invs args -> do 1041 feeds <- argsFeed [ ] Nothing [args]1042 feeds <- argsFeed [::] Nothing [args] 1042 1043 case invs of 1043 1044 Just i' -> do 1044 1045 invVal <- reduce i' 1045 1046 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 } 1047 1048 Nothing -> do 1048 return $ VV $ val $ CaptSub{ c_feeds = feeds }1049 return . VV . mkVal $ CaptSub{ c_feeds = feeds } 1049 1050 , "&prefix:|<<" ... reduceSyn "," -- XXX this is wrong as well - should handle at args level 1050 1051 ] … … 1080 1081 1081 1082 applyCapture :: 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)1083 applyCapture 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) 1087 1088 inv = case capt of 1088 1089 CaptMeth { c_invocant = val } -> Just (Val (castV val)) 1089 1090 _ -> Nothing 1090 1091 1091 argsFeed :: [ValFeed] -> Maybe ValFeed -> [[Exp]] -> Eval [ValFeed] 1092 argsFeed fAcc aAcc [] = return $ fAcc ++ maybeToList aAcc 1093 argsFeed fAcc aAcc [[]] = return $ fAcc ++ maybeToList aAcc 1092 argsFeed :: [:ValFeed:] -> Maybe ValFeed -> [[Exp]] -> Eval [:ValFeed:] 1093 argsFeed fAcc Nothing [] = return fAcc 1094 argsFeed fAcc Nothing [[]] = return fAcc 1095 argsFeed fAcc (Just x) [] = return $ fAcc +:+ [:x:] 1096 argsFeed fAcc (Just x) [[]] = return $ fAcc +:+ [:x:] 1094 1097 argsFeed fAcc aAcc (argl:als) = do 1095 1098 acc <- af aAcc argl … … 1106 1109 | Syn "|" (capExp:_) <- unwrapN = do 1107 1110 cap <- castVal =<< fromVal =<< enterRValue (enterEvalContext (cxtItem "Capture") capExp) 1108 af (Just (mconcat (resFeed: c_feeds cap))) args1111 af (Just (mconcat (resFeed:fromP (c_feeds cap)))) args 1109 1112 | App (Var var) Nothing capExps <- unwrapN 1110 1113 , var == cast "&prefix:|<<" = do 1111 1114 caps <- mapM castVal =<< fromVals =<< (enterRValue $ enterEvalContext (cxtSlurpy "Capture") (Syn "," capExps)) 1112 af (Just (mconcat (resFeed:concatMap c_feedscaps))) args1115 af (Just (mconcat (resFeed:concatMap (fromP . c_feeds) caps))) args 1113 1116 | otherwise = do 1114 1117 argVal <- fromVal =<< reduce n 1115 af (Just resFeed{ f_positionals = (f_positionals resFeed) + + [argVal] }) args1118 af (Just resFeed{ f_positionals = (f_positionals resFeed) +:+ [:argVal:] }) args 1116 1119 where 1117 1120 unwrapN = unwrap n 1118 1121 resFeed = feed res 1119 1122 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:] 1121 1124 addNamed mp k v = 1122 1125 let id = cast k in 1123 Map.insertWith (flip (+ +)) id [v] mp1126 Map.insertWith (flip (+:+)) id [:v:] mp 1124 1127 1125 1128 dummyVar :: Var … … 1172 1175 (k, v) <- pair_fetch pv 1173 1176 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 x1179 concatNamed xs = VList (map castV xs)1177 interpolateVal (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)) 1180 1183 interpolateVal val = return [Val val] 1181 1184
