Skip to content

Commit

Permalink
Know your signatures (#300)
Browse files Browse the repository at this point in the history
* Some minor improvement.

* Relative import. Related to #117.

* Close #171 with an ugly solution.
  • Loading branch information
favonia authored Sep 7, 2018
1 parent 6cf9d6a commit 2d0ce33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/frontend/Frontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ let read_from_channel file_name channel =
let (lexbuf, tokens) = Lex.tokens ~file_name channel in
let checkpoint = Grammar.Incremental.esig @@ Lexing.lexeme_start_p lexbuf in
begin
Lwt.catch (Parse.loop lexbuf tokens @@ checkpoint) @@ fun exn ->
Lwt.catch (Parse.loop lexbuf tokens checkpoint) @@ fun exn ->
Lwt_io.printlf " raised: %s" @@ Printexc.to_string exn >>= fun _ ->
Lwt_io.printlf "parser :: cleaning up…" >>= fun _ ->
Lwt_io.close channel >>= fun _ ->
Lwt.return []
Lwt.fail exn
end

let read_file file_name =
let open Lwt.Infix in
Lwt_io.open_file ~mode:Lwt_io.Input file_name >>=
read_from_channel file_name

let execute_signature esig =
let execute_signature dirname esig =
let module I =
struct
let cache = Hashtbl.create 20
let import f =
let f = Filename.concat dirname f in
match Hashtbl.find_opt cache f with
| None ->
let esig = Lwt_main.run @@ read_file @@ f ^ ".red" in
Expand All @@ -52,9 +53,11 @@ let execute_signature esig =

let load_file file_name =
let open Lwt.Infix in
read_file file_name >>= execute_signature
let dirname = Filename.dirname file_name in
read_file file_name >>= execute_signature dirname

let load_from_stdin file_name =
let open Lwt.Infix in
let dirname = Filename.dirname file_name in
read_from_channel file_name Lwt_io.stdin
>>= execute_signature
>>= execute_signature dirname
4 changes: 2 additions & 2 deletions src/frontend/Parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ let loop lexbuf tokens =
| I.HandlingError env ->
begin match I.top env with
| None ->
Lwt.return []
Lwt.fail_with "[parser] parsing failed"
| Some element ->
Lwt.bind (Message.render @@ Element.handle lexbuf element) @@ fun _ ->
Lwt.return []
Lwt.fail_with "[parser] parsing failed"
end

| I.InputNeeded _env ->
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/ResEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let rec get x renv =
| Snoc (ys, Some y) ->
if x = y
then acc
else go ys (acc + 1)
else (go[@tailcall]) ys (acc + 1)
| Snoc (ys, None) ->
(go[@tailcall]) ys (acc + 1)
in
Expand Down

0 comments on commit 2d0ce33

Please sign in to comment.