[Gridflow-cvs] [svn] commit: r3395 - in /trunk/base: flow_objects.c grid.c grid.h main.c source_filter.rb

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Tue Apr 1 18:17:24 EDT 2008


Author: matju
Date: Tue Apr  1 18:17:23 2008
New Revision: 3395

Log:
don't use method_missing for handling lists and floats as grids

Modified:
    trunk/base/flow_objects.c
    trunk/base/grid.c
    trunk/base/grid.h
    trunk/base/main.c
    trunk/base/source_filter.rb

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Tue Apr  1 18:17:23 2008
@@ -119,7 +119,7 @@
 	\decl void initialize(Ruby x, NumberTypeE cast=int32_e);
 	\decl 0 reset();
 	\decl 0 symbol(t_symbol *x);
-	\decl 0 list(...);
+	//\decl 0 list(...); !@#$
 	\decl 1 per_message();
 	\grin 0
 	\grin 1 int32
@@ -148,10 +148,7 @@
 	process(n,(uint8 *)name);
 }
 
-\def 0 list(...) {
-	if (in.size()<1 || !in[0]) _0_grid(0,0); //HACK: enable grid inlet...
-	in[0]->from_ruby_list(argc,argv,cast);
-}
+//\def 0 list(...) {in[0]->from_ruby_list(argc,argv,cast);} !@#$
 
 \def 1 per_message() { dim=0; dim_grid=0; }
 
@@ -225,7 +222,7 @@
 	int maxrows;
 	int columns;
 	t_pd *dest;
-	\decl 0 dest (Pointer *p);
+	\decl 0 dest (void *p);
 	\decl void initialize (t_symbol *name=0);
 	\decl void end_hook ();
 	\decl 0 base (int x);
@@ -299,10 +296,7 @@
        Data_Get_Struct(pointer,Pointer,foo);
        return (t_pd *)foo->p;
 }*/
-\def 0 dest (Pointer *p) {
-	dest = *(t_pd **)(p->p); // what's THIS ???
-	//fprintf(stderr,"#print:_0_dest    rself=%lx self=%p bself=%p p=%p dest=%p\n",rself,this,bself,p,dest);
-}
+\def 0 dest (void *p) {dest = (t_pd *)p;}
 \def void end_hook () {}
 \def 0 base (int x) { if (x==2 || x==8 || x==10 || x==16) base=x; else RAISE("base %d not supported",x); }
 \def 0 trunc (int x) {

Modified: trunk/base/grid.c
==============================================================================
--- trunk/base/grid.c (original)
+++ trunk/base/grid.c Tue Apr  1 18:17:23 2008
@@ -440,7 +440,7 @@
 
 // this does auto-conversion of list/float to grid
 // this also (will) do grid inputs for ruby stuff.
-\def Ruby method_missing (...) {
+\def Ruby meuthod_missing (...) {
     {
 	if (argc<1) RAISE("not enough arguments");
 	if (!SYMBOL_P(argv[0])) RAISE("expected symbol");
@@ -472,15 +472,11 @@
     }
     hell: return rb_call_super(argc,argv);
 }
-
 \classinfo {}
 \end class GridObject
 
-Ruby cGridObject;
-
 void startup_grid () {
 	\startall
-	cGridObject = rb_const_get(mGridFlow,SI(GridObject));
 }
 
 // never call this. this is a hack to make some things work.

Modified: trunk/base/grid.h
==============================================================================
--- trunk/base/grid.h (original)
+++ trunk/base/grid.h Tue Apr  1 18:17:23 2008
@@ -249,9 +249,9 @@
 		if (TYPE(r)==T_STRING) return std::string(rb_str_ptr(r));
  		RAISE("want symbol");
 	}
-	operator Pointer * () const {
+	operator void * () const {
 		if (CLASS_OF(r)!=cPointer) RAISE("not a Pointer");
-		return (Pointer *)NUM2ULONG(rb_funcall(r,SI(ptr),0));
+		return (void *)NUM2ULONG(rb_funcall(r,SI(ptr),0));
 	}
 	static R value(VALUE r) {R x; x.r=r; return x;}
 #define FOO(As,Op) \
@@ -337,7 +337,7 @@
 // you shouldn't use MethodDecl directly (used by source_filter.rb)
 struct MethodDecl { const char *selector; RMethod method; };
 void define_many_methods(Ruby rself, int n, MethodDecl *methods);
-extern Ruby mGridFlow, cFObject, cGridObject, cFormat;
+extern Ruby mGridFlow, cFObject, cFormat;
 
 #undef check
 
@@ -759,7 +759,7 @@
 };
 
 //****************************************************************
-// for use by source_filter.rb ONLY (for \grin and \classinfo)
+// for use by source_filter.rb ONLY (for \grin)
 #ifndef HAVE_LITE
 #define GRIN(TB,TS,TI,TL,TF,TD,TR) {TB,TS,TI,TL,TF,TD}
 #else
@@ -868,7 +868,7 @@
 			if (in[i] && in[i]!=gin && in[i]->dim) return true;
 		return false;
 	}
-	\decl Ruby method_missing(...);
+	\decl Ruby meuthod_missing(...);
 };
 \end class GridObject
 

Modified: trunk/base/main.c
==============================================================================
--- trunk/base/main.c (original)
+++ trunk/base/main.c Tue Apr  1 18:17:23 2008
@@ -233,7 +233,6 @@
 }
 
 \def void send_out (...) {
-	int n=0;
 	if (argc<1) RAISE("not enough args");
 	int outlet = INT(*argv);
 	if (outlet<0 || outlet>=64) RAISE("invalid outlet number: %d",outlet);
@@ -303,9 +302,8 @@
 	DATA_PTR(rself) = 0; // really!
 	delete this; // really!
 }
-
 \classinfo
-\end class FObject
+\end class
 
 /* ---------------------------------------------------------------- */
 /* C++<->Ruby bridge for classes/functions in base/number.c */

Modified: trunk/base/source_filter.rb
==============================================================================
--- trunk/base/source_filter.rb (original)
+++ trunk/base/source_filter.rb Tue Apr  1 18:17:23 2008
@@ -125,9 +125,9 @@
 	end
 	type.gsub!(/\s+/,"")
 	if type=="bool" then
-		handle_decl "void _0_#{name} (#{type} #{name}=true);"
-	else
-		handle_decl "void _0_#{name} (#{type} #{name});"
+		handle_decl "0 #{name} (#{type} #{name}=true);"
+	else
+		handle_decl "0 #{name} (#{type} #{name});"
 	end
 end
 
@@ -215,7 +215,6 @@
 	}.join(",")
 	Out.print "}; static FClass ci#{cl} = { #{cl}_allocator, #{cl}_startup,"
 	Out.print "#{cl.inspect}, COUNT(#{cl}_methods), #{cl}_methods };"
-#	STDERR.puts "attributes: "+
 	get="void ___get(t_symbol *s) {"
 	get << "t_atom a[1];"
 	frame.attrs.each {|name,attr|
@@ -231,10 +230,10 @@
 	startup2 = "@gfattrs = {"
 	frame.attrs.each {|name,attr| startup2 += ":#{name} => []," }
 	startup2 += "}"
-	line.gsub!(/\{/,"{"+"IEVAL(rself,\"#{startup2}\");") or raise "\\classinfo line should have a '{' (sorry)"
+	line.gsub!(/^\s*(\w+\s*)?\{/,"")
 	get << "RAISE(\"unknown attr %s\",s->s_name); outlet_anything(bself->out[bself->nout-1],s,1,a);}"
 	handle_def get if frame.attrs.size>0
-	Out.print "void #{frame.name}_startup (Ruby rself) "+line.chomp
+	Out.print "void #{frame.name}_startup (Ruby rself) {IEVAL(rself,\"#{startup2}\");"+line.chomp
 end
 
 def handle_grin(line)
@@ -244,7 +243,9 @@
 	Out.print "template <class T> void grin_#{i}(GridInlet *in, long n, T *data);"
 	Out.print "template <class T> static void grinw_#{i} (GridInlet *in, long n, T *data);"
 	Out.print "static GridHandler grid_#{i}_hand;"
-	handle_decl "Ruby _#{i}_grid(...);"
+	handle_decl "#{i} grid(void *foo);"
+	handle_decl "#{i} list(...);"
+	handle_decl "#{i} float(float f);"
 	$stack[-1].grins[i] = fields.dup
 end
 
@@ -260,7 +261,7 @@
 		frame.attrs.each {|name,attr|
 			type,name,default = attr.to_a
 			#STDERR.puts "type=#{type} name=#{name} default=#{default}"
-			#handle_def "void _0_#{name} (#{type} #{name}) { this->#{name}=#{name}; }"
+			#handle_def "0 #{name} (#{type} #{name}) { this->#{name}=#{name}; }"
 		}
 		frame.grins.each {|i,v|
 			cli = "#{cl}::grinw_#{i}"
@@ -272,11 +273,19 @@
 			else raise 'BORK BORK BORK' end
 			ks = k.map{|ke| if ke==0 then 0 else cli end}.join(",")
 			Out.print "static GridHandler #{cl}_grid_#{i}_hand = GRIN(#{ks});"
-			handle_def "Ruby _#{i}_grid(...) {"+
+			handle_def "#{i} grid(void *foo) {"+
 				"if (in.size()<=#{i}) in.resize(#{i}+1);"+
 				"if (!in[#{i}]) in[#{i}]=new GridInlet((GridObject *)this,&#{cl}_grid_#{i}_hand);"+
-				"return in[#{i}]->begin(argc,argv);}"
-
+				"in[#{i}]->begin(argc,argv);}"
+			handle_def "#{i} list(...) {"+
+				"if (in.size()<=#{i}) in.resize(#{i}+1);"+
+				"if (!in[#{i}]) in[#{i}]=new GridInlet((GridObject *)this,&#{cl}_grid_#{i}_hand);"+
+				"in[#{i}]->from_ruby_list(argc,argv,int32_e);}"
+			handle_def "#{i} float(float f) {"+
+				"if (in.size()<=#{i}) in.resize(#{i}+1);"+
+				"if (!in[#{i}]) in[#{i}]=new GridInlet((GridObject *)this,&#{cl}_grid_#{i}_hand);"+
+				"Ruby a[]={rb_float_new(f)};"+
+				"in[#{i}]->from_ruby(1,a);}"
 		}
 		if /^class\s*(\w+\s+)?\{(.*)/ =~ line then handle_classinfo("{"+$2) end
 		$stack.pop



More information about the Gridflow-cvs mailing list