Define global variables for async state
This commit is contained in:
parent
2bd04ed02d
commit
eca2974bba
1 changed files with 20 additions and 3 deletions
|
@ -504,6 +504,8 @@ let step_fun_call vr var_env sig_info objn out args async =
|
|||
| Some async -> args @ [Caddrof out; Caddrof async]
|
||||
| None -> args @ [Caddrof out]
|
||||
|
||||
let async_global_var_name od = "g_async__" ^ (name od.o_ident)
|
||||
|
||||
(** Generate the statement to call [objn].
|
||||
[outvl] is a list of lhs where to put the results.
|
||||
[args] is the list of expressions to use as arguments.
|
||||
|
@ -521,7 +523,7 @@ let generate_function_call vr var_env obj_env outvl objn args =
|
|||
cop_of_op_aux classln args
|
||||
else
|
||||
let async = match od.o_ack with
|
||||
| Some _ -> Some (Cvar "GlobalValueToChange")
|
||||
| Some _ -> Some (Cvar (async_global_var_name od))
|
||||
| None -> None
|
||||
in
|
||||
(* The step function takes scalar arguments and its own internal
|
||||
|
@ -924,6 +926,21 @@ let reset_fun_def_of_class_def cd =
|
|||
}
|
||||
}
|
||||
|
||||
let filter_async_objs cd =
|
||||
List.filter
|
||||
(fun od ->
|
||||
match od.o_ack with
|
||||
| Some _ -> true
|
||||
| None -> false)
|
||||
cd.cd_objs
|
||||
|
||||
let async_global_objs_defs cd =
|
||||
List.map
|
||||
(fun od ->
|
||||
let name = async_global_var_name od in
|
||||
let ty = Cty_id (qn_append od.o_class "_async") in
|
||||
Cvardef (name, ty))
|
||||
(filter_async_objs cd)
|
||||
|
||||
(** [cdecl_and_cfun_of_class_def cd] translates the class definition [cd] to
|
||||
a C program. *)
|
||||
|
@ -937,7 +954,7 @@ let cdefs_and_cdecls_of_class_def cd =
|
|||
let in_struct_decl = in_decl_of_class_def cd in
|
||||
let out_struct_decl = out_decl_of_class_def cd in
|
||||
let async_struct_decl = async_decl_of_class_def cd in
|
||||
|
||||
let objs = async_global_objs_defs cd in
|
||||
let step = fun_def_of_step_fun cd.cd_name cd.cd_objs cd.cd_mems
|
||||
cd.cd_objs step_m in
|
||||
(* TODO(Arduino): let the user choose the backend they want *)
|
||||
|
@ -963,7 +980,7 @@ let cdefs_and_cdecls_of_class_def cd =
|
|||
let decls = List.map cdecl_of_cfundef defs in
|
||||
|
||||
memory_struct_decl @ in_struct_decl @ out_struct_decl @ async_struct_decl
|
||||
@ decls, defs
|
||||
@ decls, objs @ defs
|
||||
|
||||
(** {2 Type translation} *)
|
||||
|
||||
|
|
Loading…
Reference in a new issue