forked from forked-from-1kasper/bravo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.ml
42 lines (35 loc) · 1.11 KB
/
repl.ml
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
open Module
open Error
open Decl
open Elab
open Expr
let help =
"Available commands:
<statement> infer type and normalize statement
:q quit
:r restart
:h display this message"
let init : state = empty
let st : state ref = ref init
let checkAndEval ctx e : value * value =
(Check.infer ctx e, Check.eval e ctx)
let main ctx : command -> unit = function
| Eval e -> let (t, v) = checkAndEval ctx (freshExp e) in
Printf.printf "TYPE: %s\nEVAL: %s\n" (showValue t) (showValue v)
| Action "q" -> exit 0
| Action "r" -> st := init; raise Restart
| Action "h" -> print_endline help
| Command (s, _) | Action s -> raise (UnknownCommand s)
| Nope -> ()
let check filename =
st := handleErrors (checkFile !st) filename !st
let banner = "Castle Bravo theorem prover, version 0.2.0"
let repl () =
print_endline ("\n" ^ banner) ;
let (ctx, _) = !st in
try while true do
print_string "> ";
let line = read_line () in
handleErrors (fun x ->
let cmd = Reader.parseErr Parser.repl (Lexing.from_string x) in main ctx cmd) line ()
done with End_of_file -> ()