Skip to content
Snippets Groups Projects

Update internal state of the typer

Merged E. Rivas requested to merge er433/typer/context into dev
1 file
+ 8
7
Compare changes
  • Side-by-side
  • Inline
@@ -13,11 +13,12 @@ module App_context = struct
type t = O.type_expression option * (O.expression list * O.type_expression option) list
let pop_app_context = function
_, (args, r) :: vs -> Some (args, (r , vs)) | _, [] -> None
let create tv_opt : t = tv_opt, []
let get_tv_opt ((c, _) : t) = c
let push_app_context tv_opt args ctxt =
let push_app_context tv_opt args ctxt : t =
let old_tv_opt, ctxt = ctxt in
tv_opt, (args, old_tv_opt) :: ctxt
let update_tv_opt_app_context tv_opt (_, r) = (tv_opt, r)
let update_tv_opt_app_context tv_opt (_, r) : t = tv_opt, r
end
let assert_type_expression_eq = Helpers.assert_type_expression_eq
@@ -74,7 +75,7 @@ match Location.unwrap d with
let c = List.fold_right av ~f:(fun v c -> Context.add_type_var c v ()) ~init:c in
let expr =
trace ~raise (constant_declaration_tracer loc var expr None) @@
type_expression' ~options (None, []) c expr in
type_expression' ~options (App_context.create None) c expr in
let rec aux t = function
| [] -> t
| (abs_var :: abs_vars) -> t_for_all abs_var Type (aux t abs_vars) in
@@ -92,7 +93,7 @@ match Location.unwrap d with
let tv = evaluate_type ~raise env tv in
let expr =
trace ~raise (constant_declaration_tracer loc var expr (Some tv)) @@
type_expression' ~options ~tv_opt:tv (Some tv, []) env expr in
type_expression' ~options ~tv_opt:tv (App_context.create @@ Some tv) env expr in
let rec aux t = function
| [] -> t
| (abs_var :: abs_vars) -> t_for_all abs_var Type (aux t abs_vars) in
@@ -304,7 +305,7 @@ and evaluate_type ~raise (c:context) (t:I.type_expression) : O.type_expression =
and type_expression ~raise ~options : ?env:Environment.t -> ?tv_opt:O.type_expression -> I.expression -> O.expression
= fun ?env ?tv_opt e ->
let c = Context.init ?env () in
let res = type_expression' ~raise ~options (tv_opt, []) c ?tv_opt e in
let res = type_expression' ~raise ~options (App_context.create tv_opt) c ?tv_opt e in
res
and infer_t_insts ~raise ~loc app_context ( (tc,t) : O.expression_content * O.type_expression ) =
@@ -626,12 +627,12 @@ and type_expression' ~raise ~options : App_context.t -> context -> ?tv_opt:O.typ
let eqs = List.map ~f:aux cases in
match matchee.expression_content with
| E_variable matcheevar ->
let case_exp = Pattern_matching.compile_matching ~raise ~err_loc:e.location ~type_f:(type_expression' ~options (None, [])) ~body_t:(tv_opt) matcheevar eqs in
let case_exp = Pattern_matching.compile_matching ~raise ~err_loc:e.location ~type_f:(type_expression' ~options (App_context.create None)) ~body_t:(tv_opt) matcheevar eqs in
let case_exp = { case_exp with location = e.location } in
return case_exp.expression_content case_exp.type_expression
| _ ->
let matcheevar = I.ValueVar.fresh () in
let case_exp = Pattern_matching.compile_matching ~raise ~err_loc:e.location ~type_f:(type_expression' ~options (None, [])) ~body_t:(tv_opt) matcheevar eqs in
let case_exp = Pattern_matching.compile_matching ~raise ~err_loc:e.location ~type_f:(type_expression' ~options (App_context.create None)) ~body_t:(tv_opt) matcheevar eqs in
let case_exp = { case_exp with location = e.location } in
let x = O.E_let_in { let_binder = matcheevar ; rhs = matchee' ; let_result = case_exp ; attr = {inline = false; no_mutation = false; public = true ; view= false } } in
return x case_exp.type_expression
Loading