-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathsimpleIO.lem
50 lines (44 loc) · 1.27 KB
/
simpleIO.lem
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
(*
A simple instantiation of the ffi type.
*)
open import Pervasives
open import Pervasives_extra
open import Lib
open import Ffi
type simpleIO = <| input : llist word8; output : llist word8 |>
val isEof : oracle_function simpleIO
let isEof st conf input =
match input with
| [] -> Oracle_final FFI_failed
| x::xs -> Oracle_return st ((if st.input = lnil then 1 else 0)::xs)
end
val getChar : oracle_function simpleIO
let getChar st conf input =
match input with
| [] -> Oracle_final FFI_failed
| x::xs ->
match lhd st.input with
| Just y -> Oracle_return (<| st with input = fromJust (ltl st.input) |>) (y::xs)
| _ -> Oracle_final FFI_failed
end
end
val putChar : oracle_function simpleIO
let putChar st conf input =
match input with
| [] -> Oracle_final FFI_failed
| x::_ -> Oracle_return (<| st with output = lcons x st.output |>) input
end
val exit : oracle_function simpleIO
let exit st conf input = Oracle_final FFI_diverged
val simpleIO_oracle : oracle simpleIO
let 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