fd52d172b77fecf231188a52e4757800b3670b93
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / headers / boxes.hh
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 Wire and Cut
81 *****************************************************************************/
82
83 Tree boxWire();
84 Tree boxCut();
85
86 bool isBoxWire(Tree t);
87 bool isBoxCut(Tree t);
88
89
90 /*****************************************************************************
91 Symbolic Boxes with symbolic slots
92 *****************************************************************************/
93
94 Tree boxSlot(int id);
95 Tree boxSymbolic(Tree slot, Tree body);
96
97 bool isBoxSlot(Tree t);
98 bool isBoxSymbolic(Tree t);
99
100 bool isBoxSlot(Tree t, int* id);
101 bool isBoxSymbolic(Tree t, Tree& slot, Tree& body);
102
103
104 /*****************************************************************************
105 Composition of Boxes
106 *****************************************************************************/
107
108 Tree boxSeq (Tree x, Tree y);
109 Tree boxPar (Tree x, Tree y);
110 Tree boxRec (Tree x, Tree y);
111 Tree boxSplit (Tree x, Tree y);
112 Tree boxMerge (Tree x, Tree y);
113
114 bool isBoxSeq (Tree t, Tree& x, Tree& y);
115 bool isBoxPar (Tree t, Tree& x, Tree& y);
116 bool isBoxRec (Tree t, Tree& x, Tree& y);
117 bool isBoxSplit (Tree t, Tree& x, Tree& y);
118 bool isBoxMerge (Tree t, Tree& x, Tree& y);
119
120 /*****************************************************************************
121 Algorithmic Composition of Boxes
122 *****************************************************************************/
123
124 Tree boxIPar(Tree x, Tree y, Tree z);
125 Tree boxISeq(Tree x, Tree y, Tree z);
126 Tree boxISum(Tree x, Tree y, Tree z);
127 Tree boxIProd(Tree x, Tree y, Tree z);
128
129 bool isBoxIPar(Tree t, Tree& x, Tree& y, Tree& z);
130 bool isBoxISeq(Tree t, Tree& x, Tree& y, Tree& z);
131 bool isBoxISum(Tree t, Tree& x, Tree& y, Tree& z);
132 bool isBoxIProd(Tree t, Tree& x, Tree& y, Tree& z);
133
134
135 /*****************************************************************************
136 Lambda-Calculus of Boxes
137 *****************************************************************************/
138
139 Tree buildBoxAbstr (Tree x, Tree y);
140 Tree buildBoxAppl (Tree x, Tree y);
141
142 Tree boxAbstr (Tree x, Tree y);
143 Tree boxAppl (Tree x, Tree y);
144
145 bool isBoxAbstr (Tree t);
146 bool isBoxAppl (Tree t);
147
148 bool isBoxAbstr (Tree t, Tree& x, Tree& y);
149 bool isBoxAppl (Tree t, Tree& x, Tree& y);
150
151 Tree closure (Tree abstr, Tree genv, Tree vis, Tree lenv);
152
153 bool isClosure (Tree t, Tree& abstr, Tree& genv, Tree& vis, Tree& lenv);
154
155 // for foo(x,y).faa expressions
156 Tree boxAccess (Tree exp, Tree id);
157 bool isBoxAccess(Tree t, Tree& exp, Tree& id);
158
159
160 /*****************************************************************************
161 Boxes with local definitions
162 *****************************************************************************/
163
164 Tree boxWithLocalDef (Tree body, Tree ldef);
165 bool isBoxWithLocalDef (Tree t, Tree& body, Tree& ldef);
166
167
168 /*****************************************************************************
169 Modification of local definitions
170 *****************************************************************************/
171
172 Tree boxModifLocalDef (Tree body, Tree ldef);
173 bool isBoxModifLocalDef (Tree t, Tree& body, Tree& ldef);
174
175
176 /*****************************************************************************
177 Error Boxe
178 *****************************************************************************/
179
180 Tree boxError();
181 bool isBoxError(Tree t);
182
183 /*****************************************************************************
184 Primitive Boxes (n -> 1)
185 *****************************************************************************/
186
187 typedef Tree (*prim0)();
188 typedef Tree (*prim1)(Tree x);
189 typedef Tree (*prim2)(Tree x, Tree y);
190 typedef Tree (*prim3)(Tree x, Tree y, Tree z);
191 typedef Tree (*prim4)(Tree w, Tree x, Tree y, Tree z);
192 typedef Tree (*prim5)(Tree v, Tree w, Tree x, Tree y, Tree z);
193
194 Tree boxPrim0 (prim0 foo);
195 Tree boxPrim1 (prim1 foo);
196 Tree boxPrim2 (prim2 foo);
197 Tree boxPrim3 (prim3 foo);
198 Tree boxPrim4 (prim4 foo);
199 Tree boxPrim5 (prim5 foo);
200
201 bool isBoxPrim0 (Tree s);
202 bool isBoxPrim1 (Tree s);
203 bool isBoxPrim2 (Tree s);
204 bool isBoxPrim3 (Tree s);
205 bool isBoxPrim4 (Tree s);
206 bool isBoxPrim5 (Tree s);
207
208 bool isBoxPrim0 (Tree s, prim0* p);
209 bool isBoxPrim1 (Tree s, prim1* p);
210 bool isBoxPrim2 (Tree s, prim2* p);
211 bool isBoxPrim3 (Tree s, prim3* p);
212 bool isBoxPrim4 (Tree s, prim4* p);
213 bool isBoxPrim5 (Tree s, prim5* p);
214
215
216 /*****************************************************************************
217 Foreign Functions
218 *****************************************************************************/
219
220 Tree boxFFun (Tree ff);
221 bool isBoxFFun (Tree s);
222 bool isBoxFFun (Tree s, Tree& ff);
223
224
225 Tree boxFConst (Tree type, Tree name, Tree file);
226 bool isBoxFConst (Tree s);
227 bool isBoxFConst (Tree s, Tree& type, Tree& name, Tree& file);
228
229
230 Tree boxFVar (Tree type, Tree name, Tree file);
231 bool isBoxFVar (Tree s);
232 bool isBoxFVar (Tree s, Tree& type, Tree& name, Tree& file);
233
234
235 /*****************************************************************************
236 Modules
237 *****************************************************************************/
238
239 Tree boxEnvironment();
240 bool isBoxEnvironment (Tree s);
241
242 Tree boxComponent (Tree filename);
243 bool isBoxComponent (Tree s, Tree& filename);
244
245 Tree boxLibrary (Tree filename);
246 bool isBoxLibrary (Tree s, Tree& filename);
247
248 Tree importFile(Tree filename);
249 bool isImportFile(Tree s, Tree& filename);
250
251
252 /*****************************************************************************
253 User Interface Elements
254 *****************************************************************************/
255
256 Tree boxButton (Tree label);
257 bool isBoxButton (Tree s);
258 bool isBoxButton (Tree s, Tree& label);
259
260 Tree boxCheckbox (Tree label);
261 bool isBoxCheckbox (Tree s);
262 bool isBoxCheckbox (Tree s, Tree& label);
263
264 Tree boxVSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
265 bool isBoxVSlider (Tree s);
266 bool isBoxVSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
267
268 Tree boxHSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
269 bool isBoxHSlider (Tree s);
270 bool isBoxHSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
271
272 Tree boxNumEntry (Tree label, Tree cur, Tree min, Tree max, Tree step);
273 bool isBoxNumEntry (Tree s);
274 bool isBoxNumEntry (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
275
276 Tree boxVGroup (Tree label, Tree x);
277 bool isBoxVGroup (Tree s);
278 bool isBoxVGroup (Tree s, Tree& label, Tree& x);
279
280 Tree boxHGroup (Tree label, Tree x);
281 bool isBoxHGroup (Tree s);
282 bool isBoxHGroup (Tree s, Tree& label, Tree& x);
283
284 Tree boxTGroup (Tree label, Tree x);
285 bool isBoxTGroup (Tree s);
286 bool isBoxTGroup (Tree s, Tree& label, Tree& x);
287
288 // GUI outputs
289 Tree boxVBargraph (Tree label, Tree min, Tree max);
290 bool isBoxVBargraph (Tree s);
291 bool isBoxVBargraph (Tree s, Tree& label, Tree& min, Tree& max);
292
293 Tree boxHBargraph (Tree label, Tree min, Tree max);
294 bool isBoxHBargraph (Tree s);
295 bool isBoxHBargraph (Tree s, Tree& label, Tree& min, Tree& max);
296
297
298 /*****************************************************************************
299 case (pattern matching)
300 *****************************************************************************/
301 Tree boxCase (Tree rules);
302 bool isBoxCase (Tree s);
303 bool isBoxCase (Tree s, Tree& rules);
304
305 Tree boxPatternMatcher (Automaton* a, int state, Tree env, Tree origRules, Tree revParamList);
306 bool isBoxPatternMatcher (Tree s);
307 bool isBoxPatternMatcher (Tree s, Automaton*& a, int& state, Tree& env, Tree& origRules, Tree& revParamList);
308
309 // wrap an id into a pattern variable
310 Tree boxPatternVar (Tree id);
311 bool isBoxPatternVar(Tree s, Tree& id);
312
313
314 /*****************************************************************************
315 ******************************************************************************
316
317 Box Algorithms
318
319 ******************************************************************************
320 *****************************************************************************/
321
322 // return the number of input
323 bool getBoxType (Tree box, int* inum, int* onum);
324
325
326 #endif