Use _local_out variable for _async_step method

This commit is contained in:
jeltz 2020-12-22 17:37:54 +01:00
parent e0fd48562b
commit 622a55ed81
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -223,8 +223,10 @@ let rec assoc_type_lhs lhs var_env = match lhs with
| Cty_ptr ty -> ty
| _ -> Error.message no_location Error.Ederef_not_pointer)
| CLfield(CLderef (CLvar "self"), { name = x }) -> assoc_type x var_env
(* TODO(Arduino): it's probably not necessary, but we could choose to
use assoc_type depending on the async state of the node *)
| CLfield(CLderef (CLvar "_out"), { name = x }) -> assoc_type x var_env
(* FIXME(Arduino): do we have to do something here? *)
| CLfield(CLvar "_local_out", { name = x }) -> assoc_type x var_env
| CLfield(x, f) ->
let ty = assoc_type_lhs x var_env in
let n = struct_name ty in
@ -356,7 +358,7 @@ and clhs_of_pattern out out_env var_env l = match l.pat_desc with
let n = name v in
let n_lhs =
if IdentSet.mem v out_env
then CLfield (CLderef (CLvar out), local_qn n)
then CLfield (clhs_of_cexpr out, local_qn n)
else CLvar n
in
@ -385,7 +387,7 @@ and cexpr_of_pattern out out_env var_env l = match l.pat_desc with
let n = name v in
let n_lhs =
if IdentSet.mem v out_env
then Cfield (Cderef (Cvar out), local_qn n)
then Cfield (out, local_qn n)
else Cvar n
in
@ -412,7 +414,7 @@ and cexpr_of_ext_value out out_env var_env w = match w.w_desc with
let n = name v in
let n_lhs =
if IdentSet.mem v out_env
then Cfield (Cderef (Cvar out), local_qn n)
then Cfield (out, local_qn n)
else Cvar n
in
@ -452,7 +454,7 @@ let out_var_name_of_objn o =
(** Creates the list of arguments to call a node. [targeting] is the targeting
of the called node, [mem] represents the node context and [args] the
argument list.*)
let step_fun_call out_v out_env var_env sig_info objn out args =
let step_fun_call out_env var_env sig_info objn out args =
let rec add_targeting l ads = match l, ads with
| [], [] -> []
| e::l, ad::ads ->
@ -471,7 +473,8 @@ let step_fun_call out_v out_env var_env sig_info objn out args =
let rec mk_idx pl = match pl with
| [] -> f
| p::pl ->
Carray (mk_idx pl, cexpr_of_pattern out_v out_env var_env p)
Carray (mk_idx pl, cexpr_of_pattern (Cderef (Cvar "_out"))
out_env var_env p)
in
mk_idx l
) in
@ -496,7 +499,7 @@ let generate_function_call out_env var_env obj_env outvl objn args =
else
(* The step function takes scalar arguments and its own internal memory
holding structure. *)
let args = step_fun_call "_out" out_env var_env sig_info objn out args in
let args = step_fun_call out_env var_env sig_info objn out args in
(* Our C expression for the function call. *)
Cfun_call (classn ^ "_step", args)
in
@ -719,7 +722,9 @@ let fun_def_of_step_fun n obj_env mem objs md =
IdentSet.empty
md.m_outputs
in
let body = cstm_of_act_list "_out" out_env var_env obj_env md.m_body in
let body =
cstm_of_act_list (Cderef (Cvar "_out")) out_env var_env obj_env md.m_body
in
Cfundef {
C.f_name = fun_name;
@ -745,6 +750,13 @@ let async_fun_def_of_step_fun n obj_env mem objs md copy_in_name
Cty_id (qn_append obj.o_class "_out"))
(List.filter (fun obj -> not (is_op obj.o_class)) objs)) in
let out_vars =
List.fold_left
(fun out_vars s -> ("_local" ^ s, Cty_id (qn_append n s)) :: out_vars)
out_vars
["_in"; "_out"]
in
(* TODO(Arduino): Refactor with non-async version *)
(* The body *)
let mems = List.map cvar_of_vd (mem@md.m_outputs) in
@ -756,26 +768,23 @@ let async_fun_def_of_step_fun n obj_env mem objs md copy_in_name
md.m_outputs
in
let local_in = ("_local_in", Cty_id (qn_append n "_in")) in
let local_out = ("_local_out", Cty_id (qn_append n "_out")) in
let local_in = Cvar "_local_in" in
let local_out = Cvar "_local_out" in
let copy_in = Cfun_call (copy_in_name,
[Caddrof (Cvar "_local_in"); Cvar "_in"]) in
let copy_in = Cfun_call (copy_in_name, [Caddrof local_in; Cvar "_in"]) in
(* FIXME(Arduino): rename input & output variables *)
let body =
cstm_of_act_list "_out" out_env var_env obj_env md.m_body
cstm_of_act_list local_out out_env var_env obj_env md.m_body
in
let copy_out = Cfun_call (copy_out_name,
[Cvar "_out"; Caddrof (Cvar "_local_out")]) in
let copy_out = Cfun_call (copy_out_name, [Cvar "_out"; Caddrof local_out]) in
Cfundef {
C.f_name = fun_name;
f_retty = Cty_void;
f_args = args;
f_body = {
var_decls = local_in :: local_out :: out_vars;
var_decls = out_vars;
block_body = (Csexpr copy_in) :: body @ [Csexpr copy_out]
}
}
@ -828,7 +837,8 @@ let reset_fun_def_of_class_def cd =
if cd.cd_stateful then
let var_env = List.map cvar_of_vd cd.cd_mems in
let reset = find_reset_method cd in
cstm_of_act_list "_out" IdentSet.empty var_env cd.cd_objs reset.m_body
cstm_of_act_list (Cderef (Cvar "_out")) IdentSet.empty var_env cd.cd_objs
reset.m_body
else
[]
in