From 5d227bcd0055d02e1d49a3dcd27e80a756923d5b Mon Sep 17 00:00:00 2001 From: Malte Voos Date: Sun, 23 Jun 2024 23:31:59 +0200 Subject: split code into smaller libraries and make a better repl --- src/bin/dune | 11 +++++++++++ src/bin/main.ml | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/bin/dune create mode 100644 src/bin/main.ml (limited to 'src/bin') diff --git a/src/bin/dune b/src/bin/dune new file mode 100644 index 0000000..980d799 --- /dev/null +++ b/src/bin/dune @@ -0,0 +1,11 @@ +(executable + (public_name toytt) + (name main) + (libraries + asai + linenoise + toytt.elaborator + toytt.nbe + toytt.parser + toytt.reporter + )) diff --git a/src/bin/main.ml b/src/bin/main.ml new file mode 100644 index 0000000..f762d26 --- /dev/null +++ b/src/bin/main.ml @@ -0,0 +1,19 @@ +module Term = Asai.Tty.Make(Reporter.Message) + +let ep input = + let ast = Parser.parse_expr input in + let (tp, tm) = Elaborator.infer_toplevel ast in + let value = NbE.eval ~env:Emp tm in + Format.printf "%a : %a\n%!" + (Pretty.pp ~names:Emp) (NbE.quote ~size:0 value) + (Pretty.pp ~names:Emp) (NbE.quote ~size:0 tp) + +let rec repl () = + match LNoise.linenoise "toytt> " with + | Some input -> + Reporter.run ~emit:Term.display ~fatal:Term.display (fun () -> ep input); + let _ = LNoise.history_add input in + repl () + | None -> repl () + +let () = repl (); -- cgit 1.4.1