aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-07-18 08:59:23 +0000
committerCamil Staps2017-07-18 08:59:23 +0000
commit092a92a1c17470c2cd1cfbefdc8dc4c7c4038e41 (patch)
treea51dc49c00a61ca1a5353e47618e4891e8fdc32b
parentCompiling seems to work (diff)
Easier interface
-rw-r--r--.gitignore2
-rw-r--r--sil.icl68
-rw-r--r--test.sil13
3 files changed, 62 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 6fec853..c8e7bf9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
Clean System Files/
sil
+sil_compiled
+sil_compiled.dcl
diff --git a/sil.icl b/sil.icl
index 1ca0c81..bb39f1e 100644
--- a/sil.icl
+++ b/sil.icl
@@ -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
diff --git a/test.sil b/test.sil
index db3abaf..ebbfdda 100644
--- a/test.sil
+++ b/test.sil
@@ -1,12 +1,11 @@
-Int main () {
- Int x;
- Int y;
+Int second(Int x, Int y) {
Int z;
- x := 100;
- y := 50;
z := x;
x := y;
y := z;
- z := x;
- return z;
+ return y;
+}
+
+Int main () {
+ return second(100, 200);
}