source: C-semantics/test/io2.c.ma @ 24

Last change on this file since 24 was 20, checked in by campbell, 10 years ago

Add resumption monad based version of the executable semantics with simple I/O.

File size: 1.8 KB
Line 
1include "CexecIO.ma".
2
3ndefinition myprog := mk_program fundef type
4  [
5  mk_pair ?? (succ_pos_of_nat 17) (External (succ_pos_of_nat 17) (Tcons (Tint I32 Signed  ) Tnil) (Tint I32 Signed  ));
6  mk_pair ?? (succ_pos_of_nat 20) (Internal (
7    mk_function (Tint I32 Signed  ) [] [mk_pair ?? (succ_pos_of_nat 18) (Tint I32 Signed  ); mk_pair ?? (succ_pos_of_nat 19) (Tint I32 Signed  )]
8      (Ssequence
9      (Sassign (Expr (Evar (succ_pos_of_nat 18)) (Tint I32 Signed  ))
10        (Expr (Econst_int (repr 2)) (Tint I32 Signed  )))
11      (Ssequence
12      (Ssequence
13      (Scall (Some ? (Expr (Evar (succ_pos_of_nat 19)) (Tint I32 Signed  )))
14        (Expr (Evar (succ_pos_of_nat 17)) (Tfunction (Tcons (Tint I32 Signed  ) Tnil) (Tint I32 Signed  )))
15        [(Expr (Econst_int (repr 10)) (Tint I32 Signed  ))])
16      (Sassign (Expr (Evar (succ_pos_of_nat 18)) (Tint I32 Signed  ))
17        (Expr (Ebinop Oadd
18          (Expr (Evar (succ_pos_of_nat 18)) (Tint I32 Signed  ))
19          (Expr (Evar (succ_pos_of_nat 19)) (Tint I32 Signed  ))) (Tint I32 Signed  ))))
20      (Sreturn (Some ? (Expr (Evar (succ_pos_of_nat 18)) (Tint I32 Signed  ))))))
21   
22   
23   
24  ))]
25  (succ_pos_of_nat 20)
26  []
27.
28
29(* ndefinition works fine for this, whereas nletin during proof seems to blow up. *)
30ndefinition s ≝ (
31 ! s0 ← make_initial_state myprog;:
32 ! 〈t,s〉 ← exec_steps 13 (globalenv Genv ?? myprog) s0;:
33   ret ? s).
34
35notation < "'MEM'" with precedence 1 for @{ 'mem }.
36interpretation "hide memory" 'mem = (mk_mem ???).
37
38(* The trick to being able to normalize the term is to avoid looking at the
39   continuations! *)
40nremark foo:
41    match match s with [ Interact f args k ⇒ k (EVint (repr 10))
42                 | Value v ⇒ Wrong ?
43                 | Wrong ⇒ Wrong ? ] with
44    [ Interact _ _ _ ⇒ False
45    | Value v ⇒ v = v
46    | Wrong ⇒ False
47    ].
48nnormalize; //; nqed.
Note: See TracBrowser for help on using the repository browser.