Anonymous avatar Anonymous committed 07f3f3c

more groups

Comments (0)

Files changed (1)

brainfuck/brainfuck.ml

     | Add a :: Add b :: rest ->
         let lst = if a + b <> 0 then Add (a + b) :: rest else rest in
         group lst
+    | Add a :: Macro (Set (n, 0)) :: rest -> group (Macro (Set (n, 0)) :: rest)
+    | Macro (Set (_, i)) :: Macro (Set (n, j)) :: rest 
+      when i = j -> group (Macro (Set (n, j)) :: rest)
+    | Macro (Set (n, 0)) :: Add a :: rest -> group (Macro (Set (n+a, 0)) :: rest)
     | Loop a :: rest -> (Loop (group a)) :: (group rest)
     | other :: rest -> other :: (group rest)
     | [] -> []
     | Loop ops :: rest -> replace ops :: unroll rest
     | other :: rest -> other :: (unroll rest)
     | [] -> []
+    
+  (** some mult are copies, don't need to reset *)
+  let replace_moves_with_copy ast =
+    let rec loop = function
+      | Macro (AddMultToCell2(n1, i, j)) :: Move(k) :: Macro (AddMultToCell(n2, l)) :: rest
+        when n1 = n2 && j = k && j = - l -> Macro (CopyMultToCell (n1, i)) :: Move j :: loop rest
+      | Loop ops :: rest -> Loop (loop ops) :: loop rest
+      | other :: rest -> other :: loop rest
+      | [] -> []
+    in loop ast
   
   (** replace move, action and revert back to a distant action *)
   let in_place ast =
       | Loop ops :: rest -> Loop (loop ops) :: loop rest
       | other :: rest -> other :: loop rest
       | [] -> []
-    in loop ast
-  
-  (** some mult are copies, don't need to reset *)
-  let replace_moves_with_copy ast =
-    let rec loop = function
-      | Macro (AddMultToCell2(n1, i, j)) :: Move(k) :: Macro (AddMultToCell(n2, l)) :: rest
-        when n1 = n2 && j = k && j = - l -> Macro (CopyMultToCell (n1, i)) :: Move j :: loop rest
-      | Loop ops :: rest -> Loop (loop ops) :: loop rest
-      | other :: rest -> other :: loop rest
-      | [] -> []
-    in loop ast
-    
+    in loop ast    
+        
   let (>>) f1 f2 = fun x -> f2 (f1 x)
   
   let optimize =
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.