WIP: Add MstepAsync method to ObC

This commit is contained in:
jeltz 2020-12-21 00:16:04 +01:00
parent 53cc7a739f
commit fdee5b68c0
Signed by: jeltz
GPG key ID: 800882B66C0C3326
5 changed files with 20 additions and 4 deletions

View file

@ -642,6 +642,10 @@ let rec cstm_of_act out_env var_env obj_env act =
let outvl = clhs_list_of_pattern_list out_env var_env outvl in
generate_function_call out_env var_env obj_env outvl objn args
| Acall (outv1, objn, MstepAsync, e1) ->
(* 1. Atomic copy of the inputs *)
(* 2. Atomic copy of the outputs *)
assert false
and cstm_of_act_list out_env var_env obj_env b =
let l = List.map cvar_of_vd b.b_locals in
@ -663,8 +667,14 @@ let qn_append q suffix =
{ qual = q.qual; name = q.name ^ suffix }
(** Builds the argument list of step function*)
let step_fun_args n md =
let args = inputlist_of_ovarlist md.m_inputs in
let step_fun_args n md pack_inputs =
let args =
if pack_inputs then
(* TODO(Arduino): add const qualifier *)
[("_in", Cty_ptr (Cty_id (qn_append n "_in")))]
else
inputlist_of_ovarlist md.m_inputs
in
let out_arg = [("_out", Cty_ptr (Cty_id (qn_append n "_out")))] in
let context_arg =
if is_stateful n then
@ -681,11 +691,11 @@ let step_fun_args n md =
reset calls. A step function can have multiple return values, whereas C does
not allow such functions. When it is the case, we declare a structure with a
field by return value. *)
let fun_def_of_step_fun n obj_env mem objs md =
let fun_def_of_step_fun ?(async = false) n obj_env mem objs md =
let fun_name = (cname_of_qn n) ^ "_step" in
(* Its arguments, translating Obc types to C types and adding our internal
memory structure. *)
let args = step_fun_args n md in
let args = step_fun_args n md async in
(* Out vars for function calls *)
let out_vars =

View file

@ -356,6 +356,7 @@ let rec act_list param_env act_l acts =
in
let copies = Misc.mapi copy_return_to_var p_l in
assgn::(copies@acts)
| Obc.Acall (_, _, MstepAsync, _) -> assert false
| Obc.Acall (_, obj, Mreset, _) ->
let acall = Emethod_call (obj_ref param_env obj, "reset", []) in
Aexp acall::acts

View file

@ -356,6 +356,8 @@ let rec act_list param_env act_l acts =
in
let copies = Misc.mapi copy_return_to_var p_l in
assgn::(copies@acts)
(* TODO(Arduino): Java is not supported (yet?) *)
| Obc.Acall (_, _, MstepAsync, _) -> assert false
| Obc.Acall (_, obj, Mreset, _) ->
let acall = Emethod_call (obj_ref param_env obj, "reset", []) in
Aexp acall::acts

View file

@ -92,6 +92,7 @@ type obj_ref =
type method_name =
| Mreset
| Mstep
| MstepAsync
type act =
| Aassgn of pattern * exp

View file

@ -113,6 +113,7 @@ let print_obj_call ff = function
let print_method_name ff = function
| Mstep -> fprintf ff "step"
| Mreset -> fprintf ff "reset"
| MstepAsync -> fprintf ff "step_async"
let rec print_act ff a =
@ -165,6 +166,7 @@ and print_tag_act_list ff tag_act_list =
let print_method_name ff = function
| Mreset -> fprintf ff "reset"
| Mstep -> fprintf ff "step"
| MstepAsync -> fprintf ff "step_async"
let print_arg_list ff var_list =
fprintf ff "(@[%a@])" (print_list_r print_vd "" "," "") var_list