WIP on understanding where in the AST we need the subst.
This commit is contained in:
parent
770bdda9df
commit
dce15a79c6
@ -24,18 +24,18 @@ and environment_element_definition =
|
|||||||
and free_variables = name list
|
and free_variables = name list
|
||||||
|
|
||||||
and environment_element = {
|
and environment_element = {
|
||||||
type_value : type_value ;
|
type_value : type_value ; (* SUBST ??? *)
|
||||||
source_environment : full_environment ;
|
source_environment : full_environment ;
|
||||||
definition : environment_element_definition ;
|
definition : environment_element_definition ;
|
||||||
}
|
}
|
||||||
and environment = (string * environment_element) list
|
and environment = (string * environment_element) list
|
||||||
and type_environment = (string * type_value) list
|
and type_environment = (string * type_value) list (* SUBST ??? *)
|
||||||
and small_environment = (environment * type_environment)
|
and small_environment = (environment * type_environment)
|
||||||
and full_environment = small_environment List.Ne.t
|
and full_environment = small_environment List.Ne.t
|
||||||
|
|
||||||
and annotated_expression = {
|
and annotated_expression = {
|
||||||
expression : expression ;
|
expression : expression ;
|
||||||
type_annotation : tv ;
|
type_annotation : tv ; (* SUBST *)
|
||||||
environment : full_environment ;
|
environment : full_environment ;
|
||||||
location : Location.t ;
|
location : Location.t ;
|
||||||
}
|
}
|
||||||
@ -54,20 +54,24 @@ and type_value' =
|
|||||||
| T_tuple of tv list
|
| T_tuple of tv list
|
||||||
| T_sum of tv_map
|
| T_sum of tv_map
|
||||||
| T_record of tv_map
|
| T_record of tv_map
|
||||||
| T_constant of type_name * tv list
|
| T_constant of type_name * tv list (* SUBST ??? I think not, at least not necessary for now and the types don't match *)
|
||||||
| T_variable of type_name
|
| T_variable of type_name (* SUBST *)
|
||||||
| T_function of (tv * tv)
|
| T_function of (tv * tv)
|
||||||
|
|
||||||
and type_value = {
|
and type_value = {
|
||||||
type_value' : type_value' ;
|
type_value' : type_value' ;
|
||||||
simplified : S.type_expression option ;
|
simplified : S.type_expression option ; (* If we have the simplified this AST fragment comes from, it is stored here, for easier untyping. *)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(* This is used in E_assign of (named_type_value * access_path * ae).
|
||||||
|
In mini_c, we need the type associated with `x` in the assignment
|
||||||
|
expression `x.y.z := 42`, so it is stored here. *)
|
||||||
and named_type_value = {
|
and named_type_value = {
|
||||||
type_name: name ;
|
type_name: name ;
|
||||||
type_value : type_value ;
|
type_value : type_value ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(* E_lamba and other expressions are always wrapped as an annotated_expression. *)
|
||||||
and lambda = {
|
and lambda = {
|
||||||
binder : name ;
|
binder : name ;
|
||||||
(* input_type: tv ;
|
(* input_type: tv ;
|
||||||
|
@ -3,7 +3,6 @@ open Core
|
|||||||
let pair_map = fun f (x , y) -> (f x , f y)
|
let pair_map = fun f (x , y) -> (f x , f y)
|
||||||
|
|
||||||
module Substitution = struct
|
module Substitution = struct
|
||||||
(* Replace Types variables by the infered type *)
|
|
||||||
|
|
||||||
module Pattern = struct
|
module Pattern = struct
|
||||||
|
|
||||||
@ -29,9 +28,11 @@ module Substitution = struct
|
|||||||
let%bind definition = s_environment_element_definition ~v ~expr definition in
|
let%bind definition = s_environment_element_definition ~v ~expr definition in
|
||||||
ok @@ (type_variable, T.{ type_value; source_environment; definition })
|
ok @@ (type_variable, T.{ type_value; source_environment; definition })
|
||||||
) lst
|
) lst
|
||||||
and s_type_environment ~v ~expr : T.type_environment w = fun _ ->
|
and s_type_environment ~v ~expr : T.type_environment w = fun tenv ->
|
||||||
let _TODO = (v, expr) in
|
bind_map_list (fun (type_variable , type_value) ->
|
||||||
failwith "TODO: subst: unimplemented case s_type_environment"
|
let%bind type_variable = s_type_variable ~v ~expr type_variable in
|
||||||
|
let%bind type_value = s_type_value ~v ~expr type_value in
|
||||||
|
ok @@ (type_variable , type_value)) tenv
|
||||||
and s_small_environment ~v ~expr : T.small_environment w = fun (environment, type_environment) ->
|
and s_small_environment ~v ~expr : T.small_environment w = fun (environment, type_environment) ->
|
||||||
let%bind environment = s_environment ~v ~expr environment in
|
let%bind environment = s_environment ~v ~expr environment in
|
||||||
let%bind type_environment = s_type_environment ~v ~expr type_environment in
|
let%bind type_environment = s_type_environment ~v ~expr type_environment in
|
||||||
@ -46,27 +47,62 @@ module Substitution = struct
|
|||||||
ok var
|
ok var
|
||||||
|
|
||||||
and s_type_variable ~v ~expr : T.name w = fun tvar ->
|
and s_type_variable ~v ~expr : T.name w = fun tvar ->
|
||||||
let _TODO = ignore (v, expr, tvar) in
|
let _TODO = ignore (v, expr) in
|
||||||
failwith "TODO: subst: unimplemented case s_type_variable"
|
Printf.printf "TODO: subst: unimplemented case s_type_variable";
|
||||||
(* if String.equal tvar v then
|
ok @@ tvar
|
||||||
* expr
|
(* if String.equal tvar v then
|
||||||
* else
|
* expr
|
||||||
* ok tvar *)
|
* else
|
||||||
|
* ok tvar *)
|
||||||
|
|
||||||
and s_type_value' ~v ~expr : T.type_value' w = fun _ ->
|
and s_type_name_constant ~v ~expr : T.type_name w = fun type_name ->
|
||||||
let _TODO = (v, expr) in
|
(* TODO: we don't need to subst anything, right? *)
|
||||||
failwith "TODO: subst: unimplemented case s_type_value'"
|
let () = ignore (v , expr) in
|
||||||
and s_type_expression ~v ~expr : Ast_simplified.type_expression w = fun _ ->
|
ok @@ type_name
|
||||||
let _TODO = (v, expr) in
|
|
||||||
failwith "TODO: subst: unimplemented case s_type_expression"
|
and s_type_value' ~v ~expr : T.type_value' w = function
|
||||||
|
| T.T_tuple type_value_list ->
|
||||||
|
let%bind type_value_list = bind_map_list (s_type_value ~v ~expr) type_value_list in
|
||||||
|
ok @@ T.T_tuple type_value_list
|
||||||
|
| T.T_sum _ -> failwith "TODO: T_sum"
|
||||||
|
| T.T_record _ -> failwith "TODO: T_record"
|
||||||
|
| T.T_constant (type_name, type_value_list) ->
|
||||||
|
let%bind type_name = s_type_name_constant ~v ~expr type_name in
|
||||||
|
let%bind type_value_list = bind_map_list (s_type_value ~v ~expr) type_value_list in
|
||||||
|
ok @@ T.T_constant (type_name, type_value_list)
|
||||||
|
| T.T_variable _ -> failwith "TODO: T_variable"
|
||||||
|
| T.T_function _ ->
|
||||||
|
let _TODO = (v, expr) in
|
||||||
|
failwith "TODO: T_function"
|
||||||
|
|
||||||
|
and s_type_expression ~v ~expr : Ast_simplified.type_expression w = function
|
||||||
|
| Ast_simplified.T_tuple _ -> failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
| Ast_simplified.T_sum _ -> failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
| Ast_simplified.T_record _ -> failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
| Ast_simplified.T_function (_, _) -> failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
| Ast_simplified.T_variable _ -> failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
| Ast_simplified.T_constant (_, _) ->
|
||||||
|
let _TODO = (v, expr) in
|
||||||
|
failwith "TODO: subst: unimplemented case s_type_expression"
|
||||||
|
|
||||||
and s_type_value ~v ~expr : T.type_value w = fun { type_value'; simplified } ->
|
and s_type_value ~v ~expr : T.type_value w = fun { type_value'; simplified } ->
|
||||||
let%bind type_value' = s_type_value' ~v ~expr type_value' in
|
let%bind type_value' = s_type_value' ~v ~expr type_value' in
|
||||||
let%bind simplified = bind_map_option (s_type_expression ~v ~expr) simplified in
|
let%bind simplified = bind_map_option (s_type_expression ~v ~expr) simplified in
|
||||||
ok @@ T.{ type_value'; simplified }
|
ok @@ T.{ type_value'; simplified }
|
||||||
and s_literal ~v ~expr : T.literal w = fun _ ->
|
and s_literal ~v ~expr : T.literal w = function
|
||||||
let _TODO = v, expr in
|
| T.Literal_unit ->
|
||||||
failwith "TODO: subst: unimplemented case s_literal"
|
let () = ignore (v, expr) in
|
||||||
|
ok @@ T.Literal_unit
|
||||||
|
| (T.Literal_bool _ as x)
|
||||||
|
| (T.Literal_int _ as x)
|
||||||
|
| (T.Literal_nat _ as x)
|
||||||
|
| (T.Literal_timestamp _ as x)
|
||||||
|
| (T.Literal_mutez _ as x)
|
||||||
|
| (T.Literal_string _ as x)
|
||||||
|
| (T.Literal_bytes _ as x)
|
||||||
|
| (T.Literal_address _ as x)
|
||||||
|
| (T.Literal_operation _ as x) ->
|
||||||
|
ok @@ x
|
||||||
and s_matching_expr ~v ~expr : T.matching_expr w = fun _ ->
|
and s_matching_expr ~v ~expr : T.matching_expr w = fun _ ->
|
||||||
let _TODO = v, expr in
|
let _TODO = v, expr in
|
||||||
failwith "TODO: subst: unimplemented case s_matching"
|
failwith "TODO: subst: unimplemented case s_matching"
|
||||||
@ -115,11 +151,11 @@ module Substitution = struct
|
|||||||
| T.E_record aemap ->
|
| T.E_record aemap ->
|
||||||
let _TODO = aemap in
|
let _TODO = aemap in
|
||||||
failwith "TODO: subst in record"
|
failwith "TODO: subst in record"
|
||||||
(* let%bind aemap = TSMap.bind_map_Map (fun ~k:key ~v:val_ ->
|
(* let%bind aemap = TSMap.bind_map_Map (fun ~k:key ~v:val_ ->
|
||||||
* let key = s_type_variable ~v ~expr key in
|
* let key = s_type_variable ~v ~expr key in
|
||||||
* let val_ = s_annotated_expression ~v ~expr val_ in
|
* let val_ = s_annotated_expression ~v ~expr val_ in
|
||||||
* ok @@ (key , val_)) aemap in
|
* ok @@ (key , val_)) aemap in
|
||||||
* ok @@ T.E_record aemap *)
|
* ok @@ T.E_record aemap *)
|
||||||
| T.E_record_accessor (val_, tvar) ->
|
| T.E_record_accessor (val_, tvar) ->
|
||||||
let%bind val_ = s_annotated_expression ~v ~expr val_ in
|
let%bind val_ = s_annotated_expression ~v ~expr val_ in
|
||||||
let%bind tvar = s_type_variable ~v ~expr tvar in
|
let%bind tvar = s_type_variable ~v ~expr tvar in
|
||||||
|
Loading…
Reference in New Issue
Block a user