Use the mutable_flag instead of let_kind for clambda let
parent
f7dcbf21e7
commit
211e6f54fb
|
@ -43,7 +43,7 @@ and ulambda =
|
|||
| Ugeneric_apply of ulambda * ulambda list * Debuginfo.t
|
||||
| Uclosure of ufunction list * ulambda list
|
||||
| Uoffset of ulambda * int
|
||||
| Ulet of let_kind * value_kind * Ident.t * ulambda * ulambda
|
||||
| Ulet of mutable_flag * value_kind * Ident.t * ulambda * ulambda
|
||||
| Uletrec of (Ident.t * ulambda) list * ulambda
|
||||
| Uprim of primitive * ulambda list * Debuginfo.t
|
||||
| Uswitch of ulambda * ulambda_switch
|
||||
|
|
|
@ -43,7 +43,7 @@ and ulambda =
|
|||
| Ugeneric_apply of ulambda * ulambda list * Debuginfo.t
|
||||
| Uclosure of ufunction list * ulambda list
|
||||
| Uoffset of ulambda * int
|
||||
| Ulet of let_kind * value_kind * Ident.t * ulambda * ulambda
|
||||
| Ulet of mutable_flag * value_kind * Ident.t * ulambda * ulambda
|
||||
| Uletrec of (Ident.t * ulambda) list * ulambda
|
||||
| Uprim of primitive * ulambda list * Debuginfo.t
|
||||
| Uswitch of ulambda * ulambda_switch
|
||||
|
|
|
@ -654,7 +654,7 @@ let rec bind_params_rec fpc subst params args body =
|
|||
in
|
||||
let body' =
|
||||
bind_params_rec fpc (Tbl.add p1 u2 subst) pl al body in
|
||||
if occurs_var p1 body then Ulet(Strict, Pgenval, p1', u1, body')
|
||||
if occurs_var p1 body then Ulet(Immutable, Pgenval, p1', u1, body')
|
||||
else if no_effects a1 then body'
|
||||
else Usequence(a1, body')
|
||||
end
|
||||
|
@ -854,7 +854,7 @@ let rec close fenv cenv = function
|
|||
[] -> body
|
||||
| (arg1, arg2) :: args ->
|
||||
iter args
|
||||
(Ulet (Strict, Pgenval, arg1, arg2, body))
|
||||
(Ulet (Immutable, Pgenval, arg1, arg2, body))
|
||||
in
|
||||
let internal_args =
|
||||
(List.map (fun (arg1, _arg2) -> Lvar arg1) first_args)
|
||||
|
@ -897,13 +897,13 @@ let rec close fenv cenv = function
|
|||
begin match (str, alam) with
|
||||
(Variable, _) ->
|
||||
let (ubody, abody) = close fenv cenv body in
|
||||
(Ulet(str, kind, id, ulam, ubody), abody)
|
||||
(Ulet(Mutable, kind, id, ulam, ubody), abody)
|
||||
| (_, Value_const _)
|
||||
when str = Alias || is_pure lam ->
|
||||
close (Tbl.add id alam fenv) cenv body
|
||||
| (_, _) ->
|
||||
let (ubody, abody) = close (Tbl.add id alam fenv) cenv body in
|
||||
(Ulet(str, kind, id, ulam, ubody), abody)
|
||||
(Ulet(Immutable, kind, id, ulam, ubody), abody)
|
||||
end
|
||||
| Lletrec(defs, body) ->
|
||||
if List.for_all
|
||||
|
@ -923,7 +923,7 @@ let rec close fenv cenv = function
|
|||
(fun (id, pos, _approx) sb ->
|
||||
Tbl.add id (Uoffset(Uvar clos_ident, pos)) sb)
|
||||
infos Tbl.empty in
|
||||
(Ulet(Strict, Pgenval,
|
||||
(Ulet(Immutable, Pgenval,
|
||||
clos_ident, clos, substitute !Clflags.float_const_prop sb ubody),
|
||||
approx)
|
||||
end else begin
|
||||
|
|
|
@ -2300,9 +2300,9 @@ and transl_let env str kind id exp body =
|
|||
might require some boxing, but such local references are often
|
||||
used in loops and we really want to avoid repeated boxing. *)
|
||||
match str, kind with
|
||||
| Variable, Pfloatval ->
|
||||
| Mutable, Pfloatval ->
|
||||
Boxed Boxed_float
|
||||
| Variable, Pboxedintval bi ->
|
||||
| Mutable, Pboxedintval bi ->
|
||||
Boxed (Boxed_integer bi)
|
||||
| _, (Pfloatval | Pboxedintval _) ->
|
||||
(* It would be safe to always unbox in this case, but
|
||||
|
|
|
@ -252,12 +252,12 @@ let rec to_clambda t env (flam : Flambda.t) : Clambda.ulambda =
|
|||
| Let { var; defining_expr; body; _ } ->
|
||||
(* TODO: synthesize proper value_kind *)
|
||||
let id, env_body = Env.add_fresh_ident env var in
|
||||
Ulet (Strict, Pgenval, id, to_clambda_named t env var defining_expr,
|
||||
Ulet (Immutable, Pgenval, id, to_clambda_named t env var defining_expr,
|
||||
to_clambda t env_body body)
|
||||
| Let_mutable { var = mut_var; initial_value = var; body; contents_kind } ->
|
||||
let id, env_body = Env.add_fresh_mutable_ident env mut_var in
|
||||
let def = subst_var env var in
|
||||
Ulet (Variable, contents_kind, id, def, to_clambda t env_body body)
|
||||
Ulet (Mutable, contents_kind, id, def, to_clambda t env_body body)
|
||||
| Let_rec (defs, body) ->
|
||||
let env, defs =
|
||||
List.fold_right (fun (var, def) (env, defs) ->
|
||||
|
|
|
@ -18,11 +18,9 @@ open Format
|
|||
open Asttypes
|
||||
open Clambda
|
||||
|
||||
let let_kind =
|
||||
let open Lambda in
|
||||
function
|
||||
| Variable -> "[mut]"
|
||||
| _ -> ""
|
||||
let mutable_flag = function
|
||||
| Mutable-> "[mut]"
|
||||
| Immutable -> ""
|
||||
|
||||
let value_kind =
|
||||
let open Lambda in
|
||||
|
@ -94,15 +92,15 @@ and lam ppf = function
|
|||
List.iter (fprintf ppf "@ %a" lam) in
|
||||
fprintf ppf "@[<2>(closure@ %a %a)@]" funs clos lams fv
|
||||
| Uoffset(l,i) -> fprintf ppf "@[<2>(offset %a %d)@]" lam l i
|
||||
| Ulet(str, kind, id, arg, body) ->
|
||||
| Ulet(mut, kind, id, arg, body) ->
|
||||
let rec letbody ul = match ul with
|
||||
| Ulet(str, kind, id, arg, body) ->
|
||||
| Ulet(mut, kind, id, arg, body) ->
|
||||
fprintf ppf "@ @[<2>%a%s%s@ %a@]"
|
||||
Ident.print id (let_kind str) (value_kind kind) lam arg;
|
||||
Ident.print id (mutable_flag mut) (value_kind kind) lam arg;
|
||||
letbody body
|
||||
| _ -> ul in
|
||||
fprintf ppf "@[<2>(let@ @[<hv 1>(@[<2>%a%s%s@ %a@]"
|
||||
Ident.print id (let_kind str) (value_kind kind) lam arg;
|
||||
Ident.print id (mutable_flag mut) (value_kind kind) lam arg;
|
||||
let expr = letbody body in
|
||||
fprintf ppf ")@]@ %a)@]" lam expr
|
||||
| Uletrec(id_arg_list, body) ->
|
||||
|
|
Loading…
Reference in New Issue