[Gridflow-cvs] [svn] commit: r6339 - in /trunk/src: expr.cxx gem.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Fri Sep 24 12:13:39 EDT 2010


Author: matju
Date: Fri Sep 24 12:13:38 2010
New Revision: 6339

Log:
support unary ! ~

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

Modified: trunk/src/expr.cxx
==============================================================================
--- trunk/src/expr.cxx (original)
+++ trunk/src/expr.cxx Fri Sep 24 12:13:38 2010
@@ -45,7 +45,7 @@
 		while (*s && isspace(*s)) s++;
 		if (!*s) tok.a_type=A_NULL;
 		else if (isdigit(*s) || *s=='.') {char *e; tok = strtof(s,&e); s=(const char *)e;}
-		else if (strchr("+-*/%&|^<>=!",*s)) {
+		else if (strchr("+-*/%&|^<>=!~",*s)) {
 			char t[3]={0,0,0};
 			t[0]=*s++;
 			if (*s==s[-1] || *s=='=') t[1]=*s++;
@@ -58,18 +58,27 @@
 		else RAISE("syntax error at character '%c'",*s);
 		toks.push_back(tok);
 	}
+	void add (const t_atom2 &a) {
+		if (a.a_type==A_OP1 && a.a_symbol==gensym("~")) {
+			code.push_back(-1);
+			code.push_back(t_atom2(A_OP,gensym("^")));
+		} else code.push_back(a);
+	}
 	void parse (const char *&s, int level=0, t_atom2 prevop=t_atom2(A_NULL,0)) {
 		//post("%*sbegin (prevop=%s)",level*2,"",prevop?prevop->s_name:"(null)");
            	next(s);
            top:
 		switch (int(tok.a_type)) {
-		  case A_OP:
-			if      (tok.a_symbol==gensym("+")) {parse(s,level,t_atom2(A_OP1,tok.a_symbol));}
-			else if (tok.a_symbol==gensym("-")) {parse(s,level,t_atom2(A_OP1,tok.a_symbol));}
+		  case A_OP: {
+			t_symbol *o = tok.a_symbol;
+			if      (o==gensym("+")) {parse(s,level,t_atom2(A_OP1,tok.a_symbol));}
+			else if (o==gensym("-")) {parse(s,level,t_atom2(A_OP1,tok.a_symbol));}
+			else if (o==gensym("!")) {parse(s,level,t_atom2(A_OP1,gensym("==")));}
+			else if (o==gensym("~")) {parse(s,level,t_atom2(A_OP1,tok.a_symbol));}
 			else RAISE("can't use '%s' as a unary prefix operator",tok.a_symbol->s_name);
-			break;
+		  } break;
 		  case A_FLOAT: case A_SYMBOL: case A_VAR:
-			code.push_back(tok);
+			add(tok);
 		  infix: // this section could become another method
 			next(s);
 			switch (int(tok.a_type)) {
@@ -79,17 +88,17 @@
 					if (!priority2) RAISE("unknown operator '%s'",tok.a_symbol->s_name);
 					//post("priorities %d %d",priority1,priority2);
 					if (priority1 <= priority2) {
-						code.push_back(prevop);
+						add(prevop);
 						parse(s,level,tok);
 					} else {
 						parse(s,level,tok);
-						if (prevop.a_type!=A_NULL) code.push_back(prevop);
+						if (prevop.a_type!=A_NULL) add(prevop);
 					}
 				} break;
 				case A_CLOSE: case A_NULL: case A_SEMI: {
 					if (level && int(tok.a_type)!=A_CLOSE) RAISE("missing ')' %d times",level);
-					if (prevop.a_type!=A_NULL) code.push_back(prevop);
-					if (tok.a_type==A_SEMI) code.push_back(t_atom2(A_SEMI,0));
+					if (prevop.a_type!=A_NULL) add(prevop);
+					if (tok.a_type==A_SEMI) add(t_atom2(A_SEMI,0));
 					return;
 				}
 				default: {
@@ -156,7 +165,7 @@
 void startup_classes4 () {
 	#define PR1(SYM) priorities[t_atom2(A_OP1,gensym(#SYM))]
 	#define PR(SYM)  priorities[t_atom2(A_OP ,gensym(#SYM))]
-	PR1(-) = 3;
+	PR1(-) = PR(==) = 3; // unary "==" is "!"
 	PR(*) = PR(/) = PR(%) = 5;
 	PR(+) = PR(-) = 6;
 	PR(<<) = PR(>>) = 7;

Modified: trunk/src/gem.cxx
==============================================================================
--- trunk/src/gem.cxx (original)
+++ trunk/src/gem.cxx Fri Sep 24 12:13:38 2010
@@ -184,6 +184,10 @@
 
 //------------------------------------------------------------------------
 
+// LinuxIntel y:6409 yuv:34233
+//   OsxIntel y:6409 yuv:34233
+//   OsxPPC   y:6409 yuv:
+
 \class GridFromPix : FObject {
 	P<BitPacking> bp_rgba;
 	P<BitPacking> bp_bgra;
@@ -206,7 +210,7 @@
 		  #ifdef GL_VERSION_1_2
 		  case GL_BGRA: bp = bp_bgra; break;
 		  #endif
-		  //case GL_LUMINANCE: break;
+		  //case GL_LUMINANCE: bp=bp_grey; break;
 		  //case 0x85b9: break;
 		  default: ::post("can't produce grid from pix format %d (0x%x)",im.format,im.format); return;}
 		switch (im.type) {
@@ -259,6 +263,11 @@
 		bp_rgba = new BitPacking(is_le(),4,4,rgba);
 		bp_bgra = new BitPacking(is_le(),4,4,bgra);
 	} else
+	if (s==gensym("y")) {
+		channels=1;
+		bp_rgba = 0;
+		bp_bgra = 0;
+	}
 	RAISE("unknown colorspace '%s'",s->s_name);
 }
 \def 0 gem_state (...) {if (argc==2) render((GemState *)(void *)argv[1]);}



More information about the Gridflow-cvs mailing list