feat[app]: dumping all the instruction forms
This commit is contained in:
parent
b44e238907
commit
7839627592
1 changed files with 16 additions and 2 deletions
18
app/Main.hs
18
app/Main.hs
|
@ -7,6 +7,12 @@ import qualified System.Environment as Env
|
|||
import qualified Language.Brainfuck as Brainfuck
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as TextIO
|
||||
import qualified Data.Vector as Vector
|
||||
import qualified Language.Brainfuck.Instruction.Compressed as CompressedInstruction
|
||||
import qualified Language.Brainfuck.Instruction.Extended as ExtendedInstruction
|
||||
|
||||
dumpVector :: Show a => FilePath -> Vector.Vector a -> IO ()
|
||||
dumpVector path = TextIO.writeFile path . Text.unlines . map (Text.pack . show) . Vector.toList
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
@ -14,6 +20,14 @@ main = do
|
|||
[x] -> pure x
|
||||
_ -> error "usage: [program] source.bf"
|
||||
|
||||
instructions <- Brainfuck.parse <$!> TextIO.readFile programFile
|
||||
instructions <- (Brainfuck.parse <$!> TextIO.readFile programFile) >>= \case
|
||||
Left failure -> error $ show failure
|
||||
Right x -> pure x
|
||||
|
||||
mapM_ (TextIO.putStrLn . Text.pack . show) instructions
|
||||
dumpVector "native.bf" instructions
|
||||
|
||||
let compressed = CompressedInstruction.compress instructions
|
||||
dumpVector "compressed.bf" compressed
|
||||
|
||||
let extended = ExtendedInstruction.parse compressed
|
||||
dumpVector "extended.bf" extended
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue