PRINT < END
/* 
   WARNING: This file is generated automaticaly from expressions.tmpl 
     - all changes you made into this file will be distarded in next
       recompilation!  
*/

#include <stdio.h>
#include <math.h>
#include "expressions.h"

void ex_push_const(void);
void ex_push_vector3(void);
void ex_push_vector4(void);
void ex_push_color_noise(void);
void ex_push_color_noise_xy(void);

void warp_abs_push_xy();
void warp_rel_push_xy();
void pop_xy();

END


TABLE FuncInfo < END_TABLE
// N - arbitrary number of parameters, 1<= N <= MAX_NUMBER_OF_PARAMETERS
//	or arbitrary (return|parameter) type
// R - return value, P?, P0...PN parameters, NOP - not yet implemented
//	name	     nof[pd]	altstring  ret_types paramtypes func0 code

	const		0 1	  ""		1	-	LAST( ex_push_const )
								
	vector3 	0 3	  ""		3	-	LAST( ex_push_vector3 )
	vector4 	0 4	  ""		4	-	LAST( ex_push_vector4 )
								
								
	x		0 0	  -		1	-	RETURN{{ x_val }}
	y		0 0	  -		1	-	RETURN{{ y_val }}
								
								
	plus		N 0	  "+"		N	-	INIT{{R=P0;}} BODY{{1..N-1, R+= P?; }}
	minus		2 0	  "-"		N	-	RETURN{{ P0-P1 }}
	mult		N 0	  "*"		N	-	INIT{{R=P0;}} BODY{{1..N-1, R*= P?; }}
	div		2 0	  "/"		N	-	RETURN{{ (P1!=0.0)?P0/P1:INFINITY }}
//	mod		2 0	  "%"		N	-	RETURN{{ 0.0; /*HOW TO IMPLEMENT IT ?? */ }}
								
	min		N 0	  -		N	-	INIT{{R=P0;}} BODY{{1..N-1, if (R>P?) R=P?; }}
	max		N 0	  - 		N	-	INIT{{R=P0;}} BODY{{1..N-1, if (R<P?) R=P?; }}
								
								
   	and		N 0	  "&"		N	-	INIT{{R=P0;}} BODY{{1..N-1,R=double_and(R,P?);}}
  	or		N 0	  "|"		N	-	INIT{{R=P0;}} BODY{{1..N-1,R=double_or (R,P?);}}
  	xor		N 0	  "^"		N	-	INIT{{R=P0;}} BODY{{1..N-1,R=double_xor(R,P?);}}
								
//	bw_noise_xy	0 0   "bw-noise-xy"	1	-	RETURN{{ solid_noise(x_val,y_val) }}
	bw_noise	2 0   "bw-noise"	1	11	RETURN{{ solid_noise( P0, P1) }}
								
//	color_noise_xy	0 0  "color-noise-xy"	3	-	LAST ( ex_push_color_noise_xy )
	color_noise   	2 0  "color-noise"	3	11	LAST ( ex_push_color_noise )
								
	warp_abs	3 0   "warp-abs"	N	11N	PUSH2(warp_abs_push_xy) PUSH3(pop_xy)
	warp_rel	3 0   "warp-rel"	N	11N     PUSH2(warp_rel_push_xy) PUSH3(pop_xy)
								
// boring functions :-)						
	floor		1 0	  -		N	-	RETURN{{ floor(P0) }}
	abs		1 0	  -		N	-	RETURN{{ fabs(P0) }}
								
	exp		1 0	  -		N	-	RETURN{{ exp(P0) }}
	log		1 0	  -		N	-	RETURN{{ log(P0) }}
	pow		2 0	  -		N	-	RETURN{{ pow(P0,P1) }}
								
	sin  		1 0	  -		N	-	RETURN{{ sin(P0) }}
	cos		1 0	  -		N	-	RETURN{{ cos(P0) }}
	atan		1 0	  -		N	-	RETURN{{ atan(P0) }}
END_TABLE

// flush all definition, tables etc to expr_pgen.c
	
FLUSH

// other functions...
PRINT < END

void ex_push_const(void)
{
  r_top++;  *r_top= *data_top;  data_top++;
}

void ex_push_vector3(void)
{
  r_top++;  *r_top= *data_top;  data_top++;
  g_top++;  *g_top= *data_top;  data_top++;
  b_top++;  *b_top= *data_top;  data_top++;
}

void ex_push_vector4(void)
{
  r_top++;  *r_top= *data_top;  data_top++;
  g_top++;  *g_top= *data_top;  data_top++;
  b_top++;  *b_top= *data_top;  data_top++;
  alfa_top++;  *alfa_top= *data_top;  data_top++;
}

void ex_push_color_noise(void)
{
 r_top--; *r_top= solid_noise(r_top[0]+128.,r_top[1]+199.);
 g_top--; *g_top= solid_noise(g_top[0]+232.,g_top[1]+ 74.);
 b_top--; *b_top= solid_noise(b_top[0]+312.,b_top[1]+ 32.);
}

void ex_push_color_noise_xy(void)
{
 r_top++; *r_top= solid_noise(x_val+128.,y_val+199.);
 g_top++; *g_top= solid_noise(x_val+232.,y_val+ 74.);
 b_top++; *b_top= solid_noise(x_val+312.,y_val+ 32.);
}

static DBL x_stack[MAX_TREE_DEPTH];
static DBL y_stack[MAX_TREE_DEPTH];

static DBL *xptr = x_stack,
	   *yptr = y_stack;

void warp_abs_push_xy()
{
  *xptr= x_val;  xptr++;
  *yptr= y_val;  yptr++;

  x_val= *r_top; r_top--;
  y_val= *r_top; r_top--;
}

void warp_rel_push_xy()
{
  *xptr= x_val;  xptr++;
  *yptr= y_val;  yptr++;

  x_val+= *r_top; r_top--;
  y_val+= *r_top; r_top--;
}

void pop_xy()
{
  xptr--;  yptr--;
  x_val= *xptr; y_val= *yptr;
}
END


END_OF_FILE