Fix label and Op show

This commit is contained in:
Enrico Lumetti 2024-10-13 20:22:21 +02:00
parent 08049e9955
commit 27f24389ae
2 changed files with 22 additions and 18 deletions

View File

@ -120,24 +120,24 @@ instrFromString s
instance Show InstrOperation where instance Show InstrOperation where
show op = case op of show op = case op of
Nop -> "add" Add -> "add"
Add -> "sub" Sub -> "sub"
Sub -> "mul" Mul -> "mul"
Mul -> "eq" Eq -> "eq"
Eq -> "lt" Lt -> "lt"
Lt -> "gt" Gt -> "gt"
Gt -> "le" Le -> "le"
Le -> "ge" Ge -> "ge"
Ge -> "not" Not -> "not"
Not -> "and" And -> "and"
And -> "or" Or -> "or"
Or -> "jmp" Jmp -> "jmp"
Jmp -> "br" Br -> "br"
Br -> "ret" Ret -> "ret"
Ret -> "call" Call -> "call"
Call -> "print" Print -> "print"
Print -> "id" Id -> "id"
Id -> "nop" Nop -> "nop"
optionalArrayField :: FromJSON a => Data.Aeson.Object -> Data.Aeson.Key -> Parser [a] optionalArrayField :: FromJSON a => Data.Aeson.Object -> Data.Aeson.Key -> Parser [a]

View File

@ -81,6 +81,10 @@ testInstrs = TestCase $ do
(eitherDecode "{\"op\": \"id\", \"dest\": \"a\", \"type\": \"bool\", \"args\": [\"b\"]}") (eitherDecode "{\"op\": \"id\", \"dest\": \"a\", \"type\": \"bool\", \"args\": [\"b\"]}")
(Right $ B.ValueInstr B.Id B.Bool "a" ["b"] [] []) (Right $ B.ValueInstr B.Id B.Bool "a" ["b"] [] [])
assertEqual "parse label"
(eitherDecode "{\"label\": \"test\"}")
(Right $ B.Label "test")
testProgramFromFiles :: Test testProgramFromFiles :: Test
testProgramFromFiles = TestCase $ do testProgramFromFiles = TestCase $ do
res <- try $ (B.parseBrilFromPath "bril-sources/add.json") :: IO (Either IOError (Either String B.Program)) res <- try $ (B.parseBrilFromPath "bril-sources/add.json") :: IO (Either IOError (Either String B.Program))