Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frontend [WIP] #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 *)
1 change: 1 addition & 0 deletions frontend/Frontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ include Code

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

module Driver = Driver
(** Toplevel driver for the proof assistant *)
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))