]> ruin.nu Git - proglang.git/blobdiff - CompInt.hs
minor change
[proglang.git] / CompInt.hs
index 3b28c00c2d3c9c856b924200f0742343f19f7219..1934447c5e1110079dc94f93cf2867a9cfb52c47 100644 (file)
@@ -14,7 +14,6 @@ import Abssyntax
 import Typecheck
 import Interpret
 import Compile
-import Data.Map as Map hiding (showTree)
 
 import ErrM
 
@@ -22,32 +21,37 @@ type ParseFun a = [Token] -> Err a
 
 myLLexer = myLexer
 
+splitFunStm :: [FuncStm] -> ([Func],[Stm])
+splitFunStm [] = ([],[])
+splitFunStm ((F f):fss) = let (fs,ss) = splitFunStm fss in (f:fs,ss)
+splitFunStm ((S s):fss) = let (fs,ss) = splitFunStm fss in (fs,s:ss)
+
 putStrV :: Int -> String -> IO ()
 putStrV v s = if v > 1 then putStrLn s else return ()
 
-runFile :: ([Stm] -> IO()) -> ParseFun Stms -> FilePath -> IO ()
+runFile :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> FilePath -> IO ()
 runFile e p f = readFile f >>= run e p
 
-run :: ([Stm] -> IO()) -> ParseFun Stms -> String -> IO ()
+run :: ([Func] -> [Stm] -> IO()) -> ParseFun Program -> String -> IO ()
 run e p s = let ts = myLLexer s in case p ts of
        Bad s    -> do
                putStrLn "\nParse              Failed...\n"
                putStrLn "Tokens:"
                putStrLn $ show ts
                putStrLn s
-       Ok (Program s) -> do
-               typeCheck s
-               e s
+       Ok (Program s) -> let (fun,st) = splitFunStm (s) in do
+               typeCheck fun st
+               e fun st
 
 main :: IO ()
 main = do 
        args <- getArgs
        case args of
-               [] -> hGetContents stdin >>= run interpret pStms
+               [] -> hGetContents stdin >>= run interpret pProgram
                "-c":f:[] -> let file = (f++".c") in do
                        putStrLn $ "Compiling "++f++" to the C99-compatible file:"++file
-                       runFile (writeFile file . compile)  pStms f
-               f:[] -> runFile interpret pStms f
+                       runFile (\fun st -> writeFile file $ compile fun st)  pProgram f
+               f:[] -> runFile interpret pProgram f
                _ -> do
                        putStrLn "Usage: ./CompInt [-c] <file>"
                        putStrLn "-c : compile <file> to C99-compatible file"