@@ -5,11 +5,16 @@ From Coq Require Import
55 SetoidDec.
66Import ListNotations.
77
8- From SLOT Require Import
8+ From SLOT Require
99 Setoids
1010 TransitionSystem
1111 Pid
12- ListSelector.
12+ ListSelector
13+ IOHandler
14+ Mailbox.
15+
16+ Import Setoids TransitionSystem ListSelector Mailbox.
17+ Export Pid IOHandler.
1318
1419From Hammer Require Import
1520 Tactics.
@@ -19,25 +24,12 @@ From RecordUpdate Require Import
1924
2025Open Scope positive_scope.
2126
22- Section IOHandler.
23- Context {Request : Type} {Reply : Request -> Type}.
24-
25- Definition MFunRet Ret State `{HRet : Setoid Ret} `{HState : Setoid State} :=
26- @MFun State (Ret * State) HState (@pair_setoid _ _ HRet HState).
27-
28- Class IOHandler := {
29- h_state : Type ;
30- h_setoid : Setoid h_state;
31- h_handler (pid : PID) (req : Request) : MFunRet (Reply req) h_state;
32- }.
33- End IOHandler.
34-
3527Section VM.
3628 Context `{IOH : IOHandler} {AppMessage : Type}.
3729
3830 Let World := @h_state _ _ IOH.
3931
40- CoInductive Program : Type :=
32+ CoInductive Program {Mailbox : Set } : Type :=
4133 | p_dead : (* Program terminted *)
4234 Program
4335 | p_yield :
@@ -59,18 +51,24 @@ Section VM.
5951 (continuation : Reply pending_req -> Program),
6052 Program
6153 | p_spawn : (* Spawn a new process: *)
62- forall (child : Program )
63- (continuation : PID -> Program),
54+ forall {Mailbox : Set }
55+ (child : @Program Mailbox)
56+ (continuation : @Address Mailbox -> Program),
6457 Program .
6558
59+ Record Process :=
60+ { proc_mb_t : Set ;
61+ proc_prog : @Program proc_mb_t;
62+ }.
63+
6664 Record VM :=
6765 mkVM
6866 { (* State of the I/O handler *)
6967 world : World;
7068 (* Set of runnable processes *)
71- runq : list (PID * Program );
69+ runq : list (PID * Process );
7270 (* Set of sleeping processes *)
73- sleepq : list (PID * Program );
71+ sleepq : list (PID * Process );
7472 (* Counter that gets incremented when process spawns a child.
7573 This counter is used as a suffix of the child's pid *)
7674 child_ctr : Pid.FMap.t positive;
@@ -83,7 +81,7 @@ Section VM.
8381 let (w1, rq1, sq1, cc1) := a in
8482 let (w2, rq2, sq2, cc2) := b in
8583 let w_eq := @equiv _ h_setoid in
86- let p_eq := @equiv _ (setoid_permutation (PID * Program ) ) in
84+ let p_eq := @equiv _ (setoid_permutation _ ) in
8785 w_eq w1 w2 /\
8886 p_eq rq1 rq2 /\
8987 p_eq sq1 sq2 /\
@@ -105,12 +103,14 @@ Section VM.
105103 end in
106104 (v<| child_ctr := cc |>, ctr).
107105
108- Definition do_spawn (parent : PID) (prog : Program ) (v : VM) : VM :=
106+ Definition do_spawn {Mailbox : Set } (parent : PID) (prog : @ Program Mailbox ) (v : VM) : VM :=
109107 let (v, child_pid_suffix) := new_child_id parent v in
110108 let rq := runq v in
111- v<| runq := (parent ++ [child_pid_suffix], prog) :: rq |>.
109+ let new_pid := parent ++ [child_pid_suffix] in
110+ let new_process := {| proc_mb_t := Mailbox; proc_prog := prog |} in
111+ v<| runq := (new_pid, new_process) :: rq |>.
112112
113- Definition initVm (w : World) (p : Program ) :=
113+ Definition initVm {Mailbox : Set } (w : World) (p : @ Program Mailbox ) :=
114114 let vm :=
115115 {|
116116 world := w;
0 commit comments