Commits

camlspotter committed 7b3d1a9

using assq list

Comments (0)

Files changed (2)

 
 OCAMLFLAGS    += -annot -w Ae
 OCAMLCFLAGS   +=
-OCAMLOPTFLAGS +=
+OCAMLOPTFLAGS += -p
 OCAML_LINK_FLAGS +=
 OCAML_BYTE_LINK_FLAGS +=
 OCAML_NATIVE_LINK_FLAGS +=
 
   let last_position st : Position.Region.t option = Base.last_position_of_attr (attr st)
 
-  let memoize : string -> (unit -> Str.t -> 'a) -> Str.t -> 'a = fun _ -> assert false
+  let memoize : string -> (Str.t -> 'a) -> Str.t -> 'a = fun k f str ->
+    let memo = Base.memo_of_attr (attr str) in
+    let res = 
+      try
+        List.assq k !memo
+      with
+      | Not_found ->
+          let res = try `Done (Obj.repr (f str)) with exn -> `Exn exn in
+          memo := (k, res) :: !memo;
+          res
+    in
+    match res with
+    | `Done o -> (Obj.magic o : 'a)
+    | `Exn exn -> raise exn
 end
 
 module Parser = struct