Changeset 8226 for src/Pugs/Prim/Eval.hs

Show
Ignore:
Timestamp:
12/13/05 20:35:53 (3 years ago)
Author:
gaal
Message:

* Make %*INC more useful. Keys are now Perlish names, not relative paths

to filesystem resources. Values are (for now) a simple hash with
reasonable memebers (the relative and absolute paths); this will
eventually evolve to a Module description object of some sort. This
change needs to be specced.

Files:
1 modified

Legend:

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

    r8077 r8226  
    3030opRequire :: Bool -> Val -> Eval Val 
    3131opRequire dumpEnv v = do 
    32     file        <- fromVal v 
     32    mod         <- fromVal v 
    3333    incs        <- fromVal =<< readVar "@*INC" 
    3434    glob        <- askGlobal 
    3535    seen        <- findSymRef "%*INC" glob 
    3636    loaded      <- existsFromRef seen v 
     37    let file    = (concat $ intersperse "/" $ split "::" mod) ++ ".pm" 
    3738    pathName    <- requireInc incs file (errMsg file incs) 
    3839    if loaded then opEval style pathName "" else do 
    39         -- %*INC{file} = pathname 
     40        -- %*INC{mod} = { relname => file, pathname => pathName } 
    4041        evalExp $ Syn "=" 
    41             [ Syn "{}" 
    42                 [ Var "%*INC", Val . VStr $ decodeUTF8 file ] 
    43                 , Val . VStr $ decodeUTF8 pathName 
     42            [ Syn "{}"             -- subscript 
     43                [ Var "%*INC", Val . VStr $ decodeUTF8 mod ] 
     44                , Syn "\\{}"       -- hashref 
     45                    [ Syn "," [ mkStrPair "pathname" (decodeUTF8 pathName) 
     46                              , mkStrPair "relname"  (decodeUTF8 file) ] 
     47                    ] 
    4448            ] 
    4549        str         <- liftIO $ readFile pathName 
     
    5155                                           else EvalResultLastValue)} 
    5256    errMsg file incs = "Can't locate " ++ file ++ " in @*INC (@*INC contains: " ++ unwords incs ++ ")." 
     57    mkStrPair :: String -> String -> Exp 
     58    mkStrPair key val = App (Var "&infix:=>") Nothing (map (Val . VStr) [key, val]) 
    5359 
    5460requireInc :: (MonadIO m) => [FilePath] -> FilePath -> String -> m String