From 6291957be5b3044d1112a7284e059f30032ad178 Mon Sep 17 00:00:00 2001 From: dsac Date: Sat, 17 Dec 2022 16:35:49 +0100 Subject: [PATCH] [ast2C] init or not init (field added to the state of the node) --- src/c_utils.ml | 1 + src/cprint.ml | 8 +++++--- src/test2.node | 8 -------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/c_utils.ml b/src/c_utils.ml index 83a354a..26ba5e1 100644 --- a/src/c_utils.ml +++ b/src/c_utils.ml @@ -20,6 +20,7 @@ open Ast int ivars[nt_nb_int]; (or nothing if nt_nb_int = 0) int bvars[nt_nb_bool]; (or nothing if nt_nb_bool = 0) int rvars[nt_nb_real]; (or nothing if nt_nb_real = 0) + bool is_init; } t_state_; *) type node_state = diff --git a/src/cprint.ml b/src/cprint.ml index ab2db08..bbfc952 100644 --- a/src/cprint.ml +++ b/src/cprint.ml @@ -5,9 +5,9 @@ let cp_node_state fmt (st: node_state) = let maybeprint fmt (ty, nb, name): unit = if nb = 0 then () - else Format.fprintf fmt "\n\t%s %s[%d]" ty name nb + else Format.fprintf fmt "\n\t%s %s[%d];" ty name nb in - Format.fprintf fmt "typedef struct {%a%a%a\n} %s;\n\n" + Format.fprintf fmt "typedef struct {%a%a%a\n\tbool is_init;\n} %s;\n\n" maybeprint ("int", st.nt_nb_int, "ivars") maybeprint ("bool", st.nt_nb_bool, "bvars") maybeprint ("double", st.nt_nb_real, "rvars") @@ -58,6 +58,8 @@ let rec cp_prototypes fmt (nodes, h) = (** The ollowing function prints the code to remember previous values of * variables used with the pre construct. *) let cp_prevars fmt (node, h) = + Format.fprintf fmt + "\n\t/* Remember the values of variables used in the [pre] construct */\n"; let node_st = Hashtbl.find h node.n_name in List.iter (fun v -> (** Note that «dst_array = src_array» should hold. *) @@ -68,7 +70,7 @@ let cp_prevars fmt (node, h) = node_st.nt_prevars let rec cp_node fmt (node, h) = - Format.fprintf fmt "%a\n{\nTODO...\n%a}\n" + Format.fprintf fmt "%a\n{\n\t\tTODO...\n\n\tstate->is_init = false;\n%a}\n" cp_prototype (node, h) cp_prevars (node, h) diff --git a/src/test2.node b/src/test2.node index 3598f37..2c60962 100644 --- a/src/test2.node +++ b/src/test2.node @@ -3,11 +3,3 @@ let o1 = 10 -> pre (20 -> 30); tel -node flipflop(i: int) returns (z: int); -var x, y: int; c: bool; -let - c = true fby (not c); - x = 1 on c; - y = 2 on (not c); - z = merge c x y; -tel