import Data.Error
import System.File
+from Data.Func import $
+
import _SystemArray
import StdEnv
bf :: *BFState -> Either *BFState *BFState
bf st=:{prog,pc,tc,tape,cs}
| st.pc == size st.prog = Left st
-= let (b, tape`) = uselect tape tc in Right (case select prog pc of
+= let (b, tape`) = uselect tape tc in Right $ case select prog pc of
'<' = {st & pc=pc+1, tape=tape`, tc=tc-1}
'>' = {st & pc=pc+1, tape=tape`, tc=tc+1}
'+' = {st & pc=pc+1, tape=update tape` tc (b+1)}
in {st & pc=pc+1, tape=update tape` tc (toInt c), io=io}
'[' = let st` = {st & cs=[pc:cs], tape=tape`, pc=pc+1} in if (b == 0)
{st` & pc=1+(while (\pc`->select prog pc` <> ']') ((+) 1) pc)} st`
- ']' = {st & tape=tape`, pc=hd cs, cs=tl cs}
- _ = {st & pc=pc+1})
+ ']' = {st & pc=hd cs, cs=tl cs}
+ _ = {st & pc=pc+1}
f :: (.a -> (Either .a .a)) -> .(.a -> .a)
f g = (either id (f g)) o g
mkState :: !*File String -> *BFState
-mkState f s = {pc=0,tc=0,io=f,cs=[],tape={0\\_<-[0..1024]},prog=s}
+mkState f s = {pc=0,tc=0,io=f,cs=[],tape={0\\_<-[0..TAPESIZE]},prog=s}
Start w
# ([_:p], w) = getCommandLine w