Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement the "internal" builtin environment #940

Open
wants to merge 2 commits into
base: master-dev
Choose a base branch
from

Conversation

oleg-nesterov
Copy link
Contributor

No description provided.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant