Skip to content

Commit a50f244

Browse files
committed
Update
1 parent 9a95f2f commit a50f244

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

src/compiler/rewrite/aform.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ open Ident
2121
open Zelus
2222
open Deftypes
2323

24+
let unbound x =
25+
Misc.internal_error "A-normal form" Ident.fprint_t x
26+
2427
type 'a tree = | Leaf of 'a | Lpar of 'a tree list
2528

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

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

4548
let rec make_pat t =
4649
match t with
@@ -94,7 +97,7 @@ let pattern funs ({ renaming; subst } as acc) ({ pat_desc } as p) =
9497
| Not_found ->
9598
try
9699
make_pat (Env.find x subst)
97-
with | Not_found -> assert false in
100+
with | Not_found -> unbound x in
98101
p, acc
99102
| _ -> raise Mapfold.Fallback
100103

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

114117
let equation funs acc eq =
115-
let ({ eq_desc } as eq), acc = Mapfold.equation_it funs acc eq in
118+
let ({ eq_desc } as eq), acc = Mapfold.equation funs acc eq in
116119
let eq = match eq_desc with
117120
| EQeq(p, e) ->
118121
Aux.par (matching [] p e)
@@ -124,9 +127,12 @@ let vardec_list funs ({ renaming; subst } as acc) v_list =
124127
(* default value of combine function, it is not split into a tuple *)
125128
(* but a single name. The code below makes this assumption. *)
126129
let vardec v_list ({ var_name } as v) =
127-
let t = Env.find var_name subst in
130+
let n_list =
131+
try [Env.find var_name renaming]
132+
with Not_found ->
133+
try names [] (Env.find var_name subst) with Not_found -> unbound var_name in
128134
List.fold_left
129-
(fun v_list n -> { v with var_name = n } :: v_list) v_list (names [] t) in
135+
(fun v_list n -> { v with var_name = n } :: v_list) v_list n_list in
130136
List.fold_left vardec [] v_list, acc
131137

132138
let set_index funs acc n =

src/compiler/rewrite/inline.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open Error
2424
open Mapfold
2525

2626
let error { kind; loc } =
27-
Format.eprintf "Error during static reduction\n";
27+
Format.eprintf "Error during inlining\n";
2828
Error.message loc kind;
2929
raise Error
3030

src/compiler/rewrite/period.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,18 @@ let period major time phase period =
8282
(* and z = major && (time >= last h) in z] *)
8383
let h = Ident.fresh "h" in
8484
let z = Ident.fresh "z" in
85-
Aux.e_local (Aux.block_make [Aux.vardec h false
86-
(Some(Aux.plus (Aux.var time) phase)) None;
87-
Aux.vardec z false None None]
88-
[Aux.eq_and
89-
(Aux.id_eq h (Aux.horizon
90-
(Aux.ifthenelse (Aux.var z)
91-
(Aux.plus (Aux.last_star h) period)
92-
(Aux.last_star h))))
93-
(Aux.id_eq z (Aux.and_op major
94-
(Aux.greater_or_equal (Aux.var time)
95-
(Aux.last_star z))))])
85+
Aux.e_local
86+
(Aux.block_make [Aux.vardec h false
87+
(Some(Aux.plus (Aux.var time) phase)) None;
88+
Aux.vardec z false None None]
89+
[Aux.eq_and
90+
(Aux.id_eq h (Aux.horizon
91+
(Aux.ifthenelse (Aux.var z)
92+
(Aux.plus (Aux.last_star h) period)
93+
(Aux.last_star h))))
94+
(Aux.id_eq z (Aux.and_op major
95+
(Aux.greater_or_equal (Aux.var time)
96+
(Aux.last_star z))))])
9697
(Aux.var z)
9798

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

108109
(* add the extra time argument for the application of hybrid nodes *)
109110
let expression funs acc ({ e_desc } as e) =

src/ctests/good/t_3.zci

-391 Bytes
Binary file not shown.

src/ctests/good/t_3.zls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
let node f1 () returns (o)
22
if true then o = 1 else o = 2
33

4+
let hybrid f11 (z) returns (o)
5+
der o = 1.0 init 0.0 reset z -> 2.0
6+
47
let node f2 () returns (o)
58
o = f1() + f1()
69

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

0 commit comments

Comments
 (0)