From 243e8f245aa45c77eb6f825952f7a1e8da32346e Mon Sep 17 00:00:00 2001 From: dsac Date: Sun, 18 Dec 2022 00:11:02 +0100 Subject: [PATCH] [ast2C] adding the (->) construct --- src/cprint.ml | 4 +++- src/ctranslation.ml | 8 ++++---- src/test.node | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cprint.ml b/src/cprint.ml index 0ad269a..81cb1fc 100644 --- a/src/cprint.ml +++ b/src/cprint.ml @@ -118,7 +118,9 @@ let rec cp_value fmt (value, (hloc: (ident * bool, string * int) Hashtbl.t)) = | CVInput n -> n) in let (arr, idx) = Hashtbl.find hloc (varname, true) in Format.fprintf fmt "state->%s[%d]" arr idx - | CBinOp (BOp_arrow, v, v') -> failwith "[cprint.ml] (->) TODO!" + | CBinOp (BOp_arrow, v, v') -> + Format.fprintf fmt "(state->is_init ? (%a) : (%a))" + cp_value (v, hloc) cp_value (v', hloc) | CBinOp (op, v, v') -> Format.fprintf fmt "(%a) %s (%a)" cp_value (v, hloc) (string_of_binop op) cp_value (v', hloc) diff --git a/src/ctranslation.ml b/src/ctranslation.ml index c0de7ff..78979a4 100644 --- a/src/ctranslation.ml +++ b/src/ctranslation.ml @@ -41,10 +41,10 @@ let equation_to_expression ((hloc: (ident * bool, string * int)Hashtbl.t), ((vl, | IEBinOp (op, e, e') -> CAssign (fetch_unique_var (), CBinOp (op, iexpression_to_cvalue e, iexpression_to_cvalue e')) - (*| IEComp (op, e, e') -> - CComp (op, iexpression_to_cvalue e, iexpression_to_cvalue e') - | IEConst c -> CConst c - TODO! + | IEComp (op, e, e') -> + CAssign (fetch_unique_var (), + CComp (op, iexpression_to_cvalue e, iexpression_to_cvalue e')) + (*TODO! | IETriOp of triop * i_expression * i_expression * i_expression | IEWhen of i_expression * i_expression | IEReset of i_expression * i_expression diff --git a/src/test.node b/src/test.node index 324533a..f6054ee 100644 --- a/src/test.node +++ b/src/test.node @@ -1,7 +1,7 @@ node n (i: int) returns (o: int); var v, t: int; a, b: bool; let - a = true; + a = true -> false; b = a and not (pre a); o = 1; v = pre o;