Skip to content

Commit cc870cc

Browse files
committed
Lahenda domain praktikumis
1 parent 7007826 commit cc870cc

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/abseval/abseval.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ struct
6868
ED.bot
6969
else
7070
failwith "eval_stmt: Error"
71-
| _ -> failwith "TODO"
71+
| While (c, b) ->
72+
let f env' =
73+
eval_stmt (eval_guard env' c true) b
74+
in
75+
let env_loop = EDFP.closure f env in
76+
eval_guard env_loop c false
7277
end

src/domain/intDomain.ml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,26 @@ struct
4444
include Domain.Flat (struct type t = int [@@deriving eq, ord, show] end)
4545
let of_int i = Lift i
4646
let of_interval ((l, u): int * int): t =
47-
failwith "TODO"
47+
if l = u then
48+
Lift l
49+
else
50+
Top
4851

4952
(** Vihje: Eval.Concrete.eval_binary. *)
5053
let eval_binary (i1: t) (b: Ast.binary) (i2: t): t =
51-
failwith "TODO"
54+
match i1, i2 with
55+
| Bot, _
56+
| _, Bot -> Bot
57+
| Lift i1, Lift i2 -> Lift (Eval.Concrete.eval_binary i1 b i2)
58+
| Top, _
59+
| _, Top -> Top
5260

5361
let exclude (i: int) (i': t): t =
54-
failwith "TODO"
62+
match i' with
63+
| Lift i' when i = i' -> Bot
64+
| Lift _ -> i'
65+
| Top -> Top
66+
| Bot -> Bot
5567
end
5668

5769
(** Intervallide domeen. *)
@@ -65,14 +77,16 @@ struct
6577
let show = Format.asprintf "%a" pp
6678

6779
let leq ((l1, u1): t) ((l2, u2): t): bool =
68-
failwith "TODO"
80+
l2 <= l1 && u1 <= u2
6981

7082
let join ((l1, u1): t) ((l2, u2): t): t =
71-
failwith "TODO"
83+
(min l1 l2, max u1 u2)
7284

7385
let eval_binary ((l1, u1): t) (b: Ast.binary) ((l2, u2): t): t =
7486
match b with
75-
87+
| Add -> (l1 + l2, u1 + u2)
88+
| Lt when u1 < l2 -> (1, 1)
89+
| Lt when u2 <= l1 -> (0, 0)
7690
| Eq | Ne | Lt | Le | Gt | Ge -> (0, 1) (* Võrdluse tulemus on 0 või 1, mis on korrektne, aga mitte täpne. Ettepoole saab implementeerida täpsemad juhud kui vaja. *)
7791

7892
| _ -> failwith "TODO" (* Ei pea implementeerima kõiki operaatoreid, vaid ainult testideks vajalikud. *)

0 commit comments

Comments
 (0)