Changeset 3724 for src/Pugs/Eval.hs
- Timestamp:
- 05/23/05 13:09:12 (4 years ago)
- svk:copy_cache_prev:
- 5313
- Files:
-
- 1 modified
-
src/Pugs/Eval.hs (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Eval.hs
r3709 r3724 58 58 => String -- ^ Name associated with the environment 59 59 -> [STM (Pad -> Pad)] -- ^ List of 'Pad'-mutating transactions used 60 -- to declare an initial set of global vars60 -- to declare an initial set of global vars 61 61 -> m Env 62 62 emptyEnv name genPad = do … … 224 224 | otherwise = doFindVarRef name 225 225 where 226 doFindVarRef :: Var -> Eval (Maybe (TVar VRef)) 226 227 doFindVarRef name = do 227 228 callCC $ \foundIt -> do … … 665 666 _ -> retError "Unknown syntactic construct" exp 666 667 where 668 doCond :: (Bool -> Bool) -> Eval Val 667 669 doCond f = do 668 670 let [cond, bodyIf, bodyElse] = exps … … 673 675 else reduce bodyElse 674 676 -- XXX This treatment of while/until loops probably needs work 677 doWhileUntil :: (Bool -> Bool) -> Eval Val 675 678 doWhileUntil f = do 676 679 let [cond, body] = exps … … 722 725 shiftT $ const (retVal val) 723 726 where 727 callerEnv :: Env -> Env 724 728 callerEnv env = let caller = maybe env id (envCaller env) in 725 729 env{ envCaller = envCaller caller … … 750 754 where 751 755 err = retError "No compatible subroutine found" name 756 applySub :: VCode -> [Exp] -> [Exp] -> Eval Val 752 757 applySub sub invs args 753 758 -- list-associativity … … 770 775 | otherwise 771 776 = apply sub invs args 777 mungeChainSub :: VCode -> [Exp] -> Eval Val 772 778 mungeChainSub sub invs = do 773 779 let MkCode{ subAssoc = "chain", subParams = (p:_) } = sub … … 777 783 Just sub' -> applyChainSub sub invs sub' invs' args' rest 778 784 Nothing -> apply sub{ subParams = (length invs) `replicate` p } invs [] -- XXX Wrong 785 applyChainSub :: VCode -> [Exp] -> VCode -> [Exp] -> [a] -> [Exp] -> Eval Val 779 786 applyChainSub sub invs sub' invs' args' rest 780 787 | MkCode{ subAssoc = "chain", subBody = fun, subParams = prm } <- sub … … 1044 1051 -- XXX - faking application of lexical contexts 1045 1052 -- XXX - what about defaulting that depends on a junction? 1046 -- |Apply a sub (or other code) to lists of invocants 1047 -- and arguments, in the specified context. 1053 {-| 1054 Apply a sub (or other code) to lists of invocants and arguments, in the 1055 specified context. 1056 -} 1048 1057 doApply :: Env -- ^ Environment to evaluate in 1049 1058 -> VCode -- ^ Code to apply … … 1078 1087 | typ >= SubBlock = id 1079 1088 | otherwise = resetT 1089 fixEnv :: Env -> Env 1080 1090 fixEnv env 1081 1091 | typ >= SubBlock = env … … 1117 1127 return (VRef ref) 1118 1128 return (val, (isSlurpyCxt cxt || isCollapsed (typeOfCxt cxt))) 1129 checkSlurpyLimit :: (VInt, Exp) -> Eval [Val] 1119 1130 checkSlurpyLimit (n, exp) = do 1120 1131 listVal <- enterLValue $ enterEvalContext (cxtItem "Array") exp … … 1122 1133 elms <- mapM fromVal list -- flatten 1123 1134 return $ genericDrop n (concat elms :: [Val]) 1135 isCollapsed :: Type -> Bool 1124 1136 isCollapsed typ 1125 1137 | isaType (envClasses env) "Bool" typ = True
