FAUST compiler  0.9.9.6b8
sigtyperules.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 
23 
24 #include <stdio.h>
25 #include <assert.h>
26 #include <iostream>
27 #include <fstream>
28 #include <time.h>
29 
30 
31 #include "sigtype.hh"
32 #include "sigprint.hh"
33 #include "ppsig.hh"
34 //#include "prim.hh"
35 #include "prim2.hh"
36 #include "tlib.hh"
37 #include "sigtyperules.hh"
38 #include "xtended.hh"
39 #include "recursivness.hh"
40 
41 
42 //--------------------------------------------------------------------------
43 // prototypes
44 
45 static void setSigType(Tree sig, Type t);
46 static Type getSigType(Tree sig);
47 static Type initialRecType(Tree t);
48 
49 static Type T(Tree term, Tree env);
50 
51 static Type infereSigType(Tree term, Tree env);
52 static Type infereFFType (Tree ff, Tree ls, Tree env);
53 static Type infereFConstType (Tree type);
54 static Type infereFVarType (Tree type);
55 static Type infereRecType (Tree var, Tree body, Tree env);
56 static Type infereReadTableType(Type tbl, Type ri);
57 static Type infereWriteTableType(Type tbl, Type wi, Type wd);
58 static Type infereProjType(Type t, int i, int vec);
59 static Type infereXType(Tree sig, Tree env);
60 static Type infereDocConstantTblType(Type size, Type init);
61 static Type infereDocWriteTblType(Type size, Type init, Type widx, Type wsig);
62 static Type infereDocAccessTblType(Type tbl, Type ridx);
63 static Type infereWaveformType (Tree lv, Tree env);
64 
65 static interval arithmetic (int opcode, const interval& x, const interval& y);
66 
67 
68 
69 // Uncomment to activate type inferrence tracing
70 //#define TRACE(x) x
71 #define TRACE(x) ;
72 
73 
77 static Tree NULLTYPEENV = tree(symbol("NullTypeEnv"));
78 
79 static int countInferences;
80 static int countMaximal;
81 
82 
83 
90 {
91  Tree sl = symlist(sig);
92  int n = len(sl);
93 
94  vector<Tree> vrec, vdef;
95  vector<Type> vtype;
96 
97  //cerr << "Symlist " << *sl << endl;
98  for (Tree l=sl; isList(l); l=tl(l)) {
99  Tree id, body;
100  assert(isRec(hd(l), id, body));
101  if (!isRec(hd(l), id, body)) {
102  continue;
103  }
104 
105  vrec.push_back(hd(l));
106  vdef.push_back(body);
107  }
108 
109  // init recursive types
110  for (int i=0; i<n; i++) {
111  vtype.push_back(initialRecType(vdef[i]));
112  }
113 
114  assert (int(vrec.size())==n);
115  assert (int(vdef.size())==n);
116  assert (int(vtype.size())==n);
117 
118  // find least fixpoint
119  for (bool finished = false; !finished; ) {
120 
121  // init recursive types
123  for (int i=0; i<n; i++) {
124  setSigType(vrec[i], vtype[i]);
125  vrec[i]->setVisited();
126  }
127 
128  // compute recursive types
129  for (int i=0; i<n; i++) {
130  vtype[i] = T(vdef[i], NULLTYPEENV);
131  }
132 
133  // check finished
134  finished = true;
135  for (int i=0; i<n; i++) {
136  //cerr << i << "-" << *vrec[i] << ":" << *getSigType(vrec[i]) << " => " << *vtype[i] << endl;
137  finished = finished & (getSigType(vrec[i]) == vtype[i]);
138  }
139  }
140 
141  // type full term
142  T(sig, NULLTYPEENV);
143 }
144 
145 
147 {
148  cerr << TABBER << "COUNT INFERENCE " << countInferences << " AT TIME " << clock()/CLOCKS_PER_SEC << 's' << endl;
149  cerr << TABBER << "COUNT ALLOCATION " << AudioType::gAllocationCount << endl;
150  cerr << TABBER << "COUNT MAXIMAL " << countMaximal << endl;
151 }
152 
160 {
161  Type ty = getSigType(sig);
162  assert(ty);
163  return ty;
164 }
165 
166 
167 
168 /***********************************************
169  * Set and get the type property of a signal
170  * (we suppose the signal have been previously
171  * annotated with type information)
172  ***********************************************/
173 
179 static void setSigType(Tree sig, Type t)
180 {
181  TRACE(cerr << TABBER << "SET FIX TYPE OF " << *sig << " TO TYPE " << *t << endl;)
182  sig->setType(t);
183 }
184 
185 
190 static Type getSigType(Tree sig)
191 {
192  AudioType* ty = (AudioType*) sig->getType();
193  if (ty == 0)
194  TRACE(cerr << TABBER << "GET FIX TYPE OF " << *sig << " HAS NO TYPE YET" << endl;)
195  else
196  TRACE(cerr << TABBER << "GET FIX TYPE OF " << *sig << " IS TYPE " << *ty << endl;)
197  return ty;
198 }
199 
200 
201 
202 
203 
204 /**************************************************************************
205 
206  Type Inference System
207 
208 ***************************************************************************/
209 
210 /**************************************************************************
211 
212  Infered Type property
213 
214 ***************************************************************************/
215 
223 static Type T(Tree term, Tree ignoreenv)
224 {
225  TRACE(cerr << ++TABBER << "ENTER T() " << *term << endl;)
226 
227  if (term->isAlreadyVisited()) {
228  Type ty = getSigType(term);
229  TRACE(cerr << --TABBER << "EXIT 1 T() " << *term << " AS TYPE " << *ty << endl);
230  return ty;
231 
232  } else {
233  Type ty = infereSigType(term, ignoreenv);
234  setSigType(term,ty);
235  term->setVisited();
236  TRACE(cerr << --TABBER << "EXIT 2 T() " << *term << " AS TYPE " << *ty << endl);
237  return ty;
238  }
239 }
240 
241 
249 static Type infereSigType(Tree sig, Tree env)
250 {
251  int i;
252  double r;
253  Tree sel, s1, s2, s3, ff, id, ls, l, x, y, z, u, var, body, type, name, file;
254  Tree label, cur, min, max, step;
255 
256  countInferences++;
257 
258  if ( getUserData(sig) ) return infereXType(sig, env);
259 
260  else if (isSigInt(sig, &i)) { Type t = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval(i));
261  /*sig->setType(t);*/ return t; }
262 
263  else if (isSigReal(sig, &r)) { Type t = makeSimpleType(kReal, kKonst, kComp, kVect, kNum, interval(r));
264  /*sig->setType(t);*/ return t; }
265 
266  else if (isSigWaveform(sig)) { return infereWaveformType(sig, env); }
267 
268 
269  else if (isSigInput(sig, &i)) { /*sig->setType(TINPUT);*/ return TINPUT; }
270 
271  else if (isSigOutput(sig, &i, s1)) return sampCast(T(s1,env));
272 
273  else if (isSigDelay1(sig, s1)) {
274  Type t = T(s1,env);
275  return castInterval(sampCast(t), reunion(t->getInterval(), interval(0,0)));
276  }
277 
278  else if (isSigPrefix(sig, s1, s2)) {
279  Type t1 = T(s1,env);
280  Type t2 = T(s2,env);
281  checkInit(t1);
282  return castInterval(sampCast(t1|t2), reunion(t1->getInterval(), t2->getInterval()));
283  }
284 
285  else if (isSigFixDelay(sig, s1, s2)) {
286  Type t1 = T(s1,env);
287  Type t2 = T(s2,env);
288  interval i = t2->getInterval();
289 
290 // cerr << "for sig fix delay : s1 = "
291 // << t1 << ':' << ppsig(s1) << ", s2 = "
292 // << t2 << ':' << ppsig(s2) << endl;
293  if (!i.valid) {
294  cerr << "ERROR : can't compute the min and max values of : " << ppsig(s2) << endl;
295  cerr << " used in delay expression : " << ppsig(sig) << endl;
296  cerr << " (probably a recursive signal)" << endl;
297  exit(1);
298  } else if (i.lo < 0) {
299  cerr << "ERROR : possible negative values of : " << ppsig(s2) << endl;
300  cerr << " used in delay expression : " << ppsig(sig) << endl;
301  cerr << " " << i << endl;
302  exit(1);
303  }
304 
305  return castInterval(sampCast(t1), reunion(t1->getInterval(), interval(0,0)));
306  }
307 
308  else if (isSigBinOp(sig, &i, s1, s2)) {
309  //Type t = T(s1,env)|T(s2,env);
310  Type t1 = T(s1,env);
311  Type t2 = T(s2,env);
312  Type t3 = castInterval(t1 | t2, arithmetic(i, t1->getInterval(), t2->getInterval()));
313  //cerr <<"type rule for : " << ppsig(sig) << " -> " << *t3 << endl;
314 
315  if (i == kDiv) {
316  return floatCast(t3); // division always result in a float even with int arguments
317  } else if ((i>=kGT) && (i<=kNE)) {
318  return boolCast(t3); // comparison always result in a boolean int
319  } else {
320  return t3; // otherwise most general of t1 and t2
321  }
322  }
323 
324  else if (isSigIntCast(sig, s1)) return intCast(T(s1,env));
325 
326  else if (isSigFloatCast(sig, s1)) return floatCast(T(s1,env));
327 
328  else if (isSigFFun(sig, ff, ls)) return infereFFType(ff,ls,env);
329 
330  else if (isSigFConst(sig,type,name,file)) return infereFConstType(type);
331 
332  else if (isSigFVar(sig,type,name,file)) return infereFVarType(type);
333 
334  else if (isSigButton(sig)) { /*sig->setType(TGUI01);*/ return TGUI01; }
335 
336  else if (isSigCheckbox(sig)) { /*sig->setType(TGUI01);*/ return TGUI01; }
337 
338  else if (isSigVSlider(sig,label,cur,min,max,step))
339  return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
340 
341  else if (isSigHSlider(sig,label,cur,min,max,step))
342  return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
343 
344  else if (isSigNumEntry(sig,label,cur,min,max,step))
345  return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
346 
347  else if (isSigHBargraph(sig, l, x, y, s1)) return T(s1,env);
348 
349  else if (isSigVBargraph(sig, l, x, y, s1)) return T(s1,env);
350 
351  else if (isSigAttach(sig, s1, s2)) { T(s2,env); return T(s1,env); }
352 
353  else if (isRec(sig, var, body)) return infereRecType(sig, body, env);
354 
355  else if (isProj(sig, &i, s1)) return infereProjType(T(s1,env),i,kScal);
356 
357  else if (isSigTable(sig, id, s1, s2)) { checkInt(checkInit(T(s1,env))); return makeTableType(checkInit(T(s2,env))); }
358 
359  else if (isSigWRTbl(sig, id, s1, s2, s3)) return infereWriteTableType(T(s1,env), T(s2,env), T(s3,env));
360 
361  else if (isSigRDTbl(sig, s1, s2)) return infereReadTableType(T(s1,env), T(s2,env));
362 
363  else if (isSigGen(sig, s1)) return T(s1,NULLTYPEENV);
364 
365  else if ( isSigDocConstantTbl(sig, x, y) ) return infereDocConstantTblType(T(x,env), T(y,env));
366  else if ( isSigDocWriteTbl(sig,x,y,z,u) ) return infereDocWriteTblType(T(x,env), T(y,env), T(z,env), T(u,env));
367  else if ( isSigDocAccessTbl(sig, x, y) ) return infereDocAccessTblType(T(x,env), T(y,env));
368 
369  else if (isSigSelect2(sig,sel,s1,s2)) {
370  SimpleType *st1, *st2, *stsel;
371 
372  st1 = isSimpleType(T(s1,env));
373  st2 = isSimpleType(T(s2,env));
374  stsel = isSimpleType(T(sel,env));
375 
376  return makeSimpleType( st1->nature()|st2->nature(),
377  st1->variability()|st2->variability()|stsel->variability(),
378  st1->computability()|st2->computability()|stsel->computability(),
379  st1->vectorability()|st2->vectorability()|stsel->vectorability(),
380  st1->boolean()|st2->boolean(),
381  reunion(st1->getInterval(), st2->getInterval())
382  );
383  }
384 
385  else if (isSigSelect3(sig,sel,s1,s2,s3)) { return T(sel,env)|T(s1,env)|T(s2,env)|T(s3,env); }
386 
387  else if (isNil(sig)) { Type t = new TupletType(); /*sig->setType(t);*/ return t; }
388 
389  else if (isList(sig)) { return T( hd(sig),env ) * T( tl(sig),env ); }
390 
391  // unrecognized signal here
392  fprintf(stderr, "ERROR infering signal type : unrecognized signal : "); print(sig, stderr); fprintf(stderr, "\n");
393  exit(1);
394  return 0;
395 }
396 
397 
398 
402 static Type infereProjType(Type t, int i, int vec)
403 {
404  TupletType* tt = isTupletType(t);
405  if (tt == 0) {
406  cerr << "ERROR infering projection type, not a tuplet type : " << t << endl;
407  exit(1);
408  }
409  //return (*tt)[i] ->promoteVariability(t->variability())
410  // ->promoteComputability(t->computability());
411  Type temp = (*tt)[i] ->promoteVariability(t->variability())
412  ->promoteComputability(t->computability())
413  ->promoteVectorability(vec/*t->vectorability()*/);
414  //->promoteBooleanity(t->boolean());
415 
416  if(vec==kVect) temp = vecCast(temp);
417  //cerr << "infereProjType(" << t << ',' << i << ',' << vec << ")" << " -> " << temp << endl;
418 
419  return temp;
420 }
421 
422 
423 
428 {
429  TableType* tt = isTableType(tbl);
430  if (tt == 0) {
431  cerr << "ERROR infering write table type, wrong table type : " << tbl << endl;
432  exit(1);
433  }
434  SimpleType* st = isSimpleType(wi);
435  if (st == 0 || st->nature() > kInt) {
436  cerr << "ERROR infering write table type, wrong write index type : " << wi << endl;
437  exit(1);
438  }
439 
440  int n = tt->nature();
441  int v = wi->variability() | wd->variability();
442  int c = wi->computability() | wd->computability();
443  int vec = wi->vectorability() | wd->vectorability();
444 
445  return makeTableType(tt->content(), n, v, c, vec);
446 
447 }
448 
449 
450 
455 {
456  TableType* tt = isTableType(tbl);
457  if (tt == 0) {
458  cerr << "ERROR infering read table type, wrong table type : " << tbl << endl;
459  exit(1);
460  }
461  SimpleType* st = isSimpleType(ri);
462  if (st == 0 || st->nature() > kInt) {
463  cerr << "ERROR infering read table type, wrong write index type : " << ri << endl;
464  exit(1);
465  }
466 
467  Type temp = tt->content()->promoteVariability(ri->variability()|tt->variability())
468  ->promoteComputability(ri->computability()|tt->computability())
469  ->promoteVectorability(ri->vectorability()|tt->vectorability())
470  ->promoteBoolean(ri->boolean()|tt->boolean())
471  ;
472 
473  return temp;
474 
475 }
476 
477 
479 {
480  checkKonst(checkInt(checkInit(size)));
481 
482  return init;
483 }
484 
485 static Type infereDocWriteTblType(Type size, Type init, Type widx, Type wsig)
486 {
487  checkKonst(checkInt(checkInit(size)));
488 
489  Type temp = init
490  ->promoteVariability(kSamp) // difficult to tell, therefore kSamp to be safe
491  ->promoteComputability(widx->computability()|wsig->computability())
492  ->promoteVectorability(kScal) // difficult to tell, therefore kScal to be safe
493  ->promoteNature(wsig->nature()) // nature of the initial and written signal
494  ->promoteBoolean(wsig->boolean()) // booleanity of the initial and written signal
495  ;
496  return temp;
497 }
498 
500 {
501  Type temp = tbl
502  ->promoteVariability(ridx->variability())
503  ->promoteComputability(ridx->computability())
504  ->promoteVectorability(ridx->vectorability())
505  ;
506  return temp;
507 }
508 
509 
515 {
516  assert (isList(t));
517 
518  vector<Type> v;
519  while (isList(t)) { v.push_back(TREC); t = tl(t); };
520  return new TupletType(v);
521 }
522 
523 
528 static Type infereRecType (Tree sig, Tree body, Tree env)
529 {
530  assert(false); // we should not come here
531  return 0;
532 }
533 
534 
538 static Type infereFFType (Tree ff, Tree ls, Tree env)
539 {
540  // une primitive externe ne peut pas se calculer au plus tot qu'a
541  // l'initialisation. Sa variabilite depend de celle de ses arguments
542  // sauf si elle n'en pas, auquel cas on considere que c'est comme
543  // rand() c'est a dire que le resultat varie a chaque appel.
544  if (ffarity(ff)==0) {
545  // case of functions like rand()
547  } else {
548  // otherwise variability and computability depends
549  // arguments (OR of all arg types)
551  while (isList(ls)) { t = t|T(hd(ls),env); ls=tl(ls); }
552  // but the result type is defined by the function
553 
554  //return t;
555  return makeSimpleType( ffrestype(ff),
556  t->variability(),
557  t->computability(),
558  t->vectorability(),
559  t->boolean(),
560  interval() );
561  }
562 }
563 
564 
569 {
570  // une constante externe ne peut pas se calculer au plus tot qu'a
571  // l'initialisation. Elle est constante, auquel cas on considere que c'est comme
572  // rand() c'est a dire que le resultat varie a chaque appel.
574 }
575 
576 
580 static Type infereFVarType (Tree type)
581 {
582  // une variable externe ne peut pas se calculer au plus tot qu'a
583  // l'execution. Elle est varie par blocs comme les éléments d'interface utilisateur.
585 }
586 
587 
597 static Type infereWaveformType (Tree wfsig, Tree env)
598 {
599  bool iflag = true;
600  int n = wfsig->arity();
601  double lo, hi;
602 
603  if (n == 0) {
604  std::cerr << "ERROR, empty waveform" << std::endl;
605  exit(1);
606  }
607 
608  lo = hi = tree2float(wfsig->branch(0));
609  iflag = isInt(wfsig->branch(0)->node());
610  T(wfsig->branch(0), env);
611 
612  for (int i = 1; i < n; i++) {
613  Tree v = wfsig->branch(i);
614  T(v,env);
615  // compute range
616  double f = tree2float(v);
617  if (f < lo) {
618  lo = f;
619  } else if (f > hi) {
620  hi = f;
621  }
622  iflag &= isInt(v->node());
623  }
624 
625  return makeSimpleType((iflag)?kInt:kReal, kSamp, kComp, kScal, kNum, interval(lo,hi));
626 }
627 
628 
632 static Type infereXType(Tree sig, Tree env)
633 {
634  //cerr << "infereXType :" << endl;
635  //cerr << "infereXType of " << *sig << endl;
636  xtended* p = (xtended*) getUserData(sig);
637  vector<Type> vt;
638 
639  for (int i = 0; i < sig->arity(); i++) vt.push_back(T(sig->branch(i), env));
640  return p->infereSigType(vt);
641 }
642 
643 
644 
645 
646 
655 static interval arithmetic (int opcode, const interval& x, const interval& y)
656 {
657  switch (opcode) {
658  case kAdd: return x+y;
659  case kSub: return x-y;
660  case kMul: return x*y;
661  case kDiv: return x/y;
662  case kRem: return x%y;
663  case kLsh: return x<<y;
664  case kRsh: return x>>y;
665  case kGT: return x>y;
666  case kLT: return x<y;
667  case kGE: return x>=y;
668  case kLE: return x<=y;
669  case kEQ: return x==y;
670  case kNE: return x!=y;
671  case kAND: return x&y;
672  case kOR: return x|y;
673  case kXOR: return x^y;
674  default:
675  cerr << "Unrecognized opcode : " << opcode << endl;
676  exit(1);
677  }
678 
679  return interval();
680 }
bool isSigRDTbl(Tree s, Tree &t, Tree &i)
Definition: signals.cpp:77
bool isSigHSlider(Tree s)
Definition: signals.cpp:217
Type checkInit(Type t)
verifie que t est connu a l'initialisation
Definition: sigtype.cpp:297
Type checkKonst(Type t)
verifie que t est constant
Definition: sigtype.cpp:287
bool valid
true if it is a valid interval
Definition: interval.hh:38
bool isSigFConst(Tree s)
Definition: signals.cpp:138
double lo
minimal value
Definition: interval.hh:39
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:66
Definition: sigtype.hh:58
int variability() const
returns how fast values change (constant, by blocks, by samples)
Definition: sigtype.hh:105
bool isSigCheckbox(Tree s)
Definition: signals.cpp:205
virtual Type infereSigType(const vector< Type > &args)=0
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
Definition: signals.cpp:133
static int gAllocationCount
Definition: sigtype.hh:85
bool isSigNumEntry(Tree s)
Definition: signals.cpp:257
Definition: sigtype.hh:58
Definition: binop.hh:58
Type TREC
Definition: sigtype.cpp:163
bool isSigSelect2(Tree t, Tree &selector, Tree &s1, Tree &s2)
Definition: signals.cpp:116
static Type infereProjType(Type t, int i, int vec)
Infere the type of a projection (selection) of a tuplet element.
interval getInterval() const
returns the interval (min dn max values) of a signal
Definition: sigtype.hh:110
The type of a tuplet of data.
Definition: sigtype.hh:340
void annotationStatistics()
print annotation statistics
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
static Type infereReadTableType(Type tbl, Type ri)
Infere the type of the result of reading a table.
Definition: sigtype.hh:57
Type content() const
return the type of data store in the table
Definition: sigtype.hh:320
Definition: binop.hh:59
Definition: sigtype.hh:54
int boolean() const
returns when a signal stands for a boolean value
Definition: sigtype.hh:108
static void setSigType(Tree sig, Type t)
Set the type annotation of sig.
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void typeAnnotation(Tree sig)
Fully annotate every subtree of term with type information.
bool isSigInput(Tree t, int *i)
Definition: signals.cpp:48
int ffarity(Tree t)
Definition: prim2.cpp:67
Type intCast(Type t)
Definition: sigtype.hh:269
static Type infereWriteTableType(Type tbl, Type wi, Type wd)
Infere the type of the result of writing into a table.
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
#define TRACE(x)
Tree hd(Tree l)
Definition: list.hh:133
const Node & node() const
return the content of the tree
Definition: tree.hh:143
static Type initialRecType(Tree t)
Compute an initial type solution for a recursive block E1,E2,...En -> TREC,TREC,...TREC.
Definition: sigtype.hh:57
void setType(void *t)
Definition: tree.hh:157
bool isSigVBargraph(Tree s)
Definition: signals.cpp:285
bool isSigSelect3(Tree t, Tree &selector, Tree &s1, Tree &s2, Tree &s3)
Definition: signals.cpp:119
bool isSigVSlider(Tree s)
Definition: signals.cpp:237
void * getType()
Definition: tree.hh:158
Definition: binop.hh:56
Type boolCast(Type t)
Definition: sigtype.hh:272
static Type infereRecType(Tree var, Tree body, Tree env)
Infere the type of e recursive block by trying solutions of increasing generality.
The type of a table of audio data.
Definition: sigtype.hh:288
bool isAlreadyVisited()
Definition: tree.hh:162
double max(double x, double y)
Definition: interval.hh:60
static Type getSigType(Tree sig)
Retrieve the type annotation of sig.
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
bool isNil(Tree l)
Definition: list.hh:137
static void startNewVisit()
Definition: tree.hh:161
Definition: binop.hh:56
static Type infereDocConstantTblType(Type size, Type init)
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
static Type infereXType(Tree sig, Tree env)
Infere the type of an extended (primitive) block.
AudioType * makeSimpleType(int n, int v, int c, int vec, int b, const interval &i)
Definition: sigtype.cpp:421
Type TGUI01
Definition: sigtype.cpp:157
Definition: binop.hh:59
static interval arithmetic(int opcode, const interval &x, const interval &y)
Compute the resulting interval of an arithmetic operation.
int ffrestype(Tree t)
Definition: prim2.cpp:55
Definition: ppsig.hh:48
Type floatCast(Type t)
Definition: sigtype.hh:270
Definition: sigtype.hh:55
Definition: binop.hh:58
bool isSigHBargraph(Tree s)
Definition: signals.cpp:279
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
Definition: signals.cpp:99
Definition: binop.hh:58
bool isList(Tree l)
Definition: list.hh:138
Definition: binop.hh:56
void setVisited()
Definition: tree.hh:163
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
The type of a simple numeric audio signal.
Definition: sigtype.hh:237
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
static Tree NULLTYPEENV
The empty type environment (also property key for closed term type)
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:291
Type TINPUT
Definition: sigtype.cpp:155
Definition: sigtype.hh:54
Type vecCast(Type t)
Definition: sigtype.hh:274
Definition: binop.hh:56
bool isSigDocAccessTbl(Tree t, Tree &tbl, Tree &ridx)
Definition: signals.cpp:107
static Type infereFConstType(Tree type)
Infere the type of a foreign constant.
AudioType * makeTableType(const Type &ct)
Definition: sigtype.cpp:448
Definition: sigtype.hh:56
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
interval reunion(const interval &x, const interval &y)
Definition: interval.hh:64
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
static int countMaximal
Type sampCast(Type t)
Definition: sigtype.hh:271
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
Type TGUI
Definition: sigtype.cpp:156
TableType * isTableType(AudioType *t)
Definition: sigtype.cpp:268
int nature() const
returns the kind of values (integre or floating point)
Definition: sigtype.hh:104
static Type infereDocAccessTblType(Type tbl, Type ridx)
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
static Type infereWaveformType(Tree lv, Tree env)
Infere the type of a waveform:
bool isSigWaveform(Tree s)
Definition: signals.cpp:211
Definition: binop.hh:58
TupletType * isTupletType(AudioType *t)
Definition: sigtype.cpp:269
static Type T(Tree term, Tree env)
Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type e...
int computability() const
returns when values are available (compilation, initialisation, execution)
Definition: sigtype.hh:106
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
Tree tree(const Node &n)
Definition: tree.hh:186
static Type infereFVarType(Tree type)
Infere the type of a foreign variable.
bool isSigDocWriteTbl(Tree t, Tree &n, Tree &sig, Tree &widx, Tree &wsig)
Definition: signals.cpp:103
bool isSigDelay1(Tree t, Tree &t0)
Definition: signals.cpp:58
static Type infereSigType(Tree term, Tree env)
Infere the type of a term according to its surrounding type environment.
bool isSigFloatCast(Tree t)
Definition: signals.cpp:187
Definition: binop.hh:57
bool isSigFVar(Tree s)
Definition: signals.cpp:144
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isSigIntCast(Tree t)
Definition: signals.cpp:184
Definition: binop.hh:57
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Definition: symbol.hh:95
Type castInterval(Type t, const interval &i)
Definition: sigtype.hh:278
SimpleType * isSimpleType(AudioType *t)
Definition: sigtype.cpp:267
bool isProj(Tree t, int *i, Tree &rgroup)
Definition: signals.cpp:151
Tabber TABBER(1)
Definition: tree.cpp:87
Definition: binop.hh:58
Tree symlist(Tree sig)
API to the typing system of signals.
bool isInt(const Node &n)
Definition: node.hh:126
static Type infereFFType(Tree ff, Tree ls, Tree env)
Infere the type of a foreign function call.
double min(double x, double y)
Definition: interval.hh:59
Definition: sigtype.hh:57
Definition: binop.hh:56
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Definition: tree.cpp:246
int len(Tree l)
Definition: list.cpp:198
Definition: binop.hh:58
Tree tl(Tree l)
Definition: list.hh:134
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
static int countInferences
The Root class for all audio data types.
Definition: sigtype.hh:82
bool isSigOutput(Tree t, int *i, Tree &t0)
Definition: signals.cpp:52
int vectorability() const
returns when a signal can be vectorized
Definition: sigtype.hh:107
bool isSigButton(Tree s)
Definition: signals.cpp:199
static Type infereDocWriteTblType(Type size, Type init, Type widx, Type wsig)
Type checkInt(Type t)
verifie que t est entier
Definition: sigtype.cpp:276
Definition: binop.hh:59
void print(Tree t, FILE *out)
Definition: list.cpp:154