implemented the program
This commit is contained in:
commit
e58810fea4
16 changed files with 1144 additions and 0 deletions
35
app/Main.hs
Normal file
35
app/Main.hs
Normal file
|
@ -0,0 +1,35 @@
|
|||
-- ubcf - compiling brainfuck programs into ubc bytecode
|
||||
-- Copyright (C) 2024 VegOwOtenks
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU Affero General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU Affero General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- contact me via vegowotenks at jossco dot de
|
||||
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)
|
Loading…
Add table
Add a link
Reference in a new issue