Skip to content
Snippets Groups Projects
Commit 60bc2c1e authored by Patrick Baudin's avatar Patrick Baudin
Browse files

[wp] adds some comments

parent 496ae212
No related branches found
No related tags found
No related merge requests found
...@@ -1057,7 +1057,14 @@ let block_length sigma obj l = ...@@ -1057,7 +1057,14 @@ let block_length sigma obj l =
(* --- Cast --- *) (* --- Cast --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
module Layout = module Layout : sig
val pretty : Format.formatter -> c_object -> unit
val fits: dst:c_object -> src:c_object -> bool
(* returns [true] in these cases:
- [dst] fits into [src]
- [dst] equals [src] *)
end =
struct struct
type atom = P of typ | I of c_int | F of c_float type atom = P of typ | I of c_int | F of c_float
...@@ -1144,10 +1151,10 @@ struct ...@@ -1144,10 +1151,10 @@ struct
let add_array ly n w = let add_array ly n w =
if n=1 then ly @ w else add_many ly n w if n=1 then ly @ w else add_many ly n w
let rec compare l1 l2 = let rec compare ~dst ~src =
match l1 , l2 with match dst , src with
| [] , [] -> Equal | [] , [] -> Equal (* src = dst *)
| [] , _ -> Fit | [] , _ -> Fit (* exists obj ; src = dst concat obj *)
| _ , [] -> Mismatch | _ , [] -> Mismatch
| p::w1 , q::w2 -> | p::w1 , q::w2 ->
match p , q with match p , q with
...@@ -1166,7 +1173,7 @@ struct ...@@ -1166,7 +1173,7 @@ struct
else Mismatch else Mismatch
| Arr(u,n) , Arr(v,m) -> | Arr(u,n) , Arr(v,m) ->
begin begin
match compare u v with match compare ~dst:u ~src:v with
| Mismatch -> Mismatch | Mismatch -> Mismatch
| Fit -> Mismatch | Fit -> Mismatch
| Equal -> | Equal ->
...@@ -1181,18 +1188,18 @@ struct ...@@ -1181,18 +1188,18 @@ struct
compare w1 w2 compare w1 w2
end end
| Arr(v,n) , Str _ -> | Arr(v,n) , Str _ ->
compare (v @ add_array v (n-1) w1) l2 compare ~dst:(v @ add_array v (n-1) w1) ~src
| Str _ , Arr(v,n) -> | Str _ , Arr(v,n) ->
compare l1 (v @ add_array v (n-1) w2) compare ~dst ~src:(v @ add_array v (n-1) w2)
let fits obj1 obj2 = let fits ~dst ~src =
match obj1 , obj2 with match dst , src with
| C_int i1 , C_int i2 -> i1 = i2 | C_int i1 , C_int i2 -> i1 = i2
| C_float f1 , C_float f2 -> f1 = f2 | C_float f1 , C_float f2 -> f1 = f2
| C_comp c , C_comp d when Compinfo.equal c d -> true | C_comp c , C_comp d when Compinfo.equal c d -> true
| C_pointer _ , C_pointer _ -> true | C_pointer _ , C_pointer _ -> true
| _ -> | _ ->
match compare (layout obj1) (layout obj2) with match compare ~dst:(layout dst) ~src:(layout src) with
| Equal | Fit -> true | Equal | Fit -> true
| Mismatch -> false | Mismatch -> false
...@@ -1223,10 +1230,10 @@ let cast s l = ...@@ -1223,10 +1230,10 @@ let cast s l =
match Context.get pointer with match Context.get pointer with
| NoCast -> Warning.error ~source:"Typed Model" "%a" pp_mismatch s | NoCast -> Warning.error ~source:"Typed Model" "%a" pp_mismatch s
| Fits -> | Fits ->
if Layout.fits s.post s.pre then l else if Layout.fits ~dst:s.post ~src:s.pre then l else
Warning.error ~source:"Typed Model" "%a" pp_mismatch s Warning.error ~source:"Typed Model" "%a" pp_mismatch s
| Unsafe -> | Unsafe ->
if not (Layout.fits s.post s.pre) then if not (Layout.fits ~dst:s.post ~src:s.pre) then
Warning.emit ~severe:false ~source:"Typed Model" Warning.emit ~severe:false ~source:"Typed Model"
~effect:"Keep pointer value" ~effect:"Keep pointer value"
"%a" pp_mismatch s ; l "%a" pp_mismatch s ; l
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment