Changeset 3414 for src/Pugs/Eval.hs

Show
Ignore:
Timestamp:
05/19/05 00:33:06 (4 years ago)
Author:
iblech
svk:copy_cache_prev:
4977
Message:

Autogenerated &prefix:[...]! :)
(But the parser doesn't seem to accept multichar ops, but that's another story.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r3372 r3414  
    4747import Pugs.Types 
    4848import Pugs.Prim.Eval (retEvalResult) 
     49import Pugs.Prim.List (op2Fold) 
    4950import Pugs.External 
    5051 
     
    787788            subs    <- findWithPkg (showType typ) 
    788789            if isJust subs then return subs else findSub' name 
    789         _ -> findSub' name 
     790        _ -> do 
     791            sub <- findSub' name 
     792            if isNothing sub then possiblyBuildMetaopVCode name else return sub 
    790793    where 
     794    possiblyBuildMetaopVCode ('&':'p':'r':'e':'f':'i':'x':':':'[':op') = do 
     795        -- Strip the trailing "]" from op 
     796        let op = init op' 
     797        trace (show $ invs) return () 
     798        trace (show $ args) return () 
     799        -- We try to find the userdefined sub. 
     800        -- We use the first two elements of invs as invocants, as these are the 
     801        -- types of the op. 
     802        userdefined_sub <- findSub ("&infix:" ++ op) (take 2 invs) [] 
     803        subbody <- return $ case userdefined_sub of 
     804            -- If we've found a userdefined sub, we use it. 
     805            (Just sub) -> Prim $ \_ -> do 
     806                              list_of_args <- return $ map evaluate invs 
     807                              list_of_args' <- mapM (\a -> do { z <- a; return z }) list_of_args 
     808                              op2Fold (VList list_of_args') (VCode sub) 
     809            -- Else, we use the code as defined in Pugs.Prim 
     810            _          -> Prim $ f op 
     811        -- Now we construct the sub. Is there a more simple way to do it? 
     812        code <- return $ mkPrim 
     813                            { subName     = "&prefix:[" ++ op ++ "]" 
     814                            , subType     = SubPrim 
     815                            , subAssoc    = "spre" 
     816                            , subParams   = params 
     817                            , subReturns  = mkType "Str" 
     818                            , subBody     = subbody 
     819                            } 
     820        return $ Just code 
     821        where 
     822        -- Taken from Pugs.Prim. Probably this should be refactored. (?) 
     823        f op     = \[a] -> op1 ("[" ++ op ++ "]") a 
     824        prms'    = map takeWord ["(List)"] 
     825        prms''   = foldr foldParam [] prms' 
     826        params   = map (\p -> p{ isWritable = isLValue p }) prms'' 
     827        takeWord = takeWhile isWord . dropWhile (not . isWord) 
     828        isWord   = not . (`elem` "(),:") 
     829    possiblyBuildMetaopVCode _ = return Nothing 
    791830    findWithPkg pkg = do 
    792831        subs <- findSub' (('&':pkg) ++ "::" ++ tail name)