diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-12-17 22:30:06 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-12-17 22:30:06 +0100 |
commit | 594ecf396cad8a38aac168062249ab3361c5b558 (patch) | |
tree | 8852897cfbfd8cf7bcda97760c7cfa4f000cc762 | |
parent | ef9684b0bf2780800ae3349819239e4f0a0c9c25 (diff) |
Move old things out of the way
-rw-r--r-- | main.hs | 55 | ||||
-rw-r--r-- | old/interpreter.hs (renamed from interpreter.hs) | 0 | ||||
-rw-r--r-- | old/stdlib.hs (renamed from stdlib.hs) | 0 | ||||
-rw-r--r-- | test.hs | 16 |
4 files changed, 0 insertions, 71 deletions
@@ -1,17 +1,11 @@ module Main where -import Data.Char -import Data.List -import System.Console.Readline import System.Environment import System.Exit -import System.IO.Error import Compiler -import Interpreter import Optimiser import Parser -import Stdlib import VM @@ -20,55 +14,6 @@ usage = do progname <- getProgName putStrLn $ "Usage: " ++ progname ++ " [filename.lisp]" -repl :: Context -> IO () -repl ctx = do - mline <- fmap (fmap strip) (readline "> ") - case mline of - Nothing -> putStrLn "" - Just "" -> repl ctx - Just (';' : _) -> repl ctx - Just line -> do - addHistory line - case parseExpression line of - Right val -> do - ires <- interpret ctx val - case ires of - Right (retval, ctx') -> do - putStrLn $ "\x1B[36m" ++ show retval ++ "\x1B[0m" - repl ctx' - Left err -> do - putStrLn $ "\x1B[31;1mError: " ++ err ++ "\x1B[0m" - repl ctx - Left err -> do - putStrLn $ "\x1B[31;1mParse error:\n" ++ show err ++ "\x1B[0m" - repl ctx - -runFile :: String -> Context -> IO () -runFile fname ctx = do - source <- readFile fname - case parseProgram source of - Right ast -> do - res <- interpretProgram ctx ast - case res of - Right _ -> return () - Left err -> die $ "Error: " ++ err - Left err -> die $ "Parse error:\n" ++ show err - -strip :: String -> String -strip = dropWhileEnd isSpace . dropWhile isSpace - -handleEOFError :: IO () -> IO () -handleEOFError op = catchIOError op (\e -> if isEOFError e then putStrLn "" else ioError e) - --- main :: IO () --- main = do --- clargs <- getArgs --- Right ctx <- interpretProgram newContext stdlib --- case clargs of --- [] -> handleEOFError (repl ctx) --- [fname] -> runFile fname ctx --- _ -> usage >> exitFailure - main :: IO () main = do clargs <- getArgs diff --git a/interpreter.hs b/old/interpreter.hs index 4595035..4595035 100644 --- a/interpreter.hs +++ b/old/interpreter.hs diff --git a/stdlib.hs b/old/stdlib.hs index 6f7334f..6f7334f 100644 --- a/stdlib.hs +++ b/old/stdlib.hs diff --git a/test.hs b/test.hs deleted file mode 100644 index a763524..0000000 --- a/test.hs +++ /dev/null @@ -1,16 +0,0 @@ -import System.Exit - -import Compiler -import Optimiser -import Parser -import VM - -main :: IO () -main = do - -- let Right p = parseProgram "(print (lambda (n) ((lambda (helper) (if (<= n 0) 0 (if (<= n 2) 1 (helper helper 1 1 (- n 2))))) (lambda (recur a b n) (if (<= n 0) b (recur recur b (+ a b) (- n 1)))))))" - -- let Right p = parseProgram "(print ((lambda (n) ((lambda (helper) (if (<= n 0) 0 (if (<= n 2) 1 (helper helper 1 1 (- n 2))))) (lambda (recur a b n) (if (<= n 0) b (recur recur b (+ a b) (- n 1)))))) 6))" - let Right p = parseProgram "(do (define f (lambda (n) (+ n 1))) (print (f 10)))" - prog <- either die return (compileProgram p) - let opt = optimise prog - print opt - vmRun opt |