diff options
author | Camil Staps | 2017-07-18 08:59:23 +0000 |
---|---|---|
committer | Camil Staps | 2017-07-18 08:59:23 +0000 |
commit | 092a92a1c17470c2cd1cfbefdc8dc4c7c4038e41 (patch) | |
tree | a51dc49c00a61ca1a5353e47618e4891e8fdc32b /sil.icl | |
parent | Compiling seems to work (diff) |
Easier interface
Diffstat (limited to 'sil.icl')
-rw-r--r-- | sil.icl | 68 |
1 files changed, 54 insertions, 14 deletions
@@ -7,6 +7,7 @@ from StdFunc import o, seq import StdList import StdOverloaded import StdString +import StdTuple import Control.Applicative import Control.Monad @@ -15,6 +16,7 @@ from Data.Func import $ import Data.Functor import System.CommandLine import System.File +import System.Process import ABC.Assembler @@ -29,6 +31,8 @@ from Sil.Util import :: PrintState, instance zero PrintState, :: CLI = { prettyprint :: Bool , compile :: Bool + , generate :: Bool + , run :: Bool , inputfile :: String } @@ -37,41 +41,66 @@ where zero = { prettyprint = False , compile = False + , generate = False + , run = False , inputfile = "" } Start w # (io,w) = stdio w +# err = stderr # (cmd,w) = getCommandLine w # (args,_) = runParser (arg until eof) $ tl cmd | isError args - # io = io <<< toString (fromError args) <<< "\r\n" - # (_,w) = fclose io w - = w + # err = err <<< toString (fromError args) <<< "\r\n" + = finish io err w # args = seq (fromOk args) zero # (file,w) = readFile args.inputfile w | isError file - # io = io <<< "Could not open '" <<< args.inputfile <<< "'.\r\n" - # (_,w) = fclose io w - = w + # err = err <<< "Could not open '" <<< args.inputfile <<< "' for reading.\r\n" + = finish io err w # prog = tokenise (fromString $ fromOk file) >>= parse | isError prog - # io = io <<< toString (fromError prog) <<< "\r\n" - # (_,w) = fclose io w - = w + # err = err <<< toString (fromError prog) <<< "\r\n" + = finish io err w # io = if args.prettyprint (io <<< print zero (fromOk prog) <<< "\r\n") io -# io = if args.compile - (io <<< ('SC'.compile (fromOk prog)) <<< "\r\n") - io -# (_,w) = fclose io w -= w +| not args.compile + = finish io err w +# (ok,f,w) = fopen "sil_compiled.dcl" FWriteText w +| not ok + # err = err <<< "Could not open 'sil_compiled.dcl' for writing\r\n" + = finish io err w +# f = f <<< "definition module sil_compiled" +# (_,w) = fclose f w +# (_,w) = sleep 1 w +# (ok,f,w) = fopen "Clean System Files/sil_compiled.abc" FWriteText w +| not ok + # err = err <<< "Could not open 'sil_compiled.abc' for writing\r\n" + = finish io err w +# f = f <<< 'SC'.compile (fromOk prog) +# (_,w) = fclose f w +| not args.generate + = finish io err w +# (p,w) = callProcess "/opt/clean/bin/clm" ["sil_compiled", "-o", "sil_compiled"] Nothing w +| isError p + # err = err <<< snd (fromError p) <<< "\r\n" + = finish io err w +| not args.run + = finish io err w +# (p,w) = callProcess "./sil_compiled" [] Nothing w +| isError p + # err = err <<< snd (fromError p) <<< "\r\n" + = finish io err w += finish io err w where arg :: Parser String (CLI -> CLI) arg = peek >>= \opt -> ( item "--pretty-print" *> pure (\cli -> {cli & prettyprint=True}) <|> item "--compile" *> pure (\cli -> {cli & compile=True}) + <|> item "--generate" *> pure (\cli -> {cli & generate=True}) + <|> item "--run" *> pure (\cli -> {cli & run=True}) <|> (satisfy isFilename >>= \name -> pure (\cli -> {cli & inputfile=name})) <?> Invalid "command line argument" opt ) @@ -79,6 +108,17 @@ where isFilename :: (String -> Bool) isFilename = all (\c -> isAlphanum c || isMember c ['.']) o fromString + finish :: !*File !*File !*World -> *World + finish io err w + # (_,w) = fclose io w + # (_,w) = fclose err w + = w + + sleep :: !Int !*World -> *(!Int, !*World) + sleep i w = code inline { + ccall sleep "I:I:A" + } + instance <<< (MaybeError e a) | <<< e & <<< a where <<< f (Ok a) = f <<< a |