1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-01-27 21:31:25 +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 -- encoding: UTF-8
module Main where module Main where
--module Sixtype where
import qualified Data.Map as Map import qualified Data.Map as Map
@ -189,7 +188,13 @@ block = do
return cs return cs
command :: Parser Instruction 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 :: Parser Instruction
cmp = do cmp = do
@ -237,24 +242,22 @@ address = do
-- -- -- -- driver -- -- -- -- -- -- -- -- driver -- -- -- --
usage = do
putStrLn "Usage: sixtypical (parse|check) filename.60pical"
exitWith $ ExitFailure 1
main = do main = do
args <- getArgs args <- getArgs
case args of case args of
[filename] -> do [verb, filename] -> do
programText <- readFile filename programText <- readFile filename
case parse toplevel "" programText of case (verb, parse toplevel "" programText) of
Right program -> do ("parse", Right program) -> do
putStrLn $ show $ program putStrLn $ show $ program
("check", Right program) -> do
putStrLn $ show $ checkProgram program putStrLn $ show $ checkProgram program
Left problem -> do (_, Left problem) -> do
hPutStrLn stderr (show problem) hPutStrLn stderr (show problem)
exitWith $ ExitFailure 1 exitWith $ ExitFailure 1
_ -> do (_, _) -> usage
putStrLn "Usage: sixtypical filename.60pical" _ -> usage
exitWith $ ExitFailure 1
{-
test = checkProgram [(Routine "wait" [LOAD Y "score", COPY Y A]),
(Routine "main" [LOAD X "score", JSR "wait"])]
Map.empty
-}

3
test.sh Executable file
View File

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