-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathsimpleIOScript.sml
51 lines (43 loc) · 1.32 KB
/
simpleIOScript.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(*
A simple instantiation of the ffi type.
*)
open HolKernel Parse boolLib bossLib;
open miscTheory ffiTheory;
val _ = new_theory "simpleIO"
Datatype:
simpleIO = <| input : word8 llist; output : word8 llist |>
End
Definition isEof_def:
isEof st (conf :word8 list) input =
case input of
| [] => Oracle_final FFI_failed
| x::xs => Oracle_return st ((if st.input = [||] then 1w else 0w)::xs)
End
Definition getChar_def:
getChar st (conf :word8 list) input =
case input of
| [] => Oracle_final FFI_failed
| x::xs =>
case LHD st.input of
| NONE => Oracle_final FFI_failed
| SOME y =>
Oracle_return (st with input := THE (LTL st.input)) (y::xs)
End
Definition putChar_def:
putChar st (conf :word8 list) input =
case input of
| [] => Oracle_final FFI_failed
| x::v1 => Oracle_return (st with output := x:::st.output) input
End
Definition exit_def:
exit (st :simpleIO) (conf :word8 list) (input :word8 list) = Oracle_final FFI_diverged
End
Definition simpleIO_oracle_def:
simpleIO_oracle s st conf input =
if s = "isEof" then isEof st conf input
else if s = "getChar" then getChar st conf input
else if s = "putChar" then putChar st conf input
else if s = "exit" then exit st conf input
else Oracle_final FFI_failed
End
val _ = export_theory()