[Gridflow-cvs] [svn] commit: r6386 - in /trunk/src: expr.cxx numop1.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sat Oct 2 14:05:41 EDT 2010


Author: matju
Date: Sat Oct  2 14:05:40 2010
New Revision: 6386

Log:
complete the previous fix, and also fix [#expr -$f1] and [#expr abs($f1)]

Modified:
    trunk/src/expr.cxx
    trunk/src/numop1.cxx

Modified: trunk/src/expr.cxx
==============================================================================
--- trunk/src/expr.cxx (original)
+++ trunk/src/expr.cxx Sat Oct  2 14:05:40 2010
@@ -94,9 +94,8 @@
 		switch (int(tok.a_type)) {
 		  case A_OP: { // unary
 			t_symbol *o = tok.a_symbol;
-			if      (o==gensym("+")) {parse(context,t_atom2(A_OP1,tok.a_symbol));}
-			else if (o==gensym("-")) {parse(context,t_atom2(A_OP1,gensym("inv+")));}
-			else if (o==gensym("!") || o==gensym("~")) {parse(context,t_atom2(A_OP1,o));}
+			if (o==gensym("+") || o==gensym("!") || o==gensym("~")) {parse(context,t_atom2(A_OP1,o));}
+			else if (o==gensym("-")) {parse(context,t_atom2(A_OP1,gensym("unary-")));}
 			else RAISE("can't use '%s' as a unary prefix operator",tok.a_symbol->s_name);
 		  } break;
 		  case A_FLOAT: case A_SYMBOL: case A_VAR:
@@ -118,8 +117,7 @@
 					RAISE("syntax error (c) tok=%s type=%s",z.data(),zt.data());
 				}
 				t_symbol *o = a.a_symbol; int e=1;
-				if   (a==gensym("abs"))                {a=t_atom2(A_OP1,gensym("abs-"));}
-				else if (priorities[t_atom2(A_OP1,o)]) {a=t_atom2(A_OP1,o);}
+				if      (priorities[t_atom2(A_OP1,o)]) {a=t_atom2(A_OP1,o);}
 				else if (priorities[t_atom2(A_OP ,o)]) {a=t_atom2(A_OP ,o); e=2;}
 				else RAISE("unknown function '%s'",o->s_name);
 				if (parse(2)!=e) RAISE("wrong number of arguments for '%s'",o->s_name);
@@ -235,9 +233,9 @@
 void startup_classes4 () {
 	#define PR1(SYM) priorities[t_atom2(A_OP1,gensym(#SYM))]
 	#define PR(SYM)  priorities[t_atom2(A_OP ,gensym(#SYM))]
-	PR1(sin) = PR1(cos) = PR1(exp) = PR1(log) = PR1(tanh) = PR1(sqrt) = PR1(abs-) = PR1(rand) = 2;
+	PR1(sin) = PR1(cos) = PR1(exp) = PR1(log) = PR1(tanh) = PR1(sqrt) = PR1(abs) = PR1(rand) = 2;
 	PR(min) = PR(max) = PR(div) = PR(rem) = PR(cmp) = PR(hypot) = PR(atan2) = PR(avg) = 2;
-	PR1(+) = PR1(inv+) = PR1(~) = PR1(!) = 3; // unary "-" is "inv+"
+	PR1(+) = PR1(unary-) = PR1(~) = PR1(!) = 3;
 	PR(*) = PR(/) = PR(%) = 5;
 	PR(+) = PR(-) = 6;
 	PR(<<) = PR(>>) = 7;

Modified: trunk/src/numop1.cxx
==============================================================================
--- trunk/src/numop1.cxx (original)
+++ trunk/src/numop1.cxx Sat Oct  2 14:05:40 2010
@@ -66,6 +66,11 @@
 #define DECL_VOP_NOFLOAT( O,sym,dim) DECLOP_NOFLOAT(VOL,DECL_OPON,O,sym,dim)
 #define DECL_VOP_FLOAT(   O,sym,dim) DECLOP_FLOAT(  VOL,DECL_OPON,O,sym,dim)
 
+DEF_OP(logic_not, !a);
+DEF_OP(not, -1-a); // because ~a doesn't exist for T=float
+DEF_OP(unary_minus, -a); // for use by #expr
+DEF_OP(abs, a<0 ? -a : a);
+
 DEF_OPF(sqrt,floor(sqrt(a)),sqrt(a))
 DEF_OP(rand, a==0 ? (T)0 : (T)(random()%(int32)a))
 
@@ -82,6 +87,11 @@
 DEF_OP(cx_log,  log(a))
 
 Numop1 op_table_unary[] = {
+	DECL_OP(unary_minus, "unary-"),
+	DECL_OP(logic_not, "!"),
+	DECL_OP(not, "~"),
+	DECL_OP(abs, "abs"),
+
 	DECL_OP(sqrt, "sqrt"),
 	DECL_OP(rand, "rand"),
 	DECL_OP_FLOAT(sin,  "sin"),



More information about the Gridflow-cvs mailing list