Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cparser/Ceval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ let unop env op tyres ty v =
| Olognot, _, _ -> if boolean_value v then I 0L else I 1L
| Onot, _, I n -> I (Int64.lognot n)
| _ -> raise Notconst
in cast env ty res
in cast env tyres res

let comparison env direction ptraction tyop v1 v2 =
(* tyop = type at which the comparison is done *)
(* tyop = type at which the comparison is done.
v1, v2 have been converted to tyop already. *)
let b =
match cast env tyop v1, cast env tyop v2 with
match v1, v2 with
| I n1, I n2 ->
if is_signed env tyop
then direction (compare n1 n2) 0
Expand All @@ -140,29 +141,31 @@ let comparison env direction ptraction tyop v1 v2 =
let binop env op tyop tyres ty1 v1 ty2 v2 =
(* tyop = type at which the computation is done
tyres = expected result type *)
let v1 = cast env tyop v1
and v2 = cast env tyop v2 in
let res =
match op with
| Oadd ->
if is_arith_type env ty1 && is_arith_type env ty2 then begin
match cast env tyop v1, cast env tyop v2 with
match v1, v2 with
| I n1, I n2 -> I (Int64.add n1 n2)
| _, _ -> raise Notconst
end else
raise Notconst
| Osub ->
if is_arith_type env ty1 && is_arith_type env ty2 then begin
match cast env tyop v1, cast env tyop v2 with
match v1, v2 with
| I n1, I n2 -> I (Int64.sub n1 n2)
| _, _ -> raise Notconst
end else
raise Notconst
| Omul ->
begin match cast env tyop v1, cast env tyop v2 with
begin match v1, v2 with
| I n1, I n2 -> I (Int64.mul n1 n2)
| _, _ -> raise Notconst
end
| Odiv ->
begin match cast env tyop v1, cast env tyop v2 with
begin match v1, v2 with
| I n1, I n2 ->
if n2 = 0L then raise Notconst else
if is_signed env tyop then I (Int64.div n1 n2)
Expand Down
2 changes: 1 addition & 1 deletion test