Skip to content

Commit

Permalink
Implement primitive typechecker (#11)
Browse files Browse the repository at this point in the history
* ✨ Simplify types

* ✨ Implemented full pipeline

* 💚 Fix sample type errors

---------

Co-authored-by: Joonhyup Lee <[email protected]>
  • Loading branch information
LimitEpsilon and LimitEpsilon authored Jun 7, 2024
1 parent 20bbbeb commit 19d2cf8
Show file tree
Hide file tree
Showing 10 changed files with 907 additions and 12 deletions.
9 changes: 5 additions & 4 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let command : Command.t =
and pp_opt = flag "-pp" no_arg ~doc:" Pretty print the program"
and graph_opt = flag "-graph" no_arg ~doc:" Print the compiled graph" in
fun () ->
let open Typedprog in
if pp_opt then (
printf "Pretty-print: %s\n" filename;
print_s [%sexp (get_program filename : Program.program)]);
Expand All @@ -46,16 +47,16 @@ let command : Command.t =
if pp_opt then printf "\n";
printf "Compile: %s\n" filename;
Out_channel.flush stdout;
let graph, query = get_program filename |> Compiler.compile in
let graph, query = get_program filename |> Compiler.compile_program in
graph_query := Some (graph, query);
print_s [%sexp (graph : Graph.t)]);

print_s [%sexp (Printing.of_graph graph : Printing.graph)]);
if pp_opt || graph_opt then printf "\n";
printf "Inference: %s\n" filename;
Out_channel.flush stdout;
let graph, query =
!graph_query
|> Option.value ~default:(get_program filename |> Compiler.compile)
|> Option.value
~default:(get_program filename |> Compiler.compile_program)
in
printf "Query result saved at %s\n"
(Evaluator.infer ~filename graph query))
Expand Down
2 changes: 2 additions & 0 deletions lib/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let keywords =
("in", IN);
("sample", SAMPLE);
("observe", OBSERVE);
("true", BOOL true);
("false", BOOL false);
]
}

Expand Down
2 changes: 2 additions & 0 deletions lib/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open Program

%token <int> INT
%token <float> REAL
%token <bool> BOOL
%token <string> ID
%token IF THEN ELSE FUN LET IN
%token PLUS MINUS NEG MULT DIV RPLUS RMINUS RNEG RMULT RDIV EQ NE LT GT RLT RGT AND OR NOT
Expand Down Expand Up @@ -36,6 +37,7 @@ exp:
| LPAREN; e = exp; RPAREN { e }
| i = INT { Int i }
| r = REAL { Real r }
| b = BOOL { Bool b }
| x = ID { Var x }
| f = ID; LPAREN; es = args; RPAREN { Call (f, es) }
| IF; e_pred = exp; THEN; e_con = exp; ELSE; e_alt = exp { If (e_pred, e_con, e_alt) }
Expand Down
Loading

0 comments on commit 19d2cf8

Please sign in to comment.