Fix bug of async calls of stateless functions

This commit is contained in:
jeltz 2020-12-25 00:10:14 +01:00
parent eca2974bba
commit 5b1a286999
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -777,7 +777,7 @@ let fun_stub_def_of_step_fun n md copy_in copy_out =
(inputlist_of_ovarlist md.m_inputs))
in
let body = [
Csexpr (Cfun_call (copy_in, [async_field_ptr "in"; Cvar "_in"]));
Csexpr (Cfun_call (copy_in, [async_field_ptr "in"; Caddrof (Cvar "_in")]));
Csexpr (Cfun_call (copy_out, [Cvar "_out"; async_field_ptr "out"]))
] in
@ -813,7 +813,10 @@ let async_fun_def_of_step_fun n obj_env mem objs md copy_in copy_out =
_async struct pointer, but the string "self" is hardcoded in a large
number of places *)
let out_vars =
("self", Cty_ptr (Cty_id (qn_append n "_mem"))) :: out_vars
if is_stateful n then
("self", Cty_ptr (Cty_id (qn_append n "_mem"))) :: out_vars
else
out_vars
in
(* The body *)
@ -833,9 +836,14 @@ let async_fun_def_of_step_fun n obj_env mem objs md copy_in copy_out =
in
let prologue = [
Caffect (CLvar "self", async_field_ptr "self");
Csexpr (Cfun_call (copy_in, [Caddrof l_in; async_field_ptr "in"]))
] in
let prologue =
if is_stateful n then
(Caffect (CLvar "self", async_field_ptr "self")) :: prologue
else
prologue
in
let body = cstm_of_act_list vr var_env obj_env md.m_body in
let epilogue = [
Csexpr (Cfun_call (copy_out, [async_field_ptr "out"; Caddrof l_out]))
@ -899,9 +907,13 @@ let async_decl_of_class_def cd =
in
let fields = [
struct_field "_in" "in";
struct_field "_out" "out";
struct_field "_mem" "self"
struct_field "_out" "out"
] in
let fields = if is_stateful cd.cd_name then
(struct_field "_mem" "self") :: fields
else
fields
in
[Cdecl_struct ((cname_of_qn cd.cd_name) ^ "_async", fields)]
(** [reset_fun_def_of_class_def cd] returns the defintion of the C function
@ -971,11 +983,12 @@ let cdefs_and_cdecls_of_class_def cd =
(* C function for resetting our memory structure. *)
let reset = reset_fun_def_of_class_def cd in
let defs = [step; copy_in; copy_out; async_stub; async_step] in
let defs =
if is_stateful cd.cd_name then
[reset; step; copy_in; copy_out; async_stub; async_step]
reset :: defs
else
[step]
defs
in
let decls = List.map cdecl_of_cfundef defs in