2019-09-10 15:19:15 +02:00
|
|
|
open Trace
|
|
|
|
|
2019-11-29 21:22:56 +00:00
|
|
|
let compile (program : Ast_simplified.program) : (Ast_typed.program * Typer.Solver.state) result =
|
2019-10-11 15:21:21 -04:00
|
|
|
let%bind (prog_typed , state) = Typer.type_program program in
|
|
|
|
let () = Typer.Solver.discard_state state in
|
2019-11-29 21:22:56 +00:00
|
|
|
ok @@ (prog_typed, state)
|
2019-09-20 18:56:55 +02:00
|
|
|
|
2019-12-12 11:00:04 +01:00
|
|
|
let compile_expression ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) (ae : Ast_simplified.expression)
|
|
|
|
: (Ast_typed.value * Typer.Solver.state) result =
|
2019-12-06 16:32:18 +01:00
|
|
|
let () = Typer.Solver.discard_state state in
|
2019-12-12 11:00:04 +01:00
|
|
|
Typer.type_expression env state ae
|
|
|
|
|
2019-12-11 19:15:25 +01:00
|
|
|
let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simplified.expression result =
|
|
|
|
let name = Var.of_name entry_point in
|
|
|
|
let entry_point_var : Ast_simplified.expression =
|
|
|
|
{ expression = Ast_simplified.E_variable name ;
|
|
|
|
location = Virtual "generated entry-point variable" } in
|
2019-12-06 16:32:18 +01:00
|
|
|
let applied : Ast_simplified.expression =
|
2019-12-11 19:15:25 +01:00
|
|
|
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
|
|
|
|
location = Virtual "generated application" } in
|
|
|
|
ok applied
|