From 741e1140adb8fde14d626487b5dc8ef9416da1b5 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 10 Nov 2016 20:19:47 +0100 Subject: [PATCH] remove unneccesary tape updates and use $ --- .gitignore | 2 ++ cleanbf.icl | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4ad8ecb..e9f0215 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ bf bfll *.bf +Clean System Files +cleanbf diff --git a/cleanbf.icl b/cleanbf.icl index be3c422..57064c5 100644 --- a/cleanbf.icl +++ b/cleanbf.icl @@ -5,6 +5,8 @@ import System.CommandLine import Data.Error import System.File +from Data.Func import $ + import _SystemArray import StdEnv @@ -15,7 +17,7 @@ TAPESIZE :== 1024 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)} @@ -25,14 +27,14 @@ bf st=:{prog,pc,tc,tape,cs} 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 -- 2.20.1