summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Main.hs9
-rw-r--r--Optimiser.hs2
-rw-r--r--Parser.hs2
3 files changed, 7 insertions, 6 deletions
diff --git a/Main.hs b/Main.hs
index c7ca464..83a0578 100644
--- a/Main.hs
+++ b/Main.hs
@@ -7,7 +7,7 @@ import System.Exit
import qualified System.Info as System (os)
import System.Process
-import AST
+-- import AST
import Compiler
import Interpreter
import Parser
@@ -32,13 +32,14 @@ main = do
-- putStrLn $ astSuccinct prog
-- print prog
let opt = optimise prog
- writeFile (fname ++ ".succinct") $ astSuccinct opt
- writeFile (fname ++ ".ast") $ show opt
+ -- writeFile (fname ++ ".succinct") $ astSuccinct opt
+ -- writeFile (fname ++ ".ast") $ show opt
case executionMode of
EMInterpret -> do
input <- getContents
- interpret opt (map (fromIntegral . ord) input) >>= (putStr . map (chr . fromIntegral))
+ output <- interpret opt $ map (fromIntegral . ord) input
+ putStr $ map (chr . fromIntegral) output
EMCompile -> do
writeFile (fname ++ ".asm") $ compile opt
diff --git a/Optimiser.hs b/Optimiser.hs
index a381bac..a71fd2b 100644
--- a/Optimiser.hs
+++ b/Optimiser.hs
@@ -126,7 +126,7 @@ specialLoops (ILoop [IAdd v off2] off1 : rest)
| odd v = ISet 0 off1 : specialLoops rest
specialLoops (ILoop inss off : rest)
| all isIAdd inss,
- sum (map (\(IAdd v _) -> v) $ filter ((== off) . offsetOf) inss) == -1 =
+ sum (map (\(IAdd v _) -> v) $ filter ((== off) . offsetOf) inss) == negate 1 =
let others = map (\(IAdd v o) -> (v, o)) $ filter ((/= off) . offsetOf) inss
dests = nub $ map snd others
copies = [ICopy off d (sum $ map fst $ filter ((== d) . snd) others) | d <- dests]
diff --git a/Parser.hs b/Parser.hs
index f2961ba..bc7ab24 100644
--- a/Parser.hs
+++ b/Parser.hs
@@ -25,7 +25,7 @@ parseLoop d (_:cs) = parseLoop d cs
parseSimple :: Char -> Maybe Instruction
parseSimple '+' = Just $ IAdd 1 0
-parseSimple '-' = Just $ IAdd (-1) 0
+parseSimple '-' = Just $ IAdd (negate 1) 0
parseSimple '>' = Just $ ISlide 1
parseSimple '<' = Just $ ISlide (-1)
parseSimple ',' = Just $ IInput 0