[Gridflow-cvs] [svn] commit: r3258 - in /trunk: base/flow_objects.rb base/grid.c base/grid.h base/main.c base/main.rb optional/fftw.c rubyext.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Thu Mar 20 15:43:30 EDT 2008


Author: matju
Date: Thu Mar 20 15:43:29 2008
New Revision: 3258

Log:
removed old @args and FObject#args, added new FObject#args reading from the binbuf, removed the FObject#info alias, renamed macro INFO to ARGS

Modified:
    trunk/base/flow_objects.rb
    trunk/base/grid.c
    trunk/base/grid.h
    trunk/base/main.c
    trunk/base/main.rb
    trunk/optional/fftw.c
    trunk/rubyext.c

Modified: trunk/base/flow_objects.rb
==============================================================================
--- trunk/base/flow_objects.rb (original)
+++ trunk/base/flow_objects.rb Thu Mar 20 15:43:29 2008
@@ -39,9 +39,7 @@
 			else "??? #{v.flags}"
 			end
 			post "%s %s: %s", modes, k, v.description
-			if v.respond_to? :info then
-				post "-> %s", v.info
-			end
+			post "-> %s", v.args
 		}
 		post "-"*32
 	end
@@ -589,7 +587,7 @@
 	def call; update; end
 	def _0_very_long_name_that_nobody_uses(*list)
 		@text << "\n" if @text.length>0
-		list.each {|x| @text<<x.to_i }
+		list.each {|x| @text << x.to_i }
 	end
 	install "display", 1, 1
 	gui_enable
@@ -612,6 +610,18 @@
 	}
 end
 end # respond to gui_enable
+
+FObject.subclass("printargs",1,0) {
+  def initialize(*args)
+    @aaargh = args
+    @clock = Clock.new self
+    @clock.delay 0
+  end
+  def call
+    post "ruby=%s", @aaargh.inspect
+    post "  pd=%s",    args.inspect
+  end
+}
 
 #-------- fClasses for: Hardware
 

Modified: trunk/base/grid.c
==============================================================================
--- trunk/base/grid.c (original)
+++ trunk/base/grid.c Thu Mar 20 15:43:29 2008
@@ -45,27 +45,27 @@
 	return self->p;
 }
 
-//#define TRACE fprintf(stderr,"%s %s [%s:%d]\n",INFO(parent),__PRETTY_FUNCTION__,__FILE__,__LINE__);
+//#define TRACE fprintf(stderr,"%s %s [%s:%d]\n",ARGS(parent),__PRETTY_FUNCTION__,__FILE__,__LINE__);
 #define TRACE
 
 #define CHECK_TYPE(d) \
 	if (NumberTypeE_type_of(&d)!=this->nt) RAISE("%s(%s): " \
 		"type mismatch during transmission (got %s expecting %s)", \
-		INFO(parent), __PRETTY_FUNCTION__, \
+		ARGS(parent), __PRETTY_FUNCTION__, \
 		number_type_table[NumberTypeE_type_of(&d)].name, \
 		number_type_table[this->nt].name);
 
 #define CHECK_BUSY1(s) \
-	if (!dim) RAISE("%s: " #s " not busy",INFO(parent));
+	if (!dim) RAISE("%s: " #s " not busy",ARGS(parent));
 
 #define CHECK_BUSY(s) \
-	if (!dim) RAISE("%s: " #s " not busy (wanting to write %ld values)",INFO(parent),(long)n);
+	if (!dim) RAISE("%s: " #s " not busy (wanting to write %ld values)",ARGS(parent),(long)n);
 
 #define CHECK_ALIGN(d) \
 	{int bytes = number_type_table[nt].size/8; \
 	int align = ((long)(void*)d)%bytes; \
 	if (align) {_L_;post("%s(%s): Alignment Warning: %p is not %d-aligned: %d", \
-		INFO(parent), __PRETTY_FUNCTION__, (void*)d,bytes,align);}}
+		ARGS(parent), __PRETTY_FUNCTION__, (void*)d,bytes,align);}}
 
 #define CHECK_ALIGN2(d,nt) \
 	{int bytes = number_type_table[nt].size/8; \
@@ -143,11 +143,11 @@
 // why this would be changed afterwards.
 void GridInlet::set_factor(long factor) {
 	if(!dim) RAISE("huh?");
-	if(factor<=0) RAISE("%s: factor=%d should be >= 1",INFO(parent),factor);
+	if(factor<=0) RAISE("%s: factor=%d should be >= 1",ARGS(parent),factor);
 	int i;
 	for (i=0; i<=dim->n; i++) if (dim->prod(i)==factor) break;
 	if (i>dim->n) RAISE("%s: set_factor: expecting dim->prod(i) for some i, "
-		"but factor=%ld and dim=%s",INFO(parent),factor,dim->to_s());
+		"but factor=%ld and dim=%s",ARGS(parent),factor,dim->to_s());
 	if (factor > 1) {
 		buf=new Grid(new Dim(factor), nt);
 		bufi=0;
@@ -184,14 +184,12 @@
 	GridOutlet *back_out = (GridOutlet *) Pointer_get(argv[0]);
 	nt = back_out->nt;
 	if (dim) RAISE("%s: grid inlet conflict; aborting %s in favour of %s, index %ld of %ld",
-			INFO(parent), INFO(sender), INFO(back_out->parent),
-			(long)dex, (long)dim->prod());
+			ARGS(parent), ARGS(sender), ARGS(back_out->parent), (long)dex, (long)dim->prod());
 	sender = back_out->parent;
 	if ((int)nt<0 || (int)nt>=(int)number_type_table_end)
-		RAISE("%s: inlet: unknown number type",INFO(parent));
+		RAISE("%s: inlet: unknown number type",ARGS(parent));
 	if (!supports_type(nt))
-		RAISE("%s: number type %s not supported here",
-			INFO(parent), number_type_table[nt].name);
+		RAISE("%s: number type %s not supported here", ARGS(parent), number_type_table[nt].name);
 	P<Dim> dim = this->dim = back_out->dim;
 	dex=0;
 	buf=0;
@@ -225,7 +223,7 @@
 	case 4:{
 		long d = dex + bufi;
 		if (d+n > dim->prod()) {
-			post("grid input overflow: %d of %d from [%s] to [%s]", d+n, dim->prod(), INFO(sender), 0);
+			post("grid input overflow: %d of %d from [%s] to [%s]", d+n, dim->prod(), ARGS(sender), 0);
 			n = dim->prod() - d;
 			if (n<=0) return;
 		}
@@ -274,15 +272,15 @@
 		dex = newdex;
 	}break;
 	case 0: break; // ignore data
-	default: RAISE("%s: unknown inlet mode",INFO(parent));
+	default: RAISE("%s: unknown inlet mode",ARGS(parent));
 	}
 }
 
 void GridInlet::finish() {TRACE;
-	if (!dim) RAISE("%s: inlet not busy",INFO(parent));
+	if (!dim) RAISE("%s: inlet not busy",ARGS(parent));
 	if (dim->prod() != dex) {
 		post("incomplete grid: %d of %d from [%s] to [%s]",
-			dex, dim->prod(), INFO(sender), INFO(parent));
+			dex, dim->prod(), ARGS(sender), ARGS(parent));
 	}
 #define FOO(T) try {gh->flow(this,-2,(T *)0);} CATCH_IT;
 	TYPESWITCH(nt,FOO,)
@@ -329,8 +327,7 @@
 
 void GridInlet::from_grid(Grid *g) {TRACE;
 	if (!supports_type(g->nt))
-		RAISE("%s: number type %s not supported here",
-			INFO(parent), number_type_table[g->nt].name);
+		RAISE("%s: number type %s not supported here", ARGS(parent), number_type_table[g->nt].name);
 #define FOO(T) from_grid2(g,(T)0);
 	TYPESWITCH(g->nt,FOO,)
 #undef FOO

Modified: trunk/base/grid.h
==============================================================================
--- trunk/base/grid.h (original)
+++ trunk/base/grid.h Thu Mar 20 15:43:29 2008
@@ -891,12 +891,10 @@
 extern "C" void Init_gridflow ();
 extern Numop *op_add,*op_sub,*op_mul,*op_div,*op_mod,*op_shl,*op_and,*op_put;
 
-#define INFO(OBJ) rb_str_ptr(rb_funcall(OBJ->rself,SI(info),0))
-//#define INFO(OBJ) "(bleh)"
-#define NOTEMPTY(_a_) if (!(_a_)) RAISE("in [%s], '%s' is empty",INFO(this), #_a_);
+#define ARGS(OBJ) rb_str_ptr(rb_funcall(OBJ->rself,SI(args),0))
+#define NOTEMPTY(_a_) if (!(_a_)) RAISE("in [%s], '%s' is empty",ARGS(this), #_a_);
 #define SAME_TYPE(_a_,_b_) \
-	if ((_a_)->nt != (_b_)->nt) RAISE("%s: same type please (%s has %s; %s has %s)", \
-		INFO(this), \
+	if ((_a_)->nt != (_b_)->nt) RAISE("%s: same type please (%s has %s; %s has %s)", ARGS(this), \
 		#_a_, number_type_table[(_a_)->nt].name, \
 		#_b_, number_type_table[(_b_)->nt].name);
 static void SAME_DIM(int n, P<Dim> a, int ai, P<Dim> b, int bi) {

Modified: trunk/base/main.c
==============================================================================
--- trunk/base/main.c (original)
+++ trunk/base/main.c Thu Mar 20 15:43:29 2008
@@ -142,7 +142,7 @@
 		argc = rb_ary_len(*argv);
 		argv = rb_ary_ptr(*argv);
 	} else {
-		RAISE("%s received bad message: argc=%d; argv[0]=%s",foo?INFO(foo):"", argc,
+		RAISE("%s received bad message: argc=%d; argv[0]=%s",foo?ARGS(foo):"", argc,
 			argc ? rb_str_ptr(rb_inspect(argv[0])) : "");
 	}
 }

Modified: trunk/base/main.rb
==============================================================================
--- trunk/base/main.rb (original)
+++ trunk/base/main.rb Thu Mar 20 15:43:29 2008
@@ -188,13 +188,10 @@
 		qlass.instance_eval{qlass.module_eval(&b)}
 		#qlass.module_eval(&b)
 	end
-	attr_writer :args # String
 	attr_accessor :argv # Array
 	attr_reader :outlets
 	attr_accessor :properties
 	def initialize2; end
-	def args() if defined? @args then @args else "[#{self.class} ...]" end end
-	alias info args
 	def connect outlet, object, inlet
 		@outlets ||= []
 		@outlets[outlet] ||= []
@@ -212,7 +209,7 @@
 		o=nil
 		if m.length==1 and m[0] =~ / /
 			o="[#{m[0]}]"
-			m=GridFlow.parse(m[0]) 
+			m=GridFlow.parse(m[0])
 		else
 			o=m.inspect
 		end
@@ -223,20 +220,12 @@
 		qlassname = qlass.to_s
 		qlass = name_lookup qlass.to_s unless Class===qlass
 		r = qlass.new(*m)
-		GridFlow.post "%s",r.args if GridFlow.verbose
+		GridFlow.post "[%s]",r.args if GridFlow.verbose
 		for x in ms do r.send_in(-2, *x) end
 		r
 	end
-	def inspect
-		if args then "#<#{self.class} #{args}>" else super end
-	end
+	def inspect; if args then "[#{args}]" else super end end
 	def initialize(*argv)
-		s = GridFlow.stringify_list argv
-		@argv = argv
-		@args = "["
-		@args << (self.class.foreign_name || self.to_s)
-		@args << " " if s.length>0
-		@args << s << "]"
 		@properties = {}
 		@init_messages = []
 	end
@@ -338,10 +327,10 @@
 }
 
 class Object
-  def method_missing(name,*args)
+  def method_missing(name,*)
     oc = GridFlow::FObject
-    obj = (case obj; when oc; self.info; else self      .inspect end)
-    qla = (case obj; when oc; self.info; else self.class.inspect end)
+    obj = (case obj; when oc; self.args; else self      .inspect end)
+    qla = (case obj; when oc; self.args; else self.class.inspect end)
     #begin raise; rescue Exception => e; end
     raise NameError, "undefined method \"#{name}\" for #{obj} in class #{qla}"#, ["hello"]+e.backtrace
   end

Modified: trunk/optional/fftw.c
==============================================================================
--- trunk/optional/fftw.c (original)
+++ trunk/optional/fftw.c Thu Mar 20 15:43:29 2008
@@ -28,7 +28,7 @@
 	{int bytes = 16; \
 	int align = ((ulong)(void*)d)%bytes; \
 	if (align) {_L_;post("%s(%s): Alignment Warning: %s=%p is not %d-aligned: %d", \
-		INFO(this), __PRETTY_FUNCTION__,#d,(void*)d,bytes,align);}}
+		ARGS(this), __PRETTY_FUNCTION__,#d,(void*)d,bytes,align);}}
 
 \class GridFFT < GridObject
 struct GridFFT : GridObject {

Modified: trunk/rubyext.c
==============================================================================
--- trunk/rubyext.c (original)
+++ trunk/rubyext.c Thu Mar 20 15:43:29 2008
@@ -624,8 +624,22 @@
     int ce_dollarzero;  /* value of "$0" */
 };
 
+static Ruby FObject_args (Ruby rself) {
+	DGS(FObject);
+	if (!self->bself) RAISE("can't use this in initialize");
+	char *buf;
+	int length;
+	t_binbuf *b = self->bself->te_binbuf;
+	if (!b) return Qnil;
+	binbuf_gettext(b, &buf, &length);
+	Ruby r = rb_str_new(buf,length);
+	free(buf);
+	return r;
+}
+
 static Ruby FObject_patcherargs (Ruby rself) {
 	DGS(FObject);
+	if (!self->bself) RAISE("can't use this in initialize");
 	t_glist *canvas = self->bself->mom;
 	_canvasenvironment *env = canvas_getenv(canvas);
 	Ruby ar = rb_ary_new();
@@ -834,6 +848,7 @@
 	rb_define_method(fo,"ninlets=",    (RMethod)FObject_ninlets_set,  1);
 	rb_define_method(fo,"noutlets=",   (RMethod)FObject_noutlets_set, 1);
 	rb_define_method(fo,"patcherargs", (RMethod)FObject_patcherargs,0);
+	rb_define_method(fo,"args",        (RMethod)FObject_args,0);
 	rb_define_method(fo,"bself",       (RMethod)FObject_bself,0);
 
 	SDEF("post_string",post_string,1);



More information about the Gridflow-cvs mailing list