Commits

Maxime Buquet committed 4eca856

Reset function removed, env now resets automatically in REPL

  • Participants
  • Parent commits 88e6c62

Comments (0)

Files changed (2)

 module Env = Zip.Make (struct type t = int let zero = 0 end)
 
 type t =
-    | Reset
     | Plus
     | Minus
     | Right
 let new_env () = Env.empty
 
 let rec eval env = function
-    | Reset :: tl ->
-            eval Env.empty tl
     | Plus :: tl ->
             let v = Env.pop env in
             let v = if v + 1 = 256 then 0 else v in
         | '<' :: tl -> (||) Left (sub tl)
         | '.' :: tl -> (||) Print (sub tl)
         | ',' :: tl -> (||) Read (sub tl)
-        | 'r' :: tl -> (||) Reset (sub tl)
         | '[' :: tl -> let loop, tl = (sub tl) in
                            (||) (Loop loop) (sub tl)
         | ']' :: tl -> ([], tl)
 
-let rec loop env =
-    let _env = ref env in
+let rec loop () =
     if (try
-            let () = print_string "bf> " in
+            let () = print_string "\nbf> " in
             let exp = read_line () in
-            let () = _env := Bf.eval env (Bf.parse (Bf.to_list exp)) in
-                true
+            let () = ignore (
+              Bf.eval (Bf.new_env ()) (Bf.parse (Bf.to_list exp))) in
+              true
         with _ -> false)
     then
-        loop !_env
+        loop ()
 
 let header () =
-    print_string "ml-brainfuck interpreter\n";
-    print_string "'r' to reset the environment\n"
+    print_string "ml-brainfuck interpreter"
 
 let main () =
     header ();
-    loop (Bf.new_env ())
+    loop ()
 
 let _ =
     main ()
-