2222 * along with this program; if not, write to the Free Software
2323 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
25-
26- let merge
27- (n : int )
28- (x : Lam_arity.t ) : Lam_arity.t =
29- match x with
30- | NA -> Determin (false , [n], false )
31- | Determin (b ,xs ,tail ) -> Determin (b, n :: xs, tail)
32-
3325
3426let arity_of_var (meta : Lam_stats.t ) (v : Ident.t ) =
3527 (* * for functional parameter, if it is a high order function,
@@ -42,7 +34,7 @@ let arity_of_var (meta : Lam_stats.t) (v : Ident.t) =
4234 | None ->
4335 (* Format.fprintf Format.err_formatter *)
4436 (* "@[%s %a is not function/functor@]@." meta.filename Ident.print v ; *)
45- ( NA : Lam_arity.t )
37+ Arity_na
4638
4739 end
4840
@@ -56,7 +48,7 @@ let rec get_arity
5648 (lam : Lam.t ) :
5749 Lam_arity. t =
5850 match lam with
59- | Lconst _ -> Determin (true ,[] , false )
51+ | Lconst _ -> Arity_info (true ,[] , false )
6052 | Lvar v -> arity_of_var meta v
6153 | Llet (_ ,_ ,_ , l ) -> get_arity meta l
6254
@@ -70,22 +62,22 @@ let rec get_arity
7062 args = [ Lglobal_module id ]; _} ->
7163 begin match (Lam_compile_env. cached_find_ml_id_pos id n meta.env).arity with
7264 | Single x -> x
73- | Submodule _ -> NA
65+ | Submodule _ -> Arity_na
7466 end
7567 | Lprim {primitive = Pfield (m,_);
7668 args = [ Lprim {primitive = Pfield (n,_);
7769 args = [ Lglobal_module id]} ]
7870 ; _} ->
7971 begin match (Lam_compile_env. cached_find_ml_id_pos id n meta.env).arity with
8072 | Submodule subs -> subs.(m)
81- | Single _ -> NA
73+ | Single _ -> Arity_na
8274 end
8375
84- | Lprim {primitive = Pfield _ ; _} -> NA (* * TODO *)
85- | Lprim {primitive = Praise ; _} -> Determin (true ,[] , true )
86- | Lprim {primitive = Pccall _ ; _} -> Determin (false , [] , false )
76+ | Lprim {primitive = Pfield _ ; _} -> Arity_na (* * TODO *)
77+ | Lprim {primitive = Praise ; _} -> Arity_info (true ,[] , true )
78+ | Lprim {primitive = Pccall _ ; _} -> Arity_info (false , [] , false )
8779 | Lglobal_module _ (* TODO: fix me never going to happen assert false *)
88- | Lprim _ -> Determin (true ,[] ,false )
80+ | Lprim _ -> Arity_info (true ,[] ,false )
8981 (* shall we handle primitive in a direct way,
9082 since we know all the information
9183 Invariant: all primitive application is fully applied,
@@ -106,22 +98,22 @@ let rec get_arity
10698 | Lapply {fn = app ; args; _ } -> (* detect functor application *)
10799 let fn = get_arity meta app in
108100 begin match fn with
109- | NA -> NA
110- | Determin (b , xs , tail ) ->
101+ | Arity_na -> Arity_na
102+ | Arity_info (b , xs , tail ) ->
111103 let rec take (xs : _ list ) arg_length =
112104 match xs with
113105 | (x ) :: xs ->
114- if arg_length = x then Lam_arity. Determin (b, xs, tail)
106+ if arg_length = x then Lam_arity. Arity_info (b, xs, tail)
115107 else if arg_length > x then
116108 take xs (arg_length - x)
117- else Determin (b,
109+ else Arity_info (b,
118110 (x - arg_length ) :: xs ,
119111 tail)
120112 | [] ->
121- if tail then Determin (b, [] , tail)
113+ if tail then Arity_info (b, [] , tail)
122114 else if not b then
123- NA
124- else NA
115+ Arity_na
116+ else Arity_na
125117 (* Actually, you can not have truly deministic arities
126118 for example [fun x -> x ]
127119 *)
@@ -132,7 +124,7 @@ let rec get_arity
132124 take xs (List. length args)
133125 end
134126 | Lfunction {arity; function_kind; params; body = l } ->
135- merge arity (get_arity meta l)
127+ Lam_arity. merge arity (get_arity meta l)
136128 | Lswitch (l, {sw_failaction;
137129 sw_consts;
138130 sw_blocks;
@@ -149,31 +141,31 @@ let rec get_arity
149141 | None -> all_lambdas meta (Ext_list. map snd sw )
150142 | Some v -> all_lambdas meta (v:: Ext_list. map snd sw)
151143 end
152- | Lstaticraise _ -> NA (* since it will not be in tail position *)
144+ | Lstaticraise _ -> Arity_na (* since it will not be in tail position *)
153145 | Lstaticcatch (_ , _ , handler ) -> get_arity meta handler
154146 | Ltrywith (l1 , _ , l2 ) ->
155147 all_lambdas meta [l1;l2]
156148 | Lifthenelse (l1 , l2 , l3 ) ->
157149 all_lambdas meta [l2;l3]
158150 | Lsequence (_ , l2 ) -> get_arity meta l2
159- | Lsend (u , m , o , ll , v ) -> NA
160- | Lifused (v , l ) -> NA
151+ | Lsend (u , m , o , ll , v ) -> Arity_na
152+ | Lifused (v , l ) -> Arity_na
161153 | Lwhile _
162154 | Lfor _
163- | Lassign _ -> Determin (true ,[] , false )
155+ | Lassign _ -> Arity_info (true ,[] , false )
164156
165157and all_lambdas meta (xs : Lam.t list ) =
166158 match xs with
167159 | y :: ys ->
168160 let arity = get_arity meta y in
169161 List. fold_left (fun exist (v : Lam.t ) ->
170162 match (exist : Lam_arity.t ) with
171- | NA -> NA
172- | Determin (b , xs , tail ) ->
163+ | Arity_na -> Arity_na
164+ | Arity_info (b , xs , tail ) ->
173165 begin
174166 match get_arity meta v with
175- | NA -> NA
176- | Determin (u ,ys ,tail2 ) ->
167+ | Arity_na -> Arity_na
168+ | Arity_info (u ,ys ,tail2 ) ->
177169 let rec aux (b ,acc ) xs ys =
178170 match xs,ys with
179171 | [] , [] -> (b, List. rev acc, tail && tail2)
@@ -184,7 +176,7 @@ and all_lambdas meta (xs : Lam.t list) =
184176 | x ::xs , y ::ys when x = y -> aux (b, (y :: acc)) xs ys
185177 | _ , _ -> (false , List. rev acc, false ) in
186178 let (b,acc, tail3) = aux ( u && b, [] ) xs ys in
187- Determin (b,acc, tail3)
179+ Arity_info (b,acc, tail3)
188180 end
189181 ) arity ys
190182 | _ -> assert false
0 commit comments