tentative 1 de async dans C
This commit is contained in:
parent
ed21462706
commit
fc08753bd9
|
@ -25,6 +25,7 @@ type cty =
|
||||||
| Cty_ptr of cty (** C points-to-other-type type. *)
|
| Cty_ptr of cty (** C points-to-other-type type. *)
|
||||||
| Cty_arr of int * cty (** A static array of the specified size. *)
|
| Cty_arr of int * cty (** A static array of the specified size. *)
|
||||||
| Cty_void (** Well, [void] is not really a C type. *)
|
| Cty_void (** Well, [void] is not really a C type. *)
|
||||||
|
| Cty_future of cty (** async result as a future<t> *)
|
||||||
|
|
||||||
(** A C block: declarations and statements. In source code form, it begins with
|
(** A C block: declarations and statements. In source code form, it begins with
|
||||||
variable declarations before a list of semicolon-separated statements, the
|
variable declarations before a list of semicolon-separated statements, the
|
||||||
|
@ -48,6 +49,7 @@ and cexpr =
|
||||||
| Cstructlit of string * cexpr list (** Structure literal
|
| Cstructlit of string * cexpr list (** Structure literal
|
||||||
" \{f1, f2, ... \}". *)
|
" \{f1, f2, ... \}". *)
|
||||||
| Carraylit of cexpr list (** Array literal [e1, e2, ...]. *)
|
| Carraylit of cexpr list (** Array literal [e1, e2, ...]. *)
|
||||||
|
| Cmethod_call of cexpr * string * cexpr list (** Object member function call with parameters. *)
|
||||||
and cconst =
|
and cconst =
|
||||||
| Ccint of int (** Integer constant. *)
|
| Ccint of int (** Integer constant. *)
|
||||||
| Ccfloat of float (** Floating-point number constant. *)
|
| Ccfloat of float (** Floating-point number constant. *)
|
||||||
|
|
|
@ -103,7 +103,7 @@ let rec ctype_of_otype oty =
|
||||||
ctype_of_otype ty)
|
ctype_of_otype ty)
|
||||||
| Tprod _ -> assert false
|
| Tprod _ -> assert false
|
||||||
| Tunit -> assert false
|
| Tunit -> assert false
|
||||||
| Tasync _ -> assert false (* TODO async *)
|
| Tasync (a,ty) -> Cty_future (ctype_of_otype ty)
|
||||||
|
|
||||||
let cvarlist_of_ovarlist vl =
|
let cvarlist_of_ovarlist vl =
|
||||||
let cvar_of_ovar vd =
|
let cvar_of_ovar vd =
|
||||||
|
@ -289,8 +289,8 @@ let rec cexpr_of_exp var_env exp =
|
||||||
Cstructlit (ctyn, cexps)
|
Cstructlit (ctyn, cexps)
|
||||||
| Earray e_list ->
|
| Earray e_list ->
|
||||||
Carraylit (cexprs_of_exps var_env e_list)
|
Carraylit (cexprs_of_exps var_env e_list)
|
||||||
| Ebang _ ->
|
| Ebang e ->
|
||||||
(* TODO async *) assert false
|
Cmethod_call (cexpr_of_exp var_env e, "get", [])
|
||||||
|
|
||||||
and cexprs_of_exps var_env exps =
|
and cexprs_of_exps var_env exps =
|
||||||
List.map (cexpr_of_exp var_env) exps
|
List.map (cexpr_of_exp var_env) exps
|
||||||
|
@ -309,7 +309,7 @@ and cop_of_op_aux op_name cexps = match op_name with
|
||||||
Cbop (copname op, el, er)
|
Cbop (copname op, el, er)
|
||||||
| _ -> Cfun_call(op, cexps)
|
| _ -> Cfun_call(op, cexps)
|
||||||
end
|
end
|
||||||
| {qual = m; name = op} -> Cfun_call(op,cexps) (*TODO m should be used?*)
|
| {qual = m; name = op} -> Cfun_call(op,cexps)
|
||||||
|
|
||||||
and cop_of_op var_env op_name exps =
|
and cop_of_op var_env op_name exps =
|
||||||
let cexps = cexprs_of_exps var_env exps in
|
let cexps = cexprs_of_exps var_env exps in
|
||||||
|
@ -474,6 +474,19 @@ let rec cstm_of_act var_env obj_env act =
|
||||||
[Cfor(name x, int_of_static_exp i1,
|
[Cfor(name x, int_of_static_exp i1,
|
||||||
int_of_static_exp i2, cstm_of_act_list var_env obj_env act)]
|
int_of_static_exp i2, cstm_of_act_list var_env obj_env act)]
|
||||||
|
|
||||||
|
(** Special case for x = 0^n^n...*)
|
||||||
|
| Aassgn (vn, { e_desc = Econst c }) ->
|
||||||
|
let vn = clhs_of_lhs var_env vn in
|
||||||
|
create_affect_const var_env vn c
|
||||||
|
|
||||||
|
(** Purely syntactic translation from an Obc local variable to a C
|
||||||
|
local one, with recursive translation of the rhs expression. *)
|
||||||
|
| Aassgn (vn, e) ->
|
||||||
|
let vn = clhs_of_lhs var_env vn in
|
||||||
|
let ty = assoc_type_lhs vn var_env in
|
||||||
|
let ce = cexpr_of_exp var_env e in
|
||||||
|
create_affect_stm vn ce ty
|
||||||
|
|
||||||
(** Reinitialization of an object variable, extracting the reset
|
(** Reinitialization of an object variable, extracting the reset
|
||||||
function's name from our environment [obj_env]. *)
|
function's name from our environment [obj_env]. *)
|
||||||
| Acall (name_list, o, Mreset, args) ->
|
| Acall (name_list, o, Mreset, args) ->
|
||||||
|
@ -494,20 +507,17 @@ let rec cstm_of_act var_env obj_env act =
|
||||||
[Csexpr (Cfun_call (classn ^ "_reset", elt ))] )]
|
[Csexpr (Cfun_call (classn ^ "_reset", elt ))] )]
|
||||||
)
|
)
|
||||||
|
|
||||||
| Aasync_call _ -> assert false (* TODO async *)
|
| Aasync_call (a, name_list, o, Mreset, args) ->
|
||||||
|
assert_empty name_list;
|
||||||
(** Special case for x = 0^n^n...*)
|
assert_empty args;
|
||||||
| Aassgn (vn, { e_desc = Econst c }) ->
|
let on = obj_ref_name o in
|
||||||
let vn = clhs_of_lhs var_env vn in
|
let obj = assoc_obj on obj_env in
|
||||||
create_affect_const var_env vn c
|
let classn = cname_of_qn obj.o_class in
|
||||||
|
(match obj.o_size with
|
||||||
(** Purely syntactic translation from an Obc local variable to a C
|
| None ->
|
||||||
local one, with recursive translation of the rhs expression. *)
|
[Csexpr (Cfun_call (classn ^ "_reset", [Caddrof (Cfield (Cderef (Cvar "self"), local_qn on))] ))]
|
||||||
| Aassgn (vn, e) ->
|
| _ -> assert false (* TODO array async *)
|
||||||
let vn = clhs_of_lhs var_env vn in
|
)
|
||||||
let ty = assoc_type_lhs vn var_env in
|
|
||||||
let ce = cexpr_of_exp var_env e in
|
|
||||||
create_affect_stm vn ce ty
|
|
||||||
|
|
||||||
(** Step functions applications can return multiple values, so we use a
|
(** Step functions applications can return multiple values, so we use a
|
||||||
local structure to hold the results, before allocating to our
|
local structure to hold the results, before allocating to our
|
||||||
|
@ -517,6 +527,8 @@ let rec cstm_of_act var_env obj_env act =
|
||||||
let outvl = clhss_of_lhss var_env outvl in
|
let outvl = clhss_of_lhss var_env outvl in
|
||||||
generate_function_call var_env obj_env outvl objn args
|
generate_function_call var_env obj_env outvl objn args
|
||||||
|
|
||||||
|
| Aasync_call _ -> assert false (* TODO async *)
|
||||||
|
|
||||||
|
|
||||||
and cstm_of_act_list var_env obj_env b =
|
and cstm_of_act_list var_env obj_env b =
|
||||||
let l = List.map cvar_of_vd b.b_locals in
|
let l = List.map cvar_of_vd b.b_locals in
|
||||||
|
|
|
@ -41,6 +41,7 @@ and subst_exp map = function
|
||||||
| Caddrof lhs -> Caddrof (subst_lhs map lhs)
|
| Caddrof lhs -> Caddrof (subst_lhs map lhs)
|
||||||
| Cstructlit (s, el) -> Cstructlit (s, subst_exp_list map el)
|
| Cstructlit (s, el) -> Cstructlit (s, subst_exp_list map el)
|
||||||
| Carraylit el -> Carraylit (subst_exp_list map el)
|
| Carraylit el -> Carraylit (subst_exp_list map el)
|
||||||
|
| Cmethod_call _ -> (*TODO async*) assert false
|
||||||
|
|
||||||
and subst_exp_list map =
|
and subst_exp_list map =
|
||||||
List.map (subst_exp map)
|
List.map (subst_exp map)
|
||||||
|
|
Loading…
Reference in a new issue