Changeset 4544 for src/Pugs/Prim/List.hs

Show
Ignore:
Timestamp:
06/12/05 11:40:31 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
6289
Message:

Macros.
* t/macros/ -- unSKIP and more tests
* Pugs.Eval.Var -- New module containing findVar & co.
* Pugs.Prim.Param -- New module containing foldParam
* Pugs.Prim, Pugs.AST.Internals, Pugs.Eval, Pugs.Prim.List --

Moved several functions to new Pugs.Eval.Var, Pugs.Prim.Param, and
Pugs.Prim.List.

* Pugs.Parser -- Various calls to new fun possiblyApplyMacro.
* Pugs.Parser.Unsafe -- New fun possiblyApplyMacro.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/List.hs

    r3906 r4544  
     1{-# OPTIONS_GHC -fglasgow-exts #-} 
     2 
    13module Pugs.Prim.List ( 
    24    op0Zip, op1Pick, op1Sum, 
     
    46    op2FoldL, op2Fold, op2Grep, op2Map, op2Join, 
    57    sortByM, 
     8    op1HyperPrefix, op1HyperPostfix, op2Hyper, 
    69) where 
    710import Pugs.Internals 
    811import Pugs.AST 
    912import Pugs.Types 
     13import Pugs.Monads 
    1014import qualified Data.Set as Set 
    1115 
     
    285289                rest <- doMerge f (x:xs) ys 
    286290                return (y:rest) 
     291 
     292op1HyperPrefix :: VCode -> Val -> Eval Val 
     293op1HyperPrefix sub (VRef ref) = do 
     294    x <- readRef ref 
     295    op1HyperPrefix sub x 
     296op1HyperPrefix sub x 
     297    | VList x' <- x 
     298    = fmap VList $ hyperList x' 
     299    | otherwise 
     300    = fail "Hyper OP only works on lists" 
     301    where 
     302    doHyper x 
     303        | VRef x' <- x 
     304        = doHyper =<< readRef x' 
     305        | otherwise 
     306        = enterEvalContext cxtItemAny $ App (Val $ VCode sub) Nothing [Val x] 
     307    hyperList []     = return [] 
     308    hyperList (x:xs) = do 
     309        val  <- doHyper x 
     310        rest <- hyperList xs 
     311        return (val:rest) 
     312 
     313op1HyperPostfix :: VCode -> Val -> Eval Val 
     314op1HyperPostfix = op1HyperPrefix 
     315 
     316op2Hyper :: VCode -> Val -> Val -> Eval Val 
     317op2Hyper sub (VRef ref) y = do 
     318    x <- readRef ref 
     319    op2Hyper sub x y 
     320op2Hyper sub x (VRef ref) = do 
     321    y <- readRef ref 
     322    op2Hyper sub x y 
     323op2Hyper sub x y 
     324    | VList x' <- x, VList y' <- y 
     325    = fmap VList $ hyperLists x' y' 
     326    | VList x' <- x 
     327    = fmap VList $ mapM ((flip doHyper) y) x' 
     328    | VList y' <- y 
     329    = fmap VList $ mapM (doHyper x) y' 
     330    | otherwise 
     331    = fail "Hyper OP only works on lists" 
     332    where 
     333    doHyper x y = enterEvalContext cxtItemAny $ App (Val $ VCode sub) Nothing [Val x, Val y] 
     334    hyperLists [] [] = return [] 
     335    hyperLists xs [] = return xs 
     336    hyperLists [] ys = return ys 
     337    hyperLists (x:xs) (y:ys) = do 
     338        val  <- doHyper x y 
     339        rest <- hyperLists xs ys 
     340        return (val:rest) 
     341