1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-07 06:29:32 +00:00

Three passing tests!

This commit is contained in:
Cat's Eye Technologies 2014-03-31 23:31:30 +01:00
parent 650405c2fe
commit b4eb0b0100
3 changed files with 49 additions and 15 deletions

28
README.markdown Normal file
View File

@ -0,0 +1,28 @@
SixtyPical
==========
-> Tests for functionality "Parse SixtyPical program"
-> Functionality "Parse SixtyPical program" is implemented by
-> shell command "bin/sixtypical parse %(test-file)"
| routine main {
| nop
| }
= Program [] [Routine "main" [NOP]]
| reserve word score
| assign word scram 4000
| routine main {
| lda scram
| cmp score
| }
= Program [Reserve "score" Word,Assign "scram" Word 4000] [Routine "main" [LOAD A "scram",CMP A "score"]]
All declarations (`reserve`s and `assign`s) must come before any `routines`.
| routine main {
| lda scram
| }
| reserve word score
? expecting "routine"

View File

@ -1,7 +1,6 @@
-- encoding: UTF-8
module Main where
--module Sixtype where
import qualified Data.Map as Map
@ -189,7 +188,13 @@ block = do
return cs
command :: Parser Instruction
command = cmp <|> lda <|> beq
command = cmp <|> lda <|> beq <|> nop
nop :: Parser Instruction
nop = do
string "nop"
spaces
return NOP
cmp :: Parser Instruction
cmp = do
@ -237,24 +242,22 @@ address = do
-- -- -- -- driver -- -- -- --
usage = do
putStrLn "Usage: sixtypical (parse|check) filename.60pical"
exitWith $ ExitFailure 1
main = do
args <- getArgs
case args of
[filename] -> do
[verb, filename] -> do
programText <- readFile filename
case parse toplevel "" programText of
Right program -> do
case (verb, parse toplevel "" programText) of
("parse", Right program) -> do
putStrLn $ show $ program
("check", Right program) -> do
putStrLn $ show $ checkProgram program
Left problem -> do
(_, Left problem) -> do
hPutStrLn stderr (show problem)
exitWith $ ExitFailure 1
_ -> do
putStrLn "Usage: sixtypical filename.60pical"
exitWith $ ExitFailure 1
{-
test = checkProgram [(Routine "wait" [LOAD Y "score", COPY Y A]),
(Routine "main" [LOAD X "score", JSR "wait"])]
Map.empty
-}
(_, _) -> usage
_ -> usage

3
test.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
./build.sh && falderal --substring-error README.markdown