language.v 2.09 KB
Newer Older
1
From iris.algebra Require Export cofe.
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
}.
14 15 16 17 18
Arguments of_val {_} _.
Arguments to_val {_} _.
Arguments prim_step {_} _ _ _ _ _.
Arguments to_of_val {_} _.
Arguments of_to_val {_} _ _ _.
19
Arguments val_stuck {_} _ _ _ _ _ _.
20

21 22 23
Canonical Structure stateC Λ := leibnizC (state Λ).
Canonical Structure valC Λ := leibnizC (val Λ).
Canonical Structure exprC Λ := leibnizC (expr Λ).
24 25

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

27
Section language.
28 29
  Context {Λ : language}.
  Implicit Types v : val Λ.
Ralf Jung's avatar
Ralf Jung committed
30

31
  Definition reducible (e : expr Λ) (σ : state Λ) :=
32
     e' σ' efs, prim_step e σ e' σ' efs.
33
  Definition atomic (e : expr Λ) : Prop :=
34
     σ e' σ' efs, prim_step e σ e' σ' efs  is_Some (to_val e').
35
  Inductive step (ρ1 ρ2 : cfg Λ) : Prop :=
36
    | step_atomic e1 σ1 e2 σ2 efs t1 t2 :
37
       ρ1 = (t1 ++ e1 :: t2, σ1) 
38 39
       ρ2 = (t1 ++ e2 :: t2 ++ efs, σ2) 
       prim_step e1 σ1 e2 σ2 efs 
40 41
       step ρ1 ρ2.

Robbert Krebbers's avatar
Robbert Krebbers committed
42 43
  Lemma of_to_val_flip v e : of_val v = e  to_val e = Some v.
  Proof. intros <-. by rewrite to_of_val. Qed.
44
  Lemma reducible_not_val e σ : reducible e σ  to_val e = None.
45
  Proof. intros (?&?&?&?); eauto using val_stuck. Qed.
46
  Global Instance of_val_inj : Inj (=) (=) (@of_val Λ).
47
  Proof. by intros v v' Hv; apply (inj Some); rewrite -!to_of_val Hv. Qed.
48
End language.
Ralf Jung's avatar
Ralf Jung committed
49

50 51 52
Class LanguageCtx (Λ : language) (K : expr Λ  expr Λ) := {
  fill_not_val e :
    to_val e = None  to_val (K e) = None;
53 54 55 56 57 58
  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
59
}.