FAUST compiler  0.9.9.6b8
boxes.hh
Go to the documentation of this file.
1 #ifndef _BOXES_
2 #define _BOXES_
3 
4 /************************************************************************
5  ************************************************************************
6  FAUST compiler
7  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
8  ---------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  ************************************************************************
23  ************************************************************************/
24 
25 
26 
27 /*****************************************************************************
28 ******************************************************************************
29  FAUST BOX ALGEBRA
30  Y. Orlarey, (c) Grame 2002
31 ------------------------------------------------------------------------------
32 box ::= i | f | p0 | p1 | p3
33  | _ | ! | a:b | a<:b | a,b | a:>b | a~b
34 
35  History :
36  ---------
37  2002-06-06 : First version
38 
39 ******************************************************************************
40 *****************************************************************************/
41 
42 #include "tlib.hh"
43 #include "signals.hh"
44 
45 struct Automaton;
46 
47 /*****************************************************************************
48 ******************************************************************************
49 
50  The Box Language
51 
52 ******************************************************************************
53 *****************************************************************************/
54 
55 
56 /*****************************************************************************
57  Identifiers
58 *****************************************************************************/
59 
60 Tree boxIdent(const char* name);
61 bool isBoxIdent(Tree t);
62 bool isBoxIdent(Tree t, const char** name);
63 
64 
65 /*****************************************************************************
66  Numbers
67 *****************************************************************************/
68 
69 Tree boxInt(int n);
70 Tree boxReal(double n);
71 
72 bool isBoxInt(Tree t);
73 bool isBoxReal(Tree t);
74 
75 bool isBoxInt(Tree t, int* i);
76 bool isBoxReal(Tree t, double* r);
77 
78 
79 /*****************************************************************************
80  Waveform
81  waveform {1,2,3,...}
82  an object with 2 outputs : the size of the waveform, the actual waveform.
83  A Waveform is in is all its values are int. It is float otherwise.
84 *****************************************************************************/
85 
86 Tree boxWaveform(const tvec& br);
87 bool isBoxWaveform(Tree t);
88 
89 /*****************************************************************************
90  Wire and Cut
91 *****************************************************************************/
92 
93 Tree boxWire();
94 Tree boxCut();
95 
96 bool isBoxWire(Tree t);
97 bool isBoxCut(Tree t);
98 
99 
100 /*****************************************************************************
101  Symbolic Boxes with symbolic slots
102 *****************************************************************************/
103 
104 Tree boxSlot(int id);
105 Tree boxSymbolic(Tree slot, Tree body);
106 
107 bool isBoxSlot(Tree t);
108 bool isBoxSymbolic(Tree t);
109 
110 bool isBoxSlot(Tree t, int* id);
111 bool isBoxSymbolic(Tree t, Tree& slot, Tree& body);
112 
113 
114 /*****************************************************************************
115  Composition of Boxes
116 *****************************************************************************/
117 
118 Tree boxSeq (Tree x, Tree y);
119 Tree boxPar (Tree x, Tree y);
120 Tree boxRec (Tree x, Tree y);
121 Tree boxSplit (Tree x, Tree y);
122 Tree boxMerge (Tree x, Tree y);
123 
124 bool isBoxSeq (Tree t, Tree& x, Tree& y);
125 bool isBoxPar (Tree t, Tree& x, Tree& y);
126 bool isBoxRec (Tree t, Tree& x, Tree& y);
127 bool isBoxSplit (Tree t, Tree& x, Tree& y);
128 bool isBoxMerge (Tree t, Tree& x, Tree& y);
129 
130 /*****************************************************************************
131  Algorithmic Composition of Boxes
132 *****************************************************************************/
133 
134 Tree boxIPar(Tree x, Tree y, Tree z);
135 Tree boxISeq(Tree x, Tree y, Tree z);
136 Tree boxISum(Tree x, Tree y, Tree z);
137 Tree boxIProd(Tree x, Tree y, Tree z);
138 
139 bool isBoxIPar(Tree t, Tree& x, Tree& y, Tree& z);
140 bool isBoxISeq(Tree t, Tree& x, Tree& y, Tree& z);
141 bool isBoxISum(Tree t, Tree& x, Tree& y, Tree& z);
142 bool isBoxIProd(Tree t, Tree& x, Tree& y, Tree& z);
143 
144 
145 /*****************************************************************************
146  Static information on Boxes
147 *****************************************************************************/
148 
149 Tree boxInputs (Tree x);
150 Tree boxOutputs (Tree x);
151 
152 bool isBoxInputs (Tree t, Tree& x);
153 bool isBoxOutputs (Tree t, Tree& x);
154 
155 
156 /*****************************************************************************
157  Lambda-Calculus of Boxes
158 *****************************************************************************/
159 
160 Tree buildBoxAbstr (Tree x, Tree y);
161 Tree buildBoxAppl (Tree x, Tree y);
162 
163 Tree boxAbstr (Tree x, Tree y);
164 Tree boxAppl (Tree x, Tree y);
165 
166 bool isBoxAbstr (Tree t);
167 bool isBoxAppl (Tree t);
168 
169 bool isBoxAbstr (Tree t, Tree& x, Tree& y);
170 bool isBoxAppl (Tree t, Tree& x, Tree& y);
171 
172 Tree closure (Tree abstr, Tree genv, Tree vis, Tree lenv);
173 
174 bool isClosure (Tree t, Tree& abstr, Tree& genv, Tree& vis, Tree& lenv);
175 
176 // for foo(x,y).faa expressions
177 Tree boxAccess (Tree exp, Tree id);
178 bool isBoxAccess(Tree t, Tree& exp, Tree& id);
179 
180 
181 /*****************************************************************************
182  Boxes with local definitions
183 *****************************************************************************/
184 
185 Tree boxWithLocalDef (Tree body, Tree ldef);
186 bool isBoxWithLocalDef (Tree t, Tree& body, Tree& ldef);
187 
188 
189 /*****************************************************************************
190  Modification of local definitions
191 *****************************************************************************/
192 
193 Tree boxModifLocalDef (Tree body, Tree ldef);
194 bool isBoxModifLocalDef (Tree t, Tree& body, Tree& ldef);
195 
196 
197 /*****************************************************************************
198  Error Boxe
199 *****************************************************************************/
200 
201 Tree boxError();
202 bool isBoxError(Tree t);
203 
204 /*****************************************************************************
205  Primitive Boxes (n -> 1)
206 *****************************************************************************/
207 
208 typedef Tree (*prim0)();
209 typedef Tree (*prim1)(Tree x);
210 typedef Tree (*prim2)(Tree x, Tree y);
211 typedef Tree (*prim3)(Tree x, Tree y, Tree z);
212 typedef Tree (*prim4)(Tree w, Tree x, Tree y, Tree z);
213 typedef Tree (*prim5)(Tree v, Tree w, Tree x, Tree y, Tree z);
214 
215 Tree boxPrim0 (prim0 foo);
216 Tree boxPrim1 (prim1 foo);
217 Tree boxPrim2 (prim2 foo);
218 Tree boxPrim3 (prim3 foo);
219 Tree boxPrim4 (prim4 foo);
220 Tree boxPrim5 (prim5 foo);
221 
222 bool isBoxPrim0 (Tree s);
223 bool isBoxPrim1 (Tree s);
224 bool isBoxPrim2 (Tree s);
225 bool isBoxPrim3 (Tree s);
226 bool isBoxPrim4 (Tree s);
227 bool isBoxPrim5 (Tree s);
228 
229 bool isBoxPrim0 (Tree s, prim0* p);
230 bool isBoxPrim1 (Tree s, prim1* p);
231 bool isBoxPrim2 (Tree s, prim2* p);
232 bool isBoxPrim3 (Tree s, prim3* p);
233 bool isBoxPrim4 (Tree s, prim4* p);
234 bool isBoxPrim5 (Tree s, prim5* p);
235 
236 
237 /*****************************************************************************
238  Foreign Functions
239 *****************************************************************************/
240 
241 Tree boxFFun (Tree ff);
242 bool isBoxFFun (Tree s);
243 bool isBoxFFun (Tree s, Tree& ff);
244 
245 
246 Tree boxFConst (Tree type, Tree name, Tree file);
247 bool isBoxFConst (Tree s);
248 bool isBoxFConst (Tree s, Tree& type, Tree& name, Tree& file);
249 
250 
251 Tree boxFVar (Tree type, Tree name, Tree file);
252 bool isBoxFVar (Tree s);
253 bool isBoxFVar (Tree s, Tree& type, Tree& name, Tree& file);
254 
255 
256 /*****************************************************************************
257  Modules
258 *****************************************************************************/
259 
261 bool isBoxEnvironment (Tree s);
262 
263 Tree boxComponent (Tree filename);
264 bool isBoxComponent (Tree s, Tree& filename);
265 
266 Tree boxLibrary (Tree filename);
267 bool isBoxLibrary (Tree s, Tree& filename);
268 
269 Tree importFile(Tree filename);
270 bool isImportFile(Tree s, Tree& filename);
271 
272 
273 /*****************************************************************************
274  User Interface Elements
275 *****************************************************************************/
276 
277 Tree boxButton (Tree label);
278 bool isBoxButton (Tree s);
279 bool isBoxButton (Tree s, Tree& label);
280 
281 Tree boxCheckbox (Tree label);
282 bool isBoxCheckbox (Tree s);
283 bool isBoxCheckbox (Tree s, Tree& label);
284 
285 Tree boxVSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
286 bool isBoxVSlider (Tree s);
287 bool isBoxVSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
288 
289 Tree boxHSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
290 bool isBoxHSlider (Tree s);
291 bool isBoxHSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
292 
293 Tree boxNumEntry (Tree label, Tree cur, Tree min, Tree max, Tree step);
294 bool isBoxNumEntry (Tree s);
295 bool isBoxNumEntry (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
296 
297 Tree boxVGroup (Tree label, Tree x);
298 bool isBoxVGroup (Tree s);
299 bool isBoxVGroup (Tree s, Tree& label, Tree& x);
300 
301 Tree boxHGroup (Tree label, Tree x);
302 bool isBoxHGroup (Tree s);
303 bool isBoxHGroup (Tree s, Tree& label, Tree& x);
304 
305 Tree boxTGroup (Tree label, Tree x);
306 bool isBoxTGroup (Tree s);
307 bool isBoxTGroup (Tree s, Tree& label, Tree& x);
308 
309 // GUI outputs
310 Tree boxVBargraph (Tree label, Tree min, Tree max);
311 bool isBoxVBargraph (Tree s);
312 bool isBoxVBargraph (Tree s, Tree& label, Tree& min, Tree& max);
313 
314 Tree boxHBargraph (Tree label, Tree min, Tree max);
315 bool isBoxHBargraph (Tree s);
316 bool isBoxHBargraph (Tree s, Tree& label, Tree& min, Tree& max);
317 
318 
319 /*****************************************************************************
320  case (pattern matching)
321 *****************************************************************************/
323 bool isBoxCase (Tree s);
324 bool isBoxCase (Tree s, Tree& rules);
325 
326 Tree boxPatternMatcher (Automaton* a, int state, Tree env, Tree origRules, Tree revParamList);
327 bool isBoxPatternMatcher (Tree s);
328 bool isBoxPatternMatcher (Tree s, Automaton*& a, int& state, Tree& env, Tree& origRules, Tree& revParamList);
329 
330 // wrap an id into a pattern variable
331 Tree boxPatternVar (Tree id);
332 bool isBoxPatternVar(Tree s, Tree& id);
333 
334 
335 /*****************************************************************************
336 ******************************************************************************
337 
338  Box Algorithms
339 
340 ******************************************************************************
341 *****************************************************************************/
342 
343 // return the number of input
344 bool getBoxType (Tree box, int* inum, int* onum);
345 
346 
347 #endif
Tree(* prim2)(Tree x, Tree y)
Definition: boxes.hh:210
bool isBoxAppl(Tree t)
Definition: boxes.cpp:203
Tree boxPrim3(prim3 foo)
Definition: boxes.cpp:324
Tree boxISum(Tree x, Tree y, Tree z)
Definition: boxes.cpp:166
bool isBoxWire(Tree t)
Definition: boxes.cpp:109
bool isBoxModifLocalDef(Tree t, Tree &body, Tree &ldef)
Definition: boxes.cpp:275
bool isBoxComponent(Tree s, Tree &filename)
Definition: boxes.cpp:290
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxWaveform(Tree t)
Definition: boxes.cpp:97
Tree boxPatternVar(Tree id)
Definition: boxes.cpp:621
Tree boxIdent(const char *name)
Definition: boxes.cpp:57
Tree boxIPar(Tree x, Tree y, Tree z)
Definition: boxes.cpp:164
bool isBoxPrim4(Tree s)
Definition: boxes.cpp:330
Tree boxSplit(Tree x, Tree y)
Definition: boxes.cpp:147
CTree * Tree
Definition: tree.hh:86
bool isBoxError(Tree t)
Definition: boxes.cpp:249
bool isBoxPatternVar(Tree s, Tree &id)
Definition: boxes.cpp:622
Tree boxLibrary(Tree filename)
Definition: boxes.cpp:294
Tree(* prim4)(Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:212
vector< Tree > tvec
Definition: tree.hh:90
bool isImportFile(Tree s, Tree &filename)
Definition: boxes.cpp:301
Tree boxError()
Definition: boxes.cpp:244
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isBoxSymbolic(Tree t)
Definition: boxes.cpp:126
Tree boxAbstr(Tree x, Tree y)
Definition: boxes.cpp:199
Tree boxTGroup(Tree label, Tree x)
Definition: boxes.cpp:448
Tree boxRec(Tree x, Tree y)
Definition: boxes.cpp:143
Tree boxIProd(Tree x, Tree y, Tree z)
Definition: boxes.cpp:167
bool isBoxVGroup(Tree s)
Definition: boxes.cpp:443
bool isBoxNumEntry(Tree s)
Definition: boxes.cpp:418
Tree boxMerge(Tree x, Tree y)
Definition: boxes.cpp:151
bool isBoxISum(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:171
Tree boxHSlider(Tree label, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:377
bool isBoxVBargraph(Tree s)
Definition: boxes.cpp:461
Tree boxButton(Tree label)
Definition: boxes.cpp:365
double max(double x, double y)
Definition: interval.hh:60
Tree boxCut()
Definition: boxes.cpp:104
bool isBoxIProd(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:172
bool isBoxHGroup(Tree s)
Definition: boxes.cpp:437
Tree(* prim3)(Tree x, Tree y, Tree z)
Definition: boxes.hh:211
bool isBoxButton(Tree s)
Definition: boxes.cpp:366
Tree boxHBargraph(Tree label, Tree min, Tree max)
Definition: boxes.cpp:454
Tree boxPrim4(prim4 foo)
Definition: boxes.cpp:329
Tree(* prim5)(Tree v, Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:213
bool isBoxWithLocalDef(Tree t, Tree &body, Tree &ldef)
Definition: boxes.cpp:265
Tree boxInt(int n)
Definition: boxes.cpp:75
bool isBoxPrim5(Tree s)
Definition: boxes.cpp:335
Tree boxCheckbox(Tree label)
Definition: boxes.cpp:371
Tree boxSlot(int id)
Definition: boxes.cpp:118
vector< State * > state
Tree(* prim1)(Tree x)
Definition: boxes.hh:209
bool isBoxCheckbox(Tree s)
Definition: boxes.cpp:372
Tree boxHGroup(Tree label, Tree x)
Definition: boxes.cpp:436
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
bool isBoxPrim2(Tree s)
Definition: boxes.cpp:320
bool isBoxVSlider(Tree s)
Definition: boxes.cpp:399
Tree boxWithLocalDef(Tree body, Tree ldef)
Definition: boxes.cpp:264
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
Tree boxPrim0(prim0 foo)
Definition: boxes.cpp:309
Tree boxReal(double n)
Definition: boxes.cpp:76
bool isBoxFVar(Tree s)
Definition: boxes.cpp:356
Tree boxISeq(Tree x, Tree y, Tree z)
Definition: boxes.cpp:165
Tree boxAccess(Tree exp, Tree id)
Definition: boxes.cpp:255
Tree buildBoxAbstr(Tree x, Tree y)
Definition: boxes.cpp:208
Tree boxNumEntry(Tree label, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:416
bool isBoxPrim0(Tree s)
Definition: boxes.cpp:310
bool isBoxFFun(Tree s)
Definition: boxes.cpp:344
Tree boxModifLocalDef(Tree body, Tree ldef)
Definition: boxes.cpp:274
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139
Tree boxOutputs(Tree x)
Definition: boxes.cpp:183
bool isBoxIPar(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:169
Tree boxFConst(Tree type, Tree name, Tree file)
Definition: boxes.cpp:349
Tree boxVGroup(Tree label, Tree x)
Definition: boxes.cpp:442
bool isBoxPrim3(Tree s)
Definition: boxes.cpp:325
Tree boxSymbolic(Tree slot, Tree body)
Definition: boxes.cpp:125
bool isBoxAccess(Tree t, Tree &exp, Tree &id)
Definition: boxes.cpp:256
bool isBoxISeq(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:170
Tree buildBoxAppl(Tree x, Tree y)
Definition: boxes.cpp:227
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree boxVSlider(Tree label, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:397
bool isBoxAbstr(Tree t)
Definition: boxes.cpp:202
Tree boxFVar(Tree type, Tree name, Tree file)
Definition: boxes.cpp:355
bool isBoxLibrary(Tree s, Tree &filename)
Definition: boxes.cpp:295
Tree boxWire()
Definition: boxes.cpp:108
bool isBoxOutputs(Tree t, Tree &x)
Definition: boxes.cpp:186
Tree importFile(Tree filename)
Definition: boxes.cpp:300
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
Definition: boxes.cpp:239
bool isBoxCase(Tree s)
Definition: boxes.cpp:617
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
bool isBoxCut(Tree t)
Definition: boxes.cpp:105
Tree boxPrim1(prim1 foo)
Definition: boxes.cpp:314
bool isBoxPrim1(Tree s)
Definition: boxes.cpp:315
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
bool isBoxInputs(Tree t, Tree &x)
Definition: boxes.cpp:185
Tree boxEnvironment()
Definition: boxes.cpp:284
bool isBoxHBargraph(Tree s)
Definition: boxes.cpp:455
Tree boxPatternMatcher(Automaton *a, int state, Tree env, Tree origRules, Tree revParamList)
Definition: boxes.cpp:625
Tree closure(Tree abstr, Tree genv, Tree vis, Tree lenv)
Definition: boxes.cpp:234
Tree boxInputs(Tree x)
Definition: boxes.cpp:182
bool isBoxIdent(Tree t)
Definition: boxes.cpp:58
const list< Rule > & rules(int s)
Tree boxFFun(Tree ff)
Definition: boxes.cpp:343
bool isBoxRec(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:144
bool isBoxMerge(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:152
bool isBoxEnvironment(Tree s)
Definition: boxes.cpp:285
Tree boxComponent(Tree filename)
Definition: boxes.cpp:289
Tree boxCase(Tree rules)
Definition: boxes.cpp:615
Tree boxPrim2(prim2 foo)
Definition: boxes.cpp:319
double min(double x, double y)
Definition: interval.hh:59
bool isBoxPatternMatcher(Tree s)
Definition: boxes.cpp:630
Tree boxPrim5(prim5 foo)
Definition: boxes.cpp:334
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
bool isBoxTGroup(Tree s)
Definition: boxes.cpp:449
bool isBoxSlot(Tree t)
Definition: boxes.cpp:119
Tree boxVBargraph(Tree label, Tree min, Tree max)
Definition: boxes.cpp:460
Tree(* prim0)()
Definition: boxes.hh:208
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63
bool isBoxFConst(Tree s)
Definition: boxes.cpp:350
Tree boxAppl(Tree x, Tree y)
Definition: boxes.cpp:200
Tree boxWaveform(const tvec &br)
Definition: boxes.cpp:92