From f8107f9061cd9e1b13c0523e95168e288a6414d7 Mon Sep 17 00:00:00 2001 From: Luc Maranget Date: Tue, 23 Jun 2009 09:35:12 +0000 Subject: [PATCH] PR#0004828 fixed git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9305 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- bytecomp/matching.ml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bytecomp/matching.ml b/bytecomp/matching.ml index 0addf7e37..b20022d7b 100644 --- a/bytecomp/matching.ml +++ b/bytecomp/matching.ml @@ -2650,7 +2650,7 @@ let compile_flattened repr partial ctx _ pmh = match pmh with compile_orhandlers (compile_match repr partial) lam total ctx hs | PmVar _ -> assert false -let for_multiple_match loc paraml pat_act_list partial = +let do_for_multiple_match loc paraml pat_act_list partial = let repr = None in let partial = check_partial pat_act_list partial in let raise_num,pm1 = @@ -2704,3 +2704,28 @@ let for_multiple_match loc paraml pat_act_list partial = end with Unused -> assert false (* ; partial_function loc () *) + +(* #PR4828: Believe it or not, the 'paraml' argument below + may not be side effect free. *) + +let arg_to_var arg cls = match arg with +| Lvar v -> v,arg +| _ -> + let v = name_pattern "match" cls in + v,Lvar v + + +let rec param_to_var param = match param with +| Lvar v -> v,None +| _ -> Ident.create "match",Some param + +let bind_opt (v,eo) k = match eo with +| None -> k +| Some e -> Lambda.bind Strict v e k + +let for_multiple_match loc paraml pat_act_list partial = + let v_paraml = List.map param_to_var paraml in + let paraml = List.map (fun (v,_) -> Lvar v) v_paraml in + List.fold_right bind_opt v_paraml + (do_for_multiple_match loc paraml pat_act_list partial) +