language.v 2.46 KB
Newer Older
1
From iris.algebra Require Export ofe.
Ralf Jung's avatar
Ralf Jung committed
2

3 4 5 6 7 8
Structure language := Language {
  expr : Type;
  val : Type;
  state : Type;
  of_val : val  expr;
  to_val : expr  option val;
9
  prim_step : expr  state  expr  state  list expr  Prop;
Robbert Krebbers's avatar
Robbert Krebbers committed
10 11
  to_of_val v : to_val (of_val v) = Some v;
  of_to_val e v : to_val e = Some v  of_val v = e;
12
  val_stuck e σ e' σ' efs : prim_step e σ e' σ' efs  to_val e = None
Ralf Jung's avatar
Ralf Jung committed
13
}.
Janno's avatar
Janno committed
14 15 16 17
Delimit Scope expr_scope with E.
Delimit Scope val_scope with V.
Bind Scope expr_scope with expr.
Bind Scope expr_scope with val.
18 19 20 21 22
Arguments of_val {_} _.
Arguments to_val {_} _.
Arguments prim_step {_} _ _ _ _ _.
Arguments to_of_val {_} _.
Arguments of_to_val {_} _ _ _.
23
Arguments val_stuck {_} _ _ _ _ _ _.
24

25 26 27
Canonical Structure stateC Λ := leibnizC (state Λ).
Canonical Structure valC Λ := leibnizC (val Λ).
Canonical Structure exprC Λ := leibnizC (expr Λ).
28 29

Definition cfg (Λ : language) := (list (expr Λ) * state Λ)%type.
Ralf Jung's avatar
Ralf Jung committed
30

31
Section language.
32 33
  Context {Λ : language}.
  Implicit Types v : val Λ.
Ralf Jung's avatar
Ralf Jung committed
34

35
  Definition reducible (e : expr Λ) (σ : state Λ) :=
36
     e' σ' efs, prim_step e σ e' σ' efs.
37
  Definition irreducible (e : expr Λ) (σ : state Λ) :=
Robbert Krebbers's avatar
Robbert Krebbers committed
38
    e' σ' efs, ¬prim_step e σ e' σ' efs. 
39
  Definition atomic (e : expr Λ) : Prop :=
40
     σ e' σ' efs, prim_step e σ e' σ' efs  irreducible e' σ'.
41
  Inductive step (ρ1 ρ2 : cfg Λ) : Prop :=
42
    | step_atomic e1 σ1 e2 σ2 efs t1 t2 :
43
       ρ1 = (t1 ++ e1 :: t2, σ1) 
44 45
       ρ2 = (t1 ++ e2 :: t2 ++ efs, σ2) 
       prim_step e1 σ1 e2 σ2 efs 
46 47
       step ρ1 ρ2.

Robbert Krebbers's avatar
Robbert Krebbers committed
48 49
  Lemma of_to_val_flip v e : of_val v = e  to_val e = Some v.
  Proof. intros <-. by rewrite to_of_val. Qed.
50
  Lemma reducible_not_val e σ : reducible e σ  to_val e = None.
51
  Proof. intros (?&?&?&?); eauto using val_stuck. Qed.
52 53
  Lemma val_irreducible e σ : is_Some (to_val e)  irreducible e σ.
  Proof. intros [??] ??? ?%val_stuck. by destruct (to_val e). Qed.
54
  Global Instance of_val_inj : Inj (=) (=) (@of_val Λ).
55
  Proof. by intros v v' Hv; apply (inj Some); rewrite -!to_of_val Hv. Qed.
56
End language.
Ralf Jung's avatar
Ralf Jung committed
57

58 59 60
Class LanguageCtx (Λ : language) (K : expr Λ  expr Λ) := {
  fill_not_val e :
    to_val e = None  to_val (K e) = None;
61 62 63 64 65 66
  fill_step e1 σ1 e2 σ2 efs :
    prim_step e1 σ1 e2 σ2 efs 
    prim_step (K e1) σ1 (K e2) σ2 efs;
  fill_step_inv e1' σ1 e2 σ2 efs :
    to_val e1' = None  prim_step (K e1') σ1 e2 σ2 efs 
     e2', e2 = K e2'  prim_step e1' σ1 e2' σ2 efs
67
}.