-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
85 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
(executable | ||
(public_name stappl) | ||
(name main) | ||
(libraries project) | ||
(libraries core core_unix.command_unix core_unix.filename_unix stappl) | ||
(modes byte exe) | ||
(preprocess | ||
(pps ppx_jane)) | ||
(flags | ||
(:standard -g))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
open Project | ||
open Program | ||
open Core | ||
open Stappl | ||
|
||
let src = ref "" | ||
let opt_pp = ref false | ||
|
||
let lexbuf_contents lb = | ||
let print_position (outx : Out_channel.t) (lexbuf : Lexing.lexbuf) : unit = | ||
let open Lexing in | ||
let pos = lb.lex_curr_pos in | ||
let len = lb.lex_buffer_len - lb.lex_curr_pos in | ||
Bytes.to_string (Bytes.sub lb.lex_buffer pos len) | ||
let pos = lexbuf.lex_curr_p in | ||
fprintf outx "%s:%d:%d" pos.pos_fname pos.pos_lnum | ||
(pos.pos_cnum - pos.pos_bol + 1) | ||
|
||
let parse_with_error (lexbuf : Lexing.lexbuf) : Program.program = | ||
Parser.program Lexer.start lexbuf | ||
|
||
let get_program (filename : string) : Program.program = | ||
let filename, inx = | ||
if String.(filename = "-") then ("<stdin>", In_channel.stdin) | ||
else (filename, In_channel.create filename) | ||
in | ||
let lexbuf = Lexing.from_channel inx in | ||
lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename }; | ||
|
||
match parse_with_error lexbuf with | ||
| prog -> | ||
In_channel.close inx; | ||
prog | ||
| exception Parser.Error -> | ||
fprintf stderr "%a: syntax error\n" print_position lexbuf; | ||
In_channel.close inx; | ||
exit (-1) | ||
|
||
let command : Command.t = | ||
Command.basic ~summary:"The STAPPL Compiler" | ||
~readme:(fun () -> | ||
"STAPPL is a compiler for the STAtically typed Probabilistic Programming \ | ||
Language") | ||
(let%map_open.Command filename = | ||
anon (maybe_with_default "-" ("filename" %: Filename_unix.arg_type)) | ||
and pp = flag "-pp" no_arg ~doc:" Pretty print the program" in | ||
fun () -> | ||
if pp then get_program filename |> Program.pretty |> print_endline | ||
else | ||
get_program filename |> Compiler.compile |> fst |> Graph.pretty | ||
|> print_endline) | ||
|
||
let () = | ||
Arg.parse | ||
[ ("-pp", Arg.Unit (fun _ -> opt_pp := true), "print pgm") ] | ||
(fun x -> src := x) | ||
("Usage : " ^ Filename.basename Sys.argv.(0) ^ " [-option] [filename] "); | ||
if !opt_pp then | ||
let lexbuf = | ||
Lexing.from_channel (if !src = "" then stdin else open_in !src) | ||
in | ||
try | ||
let pgm = Parser.program Lexer.start lexbuf in | ||
print_endline "=== Printing Input Program ==="; | ||
pp pgm; | ||
let open Compiler in | ||
let env = gather_functions pgm in | ||
let graph, _de = compile env Pred.Empty pgm.exp in | ||
print_endline "=== Printing Output Program ==="; | ||
Printf.printf "%s" (Graph.pp graph) | ||
with Parsing.Parse_error -> | ||
print_endline ("Parsing Error: " ^ lexbuf_contents lexbuf) | ||
else print_endline "Please provide one of options! (-pp)" | ||
let () = Command_unix.run ~version:"0.1.0" ~build_info:"STAPPL" command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(library | ||
(name project) | ||
(name stappl) | ||
(libraries str core) | ||
(preprocess | ||
(pps ppx_jane))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters