Changeset 32 for src/Main.hs

Show
Ignore:
Timestamp:
02/16/05 18:48:28 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
1041
Message:

* Code literals -- "sub", "pointy" and "bare" variants all works
* Lexical subroutine declarations via "my sub"
* Global subroutine and variables work again, via the envGlobal pad
* The "say", "exit", "die" primitives
* Bool.perl now prints correct literals (lwall)
* Blocks under void contexts now evaluates automatically
* The "..." (dotdotdot) literal

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Main.hs

    r31 r32  
    2525 
    2626main :: IO () 
    27 main = getArgs >>= run 
     27main = do 
     28    args <- getArgs 
     29    run $ concatMap procArg args 
     30    where 
     31    procArg ('-':'e':prog@(_:_)) = ["-e", prog] 
     32    procArg ('-':'d':rest@(_:_)) = ["-d", ('-':rest)] 
     33    procArg x = [x] 
    2834 
    2935run :: [String] -> IO () 
     36run ("-d":rest)                 = run rest 
     37run ("-w":rest)                 = run rest 
    3038run (('-':'e':prog@(_:_)):args) = doRun "-" args prog 
    3139run ("-e":prog:args)            = doRun "-" args prog 
    3240run ("-h":_)                    = printHelp 
     41run ("-":args)                  = do 
     42    prog <- getContents 
     43    doRun "-" [] prog 
    3344run (file:args)                 = readFile file >>= doRun file args 
    3445run []                          = do 
     
    3748    if isTTY 
    3849        then banner >> repLoop 
    39         else do 
    40             prog <- getContents 
    41             doRun "-" [] prog 
     50        else run ["-"] 
    4251 
    4352repLoop :: IO () 
     
    6170 
    6271doEval :: [String] -> String -> IO () 
    63 doEval = runProgramWith (putStrLn . pretty) "<interactive>" 
     72doEval = do 
     73    runProgramWith id (putStrLn . pretty) "<interactive>" 
    6474 
    6575doRun :: String -> [String] -> String -> IO () 
    66 doRun = runProgramWith (putStr . concatMap vCast . vCast) 
     76doRun = do 
     77    runProgramWith (\e -> e{ envDebug = Nothing }) end 
     78    where 
     79    end v@(VError str exp)  = do 
     80        hPutStrLn stderr str 
     81        exitFailure 
     82    end _               = return () 
    6783 
    68 runProgramWith :: (Val -> IO ()) -> String -> [String] -> String -> IO () 
    69 runProgramWith f name args prog = do 
     84runProgramWith :: (Env -> Env) -> (Val -> IO ()) -> VStr -> [VStr] -> String -> IO () 
     85runProgramWith fenv f name args prog = do 
    7086    env <- emptyEnv 
    71     let env' = runRule (prepare env) id ruleProgram prog 
     87    let env' = runRule (prepare $ fenv env) id ruleProgram prog 
    7288    val <- (`runReaderT` env') $ do 
    7389        (`runContT` return) $ do 
     
    8096        ] ++ envGlobal e } 
    8197 
     98{- 
     99main = do 
     100    -- (optsIO, rest, errs) <- return . getOpt Permute options $ procArgs args 
     101 
     102options :: [OptDescr (Opts -> Opts)] 
     103options = 
     104    [ reqArg "e" ["eval"]           "command"       "Command-line program" 
     105        (\s o -> o { encodings          = split "," s }) 
     106    , noArg  "d" ["debug"]                          "Turn on debugging" 
     107        (\s o -> o { inputFile          = s }) 
     108    , noArg  "h" ["help"]                           "Show help" 
     109        (\o   -> o { showHelp           = usage "" }) 
     110    ] 
     111-} 
     112