diff --git a/Core.hs b/Core.hs index 7c04844..86d46f6 100644 --- a/Core.hs +++ b/Core.hs @@ -139,7 +139,8 @@ collectV (CrApp e0 e1)=collectV e0 `S.union` collectV e1 collectV (CrLet _ bs e)=S.unions $ map collectV $ e:map snd bs collectV (CrCase e cs)=S.unions $ map collectV $ e:map thr3 cs collectV (CrLm as e)=collectV e - +collectV (CrByte _)=S.empty +collectV e=error $ "collectV: "++show e diff --git a/Main.hs b/Main.hs index b0897e5..bf1ad44 100644 --- a/Main.hs +++ b/Main.hs @@ -51,7 +51,7 @@ data Option=Option -- | Parse arguments to 'Command'. Note this is a total function. parseArgs :: [String] -> Command -parseArgs []=ShowMessage version +parseArgs []=ShowMessage $ version++"\n"++help parseArgs ("-v":_)=ShowMessage version parseArgs ("--version":_)=ShowMessage version parseArgs ("-h":_)=ShowMessage $ version++"\n"++help @@ -102,7 +102,7 @@ execCommand (Compile opt from)=partialChain opt from $ where f g=runProcessWithIO (putStr . g) partialChain opt from (c0,c1,g0,g1,s0,s1,b)=do - dir<-liftM takeDirectory $ Paths_hs2bf.getDataFileName "Prelude.hs" + dir<-Paths_hs2bf.getDataDir let (mod,env)=analyzeName from dir xs<-Front.collectModules env mod let cr =xs >>= Front.compile @@ -142,7 +142,7 @@ help=unlines $ ," -Sgr: to GMachine (simplified)" ," -Ss : to SAM" ," -Ssf: to SAM (most simplified)" - ," -Sr : to SCGR" +-- ," -Sr : to SCGR" -- not implemented ," -Sb : to BF" ," --addr n : use n byte for pointer arithmetic" ," --debug : include detailed error message (this will make the program a LOT larger)" diff --git a/SCGR.hs b/SCGR.hs index 6b617d5..5b0a86b 100644 --- a/SCGR.hs +++ b/SCGR.hs @@ -1,4 +1,4 @@ --- | Super-cool-graph-representation +-- | Super-cool-graph-representation (this module is not used now) -- -- There are 3 goals in optimization: -- diff --git a/hs2bf.cabal b/hs2bf.cabal index 4dbc694..debefdd 100644 --- a/hs2bf.cabal +++ b/hs2bf.cabal @@ -1,17 +1,19 @@ name: hs2bf cabal-version: >=1.2 -version: 0.5 +version: 0.6 author: xanxys maintainer: xanxys@gmail.com synopsis: Haskell to Brainfu*k compiler license: BSD3 license-File: LICENSE category: Compiler -description: Haskell to Brainfu*k compiler. +description: + Proof of concept implementation of Haskell to Brainfu*k compiler. + You can find examples of compilable codes at http://www.xanxys.net/public/hs2bf-demo/ build-type: Simple data-files: Prelude.hs data-dir: test -tested-with: GHC==6.10.4 +tested-with: GHC==6.10.4,GHC==6.12.1 extra-source-files: Front.hs Core.hs GMachine.hs SAM.hs SCGR.hs Brainfuck.hs Util.hs SRuntime.hs diff --git a/test/Prelude.hs b/test/Prelude.hs deleted file mode 100644 index b214cf9..0000000 --- a/test/Prelude.hs +++ /dev/null @@ -1,174 +0,0 @@ - --- internal -seq=undefined -undefined=undefined -addByteRaw=undefined -subByteRaw=undefined -cmpByteRaw=undefined - - --- generic combinanors -infixr 9 . -(.) f g x=f (g x) - -infixr 0 $ -f $ x=f x - -infixr 0 $! -f $! x=x `seq` (f x) - - -id x=x -flip f x y=f y x - - --- boolean -data Bool - =False - |True - -infixr 2 || -x || y= - case x of - True -> True - False -> y - -infixr 3 && -x && y= - case x of - False -> False - True -> y - -otherwise=True - - --- maybe -data Maybe a - =Nothing - |Just a - - --- either -data Either a b - =Left a - |Right b - - --- ordering -data Ordering - =EQ -- 0 - |LT -- 1 - |GT -- 2 - - --- tuple -data XT1 a=XT1 a -data XT2 a b=XT2 a b -data XT3 a b c=XT3 a b c - - - --- list -data XList a - =XCons a (XList a) - |XNil - - -head (x:xs)=x -tail (x:xs)=xs - -reverse []=[] -reverse (x:xs)=reverse xs++[x] - -map f []=[] -map f (x:xs)=f x:map f xs - -filter f []=[] -filter f (x:xs) - |f x = x:filter f xs - |otherwise = filter f xs - -(x:xs) !! n - |n `eqByte` 0 = x - |otherwise = xs !! (n `subByte` 1) - -xs ++ ys= - case xs of - [] -> ys - x:xs -> x:(xs++ys) - - -{- I don't know why, but this code doesn't work! -[]++ys=ys -(x:xs)++ys=x:(xs++ys) --} - - - -length []=0 -length (x:xs)=1 `addByte` (length xs) - -foldr f z []=z -foldr f z (x:xs)=f x (foldr f z xs) - -foldl f z []=z -foldl f z (x:xs)=foldl f (f x z) xs - - --- I/O -data E - =Input (Char -> E) - |Output !Char E - |Halt - - - - - - -addByte x y=x `seq` (y `seq` (addByteRaw x y)) -subByte x y=x `seq` (y `seq` (subByteRaw x y)) -cmpByte x y=x `seq` (y `seq` (cmpByteRaw x y)) - -eqByte x y=case cmpByte x y of - EQ -> True - s -> False - -ltByte x y=case cmpByte x y of - LT -> True - s -> False - -gtByte x y=case cmpByte x y of - GT -> True - s -> False - -leByte x y=case cmpByte x y of - GT -> False - s -> True - -geByte x y=case cmpByte x y of - LT -> False - s -> True - -{- -data Int - =PInt Byte - |NInt Byte - - -negateInt (PInt x)=NInt x -negateInt (NInt x)=PInt x - -addInt (PInt x) (PInt y)=PInt $ x `addByte` y -addInt (NInt x) (NInt y)=NInt $ x `addByte` y -addInt (PInt x) (NInt y) - |x `gtByte` y = PInt $ x `subByte` y - |otherwise = NInt $ y `subByte` x -addInt (NInt x) (PInt y) - |x `gtByte` y = NInt $ x `subByte` y - |otherwise = PInt $ y `subByte` x - --} - - -