ubcf/app/Main.hs

19 lines
550 B
Haskell
Raw Normal View History

2024-09-26 23:58:27 +02:00
module Main (main) where
import Lib
import Control.Monad (mapM_)
import Data.Binary (Word32, Word8, encode)
import Data.Bits
import qualified Data.ByteString.Lazy as BL
convertWord32 :: Word32 -> [Word8]
convertWord32 w = [fromIntegral (w), fromIntegral (w .>>. 8), fromIntegral (w .>>. 16), fromIntegral (w .>>. 24)]
main :: IO ()
main = do
s <- getContents
let tokens = tokenize s
case parseTokens tokens of
Left err -> putStr err
Right ops -> mapM_ (BL.putStr . encode) . (concatMap (convertWord32)) $ (compile ops)