(*to enable reuse of the lemmas eval_unop_valid and eval_binop_valid*)
(*Obtained from Cminor.state by deleting the memory components.*)
Inductive CSharpMin_core: Type :=
| CSharpMin_State:                      (**r Execution within a function *)
forall (f: function)              (**r currently executing function  *)
(s: stmt)                  (**r statement under consideration *)
(k: cont)                  (**r its continuation -- what to do next *)
(e: Csharpminor.env)                   (**r current local environment *)
(le: Csharpminor.temp_env),             (**r current temporary environment *)
CSharpMin_core
| CSharpMin_Callstate:                  (**r Invocation of a function *)
forall (f: fundef)                (**r function to invoke *)
(args: list val)           (**r arguments provided by caller *)
(k: cont),                  (**r what to do next  *)
CSharpMin_core
| CSharpMin_Returnstate:                (**r Return from a function *)
forall (v: val)                   (**r Return value *)
(k: cont),                  (**r what to do next *)
CSharpMin_core.
Definition ToState (q:CSharpMin_core) (m:mem): Csharpminor.state :=
match q with
CSharpMin_State f s k sp e => State f s k sp e m
| CSharpMin_Callstate f args k => Callstate f args k m
| CSharpMin_Returnstate v k => Returnstate v k m
end.
Definition FromState (c: Csharpminor.state) : CSharpMin_core * mem :=
match c with
State f s k sp e m => (CSharpMin_State f s k sp e, m)
| Callstate f args k m => (CSharpMin_Callstate f args k, m)
| Returnstate v k m => (CSharpMin_Returnstate v k, m)
end.
Definition CSharpMin_at_external (c: CSharpMin_core) : option (external_function * signature * list val) :=
match c with
| CSharpMin_State _ _ _ _ _ => None
| CSharpMin_Callstate fd args k => match fd with
Internal f => None
| External ef => Some (ef, ef_sig ef, args)
end
| CSharpMin_Returnstate v k => None
end.
Definition CSharpMin_after_external (vret: option val) (c: CSharpMin_core) : option CSharpMin_core :=
match c with
CSharpMin_Callstate fd args k =>
match fd with
Internal f => None
| External ef => match vret with
None => Some (CSharpMin_Returnstate Vundef k)
| Some v => Some (CSharpMin_Returnstate v k)
end
end
| _ => None
end.
Definition CSharpMin_corestep (ge : genv)  (q : CSharpMin_core) (m : mem) (q' : CSharpMin_core) (m' : mem) : Prop.
destruct q; destruct q'.
(*State - State*)
apply (exists t, step ge (State f s k e le m)  t (State f0 s0 k0 e0 le0 m')).
(*State - Callstate: one case: step_call*)
apply (exists t, step ge (State f s k e le m)  t (Callstate f0 args k0 m')).
(*State - Returnstate - three cases: step_skip_call, step_return_0, step_return_1*)
apply (exists t, step ge (State f s k e le m)  t (Returnstate v k0 m')).
(*Callstate - State: only case: step_internal_function*)
apply (exists t, step ge (Callstate f args k m) t (State f0 s k0 e le m')).
(*Callstate - Callstate: no case*)
apply False.
(*Callstate - Returnstate: one case: step_external_function : we don't want this as a step in this semantics, since stepping should not happen at_external*)
apply False.
(*Returnstate - State: one case: step_return*)
apply (exists t, step ge (Returnstate v k m) t (State f s k0 e le m')).
(*Returnstate - Callstate: no case*)
apply False.
(*Returnstate - Returnstate: no case*)
apply False.
Defined.

Lemma CSharpMin_corestep_not_at_external:
forall ge m q m' q', CSharpMin_corestep ge q m q' m' -> CSharpMin_at_external q = None.