FAUST compiler  0.9.9.6b8
Macros | Functions | Variables
sigtyperules.cpp File Reference
#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <fstream>
#include <time.h>
#include "sigtype.hh"
#include "sigprint.hh"
#include "ppsig.hh"
#include "prim2.hh"
#include "tlib.hh"
#include "sigtyperules.hh"
#include "xtended.hh"
#include "recursivness.hh"
Include dependency graph for sigtyperules.cpp:

Go to the source code of this file.

Macros

#define TRACE(x)   ;
 

Functions

static void setSigType (Tree sig, Type t)
 Set the type annotation of sig. More...
 
static Type getSigType (Tree sig)
 Retrieve the type annotation of sig. More...
 
static Type initialRecType (Tree t)
 Compute an initial type solution for a recursive block E1,E2,...En -> TREC,TREC,...TREC. More...
 
static Type T (Tree term, Tree ignoreenv)
 Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type environment. More...
 
static Type infereSigType (Tree sig, Tree env)
 Infere the type of a term according to its surrounding type environment. More...
 
static Type infereFFType (Tree ff, Tree ls, Tree env)
 Infere the type of a foreign function call. More...
 
static Type infereFConstType (Tree type)
 Infere the type of a foreign constant. More...
 
static Type infereFVarType (Tree type)
 Infere the type of a foreign variable. More...
 
static Type infereRecType (Tree sig, Tree body, Tree env)
 Infere the type of e recursive block by trying solutions of increasing generality. More...
 
static Type infereReadTableType (Type tbl, Type ri)
 Infere the type of the result of reading a table. More...
 
static Type infereWriteTableType (Type tbl, Type wi, Type wd)
 Infere the type of the result of writing into a table. More...
 
static Type infereProjType (Type t, int i, int vec)
 Infere the type of a projection (selection) of a tuplet element. More...
 
static Type infereXType (Tree sig, Tree env)
 Infere the type of an extended (primitive) block. More...
 
static Type infereDocConstantTblType (Type size, Type init)
 
static Type infereDocWriteTblType (Type size, Type init, Type widx, Type wsig)
 
static Type infereDocAccessTblType (Type tbl, Type ridx)
 
static Type infereWaveformType (Tree wfsig, Tree env)
 Infere the type of a waveform: More...
 
static interval arithmetic (int opcode, const interval &x, const interval &y)
 Compute the resulting interval of an arithmetic operation. More...
 
void typeAnnotation (Tree sig)
 Fully annotate every subtree of term with type information. More...
 
void annotationStatistics ()
 print annotation statistics More...
 
Type getCertifiedSigType (Tree sig)
 Retrieve the type of sig and check it exists. More...
 

Variables

static Tree NULLTYPEENV = tree(symbol("NullTypeEnv"))
 The empty type environment (also property key for closed term type) More...
 
static int countInferences
 
static int countMaximal
 

Macro Definition Documentation

#define TRACE (   x)    ;

Definition at line 71 of file sigtyperules.cpp.

Referenced by getSigType(), setSigType(), and T().

Function Documentation

void annotationStatistics ( )

print annotation statistics

Definition at line 146 of file sigtyperules.cpp.

References AudioType::gAllocationCount, and TABBER.

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 }
static int gAllocationCount
Definition: sigtype.hh:85
static int countMaximal
Tabber TABBER(1)
Definition: tree.cpp:87
static int countInferences
static interval arithmetic ( int  opcode,
const interval x,
const interval y 
)
static

Compute the resulting interval of an arithmetic operation.

Parameters
opcode of the operation
s1interval of the left operand
s2interval of the right operand
Returns
the resulting interval

Definition at line 655 of file sigtyperules.cpp.

References kAdd, kAND, kDiv, kEQ, kGE, kGT, kLE, kLsh, kLT, kMul, kNE, kOR, kRem, kRsh, kSub, and kXOR.

Referenced by infereSigType().

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 }
Definition: binop.hh:58
Definition: binop.hh:59
Definition: binop.hh:56
Definition: binop.hh:56
Definition: binop.hh:59
Definition: binop.hh:58
Definition: binop.hh:58
Definition: binop.hh:56
Definition: binop.hh:56
Definition: binop.hh:58
Definition: binop.hh:57
Definition: binop.hh:57
Definition: binop.hh:58
Definition: binop.hh:56
Definition: binop.hh:58
Definition: binop.hh:59

Here is the caller graph for this function:

Type getCertifiedSigType ( Tree  sig)

Retrieve the type of sig and check it exists.

Return the type of a previously annotated signal term.

Produces an error if the signal has no type associated

Parameters
sigthe signal we want to know the type
Returns
the type of the signal

Definition at line 159 of file sigtyperules.cpp.

References getSigType().

Referenced by VectorCompiler::CS(), ScalarCompiler::declareWaveform(), ScalarCompiler::forceCacheCode(), ScalarCompiler::generateBinOp(), DocCompiler::generateBinOp(), VectorCompiler::generateCacheCode(), ScalarCompiler::generateCacheCode(), DocCompiler::generateCacheCode(), ScalarCompiler::generateDelayVec(), DocCompiler::generateDelayVec(), DocCompiler::generateDocConstantTbl(), DocCompiler::generateDocWriteTbl(), ScalarCompiler::generateFConst(), DocCompiler::generateFConst(), DocCompiler::generateFVar(), ScalarCompiler::generateHBargraph(), DocCompiler::generateHBargraph(), ScalarCompiler::generateNumber(), DocCompiler::generateNumber(), ScalarCompiler::generatePrefix(), ScalarCompiler::generateRec(), DocCompiler::generateRec(), ScalarCompiler::generateStaticTable(), ScalarCompiler::generateTable(), VectorCompiler::generateVariableStore(), ScalarCompiler::generateVariableStore(), DocCompiler::generateVariableStore(), ScalarCompiler::generateVBargraph(), DocCompiler::generateVBargraph(), ScalarCompiler::generateXtended(), DocCompiler::generateXtended(), OccMarkup::incOcc(), VectorCompiler::needSeparateLoop(), recdraw(), ScalarCompiler::sharingAnnotation(), DocCompiler::sharingAnnotation(), signal2klass(), and sigToGraph().

160 {
161  Type ty = getSigType(sig);
162  assert(ty);
163  return ty;
164 }
static Type getSigType(Tree sig)
Retrieve the type annotation of sig.

Here is the call graph for this function:

Here is the caller graph for this function:

static Type getSigType ( Tree  sig)
static

Retrieve the type annotation of sig.

Parameters
sigthe signal we want to know the type

Definition at line 190 of file sigtyperules.cpp.

References CTree::getType(), TABBER, and TRACE.

Referenced by getCertifiedSigType(), T(), and typeAnnotation().

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 }
#define TRACE(x)
void * getType()
Definition: tree.hh:158
Tabber TABBER(1)
Definition: tree.cpp:87
The Root class for all audio data types.
Definition: sigtype.hh:82

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereDocAccessTblType ( Type  tbl,
Type  ridx 
)
static

Definition at line 499 of file sigtyperules.cpp.

Referenced by infereSigType().

500 {
501  Type temp = tbl
502  ->promoteVariability(ridx->variability())
503  ->promoteComputability(ridx->computability())
504  ->promoteVectorability(ridx->vectorability())
505  ;
506  return temp;
507 }

Here is the caller graph for this function:

static Type infereDocConstantTblType ( Type  size,
Type  init 
)
static

Definition at line 478 of file sigtyperules.cpp.

References checkInit(), checkInt(), and checkKonst().

Referenced by infereSigType().

479 {
480  checkKonst(checkInt(checkInit(size)));
481 
482  return init;
483 }
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
Type checkInt(Type t)
verifie que t est entier
Definition: sigtype.cpp:276

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereDocWriteTblType ( Type  size,
Type  init,
Type  widx,
Type  wsig 
)
static

Definition at line 485 of file sigtyperules.cpp.

References checkInit(), checkInt(), checkKonst(), kSamp, and kScal.

Referenced by infereSigType().

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 }
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
Definition: sigtype.hh:58
Definition: sigtype.hh:56
Type checkInt(Type t)
verifie que t est entier
Definition: sigtype.cpp:276

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFConstType ( Tree  type)
static

Infere the type of a foreign constant.

Definition at line 568 of file sigtyperules.cpp.

References kInit, kKonst, kNum, kVect, makeSimpleType(), and tree2int().

Referenced by infereSigType().

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 }
Definition: sigtype.hh:58
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
Definition: sigtype.hh:57
AudioType * makeSimpleType(int n, int v, int c, int vec, int b, const interval &i)
Definition: sigtype.cpp:421
Definition: sigtype.hh:55

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFFType ( Tree  ff,
Tree  ls,
Tree  env 
)
static

Infere the type of a foreign function call.

Definition at line 538 of file sigtyperules.cpp.

References ffarity(), ffrestype(), hd(), isList(), kInit, kInt, kKonst, kNum, kSamp, kVect, makeSimpleType(), T(), and tl().

Referenced by infereSigType().

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 }
Definition: sigtype.hh:58
Definition: sigtype.hh:57
Definition: sigtype.hh:54
int ffarity(Tree t)
Definition: prim2.cpp:67
Tree hd(Tree l)
Definition: list.hh:133
AudioType * makeSimpleType(int n, int v, int c, int vec, int b, const interval &i)
Definition: sigtype.cpp:421
int ffrestype(Tree t)
Definition: prim2.cpp:55
Definition: sigtype.hh:55
bool isList(Tree l)
Definition: list.hh:138
Definition: sigtype.hh:56
static Type T(Tree term, Tree env)
Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type e...
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFVarType ( Tree  type)
static

Infere the type of a foreign variable.

Definition at line 580 of file sigtyperules.cpp.

References kBlock, kExec, kNum, kVect, makeSimpleType(), and tree2int().

Referenced by infereSigType().

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 }
Definition: sigtype.hh:58
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
AudioType * makeSimpleType(int n, int v, int c, int vec, int b, const interval &i)
Definition: sigtype.cpp:421
Definition: sigtype.hh:55
Definition: sigtype.hh:57

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereProjType ( Type  t,
int  i,
int  vec 
)
static

Infere the type of a projection (selection) of a tuplet element.

Definition at line 402 of file sigtyperules.cpp.

References isTupletType(), kVect, and vecCast().

Referenced by infereSigType().

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 }
Definition: sigtype.hh:58
The type of a tuplet of data.
Definition: sigtype.hh:340
Type vecCast(Type t)
Definition: sigtype.hh:274
TupletType * isTupletType(AudioType *t)
Definition: sigtype.cpp:269

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereReadTableType ( Type  tbl,
Type  ri 
)
static

Infere the type of the result of reading a table.

Definition at line 454 of file sigtyperules.cpp.

References AudioType::boolean(), AudioType::computability(), TableType::content(), isSimpleType(), isTableType(), kInt, AudioType::nature(), AudioType::variability(), and AudioType::vectorability().

Referenced by infereSigType().

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 }
int variability() const
returns how fast values change (constant, by blocks, by samples)
Definition: sigtype.hh:105
Type content() const
return the type of data store in the table
Definition: sigtype.hh:320
Definition: sigtype.hh:54
int boolean() const
returns when a signal stands for a boolean value
Definition: sigtype.hh:108
The type of a table of audio data.
Definition: sigtype.hh:288
The type of a simple numeric audio signal.
Definition: sigtype.hh:237
TableType * isTableType(AudioType *t)
Definition: sigtype.cpp:268
int nature() const
returns the kind of values (integre or floating point)
Definition: sigtype.hh:104
int computability() const
returns when values are available (compilation, initialisation, execution)
Definition: sigtype.hh:106
SimpleType * isSimpleType(AudioType *t)
Definition: sigtype.cpp:267
int vectorability() const
returns when a signal can be vectorized
Definition: sigtype.hh:107

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereRecType ( Tree  var,
Tree  body,
Tree  env 
)
static

Infere the type of e recursive block by trying solutions of increasing generality.

Definition at line 528 of file sigtyperules.cpp.

Referenced by infereSigType().

529 {
530  assert(false); // we should not come here
531  return 0;
532 }

Here is the caller graph for this function:

static Type infereSigType ( Tree  sig,
Tree  env 
)
static

Infere the type of a term according to its surrounding type environment.

Parameters
sigthe signal to aanlyze
envthe type environment
Returns
the type of sig according to environment env

Definition at line 249 of file sigtyperules.cpp.

References arithmetic(), boolCast(), AudioType::boolean(), castInterval(), checkInit(), checkInt(), AudioType::computability(), floatCast(), AudioType::getInterval(), getUserData(), hd(), infereDocAccessTblType(), infereDocConstantTblType(), infereDocWriteTblType(), infereFConstType(), infereFFType(), infereFVarType(), infereProjType(), infereReadTableType(), infereRecType(), infereWaveformType(), infereWriteTableType(), infereXType(), intCast(), isList(), isNil(), isProj(), isRec(), isSigAttach(), isSigBinOp(), isSigButton(), isSigCheckbox(), isSigDelay1(), isSigDocAccessTbl(), isSigDocConstantTbl(), isSigDocWriteTbl(), isSigFConst(), isSigFFun(), isSigFixDelay(), isSigFloatCast(), isSigFVar(), isSigGen(), isSigHBargraph(), isSigHSlider(), isSigInput(), isSigInt(), isSigIntCast(), isSigNumEntry(), isSigOutput(), isSigPrefix(), isSigRDTbl(), isSigReal(), isSigSelect2(), isSigSelect3(), isSigTable(), isSigVBargraph(), isSigVSlider(), isSigWaveform(), isSigWRTbl(), isSimpleType(), kComp, kDiv, kGT, kInt, kKonst, kNE, kNum, kReal, kScal, kVect, interval::lo, makeSimpleType(), makeTableType(), max(), min(), name(), AudioType::nature(), print(), reunion(), sampCast(), T(), TGUI, TGUI01, TINPUT, tl(), tree2float(), interval::valid, AudioType::variability(), and AudioType::vectorability().

Referenced by T().

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 }
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
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
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
Definition: signals.cpp:133
bool isSigNumEntry(Tree s)
Definition: signals.cpp:257
Definition: sigtype.hh:58
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
static Type infereReadTableType(Type tbl, Type ri)
Infere the type of the result of reading a table.
Definition: sigtype.hh:54
int boolean() const
returns when a signal stands for a boolean value
Definition: sigtype.hh:108
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigInput(Tree t, int *i)
Definition: signals.cpp:48
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
Tree hd(Tree l)
Definition: list.hh:133
Definition: sigtype.hh:57
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
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.
double max(double x, double y)
Definition: interval.hh:60
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
bool isNil(Tree l)
Definition: list.hh:137
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
static interval arithmetic(int opcode, const interval &x, const interval &y)
Compute the resulting interval of an arithmetic operation.
Definition: ppsig.hh:48
Type floatCast(Type t)
Definition: sigtype.hh:270
Definition: sigtype.hh:55
bool isSigHBargraph(Tree s)
Definition: signals.cpp:279
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
Definition: signals.cpp:99
bool isList(Tree l)
Definition: list.hh:138
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
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
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
Type sampCast(Type t)
Definition: sigtype.hh:271
Type TGUI
Definition: sigtype.cpp:156
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
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
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
bool isSigFloatCast(Tree t)
Definition: signals.cpp:187
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
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
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
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Definition: tree.cpp:246
Definition: binop.hh:58
Tree tl(Tree l)
Definition: list.hh:134
static int countInferences
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
void print(Tree t, FILE *out)
Definition: list.cpp:154

Here is the caller graph for this function:

static Type infereWaveformType ( Tree  wfsig,
Tree  env 
)
static

Infere the type of a waveform:

  • the nature is int if all values are int, otherwise it is float
  • the variability is by samples
  • the waveform is known at compile time
  • it can be vectorized because all values are known
  • knum ???
  • the interval is min and max of values

Definition at line 597 of file sigtyperules.cpp.

References CTree::arity(), CTree::branch(), isInt(), kComp, kInt, kNum, kReal, kSamp, kScal, makeSimpleType(), CTree::node(), T(), and tree2float().

Referenced by infereSigType().

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 }
Definition: sigtype.hh:58
Definition: sigtype.hh:54
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
Definition: sigtype.hh:57
AudioType * makeSimpleType(int n, int v, int c, int vec, int b, const interval &i)
Definition: sigtype.cpp:421
Definition: sigtype.hh:55
Definition: sigtype.hh:54
Definition: sigtype.hh:56
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
static Type T(Tree term, Tree env)
Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type e...
bool isInt(const Node &n)
Definition: node.hh:126
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Definition: tree.cpp:246
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereWriteTableType ( Type  tbl,
Type  wi,
Type  wd 
)
static

Infere the type of the result of writing into a table.

Definition at line 427 of file sigtyperules.cpp.

References TableType::content(), isSimpleType(), isTableType(), kInt, makeTableType(), and AudioType::nature().

Referenced by infereSigType().

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 }
Type content() const
return the type of data store in the table
Definition: sigtype.hh:320
Definition: sigtype.hh:54
The type of a table of audio data.
Definition: sigtype.hh:288
The type of a simple numeric audio signal.
Definition: sigtype.hh:237
AudioType * makeTableType(const Type &ct)
Definition: sigtype.cpp:448
TableType * isTableType(AudioType *t)
Definition: sigtype.cpp:268
int nature() const
returns the kind of values (integre or floating point)
Definition: sigtype.hh:104
SimpleType * isSimpleType(AudioType *t)
Definition: sigtype.cpp:267

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereXType ( Tree  sig,
Tree  env 
)
static

Infere the type of an extended (primitive) block.

Definition at line 632 of file sigtyperules.cpp.

References CTree::arity(), CTree::branch(), getUserData(), xtended::infereSigType(), and T().

Referenced by infereSigType().

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 }
virtual Type infereSigType(const vector< Type > &args)=0
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
static Type T(Tree term, Tree env)
Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type e...
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Type initialRecType ( Tree  t)
static

Compute an initial type solution for a recursive block E1,E2,...En -> TREC,TREC,...TREC.

Definition at line 514 of file sigtyperules.cpp.

References isList(), tl(), and TREC.

Referenced by typeAnnotation().

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 }
Type TREC
Definition: sigtype.cpp:163
The type of a tuplet of data.
Definition: sigtype.hh:340
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static void setSigType ( Tree  sig,
Type  t 
)
static

Set the type annotation of sig.

Parameters
sigthe signal we want to type
tthe type of the signal

Definition at line 179 of file sigtyperules.cpp.

References CTree::setType(), TABBER, and TRACE.

Referenced by T(), and typeAnnotation().

180 {
181  TRACE(cerr << TABBER << "SET FIX TYPE OF " << *sig << " TO TYPE " << *t << endl;)
182  sig->setType(t);
183 }
#define TRACE(x)
void setType(void *t)
Definition: tree.hh:157
Tabber TABBER(1)
Definition: tree.cpp:87

Here is the call graph for this function:

Here is the caller graph for this function:

static Type T ( Tree  term,
Tree  ignoreenv 
)
static

Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type environment.

Parameters
sigthe signal to analyze
envthe type environment
Returns
the type of sig according to environment env
See also
getCertifiedSigType

Definition at line 223 of file sigtyperules.cpp.

References getSigType(), infereSigType(), CTree::isAlreadyVisited(), setSigType(), CTree::setVisited(), TABBER, and TRACE.

Referenced by infereFFType(), infereSigType(), infereWaveformType(), infereXType(), and typeAnnotation().

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 }
static void setSigType(Tree sig, Type t)
Set the type annotation of sig.
#define TRACE(x)
bool isAlreadyVisited()
Definition: tree.hh:162
static Type getSigType(Tree sig)
Retrieve the type annotation of sig.
void setVisited()
Definition: tree.hh:163
static Type infereSigType(Tree term, Tree env)
Infere the type of a term according to its surrounding type environment.
Tabber TABBER(1)
Definition: tree.cpp:87

Here is the call graph for this function:

Here is the caller graph for this function:

void typeAnnotation ( Tree  sig)

Fully annotate every subtree of term with type information.

Annotates a signal term and its subterms with type information.

Parameters
sigthe signal term tree to annotate

Definition at line 89 of file sigtyperules.cpp.

References getSigType(), hd(), initialRecType(), isList(), isRec(), len(), setSigType(), CTree::startNewVisit(), symlist(), T(), and tl().

Referenced by DocCompiler::annotate(), ScalarCompiler::prepare(), and ScalarCompiler::prepare2().

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 }
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
Tree hd(Tree l)
Definition: list.hh:133
static Type initialRecType(Tree t)
Compute an initial type solution for a recursive block E1,E2,...En -> TREC,TREC,...TREC.
static Type getSigType(Tree sig)
Retrieve the type annotation of sig.
static void startNewVisit()
Definition: tree.hh:161
bool isList(Tree l)
Definition: list.hh:138
static Tree NULLTYPEENV
The empty type environment (also property key for closed term type)
static Type T(Tree term, Tree env)
Shortcut to getOrInferType, retrieve or infere the type of a term according to its surrounding type e...
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree symlist(Tree sig)
int len(Tree l)
Definition: list.cpp:198
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int countInferences
static

Definition at line 79 of file sigtyperules.cpp.

int countMaximal
static

Definition at line 80 of file sigtyperules.cpp.

Tree NULLTYPEENV = tree(symbol("NullTypeEnv"))
static

The empty type environment (also property key for closed term type)

Definition at line 77 of file sigtyperules.cpp.