Skip to content

Commit

Permalink
ref jonsterling#6: A dummy driver
Browse files Browse the repository at this point in the history
  • Loading branch information
anqurvanillapy committed Mar 27, 2021
1 parent 012c678 commit 47398dd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names main)
(libraries dreamtt.core))
(libraries dreamtt.frontend cmdliner))

(install
(section bin)
Expand Down
43 changes: 41 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
let () =
print_endline "Hello, world"
open Frontend
open Cmdliner

type options = { mode : [ `Stdin | `File of string ] }

let main { mode } =
match Driver.process_file mode with
| Ok () -> `Ok ()
| Error () -> `Error (false, "encountered one or more errors")

let proginfo =
let doc =
"A pedagogic abstract bidirectional elaborator for dependent type theory."
in
let err_exit = Term.exit_info ~doc:"on ill-formed types or terms." 1 in
Term.info "dreamtt" ~version:"0.0" ~doc
~exits:(err_exit :: Term.default_exits)

let opt_input_file =
let doc = "The file to typecheck. When $(docv) is -, read stdin." in
let parse_dash =
Term.(
app @@ const @@ Option.map
@@ fun str -> if str = "-" then `Stdin else `File str)
in
Arg.(
parse_dash & value
& pos ~rev:true 0 (some string) None
& info [] ~doc ~docv:"FILE")

let consolidate_options input_file : options Term.ret =
match input_file with
| Some input_file -> `Ok { mode = input_file }
| None -> `Error (true, "scripting mode expects an input file")

let () =
let options : options Term.t =
Term.(ret (const consolidate_options $ opt_input_file))
in
let t = Term.ret @@ Term.(const main $ options) in
Term.exit @@ Term.eval ~catch:true ~err:Format.std_formatter (t, proginfo)
8 changes: 8 additions & 0 deletions frontend/Driver.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let process_file input =
match input with
| `Stdin ->
print_endline "stdin";
Ok ()
| `File f ->
print_endline f;
Ok ()
2 changes: 2 additions & 0 deletions frontend/Driver.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val process_file : [ `Stdin | `File of string ] -> (unit, unit) result
(** Process a file from stdin or filename *)
2 changes: 2 additions & 0 deletions frontend/Frontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ struct
and+ code1 = distill_ltm tm1 in
R (Pair (code0, code1))
end

module Driver = Driver
3 changes: 3 additions & 0 deletions frontend/Frontend.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ module Distiller : sig
val run : string Env.t -> 'a m -> 'a Error.M.m
val distill_ltm : Syntax.ltm -> code m
end

module Driver = Driver
(** Toplevel driver for dreamtt *)
2 changes: 0 additions & 2 deletions frontend/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
(flags
(:standard -w -37))
(public_name dreamtt.frontend))


0 comments on commit 47398dd

Please sign in to comment.