13
13
(* *)
14
14
(* *************************************************************************)
15
15
16
- module Id : sig
17
- type t
18
-
19
- val fresh : unit -> t
20
-
21
- val print : Format .formatter -> t -> unit
22
-
23
- module Map : Container_types .Map with type key = t
24
- end = struct
25
- type t = int
26
-
27
- let print = Numbers.Int. print
28
-
29
- let fresh =
30
- let r = ref 0 in
31
- fun () ->
32
- incr r;
33
- ! r
34
-
35
- module Tree = Patricia_tree. Make (struct
36
- let print = print
37
- end )
38
-
39
- module Map = Tree. Map
40
- end
16
+ module BP = Bound_parameter
41
17
42
18
type t =
43
19
{ len : int ;
44
- new_params_indexed : Bound_parameter .t Id .Map.t
20
+ new_params_indexed : BP .t BP .Map.t
45
21
}
46
22
47
23
let print ppf { len = _ ; new_params_indexed } =
48
24
Format. fprintf ppf " @[<hov 1>(@[<hov 1>(new_params_indexed@ %a)@])@]"
49
- (Id.Map. print Bound_parameter. print)
50
- new_params_indexed
25
+ (BP.Map. print BP. print) new_params_indexed
51
26
52
- let empty = { len = 0 ; new_params_indexed = Id .Map. empty }
27
+ let empty = { len = 0 ; new_params_indexed = BP .Map. empty }
53
28
54
29
let is_empty { len; new_params_indexed = _ } = len = 0
55
30
56
31
let length { len; new_params_indexed = _ } = len
57
32
58
33
let new_param t bound_param =
59
- (* create a fresh var/bound_param to index the new parameter *)
60
- let id = Id. fresh () in
61
- let new_params_indexed = Id.Map. add id bound_param t.new_params_indexed in
34
+ let new_params_indexed =
35
+ BP.Map. add bound_param bound_param t.new_params_indexed
36
+ in
62
37
{ len = t.len + 1 ; new_params_indexed }
63
38
64
39
let rename t =
65
- let bindings = Id .Map. bindings t.new_params_indexed in
40
+ let bindings = BP .Map. bindings t.new_params_indexed in
66
41
let keys, bound_param_list = List. split bindings in
67
42
let bound_params = Bound_parameters. create bound_param_list in
68
43
let new_bound_params = Bound_parameters. rename bound_params in
69
44
let renaming =
70
45
Bound_parameters. renaming bound_params ~guaranteed_fresh: new_bound_params
71
46
in
72
47
let new_params_indexed =
73
- Id .Map. of_list
48
+ BP .Map. of_list
74
49
(List. combine keys (Bound_parameters. to_list new_bound_params))
75
50
in
76
51
{ t with new_params_indexed }, renaming
77
52
78
53
let fold_aux ~init ~f { len = _ ; new_params_indexed } =
79
- Id .Map. fold f new_params_indexed init
54
+ BP .Map. fold f new_params_indexed init
80
55
81
56
let fold ~init ~f t = fold_aux ~init ~f: (fun _ param acc -> f param acc) t
82
57
83
- let rec find_arg id = function
58
+ let rec find_arg bp = function
84
59
| [] ->
85
60
Misc. fatal_errorf
86
61
" Missing lifted param id: %a not found in lifted_cont_params stack"
87
- Id . print id
62
+ BP . print bp
88
63
| { len = _ ; new_params_indexed } :: r -> (
89
- match Id .Map. find_opt id new_params_indexed with
90
- | Some param -> Bound_parameter . simple param
91
- | None -> find_arg id r)
64
+ match BP .Map. find_opt bp new_params_indexed with
65
+ | Some param -> BP . simple param
66
+ | None -> find_arg bp r)
92
67
93
68
(* NOTE about the order of the returned args/params for the {args} and
94
69
{bound_parameters} functions: The exact order does not matter as long as both
@@ -99,8 +74,8 @@ let rec find_arg id = function
99
74
order of the bindings in the Map, but that's fine since it is the case for
100
75
both functions. *)
101
76
let args ~callee_lifted_params ~caller_stack_lifted_params =
102
- fold_aux callee_lifted_params ~init: [] ~f: (fun id _callee_param acc ->
103
- find_arg id caller_stack_lifted_params :: acc)
77
+ fold_aux callee_lifted_params ~init: [] ~f: (fun bp_key _callee_param acc ->
78
+ find_arg bp_key caller_stack_lifted_params :: acc)
104
79
105
80
let bound_parameters t =
106
81
Bound_parameters. create
0 commit comments