94 vector<Tree> vrec, vdef;
100 assert(
isRec(
hd(l),
id, body));
105 vrec.push_back(
hd(l));
106 vdef.push_back(body);
110 for (
int i=0; i<n; i++) {
114 assert (
int(vrec.size())==n);
115 assert (
int(vdef.size())==n);
116 assert (
int(vtype.size())==n);
119 for (
bool finished =
false; !finished; ) {
123 for (
int i=0; i<n; i++) {
125 vrec[i]->setVisited();
129 for (
int i=0; i<n; i++) {
130 vtype[i] =
T(vdef[i], NULLTYPEENV);
135 for (
int i=0; i<n; i++) {
137 finished = finished & (
getSigType(vrec[i]) == vtype[i]);
148 cerr <<
TABBER <<
"COUNT INFERENCE " << countInferences <<
" AT TIME " << clock()/CLOCKS_PER_SEC <<
's' << endl;
150 cerr <<
TABBER <<
"COUNT MAXIMAL " << countMaximal << endl;
181 TRACE(cerr <<
TABBER <<
"SET FIX TYPE OF " << *sig <<
" TO TYPE " << *t << endl;)
194 TRACE(cerr <<
TABBER <<
"GET FIX TYPE OF " << *sig <<
" HAS NO TYPE YET" << endl;)
196 TRACE(cerr <<
TABBER <<
"GET FIX TYPE OF " << *sig <<
" IS TYPE " << *ty << endl;)
225 TRACE(cerr << ++
TABBER <<
"ENTER T() " << *term << endl;)
229 TRACE(cerr << --
TABBER <<
"EXIT 1 T() " << *term <<
" AS TYPE " << *ty << endl);
236 TRACE(cerr << --
TABBER <<
"EXIT 2 T() " << *term <<
" AS TYPE " << *ty << endl);
253 Tree sel, s1, s2, s3, ff, id, ls, l, x, y, z, u, var, body, type,
name, file;
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;
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;
317 }
else if ((i>=
kGT) && (i<=
kNE)) {
351 else if (
isSigAttach(sig, s1, s2)) {
T(s2,env);
return T(s1,env); }
363 else if (
isSigGen(sig, s1))
return T(s1,NULLTYPEENV);
366 else if (
isSigDocWriteTbl(sig,x,y,z,u) )
return infereDocWriteTblType(
T(x,env),
T(y,env),
T(z,env),
T(u,env));
385 else if (
isSigSelect3(sig,sel,s1,s2,s3)) {
return T(sel,env)|
T(s1,env)|
T(s2,env)|
T(s3,env); }
389 else if (
isList(sig)) {
return T(
hd(sig),env ) *
T(
tl(sig),env ); }
392 fprintf(stderr,
"ERROR infering signal type : unrecognized signal : ");
print(sig, stderr); fprintf(stderr,
"\n");
406 cerr <<
"ERROR infering projection type, not a tuplet type : " << t << endl;
411 Type temp = (*tt)[i] ->promoteVariability(t->variability())
412 ->promoteComputability(t->computability())
413 ->promoteVectorability(vec);
431 cerr <<
"ERROR infering write table type, wrong table type : " << tbl << endl;
436 cerr <<
"ERROR infering write table type, wrong write index type : " << wi << endl;
441 int v = wi->variability() | wd->variability();
442 int c = wi->computability() | wd->computability();
443 int vec = wi->vectorability() | wd->vectorability();
458 cerr <<
"ERROR infering read table type, wrong table type : " << tbl << endl;
463 cerr <<
"ERROR infering read table type, wrong write index type : " << ri << endl;
468 ->promoteComputability(ri->computability()|tt->
computability())
469 ->promoteVectorability(ri->vectorability()|tt->
vectorability())
470 ->promoteBoolean(ri->boolean()|tt->
boolean())
490 ->promoteVariability(
kSamp)
491 ->promoteComputability(widx->computability()|wsig->computability())
492 ->promoteVectorability(
kScal)
493 ->promoteNature(wsig->nature())
494 ->promoteBoolean(wsig->boolean())
502 ->promoteVariability(ridx->variability())
503 ->promoteComputability(ridx->computability())
504 ->promoteVectorability(ridx->vectorability())
551 while (
isList(ls)) { t = t|
T(
hd(ls),env); ls=
tl(ls); }
600 int n = wfsig->
arity();
604 std::cerr <<
"ERROR, empty waveform" << std::endl;
612 for (
int i = 1; i < n; i++) {
639 for (
int i = 0; i < sig->
arity(); i++) vt.push_back(
T(sig->
branch(i), env));
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;
675 cerr <<
"Unrecognized opcode : " << opcode << endl;
bool isSigRDTbl(Tree s, Tree &t, Tree &i)
bool isSigHSlider(Tree s)
Type checkInit(Type t)
verifie que t est connu a l'initialisation
Type checkKonst(Type t)
verifie que t est constant
bool valid
true if it is a valid interval
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
int variability() const
returns how fast values change (constant, by blocks, by samples)
bool isSigCheckbox(Tree s)
virtual Type infereSigType(const vector< Type > &args)=0
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
static int gAllocationCount
bool isSigNumEntry(Tree s)
bool isSigSelect2(Tree t, Tree &selector, Tree &s1, Tree &s2)
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
The type of a tuplet of data.
void annotationStatistics()
print annotation statistics
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
static Type infereReadTableType(Type tbl, Type ri)
Infere the type of the result of reading a table.
Type content() const
return the type of data store in the table
int boolean() const
returns when a signal stands for a boolean value
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.
void typeAnnotation(Tree sig)
Fully annotate every subtree of term with type information.
bool isSigInput(Tree t, int *i)
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)
const Node & node() const
return the content of the tree
static Type initialRecType(Tree t)
Compute an initial type solution for a recursive block E1,E2,...En -> TREC,TREC,...TREC.
bool isSigVBargraph(Tree s)
bool isSigSelect3(Tree t, Tree &selector, Tree &s1, Tree &s2, Tree &s3)
bool isSigVSlider(Tree s)
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.
double max(double x, double y)
static Type getSigType(Tree sig)
Retrieve the type annotation of sig.
bool isSigGen(Tree t, Tree &x)
static void startNewVisit()
static Type infereDocConstantTblType(Type size, Type init)
bool isSigReal(Tree t, double *r)
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)
static interval arithmetic(int opcode, const interval &x, const interval &y)
Compute the resulting interval of an arithmetic operation.
bool isSigHBargraph(Tree s)
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
The type of a simple numeric audio signal.
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
static Tree NULLTYPEENV
The empty type environment (also property key for closed term type)
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
bool isSigDocAccessTbl(Tree t, Tree &tbl, Tree &ridx)
static Type infereFConstType(Tree type)
Infere the type of a foreign constant.
AudioType * makeTableType(const Type &ct)
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
interval reunion(const interval &x, const interval &y)
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
int arity() const
return the number of branches (subtrees) of a tree
TableType * isTableType(AudioType *t)
int nature() const
returns the kind of values (integre or floating point)
static Type infereDocAccessTblType(Type tbl, Type ridx)
const char * name(Symbol *sym)
Returns the name of a symbol.
static Type infereWaveformType(Tree lv, Tree env)
Infere the type of a waveform:
bool isSigWaveform(Tree s)
TupletType * isTupletType(AudioType *t)
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)
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
static Type infereFVarType(Tree type)
Infere the type of a foreign variable.
bool isSigDocWriteTbl(Tree t, Tree &n, Tree &sig, Tree &widx, Tree &wsig)
bool isSigDelay1(Tree t, Tree &t0)
static Type infereSigType(Tree term, Tree env)
Infere the type of a term according to its surrounding type environment.
bool isSigFloatCast(Tree t)
void * getUserData(Symbol *sym)
Returns user data.
bool isSigIntCast(Tree t)
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Type castInterval(Type t, const interval &i)
SimpleType * isSimpleType(AudioType *t)
bool isProj(Tree t, int *i, Tree &rgroup)
API to the typing system of signals.
bool isInt(const Node &n)
static Type infereFFType(Tree ff, Tree ls, Tree env)
Infere the type of a foreign function call.
double min(double x, double y)
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Tree branch(int i) const
return the ith branch (subtree) of a tree
static int countInferences
The Root class for all audio data types.
bool isSigOutput(Tree t, int *i, Tree &t0)
int vectorability() const
returns when a signal can be vectorized
static Type infereDocWriteTblType(Type size, Type init, Type widx, Type wsig)
Type checkInt(Type t)
verifie que t est entier
void print(Tree t, FILE *out)