2 <link rel=
"stylesheet" href=
"style.css" type=
"text/css">
3 <meta content=
"text/html; charset=iso-8859-1" http-equiv=
"Content-Type">
4 <link rel=
"Start" href=
"index.html">
5 <link title=
"Index of types" rel=Appendix
href=
"index_types.html">
6 <link title=
"Index of exceptions" rel=Appendix
href=
"index_exceptions.html">
7 <link title=
"Index of values" rel=Appendix
href=
"index_values.html">
8 <link title=
"Index of modules" rel=Appendix
href=
"index_modules.html">
9 <link title=
"Types" rel=
"Chapter" href=
"Types.html">
10 <link title=
"Value" rel=
"Chapter" href=
"Value.html">
11 <link title=
"Signal" rel=
"Chapter" href=
"Signal.html">
12 <link title=
"Faustexp" rel=
"Chapter" href=
"Faustexp.html">
13 <link title=
"Interpreter" rel=
"Chapter" href=
"Interpreter.html">
14 <link title=
"Main" rel=
"Chapter" href=
"Main.html"><title>Interpreter.interpreter_rec
</title>
17 <code class=
"code"><span class=
"keyword">let
</span> <span class=
"keyword">rec
</span> interpreter_rec
exp_faust
dimension_tree
input_beam
=
<br>
20 </code><table><tr><td></td><td><span class=
"comment">(** val interpret_par : faust_exp -
> faust_exp -
> beam -
> beam,
21 interprets par(e1, e2) with input beam, produces output beam.*)
</span></td></tr></table><code class=
"code"><br>
22 <span class=
"keyword">let
</span> interpret_par
=
<span class=
"keyword">fun
</span> e1
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> e2
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> dimension_tree
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> input_beam
<span class=
"keywordsign">-
></span><br>
23 <span class=
"keyword">let
</span> n
=
<span class=
"constructor">List
</span>.length
input_beam
<span class=
"keyword">in
</span><br>
24 <span class=
"keyword">let
</span> subtree1
=
subtree_left
dimension_tree
<span class=
"keyword">in
</span><br>
25 <span class=
"keyword">let
</span> subtree2
=
subtree_right
dimension_tree
<span class=
"keyword">in
</span><br>
26 <span class=
"keyword">let
</span> d1
=
get_root
subtree1
<span class=
"keyword">in
</span><br>
27 <span class=
"keyword">let
</span> d2
=
get_root
subtree2
<span class=
"keyword">in
</span><br>
28 <span class=
"keyword">if
</span> n
=
(fst
d1)
+
(fst
d2)
<span class=
"keyword">then
</span> <br>
29 (
<br>
30 <span class=
"keyword">let
</span> input_beam1
=
sublist
input_beam
0 (fst
d1)
<span class=
"keyword">in
</span><br>
31 <span class=
"keyword">let
</span> input_beam2
=
sublist
input_beam
(fst
d1)
(fst
d2)
<span class=
"keyword">in
</span><br>
32 <span class=
"keyword">let
</span> output_beam1
=
interpreter_rec
e1
subtree1
input_beam1
<span class=
"keyword">in
</span><br>
33 <span class=
"keyword">let
</span> output_beam2
=
interpreter_rec
e2
subtree2
input_beam2
<span class=
"keyword">in
</span><br>
34 <span class=
"keyword">if
</span> <span class=
"constructor">List
</span>.length
output_beam1
=
snd
d1
<span class=
"keywordsign">&&</span> <span class=
"constructor">List
</span>.length
output_beam2
=
snd
d2
<br>
35 <span class=
"keyword">then
</span> (output_beam1
@
output_beam2)
<br>
36 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Par"</span>)
<br>
37 )
<br>
38 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Par"</span>)
<span class=
"keyword">in
</span><br>
41 </code><table><tr><td></td><td><span class=
"comment">(** val interpret_seq : faust_exp -
> faust_exp -
> beam -
> beam,
42 interprets seq(e1, e2) with input beam, produces output beam.*)
</span></td></tr></table><code class=
"code"><br>
43 <span class=
"keyword">let
</span> interpret_seq
=
<span class=
"keyword">fun
</span> e1
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> e2
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> dimension_tree
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> input_beam
<span class=
"keywordsign">-
></span><br>
44 <span class=
"keyword">let
</span> n
=
<span class=
"constructor">List
</span>.length
input_beam
<span class=
"keyword">in
</span><br>
45 <span class=
"keyword">let
</span> subtree1
=
subtree_left
dimension_tree
<span class=
"keyword">in
</span><br>
46 <span class=
"keyword">let
</span> subtree2
=
subtree_right
dimension_tree
<span class=
"keyword">in
</span><br>
47 <span class=
"keyword">let
</span> d1
=
get_root
subtree1
<span class=
"keyword">in
</span><br>
48 <span class=
"keyword">let
</span> d2
=
get_root
subtree2
<span class=
"keyword">in
</span><br>
49 <span class=
"keyword">if
</span> n
=
fst
d1
<span class=
"keyword">then
</span><br>
50 (
<br>
51 <span class=
"keyword">let
</span> output_beam1
=
interpreter_rec
e1
subtree1
input_beam
<span class=
"keyword">in
</span><br>
52 <span class=
"keyword">if
</span> <span class=
"constructor">List
</span>.length
output_beam1
=
fst
d2
<br>
53 <span class=
"keyword">then
</span> interpreter_rec
e2
subtree2
output_beam1
<br>
54 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Seq"</span>)
<br>
55 )
<br>
56 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Seq"</span>)
<span class=
"keyword">in
</span><br>
59 </code><table><tr><td></td><td><span class=
"comment">(** val interpret_split : faust_exp -
> faust_exp -
> beam -
> beam,
60 interprets split(e1, e2) with input beam, produces output beam.*)
</span></td></tr></table><code class=
"code"><br>
61 <span class=
"keyword">let
</span> interpret_split
=
<span class=
"keyword">fun
</span> e1
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> e2
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> dimension_tree
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> input_beam
<span class=
"keywordsign">-
></span><br>
62 <span class=
"keyword">let
</span> n
=
<span class=
"constructor">List
</span>.length
input_beam
<span class=
"keyword">in
</span><br>
63 <span class=
"keyword">let
</span> subtree1
=
subtree_left
dimension_tree
<span class=
"keyword">in
</span><br>
64 <span class=
"keyword">let
</span> subtree2
=
subtree_right
dimension_tree
<span class=
"keyword">in
</span><br>
65 <span class=
"keyword">let
</span> d1
=
get_root
subtree1
<span class=
"keyword">in
</span><br>
66 <span class=
"keyword">let
</span> d2
=
get_root
subtree2
<span class=
"keyword">in
</span><br>
67 <span class=
"keyword">if
</span> n
=
fst
d1
<span class=
"keyword">then
</span><br>
68 (
<br>
69 <span class=
"keyword">let
</span> output_beam1
=
interpreter_rec
e1
subtree1
input_beam
<span class=
"keyword">in
</span><br>
70 <span class=
"keyword">let
</span> ref_output_beam1
=
ref
(beam_add_one_memory
output_beam1)
<span class=
"keyword">in
</span><br>
71 <span class=
"keyword">let
</span> input_beam2
=
<span class=
"constructor">List
</span>.concat
<br>
72 (
<span class=
"constructor">Array
</span>.to_list
(
<span class=
"constructor">Array
</span>.make
((fst
d2)/(
<span class=
"constructor">List
</span>.length
output_beam1))
!ref_output_beam1))
<br>
73 <span class=
"keyword">in
</span><br>
74 <span class=
"keyword">if
</span> <span class=
"constructor">List
</span>.length
input_beam2
=
fst
d2
<br>
75 <span class=
"keyword">then
</span> interpreter_rec
e2
subtree2
input_beam2
<br>
76 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Split"</span>)
<br>
77 )
<br>
78 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Split"</span>)
<span class=
"keyword">in
</span><br>
81 </code><table><tr><td></td><td><span class=
"comment">(** val interpret_merge : faust_exp -
> faust_exp -
> beam -
> beam,
82 interprets merge(e1, e2) with input beam, produces output beam.*)
</span></td></tr></table><code class=
"code"><br>
83 <span class=
"keyword">let
</span> interpret_merge
=
<span class=
"keyword">fun
</span> e1
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> e2
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> dimension_tree
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> input_beam
<span class=
"keywordsign">-
></span><br>
84 <span class=
"keyword">let
</span> n
=
<span class=
"constructor">List
</span>.length
input_beam
<span class=
"keyword">in
</span><br>
85 <span class=
"keyword">let
</span> subtree1
=
subtree_left
dimension_tree
<span class=
"keyword">in
</span><br>
86 <span class=
"keyword">let
</span> subtree2
=
subtree_right
dimension_tree
<span class=
"keyword">in
</span><br>
87 <span class=
"keyword">let
</span> d1
=
get_root
subtree1
<span class=
"keyword">in
</span><br>
88 <span class=
"keyword">let
</span> d2
=
get_root
subtree2
<span class=
"keyword">in
</span><br>
89 <span class=
"keyword">if
</span> n
=
fst
d1
<span class=
"keyword">then
</span><br>
90 (
<br>
91 <span class=
"keyword">let
</span> output_beam1
=
interpreter_rec
e1
subtree1
input_beam
<span class=
"keyword">in
</span><br>
92 <span class=
"keyword">let
</span> input_beam2
=
<br>
93 (
<br>
94 <span class=
"keyword">let
</span> fois
=
(snd
d1)/(fst
d2)
<span class=
"keyword">in
</span><br>
95 <span class=
"keyword">let
</span> ref_beam
=
ref
(sublist
output_beam1
0 (fst
d2))
<span class=
"keyword">in
</span><br>
96 <span class=
"keyword">for
</span> i
=
1 <span class=
"keyword">to
</span> fois
-
1 <span class=
"keyword">do
</span><br>
97 <span class=
"keyword">let
</span> temp_beam
=
sublist
output_beam1
(i*(fst
d2))
(fst
d2)
<span class=
"keyword">in
</span><br>
98 ref_beam
:=
<span class=
"constructor">List
</span>.map2
signal_add
(!ref_beam)
temp_beam;
<br>
99 <span class=
"keyword">done
</span>;
<br>
100 !ref_beam
<br>
101 )
<br>
102 <span class=
"keyword">in
</span><br>
103 <span class=
"keyword">if
</span> <span class=
"constructor">List
</span>.length
input_beam2
=
fst
d2
<br>
104 <span class=
"keyword">then
</span> interpreter_rec
e2
subtree2
input_beam2
<br>
105 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Merge"</span>)
<br>
106 )
<br>
107 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Merge"</span>)
<span class=
"keyword">in
</span><br>
110 </code><table><tr><td></td><td><span class=
"comment">(** val interpret_rec : faust_exp -
> faust_exp -
> beam -
> beam,
111 interprets rec(e1, e2) with input beam, produces output beam.*)
</span></td></tr></table><code class=
"code"><br>
112 <span class=
"keyword">let
</span> interpret_rec
=
<span class=
"keyword">fun
</span> e1
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> e2
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> dimension_tree
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> input_beam
<span class=
"keywordsign">-
></span><br>
113 <span class=
"keyword">let
</span> n
=
<span class=
"constructor">List
</span>.length
input_beam
<span class=
"keyword">in
</span><br>
114 <span class=
"keyword">let
</span> subtree1
=
subtree_left
dimension_tree
<span class=
"keyword">in
</span><br>
115 <span class=
"keyword">let
</span> subtree2
=
subtree_right
dimension_tree
<span class=
"keyword">in
</span><br>
116 <span class=
"keyword">let
</span> d1
=
get_root
subtree1
<span class=
"keyword">in
</span><br>
117 <span class=
"keyword">let
</span> d2
=
get_root
subtree2
<span class=
"keyword">in
</span><br>
118 <span class=
"keyword">if
</span> n
=
(fst
d1)
-
(snd
d2)
<span class=
"keyword">then
</span><br>
119 (
<br>
120 <span class=
"keyword">let
</span> aux1
=
<span class=
"keyword">fun
</span> t
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> f
<span class=
"keywordsign">-
></span> f
t
<span class=
"keyword">in
</span><br>
121 <span class=
"keyword">let
</span> aux2
=
<span class=
"keyword">fun
</span> beam_fun
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> i
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> t
<span class=
"keywordsign">-
></span> <span class=
"constructor">List
</span>.nth
(snd
(beam_fun
t))
i
<span class=
"keyword">in
</span><br>
122 <span class=
"keyword">let
</span> aux3
=
<span class=
"keyword">fun
</span> beam_fun
<span class=
"keywordsign">-
></span> <span class=
"constructor">List
</span>.map
<br>
123 (aux2
beam_fun)
<br>
124 (
<span class=
"constructor">Array
</span>.to_list
(
<span class=
"constructor">Array
</span>.init
(snd
d1)
(
<span class=
"keyword">fun
</span> n
<span class=
"keywordsign">-
></span> n)))
<br>
125 <span class=
"keyword">in
</span><br>
126 <span class=
"keyword">let
</span> make_signal
=
<span class=
"keyword">fun
</span> rate
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> f
<span class=
"keywordsign">-
></span> (rate,
f)
<span class=
"keyword">in
</span><br>
127 <span class=
"keyword">let
</span> delay_int
=
1 +
delay
e2
+
delay
e1
<span class=
"keyword">in
</span><br>
128 <span class=
"keyword">let
</span> memory_hashtbl
=
<span class=
"constructor">Hashtbl
</span>.create
delay_int
<span class=
"keyword">in
</span><br>
129 <span class=
"keyword">let
</span> rate_list
=
ref
(
<span class=
"constructor">Array
</span>.to_list
(
<span class=
"constructor">Array
</span>.make
(snd
d1)
0))
<span class=
"keyword">in
</span><br>
130 <span class=
"keyword">let
</span> <span class=
"keyword">rec
</span> output_beam_fun
=
<span class=
"keyword">fun
</span> t
<span class=
"keywordsign">-
></span><br>
131 <span class=
"keyword">if
</span> t
< 0 <span class=
"keyword">then
</span><br>
132 <span class=
"keyword">let
</span> init_rate_list
=
<span class=
"constructor">Array
</span>.to_list
(
<span class=
"constructor">Array
</span>.make
(snd
d1)
0)
<span class=
"keyword">in
</span><br>
133 <span class=
"keyword">let
</span> value_list
=
<span class=
"constructor">Array
</span>.to_list
(
<span class=
"constructor">Array
</span>.make
(snd
d1)
<span class=
"constructor">Zero
</span>)
<span class=
"keyword">in
</span><br>
134 (init_rate_list,
value_list)
<br>
135 <span class=
"keyword">else
</span> <span class=
"keyword">if
</span> <span class=
"constructor">Hashtbl
</span>.mem
memory_hashtbl
t
<span class=
"keyword">then
</span> <br>
136 (!rate_list,
<span class=
"constructor">Hashtbl
</span>.find
memory_hashtbl
t)
<br>
137 <span class=
"keyword">else
</span> <br>
138 <span class=
"keyword">let
</span> mid_output_fun_list1
=
aux3
output_beam_fun
<span class=
"keyword">in
</span> <span class=
"comment">(*
danger!
*)
</span><br>
139 <span class=
"keyword">let
</span> b_input_fun_list
=
<span class=
"constructor">List
</span>.map
<br>
140 (
<span class=
"keyword">fun
</span> s
<span class=
"keywordsign">-
></span> <span class=
"keyword">fun
</span> t
<span class=
"keywordsign">-
></span> s
(t
-
1))
<br>
141 (sublist
mid_output_fun_list1
0 (fst
d2))
<br>
142 <span class=
"keyword">in
</span><br>
143 <span class=
"keyword">let
</span> b_input_beam
=
<span class=
"constructor">List
</span>.map2
make_signal
!rate_list
b_input_fun_list
<span class=
"keyword">in
</span><br>
144 <span class=
"keyword">let
</span> b_output_beam
=
(interpreter_rec
e2
subtree2
b_input_beam)
<span class=
"keyword">in
</span><br>
145 <span class=
"keyword">let
</span> a_input_beam
=
b_output_beam
@
input_beam
<span class=
"keyword">in
</span><br>
146 <span class=
"keyword">let
</span> mid_output_beam2
=
interpreter_rec
e1
subtree1
a_input_beam
<span class=
"keyword">in
</span><br>
147 <span class=
"keyword">let
</span> mid_output_rate_list
=
<span class=
"constructor">List
</span>.map
fst
mid_output_beam2
<span class=
"keyword">in
</span><br>
148 <span class=
"keyword">let
</span> mid_output_value_list
=
<span class=
"constructor">List
</span>.map
(aux1
t)
(
<span class=
"constructor">List
</span>.map
snd
mid_output_beam2)
<span class=
"keyword">in
</span><br>
149 <span class=
"keyword">let
</span> ()
=
(rate_list
:=
mid_output_rate_list)
<span class=
"keyword">in
</span><br>
150 <span class=
"keyword">let
</span> mid_output_value_list_for_stock
=
v_list_memory
mid_output_value_list
<span class=
"keyword">in
</span><br>
151 <span class=
"keyword">let
</span> ()
=
<span class=
"constructor">Hashtbl
</span>.add
memory_hashtbl
t
mid_output_value_list_for_stock
<span class=
"keyword">in
</span><br>
152 <span class=
"keyword">let
</span> ()
=
<span class=
"constructor">Hashtbl
</span>.remove
memory_hashtbl
(t
-
delay_int)
<span class=
"keyword">in
</span><br>
153 (mid_output_rate_list,
mid_output_value_list_for_stock)
<br>
154 <span class=
"keyword">in
</span><br>
155 <span class=
"keyword">let
</span> output_beam
=
<span class=
"constructor">List
</span>.map2
make_signal
!rate_list
(aux3
output_beam_fun)
<span class=
"keyword">in
</span><br>
156 output_beam
<br>
157 )
<br>
158 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Evaluation_Error
</span> <span class=
"string">"Rec1"</span>)
<span class=
"keyword">in
</span><br>
161 </code><table><tr><td> </td><td><span class=
"comment">(** Call for previous functions *)
</span></td></tr></table><code class=
"code"><br>
162 <span class=
"keyword">match
</span> exp_faust
<span class=
"keyword">with
</span><br>
163 <span class=
"keywordsign">|
</span><span class=
"constructor">Const
</span> v
<span class=
"keywordsign">-
></span> interpret_const
v
input_beam
<br>
164 <span class=
"keywordsign">|
</span><span class=
"constructor">Ident
</span> s
<span class=
"keywordsign">-
></span> interpret_ident
s
input_beam
<br>
165 <span class=
"keywordsign">|
</span><span class=
"constructor">Par
</span> (e1,
e2)
<span class=
"keywordsign">-
></span> interpret_par
e1
e2
dimension_tree
input_beam
<br>
166 <span class=
"keywordsign">|
</span><span class=
"constructor">Seq
</span> (e1,
e2)
<span class=
"keywordsign">-
></span> interpret_seq
e1
e2
dimension_tree
input_beam
<br>
167 <span class=
"keywordsign">|
</span><span class=
"constructor">Split
</span> (e1,
e2)
<span class=
"keywordsign">-
></span> interpret_split
e1
e2
dimension_tree
input_beam
<br>
168 <span class=
"keywordsign">|
</span><span class=
"constructor">Merge
</span> (e1,
e2)
<span class=
"keywordsign">-
></span> interpret_merge
e1
e2
dimension_tree
input_beam
<br>
169 <span class=
"keywordsign">|
</span><span class=
"constructor">Rec
</span> (e1,
e2)
<span class=
"keywordsign">-
></span> interpret_rec
e1
e2
dimension_tree
input_beam
</code></body></html>