Skip to content

Commit dfc2d32

Browse files
committed
Endow VM processes with mailbox type
1 parent 57d3e3d commit dfc2d32

4 files changed

Lines changed: 52 additions & 26 deletions

File tree

_CoqProject

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ theories/TransitionSystem.v
77
theories/Queue.v
88
theories/Pid.v
99
theories/ListSelector.v
10+
theories/IOHandler.v
11+
theories/Handlers/Mailbox.v
1012
theories/VM.v
1113
theories/Handlers/Storage.v
12-
theories/Handlers/Mailbox.v

theories/Handlers/Mailbox.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Require Import
77
Queue
88
Multifunction
99
Pid
10-
VM.
10+
IOHandler.
1111

1212
From Hammer Require Import
1313
Tactics.

theories/IOHandler.v

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From Coq Require Import
2+
List
3+
ZArith
4+
SetoidClass.
5+
6+
From SLOT Require Import
7+
Setoids
8+
TransitionSystem
9+
Pid.
10+
11+
From Hammer Require Import
12+
Tactics.
13+
14+
Section IOHandler.
15+
Context {Request : Type} {Reply : Request -> Type}.
16+
17+
Definition MFunRet Ret State `{HRet : Setoid Ret} `{HState : Setoid State} :=
18+
@MFun State (Ret * State) HState (@pair_setoid _ _ HRet HState).
19+
20+
Class IOHandler := {
21+
h_state : Type;
22+
h_setoid : Setoid h_state;
23+
h_handler (pid : PID) (req : Request) : MFunRet (Reply req) h_state;
24+
}.
25+
End IOHandler.

theories/VM.v

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ From Coq Require Import
55
SetoidDec.
66
Import 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

1419
From Hammer Require Import
1520
Tactics.
@@ -19,25 +24,12 @@ From RecordUpdate Require Import
1924

2025
Open 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-
3527
Section 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

Comments
 (0)