Skip to content

Commit 60a35c1

Browse files
committed
Extraction for C.I.t added
1 parent 601ad88 commit 60a35c1

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/Extraction.v

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ Require System.
1313
Import ListNotations.
1414
Local Open Scope type.
1515

16+
(** Usefull values to define fixpoints. *)
17+
Module Loop.
18+
Parameter infinity : nat.
19+
Extract Constant infinity => "let rec inf = S inf in inf".
20+
21+
Parameter error : forall {A}, A.
22+
Extract Constant error => "failwith ""Unexpected end of infinite loop.""".
23+
End Loop.
24+
1625
(** Interface to the Big_int library. *)
1726
Module BigInt.
1827
(** The OCaml's `big_int` type. *)
@@ -147,7 +156,7 @@ Definition eval_command (c : Effect.command System.effect)
147156
end.
148157

149158
(** Evaluate an expression using Lwt. *)
150-
Fixpoint eval {A : Type} (x : C.t System.effect A) : Lwt.t A.
159+
Fixpoint eval {A} (x : C.t System.effect A) : Lwt.t A.
151160
destruct x as [A x | command | A B x f | A x1 x2 | A B x y].
152161
- exact (Lwt.ret x).
153162
- exact (eval_command command).
@@ -160,3 +169,27 @@ Defined.
160169
Definition launch (main : list LString.t -> C.t System.effect unit) : unit :=
161170
let argv := List.map String.to_lstring Sys.argv in
162171
Lwt.launch (eval (main argv)).
172+
173+
Module I.
174+
Fixpoint eval_aux {A} (steps : nat) (x : C.I.t System.effect A) : Lwt.t A :=
175+
match steps with
176+
| O => Loop.error
177+
| S steps =>
178+
match x with
179+
| C.I.Ret _ v => Lwt.ret v
180+
| C.I.Call c => eval_command c
181+
| C.I.Let _ _ x f =>
182+
Lwt.bind (eval_aux steps x) (fun v_x => eval_aux steps (f v_x))
183+
| C.I.Choose _ x1 x2 => Lwt.choose (eval_aux steps x1) (eval_aux steps x2)
184+
| C.I.Join _ _ x y => Lwt.join (eval_aux steps x) (eval_aux steps y)
185+
end
186+
end.
187+
188+
Definition eval {A} (x : C.I.t System.effect A) : Lwt.t A :=
189+
eval_aux Loop.infinity x.
190+
191+
Definition launch (main : list LString.t -> C.I.t System.effect unit)
192+
: unit :=
193+
let argv := List.map String.to_lstring Sys.argv in
194+
Lwt.launch (eval (main argv)).
195+
End I.

0 commit comments

Comments
 (0)