Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpouzet committed Oct 31, 2024
1 parent 9a95f2f commit a50f244
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
18 changes: 12 additions & 6 deletions src/compiler/rewrite/aform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ open Ident
open Zelus
open Deftypes

let unbound x =
Misc.internal_error "A-normal form" Ident.fprint_t x

type 'a tree = | Leaf of 'a | Lpar of 'a tree list

(* the type of the accumulator *)
Expand All @@ -40,7 +43,7 @@ let rec matching eq_list ({ pat_desc } as p) ({ e_desc } as e) =
| _ -> (Aux.eq_make p e) :: eq_list

let find { renaming; subst } id =
try Env.find id renaming with | Not_found -> assert false
try Env.find id renaming with | Not_found -> unbound id

let rec make_pat t =
match t with
Expand Down Expand Up @@ -94,7 +97,7 @@ let pattern funs ({ renaming; subst } as acc) ({ pat_desc } as p) =
| Not_found ->
try
make_pat (Env.find x subst)
with | Not_found -> assert false in
with | Not_found -> unbound x in
p, acc
| _ -> raise Mapfold.Fallback

Expand All @@ -107,12 +110,12 @@ let expression funs ({ renaming; subst } as acc) ({ e_desc } as e) =
| Not_found ->
try
make_exp (Env.find x subst)
with | Not_found -> assert false in
with | Not_found -> unbound x in
e, acc
| _ -> raise Mapfold.Fallback

let equation funs acc eq =
let ({ eq_desc } as eq), acc = Mapfold.equation_it funs acc eq in
let ({ eq_desc } as eq), acc = Mapfold.equation funs acc eq in
let eq = match eq_desc with
| EQeq(p, e) ->
Aux.par (matching [] p e)
Expand All @@ -124,9 +127,12 @@ let vardec_list funs ({ renaming; subst } as acc) v_list =
(* default value of combine function, it is not split into a tuple *)
(* but a single name. The code below makes this assumption. *)
let vardec v_list ({ var_name } as v) =
let t = Env.find var_name subst in
let n_list =
try [Env.find var_name renaming]
with Not_found ->
try names [] (Env.find var_name subst) with Not_found -> unbound var_name in
List.fold_left
(fun v_list n -> { v with var_name = n } :: v_list) v_list (names [] t) in
(fun v_list n -> { v with var_name = n } :: v_list) v_list n_list in
List.fold_left vardec [] v_list, acc

let set_index funs acc n =
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/rewrite/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open Error
open Mapfold

let error { kind; loc } =
Format.eprintf "Error during static reduction\n";
Format.eprintf "Error during inlining\n";
Error.message loc kind;
raise Error

Expand Down
25 changes: 13 additions & 12 deletions src/compiler/rewrite/period.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ let period major time phase period =
(* and z = major && (time >= last h) in z] *)
let h = Ident.fresh "h" in
let z = Ident.fresh "z" in
Aux.e_local (Aux.block_make [Aux.vardec h false
(Some(Aux.plus (Aux.var time) phase)) None;
Aux.vardec z false None None]
[Aux.eq_and
(Aux.id_eq h (Aux.horizon
(Aux.ifthenelse (Aux.var z)
(Aux.plus (Aux.last_star h) period)
(Aux.last_star h))))
(Aux.id_eq z (Aux.and_op major
(Aux.greater_or_equal (Aux.var time)
(Aux.last_star z))))])
Aux.e_local
(Aux.block_make [Aux.vardec h false
(Some(Aux.plus (Aux.var time) phase)) None;
Aux.vardec z false None None]
[Aux.eq_and
(Aux.id_eq h (Aux.horizon
(Aux.ifthenelse (Aux.var z)
(Aux.plus (Aux.last_star h) period)
(Aux.last_star h))))
(Aux.id_eq z (Aux.and_op major
(Aux.greater_or_equal (Aux.var time)
(Aux.last_star z))))])
(Aux.var z)

(* Add the extra input parameter "time" for hybrid nodes *)
Expand All @@ -103,7 +104,7 @@ let funexp funs acc ({ f_kind } as f) =
let time, _ = intro acc_local in
{ f with f_args = [Aux.vardec time false None None] :: f_args;
f_env = Env.add time Typinfo.no_ienv f_env }, acc
| _ -> raise Mapfold.Fallback
| _ -> Mapfold.funexp funs acc f

(* add the extra time argument for the application of hybrid nodes *)
let expression funs acc ({ e_desc } as e) =
Expand Down
Binary file removed src/ctests/good/t_3.zci
Binary file not shown.
5 changes: 4 additions & 1 deletion src/ctests/good/t_3.zls
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let node f1 () returns (o)
if true then o = 1 else o = 2

let hybrid f11 (z) returns (o)
der o = 1.0 init 0.0 reset z -> 2.0

let node f2 () returns (o)
o = f1() + f1()

Expand All @@ -10,4 +13,4 @@ let node f3 () returns (o)
| B -> do o = f2 () until false then A
init
if true then B else A
end
end

0 comments on commit a50f244

Please sign in to comment.