1 (*===----------------------------------------------------------------------===
2 * Top-Level parsing and JIT Driver
3 *===----------------------------------------------------------------------===*)
7 (* top ::= definition | external | expression | ';' *)
8 let rec main_loop stream
=
9 match Stream.peek stream
with
12 (* ignore top-level semicolons. *)
13 | Some
(Token.Kwd '
;'
) ->
21 let e = Parser.parse_definition stream
in
22 print_endline
"parsed a function definition.";
23 dump_value
(Codegen.codegen_func
e);
25 let e = Parser.parse_extern stream
in
26 print_endline
"parsed an extern.";
27 dump_value
(Codegen.codegen_proto
e);
29 (* Evaluate a top-level expression into an anonymous function. *)
30 let e = Parser.parse_toplevel stream
in
31 print_endline
"parsed a top-level expr";
32 dump_value
(Codegen.codegen_func
e);
33 with Stream.Error s
| Codegen.Error s
->
34 (* Skip token for error recovery. *)
38 print_string
"ready> "; flush stdout
;