implement the "internal" builtin environment#940
Open
oleg-nesterov wants to merge 2 commits intograme-cncm:master-devfrom
Open
implement the "internal" builtin environment#940oleg-nesterov wants to merge 2 commits intograme-cncm:master-devfrom
oleg-nesterov wants to merge 2 commits intograme-cncm:master-devfrom
Conversation
NOTE: this patch touches compiler/parser/, so you obviously need
"cd compiler/parser; make" before "make" to build the compiler.
This patch adds the new keyword `internal` which returns the builtin
environment with 2 primitives (so far):
1. id(sig) - sig->serial()
2. rate(sig) - getSigOrder(sig)
Note that they compute the returned value at compile time.
//-------------------------------------------------------------------
rate(sig) - returns the computability
Example:
process = sin(1), ma.SR/2, nentry("",0,0,10,1), ba.time
: par(i,4,internal.rate);
outputs
output0[i0] = FAUSTFLOAT(0); // compile time const
output1[i0] = FAUSTFLOAT(1); // run time const
output2[i0] = FAUSTFLOAT(2); // block
output3[i0] = FAUSTFLOAT(3); // sample
//-------------------------------------------------------------------
id(sig) - returns the unique signal id. If the compiler can detect that
sig1 and sig2 are "equal", id(sig1) == id(sig2).
Example. Suppose we have
a = +(1);
s = -(1);
as = a : s;
sa = s : a;
id = internal.id;
Now,
process = _ <: id, id(as), id(sa);
or
process = _ <: _, as, sa : par(i,3,id);
outputs
output0[i0] = FAUSTFLOAT(241);
output1[i0] = FAUSTFLOAT(241);
output2[i0] = FAUSTFLOAT(241);
Another example:
process = _ <: id(as-sa), id(0);
outputs
output0[i0] = FAUSTFLOAT(8);
output1[i0] = FAUSTFLOAT(8);
//-------------------------------------------------------------------
Now a bit more useful example:
isZero = internal.id(float) == internal.id(0.0);
returns 1 if the input is compile time constant == 0 or 0.0,
otherwise 0. Afaics, it is not possible to implement such a
helper in faust.
This comes in a separate patch to a) show that it is very easy to add the new primitives, and b) add some documentation. So the new lo/hi primitives act as undocumented lowest/highest but actually work. Say, both process = lowest; and process = internal.lo; output output0[i0] = FAUSTFLOAT(-1.0f); But, say, process = +(1) : lowest; crashes the compiler, while process = +(1) : internal.lo; correctly outputs output0[i0] = FAUSTFLOAT(0.0f); (I guess the implementation of lowest/highest is not finished, with this patch this code can be removed). //------------------------------------------------------------ Example: ge(x,y) = internal.lo(x) >= internal.hi(y); returns 1 if the compiler can deduce at compile time that x >= y, otherwise 0. So process = _,_ <: _,_, +(1),-(1) : ge,ge; does not generate any code and outputs output0[i0] = FAUSTFLOAT(0); output1[i0] = FAUSTFLOAT(1); Again, I don't think it is possible to implement this in faust.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.