git @ Cat's Eye Technologies UampirNexol / aaee498
Treat warnings as errors. Clean up following that. Chris Pressey a month ago
7 changed file(s) with 21 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
77
88 if command -v ghc >/dev/null 2>&1; then
99 echo "building $PROG.exe with ghc"
10 (cd src && ghc --make Main.hs -o ../bin/$PROG.exe)
10 WARNS="-Wall -Wno-missing-signatures -Werror"
11 (cd src && ghc $WARNS --make Main.hs -o ../bin/$PROG.exe)
1112 else
1213 echo "ghc not found, not building $PROG.exe"
1314 fi
99 -- meanings of (and can thus assign meanings to) UampirNexol expressions.
1010 --
1111
12 import Language.UampirNexol.Type
1312 import Language.UampirNexol.State
1413 import Language.UampirNexol.Expr
1514
7473 then eval thenP s
7574 else eval elseP s
7675
76 eval other _ =
77 error $ "unsupported for eval: " ++ show other
78
7779 evalCond :: Condition -> State -> Bool
7880 evalCond (IsSet loc) s = (fetch loc s) /= 0
7981 evalCond (IsUnset loc) s = (fetch loc s) == 0
77 -- Data structures describing UampirNexol expressions
88 -- (which denote 6502 programs).
99 --
10
11 import qualified Data.Set as Set
1210
1311 import Language.UampirNexol.State
1412
5050 in
5151 c1 ++ [offset1] ++ f ++ c2a ++ [offset2a] ++ c2b ++ [offset2b] ++ t
5252
53 extract other =
54 error $ "unsupported for extraction: " ++ show other
55
5356 extractCond (IsSet Z) = [0xf0] -- BEQ
5457 extractCond (IsSet N) = [0x30] -- BMI
5558 extractCond (IsSet C) = [0xb0] -- BCS
5760 extractCond (IsUnset Z) = [0xd0] -- BNE
5861 extractCond (IsUnset N) = [0x10] -- BPL
5962 extractCond (IsUnset C) = [0x90] -- BCC
63
64 extractCond other =
65 error $ "unsupported for extraction: " ++ show other
6066
6167 computeOffset distance =
6268 -- TODO check this offset is within range
2424 import Prelude hiding (sequence)
2525 import Text.Parsec
2626 import Text.Parsec.String (Parser)
27 import Text.Parsec.Char
28 import Text.Parsec.Combinator
2927 import qualified Text.Parsec.Token as Token
3028 import Text.Parsec.Language (emptyDef)
3129
119117 ifP = do
120118 reserved "if"
121119 whiteSpace
122 condition <- condition
120 cond <- condition
123121 whiteSpace
124122 thenBranch <- expr
125123 whiteSpace
126124 reserved "else"
127125 whiteSpace
128126 elseBranch <- expr
129 return $ If condition thenBranch elseBranch
127 return $ If cond thenBranch elseBranch
130128
131129 repeatP :: Parser Expr
132130 repeatP = do
136134 whiteSpace
137135 reserved "until"
138136 whiteSpace
139 condition <- condition
140 return $ Repeat body condition
137 cond <- condition
138 return $ Repeat body cond
141139
142140 whileP :: Parser Expr
143141 whileP = do
144142 reserved "while"
145143 whiteSpace
146 condition <- condition
144 cond <- condition
147145 whiteSpace
148146 reserved "do"
149147 whiteSpace
150148 body <- expr
151 return $ If condition (Repeat body (compCond condition)) Skip
149 return $ If cond (Repeat body $ compCond cond) Skip
152150
153151 expr :: Parser Expr
154152 expr = sequence <|> expr1
5555 typeOf (IntLit _) = Right TByte
5656
5757 typeOf LDA_i =
58 let
59 Right t = tprog [] [A, Z, N]
60 in
61 Right $ TFunction TByte t
58 case tprog [] [A, Z, N] of
59 Right t -> Right $ TFunction TByte t
60 other -> other
6261 typeOf TAX = tprog [A] [X, Z, N]
6362 typeOf TAY = tprog [A] [Y, Z, N]
6463 typeOf CLC = tprog [] [C]
7271 (Right (TFunction tIn tOut), Right tArg) ->
7372 if tcompat tIn tArg then Right tOut else Left "Unacceptable argument type"
7473 (Right other, Right _) ->
75 Left "Application of non-function"
74 Left $ "Application of non-function " ++ show other
7675 (Left e, Right _) ->
7776 Left e
7877 (Right _, Left e) ->
6262 putStrLn $ show $ typ
6363 ["run", fileName] -> do
6464 programText <- readFile fileName
65 programText <- readFile fileName
6665 case parseProgram programText of
6766 Left e -> do
6867 abortWith $ "error: " ++ show e