module Term = Asai.Tty.Make(Error.Message) let display = Term.display ~show_backtrace:false let handle_error f = Error.run ~emit:display ~fatal:display f let handle_fatal f = Error.run ~emit:display ~fatal:(fun msg -> display msg; exit 1) f let ep ~toplvl input = let ast = Parser.parse_expr input in let toplvl = Option.value toplvl ~default:Yuujinchou.Trie.empty in let (tp, tm) = Elaborator.infer_toplevel ~toplvl ast in let value = NbE.eval_toplevel tm in Format.printf "%a : %a\n%!" (Pretty.pp ~names:Emp) (NbE.quote_toplevel @@ NbE.force_all value) (Pretty.pp ~names:Emp) (NbE.quote_toplevel @@ NbE.force_all tp) let rec repl ~toplvl () = match LNoise.linenoise "toytt> " with | Some input -> handle_error (fun () -> ep ~toplvl input); let _ = LNoise.history_add input in repl ~toplvl () | None -> repl ~toplvl () let input_file = ref None let () = let anon_fun path = input_file := Some path in let usage_msg = "usage: toytt [input file]" in let () = Arg.parse [] anon_fun usage_msg in match !input_file with | None -> repl ~toplvl:None () | Some path -> let toplvl = handle_fatal (fun () -> Driver.process_file path) in repl ~toplvl:(Some toplvl) ()